nip46: add logout method

This commit is contained in:
hzrd149
2026-06-10 12:12:18 -05:00
committed by fiatjaf
parent 5de4f4549b
commit 3defeeb796

View File

@@ -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<string> {
@@ -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<void> {
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