mirror of
https://github.com/nbd-wtf/nostr-tools.git
synced 2026-10-05 14:38:23 +00:00
nip46: add logout method
This commit is contained in:
@@ -311,7 +311,8 @@ export class BunkerSigner implements Signer {
|
|||||||
// closes the subscription -- this object can't be used anymore after this
|
// closes the subscription -- this object can't be used anymore after this
|
||||||
async close() {
|
async close() {
|
||||||
this.isOpen = false
|
this.isOpen = false
|
||||||
this.subCloser!.close()
|
this.subCloser?.close()
|
||||||
|
this.subCloser = undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
async sendRequest(method: string, params: string[]): Promise<string> {
|
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 || ''])
|
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.
|
* Calls the "get_public_key" method on the bunker.
|
||||||
* (before we would return the public key hardcoded in the bunker parameters, but
|
* (before we would return the public key hardcoded in the bunker parameters, but
|
||||||
|
|||||||
Reference in New Issue
Block a user