From af50580aca52dc2bff523259afd2cd8d835ee2b9 Mon Sep 17 00:00:00 2001 From: Dorian Date: Thu, 12 Mar 2026 16:49:22 +0000 Subject: [PATCH] fix: generated identity uses extension signer instead of local key buildNip98Token checked window.nostr before secretKeyHex, so "Generate New Identity" would sign with the browser extension's key after saving. Now explicit keys always take priority over extensions. Also made setup flow mode-aware: webhook users get BOTFIGHTS-WEBHOOK.md, polling users get BOTFIGHTS-POLLING.md with matching copy prompts. Co-Authored-By: Claude Opus 4.6 --- frontend/src/lib/nostr-auth.ts | 16 +++++++++------- frontend/src/pages/JoinBoutPage.vue | 19 ++++++++++++++----- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/frontend/src/lib/nostr-auth.ts b/frontend/src/lib/nostr-auth.ts index b261e05..7855f5d 100644 --- a/frontend/src/lib/nostr-auth.ts +++ b/frontend/src/lib/nostr-auth.ts @@ -68,19 +68,21 @@ export async function buildNip98Token( let signedEvent: Record - const signer = (window as { nostr?: NostrSigner }).nostr - if (signer) { - // Sign via NIP-07 extension or Amber - signedEvent = await signer.signEvent(unsignedEvent) - } else if (secretKeyHex) { - // Sign locally with secret key + if (secretKeyHex) { + // Sign locally with provided secret key — always prefer explicit key over extension const { hexToBytes } = await import('nostr-tools/utils') const { finalizeEvent } = await import('nostr-tools') const sk = hexToBytes(secretKeyHex) const event = finalizeEvent(unsignedEvent, sk) signedEvent = event as unknown as Record } else { - throw new Error('No Nostr signer available. Install a NIP-07 extension or use a saved key.') + const signer = (window as { nostr?: NostrSigner }).nostr + if (signer) { + // Sign via NIP-07 extension or Amber + signedEvent = await signer.signEvent(unsignedEvent) + } else { + throw new Error('No Nostr signer available. Install a NIP-07 extension or use a saved key.') + } } return btoa(JSON.stringify(signedEvent)) diff --git a/frontend/src/pages/JoinBoutPage.vue b/frontend/src/pages/JoinBoutPage.vue index 79dd72b..db04d93 100644 --- a/frontend/src/pages/JoinBoutPage.vue +++ b/frontend/src/pages/JoinBoutPage.vue @@ -523,12 +523,21 @@ async function confirmPolling() { } } +function setupDocPath() { + return connectionMode.value === 'polling' ? '/docs/BOTFIGHTS-POLLING.md' : '/docs/BOTFIGHTS-WEBHOOK.md' +} + +function setupDocName() { + return connectionMode.value === 'polling' ? 'BOTFIGHTS-POLLING.md' : 'BOTFIGHTS-WEBHOOK.md' +} + function downloadSetupGuide() { - window.open('/docs/BOTFIGHTS.md', '_blank') + window.open(setupDocPath(), '_blank') } function copyFullPrompt() { - const text = `Read BOTFIGHTS.md and follow the setup instructions. Here are my credentials:\nBOT_ID=${botId.value}\nBOT_SECRET=${botSecret.value}` + const docName = setupDocName() + const text = `Read ${docName} and follow the setup instructions. Here are my credentials:\nBOT_ID=${botId.value}\nBOT_SECRET=${botSecret.value}` navigator.clipboard.writeText(text) setupGuideCopied.value = true setTimeout(() => { setupGuideCopied.value = false }, 2000) @@ -1336,13 +1345,13 @@ function handleSignOut() {
1
-

Download BOTFIGHTS.md into your workspace

+

Download {{ setupDocName() }} into your workspace

@@ -1353,7 +1362,7 @@ function handleSignOut() {

Tell your AI this:

-

Read BOTFIGHTS.md and follow the setup instructions. Here are my credentials:

+

Read {{ setupDocName() }} and follow the setup instructions. Here are my credentials:

BOT_ID={{ botId }}
BOT_SECRET={{ botSecret }}