@openzeppelin/miden-multisig-client 0.17.0-rc.2 → 0.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (278) hide show
  1. package/README.md +172 -47
  2. package/dist/account/builder.d.ts +2 -2
  3. package/dist/account/builder.d.ts.map +1 -1
  4. package/dist/account/builder.js +49 -24
  5. package/dist/account/builder.js.map +1 -1
  6. package/dist/connectivity.d.ts +2 -0
  7. package/dist/connectivity.d.ts.map +1 -1
  8. package/dist/connectivity.js +7 -4
  9. package/dist/connectivity.js.map +1 -1
  10. package/dist/index.d.ts +8 -1
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +7 -1
  13. package/dist/index.js.map +1 -1
  14. package/dist/multisig/authArgErrors.d.ts +59 -0
  15. package/dist/multisig/authArgErrors.d.ts.map +1 -0
  16. package/dist/multisig/authArgErrors.js +115 -0
  17. package/dist/multisig/authArgErrors.js.map +1 -0
  18. package/dist/multisig/helpers.d.ts +5 -0
  19. package/dist/multisig/helpers.d.ts.map +1 -1
  20. package/dist/multisig/helpers.js +7 -2
  21. package/dist/multisig/helpers.js.map +1 -1
  22. package/dist/multisig.d.ts +140 -0
  23. package/dist/multisig.d.ts.map +1 -1
  24. package/dist/multisig.js +419 -12
  25. package/dist/multisig.js.map +1 -1
  26. package/dist/procedures.d.ts +1 -1
  27. package/dist/procedures.js +1 -1
  28. package/dist/recovery/proposalNoteImport.d.ts +173 -0
  29. package/dist/recovery/proposalNoteImport.d.ts.map +1 -0
  30. package/dist/recovery/proposalNoteImport.js +411 -0
  31. package/dist/recovery/proposalNoteImport.js.map +1 -0
  32. package/dist/recovery/publicNoteBackfill.d.ts +168 -0
  33. package/dist/recovery/publicNoteBackfill.d.ts.map +1 -0
  34. package/dist/recovery/publicNoteBackfill.js +368 -0
  35. package/dist/recovery/publicNoteBackfill.js.map +1 -0
  36. package/dist/recovery/recoverNotes.d.ts +147 -0
  37. package/dist/recovery/recoverNotes.d.ts.map +1 -0
  38. package/dist/recovery/recoverNotes.js +163 -0
  39. package/dist/recovery/recoverNotes.js.map +1 -0
  40. package/dist/recovery/transportDrain.d.ts +124 -0
  41. package/dist/recovery/transportDrain.d.ts.map +1 -0
  42. package/dist/recovery/transportDrain.js +262 -0
  43. package/dist/recovery/transportDrain.js.map +1 -0
  44. package/dist/transaction/consumeNotes.d.ts.map +1 -1
  45. package/dist/transaction/consumeNotes.js +4 -1
  46. package/dist/transaction/consumeNotes.js.map +1 -1
  47. package/dist/transaction/p2id.d.ts.map +1 -1
  48. package/dist/transaction/p2id.js +4 -1
  49. package/dist/transaction/p2id.js.map +1 -1
  50. package/dist/transaction/summary.d.ts +10 -4
  51. package/dist/transaction/summary.d.ts.map +1 -1
  52. package/dist/transaction/summary.js +13 -7
  53. package/dist/transaction/summary.js.map +1 -1
  54. package/dist/transaction/updateGuardian.js +4 -1
  55. package/dist/transaction/updateGuardian.js.map +1 -1
  56. package/dist/transaction/updateProcedureThreshold.js +4 -1
  57. package/dist/transaction/updateProcedureThreshold.js.map +1 -1
  58. package/dist/transaction/updateSigners.js +4 -1
  59. package/dist/transaction/updateSigners.js.map +1 -1
  60. package/dist/transaction.d.ts +1 -1
  61. package/dist/transaction.d.ts.map +1 -1
  62. package/dist/transaction.js +1 -1
  63. package/dist/transaction.js.map +1 -1
  64. package/package.json +14 -10
  65. package/src/account/builder.ts +87 -35
  66. package/src/connectivity.ts +9 -4
  67. package/src/index.ts +34 -1
  68. package/src/multisig/authArgErrors.ts +138 -0
  69. package/src/multisig/helpers.ts +7 -2
  70. package/src/multisig.ts +513 -20
  71. package/src/procedures.ts +1 -1
  72. package/src/recovery/proposalNoteImport.ts +548 -0
  73. package/src/recovery/publicNoteBackfill.ts +502 -0
  74. package/src/recovery/recoverNotes.ts +288 -0
  75. package/src/recovery/transportDrain.ts +330 -0
  76. package/src/transaction/consumeNotes.ts +4 -1
  77. package/src/transaction/p2id.ts +4 -1
  78. package/src/transaction/summary.ts +13 -7
  79. package/src/transaction/updateGuardian.ts +4 -1
  80. package/src/transaction/updateProcedureThreshold.ts +4 -1
  81. package/src/transaction/updateSigners.ts +4 -1
  82. package/src/transaction.ts +1 -1
  83. package/dist/account/builder.test.d.ts +0 -2
  84. package/dist/account/builder.test.d.ts.map +0 -1
  85. package/dist/account/builder.test.js +0 -166
  86. package/dist/account/builder.test.js.map +0 -1
  87. package/dist/account/masm/account-components/auth.d.ts +0 -2
  88. package/dist/account/masm/account-components/auth.d.ts.map +0 -1
  89. package/dist/account/masm/account-components/auth.js +0 -46
  90. package/dist/account/masm/account-components/auth.js.map +0 -1
  91. package/dist/account/masm/index.d.ts +0 -2
  92. package/dist/account/masm/index.d.ts.map +0 -1
  93. package/dist/account/masm/index.js +0 -4
  94. package/dist/account/masm/index.js.map +0 -1
  95. package/dist/account/masm.d.ts +0 -2
  96. package/dist/account/masm.d.ts.map +0 -1
  97. package/dist/account/masm.js +0 -4
  98. package/dist/account/masm.js.map +0 -1
  99. package/dist/account/storage.test.d.ts +0 -2
  100. package/dist/account/storage.test.d.ts.map +0 -1
  101. package/dist/account/storage.test.js +0 -73
  102. package/dist/account/storage.test.js.map +0 -1
  103. package/dist/client.test.d.ts +0 -2
  104. package/dist/client.test.d.ts.map +0 -1
  105. package/dist/client.test.js +0 -380
  106. package/dist/client.test.js.map +0 -1
  107. package/dist/connectivity.test.d.ts +0 -2
  108. package/dist/connectivity.test.d.ts.map +0 -1
  109. package/dist/connectivity.test.js +0 -61
  110. package/dist/connectivity.test.js.map +0 -1
  111. package/dist/inspector.test.d.ts +0 -2
  112. package/dist/inspector.test.d.ts.map +0 -1
  113. package/dist/inspector.test.js +0 -425
  114. package/dist/inspector.test.js.map +0 -1
  115. package/dist/lookupAuth.test.d.ts +0 -2
  116. package/dist/lookupAuth.test.d.ts.map +0 -1
  117. package/dist/lookupAuth.test.js +0 -138
  118. package/dist/lookupAuth.test.js.map +0 -1
  119. package/dist/multisig/consumeNotesErrors.test.d.ts +0 -2
  120. package/dist/multisig/consumeNotesErrors.test.d.ts.map +0 -1
  121. package/dist/multisig/consumeNotesErrors.test.js +0 -28
  122. package/dist/multisig/consumeNotesErrors.test.js.map +0 -1
  123. package/dist/multisig/helpers.test.d.ts +0 -2
  124. package/dist/multisig/helpers.test.d.ts.map +0 -1
  125. package/dist/multisig/helpers.test.js +0 -94
  126. package/dist/multisig/helpers.test.js.map +0 -1
  127. package/dist/multisig.test.d.ts +0 -2
  128. package/dist/multisig.test.d.ts.map +0 -1
  129. package/dist/multisig.test.js +0 -4112
  130. package/dist/multisig.test.js.map +0 -1
  131. package/dist/proposal/factory.test.d.ts +0 -2
  132. package/dist/proposal/factory.test.d.ts.map +0 -1
  133. package/dist/proposal/factory.test.js +0 -32
  134. package/dist/proposal/factory.test.js.map +0 -1
  135. package/dist/proposal/metadata.test.d.ts +0 -2
  136. package/dist/proposal/metadata.test.d.ts.map +0 -1
  137. package/dist/proposal/metadata.test.js +0 -193
  138. package/dist/proposal/metadata.test.js.map +0 -1
  139. package/dist/prover/config.test.d.ts +0 -2
  140. package/dist/prover/config.test.d.ts.map +0 -1
  141. package/dist/prover/config.test.js +0 -54
  142. package/dist/prover/config.test.js.map +0 -1
  143. package/dist/prover/errors.test.d.ts +0 -2
  144. package/dist/prover/errors.test.d.ts.map +0 -1
  145. package/dist/prover/errors.test.js +0 -29
  146. package/dist/prover/errors.test.js.map +0 -1
  147. package/dist/prover/retry.test.d.ts +0 -2
  148. package/dist/prover/retry.test.d.ts.map +0 -1
  149. package/dist/prover/retry.test.js +0 -20
  150. package/dist/prover/retry.test.js.map +0 -1
  151. package/dist/prover/workflow.test.d.ts +0 -2
  152. package/dist/prover/workflow.test.d.ts.map +0 -1
  153. package/dist/prover/workflow.test.js +0 -105
  154. package/dist/prover/workflow.test.js.map +0 -1
  155. package/dist/raw-client.test.d.ts +0 -2
  156. package/dist/raw-client.test.d.ts.map +0 -1
  157. package/dist/raw-client.test.js +0 -111
  158. package/dist/raw-client.test.js.map +0 -1
  159. package/dist/rpc/config.test.d.ts +0 -2
  160. package/dist/rpc/config.test.d.ts.map +0 -1
  161. package/dist/rpc/config.test.js +0 -24
  162. package/dist/rpc/config.test.js.map +0 -1
  163. package/dist/rpc/errors.test.d.ts +0 -2
  164. package/dist/rpc/errors.test.d.ts.map +0 -1
  165. package/dist/rpc/errors.test.js +0 -34
  166. package/dist/rpc/errors.test.js.map +0 -1
  167. package/dist/rpc/retry.test.d.ts +0 -2
  168. package/dist/rpc/retry.test.d.ts.map +0 -1
  169. package/dist/rpc/retry.test.js +0 -98
  170. package/dist/rpc/retry.test.js.map +0 -1
  171. package/dist/signers/ecdsa.test.d.ts +0 -2
  172. package/dist/signers/ecdsa.test.d.ts.map +0 -1
  173. package/dist/signers/ecdsa.test.js +0 -88
  174. package/dist/signers/ecdsa.test.js.map +0 -1
  175. package/dist/signers/falcon.test.d.ts +0 -2
  176. package/dist/signers/falcon.test.d.ts.map +0 -1
  177. package/dist/signers/falcon.test.js +0 -161
  178. package/dist/signers/falcon.test.js.map +0 -1
  179. package/dist/signers/miden-wallet.ecdsa-recovery.test.d.ts +0 -2
  180. package/dist/signers/miden-wallet.ecdsa-recovery.test.d.ts.map +0 -1
  181. package/dist/signers/miden-wallet.ecdsa-recovery.test.js +0 -148
  182. package/dist/signers/miden-wallet.ecdsa-recovery.test.js.map +0 -1
  183. package/dist/signers/miden-wallet.test.d.ts +0 -2
  184. package/dist/signers/miden-wallet.test.d.ts.map +0 -1
  185. package/dist/signers/miden-wallet.test.js +0 -164
  186. package/dist/signers/miden-wallet.test.js.map +0 -1
  187. package/dist/signers/para.test.d.ts +0 -2
  188. package/dist/signers/para.test.d.ts.map +0 -1
  189. package/dist/signers/para.test.js +0 -146
  190. package/dist/signers/para.test.js.map +0 -1
  191. package/dist/transaction/index.d.ts +0 -8
  192. package/dist/transaction/index.d.ts.map +0 -1
  193. package/dist/transaction/index.js +0 -7
  194. package/dist/transaction/index.js.map +0 -1
  195. package/dist/transaction/p2id.test.d.ts +0 -2
  196. package/dist/transaction/p2id.test.d.ts.map +0 -1
  197. package/dist/transaction/p2id.test.js +0 -246
  198. package/dist/transaction/p2id.test.js.map +0 -1
  199. package/dist/transaction/rpoRandomCoin.test.d.ts +0 -2
  200. package/dist/transaction/rpoRandomCoin.test.d.ts.map +0 -1
  201. package/dist/transaction/rpoRandomCoin.test.js +0 -52
  202. package/dist/transaction/rpoRandomCoin.test.js.map +0 -1
  203. package/dist/transaction/summary.test.d.ts +0 -2
  204. package/dist/transaction/summary.test.d.ts.map +0 -1
  205. package/dist/transaction/summary.test.js +0 -26
  206. package/dist/transaction/summary.test.js.map +0 -1
  207. package/dist/transaction.test.d.ts +0 -2
  208. package/dist/transaction.test.d.ts.map +0 -1
  209. package/dist/transaction.test.js +0 -122
  210. package/dist/transaction.test.js.map +0 -1
  211. package/dist/types/proposal.test.d.ts +0 -2
  212. package/dist/types/proposal.test.d.ts.map +0 -1
  213. package/dist/types/proposal.test.js +0 -56
  214. package/dist/types/proposal.test.js.map +0 -1
  215. package/dist/utils/digest.test.d.ts +0 -2
  216. package/dist/utils/digest.test.d.ts.map +0 -1
  217. package/dist/utils/digest.test.js +0 -48
  218. package/dist/utils/digest.test.js.map +0 -1
  219. package/dist/utils/ecdsa.test.d.ts +0 -2
  220. package/dist/utils/ecdsa.test.d.ts.map +0 -1
  221. package/dist/utils/ecdsa.test.js +0 -131
  222. package/dist/utils/ecdsa.test.js.map +0 -1
  223. package/dist/utils/encoding.test.d.ts +0 -2
  224. package/dist/utils/encoding.test.d.ts.map +0 -1
  225. package/dist/utils/encoding.test.js +0 -185
  226. package/dist/utils/encoding.test.js.map +0 -1
  227. package/dist/utils/key.test.d.ts +0 -2
  228. package/dist/utils/key.test.d.ts.map +0 -1
  229. package/dist/utils/key.test.js +0 -82
  230. package/dist/utils/key.test.js.map +0 -1
  231. package/dist/utils/signature.test.d.ts +0 -2
  232. package/dist/utils/signature.test.d.ts.map +0 -1
  233. package/dist/utils/signature.test.js +0 -164
  234. package/dist/utils/signature.test.js.map +0 -1
  235. package/dist/utils/word.test.d.ts +0 -2
  236. package/dist/utils/word.test.d.ts.map +0 -1
  237. package/dist/utils/word.test.js +0 -54
  238. package/dist/utils/word.test.js.map +0 -1
  239. package/masm/account_components/auth/guarded_multisig.masm +0 -42
  240. package/src/account/builder.test.ts +0 -238
  241. package/src/account/masm/account-components/auth.ts +0 -46
  242. package/src/account/masm/index.ts +0 -4
  243. package/src/account/masm.ts +0 -4
  244. package/src/account/storage.test.ts +0 -90
  245. package/src/client.test.ts +0 -473
  246. package/src/connectivity.test.ts +0 -67
  247. package/src/inspector.test.ts +0 -542
  248. package/src/lookupAuth.test.ts +0 -185
  249. package/src/multisig/consumeNotesErrors.test.ts +0 -43
  250. package/src/multisig/helpers.test.ts +0 -114
  251. package/src/multisig.test.ts +0 -5008
  252. package/src/proposal/factory.test.ts +0 -40
  253. package/src/proposal/metadata.test.ts +0 -235
  254. package/src/prover/config.test.ts +0 -90
  255. package/src/prover/errors.test.ts +0 -61
  256. package/src/prover/retry.test.ts +0 -38
  257. package/src/prover/workflow.test.ts +0 -145
  258. package/src/raw-client.test.ts +0 -171
  259. package/src/rpc/config.test.ts +0 -45
  260. package/src/rpc/errors.test.ts +0 -69
  261. package/src/rpc/retry.test.ts +0 -144
  262. package/src/signers/ecdsa.test.ts +0 -111
  263. package/src/signers/falcon.test.ts +0 -197
  264. package/src/signers/miden-wallet.ecdsa-recovery.test.ts +0 -201
  265. package/src/signers/miden-wallet.test.ts +0 -206
  266. package/src/signers/para.test.ts +0 -186
  267. package/src/transaction/index.ts +0 -13
  268. package/src/transaction/p2id.test.ts +0 -371
  269. package/src/transaction/rpoRandomCoin.test.ts +0 -64
  270. package/src/transaction/summary.test.ts +0 -32
  271. package/src/transaction.test.ts +0 -142
  272. package/src/types/proposal.test.ts +0 -68
  273. package/src/utils/digest.test.ts +0 -55
  274. package/src/utils/ecdsa.test.ts +0 -164
  275. package/src/utils/encoding.test.ts +0 -233
  276. package/src/utils/key.test.ts +0 -91
  277. package/src/utils/signature.test.ts +0 -210
  278. package/src/utils/word.test.ts +0 -64
@@ -1,185 +0,0 @@
1
- import { describe, it, expect, vi, beforeEach } from 'vitest';
2
-
3
- // The Miden SDK is wasm-bound and is mocked across this test suite (matching
4
- // the pattern in transaction.test.ts, multisig.test.ts, etc.). We cannot run
5
- // real RPO256 here, but we CAN verify the lookup-digest function builds the
6
- // FeltArray sequence in the right order and chunking convention. Cross-language
7
- // parity against `crates/shared/tests/fixtures/lookup_auth_vectors.json` is
8
- // intentionally a separate runner — see `runRealSdkParity` below for the gated
9
- // hook.
10
-
11
- interface FakeFelt {
12
- __felt: true;
13
- value: bigint;
14
- }
15
-
16
- interface FakeWord {
17
- __word: true;
18
- felts: FakeFelt[];
19
- toFelts: () => FakeFelt[];
20
- toHex: () => string;
21
- }
22
-
23
- const hashCalls: { input: FakeFelt[] }[] = [];
24
-
25
- vi.mock('@miden-sdk/miden-sdk', () => {
26
- const Felt = vi.fn().mockImplementation((value: bigint) => ({
27
- __felt: true,
28
- value,
29
- }));
30
-
31
- const FeltArray = vi.fn().mockImplementation((felts: FakeFelt[]) => felts);
32
-
33
- const makeWord = (felts: FakeFelt[], hex = '0xMOCKED'): FakeWord => ({
34
- __word: true,
35
- felts,
36
- toFelts: () => felts,
37
- toHex: () => hex,
38
- });
39
-
40
- const Word = {
41
- fromHex: vi.fn().mockImplementation((hex: string) => {
42
- // Deterministic four-felt decomposition: split hex into 4 8-byte pieces.
43
- // The values are not real Word semantics, but they let us assert the
44
- // implementation passes them through in order.
45
- const stripped = hex.startsWith('0x') ? hex.slice(2) : hex;
46
- const padded = stripped.padStart(64, '0');
47
- const felts: FakeFelt[] = [];
48
- for (let i = 0; i < 4; i += 1) {
49
- const piece = padded.slice(i * 16, (i + 1) * 16);
50
- felts.push({ __felt: true, value: BigInt('0x' + piece) });
51
- }
52
- return makeWord(felts, hex);
53
- }),
54
- };
55
-
56
- const Rpo256 = {
57
- hashElements: vi.fn().mockImplementation((felts: FakeFelt[]) => {
58
- hashCalls.push({ input: [...felts] });
59
- // Synthesize a fake digest: 4 felts derived from the input length and
60
- // first felt's value, so each call's output is distinguishable.
61
- const seed = felts.length === 0 ? 0n : felts[0].value;
62
- return makeWord(
63
- [
64
- { __felt: true, value: seed ^ BigInt(felts.length) },
65
- { __felt: true, value: seed + 1n },
66
- { __felt: true, value: seed + 2n },
67
- { __felt: true, value: seed + 3n },
68
- ],
69
- '0xfakehash',
70
- );
71
- }),
72
- };
73
-
74
- return { Felt, FeltArray, Rpo256, Word };
75
- });
76
-
77
- const DOMAIN_TAG_BYTES = new TextEncoder().encode('guardian.lookup.v1');
78
-
79
- function bytesToExpectedFelts(bytes: Uint8Array): bigint[] {
80
- const out: bigint[] = [];
81
- for (let offset = 0; offset < bytes.length; offset += 8) {
82
- let value = 0n;
83
- for (let i = 0; i < 8; i += 1) {
84
- const byte = offset + i < bytes.length ? bytes[offset + i] : 0;
85
- value |= BigInt(byte) << BigInt(8 * i);
86
- }
87
- out.push(value);
88
- }
89
- return out;
90
- }
91
-
92
- let lookupAuthDigest: typeof import('./lookupAuth.js').lookupAuthDigest;
93
- let _resetLookupDomainTagCacheForTesting: typeof import('./lookupAuth.js')._resetLookupDomainTagCacheForTesting;
94
-
95
- beforeEach(async () => {
96
- hashCalls.length = 0;
97
- // Re-import to pick up a fresh cached domain tag per test, in addition to
98
- // the explicit reset, so test ordering does not change behavior.
99
- const mod = await import('./lookupAuth.js');
100
- lookupAuthDigest = mod.lookupAuthDigest;
101
- _resetLookupDomainTagCacheForTesting = mod._resetLookupDomainTagCacheForTesting;
102
- _resetLookupDomainTagCacheForTesting();
103
- });
104
-
105
- describe('lookupAuthDigest', () => {
106
- it('hashes the domain-tag bytes via the same 8-byte LE chunking as Rust', () => {
107
- const keyCommitmentHex = '0x' + 'aa'.repeat(32);
108
- lookupAuthDigest(1_700_000_000_000, keyCommitmentHex);
109
-
110
- // First Rpo256.hashElements call must be the domain-tag computation
111
- // (3 felts for "guardian.lookup.v1" — 18 bytes → ceil(18/8) = 3 chunks).
112
- expect(hashCalls.length).toBeGreaterThanOrEqual(2);
113
- const tagCall = hashCalls[0];
114
- const expected = bytesToExpectedFelts(DOMAIN_TAG_BYTES);
115
- expect(tagCall.input).toHaveLength(expected.length);
116
- expect(tagCall.input.length).toBe(3);
117
- for (let i = 0; i < expected.length; i += 1) {
118
- expect(tagCall.input[i].value).toBe(expected[i]);
119
- }
120
- });
121
-
122
- it('caches the domain-tag computation across calls', () => {
123
- const keyCommitmentHex = '0x' + 'bb'.repeat(32);
124
- lookupAuthDigest(1_700_000_000_000, keyCommitmentHex);
125
- const callsAfterFirst = hashCalls.length;
126
- lookupAuthDigest(1_700_000_000_001, keyCommitmentHex);
127
- const callsAfterSecond = hashCalls.length;
128
-
129
- // Second invocation should perform exactly one Rpo256.hashElements call
130
- // (the message hash); the domain-tag hash is cached.
131
- expect(callsAfterSecond - callsAfterFirst).toBe(1);
132
- });
133
-
134
- it('passes 9 felts in [tag, timestamp, key_commitment] order to the message hash', () => {
135
- const keyCommitmentHex = '0x' + '01'.repeat(32);
136
- const timestamp = 1_700_000_000_000n;
137
- lookupAuthDigest(timestamp, keyCommitmentHex);
138
-
139
- const messageCall = hashCalls[hashCalls.length - 1];
140
- expect(messageCall.input).toHaveLength(9);
141
-
142
- // Felt 4 is the timestamp, reinterpreted as u64 (no change for positive).
143
- expect(messageCall.input[4].value).toBe(timestamp);
144
-
145
- // Felts 5..8 are the key-commitment felts, derived deterministically by
146
- // the mocked Word.fromHex from the hex representation.
147
- const expectedKcWord = '01'.repeat(32);
148
- for (let i = 0; i < 4; i += 1) {
149
- const piece = expectedKcWord.slice(i * 16, (i + 1) * 16);
150
- expect(messageCall.input[5 + i].value).toBe(BigInt('0x' + piece));
151
- }
152
- });
153
-
154
- it('reinterprets a negative timestamp via two-complement u64 cast', () => {
155
- const keyCommitmentHex = '0x' + 'cc'.repeat(32);
156
- lookupAuthDigest(-1, keyCommitmentHex);
157
-
158
- const messageCall = hashCalls[hashCalls.length - 1];
159
- // -1 casts to u64 0xFFFFFFFFFFFFFFFF, then reduces mod the Goldilocks prime
160
- // (matching Rust `felt_from_u64_reduced`): 0xFFFFFFFFFFFFFFFF - (2^64 - 2^32 + 1) = 0xFFFFFFFE.
161
- expect(messageCall.input[4].value).toBe(0xFFFFFFFEn);
162
- });
163
-
164
- it('produces distinct digest inputs for distinct commitments', () => {
165
- lookupAuthDigest(1_700_000_000_000, '0x' + '01'.repeat(32));
166
- lookupAuthDigest(1_700_000_000_000, '0x' + '02'.repeat(32));
167
-
168
- // Call 0 is the cached domain-tag hash. Calls 1 and 2 are the two message
169
- // hashes; the second call hits the domain-tag cache so it does not produce
170
- // an extra hash call.
171
- const messageCallA = hashCalls[1];
172
- const messageCallB = hashCalls[2];
173
- expect(messageCallA.input[5].value).not.toBe(messageCallB.input[5].value);
174
- });
175
-
176
- it('produces distinct digest inputs for distinct timestamps', () => {
177
- const keyCommitmentHex = '0x' + '01'.repeat(32);
178
- lookupAuthDigest(1_700_000_000_000, keyCommitmentHex);
179
- lookupAuthDigest(1_700_000_000_001, keyCommitmentHex);
180
-
181
- const messageCallA = hashCalls[1];
182
- const messageCallB = hashCalls[2];
183
- expect(messageCallA.input[4].value).not.toBe(messageCallB.input[4].value);
184
- });
185
- });
@@ -1,43 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import {
3
- ConsumeNotesMetadataOversizeError,
4
- LegacyConsumeNotesNoteMissingError,
5
- NoteBindingMismatchError,
6
- UnsupportedMetadataVersionError,
7
- } from './consumeNotesErrors.js';
8
-
9
- describe('consume_notes error taxonomy (issue #229)', () => {
10
- it('pins stable codes identical to the Rust SDK', () => {
11
- expect(new NoteBindingMismatchError('x').code).toBe('consume_notes_note_binding_mismatch');
12
- expect(new UnsupportedMetadataVersionError(99).code).toBe(
13
- 'consume_notes_unsupported_metadata_version',
14
- );
15
- expect(new ConsumeNotesMetadataOversizeError(1, 2).code).toBe(
16
- 'consume_notes_metadata_oversize',
17
- );
18
- expect(new LegacyConsumeNotesNoteMissingError('0xabc').code).toBe(
19
- 'consume_notes_legacy_note_missing',
20
- );
21
- });
22
-
23
- it('preserves structured error fields for programmatic branching', () => {
24
- const oversize = new ConsumeNotesMetadataOversizeError(262_144, 300_000);
25
- expect(oversize.limit).toBe(262_144);
26
- expect(oversize.actual).toBe(300_000);
27
-
28
- const missing = new LegacyConsumeNotesNoteMissingError('0xnoteid');
29
- expect(missing.noteId).toBe('0xnoteid');
30
-
31
- const unsupported = new UnsupportedMetadataVersionError(99);
32
- expect(unsupported.found).toBe(99);
33
- const absent = new UnsupportedMetadataVersionError(undefined);
34
- expect(absent.found).toBeUndefined();
35
- });
36
-
37
- it('extends Error so instanceof Error and instanceof <subclass> both work', () => {
38
- const err = new NoteBindingMismatchError('boom');
39
- expect(err).toBeInstanceOf(Error);
40
- expect(err).toBeInstanceOf(NoteBindingMismatchError);
41
- expect(err.name).toBe('NoteBindingMismatchError');
42
- });
43
- });
@@ -1,114 +0,0 @@
1
- import { describe, it, expect, vi, beforeEach } from 'vitest';
2
- import { computeCommitmentFromTxSummary, accountIdToHex } from './helpers.js';
3
-
4
- vi.mock('@miden-sdk/miden-sdk', () => ({
5
- Account: {},
6
- TransactionSummary: {
7
- deserialize: vi.fn((bytes: Uint8Array) => ({
8
- toCommitment: () => ({
9
- toHex: () => '0x' + 'c'.repeat(64),
10
- }),
11
- })),
12
- },
13
- Word: {},
14
- }));
15
-
16
- describe('multisig helpers', () => {
17
- beforeEach(() => {
18
- vi.clearAllMocks();
19
- });
20
-
21
- describe('computeCommitmentFromTxSummary', () => {
22
- it('computes commitment from base64 tx summary', async () => {
23
- const base64 = btoa(String.fromCharCode(...new Uint8Array([1, 2, 3])));
24
- const commitment = computeCommitmentFromTxSummary(base64);
25
-
26
- expect(commitment).toBe('0x' + 'c'.repeat(64));
27
- });
28
-
29
- it('deserializes the tx summary bytes', async () => {
30
- const { TransactionSummary } = await import('@miden-sdk/miden-sdk');
31
- const base64 = btoa(String.fromCharCode(...new Uint8Array([4, 5, 6])));
32
-
33
- computeCommitmentFromTxSummary(base64);
34
-
35
- expect(TransactionSummary.deserialize).toHaveBeenCalledWith(
36
- new Uint8Array([4, 5, 6])
37
- );
38
- });
39
-
40
- it('returns hex string with 0x prefix', () => {
41
- const base64 = btoa(String.fromCharCode(...new Uint8Array([1])));
42
- const commitment = computeCommitmentFromTxSummary(base64);
43
-
44
- expect(commitment.startsWith('0x')).toBe(true);
45
- });
46
- });
47
-
48
- describe('accountIdToHex', () => {
49
- it('returns account ID string if already hex formatted', () => {
50
- const mockAccount = {
51
- id: () => ({
52
- toString: () => '0xabc123',
53
- prefix: () => ({ asInt: () => BigInt(1) }),
54
- suffix: () => ({ asInt: () => BigInt(2) }),
55
- }),
56
- };
57
-
58
- const hex = accountIdToHex(mockAccount as any);
59
- expect(hex).toBe('0xabc123');
60
- });
61
-
62
- it('handles 0X prefix', () => {
63
- const mockAccount = {
64
- id: () => ({
65
- toString: () => '0Xabc123',
66
- prefix: () => ({ asInt: () => BigInt(1) }),
67
- suffix: () => ({ asInt: () => BigInt(2) }),
68
- }),
69
- };
70
-
71
- const hex = accountIdToHex(mockAccount as any);
72
- expect(hex).toBe('0Xabc123');
73
- });
74
-
75
- it('constructs hex from prefix and suffix if no 0x prefix', () => {
76
- const mockAccount = {
77
- id: () => ({
78
- toString: () => 'not-a-hex',
79
- prefix: () => ({ asInt: () => BigInt('0x0102030405060708') }),
80
- suffix: () => ({ asInt: () => BigInt('0x0a0b0c0d0e0f1011') }),
81
- }),
82
- };
83
-
84
- const hex = accountIdToHex(mockAccount as any);
85
- expect(hex).toBe('0x01020304050607080a0b0c0d0e0f10');
86
- });
87
-
88
- it('pads prefix to 16 hex characters', () => {
89
- const mockAccount = {
90
- id: () => ({
91
- toString: () => 'not-a-hex',
92
- prefix: () => ({ asInt: () => BigInt(1) }),
93
- suffix: () => ({ asInt: () => BigInt(0) }),
94
- }),
95
- };
96
-
97
- const hex = accountIdToHex(mockAccount as any);
98
- expect(hex).toBe('0x000000000000000100000000000000');
99
- });
100
-
101
- it('produces 30-character hex (excluding 0x prefix)', () => {
102
- const mockAccount = {
103
- id: () => ({
104
- toString: () => 'not-a-hex',
105
- prefix: () => ({ asInt: () => BigInt('0xffffffffffffffff') }),
106
- suffix: () => ({ asInt: () => BigInt('0xffffffffffffffff') }),
107
- }),
108
- };
109
-
110
- const hex = accountIdToHex(mockAccount as any);
111
- expect(hex.length).toBe(32);
112
- });
113
- });
114
- });