mirror of
https://github.com/nbd-wtf/nostr-tools.git
synced 2026-07-22 07:48:27 +00:00
nip46: add logout method
This commit is contained in:
13
nip46.ts
13
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<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
|
||||
|
||||
Reference in New Issue
Block a user