nip46: fix crash caused by endless resubscribe
This commit is contained in:
parent
c015b6e794
commit
cb370fbf4f
10
nip46.ts
10
nip46.ts
|
@ -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}`
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue