nip46: fix crash caused by endless resubscribe

This commit is contained in:
codytseng 2025-05-11 23:59:07 +08:00 committed by fiatjaf_
parent c015b6e794
commit cb370fbf4f
1 changed files with 5 additions and 5 deletions

View File

@ -83,6 +83,7 @@ export type BunkerSignerParams = {
} }
export class BunkerSigner { export class BunkerSigner {
private params: BunkerSignerParams
private pool: AbstractSimplePool private pool: AbstractSimplePool
private subCloser: SubCloser | undefined private subCloser: SubCloser | undefined
private isOpen: boolean private isOpen: boolean
@ -112,6 +113,7 @@ export class BunkerSigner {
throw new Error('no relays are specified for this bunker') throw new Error('no relays are specified for this bunker')
} }
this.params = params
this.pool = params.pool || new SimplePool() this.pool = params.pool || new SimplePool()
this.secretKey = clientSecretKey this.secretKey = clientSecretKey
this.conversationKey = getConversationKey(clientSecretKey, bp.pubkey) this.conversationKey = getConversationKey(clientSecretKey, bp.pubkey)
@ -159,11 +161,7 @@ export class BunkerSigner {
} }
}, },
onclose: () => { onclose: () => {
if (this.isOpen) { this.subCloser = undefined
// If we get onclose but isOpen is still true, that means the client still wants to stay connected
this.subCloser!.close()
this.setupSubscription(params)
}
}, },
}, },
) )
@ -180,6 +178,8 @@ export class BunkerSigner {
return new Promise(async (resolve, reject) => { return new Promise(async (resolve, reject) => {
try { try {
if (!this.isOpen) throw new Error('this signer is not open anymore, create a new one') if (!this.isOpen) throw new Error('this signer is not open anymore, create a new one')
if (!this.subCloser) this.setupSubscription(this.params)
this.serial++ this.serial++
const id = `${this.idPrefix}-${this.serial}` const id = `${this.idPrefix}-${this.serial}`