From 0d0a08ad49bbb881d5fe4649d47d92cc05cd11da Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 18 Aug 2025 12:32:20 -0400 Subject: [PATCH] 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 --- app.js | 15 +- views/login.ejs | 371 +++++++++++++++++++++++++----------------------- 2 files changed, 207 insertions(+), 179 deletions(-) diff --git a/app.js b/app.js index 28a410e..1489a11 100644 --- a/app.js +++ b/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'); } diff --git a/views/login.ejs b/views/login.ejs index 98c5d0e..caa8d80 100644 --- a/views/login.ejs +++ b/views/login.ejs @@ -3,204 +3,219 @@ - Nostr Login - OIDC Bridge - + Nostr Login - OIDC Bridge v2.1 -
- - +
+ + + + + + <% if (typeof error !== 'undefined') { %> -
- Error: <%= error %> +
+ Authentication Error: <%= error %>
<% } %> - -
- Challenge to sign:
- <%= challenge %> -
- - - -
- or + +
+ 🚀 Nostr OIDC Bridge v2.1 - Form Auth + event_json fix
- - -
- - -
- - -
Your public Nostr identity key
-
- -
- - -
Create and sign a kind 1 event with the challenge as content
-
- - -
- -
- Instructions:
- 1. Use a browser extension (recommended) or
- 2. Create a Nostr event with the challenge above as content
- 3. Sign it with your private key and paste the JSON + + +
+ + +
+ v2.1 - Form Auth + event_json fix
+ + + + + + +