fix(smirk): fall back to legacy connect() on a locked signNostrEvent (restores unlock-popup path)

Only an explicit user-cancel skips the fallback now — a LOCKED signNostrEvent again tries connect(), which opens the unlock popup on capable builds. My earlier refinement had removed this path.
This commit is contained in:
jwinterm
2026-07-10 09:55:01 -04:00
parent 7e7e66e887
commit 057767152c
+8 -9
View File
@@ -77,16 +77,15 @@ const SmirkAuth = {
verifyData = result.verifyData;
provenPublicKey = result.pubkey;
} catch (nip98Err) {
// Only fall back to the legacy path when the wallet genuinely can't do NIP-98
// (method missing / unsupported). For LOCKED (unlock the extension), USER_REJECTED
// (user closed the popup), or a real signing failure, SURFACE it — re-invoking
// connect() would just pop a second prompt. On a current Smirk build a locked
// signNostrEvent auto-opens the unlock popup and never reaches here.
// Fall back to the legacy connect() path UNLESS the user explicitly cancelled the
// popup. This gives connect() a chance to open the unlock prompt when a locked
// signNostrEvent threw LOCKED instead of prompting (partial/stale builds), and
// covers wallets that lack NIP-98 entirely. Only an explicit cancel is not retried.
const code = nip98Err && nip98Err.code;
const methodMissing = code === 'UNSUPPORTED' || code === 'METHOD_NOT_FOUND'
|| /not a function|is not supported|no such method|unsupported/i.test((nip98Err && nip98Err.message) || '');
if (!methodMissing) throw nip98Err;
console.warn('Smirk NIP-98 unsupported, falling back to legacy:', nip98Err && nip98Err.message);
const userCancelled = code === 'USER_REJECTED'
|| /reject|cancel|denied|declined/i.test((nip98Err && nip98Err.message) || '');
if (userCancelled) throw nip98Err;
console.warn('Smirk NIP-98 failed, trying legacy connect():', nip98Err && nip98Err.message);
const result = await this._verifyLegacy(socketId, challenge);
verifyData = result.verifyData;
provenPublicKey = result.pubkey;