Skip to content

Commit

Permalink
nip46: only handle the first auth_url for every command.
Browse files Browse the repository at this point in the history
  • Loading branch information
fiatjaf committed Feb 16, 2024
1 parent 5626d30 commit bb1e6f4
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion nip46.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export class BunkerSigner {
reject: (_: string) => void
}
}
private waitingForAuth: { [id: string]: boolean }
private secretKey: Uint8Array
public bp: BunkerPointer

Expand All @@ -104,8 +105,10 @@ export class BunkerSigner {
this.idPrefix = Math.random().toString(36).substring(7)
this.serial = 0
this.listeners = {}
this.waitingForAuth = {}

const listeners = this.listeners
const waitingForAuth = this.waitingForAuth

this.subCloser = this.pool.subscribeMany(
this.bp.relays,
Expand All @@ -114,7 +117,9 @@ export class BunkerSigner {
async onevent(event: NostrEvent) {
const { id, result, error } = JSON.parse(await decrypt(clientSecretKey, event.pubkey, event.content))

if (result === 'auth_url') {
if (result === 'auth_url' && waitingForAuth[id]) {
delete listeners[id]

if (params.onauth) {
params.onauth(error)
} else {
Expand Down Expand Up @@ -165,6 +170,7 @@ export class BunkerSigner {

// setup callback listener
this.listeners[id] = { resolve, reject }
this.waitingForAuth[id] = true

// publish the event
await Promise.any(this.pool.publish(this.bp.relays, verifiedEvent))
Expand Down

0 comments on commit bb1e6f4

Please sign in to comment.