diff --git a/package.json b/package.json index fa6c675733..51a692f11a 100644 --- a/package.json +++ b/package.json @@ -63,6 +63,7 @@ "lodash.merge": "^4.6.2", "lodash.pick": "^4.4.0", "lodash.snakecase": "^4.1.1", + "nostr-tools": "^2.1.0", "pubsub-js": "^1.9.4", "react": "^18.2.0", "react-confetti": "^6.1.0", diff --git a/src/common/utils/lruCache.ts b/src/common/utils/lruCache.ts new file mode 100644 index 0000000000..1cd96052cd --- /dev/null +++ b/src/common/utils/lruCache.ts @@ -0,0 +1,33 @@ +export class LRUCache { + map = new Map(); + keys: T[] = []; + + constructor(readonly maxSize: number) {} + + has(k: T) { + return this.map.has(k); + } + + get(k: T) { + const v = this.map.get(k); + + if (v !== undefined) { + this.keys.push(k as T); + + if (this.keys.length > this.maxSize * 2) { + this.keys.splice(-this.maxSize); + } + } + + return v; + } + + set(k: T, v: U) { + this.map.set(k, v); + this.keys.push(k); + + if (this.map.size > this.maxSize) { + this.map.delete(this.keys.shift() as T); + } + } +} diff --git a/src/extension/background-script/actions/nostr/nip44DecryptOrPrompt.ts b/src/extension/background-script/actions/nostr/nip44DecryptOrPrompt.ts new file mode 100644 index 0000000000..186ffc37c6 --- /dev/null +++ b/src/extension/background-script/actions/nostr/nip44DecryptOrPrompt.ts @@ -0,0 +1,75 @@ +import { USER_REJECTED_ERROR } from "~/common/constants"; +import utils from "~/common/lib/utils"; +import { getHostFromSender } from "~/common/utils/helpers"; +import { + addPermissionFor, + hasPermissionFor, +} from "~/extension/background-script/permissions"; +import state from "~/extension/background-script/state"; +import { MessageNip44DecryptGet, PermissionMethodNostr, Sender } from "~/types"; + +const nip44DecryptOrPrompt = async ( + message: MessageNip44DecryptGet, + sender: Sender +) => { + const host = getHostFromSender(sender); + if (!host) return; + + try { + const hasPermission = await hasPermissionFor( + PermissionMethodNostr["NOSTR_NIP44DECRYPT"], + host + ); + + if (hasPermission) { + const nostr = await state.getState().getNostr(); + const response = await nostr.nip44Decrypt( + message.args.peer, + message.args.payload + ); + + return { data: response }; + } else { + const promptResponse = await utils.openPrompt<{ + confirm: boolean; + rememberPermission: boolean; + }>({ + ...message, + action: "public/nostr/confirmEncryptOrDecrypt", + args: { + encryptOrDecrypt: { + action: "decrypt", + peer: message.args.peer, + payload: message.args.payload, + }, + }, + }); + + // add permission to db only if user decided to always allow this request + if (promptResponse.data.rememberPermission) { + await addPermissionFor( + PermissionMethodNostr["NOSTR_NIP44DECRYPT"], + host + ); + } + if (promptResponse.data.confirm) { + const nostr = await state.getState().getNostr(); + const response = await nostr.nip44Decrypt( + message.args.peer, + message.args.payload + ); + + return { data: response }; + } else { + return { error: USER_REJECTED_ERROR }; + } + } + } catch (e) { + console.error("decrypt failed", e); + if (e instanceof Error) { + return { error: e.message }; + } + } +}; + +export default nip44DecryptOrPrompt; diff --git a/src/extension/background-script/actions/nostr/nip44EncryptOrPrompt.ts b/src/extension/background-script/actions/nostr/nip44EncryptOrPrompt.ts new file mode 100644 index 0000000000..2a0804aebd --- /dev/null +++ b/src/extension/background-script/actions/nostr/nip44EncryptOrPrompt.ts @@ -0,0 +1,74 @@ +import { USER_REJECTED_ERROR } from "~/common/constants"; +import utils from "~/common/lib/utils"; +import { getHostFromSender } from "~/common/utils/helpers"; +import { + addPermissionFor, + hasPermissionFor, +} from "~/extension/background-script/permissions"; +import state from "~/extension/background-script/state"; +import { MessageNip44EncryptGet, PermissionMethodNostr, Sender } from "~/types"; + +const nip44EncryptOrPrompt = async ( + message: MessageNip44EncryptGet, + sender: Sender +) => { + const host = getHostFromSender(sender); + if (!host) return; + + try { + const hasPermission = await hasPermissionFor( + PermissionMethodNostr["NOSTR_NIP44ENCRYPT"], + host + ); + + if (hasPermission) { + const response = (await state.getState().getNostr()).nip44Encrypt( + message.args.peer, + message.args.plaintext, + message.args.v + ); + return { data: response }; + } else { + const promptResponse = await utils.openPrompt<{ + confirm: boolean; + rememberPermission: boolean; + }>({ + ...message, + action: "public/nostr/confirmEncryptOrDecrypt", + args: { + encryptOrDecrypt: { + action: "encrypt", + peer: message.args.peer, + message: message.args.plaintext, + }, + }, + }); + + // add permission to db only if user decided to always allow this request + if (promptResponse.data.rememberPermission) { + await addPermissionFor( + PermissionMethodNostr["NOSTR_NIP44ENCRYPT"], + host + ); + } + if (promptResponse.data.confirm) { + const response = (await state.getState().getNostr()).nip44Encrypt( + message.args.peer, + message.args.plaintext, + message.args.v + ); + + return { data: response }; + } else { + return { error: USER_REJECTED_ERROR }; + } + } + } catch (e) { + console.error("encrypt failed", e); + if (e instanceof Error) { + return { error: e.message }; + } + } +}; + +export default nip44EncryptOrPrompt; diff --git a/src/extension/background-script/nostr/__test__/nostr.test.ts b/src/extension/background-script/nostr/__test__/nostr.test.ts index 779fd65007..3db5956d9a 100644 --- a/src/extension/background-script/nostr/__test__/nostr.test.ts +++ b/src/extension/background-script/nostr/__test__/nostr.test.ts @@ -18,7 +18,7 @@ const carol = { publicKey: "a8c7d70a7d2e2826ce519a0a490fb953464c9d130235c321282983cd73be333f", }; -describe("nostr", () => { +describe("nostr.nip04", () => { test("encrypt & decrypt", async () => { const aliceNostr = new Nostr(alice.privateKey); @@ -50,3 +50,36 @@ describe("nostr", () => { expect(decrypted).not.toMatch(message); }); }); + +describe("nostr.nip44", () => { + test("encrypt & decrypt", async () => { + const aliceNostr = new Nostr(alice.privateKey); + + const message = "Secret message that is sent from Alice to Bob"; + const encrypted = aliceNostr.nip44Encrypt(bob.publicKey, message); + + const bobNostr = new Nostr(bob.privateKey); + + const decrypted = await bobNostr.nip44Decrypt(alice.publicKey, encrypted); + + expect(decrypted).toMatch(message); + }); + + test("Carol can't decrypt Alice's message for Bob", async () => { + const aliceNostr = new Nostr(alice.privateKey); + + const message = "Secret message that is sent from Alice to Bob"; + const encrypted = aliceNostr.nip44Encrypt(bob.publicKey, message); + + const carolNostr = new Nostr(carol.privateKey); + + let decrypted; + try { + decrypted = await carolNostr.nip44Decrypt(alice.publicKey, encrypted); + } catch (e) { + decrypted = "error decrypting message"; + } + + expect(decrypted).not.toMatch(message); + }); +}); diff --git a/src/extension/background-script/nostr/index.ts b/src/extension/background-script/nostr/index.ts index ef468791b9..f535918319 100644 --- a/src/extension/background-script/nostr/index.ts +++ b/src/extension/background-script/nostr/index.ts @@ -1,20 +1,33 @@ import { schnorr } from "@noble/curves/secp256k1"; import * as secp256k1 from "@noble/secp256k1"; +import { nip44 } from "nostr-tools"; import { Buffer } from "buffer"; import * as CryptoJS from "crypto-js"; import { AES } from "crypto-js"; import Base64 from "crypto-js/enc-base64"; import Hex from "crypto-js/enc-hex"; import Utf8 from "crypto-js/enc-utf8"; +import { LRUCache } from "~/common/utils/lruCache"; import { Event } from "~/extension/providers/nostr/types"; import { getEventHash, signEvent } from "../actions/nostr/helpers"; class Nostr { - privateKey: string; + nip44SharedSecretCache = new LRUCache(100); - constructor(privateKey: string) { - this.privateKey = privateKey; + constructor(readonly privateKey: string) {} + + // Deriving shared secret is an expensive computation + getNip44SharedSecret(pk: string) { + let key = this.nip44SharedSecretCache.get(pk); + + if (!key) { + key = nip44.v2.utils.getConversationKey(this.privateKey, pk); + + this.nip44SharedSecretCache.set(pk, key); + } + + return key; } getPublicKey() { @@ -69,6 +82,18 @@ class Nostr { return Utf8.stringify(decrypted); } + nip44Encrypt(pubkey: string, text: string, v = 2) { + if (v !== 2) { + throw new Error("NIP44: unknown encryption version"); + } + + return nip44.v2.encrypt(text, this.getNip44SharedSecret(pubkey)); + } + + nip44Decrypt(pubkey: string, payload: string) { + return nip44.v2.decrypt(payload, this.getNip44SharedSecret(pubkey)); + } + getEventHash(event: Event) { return getEventHash(event); } diff --git a/src/extension/providers/nostr/index.ts b/src/extension/providers/nostr/index.ts index 2570a8a01f..2bf3c0549e 100644 --- a/src/extension/providers/nostr/index.ts +++ b/src/extension/providers/nostr/index.ts @@ -10,6 +10,7 @@ declare global { export default class NostrProvider extends ProviderBase { nip04 = new Nip04(this); + nip44 = new Nip44(this); constructor() { super("nostr"); @@ -70,3 +71,25 @@ class Nip04 { }); } } + +class Nip44 { + provider: NostrProvider; + + constructor(provider: NostrProvider) { + this.provider = provider; + } + + async encrypt(peer: string, plaintext: string, v: number) { + await this.provider.enable(); + return this.provider.execute("nip44EncryptOrPrompt", { + peer, + plaintext, + v, + }); + } + + async decrypt(peer: string, payload: string) { + await this.provider.enable(); + return this.provider.execute("nip44DecryptOrPrompt", { peer, payload }); + } +} diff --git a/src/i18n/locales/cs/translation.json b/src/i18n/locales/cs/translation.json index f0650f674c..3f67fa2412 100644 --- a/src/i18n/locales/cs/translation.json +++ b/src/i18n/locales/cs/translation.json @@ -864,10 +864,12 @@ "invoice": "Vytvořit novou platební fakturu" }, "nostr": { - "nip04encrypt": "Zašifrovat data", - "getpublickey": "Přečíst svůj veřejný klíč", - "nip04decrypt": "Dešifrovat data", - "signmessage": "Podepsat zprávu klíčem" + "getpublickey": "Přečíst svůj veřejný klíč.", + "nip04decrypt": "Dešifrovat data.", + "nip04encrypt": "Zašifrovat data.", + "nip44decrypt": "Dešifrovat data.", + "nip44encrypt": "Zašifrovat data.", + "signmessage": "Podepsat zprávu klíčem." }, "lnc": { "estimatefee": "Odhadnout sazbu poplatku a celkové poplatky za transakci", diff --git a/src/i18n/locales/da/translation.json b/src/i18n/locales/da/translation.json index f688513941..f262adb4d4 100644 --- a/src/i18n/locales/da/translation.json +++ b/src/i18n/locales/da/translation.json @@ -732,10 +732,12 @@ }, "permissions": { "nostr": { - "getpublickey": "Læs din offentlige nøgle", - "nip04encrypt": "Krypter data", - "nip04decrypt": "De-krypter data", - "signmessage": "Underskriv meddelelse med din nøgle" + "getpublickey": "Læs din offentlige nøgle.", + "nip04decrypt": "De-krypter data.", + "nip04encrypt": "Krypter data.", + "nip44decrypt": "De-krypter data.", + "nip44encrypt": "Krypter data.", + "signmessage": "Underskriv meddelelse med din nøgle." }, "commando": { "bkpr-listbalances": "Liste over alle nuværende og tidligere kontosaldi", diff --git a/src/i18n/locales/de/translation.json b/src/i18n/locales/de/translation.json index df5eab35a4..90b6bd2b49 100644 --- a/src/i18n/locales/de/translation.json +++ b/src/i18n/locales/de/translation.json @@ -1164,10 +1164,12 @@ "settleinvoice": "Begleiche eine akzeptierte Rechnung" }, "nostr": { - "getpublickey": "Lese deinen öffentlichen Schlüssel", - "nip04decrypt": "Daten entschlüsseln", - "nip04encrypt": "Daten verschlüsseln", - "signmessage": "Unterschreibe deine Nachricht mit deinem Schlüssel" + "getpublickey": "Lese deinen öffentlichen Schlüssel.", + "nip04decrypt": "Daten entschlüsseln.", + "nip04encrypt": "Daten verschlüsseln.", + "nip44decrypt": "Daten entschlüsseln.", + "nip44encrypt": "Daten verschlüsseln.", + "signmessage": "Unterschreibe deine Nachricht mit deinem Schlüssel." }, "lnc": { "connectpeer": "Stelle eine Verbindung zu einer Gegenstelle her", diff --git a/src/i18n/locales/en/translation.json b/src/i18n/locales/en/translation.json index 9d29727f7f..034d684941 100644 --- a/src/i18n/locales/en/translation.json +++ b/src/i18n/locales/en/translation.json @@ -1148,12 +1148,6 @@ "webln": { "getbalance": "Read the balance of your account" }, - "nostr": { - "getpublickey": "Read your public key", - "signmessage": "Sign message with your key", - "nip04encrypt": "Encrypt data", - "nip04decrypt": "Decrypt data" - }, "bitcoin": { "getaddress": "Read your Bitcoin receive address" }, @@ -1161,6 +1155,14 @@ "getaddress": "Read your Liquid receive address", "signschnorr": "Sign message with your key" }, + "nostr": { + "getpublickey": "Read your public key.", + "nip04encrypt": "Encrypt data.", + "nip04decrypt": "Decrypt data.", + "nip44encrypt": "Encrypt data.", + "nip44decrypt": "Decrypt data.", + "signmessage": "Sign message with your key." + }, "commando": { "bkpr-listbalances": "List of all current and historical account balances", "checkmessage": "Verify that the signature was generated by a given node", diff --git a/src/i18n/locales/es/translation.json b/src/i18n/locales/es/translation.json index e3675688f5..1b8d839bea 100644 --- a/src/i18n/locales/es/translation.json +++ b/src/i18n/locales/es/translation.json @@ -867,10 +867,12 @@ "feerates": "Devuelve las tarifas que utilizará CLN" }, "nostr": { - "signmessage": "Firma el mensaje con tu clave", - "getpublickey": "Leer tu clave pública", - "nip04encrypt": "Cifrar datos", - "nip04decrypt": "Descifrar datos" + "getpublickey": "Leer tu clave pública.", + "nip04decrypt": "Descifrar datos.", + "nip04encrypt": "Cifrar datos.", + "nip44decrypt": "Descifrar datos.", + "nip44encrypt": "Cifrar datos.", + "signmessage": "Firma el mensaje con tu clave." }, "lnd": { "queryroutes": "Consultar una posible ruta", diff --git a/src/i18n/locales/fa/translation.json b/src/i18n/locales/fa/translation.json index 3a10786620..6495bd5791 100644 --- a/src/i18n/locales/fa/translation.json +++ b/src/i18n/locales/fa/translation.json @@ -1023,10 +1023,12 @@ }, "permissions": { "nostr": { - "getpublickey": "کلید عمومی تان را بخوانید", - "nip04encrypt": "رمزنگاری داده", - "nip04decrypt": "رمزگشایی داده", - "signmessage": "پیام را با کلید خود امضا کنید" + "getpublickey": "کلید عمومی تان را بخوانید.", + "nip04decrypt": "رمزگشایی داده.", + "nip04encrypt": "رمزنگاری داده.", + "nip44decrypt": "رمزگشایی داده.", + "nip44encrypt": "رمزنگاری داده.", + "signmessage": "پیام را با کلید خود امضا کنید." }, "commando": { "bkpr-listbalances": "لیست تمام ترازهای فعلی و قدیمی حساب کاربری", diff --git a/src/i18n/locales/fr/translation.json b/src/i18n/locales/fr/translation.json index fadcfa7140..1a60594b48 100644 --- a/src/i18n/locales/fr/translation.json +++ b/src/i18n/locales/fr/translation.json @@ -738,10 +738,12 @@ }, "permissions": { "nostr": { - "getpublickey": "Lisez votre clé publique", - "nip04encrypt": "Crypter les données", - "nip04decrypt": "Déchiffrer les données", - "signmessage": "Signez le message avec votre clé" + "getpublickey": "Lisez votre clé publique.", + "nip04decrypt": "Déchiffrer les données.", + "nip04encrypt": "Crypter les données.", + "nip44decrypt": "Déchiffrer les données.", + "nip44encrypt": "Crypter les données.", + "signmessage": "Signez le message avec votre clé." }, "commando": { "bkpr-listbalances": "Liste de tous les soldes de compte actuels et historiques", diff --git a/src/i18n/locales/hi/translation.json b/src/i18n/locales/hi/translation.json index 9875ff8247..5ccbcbf322 100644 --- a/src/i18n/locales/hi/translation.json +++ b/src/i18n/locales/hi/translation.json @@ -695,8 +695,10 @@ "permissions": { "nostr": { "getpublickey": "अपनी सार्वजनिक कुंजी पढ़ें।", - "nip04encrypt": "डेटा एन्क्रिप्ट करें।", "nip04decrypt": "डेटा डिक्रिप्ट करें।", + "nip04encrypt": "डेटा एन्क्रिप्ट करें।", + "nip44decrypt": "डेटा डिक्रिप्ट करें।", + "nip44encrypt": "डेटा एन्क्रिप्ट करें।", "signmessage": "अपनी चाबी से संदेश पर हस्ताक्षर करें।" }, "commando": { diff --git a/src/i18n/locales/id/translation.json b/src/i18n/locales/id/translation.json index af809c3c19..a1a7cb6aa7 100644 --- a/src/i18n/locales/id/translation.json +++ b/src/i18n/locales/id/translation.json @@ -835,9 +835,11 @@ }, "permissions": { "nostr": { - "nip04decrypt": "Dekripsi data", - "getpublickey": "Membaca kunci publik Anda", - "nip04encrypt": "Enkripsi data" + "getpublickey": "Membaca kunci publik Anda.", + "nip04decrypt": "Dekripsi data.", + "nip04encrypt": "Enkripsi data.", + "nip44decrypt": "Dekripsi data.", + "nip44encrypt": "Enkripsi data." }, "commando": { "decode": "Decode teks bolt11/bolt12/rune" diff --git a/src/i18n/locales/it/translation.json b/src/i18n/locales/it/translation.json index d8000c5eb3..8559d6fe70 100644 --- a/src/i18n/locales/it/translation.json +++ b/src/i18n/locales/it/translation.json @@ -809,10 +809,12 @@ "addinvoice": "Crea nuove ricevute di pagamento" }, "nostr": { - "nip04decrypt": "Decripta i dati", - "getpublickey": "Leggi la tua chiave pubblica", - "nip04encrypt": "Cripta i dati", - "signmessage": "Firma il messaggio con la tua chiave" + "getpublickey": "Leggi la tua chiave pubblica.", + "nip04decrypt": "Decripta i dati.", + "nip04encrypt": "Cripta i dati.", + "nip44decrypt": "Decripta i dati.", + "nip44encrypt": "Cripta i dati.", + "signmessage": "Firma il messaggio con la tua chiave." } } } diff --git a/src/i18n/locales/mr/translation.json b/src/i18n/locales/mr/translation.json index 74971c920b..3a3398b7ec 100644 --- a/src/i18n/locales/mr/translation.json +++ b/src/i18n/locales/mr/translation.json @@ -755,10 +755,12 @@ }, "permissions": { "nostr": { - "getpublickey": "तुमची सार्वजनिक की वाचा", - "nip04encrypt": "डेटा Encrypt करा", - "nip04decrypt": "डेटा Decrypt करा", - "signmessage": "तुमच्या किल्लीने संदेशावर स्वाक्षरी करा" + "getpublickey": "तुमची सार्वजनिक की वाचा.", + "nip04decrypt": "डेटा Decrypt करा.", + "nip04encrypt": "डेटा Encrypt करा.", + "nip44decrypt": "डेटा Decrypt करा.", + "nip44encrypt": "डेटा Encrypt करा.", + "signmessage": "तुमच्या किल्लीने संदेशावर स्वाक्षरी करा." }, "commando": { "bkpr-listbalances": "सर्व चालू आणि ऐतिहासिक खात्यातील शिल्लकांची यादी", diff --git a/src/i18n/locales/pl/translation.json b/src/i18n/locales/pl/translation.json index 0eb098b7c9..4782394189 100644 --- a/src/i18n/locales/pl/translation.json +++ b/src/i18n/locales/pl/translation.json @@ -793,8 +793,10 @@ "permissions": { "nostr": { "getpublickey": "Czytanie Twojego klucza publicznego.", - "nip04encrypt": "Szyfrowanie danych.", "nip04decrypt": "Deszyfrowanie danych.", + "nip04encrypt": "Szyfrowanie danych.", + "nip44decrypt": "Deszyfrowanie danych.", + "nip44encrypt": "Szyfrowanie danych.", "signmessage": "Podpisywanie wiadomości Twoim kluczem." }, "commando": { diff --git a/src/i18n/locales/pt_BR/translation.json b/src/i18n/locales/pt_BR/translation.json index a6f071ef58..df93dc7bba 100644 --- a/src/i18n/locales/pt_BR/translation.json +++ b/src/i18n/locales/pt_BR/translation.json @@ -1088,7 +1088,9 @@ "getpublickey": "Ler sua chave pública", "signmessage": "Assinar mensagem com sua chave", "nip04decrypt": "Descriptografar dados", - "nip04encrypt": "Criptografar dados" + "nip04encrypt": "Criptografar dados", + "nip44decrypt": "Descriptografar dados", + "nip44encrypt": "Criptografar dados" }, "lnc": { "openchannel": "" diff --git a/src/i18n/locales/ru/translation.json b/src/i18n/locales/ru/translation.json index ca3fc10de0..aa68f53d08 100644 --- a/src/i18n/locales/ru/translation.json +++ b/src/i18n/locales/ru/translation.json @@ -743,8 +743,10 @@ "permissions": { "nostr": { "getpublickey": "", - "nip04encrypt": "", "nip04decrypt": "", + "nip04encrypt": "", + "nip44decrypt": "", + "nip44encrypt": "", "signmessage": "" }, "commando": { diff --git a/src/i18n/locales/sl/translation.json b/src/i18n/locales/sl/translation.json index 2ba2170667..0d6d28dc3e 100644 --- a/src/i18n/locales/sl/translation.json +++ b/src/i18n/locales/sl/translation.json @@ -671,8 +671,10 @@ }, "nostr": { "nip04encrypt": "Kriptiraj podatke", + "nip44encrypt": "Kriptiraj podatke", "signmessage": "Podpiši sporočilo s svojim ključem", "nip04decrypt": "Dekriptiraj podatke", + "nip44decrypt": "Dekriptiraj podatke", "getpublickey": "Bere tvoj javni ključ" }, "webln": { diff --git a/src/i18n/locales/sv/translation.json b/src/i18n/locales/sv/translation.json index fdf2a45f7e..089c944ae5 100644 --- a/src/i18n/locales/sv/translation.json +++ b/src/i18n/locales/sv/translation.json @@ -1111,10 +1111,12 @@ }, "permissions": { "nostr": { - "nip04decrypt": "Dekryptera data", - "getpublickey": "Läs din publika nyckel", - "signmessage": "Skriv under meddelandet med din nyckel", - "nip04encrypt": "Kryptera data" + "getpublickey": "Läs din publika nyckel.", + "nip04decrypt": "Dekryptera data.", + "nip04encrypt": "Kryptera data.", + "nip44decrypt": "Dekryptera data.", + "nip44encrypt": "Kryptera data.", + "signmessage": "Skriv under meddelandet med din nyckel." }, "lnd": { "channelbalance": "Få en rapport om de totala medlen över alla öppna kanaler", diff --git a/src/i18n/locales/th/translation.json b/src/i18n/locales/th/translation.json index 6a6f1a5971..99c126fcf4 100644 --- a/src/i18n/locales/th/translation.json +++ b/src/i18n/locales/th/translation.json @@ -813,6 +813,8 @@ "signmessage": "เซ็นข้อความด้วย key ของคุณ", "nip04encrypt": "เข้ารหัสข้อมูล", "nip04decrypt": "ถอดรหัสข้อมูล", + "nip44encrypt": "เข้ารหัสข้อมูล", + "nip44decrypt": "ถอดรหัสข้อมูล", "getpublickey": "แสดง public key ของคุณ" }, "commando": { diff --git a/src/i18n/locales/uk/translation.json b/src/i18n/locales/uk/translation.json index 876691ddd5..babf7ad938 100644 --- a/src/i18n/locales/uk/translation.json +++ b/src/i18n/locales/uk/translation.json @@ -733,8 +733,10 @@ "permissions": { "nostr": { "getpublickey": "", - "nip04encrypt": "", "nip04decrypt": "", + "nip04encrypt": "", + "nip44decrypt": "", + "nip44encrypt": "", "signmessage": "" }, "commando": { diff --git a/src/i18n/locales/zh_Hans/translation.json b/src/i18n/locales/zh_Hans/translation.json index c06c581608..fbb3431c5c 100644 --- a/src/i18n/locales/zh_Hans/translation.json +++ b/src/i18n/locales/zh_Hans/translation.json @@ -1013,10 +1013,12 @@ }, "permissions": { "nostr": { - "signmessage": "使用你的密钥签署消息", - "nip04decrypt": "解密数据", - "nip04encrypt": "加密数据", - "getpublickey": "读取你的公钥" + "getpublickey": "读取你的公钥。", + "nip04decrypt": "解密数据。", + "nip04encrypt": "加密数据。", + "nip44decrypt": "解密数据。", + "nip44encrypt": "加密数据。", + "signmessage": "使用你的密钥签署消息。" }, "commando": { "bkpr-listbalances": "所有当前和历史帐户余额列表", diff --git a/src/i18n/locales/zh_Hant/translation.json b/src/i18n/locales/zh_Hant/translation.json index 76856b84d5..6826f784c9 100644 --- a/src/i18n/locales/zh_Hant/translation.json +++ b/src/i18n/locales/zh_Hant/translation.json @@ -1020,10 +1020,12 @@ }, "permissions": { "nostr": { - "getpublickey": "讀取你的公鑰", - "nip04encrypt": "加密數據", - "nip04decrypt": "解密數據", - "signmessage": "用你的密鑰簽署消息" + "getpublickey": "讀取你的公鑰。", + "nip04decrypt": "解密數據。", + "nip04encrypt": "加密數據。", + "nip44decrypt": "解密數據。", + "nip44encrypt": "加密數據。", + "signmessage": "用你的密鑰簽署消息。" }, "commando": { "bkpr-listbalances": "所有當前和歷史帳戶餘額列表", diff --git a/src/types.ts b/src/types.ts index 66626e6002..7b1d775645 100644 --- a/src/types.ts +++ b/src/types.ts @@ -561,6 +561,23 @@ export interface MessageDecryptGet extends MessageDefault { action: "decrypt"; } +export interface MessageNip44EncryptGet extends MessageDefault { + args: { + peer: string; + plaintext: string; + v: 2; + }; + action: "encrypt"; +} + +export interface MessageNip44DecryptGet extends MessageDefault { + args: { + peer: string; + payload: string; + }; + action: "decrypt"; +} + export interface MessageSignPsbt extends MessageDefault { args: { psbt: string; @@ -770,6 +787,8 @@ export enum PermissionMethodNostr { NOSTR_GETPUBLICKEY = "nostr/getPublicKey", NOSTR_NIP04DECRYPT = "nostr/nip04decrypt", NOSTR_NIP04ENCRYPT = "nostr/nip04encrypt", + NOSTR_NIP44DECRYPT = "nostr/nip44decrypt", + NOSTR_NIP44ENCRYPT = "nostr/nip44encrypt", } export interface DbPermission { diff --git a/yarn.lock b/yarn.lock index 8d6a01111a..287a2fef66 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1064,12 +1064,19 @@ dependencies: "@noble/hashes" "1.3.1" +"@noble/curves@1.2.0": + version "1.2.0" + resolved "https://registry.yarnpkg.com/@noble/curves/-/curves-1.2.0.tgz#92d7e12e4e49b23105a2555c6984d41733d65c35" + integrity sha512-oYclrNgRaM9SsBUBVbb8M6DTV7ZHRTKugureoYEncY5c65HOmRzvSiTE3y5CYaPYJA/GVkrhXEoF0M3Ya9PMnw== + dependencies: + "@noble/hashes" "1.3.2" + "@noble/hashes@1.3.1", "@noble/hashes@~1.3.0", "@noble/hashes@~1.3.1": version "1.3.1" - resolved "https://registry.npmjs.org/@noble/hashes/-/hashes-1.3.1.tgz" + resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-1.3.1.tgz#8831ef002114670c603c458ab8b11328406953a9" integrity sha512-EbqwksQwz9xDRGfDST86whPBgM65E0OH/pCgqW0GBVzO22bNE+NuIbeTb714+IfSjU3aRk47EUvXIb5bTsenKA== -"@noble/hashes@^1.1.5": +"@noble/hashes@1.3.2", "@noble/hashes@^1.1.5": version "1.3.2" resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-1.3.2.tgz#6f26dbc8fbc7205873ce3cee2f690eba0d421b39" integrity sha512-MVC8EAQp7MvEcm30KWENFjgR+Mkmf+D189XJTkFIlwohU5hcBbn1ZkKq7KVTi2Hme3PMGF390DaL52beVrIihQ== @@ -6979,6 +6986,11 @@ minimist@^1.2.0, minimist@^1.2.6: resolved "https://registry.npmjs.org/minimist/-/minimist-1.2.6.tgz" integrity sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q== +mitata@^0.1.6: + version "0.1.6" + resolved "https://registry.yarnpkg.com/mitata/-/mitata-0.1.6.tgz#0d25f0dd105d6c50ec8d9047ee21bed1552fbffd" + integrity sha512-VKQ0r3jriTOU9E2Z+mwbZrUmbg4Li4QyFfi7kfHKl6reZhGzL0AYlu3wE0VPXzIwA5xnFzmEQoBwCcNT8stUkA== + mitt@3.0.1: version "3.0.1" resolved "https://registry.npmjs.org/mitt/-/mitt-3.0.1.tgz" @@ -7163,6 +7175,25 @@ nostr-tools@^1.17.0: "@scure/bip32" "1.3.1" "@scure/bip39" "1.2.1" +nostr-tools@^2.1.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/nostr-tools/-/nostr-tools-2.1.0.tgz#74e655c31fd03457352cd319a7404048ca9bc674" + integrity sha512-LY5y3/BWaqtfySOhG+NSY3mAt+vUw4vQVFjqvawtO6SdEHqvWdNsb2uUqYdyBztFcIKFxoAbGMntbXQ9QO22oA== + dependencies: + "@noble/ciphers" "0.2.0" + "@noble/curves" "1.2.0" + "@noble/hashes" "1.3.1" + "@scure/base" "1.1.1" + "@scure/bip32" "1.3.1" + "@scure/bip39" "1.2.1" + mitata "^0.1.6" + nostr-wasm v0.1.0 + +nostr-wasm@v0.1.0: + version "0.1.0" + resolved "https://registry.yarnpkg.com/nostr-wasm/-/nostr-wasm-0.1.0.tgz#17af486745feb2b7dd29503fdd81613a24058d94" + integrity sha512-78BTryCLcLYv96ONU8Ws3Q1JzjlAt+43pWQhIl86xZmWeegYCNLPml7yQ+gG3vR6V5h4XGj+TxO+SS5dsThQIA== + npm-run-path@^4.0.1: version "4.0.1" resolved "https://registry.npmjs.org/npm-run-path/-/npm-run-path-4.0.1.tgz"