Skip to content

Commit 2f389fa

Browse files
vveerrggclaude
andcommitted
fix: update test mocks for @noble/curves/secp256k1 schnorr functions
Add mock for @noble/curves/secp256k1 module to match the Schnorr signing migration. Tests now correctly mock schnorr.sign/verify instead of the old ECDSA secp256k1.sign/verify. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent a5be14d commit 2f389fa

1 file changed

Lines changed: 33 additions & 18 deletions

File tree

src/__tests__/index.test.ts

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,8 @@
44

55
// Mock dependencies
66
vi.mock("@noble/secp256k1", () => {
7-
const TEST_PRIVATE_KEY =
8-
"27e2a04464f4e73b9131548b6dffbe47ae49ec7a7562c5a157e6a30f9f1ceb69";
97
const TEST_PUBLIC_KEY =
108
"02030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f2021";
11-
let lastSignedMessage = "";
129

1310
return {
1411
getPublicKey: () => new Uint8Array(hexToBytes(TEST_PUBLIC_KEY)),
@@ -23,22 +20,40 @@ vi.mock("@noble/secp256k1", () => {
2320
),
2421
isValidPrivateKey: () => true,
2522
},
26-
sign: (msg: Uint8Array) => {
27-
lastSignedMessage = Array.from(msg)
28-
.map((b) => String.fromCharCode(b))
29-
.join("");
30-
return { toCompactRawBytes: () => new Uint8Array([1, 2, 3, 4]) };
31-
},
32-
verify: (sig: Uint8Array, msg: Uint8Array, pub: Uint8Array) => {
33-
const msgStr = Array.from(msg)
34-
.map((b) => String.fromCharCode(b))
35-
.join("");
36-
return msgStr === lastSignedMessage;
23+
};
24+
});
25+
26+
vi.mock("@noble/curves/secp256k1", () => {
27+
let lastSignedHash = "";
28+
29+
return {
30+
schnorr: {
31+
sign: (msgHash: string | Uint8Array, _privKey: Uint8Array) => {
32+
lastSignedHash =
33+
typeof msgHash === "string"
34+
? msgHash
35+
: Array.from(msgHash)
36+
.map((b) => b.toString(16).padStart(2, "0"))
37+
.join("");
38+
return new Uint8Array(64).fill(1);
39+
},
40+
verify: (
41+
_sig: Uint8Array,
42+
msgHash: string | Uint8Array,
43+
_pubKey: Uint8Array,
44+
) => {
45+
const currentHash =
46+
typeof msgHash === "string"
47+
? msgHash
48+
: Array.from(msgHash)
49+
.map((b) => b.toString(16).padStart(2, "0"))
50+
.join("");
51+
return currentHash === lastSignedHash;
52+
},
53+
getPublicKey: () => new Uint8Array(32).fill(2),
3754
},
38-
Signature: {
39-
fromCompact: () => ({
40-
toCompactRawBytes: () => new Uint8Array([1, 2, 3, 4]),
41-
}),
55+
secp256k1: {
56+
getSharedSecret: () => new Uint8Array(33).fill(3),
4257
},
4358
};
4459
});

0 commit comments

Comments
 (0)