diff --git a/js/nostr/nip46Client.js b/js/nostr/nip46Client.js index e4270d4d..893d25b5 100644 --- a/js/nostr/nip46Client.js +++ b/js/nostr/nip46Client.js @@ -762,11 +762,11 @@ export function resolveNip46Relays(relays, fallbackRelays = []) { function resolveNip44V2ConversationKeyGetter(tools) { if (typeof tools?.nip44?.v2?.getConversationKey === "function") { - return tools.nip44.v2.getConversationKey.bind(tools.nip44.v2); + return tools.nip44.v2.getConversationKey; } if (typeof tools?.nip44?.v2?.utils?.getConversationKey === "function") { - return tools.nip44.v2.utils.getConversationKey.bind(tools.nip44.v2.utils); + return tools.nip44.v2.utils.getConversationKey; } return null; @@ -774,11 +774,11 @@ function resolveNip44V2ConversationKeyGetter(tools) { function resolveLegacyNip44ConversationKeyGetter(tools) { if (typeof tools?.nip44?.getConversationKey === "function") { - return tools.nip44.getConversationKey.bind(tools.nip44); + return tools.nip44.getConversationKey; } if (typeof tools?.nip44?.utils?.getConversationKey === "function") { - return tools.nip44.utils.getConversationKey.bind(tools.nip44.utils); + return tools.nip44.utils.getConversationKey; } return null; @@ -1054,18 +1054,16 @@ function resolveAvailableNip46Ciphers( typeof nip44v2GetConversationKey === "function" ) { registerCipher("nip44.v2", () => { - // nostr-tools v2 `getConversationKey(priv, pub)` expects: - // priv: Uint8Array (private key bytes) - // pub: string (public key hex string, which it prefixes with '02' and converts) - const privKeyInput = - typeof privateKey === "string" && tools?.utils?.hexToBytes - ? tools.utils.hexToBytes(privateKey) - : privateKey; + let privKeyBytes = privateKey; + if (typeof privateKey === "string") { + if (typeof tools?.utils?.hexToBytes === "function") { + privKeyBytes = tools.utils.hexToBytes(privateKey); + } else if (typeof tools?.hexToBytes === "function") { + privKeyBytes = tools.hexToBytes(privateKey); + } + } - // Keep remotePubkey as string if it is one, otherwise pass as is (e.g. if already bytes, though v2 expects string) - const pubKeyInput = remotePubkey; - - const conversationKey = nip44v2GetConversationKey(privKeyInput, pubKeyInput); + const conversationKey = nip44v2GetConversationKey(privKeyBytes, remotePubkey); if (!conversationKey) { throw new Error("Failed to derive a nip44 conversation key for remote signing."); @@ -1089,7 +1087,16 @@ function resolveAvailableNip46Ciphers( typeof nip44GetConversationKey === "function" ) { registerCipher("nip44", () => { - const conversationKey = nip44GetConversationKey(privateKey, remotePubkey); + let privKeyBytes = privateKey; + if (typeof privateKey === "string") { + if (typeof tools?.utils?.hexToBytes === "function") { + privKeyBytes = tools.utils.hexToBytes(privateKey); + } else if (typeof tools?.hexToBytes === "function") { + privKeyBytes = tools.hexToBytes(privateKey); + } + } + + const conversationKey = nip44GetConversationKey(privKeyBytes, remotePubkey); if (!conversationKey) { throw new Error("Failed to derive a nip44 conversation key for remote signing."); @@ -2071,10 +2078,10 @@ export class Nip46RpcClient { decrypt: (pubkey, ciphertext, options) => this.nip44Decrypt(pubkey, ciphertext, options), }, - nip04Encrypt: (pubkey, plaintext, options) => - this.nip04Encrypt(pubkey, plaintext, options), - nip04Decrypt: (pubkey, ciphertext, options) => - this.nip04Decrypt(pubkey, ciphertext, options), + nip44Encrypt: (pubkey, plaintext, options) => + this.nip44Encrypt(pubkey, plaintext, options), + nip44Decrypt: (pubkey, ciphertext, options) => + this.nip44Decrypt(pubkey, ciphertext, options), nip44Encrypt: (pubkey, plaintext, options) => this.nip44Encrypt(pubkey, plaintext, options), nip44Decrypt: (pubkey, ciphertext, options) => diff --git a/test-audit/flakiness-matrix.json b/test-audit/flakiness-matrix.json index ce8e9a63..56a16be2 100644 --- a/test-audit/flakiness-matrix.json +++ b/test-audit/flakiness-matrix.json @@ -3,21 +3,21 @@ "iteration": 1, "passed": false, "code": 1, - "duration": 945, + "duration": 1025, "failure": "Suite failed" }, { "iteration": 2, "passed": false, "code": 1, - "duration": 903, + "duration": 965, "failure": "Suite failed" }, { "iteration": 3, "passed": false, "code": 1, - "duration": 978, + "duration": 988, "failure": "Suite failed" } ] \ No newline at end of file diff --git a/tests/minimal-webtorrent.test.mjs b/tests/minimal-webtorrent.test.mjs index da2601c4..b62aa18b 100644 --- a/tests/minimal-webtorrent.test.mjs +++ b/tests/minimal-webtorrent.test.mjs @@ -1,8 +1,7 @@ import test from "node:test"; +import assert from "node:assert"; import WebTorrent from "../js/webtorrent.min.js"; test("can import WebTorrent", () => { - if (typeof WebTorrent !== "function") { - throw new Error("Import failed"); - } + assert.strictEqual(typeof WebTorrent, "function", "WebTorrent should be a function"); }); diff --git a/tests/ui/components/debug_hashtag_strip_helper.test.mjs b/tests/ui/components/debug_hashtag_strip_helper.test.mjs index 8546fa57..eac4a870 100644 --- a/tests/ui/components/debug_hashtag_strip_helper.test.mjs +++ b/tests/ui/components/debug_hashtag_strip_helper.test.mjs @@ -34,10 +34,16 @@ test("Debug HashtagStripHelper fallback", (t) => { const container = document.getElementById("container"); const helper = new HashtagStripHelper({ window, document }); + assert.ok(helper, "HashtagStripHelper instance created"); console.log("Helper window ResizeObserver:", typeof helper.window.ResizeObserver); - helper.mount(container); - // Need to update with tags to trigger render and observer setup - helper.update([{ tags: [["t", "test"]] }]); + assert.doesNotThrow(() => { + helper.mount(container); + }, "mount() should not throw"); + + assert.doesNotThrow(() => { + // Need to update with tags to trigger render and observer setup + helper.update([{ tags: [["t", "test"]] }]); + }, "update() should not throw"); });