mirror of
https://github.com/nbd-wtf/nostr-tools.git
synced 2025-12-08 16:28:49 +00:00
nip46: fix checking event that comes from bunker call sign_event and bump version.
This commit is contained in:
16
nip46.ts
16
nip46.ts
@@ -115,12 +115,16 @@ export class BunkerSigner {
|
|||||||
[{ kinds: [NostrConnect, NostrConnectAdmin], '#p': [getPublicKey(this.secretKey)] }],
|
[{ kinds: [NostrConnect, NostrConnectAdmin], '#p': [getPublicKey(this.secretKey)] }],
|
||||||
{
|
{
|
||||||
async onevent(event: NostrEvent) {
|
async onevent(event: NostrEvent) {
|
||||||
const decryptedContent = await decrypt(clientSecretKey, event.pubkey, event.content)
|
const { id, result, error } = JSON.parse(await decrypt(clientSecretKey, event.pubkey, event.content))
|
||||||
const parsedContent = JSON.parse(decryptedContent)
|
|
||||||
const { id, result, error } = parsedContent
|
|
||||||
|
|
||||||
if (result === 'auth_url') {
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -207,10 +211,10 @@ export class BunkerSigner {
|
|||||||
async signEvent(event: UnsignedEvent): Promise<VerifiedEvent> {
|
async signEvent(event: UnsignedEvent): Promise<VerifiedEvent> {
|
||||||
let resp = await this.sendRequest('sign_event', [JSON.stringify(event)])
|
let resp = await this.sendRequest('sign_event', [JSON.stringify(event)])
|
||||||
let signed: NostrEvent = JSON.parse(resp)
|
let signed: NostrEvent = JSON.parse(resp)
|
||||||
if (signed.pubkey === getPublicKey(this.secretKey) && verifyEvent(signed)) {
|
if (signed.pubkey === this.remotePubkey && verifyEvent(signed)) {
|
||||||
return signed
|
return signed
|
||||||
} else {
|
} 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)}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"name": "nostr-tools",
|
"name": "nostr-tools",
|
||||||
"version": "2.1.6",
|
"version": "2.1.7",
|
||||||
"description": "Tools for making a Nostr client.",
|
"description": "Tools for making a Nostr client.",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|||||||
Reference in New Issue
Block a user