nip46: fix checking event that comes from bunker call sign_event and bump version.

This commit is contained in:
fiatjaf 2024-02-12 16:06:20 -03:00
parent 9d78c90a79
commit b4e54d679f
No known key found for this signature in database
GPG Key ID: BAD43C4BE5C1A3A1
2 changed files with 11 additions and 7 deletions

View File

@ -115,12 +115,16 @@ export class BunkerSigner {
[{ kinds: [NostrConnect, NostrConnectAdmin], '#p': [getPublicKey(this.secretKey)] }],
{
async onevent(event: NostrEvent) {
const decryptedContent = await decrypt(clientSecretKey, event.pubkey, event.content)
const parsedContent = JSON.parse(decryptedContent)
const { id, result, error } = parsedContent
const { id, result, error } = JSON.parse(await decrypt(clientSecretKey, event.pubkey, event.content))
if (result === 'auth_url') {
params.onauth?.(error)
if (params.onauth) {
params.onauth(error)
} else {
console.warn(
`nostr-tools/nip46: remote signer ${bp.pubkey} tried to send an "auth_url"='${error}' but there was no onauth() callback configured.`,
)
}
return
}
@ -207,10 +211,10 @@ export class BunkerSigner {
async signEvent(event: UnsignedEvent): Promise<VerifiedEvent> {
let resp = await this.sendRequest('sign_event', [JSON.stringify(event)])
let signed: NostrEvent = JSON.parse(resp)
if (signed.pubkey === getPublicKey(this.secretKey) && verifyEvent(signed)) {
if (signed.pubkey === this.remotePubkey && verifyEvent(signed)) {
return signed
} else {
throw new Error(`event returned from bunker is improperly signed: ${signed}`)
throw new Error(`event returned from bunker is improperly signed: ${JSON.stringify(signed)}`)
}
}
}

View File

@ -1,7 +1,7 @@
{
"type": "module",
"name": "nostr-tools",
"version": "2.1.6",
"version": "2.1.7",
"description": "Tools for making a Nostr client.",
"repository": {
"type": "git",