mirror of
https://github.com/nbd-wtf/nostr-tools.git
synced 2025-12-09 16:48:50 +00:00
nip46: only encrypt with nip44 (breaking).
This commit is contained in:
2
jsr.json
2
jsr.json
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@nostr/tools",
|
"name": "@nostr/tools",
|
||||||
"version": "2.9.4",
|
"version": "2.10.0",
|
||||||
"exports": {
|
"exports": {
|
||||||
".": "./index.ts",
|
".": "./index.ts",
|
||||||
"./core": "./core.ts",
|
"./core": "./core.ts",
|
||||||
|
|||||||
16
nip46.ts
16
nip46.ts
@@ -1,8 +1,8 @@
|
|||||||
import { NostrEvent, UnsignedEvent, VerifiedEvent } from './core.ts'
|
import { NostrEvent, UnsignedEvent, VerifiedEvent } from './core.ts'
|
||||||
import { generateSecretKey, finalizeEvent, getPublicKey, verifyEvent } from './pure.ts'
|
import { generateSecretKey, finalizeEvent, getPublicKey, verifyEvent } from './pure.ts'
|
||||||
import { AbstractSimplePool, SubCloser } from './abstract-pool.ts'
|
import { AbstractSimplePool, SubCloser } from './abstract-pool.ts'
|
||||||
import { decrypt, encrypt } from './nip04.ts'
|
import { decrypt as legacyDecrypt } from './nip04.ts'
|
||||||
import { getConversationKey, decrypt as nip44decrypt } from './nip44.ts'
|
import { getConversationKey, decrypt, encrypt } from './nip44.ts'
|
||||||
import { NIP05_REGEX } from './nip05.ts'
|
import { NIP05_REGEX } from './nip05.ts'
|
||||||
import { SimplePool } from './pool.ts'
|
import { SimplePool } from './pool.ts'
|
||||||
import { Handlerinformation, NostrConnect } from './kinds.ts'
|
import { Handlerinformation, NostrConnect } from './kinds.ts'
|
||||||
@@ -86,6 +86,7 @@ export class BunkerSigner {
|
|||||||
}
|
}
|
||||||
private waitingForAuth: { [id: string]: boolean }
|
private waitingForAuth: { [id: string]: boolean }
|
||||||
private secretKey: Uint8Array
|
private secretKey: Uint8Array
|
||||||
|
private conversationKey: Uint8Array
|
||||||
public bp: BunkerPointer
|
public bp: BunkerPointer
|
||||||
|
|
||||||
private cachedPubKey: string | undefined
|
private cachedPubKey: string | undefined
|
||||||
@@ -103,6 +104,7 @@ export class BunkerSigner {
|
|||||||
|
|
||||||
this.pool = params.pool || new SimplePool()
|
this.pool = params.pool || new SimplePool()
|
||||||
this.secretKey = clientSecretKey
|
this.secretKey = clientSecretKey
|
||||||
|
this.conversationKey = getConversationKey(clientSecretKey, bp.pubkey)
|
||||||
this.bp = bp
|
this.bp = bp
|
||||||
this.isOpen = false
|
this.isOpen = false
|
||||||
this.idPrefix = Math.random().toString(36).substring(7)
|
this.idPrefix = Math.random().toString(36).substring(7)
|
||||||
@@ -112,18 +114,18 @@ export class BunkerSigner {
|
|||||||
|
|
||||||
const listeners = this.listeners
|
const listeners = this.listeners
|
||||||
const waitingForAuth = this.waitingForAuth
|
const waitingForAuth = this.waitingForAuth
|
||||||
const skBytes = this.secretKey
|
const convKey = this.conversationKey
|
||||||
|
|
||||||
this.subCloser = this.pool.subscribeMany(
|
this.subCloser = this.pool.subscribeMany(
|
||||||
this.bp.relays,
|
this.bp.relays,
|
||||||
[{ kinds: [NostrConnect], '#p': [getPublicKey(this.secretKey)] }],
|
[{ kinds: [NostrConnect], authors: [bp.pubkey], '#p': [getPublicKey(this.secretKey)] }],
|
||||||
{
|
{
|
||||||
async onevent(event: NostrEvent) {
|
async onevent(event: NostrEvent) {
|
||||||
let o
|
let o
|
||||||
try {
|
try {
|
||||||
o = JSON.parse(await decrypt(clientSecretKey, event.pubkey, event.content))
|
o = JSON.parse(decrypt(event.content, convKey))
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
o = JSON.parse(nip44decrypt(event.content, getConversationKey(skBytes, event.pubkey)))
|
o = JSON.parse(await legacyDecrypt(event.content, event.pubkey, event.content))
|
||||||
}
|
}
|
||||||
|
|
||||||
const { id, result, error } = o
|
const { id, result, error } = o
|
||||||
@@ -166,7 +168,7 @@ export class BunkerSigner {
|
|||||||
this.serial++
|
this.serial++
|
||||||
const id = `${this.idPrefix}-${this.serial}`
|
const id = `${this.idPrefix}-${this.serial}`
|
||||||
|
|
||||||
const encryptedContent = await encrypt(this.secretKey, this.bp.pubkey, JSON.stringify({ id, method, params }))
|
const encryptedContent = encrypt(JSON.stringify({ id, method, params }), this.conversationKey)
|
||||||
|
|
||||||
// the request event
|
// the request event
|
||||||
const verifiedEvent: VerifiedEvent = finalizeEvent(
|
const verifiedEvent: VerifiedEvent = finalizeEvent(
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"name": "nostr-tools",
|
"name": "nostr-tools",
|
||||||
"version": "2.9.4",
|
"version": "2.10.0",
|
||||||
"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