From 3defeeb7967d8aa914469c833853d24b991a1d29 Mon Sep 17 00:00:00 2001 From: hzrd149 Date: Wed, 10 Jun 2026 12:12:18 -0500 Subject: [PATCH] nip46: add logout method --- nip46.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) 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