@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/raw-client.test.ts
DELETED
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
-
|
|
3
|
-
const { mockCreateClient } = vi.hoisted(() => ({
|
|
4
|
-
mockCreateClient: vi.fn(),
|
|
5
|
-
}));
|
|
6
|
-
|
|
7
|
-
vi.mock('@miden-sdk/miden-sdk', () => ({
|
|
8
|
-
WasmWebClient: {
|
|
9
|
-
createClient: mockCreateClient,
|
|
10
|
-
},
|
|
11
|
-
}));
|
|
12
|
-
|
|
13
|
-
import {
|
|
14
|
-
compileTxScript,
|
|
15
|
-
getRawMidenClient,
|
|
16
|
-
getTransactionProver,
|
|
17
|
-
requireConfigValue,
|
|
18
|
-
} from './raw-client.js';
|
|
19
|
-
|
|
20
|
-
describe('raw-client', () => {
|
|
21
|
-
beforeEach(() => {
|
|
22
|
-
mockCreateClient.mockReset();
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
it.each([undefined, null, 42, {}, []])(
|
|
26
|
-
'rejects non-string configuration value %j consistently',
|
|
27
|
-
(value) => {
|
|
28
|
-
expect(() => requireConfigValue('guardianEndpoint', value)).toThrow(
|
|
29
|
-
'missing required configuration: guardianEndpoint',
|
|
30
|
-
);
|
|
31
|
-
},
|
|
32
|
-
);
|
|
33
|
-
|
|
34
|
-
it('trims surrounding whitespace from configuration values', () => {
|
|
35
|
-
expect(requireConfigValue('guardianEndpoint', ' http://localhost:3000\n')).toBe(
|
|
36
|
-
'http://localhost:3000',
|
|
37
|
-
);
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it('rejects shadow client creation without an RPC endpoint', async () => {
|
|
41
|
-
const client = {
|
|
42
|
-
accounts: {},
|
|
43
|
-
sync: vi.fn(),
|
|
44
|
-
defaultProver: null,
|
|
45
|
-
storeIdentifier: vi.fn(() => 'browser-db'),
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
await expect(getRawMidenClient(client as any)).rejects.toThrow(
|
|
49
|
-
'missing required configuration: midenRpcEndpoint',
|
|
50
|
-
);
|
|
51
|
-
await expect(getRawMidenClient(client as any, ' ')).rejects.toThrow(
|
|
52
|
-
'missing required configuration: midenRpcEndpoint',
|
|
53
|
-
);
|
|
54
|
-
expect(mockCreateClient).not.toHaveBeenCalled();
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it('returns an injected raw web client without needing an endpoint', async () => {
|
|
58
|
-
const rawClient = {
|
|
59
|
-
executeTransaction: vi.fn(),
|
|
60
|
-
proveTransaction: vi.fn(),
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
await expect(getRawMidenClient(rawClient as any)).resolves.toBe(rawClient);
|
|
64
|
-
expect(mockCreateClient).not.toHaveBeenCalled();
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
it('returns the default prover from a public MidenClient', () => {
|
|
68
|
-
const prover = { kind: 'devnet-prover' };
|
|
69
|
-
const client = {
|
|
70
|
-
accounts: {},
|
|
71
|
-
sync: vi.fn(),
|
|
72
|
-
defaultProver: prover,
|
|
73
|
-
storeIdentifier: vi.fn(() => 'browser-db'),
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
expect(getTransactionProver(client as any)).toBe(prover);
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
it('returns null for raw web clients', () => {
|
|
80
|
-
const rawClient = {
|
|
81
|
-
executeTransaction: vi.fn(),
|
|
82
|
-
proveTransaction: vi.fn(),
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
expect(getTransactionProver(rawClient as any)).toBeNull();
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
it('creates and caches a raw client for a public MidenClient', async () => {
|
|
89
|
-
const rawClient = { kind: 'raw-client' };
|
|
90
|
-
const client = {
|
|
91
|
-
accounts: {},
|
|
92
|
-
sync: vi.fn(),
|
|
93
|
-
defaultProver: null,
|
|
94
|
-
storeIdentifier: vi.fn(() => 'browser-db'),
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
mockCreateClient.mockResolvedValue(rawClient);
|
|
98
|
-
|
|
99
|
-
await expect(
|
|
100
|
-
getRawMidenClient(client as any, 'https://rpc.devnet.miden.io'),
|
|
101
|
-
).resolves.toBe(rawClient);
|
|
102
|
-
await expect(
|
|
103
|
-
getRawMidenClient(client as any, 'https://rpc.devnet.miden.io'),
|
|
104
|
-
).resolves.toBe(rawClient);
|
|
105
|
-
|
|
106
|
-
expect(mockCreateClient).toHaveBeenCalledTimes(1);
|
|
107
|
-
expect(mockCreateClient).toHaveBeenCalledWith(
|
|
108
|
-
'https://rpc.devnet.miden.io',
|
|
109
|
-
undefined,
|
|
110
|
-
undefined,
|
|
111
|
-
'browser-db',
|
|
112
|
-
);
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
it('uses the public compile resource when available', async () => {
|
|
116
|
-
const script = { kind: 'compiled-script' };
|
|
117
|
-
const client = {
|
|
118
|
-
accounts: {},
|
|
119
|
-
sync: vi.fn(),
|
|
120
|
-
compile: {
|
|
121
|
-
txScript: vi.fn().mockResolvedValue(script),
|
|
122
|
-
},
|
|
123
|
-
storeIdentifier: vi.fn(() => 'browser-db'),
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
await expect(
|
|
127
|
-
compileTxScript(
|
|
128
|
-
client as any,
|
|
129
|
-
'begin end',
|
|
130
|
-
[{ namespace: 'auth::multisig', code: 'export.foo' }],
|
|
131
|
-
),
|
|
132
|
-
).resolves.toBe(script);
|
|
133
|
-
|
|
134
|
-
expect(client.compile.txScript).toHaveBeenCalledWith({
|
|
135
|
-
code: 'begin end',
|
|
136
|
-
libraries: [{ namespace: 'auth::multisig', code: 'export.foo' }],
|
|
137
|
-
});
|
|
138
|
-
expect(mockCreateClient).not.toHaveBeenCalled();
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
it('falls back to raw client compilation for low-level callers', async () => {
|
|
142
|
-
const compiledScript = { kind: 'compiled-script' };
|
|
143
|
-
const builtLibrary = { kind: 'built-library' };
|
|
144
|
-
const builder = {
|
|
145
|
-
buildLibrary: vi.fn().mockReturnValue(builtLibrary),
|
|
146
|
-
linkDynamicLibrary: vi.fn(),
|
|
147
|
-
linkStaticLibrary: vi.fn(),
|
|
148
|
-
compileTxScript: vi.fn().mockReturnValue(compiledScript),
|
|
149
|
-
};
|
|
150
|
-
const rawClient = {
|
|
151
|
-
createCodeBuilder: vi.fn().mockReturnValue(builder),
|
|
152
|
-
};
|
|
153
|
-
|
|
154
|
-
await expect(
|
|
155
|
-
compileTxScript(
|
|
156
|
-
rawClient as any,
|
|
157
|
-
'begin end',
|
|
158
|
-
[
|
|
159
|
-
{ namespace: 'auth::multisig', code: 'export.foo' },
|
|
160
|
-
{ namespace: 'auth::guardian', code: 'export.bar', linking: 'static' },
|
|
161
|
-
],
|
|
162
|
-
),
|
|
163
|
-
).resolves.toBe(compiledScript);
|
|
164
|
-
|
|
165
|
-
expect(builder.buildLibrary).toHaveBeenNthCalledWith(1, 'auth::multisig', 'export.foo');
|
|
166
|
-
expect(builder.buildLibrary).toHaveBeenNthCalledWith(2, 'auth::guardian', 'export.bar');
|
|
167
|
-
expect(builder.linkDynamicLibrary).toHaveBeenCalledWith(builtLibrary);
|
|
168
|
-
expect(builder.linkStaticLibrary).toHaveBeenCalledWith(builtLibrary);
|
|
169
|
-
expect(builder.compileTxScript).toHaveBeenCalledWith('begin end');
|
|
170
|
-
});
|
|
171
|
-
});
|
package/src/rpc/config.test.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { readFileSync } from 'node:fs';
|
|
2
|
-
import { describe, expect, it } from 'vitest';
|
|
3
|
-
import { resolveRpcConfig } from './config.js';
|
|
4
|
-
|
|
5
|
-
interface Fixtures {
|
|
6
|
-
attemptBudgets: Array<{ input: number | null; normalized: number }>;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
function fixtures(): Fixtures {
|
|
10
|
-
return JSON.parse(
|
|
11
|
-
readFileSync(
|
|
12
|
-
new URL(
|
|
13
|
-
'../../../../fixtures/miden-multisig-client/rpc-policy-fixtures.json',
|
|
14
|
-
import.meta.url,
|
|
15
|
-
),
|
|
16
|
-
'utf8',
|
|
17
|
-
),
|
|
18
|
-
) as Fixtures;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
describe('resolveRpcConfig', () => {
|
|
22
|
-
it('matches shared attempt-budget vectors', () => {
|
|
23
|
-
for (const fixture of fixtures().attemptBudgets) {
|
|
24
|
-
const retry = fixture.input === null ? undefined : { maxAttempts: fixture.input };
|
|
25
|
-
expect(resolveRpcConfig({ retry }).maxAttempts).toBe(fixture.normalized);
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it('defaults to one retry when no config is given', () => {
|
|
30
|
-
expect(resolveRpcConfig(undefined).maxAttempts).toBe(2);
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it('treats an explicit single attempt as a full opt-out', () => {
|
|
34
|
-
expect(resolveRpcConfig({ retry: { maxAttempts: 1 } }).maxAttempts).toBe(1);
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it.each([-1, 1.5, Number.NaN, Number.POSITIVE_INFINITY, 4_294_967_296])(
|
|
38
|
-
'rejects invalid maxAttempts value %s',
|
|
39
|
-
(maxAttempts) => {
|
|
40
|
-
expect(() => resolveRpcConfig({ retry: { maxAttempts } })).toThrow(
|
|
41
|
-
'rpc.retry.maxAttempts',
|
|
42
|
-
);
|
|
43
|
-
},
|
|
44
|
-
);
|
|
45
|
-
});
|
package/src/rpc/errors.test.ts
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { readFileSync } from 'node:fs';
|
|
2
|
-
import { describe, expect, it } from 'vitest';
|
|
3
|
-
import { isTransientRpcError } from './errors.js';
|
|
4
|
-
|
|
5
|
-
interface FixtureError {
|
|
6
|
-
code?: string;
|
|
7
|
-
status?: number;
|
|
8
|
-
message: string;
|
|
9
|
-
cause?: FixtureError;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
interface Fixtures {
|
|
13
|
-
classifications: Array<{
|
|
14
|
-
name: string;
|
|
15
|
-
chain: FixtureError[];
|
|
16
|
-
transient: boolean;
|
|
17
|
-
}>;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
function fixtures(): Fixtures {
|
|
21
|
-
return JSON.parse(
|
|
22
|
-
readFileSync(
|
|
23
|
-
new URL(
|
|
24
|
-
'../../../../fixtures/miden-multisig-client/rpc-policy-fixtures.json',
|
|
25
|
-
import.meta.url,
|
|
26
|
-
),
|
|
27
|
-
'utf8',
|
|
28
|
-
),
|
|
29
|
-
) as Fixtures;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
describe('isTransientRpcError', () => {
|
|
33
|
-
it('matches every shared classification vector', () => {
|
|
34
|
-
for (const fixture of fixtures().classifications) {
|
|
35
|
-
const error = fixture.chain.reduceRight<FixtureError | undefined>(
|
|
36
|
-
(cause, item) => ({ ...item, cause }),
|
|
37
|
-
undefined,
|
|
38
|
-
);
|
|
39
|
-
expect(isTransientRpcError(error), fixture.name).toBe(fixture.transient);
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it('stops safely on cyclic cause graphs', () => {
|
|
44
|
-
const error: FixtureError = { code: 'Unknown', message: 'not retryable' };
|
|
45
|
-
error.cause = error;
|
|
46
|
-
expect(isTransientRpcError(error)).toBe(false);
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it('recognizes numeric gRPC status codes', () => {
|
|
50
|
-
expect(isTransientRpcError({ code: 14, message: 'unavailable' })).toBe(true);
|
|
51
|
-
expect(isTransientRpcError({ code: 3, message: 'timeout text' })).toBe(false);
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it('keeps permanent status evidence ahead of transport wording', () => {
|
|
55
|
-
expect(
|
|
56
|
-
isTransientRpcError({
|
|
57
|
-
code: 'FailedPrecondition',
|
|
58
|
-
message: 'transport error while checking preconditions',
|
|
59
|
-
}),
|
|
60
|
-
).toBe(false);
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it('reads grpc code wording out of plain message text', () => {
|
|
64
|
-
expect(isTransientRpcError(new Error('grpc code: InvalidArgument; request timeout'))).toBe(
|
|
65
|
-
false,
|
|
66
|
-
);
|
|
67
|
-
expect(isTransientRpcError(new Error('grpc code: Unavailable'))).toBe(true);
|
|
68
|
-
});
|
|
69
|
-
});
|
package/src/rpc/retry.test.ts
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
import { readFileSync } from 'node:fs';
|
|
2
|
-
import { describe, expect, it, vi } from 'vitest';
|
|
3
|
-
import { resolveRpcConfig } from './config.js';
|
|
4
|
-
import { retryRpcRead } from './retry.js';
|
|
5
|
-
import type { RetryRuntime } from '../retry/runtime.js';
|
|
6
|
-
import { retryDelay } from '../retry/runtime.js';
|
|
7
|
-
|
|
8
|
-
interface Fixtures {
|
|
9
|
-
delays: Array<{ retryIndex: number; unitRandom: number; delayMs: number }>;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
function fixtures(): Fixtures {
|
|
13
|
-
return JSON.parse(
|
|
14
|
-
readFileSync(
|
|
15
|
-
new URL(
|
|
16
|
-
'../../../../fixtures/miden-multisig-client/rpc-policy-fixtures.json',
|
|
17
|
-
import.meta.url,
|
|
18
|
-
),
|
|
19
|
-
'utf8',
|
|
20
|
-
),
|
|
21
|
-
) as Fixtures;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function recordingRuntime(): RetryRuntime & { sleeps: number[] } {
|
|
25
|
-
const sleeps: number[] = [];
|
|
26
|
-
return {
|
|
27
|
-
sleeps,
|
|
28
|
-
sleep: (delayMs) => {
|
|
29
|
-
sleeps.push(delayMs);
|
|
30
|
-
return Promise.resolve();
|
|
31
|
-
},
|
|
32
|
-
unitRandom: () => 0.5,
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function rateLimitError(): Error {
|
|
37
|
-
return Object.assign(new Error('Too Many Requests!'), {
|
|
38
|
-
code: 'ResourceExhausted',
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
describe('retryRpcRead', () => {
|
|
43
|
-
it('matches every shared delay vector', () => {
|
|
44
|
-
for (const fixture of fixtures().delays) {
|
|
45
|
-
expect(retryDelay(fixture.retryIndex, fixture.unitRandom)).toBe(fixture.delayMs);
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it('waits out rate limiting and returns the eventual result', async () => {
|
|
50
|
-
const runtime = recordingRuntime();
|
|
51
|
-
const operation = vi
|
|
52
|
-
.fn()
|
|
53
|
-
.mockRejectedValueOnce(rateLimitError())
|
|
54
|
-
.mockRejectedValueOnce(rateLimitError())
|
|
55
|
-
.mockResolvedValueOnce('synced');
|
|
56
|
-
|
|
57
|
-
const result = await retryRpcRead(
|
|
58
|
-
operation,
|
|
59
|
-
resolveRpcConfig({ retry: { maxAttempts: 3 } }),
|
|
60
|
-
runtime,
|
|
61
|
-
);
|
|
62
|
-
|
|
63
|
-
expect(result).toBe('synced');
|
|
64
|
-
expect(operation).toHaveBeenCalledTimes(3);
|
|
65
|
-
expect(runtime.sleeps).toEqual([retryDelay(0, 0.5), retryDelay(1, 0.5)]);
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it('throws a permanent error immediately without sleeping', async () => {
|
|
69
|
-
const runtime = recordingRuntime();
|
|
70
|
-
const permanent = Object.assign(new Error('malformed account id'), {
|
|
71
|
-
code: 'InvalidArgument',
|
|
72
|
-
});
|
|
73
|
-
const operation = vi.fn().mockRejectedValue(permanent);
|
|
74
|
-
|
|
75
|
-
await expect(
|
|
76
|
-
retryRpcRead(operation, resolveRpcConfig({ retry: { maxAttempts: 5 } }), runtime),
|
|
77
|
-
).rejects.toBe(permanent);
|
|
78
|
-
expect(operation).toHaveBeenCalledTimes(1);
|
|
79
|
-
expect(runtime.sleeps).toEqual([]);
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
it('rethrows the final upstream error unchanged after budget exhaustion', async () => {
|
|
83
|
-
const runtime = recordingRuntime();
|
|
84
|
-
const final = Object.assign(new Error('still rate limited'), {
|
|
85
|
-
code: 'ResourceExhausted',
|
|
86
|
-
});
|
|
87
|
-
const operation = vi
|
|
88
|
-
.fn()
|
|
89
|
-
.mockRejectedValueOnce(rateLimitError())
|
|
90
|
-
.mockRejectedValueOnce(final);
|
|
91
|
-
|
|
92
|
-
await expect(
|
|
93
|
-
retryRpcRead(operation, resolveRpcConfig({ retry: { maxAttempts: 2 } }), runtime),
|
|
94
|
-
).rejects.toBe(final);
|
|
95
|
-
expect(operation).toHaveBeenCalledTimes(2);
|
|
96
|
-
expect(runtime.sleeps).toHaveLength(1);
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
it('retries a transient read once under the default config', async () => {
|
|
100
|
-
const runtime = recordingRuntime();
|
|
101
|
-
const operation = vi
|
|
102
|
-
.fn()
|
|
103
|
-
.mockRejectedValueOnce(rateLimitError())
|
|
104
|
-
.mockResolvedValueOnce('synced');
|
|
105
|
-
|
|
106
|
-
await expect(retryRpcRead(operation, resolveRpcConfig(undefined), runtime)).resolves.toBe(
|
|
107
|
-
'synced',
|
|
108
|
-
);
|
|
109
|
-
expect(operation).toHaveBeenCalledTimes(2);
|
|
110
|
-
expect(runtime.sleeps).toHaveLength(1);
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
it('never retries under an explicit single-attempt config', async () => {
|
|
114
|
-
const runtime = recordingRuntime();
|
|
115
|
-
const operation = vi.fn().mockRejectedValue(rateLimitError());
|
|
116
|
-
|
|
117
|
-
await expect(
|
|
118
|
-
retryRpcRead(operation, resolveRpcConfig({ retry: { maxAttempts: 1 } }), runtime),
|
|
119
|
-
).rejects.toThrow('Too Many Requests!');
|
|
120
|
-
expect(operation).toHaveBeenCalledTimes(1);
|
|
121
|
-
expect(runtime.sleeps).toEqual([]);
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
it('completes 64 concurrent reads against a rate-limited node', async () => {
|
|
125
|
-
const runtime = recordingRuntime();
|
|
126
|
-
let rejected = 0;
|
|
127
|
-
const operation = () => {
|
|
128
|
-
if (rejected < 40) {
|
|
129
|
-
rejected += 1;
|
|
130
|
-
return Promise.reject(rateLimitError());
|
|
131
|
-
}
|
|
132
|
-
return Promise.resolve('synced');
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
const results = await Promise.all(
|
|
136
|
-
Array.from({ length: 64 }, () =>
|
|
137
|
-
retryRpcRead(operation, resolveRpcConfig({ retry: { maxAttempts: 4 } }), runtime),
|
|
138
|
-
),
|
|
139
|
-
);
|
|
140
|
-
|
|
141
|
-
expect(results).toEqual(Array.from({ length: 64 }, () => 'synced'));
|
|
142
|
-
expect(rejected).toBe(40);
|
|
143
|
-
});
|
|
144
|
-
});
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it, vi, beforeEach } from 'vitest';
|
|
2
|
-
import { EcdsaSigner } from './ecdsa.js';
|
|
3
|
-
|
|
4
|
-
vi.mock('@miden-sdk/miden-sdk', () => {
|
|
5
|
-
const mockSignature = {
|
|
6
|
-
serialize: () => new Uint8Array([0, 1, 2, 3, 4, 5]),
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
const mockCommitment = {
|
|
10
|
-
toHex: () => '0x' + 'a'.repeat(64),
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
const mockPublicKey = {
|
|
14
|
-
toCommitment: () => mockCommitment,
|
|
15
|
-
serialize: () => new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]),
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
const mockSecretKey = {
|
|
19
|
-
publicKey: vi.fn().mockReturnValue(mockPublicKey),
|
|
20
|
-
sign: vi.fn().mockReturnValue(mockSignature),
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
return {
|
|
24
|
-
AuthSecretKey: vi.fn(),
|
|
25
|
-
Word: {
|
|
26
|
-
fromHex: vi.fn((hex: string) => ({
|
|
27
|
-
toHex: () => hex,
|
|
28
|
-
toFelts: () => [1, 2, 3, 4],
|
|
29
|
-
})),
|
|
30
|
-
},
|
|
31
|
-
AccountId: {
|
|
32
|
-
fromHex: vi.fn((hex: string) => ({
|
|
33
|
-
toString: () => hex,
|
|
34
|
-
prefix: () => ({ asInt: () => BigInt(1) }),
|
|
35
|
-
suffix: () => ({ asInt: () => BigInt(2) }),
|
|
36
|
-
})),
|
|
37
|
-
},
|
|
38
|
-
Felt: vi.fn().mockImplementation((value: bigint) => ({ value })),
|
|
39
|
-
FeltArray: vi.fn().mockImplementation((elements: unknown[]) => elements),
|
|
40
|
-
Rpo256: {
|
|
41
|
-
hashElements: vi.fn().mockReturnValue({
|
|
42
|
-
toHex: () => '0x' + 'b'.repeat(64),
|
|
43
|
-
toFelts: () => [1, 2, 3, 4],
|
|
44
|
-
}),
|
|
45
|
-
},
|
|
46
|
-
};
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
describe('EcdsaSigner', () => {
|
|
50
|
-
let mockSecretKey: {
|
|
51
|
-
publicKey: ReturnType<typeof vi.fn>;
|
|
52
|
-
sign: ReturnType<typeof vi.fn>;
|
|
53
|
-
};
|
|
54
|
-
let signer: EcdsaSigner;
|
|
55
|
-
|
|
56
|
-
beforeEach(async () => {
|
|
57
|
-
vi.clearAllMocks();
|
|
58
|
-
mockSecretKey = {
|
|
59
|
-
publicKey: vi.fn().mockReturnValue({
|
|
60
|
-
toCommitment: () => ({ toHex: () => '0x' + 'a'.repeat(64) }),
|
|
61
|
-
serialize: () => new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]),
|
|
62
|
-
}),
|
|
63
|
-
sign: vi.fn().mockReturnValue({
|
|
64
|
-
serialize: () => new Uint8Array([0, 1, 2, 3, 4, 5]),
|
|
65
|
-
}),
|
|
66
|
-
};
|
|
67
|
-
signer = new EcdsaSigner(mockSecretKey as never);
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
it('signs request-bound auth messages for ECDSA', async () => {
|
|
71
|
-
const { Rpo256 } = await import('@miden-sdk/miden-sdk');
|
|
72
|
-
|
|
73
|
-
const signature = await signer.signRequest(
|
|
74
|
-
'0x' + 'a'.repeat(30),
|
|
75
|
-
1700000000,
|
|
76
|
-
{ toBytes: () => new Uint8Array([1, 2, 3, 4]) } as never,
|
|
77
|
-
);
|
|
78
|
-
|
|
79
|
-
expect(signature).toBe('0x0102030405');
|
|
80
|
-
expect(mockSecretKey.sign).toHaveBeenCalled();
|
|
81
|
-
expect(Rpo256.hashElements).toHaveBeenCalledTimes(2);
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
it('skips rebinding when the signer key is already attached to the same account', async () => {
|
|
85
|
-
const accountId = '0x' + 'd'.repeat(30);
|
|
86
|
-
const midenClient = {
|
|
87
|
-
keystore: {
|
|
88
|
-
getAccountId: vi.fn().mockResolvedValue({ toString: () => accountId }),
|
|
89
|
-
insert: vi.fn().mockResolvedValue(undefined),
|
|
90
|
-
},
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
await signer.bindAccountKey(midenClient as never, accountId);
|
|
94
|
-
|
|
95
|
-
expect(midenClient.keystore.insert).not.toHaveBeenCalled();
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
it('throws when the signer key is already attached to a different account', async () => {
|
|
99
|
-
const midenClient = {
|
|
100
|
-
keystore: {
|
|
101
|
-
getAccountId: vi.fn().mockResolvedValue({ toString: () => '0x' + 'e'.repeat(30) }),
|
|
102
|
-
insert: vi.fn().mockResolvedValue(undefined),
|
|
103
|
-
},
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
await expect(
|
|
107
|
-
signer.bindAccountKey(midenClient as never, '0x' + 'd'.repeat(30)),
|
|
108
|
-
).rejects.toThrow('already bound to account');
|
|
109
|
-
expect(midenClient.keystore.insert).not.toHaveBeenCalled();
|
|
110
|
-
});
|
|
111
|
-
});
|