@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.
- package/README.md +172 -47
- package/dist/account/builder.d.ts +2 -2
- package/dist/account/builder.d.ts.map +1 -1
- package/dist/account/builder.js +49 -24
- package/dist/account/builder.js.map +1 -1
- package/dist/connectivity.d.ts +2 -0
- package/dist/connectivity.d.ts.map +1 -1
- package/dist/connectivity.js +7 -4
- package/dist/connectivity.js.map +1 -1
- package/dist/index.d.ts +8 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -1
- package/dist/index.js.map +1 -1
- package/dist/multisig/authArgErrors.d.ts +59 -0
- package/dist/multisig/authArgErrors.d.ts.map +1 -0
- package/dist/multisig/authArgErrors.js +115 -0
- package/dist/multisig/authArgErrors.js.map +1 -0
- package/dist/multisig/helpers.d.ts +5 -0
- package/dist/multisig/helpers.d.ts.map +1 -1
- package/dist/multisig/helpers.js +7 -2
- package/dist/multisig/helpers.js.map +1 -1
- package/dist/multisig.d.ts +140 -0
- package/dist/multisig.d.ts.map +1 -1
- package/dist/multisig.js +419 -12
- package/dist/multisig.js.map +1 -1
- package/dist/procedures.d.ts +1 -1
- package/dist/procedures.js +1 -1
- package/dist/recovery/proposalNoteImport.d.ts +173 -0
- package/dist/recovery/proposalNoteImport.d.ts.map +1 -0
- package/dist/recovery/proposalNoteImport.js +411 -0
- package/dist/recovery/proposalNoteImport.js.map +1 -0
- package/dist/recovery/publicNoteBackfill.d.ts +168 -0
- package/dist/recovery/publicNoteBackfill.d.ts.map +1 -0
- package/dist/recovery/publicNoteBackfill.js +368 -0
- package/dist/recovery/publicNoteBackfill.js.map +1 -0
- package/dist/recovery/recoverNotes.d.ts +147 -0
- package/dist/recovery/recoverNotes.d.ts.map +1 -0
- package/dist/recovery/recoverNotes.js +163 -0
- package/dist/recovery/recoverNotes.js.map +1 -0
- package/dist/recovery/transportDrain.d.ts +124 -0
- package/dist/recovery/transportDrain.d.ts.map +1 -0
- package/dist/recovery/transportDrain.js +262 -0
- package/dist/recovery/transportDrain.js.map +1 -0
- package/dist/transaction/consumeNotes.d.ts.map +1 -1
- package/dist/transaction/consumeNotes.js +4 -1
- package/dist/transaction/consumeNotes.js.map +1 -1
- package/dist/transaction/p2id.d.ts.map +1 -1
- package/dist/transaction/p2id.js +4 -1
- package/dist/transaction/p2id.js.map +1 -1
- package/dist/transaction/summary.d.ts +10 -4
- package/dist/transaction/summary.d.ts.map +1 -1
- package/dist/transaction/summary.js +13 -7
- package/dist/transaction/summary.js.map +1 -1
- package/dist/transaction/updateGuardian.js +4 -1
- package/dist/transaction/updateGuardian.js.map +1 -1
- package/dist/transaction/updateProcedureThreshold.js +4 -1
- package/dist/transaction/updateProcedureThreshold.js.map +1 -1
- package/dist/transaction/updateSigners.js +4 -1
- package/dist/transaction/updateSigners.js.map +1 -1
- package/dist/transaction.d.ts +1 -1
- package/dist/transaction.d.ts.map +1 -1
- package/dist/transaction.js +1 -1
- package/dist/transaction.js.map +1 -1
- package/package.json +14 -10
- package/src/account/builder.ts +87 -35
- package/src/connectivity.ts +9 -4
- package/src/index.ts +34 -1
- package/src/multisig/authArgErrors.ts +138 -0
- package/src/multisig/helpers.ts +7 -2
- package/src/multisig.ts +513 -20
- package/src/procedures.ts +1 -1
- package/src/recovery/proposalNoteImport.ts +548 -0
- package/src/recovery/publicNoteBackfill.ts +502 -0
- package/src/recovery/recoverNotes.ts +288 -0
- package/src/recovery/transportDrain.ts +330 -0
- package/src/transaction/consumeNotes.ts +4 -1
- package/src/transaction/p2id.ts +4 -1
- package/src/transaction/summary.ts +13 -7
- package/src/transaction/updateGuardian.ts +4 -1
- package/src/transaction/updateProcedureThreshold.ts +4 -1
- package/src/transaction/updateSigners.ts +4 -1
- package/src/transaction.ts +1 -1
- package/dist/account/builder.test.d.ts +0 -2
- package/dist/account/builder.test.d.ts.map +0 -1
- package/dist/account/builder.test.js +0 -166
- package/dist/account/builder.test.js.map +0 -1
- package/dist/account/masm/account-components/auth.d.ts +0 -2
- package/dist/account/masm/account-components/auth.d.ts.map +0 -1
- package/dist/account/masm/account-components/auth.js +0 -46
- package/dist/account/masm/account-components/auth.js.map +0 -1
- package/dist/account/masm/index.d.ts +0 -2
- package/dist/account/masm/index.d.ts.map +0 -1
- package/dist/account/masm/index.js +0 -4
- package/dist/account/masm/index.js.map +0 -1
- package/dist/account/masm.d.ts +0 -2
- package/dist/account/masm.d.ts.map +0 -1
- package/dist/account/masm.js +0 -4
- package/dist/account/masm.js.map +0 -1
- package/dist/account/storage.test.d.ts +0 -2
- package/dist/account/storage.test.d.ts.map +0 -1
- package/dist/account/storage.test.js +0 -73
- package/dist/account/storage.test.js.map +0 -1
- package/dist/client.test.d.ts +0 -2
- package/dist/client.test.d.ts.map +0 -1
- package/dist/client.test.js +0 -380
- package/dist/client.test.js.map +0 -1
- package/dist/connectivity.test.d.ts +0 -2
- package/dist/connectivity.test.d.ts.map +0 -1
- package/dist/connectivity.test.js +0 -61
- package/dist/connectivity.test.js.map +0 -1
- package/dist/inspector.test.d.ts +0 -2
- package/dist/inspector.test.d.ts.map +0 -1
- package/dist/inspector.test.js +0 -425
- package/dist/inspector.test.js.map +0 -1
- package/dist/lookupAuth.test.d.ts +0 -2
- package/dist/lookupAuth.test.d.ts.map +0 -1
- package/dist/lookupAuth.test.js +0 -138
- package/dist/lookupAuth.test.js.map +0 -1
- package/dist/multisig/consumeNotesErrors.test.d.ts +0 -2
- package/dist/multisig/consumeNotesErrors.test.d.ts.map +0 -1
- package/dist/multisig/consumeNotesErrors.test.js +0 -28
- package/dist/multisig/consumeNotesErrors.test.js.map +0 -1
- package/dist/multisig/helpers.test.d.ts +0 -2
- package/dist/multisig/helpers.test.d.ts.map +0 -1
- package/dist/multisig/helpers.test.js +0 -94
- package/dist/multisig/helpers.test.js.map +0 -1
- package/dist/multisig.test.d.ts +0 -2
- package/dist/multisig.test.d.ts.map +0 -1
- package/dist/multisig.test.js +0 -4112
- package/dist/multisig.test.js.map +0 -1
- package/dist/proposal/factory.test.d.ts +0 -2
- package/dist/proposal/factory.test.d.ts.map +0 -1
- package/dist/proposal/factory.test.js +0 -32
- package/dist/proposal/factory.test.js.map +0 -1
- package/dist/proposal/metadata.test.d.ts +0 -2
- package/dist/proposal/metadata.test.d.ts.map +0 -1
- package/dist/proposal/metadata.test.js +0 -193
- package/dist/proposal/metadata.test.js.map +0 -1
- package/dist/prover/config.test.d.ts +0 -2
- package/dist/prover/config.test.d.ts.map +0 -1
- package/dist/prover/config.test.js +0 -54
- package/dist/prover/config.test.js.map +0 -1
- package/dist/prover/errors.test.d.ts +0 -2
- package/dist/prover/errors.test.d.ts.map +0 -1
- package/dist/prover/errors.test.js +0 -29
- package/dist/prover/errors.test.js.map +0 -1
- package/dist/prover/retry.test.d.ts +0 -2
- package/dist/prover/retry.test.d.ts.map +0 -1
- package/dist/prover/retry.test.js +0 -20
- package/dist/prover/retry.test.js.map +0 -1
- package/dist/prover/workflow.test.d.ts +0 -2
- package/dist/prover/workflow.test.d.ts.map +0 -1
- package/dist/prover/workflow.test.js +0 -105
- package/dist/prover/workflow.test.js.map +0 -1
- package/dist/raw-client.test.d.ts +0 -2
- package/dist/raw-client.test.d.ts.map +0 -1
- package/dist/raw-client.test.js +0 -111
- package/dist/raw-client.test.js.map +0 -1
- package/dist/rpc/config.test.d.ts +0 -2
- package/dist/rpc/config.test.d.ts.map +0 -1
- package/dist/rpc/config.test.js +0 -24
- package/dist/rpc/config.test.js.map +0 -1
- package/dist/rpc/errors.test.d.ts +0 -2
- package/dist/rpc/errors.test.d.ts.map +0 -1
- package/dist/rpc/errors.test.js +0 -34
- package/dist/rpc/errors.test.js.map +0 -1
- package/dist/rpc/retry.test.d.ts +0 -2
- package/dist/rpc/retry.test.d.ts.map +0 -1
- package/dist/rpc/retry.test.js +0 -98
- package/dist/rpc/retry.test.js.map +0 -1
- package/dist/signers/ecdsa.test.d.ts +0 -2
- package/dist/signers/ecdsa.test.d.ts.map +0 -1
- package/dist/signers/ecdsa.test.js +0 -88
- package/dist/signers/ecdsa.test.js.map +0 -1
- package/dist/signers/falcon.test.d.ts +0 -2
- package/dist/signers/falcon.test.d.ts.map +0 -1
- package/dist/signers/falcon.test.js +0 -161
- package/dist/signers/falcon.test.js.map +0 -1
- package/dist/signers/miden-wallet.ecdsa-recovery.test.d.ts +0 -2
- package/dist/signers/miden-wallet.ecdsa-recovery.test.d.ts.map +0 -1
- package/dist/signers/miden-wallet.ecdsa-recovery.test.js +0 -148
- package/dist/signers/miden-wallet.ecdsa-recovery.test.js.map +0 -1
- package/dist/signers/miden-wallet.test.d.ts +0 -2
- package/dist/signers/miden-wallet.test.d.ts.map +0 -1
- package/dist/signers/miden-wallet.test.js +0 -164
- package/dist/signers/miden-wallet.test.js.map +0 -1
- package/dist/signers/para.test.d.ts +0 -2
- package/dist/signers/para.test.d.ts.map +0 -1
- package/dist/signers/para.test.js +0 -146
- package/dist/signers/para.test.js.map +0 -1
- package/dist/transaction/index.d.ts +0 -8
- package/dist/transaction/index.d.ts.map +0 -1
- package/dist/transaction/index.js +0 -7
- package/dist/transaction/index.js.map +0 -1
- package/dist/transaction/p2id.test.d.ts +0 -2
- package/dist/transaction/p2id.test.d.ts.map +0 -1
- package/dist/transaction/p2id.test.js +0 -246
- package/dist/transaction/p2id.test.js.map +0 -1
- package/dist/transaction/rpoRandomCoin.test.d.ts +0 -2
- package/dist/transaction/rpoRandomCoin.test.d.ts.map +0 -1
- package/dist/transaction/rpoRandomCoin.test.js +0 -52
- package/dist/transaction/rpoRandomCoin.test.js.map +0 -1
- package/dist/transaction/summary.test.d.ts +0 -2
- package/dist/transaction/summary.test.d.ts.map +0 -1
- package/dist/transaction/summary.test.js +0 -26
- package/dist/transaction/summary.test.js.map +0 -1
- package/dist/transaction.test.d.ts +0 -2
- package/dist/transaction.test.d.ts.map +0 -1
- package/dist/transaction.test.js +0 -122
- package/dist/transaction.test.js.map +0 -1
- package/dist/types/proposal.test.d.ts +0 -2
- package/dist/types/proposal.test.d.ts.map +0 -1
- package/dist/types/proposal.test.js +0 -56
- package/dist/types/proposal.test.js.map +0 -1
- package/dist/utils/digest.test.d.ts +0 -2
- package/dist/utils/digest.test.d.ts.map +0 -1
- package/dist/utils/digest.test.js +0 -48
- package/dist/utils/digest.test.js.map +0 -1
- package/dist/utils/ecdsa.test.d.ts +0 -2
- package/dist/utils/ecdsa.test.d.ts.map +0 -1
- package/dist/utils/ecdsa.test.js +0 -131
- package/dist/utils/ecdsa.test.js.map +0 -1
- package/dist/utils/encoding.test.d.ts +0 -2
- package/dist/utils/encoding.test.d.ts.map +0 -1
- package/dist/utils/encoding.test.js +0 -185
- package/dist/utils/encoding.test.js.map +0 -1
- package/dist/utils/key.test.d.ts +0 -2
- package/dist/utils/key.test.d.ts.map +0 -1
- package/dist/utils/key.test.js +0 -82
- package/dist/utils/key.test.js.map +0 -1
- package/dist/utils/signature.test.d.ts +0 -2
- package/dist/utils/signature.test.d.ts.map +0 -1
- package/dist/utils/signature.test.js +0 -164
- package/dist/utils/signature.test.js.map +0 -1
- package/dist/utils/word.test.d.ts +0 -2
- package/dist/utils/word.test.d.ts.map +0 -1
- package/dist/utils/word.test.js +0 -54
- package/dist/utils/word.test.js.map +0 -1
- package/masm/account_components/auth/guarded_multisig.masm +0 -42
- package/src/account/builder.test.ts +0 -238
- package/src/account/masm/account-components/auth.ts +0 -46
- package/src/account/masm/index.ts +0 -4
- package/src/account/masm.ts +0 -4
- package/src/account/storage.test.ts +0 -90
- package/src/client.test.ts +0 -473
- package/src/connectivity.test.ts +0 -67
- package/src/inspector.test.ts +0 -542
- package/src/lookupAuth.test.ts +0 -185
- package/src/multisig/consumeNotesErrors.test.ts +0 -43
- package/src/multisig/helpers.test.ts +0 -114
- package/src/multisig.test.ts +0 -5008
- package/src/proposal/factory.test.ts +0 -40
- package/src/proposal/metadata.test.ts +0 -235
- package/src/prover/config.test.ts +0 -90
- package/src/prover/errors.test.ts +0 -61
- package/src/prover/retry.test.ts +0 -38
- package/src/prover/workflow.test.ts +0 -145
- package/src/raw-client.test.ts +0 -171
- package/src/rpc/config.test.ts +0 -45
- package/src/rpc/errors.test.ts +0 -69
- package/src/rpc/retry.test.ts +0 -144
- package/src/signers/ecdsa.test.ts +0 -111
- package/src/signers/falcon.test.ts +0 -197
- package/src/signers/miden-wallet.ecdsa-recovery.test.ts +0 -201
- package/src/signers/miden-wallet.test.ts +0 -206
- package/src/signers/para.test.ts +0 -186
- package/src/transaction/index.ts +0 -13
- package/src/transaction/p2id.test.ts +0 -371
- package/src/transaction/rpoRandomCoin.test.ts +0 -64
- package/src/transaction/summary.test.ts +0 -32
- package/src/transaction.test.ts +0 -142
- package/src/types/proposal.test.ts +0 -68
- package/src/utils/digest.test.ts +0 -55
- package/src/utils/ecdsa.test.ts +0 -164
- package/src/utils/encoding.test.ts +0 -233
- package/src/utils/key.test.ts +0 -91
- package/src/utils/signature.test.ts +0 -210
- package/src/utils/word.test.ts +0 -64
package/src/lookupAuth.test.ts
DELETED
|
@@ -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
|
-
});
|