aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/nip07.ts
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-03-05 23:01:15 -0800
committerAdam Soltys <[email protected]>2026-03-05 23:01:15 -0800
commit3b18232d52957dbd1a5a0c12891020d2a6e3295e (patch)
treeebb2d2673b89e71b0eaaa0ab829cab0d707ce3ee /src/lib/nip07.ts
parent7471599082e053cabea19df25c867c654cb7445c (diff)
downloadcoinos-ui-3b18232d52957dbd1a5a0c12891020d2a6e3295e.tar.gz
coinos-ui-3b18232d52957dbd1a5a0c12891020d2a6e3295e.zip
messaging fixes
Diffstat (limited to 'src/lib/nip07.ts')
-rw-r--r--src/lib/nip07.ts14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/lib/nip07.ts b/src/lib/nip07.ts
index e90d13a7..691e3bcd 100644
--- a/src/lib/nip07.ts
+++ b/src/lib/nip07.ts
@@ -32,15 +32,23 @@ const tryNsecFromStorage = async (): Promise<Uint8Array | null> => {
// Ensures we have access to a secret key, triggering the signer modal if needed.
// Returns the sk as Uint8Array, or null if using NIP-07 extension.
export const ensureSigner = async (userPubkey: string): Promise<Uint8Array | null> => {
- // Check if signer already has a valid sk (64 hex chars = 32 bytes)
+ // Check if signer already has a valid sk that matches the user's pubkey
const currentSigner = get(signer);
if (currentSigner?.ready && currentSigner?.params?.sk && currentSigner.params.sk.length === 64) {
- return hexToBytes(currentSigner.params.sk);
+ const sk = hexToBytes(currentSigner.params.sk);
+ if (getPublicKey(sk) === userPubkey) return sk;
+ // Stale signer — clear it so we re-derive below
+ signer.set(undefined);
}
// Try to load from localStorage nsec before triggering the modal
const skFromStorage = await tryNsecFromStorage();
- if (skFromStorage) return skFromStorage;
+ if (skFromStorage) {
+ if (getPublicKey(skFromStorage) === userPubkey) return skFromStorage;
+ // localStorage nsec doesn't match — clear it
+ localStorage.removeItem("nsec");
+ signer.set(undefined);
+ }
// Try to derive nostr key from cached canonical key (e.g. passkey accounts)
try {