diff --git a/nip46.ts b/nip46.ts index 78c2693..25669f2 100644 --- a/nip46.ts +++ b/nip46.ts @@ -311,7 +311,8 @@ export class BunkerSigner implements Signer { // closes the subscription -- this object can't be used anymore after this async close() { this.isOpen = false - this.subCloser!.close() + this.subCloser?.close() + this.subCloser = undefined } async sendRequest(method: string, params: string[]): Promise { @@ -364,6 +365,16 @@ export class BunkerSigner implements Signer { await this.sendRequest('connect', [this.bp.pubkey, this.bp.secret || '']) } + /** + * Calls the "logout" method on the bunker and closes the local session. + * The client secret key should be discarded by the caller after this. + */ + async logout(): Promise { + let resp = await this.sendRequest('logout', []) + if (resp !== 'ack') throw new Error(`result is not ack: ${resp}`) + await this.close() + } + /** * Calls the "get_public_key" method on the bunker. * (before we would return the public key hardcoded in the bunker parameters, but