mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-11-08 22:02:54 +00:00
Refine NIP-46 decryption to use conversation keys
This commit is contained in:
1 parent
d1a197e5d1
commit
c0e2fa3324
2 files changed
+122
-74
No files matched your search
@@ -54,3 +54,30 @@ test("Nip46RpcClient encrypts payloads with nip44 conversation keys", async () =
|
||||
"client should decrypt ciphertext produced by nostr-tools",
|
||||
);
|
||||
});
|
||||
|
||||
test("decryptNip46PayloadWithKeys handles nip44.v2 ciphertext", async () => {
|
||||
const nostrTools = await loadNostrTools();
|
||||
const { generateSecretKey, getPublicKey, nip44, utils } = nostrTools;
|
||||
|
||||
const clientSecret = utils.bytesToHex(generateSecretKey());
|
||||
const remoteSecret = utils.bytesToHex(generateSecretKey());
|
||||
const remotePubkey = getPublicKey(remoteSecret);
|
||||
|
||||
const serialized = JSON.stringify(PAYLOAD);
|
||||
const conversationKey =
|
||||
typeof nip44.v2.getConversationKey === "function"
|
||||
? nip44.v2.getConversationKey(clientSecret, remotePubkey)
|
||||
: nip44.v2.utils.getConversationKey(clientSecret, remotePubkey);
|
||||
const ciphertext = nip44.v2.encrypt(serialized, conversationKey);
|
||||
|
||||
const { __testExports } = await import("../js/nostr.js");
|
||||
const { decryptNip46PayloadWithKeys } = __testExports;
|
||||
|
||||
const roundTrip = await decryptNip46PayloadWithKeys(
|
||||
clientSecret,
|
||||
remotePubkey,
|
||||
ciphertext,
|
||||
);
|
||||
|
||||
assert.equal(roundTrip, serialized, "helper should decrypt nip44.v2 ciphertext");
|
||||
});
|
||||
Reference in new issue
Block a user