Skip to content

Commit 01ba3c8

Browse files
authored
fix(nip46): use getPublicKey() in nostrconnect flow to get actual user pubkey (#374)
The nostrconnect:// flow was incorrectly using response.event.pubkey as the userPubkey, but that's actually the bunker's pubkey (the one signing the NIP-46 response event). This fix aligns the nostrconnect flow with the bunker:// flow, which correctly calls getPublicKey() to retrieve the actual user's pubkey from the remote signer. Fixes #373
1 parent 49eceed commit 01ba3c8

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

core/src/signers/nip46/index.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,12 +226,17 @@ export class NDKNip46Signer extends EventEmitter implements NDKSigner {
226226
return new Promise((resolve, reject) => {
227227
const connect = (response: NDKRpcResponse) => {
228228
if (response.result === this.nostrConnectSecret) {
229-
this._user = response.event.author;
230-
this.userPubkey = response.event.pubkey;
229+
// The response event pubkey is the bunker's pubkey, not the user's
231230
this.bunkerPubkey = response.event.pubkey;
232231

233232
this.rpc.off("response", connect);
234-
resolve(this._user);
233+
234+
// Get the actual user's pubkey from the bunker
235+
this.getPublicKey().then((pubkey) => {
236+
this.userPubkey = pubkey;
237+
this._user = this.ndk.getUser({ pubkey });
238+
resolve(this._user);
239+
}).catch(reject);
235240
}
236241
};
237242

0 commit comments

Comments
 (0)