diff --git a/src/extension/background-script/actions/nostr/decryptOrPrompt.ts b/src/extension/background-script/actions/nostr/decryptOrPrompt.ts index b6e0e54136..516af85da4 100644 --- a/src/extension/background-script/actions/nostr/decryptOrPrompt.ts +++ b/src/extension/background-script/actions/nostr/decryptOrPrompt.ts @@ -20,7 +20,7 @@ const decryptOrPrompt = async (message: MessageDecryptGet, sender: Sender) => { if (hasPermission) { const nostr = await state.getState().getNostr(); - const response = await nostr.decrypt( + const response = await nostr.nip04Decrypt( message.args.peer, message.args.ciphertext ); @@ -44,7 +44,7 @@ const decryptOrPrompt = async (message: MessageDecryptGet, sender: Sender) => { } if (promptResponse.data.confirm) { const nostr = await state.getState().getNostr(); - const response = await nostr.decrypt( + const response = await nostr.nip04Decrypt( message.args.peer, message.args.ciphertext ); diff --git a/src/extension/background-script/actions/nostr/encryptOrPrompt.ts b/src/extension/background-script/actions/nostr/encryptOrPrompt.ts index 2eb7800697..3bb45f6454 100644 --- a/src/extension/background-script/actions/nostr/encryptOrPrompt.ts +++ b/src/extension/background-script/actions/nostr/encryptOrPrompt.ts @@ -20,7 +20,8 @@ const encryptOrPrompt = async (message: MessageEncryptGet, sender: Sender) => { ); if (hasPermission) { - const response = (await state.getState().getNostr()).encrypt( + const nostr = await state.getState().getNostr(); + const response = await nostr.nip04Encrypt( message.args.peer, message.args.plaintext ); @@ -48,7 +49,8 @@ const encryptOrPrompt = async (message: MessageEncryptGet, sender: Sender) => { ); } if (promptResponse.data.confirm) { - const response = (await state.getState().getNostr()).encrypt( + const nostr = await state.getState().getNostr(); + const response = await nostr.nip04Encrypt( message.args.peer, message.args.plaintext ); diff --git a/src/extension/background-script/nostr/__test__/nostr.test.ts b/src/extension/background-script/nostr/__test__/nostr.test.ts index 3db5956d9a..2a21e7d7e4 100644 --- a/src/extension/background-script/nostr/__test__/nostr.test.ts +++ b/src/extension/background-script/nostr/__test__/nostr.test.ts @@ -23,11 +23,11 @@ describe("nostr.nip04", () => { const aliceNostr = new Nostr(alice.privateKey); const message = "Secret message that is sent from Alice to Bob"; - const encrypted = aliceNostr.encrypt(bob.publicKey, message); + const encrypted = aliceNostr.nip04Encrypt(bob.publicKey, message); const bobNostr = new Nostr(bob.privateKey); - const decrypted = await bobNostr.decrypt(alice.publicKey, encrypted); + const decrypted = await bobNostr.nip04Decrypt(alice.publicKey, encrypted); expect(decrypted).toMatch(message); }); @@ -36,13 +36,13 @@ describe("nostr.nip04", () => { const aliceNostr = new Nostr(alice.privateKey); const message = "Secret message that is sent from Alice to Bob"; - const encrypted = aliceNostr.encrypt(bob.publicKey, message); + const encrypted = aliceNostr.nip04Encrypt(bob.publicKey, message); const carolNostr = new Nostr(carol.privateKey); let decrypted; try { - decrypted = await carolNostr.decrypt(alice.publicKey, encrypted); + decrypted = await carolNostr.nip04Decrypt(alice.publicKey, encrypted); } catch (e) { decrypted = "error decrypting message"; } diff --git a/src/extension/background-script/nostr/index.ts b/src/extension/background-script/nostr/index.ts index 867177f579..566794f336 100644 --- a/src/extension/background-script/nostr/index.ts +++ b/src/extension/background-script/nostr/index.ts @@ -53,7 +53,7 @@ class Nostr { return signedHex; } - encrypt(pubkey: string, text: string) { + nip04Encrypt(pubkey: string, text: string) { const key = secp256k1.getSharedSecret(this.privateKey, "02" + pubkey); const normalizedKey = Buffer.from(key.slice(1, 33)); const hexNormalizedKey = secp256k1.etc.bytesToHex(normalizedKey); @@ -68,7 +68,7 @@ class Nostr { )}`; } - async decrypt(pubkey: string, ciphertext: string) { + async nip04Decrypt(pubkey: string, ciphertext: string) { const [cip, iv] = ciphertext.split("?iv="); const key = secp256k1.getSharedSecret(this.privateKey, "02" + pubkey); const normalizedKey = Buffer.from(key.slice(1, 33));