184 lines
7.2 KiB
HTML
184 lines
7.2 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>NIP-07 Signing Test</title>
|
|
</head>
|
|
|
|
<body>
|
|
<div>
|
|
<div id="status"></div>
|
|
|
|
<div id="test-section" style="display:none;">
|
|
<button id="sign-button">Sign Event</button>
|
|
<button id="encrypt-button">Test NIP-04 Encrypt</button>
|
|
<button id="decrypt-button">Test NIP-04 Decrypt</button>
|
|
<div id="results"></div>
|
|
</div>
|
|
</div>
|
|
|
|
<script src="../lite/nostr.bundle.js"></script>
|
|
<script src="../lite/nostr-lite.js"></script>
|
|
|
|
<script>
|
|
let testPubkey = 'npub1damus9dqe7g7jqn45kjcjgsv0vxjqnk8cxjkf8gqjwm8t8qjm7cqm3z7l';
|
|
let ciphertext = '';
|
|
|
|
document.addEventListener('DOMContentLoaded', async () => {
|
|
await window.NOSTR_LOGIN_LITE.init({
|
|
theme: 'default',
|
|
methods: {
|
|
extension: true,
|
|
local: true,
|
|
readonly: true,
|
|
connect: true,
|
|
remote: true,
|
|
otp: true
|
|
},
|
|
floatingTab: {
|
|
enabled: true,
|
|
hPosition: 1, // 0.0-1.0 or '95%' from left
|
|
vPosition: 0, // 0.0-1.0 or '50%' from top
|
|
appearance: {
|
|
style: 'pill', // 'pill', 'square', 'circle', 'minimal'
|
|
icon: '', // Clean display without icon placeholders
|
|
text: 'Login'
|
|
},
|
|
behavior: {
|
|
hideWhenAuthenticated: false,
|
|
showUserInfo: true,
|
|
autoSlide: true
|
|
},
|
|
getUserInfo: true, // Enable profile fetching
|
|
getUserRelay: [ // Specific relays for profile fetching
|
|
'wss://relay.laantungir.net'
|
|
]
|
|
}});
|
|
|
|
|
|
// document.getElementById('login-button').addEventListener('click', () => {
|
|
// window.NOSTR_LOGIN_LITE.launch('login');
|
|
// });
|
|
|
|
window.addEventListener('nlMethodSelected', (event) => {
|
|
document.getElementById('status').textContent = `Authenticated with: ${event.detail.method}`;
|
|
document.getElementById('test-section').style.display = 'block';
|
|
});
|
|
|
|
document.getElementById('sign-button').addEventListener('click', testSigning);
|
|
document.getElementById('encrypt-button').addEventListener('click', testEncryption);
|
|
document.getElementById('decrypt-button').addEventListener('click', testDecryption);
|
|
});
|
|
|
|
async function testSigning() {
|
|
try {
|
|
console.log('=== DEBUGGING SIGN EVENT START ===');
|
|
console.log('testSigning: window.nostr is:', window.nostr);
|
|
console.log('testSigning: window.nostr constructor:', window.nostr?.constructor?.name);
|
|
console.log('testSigning: window.nostr === our facade?', window.nostr?.constructor?.name === 'WindowNostr');
|
|
|
|
// Get user public key for comparison
|
|
const userPubkey = await window.nostr.getPublicKey();
|
|
console.log('User public key:', userPubkey);
|
|
|
|
// Check auth state if our facade
|
|
if (window.nostr?.constructor?.name === 'WindowNostr') {
|
|
console.log('WindowNostr authState:', window.nostr.authState);
|
|
console.log('WindowNostr authenticatedExtension:', window.nostr.authenticatedExtension);
|
|
console.log('WindowNostr existingNostr:', window.nostr.existingNostr);
|
|
}
|
|
|
|
const event = {
|
|
kind: 1,
|
|
content: 'Hello from NIP-07!',
|
|
tags: [],
|
|
created_at: Math.floor(Date.now() / 1000)
|
|
};
|
|
|
|
console.log('=== EVENT BEING SENT TO EXTENSION ===');
|
|
console.log('Event object:', JSON.stringify(event, null, 2));
|
|
console.log('Event keys:', Object.keys(event));
|
|
console.log('Event kind type:', typeof event.kind, event.kind);
|
|
console.log('Event content type:', typeof event.content, event.content);
|
|
console.log('Event tags type:', typeof event.tags, event.tags);
|
|
console.log('Event created_at type:', typeof event.created_at, event.created_at);
|
|
console.log('Event created_at value:', event.created_at);
|
|
|
|
// Check if created_at is within reasonable bounds
|
|
const now = Math.floor(Date.now() / 1000);
|
|
const timeDiff = Math.abs(event.created_at - now);
|
|
console.log('Time difference from now (seconds):', timeDiff);
|
|
console.log('Event timestamp as Date:', new Date(event.created_at * 1000));
|
|
|
|
// Additional debugging for user-specific issues
|
|
console.log('=== USER-SPECIFIC DEBUG INFO ===');
|
|
console.log('User pubkey length:', userPubkey?.length);
|
|
console.log('User pubkey format check (hex):', /^[a-fA-F0-9]{64}$/.test(userPubkey));
|
|
|
|
// Try to get user profile info if available
|
|
try {
|
|
const profileEvent = {
|
|
kinds: [0],
|
|
authors: [userPubkey],
|
|
limit: 1
|
|
};
|
|
console.log('Would query profile with filter:', profileEvent);
|
|
} catch (profileErr) {
|
|
console.log('Profile query setup failed:', profileErr);
|
|
}
|
|
|
|
console.log('=== ABOUT TO CALL EXTENSION SIGN EVENT ===');
|
|
const signedEvent = await window.nostr.signEvent(event);
|
|
|
|
console.log('=== SIGN EVENT SUCCESSFUL ===');
|
|
console.log('Signed event:', JSON.stringify(signedEvent, null, 2));
|
|
console.log('Signed event keys:', Object.keys(signedEvent));
|
|
console.log('Signature present:', !!signedEvent.sig);
|
|
console.log('ID present:', !!signedEvent.id);
|
|
console.log('Pubkey matches user:', signedEvent.pubkey === userPubkey);
|
|
|
|
document.getElementById('results').innerHTML = `<h3>Signed Event:</h3><pre>${JSON.stringify(signedEvent, null, 2)}</pre>`;
|
|
|
|
console.log('=== DEBUGGING SIGN EVENT END ===');
|
|
} catch (error) {
|
|
console.error('=== SIGN EVENT ERROR ===');
|
|
console.error('Error message:', error.message);
|
|
console.error('Error stack:', error.stack);
|
|
console.error('Error object:', error);
|
|
|
|
document.getElementById('results').innerHTML = `<h3>Sign Error:</h3><pre>${error.message}</pre><pre>${error.stack}</pre>`;
|
|
}
|
|
}
|
|
|
|
async function testEncryption() {
|
|
try {
|
|
const plaintext = 'Secret message for testing';
|
|
const pubkey = await window.nostr.getPublicKey();
|
|
|
|
ciphertext = await window.nostr.nip04.encrypt(pubkey, plaintext);
|
|
document.getElementById('results').innerHTML = `<h3>Encrypted:</h3><pre>${ciphertext}</pre>`;
|
|
} catch (error) {
|
|
document.getElementById('results').innerHTML = `<h3>Encrypt Error:</h3><pre>${error.message}</pre>`;
|
|
}
|
|
}
|
|
|
|
async function testDecryption() {
|
|
try {
|
|
if (!ciphertext) {
|
|
document.getElementById('results').innerHTML = `<h3>Decrypt Error:</h3><pre>No ciphertext available. Run encrypt first.</pre>`;
|
|
return;
|
|
}
|
|
|
|
const pubkey = await window.nostr.getPublicKey();
|
|
const decrypted = await window.nostr.nip04.decrypt(pubkey, ciphertext);
|
|
document.getElementById('results').innerHTML = `<h3>Decrypted:</h3><pre>${decrypted}</pre>`;
|
|
} catch (error) {
|
|
document.getElementById('results').innerHTML = `<h3>Decrypt Error:</h3><pre>${error.message}</pre>`;
|
|
}
|
|
}
|
|
</script>
|
|
</body>
|
|
|
|
</html> |