@openzeppelin/miden-multisig-client 0.17.0 → 0.18.0-rc.2
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 +171 -46
- package/dist/account/builder.d.ts +4 -4
- package/dist/account/builder.d.ts.map +1 -1
- package/dist/account/builder.js +17 -7
- package/dist/account/builder.js.map +1 -1
- package/dist/account/layout.d.ts +5 -5
- package/dist/account/layout.d.ts.map +1 -1
- package/dist/account/layout.js +5 -5
- package/dist/account/layout.js.map +1 -1
- package/dist/client.d.ts +18 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +79 -6
- package/dist/client.js.map +1 -1
- package/dist/index.d.ts +6 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -5
- package/dist/index.js.map +1 -1
- package/dist/multisig/authArgErrors.d.ts +28 -31
- package/dist/multisig/authArgErrors.d.ts.map +1 -1
- package/dist/multisig/authArgErrors.js +42 -46
- package/dist/multisig/authArgErrors.js.map +1 -1
- package/dist/multisig/consumeNotesErrors.d.ts +13 -1
- package/dist/multisig/consumeNotesErrors.d.ts.map +1 -1
- package/dist/multisig/consumeNotesErrors.js +17 -0
- package/dist/multisig/consumeNotesErrors.js.map +1 -1
- package/dist/multisig/signing.d.ts +1 -1
- package/dist/multisig/signing.d.ts.map +1 -1
- package/dist/multisig/signing.js +8 -3
- package/dist/multisig/signing.js.map +1 -1
- package/dist/multisig.d.ts +145 -18
- package/dist/multisig.d.ts.map +1 -1
- package/dist/multisig.js +493 -162
- package/dist/multisig.js.map +1 -1
- package/dist/procedures.d.ts +7 -7
- package/dist/procedures.js +7 -7
- package/dist/proposal/factory.d.ts.map +1 -1
- package/dist/proposal/factory.js +7 -0
- package/dist/proposal/factory.js.map +1 -1
- package/dist/prover/workflow.d.ts +7 -3
- package/dist/prover/workflow.d.ts.map +1 -1
- package/dist/prover/workflow.js +7 -5
- package/dist/prover/workflow.js.map +1 -1
- package/dist/raw-client.d.ts +1 -0
- package/dist/raw-client.d.ts.map +1 -1
- package/dist/raw-client.js +10 -2
- package/dist/raw-client.js.map +1 -1
- package/dist/recovery/publicNoteBackfill.js +1 -1
- package/dist/recovery/publicNoteBackfill.js.map +1 -1
- package/dist/retry/classify.d.ts +3 -0
- package/dist/retry/classify.d.ts.map +1 -1
- package/dist/retry/classify.js +2 -2
- package/dist/retry/classify.js.map +1 -1
- package/dist/signer.d.ts +1 -0
- package/dist/signer.d.ts.map +1 -1
- package/dist/signer.js +1 -0
- package/dist/signer.js.map +1 -1
- package/dist/signers/index.d.ts +1 -0
- package/dist/signers/index.d.ts.map +1 -1
- package/dist/signers/index.js +1 -0
- package/dist/signers/index.js.map +1 -1
- package/dist/signers/ledger.d.ts +25 -0
- package/dist/signers/ledger.d.ts.map +1 -0
- package/dist/signers/ledger.js +96 -0
- package/dist/signers/ledger.js.map +1 -0
- package/dist/state/adopt.d.ts +45 -0
- package/dist/state/adopt.d.ts.map +1 -0
- package/dist/state/adopt.js +101 -0
- package/dist/state/adopt.js.map +1 -0
- package/dist/transaction/authArgs.d.ts +57 -0
- package/dist/transaction/authArgs.d.ts.map +1 -0
- package/dist/transaction/authArgs.js +108 -0
- package/dist/transaction/authArgs.js.map +1 -0
- package/dist/transaction/consumeNotes.d.ts +9 -5
- package/dist/transaction/consumeNotes.d.ts.map +1 -1
- package/dist/transaction/consumeNotes.js +8 -23
- package/dist/transaction/consumeNotes.js.map +1 -1
- package/dist/transaction/noteAuthentication.d.ts +39 -0
- package/dist/transaction/noteAuthentication.d.ts.map +1 -0
- package/dist/transaction/noteAuthentication.js +94 -0
- package/dist/transaction/noteAuthentication.js.map +1 -0
- package/dist/transaction/options.d.ts +25 -0
- package/dist/transaction/options.d.ts.map +1 -1
- package/dist/transaction/p2id.d.ts +3 -2
- package/dist/transaction/p2id.d.ts.map +1 -1
- package/dist/transaction/p2id.js +36 -27
- package/dist/transaction/p2id.js.map +1 -1
- package/dist/transaction/summary.d.ts +126 -22
- package/dist/transaction/summary.d.ts.map +1 -1
- package/dist/transaction/summary.js +164 -22
- package/dist/transaction/summary.js.map +1 -1
- package/dist/transaction/updateGuardian.d.ts +3 -3
- package/dist/transaction/updateGuardian.d.ts.map +1 -1
- package/dist/transaction/updateGuardian.js +5 -16
- package/dist/transaction/updateGuardian.js.map +1 -1
- package/dist/transaction/updateProcedureThreshold.d.ts +3 -3
- package/dist/transaction/updateProcedureThreshold.d.ts.map +1 -1
- package/dist/transaction/updateProcedureThreshold.js +6 -16
- package/dist/transaction/updateProcedureThreshold.js.map +1 -1
- package/dist/transaction/updateSigners.d.ts +3 -3
- package/dist/transaction/updateSigners.d.ts.map +1 -1
- package/dist/transaction/updateSigners.js +9 -16
- package/dist/transaction/updateSigners.js.map +1 -1
- package/dist/transaction.d.ts +3 -2
- package/dist/transaction.d.ts.map +1 -1
- package/dist/transaction.js +3 -2
- package/dist/transaction.js.map +1 -1
- package/dist/types/proposal.d.ts +37 -5
- package/dist/types/proposal.d.ts.map +1 -1
- package/dist/types/proposal.js +8 -0
- package/dist/types/proposal.js.map +1 -1
- package/dist/utils/eip712.d.ts +80 -0
- package/dist/utils/eip712.d.ts.map +1 -0
- package/dist/utils/eip712.js +49 -0
- package/dist/utils/eip712.js.map +1 -0
- package/dist/utils/signature.d.ts +4 -0
- package/dist/utils/signature.d.ts.map +1 -1
- package/dist/utils/signature.js +49 -1
- package/dist/utils/signature.js.map +1 -1
- package/package.json +11 -6
- package/src/account/builder.ts +18 -7
- package/src/account/layout.ts +5 -5
- package/src/client.ts +94 -6
- package/src/index.ts +24 -3
- package/src/multisig/authArgErrors.ts +47 -53
- package/src/multisig/consumeNotesErrors.ts +20 -1
- package/src/multisig/signing.ts +8 -2
- package/src/multisig.ts +614 -205
- package/src/procedures.ts +7 -7
- package/src/proposal/factory.ts +7 -0
- package/src/prover/workflow.ts +7 -10
- package/src/raw-client.ts +11 -7
- package/src/recovery/publicNoteBackfill.ts +1 -1
- package/src/retry/classify.ts +3 -3
- package/src/signer.ts +1 -0
- package/src/signers/index.ts +1 -0
- package/src/signers/ledger.ts +122 -0
- package/src/state/adopt.ts +132 -0
- package/src/transaction/authArgs.ts +142 -0
- package/src/transaction/consumeNotes.ts +23 -30
- package/src/transaction/noteAuthentication.ts +136 -0
- package/src/transaction/options.ts +27 -0
- package/src/transaction/p2id.ts +45 -34
- package/src/transaction/summary.ts +239 -30
- package/src/transaction/updateGuardian.ts +8 -22
- package/src/transaction/updateProcedureThreshold.ts +8 -20
- package/src/transaction/updateSigners.ts +11 -22
- package/src/transaction.ts +18 -1
- package/src/types/proposal.ts +36 -5
- package/src/utils/eip712.ts +57 -0
- package/src/utils/signature.ts +57 -0
- package/src/prover/test-node.d.ts +0 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"proposal.js","sourceRoot":"","sources":["../../src/types/proposal.ts"],"names":[],"mappings":"AAqEA,gFAAgF;AAChF,MAAM,CAAC,MAAM,iCAAiC,GAAG,CAAU,CAAC;AAE5D,iEAAiE;AACjE,MAAM,CAAC,MAAM,gCAAgC,GAAG,GAAG,GAAG,IAAI,CAAC;AAW3D,MAAM,UAAU,gBAAgB,CAAC,EAAgC;IAC/D,OAAO,EAAE,CAAC,eAAe,KAAK,iCAAiC,CAAC;AAClE,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,EAAgC;IAC/D,OAAO,EAAE,CAAC,eAAe,KAAK,SAAS,IAAI,EAAE,CAAC,eAAe,KAAK,CAAC,CAAC;AACtE,CAAC;AAKD,MAAM,UAAU,oBAAoB,CAAC,KAAa;IAChD,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,SAAS,CAAC;AACnD,CAAC;AAED,8EAA8E;AAC9E,MAAM,CAAC,MAAM,sBAAsB,GAAG,WAAW,CAAC;AAElD;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB,CAC9B,KAAyC,EACzC,KAAyB;IAEzB,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACxB,OAAO,SAAS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wCAAwC,sBAAsB,EAAE,CAC/F,CAAC;IACJ,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAiED;;;;GAIG;AACH,MAAM,UAAU,oBAAoB,CAAC,QAAkB;IACrD,OAAO,QAAQ,CAAC,YAAY,CAAC,MAAM,KAAK,UAAU,IAAI,QAAQ,CAAC,MAAM,KAAK,OAAO,CAAC;AACpF,CAAC"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
type TypedField = {
|
|
2
|
+
name: string;
|
|
3
|
+
type: string;
|
|
4
|
+
};
|
|
5
|
+
declare function typedData(name: string, primaryType: string, fieldName: string, value: string): {
|
|
6
|
+
types: {
|
|
7
|
+
[primaryType]: {
|
|
8
|
+
name: string;
|
|
9
|
+
type: string;
|
|
10
|
+
}[];
|
|
11
|
+
EIP712Domain: TypedField[];
|
|
12
|
+
};
|
|
13
|
+
primaryType: string;
|
|
14
|
+
domain: {
|
|
15
|
+
name: string;
|
|
16
|
+
version: string;
|
|
17
|
+
};
|
|
18
|
+
message: {
|
|
19
|
+
[fieldName]: string;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
export declare function guardianRequestTypedData(requestHash: Uint8Array): {
|
|
23
|
+
types: {
|
|
24
|
+
[x: string]: TypedField[];
|
|
25
|
+
EIP712Domain: TypedField[];
|
|
26
|
+
};
|
|
27
|
+
primaryType: string;
|
|
28
|
+
domain: {
|
|
29
|
+
name: string;
|
|
30
|
+
version: string;
|
|
31
|
+
};
|
|
32
|
+
message: {
|
|
33
|
+
[x: string]: string;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
export declare function guardianLookupTypedData(lookupHash: Uint8Array): {
|
|
37
|
+
types: {
|
|
38
|
+
[x: string]: TypedField[];
|
|
39
|
+
EIP712Domain: TypedField[];
|
|
40
|
+
};
|
|
41
|
+
primaryType: string;
|
|
42
|
+
domain: {
|
|
43
|
+
name: string;
|
|
44
|
+
version: string;
|
|
45
|
+
};
|
|
46
|
+
message: {
|
|
47
|
+
[x: string]: string;
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
export declare function midenTransactionTypedData(txSummaryHash: Uint8Array): {
|
|
51
|
+
types: {
|
|
52
|
+
[x: string]: TypedField[];
|
|
53
|
+
EIP712Domain: TypedField[];
|
|
54
|
+
};
|
|
55
|
+
primaryType: string;
|
|
56
|
+
domain: {
|
|
57
|
+
name: string;
|
|
58
|
+
version: string;
|
|
59
|
+
};
|
|
60
|
+
message: {
|
|
61
|
+
[x: string]: string;
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
export declare function guardianKeyDiscoveryTypedData(challenge: Uint8Array): {
|
|
65
|
+
types: {
|
|
66
|
+
[x: string]: TypedField[];
|
|
67
|
+
EIP712Domain: TypedField[];
|
|
68
|
+
};
|
|
69
|
+
primaryType: string;
|
|
70
|
+
domain: {
|
|
71
|
+
name: string;
|
|
72
|
+
version: string;
|
|
73
|
+
};
|
|
74
|
+
message: {
|
|
75
|
+
[x: string]: string;
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
export declare function typedDataDigest(data: ReturnType<typeof typedData>): Uint8Array;
|
|
79
|
+
export {};
|
|
80
|
+
//# sourceMappingURL=eip712.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eip712.d.ts","sourceRoot":"","sources":["../../src/utils/eip712.ts"],"names":[],"mappings":"AAGA,KAAK,UAAU,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAUjD,iBAAS,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;;QAIhF,CAAC,WAAW,CAAC;;;YAAwC;;;;;;;;;QAI5C,CAAC,SAAS,CAAC,SAAO;;EAEhC;AAED,wBAAgB,wBAAwB,CAAC,WAAW,EAAE,UAAU;;;;;;;;;;;;;EAE/D;AAED,wBAAgB,uBAAuB,CAAC,UAAU,EAAE,UAAU;;;;;;;;;;;;;EAE7D;AAED,wBAAgB,yBAAyB,CAAC,aAAa,EAAE,UAAU;;;;;;;;;;;;;EAElE;AAED,wBAAgB,6BAA6B,CAAC,SAAS,EAAE,UAAU;;;;;;;;;;;;;EAElE;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,UAAU,CAAC,OAAO,SAAS,CAAC,GAAG,UAAU,CAe9E"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { keccak_256 } from '@noble/hashes/sha3.js';
|
|
2
|
+
import { bytesToHex, hexToBytes } from './encoding.js';
|
|
3
|
+
const EIP191_PREFIX = 0x19;
|
|
4
|
+
const EIP712_VERSION = 0x01;
|
|
5
|
+
const DOMAIN_VERSION = '1';
|
|
6
|
+
const domainFields = [
|
|
7
|
+
{ name: 'name', type: 'string' },
|
|
8
|
+
{ name: 'version', type: 'string' },
|
|
9
|
+
];
|
|
10
|
+
function typedData(name, primaryType, fieldName, value) {
|
|
11
|
+
return {
|
|
12
|
+
types: {
|
|
13
|
+
EIP712Domain: domainFields,
|
|
14
|
+
[primaryType]: [{ name: fieldName, type: 'bytes32' }],
|
|
15
|
+
},
|
|
16
|
+
primaryType,
|
|
17
|
+
domain: { name, version: DOMAIN_VERSION },
|
|
18
|
+
message: { [fieldName]: value },
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export function guardianRequestTypedData(requestHash) {
|
|
22
|
+
return typedData('Guardian Request', 'GuardianRequest', 'requestHash', bytesToHex(requestHash));
|
|
23
|
+
}
|
|
24
|
+
export function guardianLookupTypedData(lookupHash) {
|
|
25
|
+
return typedData('Guardian Lookup', 'GuardianLookup', 'lookupHash', bytesToHex(lookupHash));
|
|
26
|
+
}
|
|
27
|
+
export function midenTransactionTypedData(txSummaryHash) {
|
|
28
|
+
return typedData('Miden Transaction', 'MidenTransaction', 'txSummaryHash', bytesToHex(txSummaryHash));
|
|
29
|
+
}
|
|
30
|
+
export function guardianKeyDiscoveryTypedData(challenge) {
|
|
31
|
+
return typedData('Guardian Key Discovery', 'GuardianKeyDiscovery', 'challenge', bytesToHex(challenge));
|
|
32
|
+
}
|
|
33
|
+
export function typedDataDigest(data) {
|
|
34
|
+
const domainType = new TextEncoder().encode('EIP712Domain(string name,string version)');
|
|
35
|
+
const primaryType = new TextEncoder().encode(`${data.primaryType}(bytes32 ${Object.keys(data.message)[0]})`);
|
|
36
|
+
const domain = new Uint8Array(96);
|
|
37
|
+
domain.set(keccak_256(domainType));
|
|
38
|
+
domain.set(keccak_256(new TextEncoder().encode(data.domain.name)), 32);
|
|
39
|
+
domain.set(keccak_256(new TextEncoder().encode(data.domain.version)), 64);
|
|
40
|
+
const struct = new Uint8Array(64);
|
|
41
|
+
struct.set(keccak_256(primaryType));
|
|
42
|
+
struct.set(hexToBytes(Object.values(data.message)[0]), 32);
|
|
43
|
+
const preimage = new Uint8Array(66);
|
|
44
|
+
preimage.set([EIP191_PREFIX, EIP712_VERSION]);
|
|
45
|
+
preimage.set(keccak_256(domain), 2);
|
|
46
|
+
preimage.set(keccak_256(struct), 34);
|
|
47
|
+
return keccak_256(preimage);
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=eip712.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eip712.js","sourceRoot":"","sources":["../../src/utils/eip712.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAGvD,MAAM,aAAa,GAAG,IAAI,CAAC;AAC3B,MAAM,cAAc,GAAG,IAAI,CAAC;AAC5B,MAAM,cAAc,GAAG,GAAG,CAAC;AAE3B,MAAM,YAAY,GAAiB;IACjC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE;IAChC,EAAE,IAAI,EAAE,SAAS,EAAE,IAA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
17
|
};
|
|
18
|
+
export declare function buildEip712SignatureAdviceEntry(pubkeyCommitment: Word, txSummaryCommitment: Word, signatureHex: string, publicKeyHex: string): {
|
|
19
|
+
key: Word;
|
|
20
|
+
values: Felt[];
|
|
21
|
+
};
|
|
18
22
|
/** Rejects unrecoverable ECDSA signatures before entering WASM. */
|
|
19
23
|
export declare function assertEcdsaSignatureRecoverable(signatureHex: string, messageHex: string, expectedPublicKeyHex: string): void;
|
|
20
24
|
export declare function tryComputeEcdsaCommitmentHex(pubkeyHex: string): string | null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signature.d.ts","sourceRoot":"","sources":["../../src/utils/signature.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,IAAI,EAAwB,SAAS,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"signature.d.ts","sourceRoot":"","sources":["../../src/utils/signature.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,IAAI,EAAwB,SAAS,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAO9F,OAAO,KAAK,EAAE,sBAAsB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE3E,eAAO,MAAM,oBAAoB,IAAI,CAAC;AACtC,eAAO,MAAM,qBAAqB,IAAI,CAAC;AAEvC,wBAAgB,YAAY,CAAC,MAAM,EAAE,eAAe,GAAG,MAAM,CAE5D;AAED,wBAAgB,mBAAmB,CACjC,GAAG,EAAE,MAAM,EACX,MAAM,GAAE,eAA0B,GACjC,UAAU,CAMZ;AAED;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CACvC,gBAAgB,EAAE,IAAI,EACtB,OAAO,EAAE,IAAI,EACb,SAAS,EAAE,SAAS,GACnB;IAAE,GAAG,EAAE,IAAI,CAAC;IAAC,MAAM,EAAE,IAAI,EAAE,CAAA;CAAE,CAQ/B;AAcD,wBAAgB,+BAA+B,CAC7C,gBAAgB,EAAE,IAAI,EACtB,mBAAmB,EAAE,IAAI,EACzB,YAAY,EAAE,MAAM,EACpB,YAAY,EAAE,MAAM,GACnB;IAAE,GAAG,EAAE,IAAI,CAAC;IAAC,MAAM,EAAE,IAAI,EAAE,CAAA;CAAE,CAmC/B;AAED,mEAAmE;AACnE,wBAAgB,+BAA+B,CAC7C,YAAY,EAAE,MAAM,EACpB,UAAU,EAAE,MAAM,EAClB,oBAAoB,EAAE,MAAM,GAC3B,IAAI,CAiBN;AAED,wBAAgB,4BAA4B,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAE7E;AAED,wBAAgB,uBAAuB,CACrC,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,eAAe,GACtB,MAAM,GAAG,IAAI,CAaf;AAED,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,SAAS,EACjB,OAAO,EAAE,KAAK,CAAC;IAAE,GAAG,EAAE,IAAI,CAAC;IAAC,MAAM,EAAE,IAAI,EAAE,CAAA;CAAE,CAAC,GAC5C,SAAS,CAKX;AAED,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAExC;AAED,wBAAgB,yBAAyB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAUlE;AAED,wBAAgB,qBAAqB,CACnC,SAAS,EAAE,sBAAsB,EACjC,iBAAiB,EAAE,GAAG,CAAC,MAAM,CAAC,GAC7B,sBAAsB,CAexB"}
|
package/dist/utils/signature.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import { FeltArray, Poseidon2, Word } from '@miden-sdk/miden-sdk';
|
|
1
|
+
import { Felt, FeltArray, Poseidon2, Word } from '@miden-sdk/miden-sdk';
|
|
2
2
|
import * as midenSdk from '@miden-sdk/miden-sdk';
|
|
3
3
|
import { EcdsaFormat } from './ecdsa.js';
|
|
4
|
+
import { midenTransactionTypedData, typedDataDigest } from './eip712.js';
|
|
4
5
|
import { hexToBytes, normalizeHexWord } from './encoding.js';
|
|
6
|
+
import { wordToBytes } from './word.js';
|
|
7
|
+
import { secp256k1 } from '@noble/curves/secp256k1';
|
|
5
8
|
export const ECDSA_AUTH_SCHEME_ID = 1;
|
|
6
9
|
export const FALCON_AUTH_SCHEME_ID = 2;
|
|
7
10
|
export function authSchemeId(scheme) {
|
|
@@ -29,6 +32,51 @@ export function buildSignatureAdviceEntry(pubkeyCommitment, message, signature)
|
|
|
29
32
|
const key = Poseidon2.hashElements(elements);
|
|
30
33
|
return { key, values: signature.toPreparedSignature(message) };
|
|
31
34
|
}
|
|
35
|
+
// Little-endian ASCII "EIP712", matching the protocol advice-key domain.
|
|
36
|
+
const EIP712_SIGNATURE_KEY_DOMAIN = 0x323137504945n;
|
|
37
|
+
function littleEndianU32Limbs(bytes) {
|
|
38
|
+
const limbs = [];
|
|
39
|
+
for (let i = 28; i >= 0; i -= 4) {
|
|
40
|
+
const limb = (bytes[i] << 24) | (bytes[i + 1] << 16) | (bytes[i + 2] << 8) | bytes[i + 3];
|
|
41
|
+
limbs.push(new Felt(BigInt(limb >>> 0)));
|
|
42
|
+
}
|
|
43
|
+
return limbs;
|
|
44
|
+
}
|
|
45
|
+
export function buildEip712SignatureAdviceEntry(pubkeyCommitment, txSummaryCommitment, signatureHex, publicKeyHex) {
|
|
46
|
+
const expectedCommitment = tryComputeEcdsaCommitmentHex(publicKeyHex);
|
|
47
|
+
if (expectedCommitment !== normalizeHexWord(pubkeyCommitment.toHex())) {
|
|
48
|
+
throw new Error('EIP-712 public key commitment mismatch');
|
|
49
|
+
}
|
|
50
|
+
const publicKey = secp256k1.ProjectivePoint.fromHex(publicKeyHex.replace(/^0x/i, ''));
|
|
51
|
+
const uncompressed = publicKey.toRawBytes(false);
|
|
52
|
+
const normalizedSignature = EcdsaFormat.normalizeRecoveryByte(signatureHex);
|
|
53
|
+
if (!/^0x[0-9a-fA-F]{130}$/.test(normalizedSignature)) {
|
|
54
|
+
throw new Error('EIP-712 signature must be 65 hex-encoded bytes');
|
|
55
|
+
}
|
|
56
|
+
const signature = hexToBytes(normalizedSignature);
|
|
57
|
+
if (signature.length !== 65 || (signature[64] !== 0 && signature[64] !== 1)) {
|
|
58
|
+
throw new Error('EIP-712 signature must contain a valid recovery ID');
|
|
59
|
+
}
|
|
60
|
+
const typedData = midenTransactionTypedData(wordToBytes(txSummaryCommitment));
|
|
61
|
+
if (!secp256k1.verify(signature.slice(0, 64), typedDataDigest(typedData), publicKey.toRawBytes(true))) {
|
|
62
|
+
throw new Error('EIP-712 signature does not match the transaction summary');
|
|
63
|
+
}
|
|
64
|
+
const rawKey = Poseidon2.hashElements(new FeltArray([
|
|
65
|
+
...pubkeyCommitment.toFelts(),
|
|
66
|
+
...txSummaryCommitment.toFelts(),
|
|
67
|
+
]));
|
|
68
|
+
const domain = new Word(new BigUint64Array([EIP712_SIGNATURE_KEY_DOMAIN, 0n, 0n, 0n]));
|
|
69
|
+
const key = Poseidon2.hashElements(new FeltArray([...rawKey.toFelts(), ...domain.toFelts()]));
|
|
70
|
+
return {
|
|
71
|
+
key,
|
|
72
|
+
values: [
|
|
73
|
+
...littleEndianU32Limbs(uncompressed.slice(1, 33)),
|
|
74
|
+
...littleEndianU32Limbs(uncompressed.slice(33, 65)),
|
|
75
|
+
...littleEndianU32Limbs(signature.slice(0, 32)),
|
|
76
|
+
...littleEndianU32Limbs(signature.slice(32, 64)),
|
|
77
|
+
],
|
|
78
|
+
};
|
|
79
|
+
}
|
|
32
80
|
/** Rejects unrecoverable ECDSA signatures before entering WASM. */
|
|
33
81
|
export function assertEcdsaSignatureRecoverable(signatureHex, messageHex, expectedPublicKeyHex) {
|
|
34
82
|
let recovered;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signature.js","sourceRoot":"","sources":["../../src/utils/signature.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"signature.js","sourceRoot":"","sources":["../../src/utils/signature.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,IA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AC,GAAG,CAAC,EAAE,CAAC;QACrD,MAAM,IAAI,KAAK,CAAC,yCAAyC,QAAQ,EAAE,CAAC,CAAC;IACvE,CAAC;IAED,OAAO,gBAAgB,CAAC,QAAQ,CAAC,CAAC;AACpC,CAAC;AAED,MAAM,UAAU,qBAAqB,CACnC,SAAiC,EACjC,iBAA8B;IAE9B,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,yBAAyB,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;QAC/D,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC;YACrC,MAAM,IAAI,KAAK,CAAC,UAAU,QAAQ,+BAA+B,CAAC,CAAC;QACrE,CAAC;QAED,OAAO;YACL,GAAG,SAAS;YACZ,QAAQ;SACT,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACvE,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;IAC3B,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openzeppelin/miden-multisig-client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.0-rc.2",
|
|
4
4
|
"description": "TypeScript SDK for Miden multisig accounts with GUARDIAN integration",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -34,23 +34,28 @@
|
|
|
34
34
|
"build": "tsc",
|
|
35
35
|
"dev": "tsc --watch",
|
|
36
36
|
"typecheck": "tsc --noEmit",
|
|
37
|
+
"typecheck:tests": "tsc --noEmit -p tsconfig.test.json",
|
|
37
38
|
"clean": "rm -rf dist",
|
|
38
39
|
"test": "vitest run",
|
|
39
40
|
"test:watch": "vitest",
|
|
40
|
-
"test:browser": "playwright test --config playwright.config.ts"
|
|
41
|
+
"test:browser": "playwright test --config playwright.config.ts",
|
|
42
|
+
"test:qualification": "vitest run --config vitest.qualification.config.ts"
|
|
41
43
|
},
|
|
42
44
|
"dependencies": {
|
|
43
|
-
"@miden-sdk/miden-sdk": "0.
|
|
45
|
+
"@miden-sdk/miden-sdk": "0.17.0-rc.4",
|
|
44
46
|
"@noble/curves": "^1.9.7",
|
|
45
47
|
"@noble/hashes": "^2.0.1",
|
|
46
|
-
"@openzeppelin/guardian-client": "^0.
|
|
48
|
+
"@openzeppelin/guardian-client": "^0.18.0-rc.2"
|
|
47
49
|
},
|
|
48
50
|
"devDependencies": {
|
|
51
|
+
"@openzeppelin/guardian-operator-client": "^0.18.0-rc.2",
|
|
49
52
|
"@playwright/test": "^1.60.0",
|
|
53
|
+
"@types/node": "^24.13.5",
|
|
50
54
|
"fake-indexeddb": "^6.2.5",
|
|
55
|
+
"viem": "^2.47.5",
|
|
51
56
|
"typescript": "^5.7.2",
|
|
52
|
-
"vite": "^
|
|
53
|
-
"vitest": "^
|
|
57
|
+
"vite": "^6.4.3",
|
|
58
|
+
"vitest": "^5.0.0"
|
|
54
59
|
},
|
|
55
60
|
"engines": {
|
|
56
61
|
"node": ">=18"
|
package/src/account/builder.ts
CHANGED
|
@@ -15,6 +15,8 @@ import {
|
|
|
15
15
|
type MidenClient,
|
|
16
16
|
} from "@miden-sdk/miden-sdk";
|
|
17
17
|
import { getProcedureRoot } from "../procedures.js";
|
|
18
|
+
import { isPublicMidenClient, type RawClientSource } from "../raw-client.js";
|
|
19
|
+
import { MAX_SIGNERS } from "./layout.js";
|
|
18
20
|
import type { MultisigConfig, CreateAccountResult } from "../types.js";
|
|
19
21
|
import { normalizeSignerCommitment } from "../utils/signature.js";
|
|
20
22
|
|
|
@@ -82,13 +84,13 @@ function buildGuardedMultisigComponent(
|
|
|
82
84
|
/**
|
|
83
85
|
* Creates a multisig account with GUARDIAN authentication.
|
|
84
86
|
*
|
|
85
|
-
* @param
|
|
87
|
+
* @param client - Initialized MidenClient, or the WASM client behind one
|
|
86
88
|
* @param config - Multisig configuration
|
|
87
|
-
* @param midenRpcEndpoint - RPC endpoint for the
|
|
89
|
+
* @param midenRpcEndpoint - RPC endpoint for the client's network
|
|
88
90
|
* @returns The created account and seed
|
|
89
91
|
*/
|
|
90
92
|
export async function createMultisigAccount(
|
|
91
|
-
|
|
93
|
+
client: RawClientSource,
|
|
92
94
|
config: MultisigConfig,
|
|
93
95
|
midenRpcEndpoint: string,
|
|
94
96
|
): Promise<CreateAccountResult> {
|
|
@@ -115,10 +117,14 @@ export async function createMultisigAccount(
|
|
|
115
117
|
|
|
116
118
|
const result = accountBuilder.buildWithoutSchemaCommitment();
|
|
117
119
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
120
|
+
if (isPublicMidenClient(client)) {
|
|
121
|
+
await client.accounts.insert({
|
|
122
|
+
account: result.account,
|
|
123
|
+
overwrite: false,
|
|
124
|
+
});
|
|
125
|
+
} else {
|
|
126
|
+
await client.newAccount(result.account, false);
|
|
127
|
+
}
|
|
122
128
|
|
|
123
129
|
return {
|
|
124
130
|
account: result.account,
|
|
@@ -149,6 +155,11 @@ export function validateMultisigConfig(config: MultisigConfig): void {
|
|
|
149
155
|
signerCommitments.add(normalizedCommitment);
|
|
150
156
|
}
|
|
151
157
|
|
|
158
|
+
if (config.signerCommitments.length > MAX_SIGNERS) {
|
|
159
|
+
throw new Error(
|
|
160
|
+
`too many signers (${config.signerCommitments.length}): a multisig account holds at most ${MAX_SIGNERS}`,
|
|
161
|
+
);
|
|
162
|
+
}
|
|
152
163
|
if (config.threshold > config.signerCommitments.length) {
|
|
153
164
|
throw new Error(
|
|
154
165
|
`threshold (${config.threshold}) cannot exceed number of signers (${config.signerCommitments.length})`,
|
package/src/account/layout.ts
CHANGED
|
@@ -25,9 +25,9 @@ export const GUARDIAN_SLOT_NAMES = {
|
|
|
25
25
|
} as const;
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
28
|
+
* The most approvers a multisig account can hold: `ApproverSet::MAX_APPROVERS`
|
|
29
|
+
* in miden-standards, enforced at account creation and again on-chain by
|
|
30
|
+
* `update_signers_and_threshold`. Readers bound their loops with it, so a
|
|
31
|
+
* corrupt `threshold_config` cannot drive an unbounded storage walk.
|
|
32
32
|
*/
|
|
33
|
-
export const MAX_SIGNERS =
|
|
33
|
+
export const MAX_SIGNERS = 64;
|
package/src/client.ts
CHANGED
|
@@ -13,6 +13,8 @@ import { createMultisigAccount } from './account/index.js';
|
|
|
13
13
|
import { AccountInspector, assertCompleteDetectedConfig } from './inspector.js';
|
|
14
14
|
import { getRawMidenClient, requireConfigValue, requireMidenRpcEndpoint } from './raw-client.js';
|
|
15
15
|
import type { MultisigConfig, Signer } from './types.js';
|
|
16
|
+
import { isSafeToAdoptGuardianState, readOnChainCommitment } from './state/adopt.js';
|
|
17
|
+
import { normalizeHexWord } from './utils/encoding.js';
|
|
16
18
|
import {
|
|
17
19
|
resolveProverConfig,
|
|
18
20
|
type ProverConfig,
|
|
@@ -141,7 +143,7 @@ export class MultisigClient {
|
|
|
141
143
|
* which would fail authentication first).
|
|
142
144
|
*
|
|
143
145
|
* @throws if `signer` does not implement `signLookupMessage`. The bundled
|
|
144
|
-
* `FalconSigner` and `
|
|
146
|
+
* `FalconSigner`, `EcdsaSigner`, and `LedgerSigner` do.
|
|
145
147
|
*/
|
|
146
148
|
async recoverByKey(signer: Signer): Promise<RecoveredAccount[]> {
|
|
147
149
|
this._guardianClient.setSigner(signer);
|
|
@@ -211,7 +213,9 @@ export class MultisigClient {
|
|
|
211
213
|
for (let i = 0; i < binaryString.length; i++) {
|
|
212
214
|
accountBytes[i] = binaryString.charCodeAt(i);
|
|
213
215
|
}
|
|
214
|
-
const
|
|
216
|
+
const incomingAccount = Account.deserialize(accountBytes);
|
|
217
|
+
|
|
218
|
+
const account = await this.adoptGuardianAccount(accountId, incomingAccount);
|
|
215
219
|
|
|
216
220
|
const detected = AccountInspector.fromAccount(account);
|
|
217
221
|
// Fail closed on a partial read: the detected signer set becomes the
|
|
@@ -226,10 +230,6 @@ export class MultisigClient {
|
|
|
226
230
|
),
|
|
227
231
|
};
|
|
228
232
|
|
|
229
|
-
const existingAccount = await this.midenClient.accounts.get(AccountId.fromHex(accountId));
|
|
230
|
-
if (!existingAccount) {
|
|
231
|
-
await this.midenClient.accounts.insert({ account, overwrite: true });
|
|
232
|
-
}
|
|
233
233
|
await bindSignerAccountKey(signer, this.midenClient, accountId);
|
|
234
234
|
|
|
235
235
|
return new Multisig(
|
|
@@ -244,4 +244,92 @@ export class MultisigClient {
|
|
|
244
244
|
this.rpcConfig,
|
|
245
245
|
);
|
|
246
246
|
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Reconcile the account GUARDIAN returned with the local store, and answer
|
|
250
|
+
* with the one that is actually current.
|
|
251
|
+
*
|
|
252
|
+
* Writing GUARDIAN's account only when the store held nothing meant a caller
|
|
253
|
+
* that already had the account kept its own copy while the returned
|
|
254
|
+
* `Multisig` carried a config derived from GUARDIAN's. One object, two
|
|
255
|
+
* sources, silently disagreeing: after a membership change the config said
|
|
256
|
+
* one thing and every account read said another, with no error.
|
|
257
|
+
*
|
|
258
|
+
* Overwriting unconditionally is not the fix either. Between pushing a delta
|
|
259
|
+
* and GUARDIAN canonicalizing it, local is legitimately ahead, and clobbering
|
|
260
|
+
* it would build the next transaction on a stale nonce. So this applies the
|
|
261
|
+
* same rule `syncState` does, and returns whichever account wins so the
|
|
262
|
+
* caller describes the state it will actually read.
|
|
263
|
+
*/
|
|
264
|
+
private async adoptGuardianAccount(
|
|
265
|
+
accountId: string,
|
|
266
|
+
incomingAccount: Account,
|
|
267
|
+
): Promise<Account> {
|
|
268
|
+
const localAccount = await this.midenClient.accounts.get(AccountId.fromHex(accountId));
|
|
269
|
+
if (!localAccount) {
|
|
270
|
+
// Still checked against chain, and through the same rule the other path
|
|
271
|
+
// uses. An empty store is the ordinary shape for loading an account this
|
|
272
|
+
// client has never held, so inserting without the check would make it the
|
|
273
|
+
// one path where GUARDIAN's word is taken on its own. Checking only that
|
|
274
|
+
// *some* commitment exists is not the check: it admits state that
|
|
275
|
+
// disagrees with chain, which is the thing being guarded against.
|
|
276
|
+
// Only for an account that has transacted. One that has not is not
|
|
277
|
+
// deployed, so there is no on-chain commitment to agree or disagree with,
|
|
278
|
+
// and reading the node for one would make loading a fresh account depend
|
|
279
|
+
// on the node as well as on GUARDIAN.
|
|
280
|
+
const transacted = incomingAccount.nonce().asInt() > BigInt(0);
|
|
281
|
+
const onChain = transacted
|
|
282
|
+
? await readOnChainCommitment(
|
|
283
|
+
this.midenRpcEndpoint,
|
|
284
|
+
AccountId.fromHex(accountId),
|
|
285
|
+
this.rpcConfig,
|
|
286
|
+
)
|
|
287
|
+
: null;
|
|
288
|
+
// The one rule the shared predicate cannot apply here. It keys its
|
|
289
|
+
// null-commitment guard on the *local* nonce, because `syncState`
|
|
290
|
+
// legitimately meets a higher incoming nonce with no local history. With
|
|
291
|
+
// no local record at all, the incoming nonce is the only evidence there
|
|
292
|
+
// is: an account GUARDIAN reports as having transacted is deployed, so a
|
|
293
|
+
// node reporting nothing for it is an RPC or gateway failure rather than
|
|
294
|
+
// an undeployed account. `readOnChainCommitment` reports a missing
|
|
295
|
+
// account by matching `not found`, which a 404 also says.
|
|
296
|
+
if (transacted && !onChain) {
|
|
297
|
+
throw new Error(
|
|
298
|
+
`Refusing to adopt GUARDIAN state for ${accountId}: it has transacted (nonce ${incomingAccount.nonce().asInt().toString()}) but the node reported no on-chain commitment, so it could not be checked against chain`
|
|
299
|
+
);
|
|
300
|
+
}
|
|
301
|
+
// Handed the commitment already read, rather than letting the predicate
|
|
302
|
+
// read it again: two reads can disagree, and the guard above would then
|
|
303
|
+
// have passed on a different answer than the comparison rejects.
|
|
304
|
+
await isSafeToAdoptGuardianState({
|
|
305
|
+
accountId,
|
|
306
|
+
incomingAccount,
|
|
307
|
+
readCommitment: () => Promise.resolve(onChain),
|
|
308
|
+
});
|
|
309
|
+
await this.midenClient.accounts.insert({ account: incomingAccount, overwrite: true });
|
|
310
|
+
return incomingAccount;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
const localCommitment = normalizeHexWord(localAccount.to_commitment().toHex());
|
|
314
|
+
const incomingCommitment = normalizeHexWord(incomingAccount.to_commitment().toHex());
|
|
315
|
+
// Equal commitments are the same state, and the safety rule reads an equal
|
|
316
|
+
// nonce as divergence, so it must not be asked about a pair that agrees.
|
|
317
|
+
if (localCommitment === incomingCommitment) {
|
|
318
|
+
return localAccount;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
const adopt = await isSafeToAdoptGuardianState({
|
|
322
|
+
accountId,
|
|
323
|
+
incomingAccount,
|
|
324
|
+
localAccount,
|
|
325
|
+
readCommitment: () =>
|
|
326
|
+
readOnChainCommitment(this.midenRpcEndpoint, AccountId.fromHex(accountId), this.rpcConfig),
|
|
327
|
+
});
|
|
328
|
+
if (!adopt) {
|
|
329
|
+
return localAccount;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
await this.midenClient.accounts.insert({ account: incomingAccount, overwrite: true });
|
|
333
|
+
return incomingAccount;
|
|
334
|
+
}
|
|
247
335
|
}
|
package/src/index.ts
CHANGED
|
@@ -65,16 +65,25 @@ export {
|
|
|
65
65
|
} from './multisig.js';
|
|
66
66
|
export { AccountInspector, type DetectedMultisigConfig, type VaultBalance } from './inspector.js';
|
|
67
67
|
export {
|
|
68
|
+
ChainBehindBoundBlockError,
|
|
68
69
|
chainAnchorFromBase64,
|
|
69
70
|
chainAnchorToBase64,
|
|
71
|
+
chainAnchorBlockNum,
|
|
70
72
|
executeForSummary,
|
|
71
73
|
executeForSummaryAt,
|
|
72
|
-
|
|
74
|
+
executeForSummaryAtTip,
|
|
75
|
+
summaryApprovalExpirationBlockNum,
|
|
76
|
+
summarySalt,
|
|
77
|
+
SummaryAnchorMismatchError,
|
|
73
78
|
buildUpdateSignersTransactionRequest,
|
|
74
79
|
buildUpdateProcedureThresholdTransactionRequest,
|
|
75
80
|
buildUpdateGuardianTransactionRequest,
|
|
76
81
|
buildConsumeNotesTransactionRequest,
|
|
82
|
+
buildConsumeNotesTransactionRequestFromNotes,
|
|
77
83
|
buildP2idTransactionRequest,
|
|
84
|
+
requestBoundBlockNum,
|
|
85
|
+
requestSaltHex,
|
|
86
|
+
MAX_APPROVAL_EXPIRATION_DELTA,
|
|
78
87
|
parseP2idNoteType,
|
|
79
88
|
p2idNoteTypeToMetadata,
|
|
80
89
|
type P2idTransactionOptions,
|
|
@@ -85,7 +94,12 @@ export {
|
|
|
85
94
|
// serialized summary exactly as import verification does. Returns normalized
|
|
86
95
|
// hex, directly comparable to `ExportedProposal.commitment` / `Proposal.id`.
|
|
87
96
|
export { computeCommitmentFromTxSummary } from './multisig/helpers.js';
|
|
88
|
-
export type {
|
|
97
|
+
export type {
|
|
98
|
+
MidenClientMultisigRequestOptions,
|
|
99
|
+
MidenClientSignatureOptions,
|
|
100
|
+
MultisigRequestOptions,
|
|
101
|
+
SignatureOptions,
|
|
102
|
+
} from './transaction/options.js';
|
|
89
103
|
|
|
90
104
|
export { GuardianHttpClient, GuardianHttpError } from '@openzeppelin/guardian-client';
|
|
91
105
|
export type { GuardianErrorMeta } from '@openzeppelin/guardian-client';
|
|
@@ -134,9 +148,12 @@ export type {
|
|
|
134
148
|
export {
|
|
135
149
|
FalconSigner,
|
|
136
150
|
EcdsaSigner,
|
|
151
|
+
Eip712Signer,
|
|
152
|
+
LedgerSigner,
|
|
137
153
|
ParaSigner,
|
|
138
154
|
MidenWalletSigner,
|
|
139
155
|
type ParaSigningContext,
|
|
156
|
+
type Eip1193SignerProvider,
|
|
140
157
|
type WalletSigningContext,
|
|
141
158
|
} from './signer.js';
|
|
142
159
|
export { PublicKeyFormat } from './utils/key.js';
|
|
@@ -157,6 +174,8 @@ export {
|
|
|
157
174
|
MAX_CONSUME_NOTES_METADATA_BYTES,
|
|
158
175
|
isConsumeNotesV1,
|
|
159
176
|
isConsumeNotesV2,
|
|
177
|
+
isProposalActionable,
|
|
178
|
+
type ProposalVerification,
|
|
160
179
|
isP2idNoteVisibility,
|
|
161
180
|
type P2idNoteVisibility,
|
|
162
181
|
MAX_P2IDE_BLOCK_HEIGHT,
|
|
@@ -173,11 +192,13 @@ export {
|
|
|
173
192
|
UnsupportedMetadataVersionError,
|
|
174
193
|
ConsumeNotesMetadataOversizeError,
|
|
175
194
|
LegacyConsumeNotesNoteMissingError,
|
|
195
|
+
ConsumeNoteNotAuthenticatedError,
|
|
176
196
|
} from './multisig/consumeNotesErrors.js';
|
|
177
197
|
|
|
178
198
|
export {
|
|
179
199
|
type AuthArgErrorCode,
|
|
180
|
-
|
|
200
|
+
BoundBlockNotDeclaredError,
|
|
201
|
+
MultisigAuthArgsMissingError,
|
|
181
202
|
ProposalSaltMalformedError,
|
|
182
203
|
} from './multisig/authArgErrors.js';
|
|
183
204
|
|