Fix npub encoding and validation errors

- Fixed frontend to properly encode npub using nip19.npubEncode()
- Enhanced backend to handle both npub and hex pubkey formats
- Resolved 'Data must be at least 6 characters long' validation error
- Added proper error handling for pubkey format validation
- Should eliminate retry loop issues during authentication
This commit is contained in:
Your Name
2025-08-18 12:32:20 -04:00
parent d0845a8323
commit 0d0a08ad49
2 changed files with 207 additions and 179 deletions

15
app.js
View File

@@ -225,7 +225,20 @@ app.post('/complete-auth/:sessionId', async (req, res) => {
throw new Error('Challenge mismatch');
}
const { data: pubkey } = nip19.decode(npub);
// Handle both npub format and raw hex pubkey
let pubkey;
try {
if (npub.startsWith('npub')) {
const decoded = nip19.decode(npub);
pubkey = decoded.data;
} else {
// Assume it's raw hex pubkey
pubkey = npub;
}
} catch (error) {
throw new Error('Invalid public key format');
}
if (event.pubkey !== pubkey) {
throw new Error('Public key mismatch');
}