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:
15
app.js
15
app.js
@@ -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');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user