mirror of
https://github.com/nbd-wtf/nostr-tools.git
synced 2025-12-09 16:48:50 +00:00
nip46: only handle the first auth_url for every command.
This commit is contained in:
8
nip46.ts
8
nip46.ts
@@ -83,6 +83,7 @@ export class BunkerSigner {
|
|||||||
reject: (_: string) => void
|
reject: (_: string) => void
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private waitingForAuth: { [id: string]: boolean }
|
||||||
private secretKey: Uint8Array
|
private secretKey: Uint8Array
|
||||||
public bp: BunkerPointer
|
public bp: BunkerPointer
|
||||||
|
|
||||||
@@ -104,8 +105,10 @@ export class BunkerSigner {
|
|||||||
this.idPrefix = Math.random().toString(36).substring(7)
|
this.idPrefix = Math.random().toString(36).substring(7)
|
||||||
this.serial = 0
|
this.serial = 0
|
||||||
this.listeners = {}
|
this.listeners = {}
|
||||||
|
this.waitingForAuth = {}
|
||||||
|
|
||||||
const listeners = this.listeners
|
const listeners = this.listeners
|
||||||
|
const waitingForAuth = this.waitingForAuth
|
||||||
|
|
||||||
this.subCloser = this.pool.subscribeMany(
|
this.subCloser = this.pool.subscribeMany(
|
||||||
this.bp.relays,
|
this.bp.relays,
|
||||||
@@ -114,7 +117,9 @@ export class BunkerSigner {
|
|||||||
async onevent(event: NostrEvent) {
|
async onevent(event: NostrEvent) {
|
||||||
const { id, result, error } = JSON.parse(await decrypt(clientSecretKey, event.pubkey, event.content))
|
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) {
|
if (params.onauth) {
|
||||||
params.onauth(error)
|
params.onauth(error)
|
||||||
} else {
|
} else {
|
||||||
@@ -165,6 +170,7 @@ export class BunkerSigner {
|
|||||||
|
|
||||||
// setup callback listener
|
// setup callback listener
|
||||||
this.listeners[id] = { resolve, reject }
|
this.listeners[id] = { resolve, reject }
|
||||||
|
this.waitingForAuth[id] = true
|
||||||
|
|
||||||
// publish the event
|
// publish the event
|
||||||
await Promise.any(this.pool.publish(this.bp.relays, verifiedEvent))
|
await Promise.any(this.pool.publish(this.bp.relays, verifiedEvent))
|
||||||
|
|||||||
Reference in New Issue
Block a user