Use window.nostr.connect, getSigner and disconnect where the extension offers them

Din's and Tenna's NIP-07 providers add three optional methods, after NIP-46's
names. Logging in through an extension now asks connect() for an account
(skipping the Welcome back preview, since the extension shows the account),
each extension login signs through getSigner(pubkey) so switching accounts
in the extension doesn't change who the app signs as, and logging out calls
disconnect(pubkey). Each is feature-detected on its own; extensions without
them work as before. The onchain-bitcoin skill's NBrowserSignerBtc now
builds on the same signer.
This commit is contained in:
Alex Gleason committed 2026-11-28 16:50:29 -06:00
1 parent 67eb5f2a1c
commit 9d43fdbcc3
10 files changed
+262 -33

No files matched your search

+15 -1
View File
@@ -8,6 +8,7 @@ import {
} from '@nostrify/react/login';
import { useAppContext } from '@/hooks/useAppContext';
import { APP_RELAYS } from '@/lib/appRelays';
import { getNip07Provider, hasConnect } from '@/lib/nip07';
// NOTE: This file should not be edited except for adding new login methods.
@@ -40,8 +41,21 @@ export function useLoginActions() {
const login = await NLogin.fromBunker(uri, nostr);
addAndActivate(login);
},
// Login with a NIP-07 browser extension
// Login with a NIP-07 browser extension. One that can give the site an
// account of the user's choosing (connect) is asked for one; the
// extension shows the account itself.
async extension(): Promise<void> {
const provider = getNip07Provider();
if (hasConnect(provider)) {
const signer = await provider.connect();
const answer: unknown = await signer.getPublicKey();
const pubkey = typeof answer === 'string' ? answer.toLowerCase() : '';
if (!/^[0-9a-f]{64}$/.test(pubkey)) {
throw new Error('The extension returned an invalid public key');
}
addAndActivate(new NLogin('extension', pubkey, null));
return;
}
const login = await NLogin.fromExtension();
addAndActivate(login);
},