@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
package/dist/retry/classify.d.ts
CHANGED
|
@@ -6,6 +6,9 @@
|
|
|
6
6
|
* transient-wording fallback fires only when no status-level evidence exists
|
|
7
7
|
* in any link. Behavior is pinned by the cross-SDK fixture corpus.
|
|
8
8
|
*/
|
|
9
|
+
export type StructuredEvidence = 'transient' | 'permanent' | 'indeterminate';
|
|
10
|
+
export declare function httpMessageEvidence(message: string): StructuredEvidence | undefined;
|
|
11
|
+
export declare function grpcMessageEvidence(message: string): StructuredEvidence | undefined;
|
|
9
12
|
/**
|
|
10
13
|
* Walks the error's cause chain and reports whether every piece of evidence
|
|
11
14
|
* points at a transient failure. `extraTransientSignals` extends the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"classify.d.ts","sourceRoot":"","sources":["../../src/retry/classify.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;
|
|
1
|
+
{"version":3,"file":"classify.d.ts","sourceRoot":"","sources":["../../src/retry/classify.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAUH,MAAM,MAAM,kBAAkB,GAAG,WAAW,GAAG,WAAW,GAAG,eAAe,CAAC;AAiF7E,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,kBAAkB,GAAG,SAAS,CAYnF;AAED,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,kBAAkB,GAAG,SAAS,CAYnF;AAiCD;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,OAAO,EACd,qBAAqB,GAAE,SAAS,MAAM,EAAO,GAC5C,OAAO,CAqDT"}
|
package/dist/retry/classify.js
CHANGED
|
@@ -78,7 +78,7 @@ function httpEvidence(value) {
|
|
|
78
78
|
}
|
|
79
79
|
return TRANSIENT_HTTP.has(value) ? 'transient' : 'permanent';
|
|
80
80
|
}
|
|
81
|
-
function httpMessageEvidence(message) {
|
|
81
|
+
export function httpMessageEvidence(message) {
|
|
82
82
|
let hasTransient = false;
|
|
83
83
|
for (const match of message.matchAll(/(?:\bhttp(?:\s+status)?|\bstatus)(?:\s+code)?\s*:?\s*(\d{3})\b/g)) {
|
|
84
84
|
const evidence = httpEvidence(Number(match[1]));
|
|
@@ -89,7 +89,7 @@ function httpMessageEvidence(message) {
|
|
|
89
89
|
}
|
|
90
90
|
return hasTransient ? 'transient' : undefined;
|
|
91
91
|
}
|
|
92
|
-
function grpcMessageEvidence(message) {
|
|
92
|
+
export function grpcMessageEvidence(message) {
|
|
93
93
|
const normalized = message.replaceAll(/[^a-z0-9]/g, '');
|
|
94
94
|
let hasTransient = false;
|
|
95
95
|
for (const { token, evidence } of GRPC_MESSAGE_TOKENS) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"classify.js","sourceRoot":"","sources":["../../src/retry/classify.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAYH,MAAM,cAAc,GAAG,IAAI,GAAG,CAAC;IAC7B,WAAW;IACX,UAAU;IACV,kBAAkB;IAClB,aAAa;IACb,mBAAmB;CACpB,CAAC,CAAC;AAEH,MAAM,cAAc,GAAG,IAAI,GAAG,CAAC;IAC7B,iBAAiB;IACjB,oBAAoB;IACpB,kBAAkB;IAClB,iBAAiB;IACjB,UAAU;IACV,eAAe;IACf,YAAY;IACZ,eAAe;IAC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cdsaSigner } from './signers/ecdsa.js';
|
|
3
|
+
export { Eip712Signer, LedgerSigner, type Eip1193SignerProvider } from './signers/ledger.js';
|
|
3
4
|
export { ParaSigner, type ParaSigningContext } from './signers/para.js';
|
|
4
5
|
export { MidenWalletSigner, type WalletSigningContext } from './signers/miden-wallet.js';
|
|
5
6
|
//# sourceMappingURL=signer.d.ts.map
|
package/dist/signer.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signer.d.ts","sourceRoot":"","sources":["../src/signer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,KAAK,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACxE,OAAO,EAAE,iBAAiB,EAAE,KAAK,oBAAoB,EAAE,MAAM,2BAA2B,CAAC"}
|
|
1
|
+
{"version":3,"file":"signer.d.ts","sourceRoot":"","sources":["../src/signer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,KAAK,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAC7F,OAAO,EAAE,UAAU,EAAE,KAAK,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACxE,OAAO,EAAE,iBAAiB,EAAE,KAAK,oBAAoB,EAAE,MAAM,2BAA2B,CAAC"}
|
package/dist/signer.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { FalconSigner } from './signers/falcon.js';
|
|
2
2
|
export { EcdsaSigner } from './signers/ecdsa.js';
|
|
3
|
+
export { Eip712Signer, LedgerSigner } from './signers/ledger.js';
|
|
3
4
|
export { ParaSigner } from './signers/para.js';
|
|
4
5
|
export { MidenWalletSigner } from './signers/miden-wallet.js';
|
|
5
6
|
//# sourceMappingURL=signer.js.map
|
package/dist/signer.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signer.js","sourceRoot":"","sources":["../src/signer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,UAAU,EAA2B,MAAM,mBAAmB,CAAC;AACxE,OAAO,EAAE,iBAAiB,EAA6B,MAAM,2BAA2B,CAAC"}
|
|
1
|
+
{"version":3,"file":"signer.js","sourceRoot":"","sources":["../src/signer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,YAAY,EAA8B,MAAM,qBAAqB,CAAC;AAC7F,OAAO,EAAE,UAAU,EAA2B,MAAM,mBAAmB,CAAC;AACxE,OAAO,EAAE,iBAAiB,EAA6B,MAAM,2BAA2B,CAAC"}
|
package/dist/signers/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { FalconSigner } from './falcon.js';
|
|
2
2
|
export { EcdsaSigner } from './ecdsa.js';
|
|
3
|
+
export { Eip712Signer, LedgerSigner, type Eip1193SignerProvider } from './ledger.js';
|
|
3
4
|
export { ParaSigner, type ParaSigningContext } from './para.js';
|
|
4
5
|
export { MidenWalletSigner, type WalletSigningContext } from './miden-wallet.js';
|
|
5
6
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/signers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,KAAK,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAChE,OAAO,EAAE,iBAAiB,EAAE,KAAK,oBAAoB,EAAE,MAAM,mBAAmB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/signers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,KAAK,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACrF,OAAO,EAAE,UAAU,EAAE,KAAK,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAChE,OAAO,EAAE,iBAAiB,EAAE,KAAK,oBAAoB,EAAE,MAAM,mBAAmB,CAAC"}
|
package/dist/signers/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { FalconSigner } from './falcon.js';
|
|
2
2
|
export { EcdsaSigner } from './ecdsa.js';
|
|
3
|
+
export { Eip712Signer, LedgerSigner } from './ledger.js';
|
|
3
4
|
export { ParaSigner } from './para.js';
|
|
4
5
|
export { MidenWalletSigner } from './miden-wallet.js';
|
|
5
6
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/signers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,UAAU,EAA2B,MAAM,WAAW,CAAC;AAChE,OAAO,EAAE,iBAAiB,EAA6B,MAAM,mBAAmB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/signers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,YAAY,EAA8B,MAAM,aAAa,CAAC;AACrF,OAAO,EAAE,UAAU,EAA2B,MAAM,WAAW,CAAC;AAChE,OAAO,EAAE,iBAAiB,EAA6B,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { RequestAuthPayload, Signer } from '@openzeppelin/guardian-client';
|
|
2
|
+
export interface Eip1193SignerProvider {
|
|
3
|
+
request(args: {
|
|
4
|
+
method: string;
|
|
5
|
+
params: unknown[];
|
|
6
|
+
}): Promise<unknown>;
|
|
7
|
+
}
|
|
8
|
+
export declare class Eip712Signer implements Signer {
|
|
9
|
+
private readonly provider;
|
|
10
|
+
readonly scheme = "ecdsa";
|
|
11
|
+
readonly requestAuthFormat = "eip712";
|
|
12
|
+
readonly proposalMessageFormat = "eip712";
|
|
13
|
+
readonly publicKey: string;
|
|
14
|
+
readonly commitment: string;
|
|
15
|
+
readonly address: string;
|
|
16
|
+
static connect(provider: Eip1193SignerProvider): Promise<Eip712Signer>;
|
|
17
|
+
constructor(provider: Eip1193SignerProvider, publicKey: string, address: string);
|
|
18
|
+
signAccountIdWithTimestamp(): Promise<string>;
|
|
19
|
+
signRequest(accountId: string, timestamp: number, requestPayload: RequestAuthPayload): Promise<string>;
|
|
20
|
+
signLookupMessage(keyCommitmentHex: string, timestampMs: number): Promise<string>;
|
|
21
|
+
signCommitment(commitmentHex: string): Promise<string>;
|
|
22
|
+
private signTypedData;
|
|
23
|
+
}
|
|
24
|
+
export { Eip712Signer as LedgerSigner };
|
|
25
|
+
//# sourceMappingURL=ledger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ledger.d.ts","sourceRoot":"","sources":["../../src/signers/ledger.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,EAAE,MAAM,+BAA+B,CAAC;AAehF,MAAM,WAAW,qBAAqB;IACpC,OAAO,CAAC,IAAI,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,OAAO,EAAE,CAAA;KAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CACxE;AAED,qBAAa,YAAa,YAAW,MAAM;IAmCvC,OAAO,CAAC,QAAQ,CAAC,QAAQ;IAlC3B,QAAQ,CAAC,MAAM,WAAW;IAC1B,QAAQ,CAAC,iBAAiB,YAAY;IACtC,QAAQ,CAAC,qBAAqB,YAAY;IAC1C,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;WAEZ,OAAO,CAAC,QAAQ,EAAE,qBAAqB,GAAG,OAAO,CAAC,YAAY,CAAC;gBA2BzD,QAAQ,EAAE,qBAAqB,EAChD,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM;IAoBjB,0BAA0B,IAAI,OAAO,CAAC,MAAM,CAAC;IAIvC,WAAW,CACf,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,EACjB,cAAc,EAAE,kBAAkB,GACjC,OAAO,CAAC,MAAM,CAAC;IAKZ,iBAAiB,CAAC,gBAAgB,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAKjF,cAAc,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;YAK9C,aAAa;CAkB5B;AAED,OAAO,EAAE,YAAY,IAAI,YAAY,EAAE,CAAC"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { secp256k1 } from '@noble/curves/secp256k1';
|
|
2
|
+
import { keccak_256 } from '@noble/hashes/sha3.js';
|
|
3
|
+
import { AuthDigest } from '../utils/digest.js';
|
|
4
|
+
import { lookupAuthDigest } from '../lookupAuth.js';
|
|
5
|
+
import { EcdsaFormat } from '../utils/ecdsa.js';
|
|
6
|
+
import { bytesToHex, hexToBytes } from '../utils/encoding.js';
|
|
7
|
+
import { guardianKeyDiscoveryTypedData, guardianLookupTypedData, guardianRequestTypedData, midenTransactionTypedData, typedDataDigest, } from '../utils/eip712.js';
|
|
8
|
+
import { tryComputeEcdsaCommitmentHex } from '../utils/signature.js';
|
|
9
|
+
import { wordToBytes } from '../utils/word.js';
|
|
10
|
+
export class Eip712Signer {
|
|
11
|
+
provider;
|
|
12
|
+
scheme = 'ecdsa';
|
|
13
|
+
requestAuthFormat = 'eip712';
|
|
14
|
+
proposalMessageFormat = 'eip712';
|
|
15
|
+
publicKey;
|
|
16
|
+
commitment;
|
|
17
|
+
address;
|
|
18
|
+
static async connect(provider) {
|
|
19
|
+
const accounts = await provider.request({ method: 'eth_requestAccounts', params: [] });
|
|
20
|
+
if (!Array.isArray(accounts) || typeof accounts[0] !== 'string') {
|
|
21
|
+
throw new Error('Wallet did not provide an Ethereum address');
|
|
22
|
+
}
|
|
23
|
+
const address = accounts[0];
|
|
24
|
+
const challenge = crypto.getRandomValues(new Uint8Array(32));
|
|
25
|
+
const data = guardianKeyDiscoveryTypedData(challenge);
|
|
26
|
+
const result = await provider.request({
|
|
27
|
+
method: 'eth_signTypedData_v4',
|
|
28
|
+
params: [address, JSON.stringify(data)],
|
|
29
|
+
});
|
|
30
|
+
if (typeof result !== 'string' || !/^0x[0-9a-fA-F]{130}$/.test(result)) {
|
|
31
|
+
throw new Error('Wallet returned an invalid key-discovery signature');
|
|
32
|
+
}
|
|
33
|
+
const signature = hexToBytes(EcdsaFormat.normalizeRecoveryByte(result));
|
|
34
|
+
if (signature[64] !== 0 && signature[64] !== 1) {
|
|
35
|
+
throw new Error('Wallet returned an invalid recovery ID');
|
|
36
|
+
}
|
|
37
|
+
const publicKey = secp256k1.Signature.fromCompact(signature.slice(0, 64))
|
|
38
|
+
.addRecoveryBit(signature[64])
|
|
39
|
+
.recoverPublicKey(typedDataDigest(data))
|
|
40
|
+
.toRawBytes(true);
|
|
41
|
+
return new Eip712Signer(provider, bytesToHex(publicKey), address);
|
|
42
|
+
}
|
|
43
|
+
constructor(provider, publicKey, address) {
|
|
44
|
+
this.provider = provider;
|
|
45
|
+
if (!EcdsaFormat.isValidPublicKeyPoint(publicKey)) {
|
|
46
|
+
throw new Error('Invalid wallet public key');
|
|
47
|
+
}
|
|
48
|
+
this.publicKey = EcdsaFormat.compressPublicKey(publicKey);
|
|
49
|
+
const commitment = tryComputeEcdsaCommitmentHex(this.publicKey);
|
|
50
|
+
if (!commitment) {
|
|
51
|
+
throw new Error('Cannot derive the Miden commitment for the wallet public key');
|
|
52
|
+
}
|
|
53
|
+
this.commitment = commitment;
|
|
54
|
+
const uncompressed = secp256k1.ProjectivePoint.fromHex(this.publicKey.slice(2)).toRawBytes(false);
|
|
55
|
+
const derivedAddress = bytesToHex(keccak_256(uncompressed.slice(1)).slice(-20));
|
|
56
|
+
if (derivedAddress.toLowerCase() !== address.toLowerCase()) {
|
|
57
|
+
throw new Error('Wallet address does not match its public key');
|
|
58
|
+
}
|
|
59
|
+
this.address = address;
|
|
60
|
+
}
|
|
61
|
+
signAccountIdWithTimestamp() {
|
|
62
|
+
throw new Error('Eip712Signer requires request-bound Guardian authentication');
|
|
63
|
+
}
|
|
64
|
+
async signRequest(accountId, timestamp, requestPayload) {
|
|
65
|
+
const requestHash = AuthDigest.fromRequest(accountId, timestamp, requestPayload);
|
|
66
|
+
return this.signTypedData(guardianRequestTypedData(wordToBytes(requestHash)));
|
|
67
|
+
}
|
|
68
|
+
async signLookupMessage(keyCommitmentHex, timestampMs) {
|
|
69
|
+
const lookupHash = lookupAuthDigest(timestampMs, keyCommitmentHex);
|
|
70
|
+
return this.signTypedData(guardianLookupTypedData(wordToBytes(lookupHash)));
|
|
71
|
+
}
|
|
72
|
+
async signCommitment(commitmentHex) {
|
|
73
|
+
const commitment = AuthDigest.fromCommitmentHex(commitmentHex);
|
|
74
|
+
return this.signTypedData(midenTransactionTypedData(wordToBytes(commitment)));
|
|
75
|
+
}
|
|
76
|
+
async signTypedData(data) {
|
|
77
|
+
const result = await this.provider.request({
|
|
78
|
+
method: 'eth_signTypedData_v4',
|
|
79
|
+
params: [this.address, JSON.stringify(data)],
|
|
80
|
+
});
|
|
81
|
+
if (typeof result !== 'string' || !/^0x[0-9a-fA-F]{130}$/.test(result)) {
|
|
82
|
+
throw new Error('Wallet returned an invalid EIP-712 signature');
|
|
83
|
+
}
|
|
84
|
+
const signatureHex = EcdsaFormat.normalizeRecoveryByte(result);
|
|
85
|
+
const signature = hexToBytes(signatureHex);
|
|
86
|
+
if (signature[64] !== 0 && signature[64] !== 1) {
|
|
87
|
+
throw new Error('Wallet returned an invalid ECDSA recovery ID');
|
|
88
|
+
}
|
|
89
|
+
if (!secp256k1.verify(signature.slice(0, 64), typedDataDigest(data), hexToBytes(this.publicKey))) {
|
|
90
|
+
throw new Error('Wallet signature was produced by a different key');
|
|
91
|
+
}
|
|
92
|
+
return signatureHex;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
export { Eip712Signer as LedgerSigner };
|
|
96
|
+
//# sourceMappingURL=ledger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ledger.js","sourceRoot":"","sources":["../../src/signers/ledger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAEnD,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EACL,6BAA6B,EAC7B,uBAAuB,EACvB,wBAAwB,EACxB,yBAA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YACzC,MAAM,EAAE,sBAAsB;YAC9B,MAAM,EAAE,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;SAC7C,CAAC,CAAC;QACH,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,CAAC,sBAAsB,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;YACvE,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;QAClE,CAAC;QACD,MAAM,YAAY,GAAG,WAAW,CAAC,qBAAqB,CAAC,MAAM,CAAC,CAAC;QAC/D,MAAM,SAAS,GAAG,UAAU,CAAC,YAAY,CAAC,CAAC;QAC3C,IAAI,SAAS,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,SAAS,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC;YAC/C,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;QAClE,CAAC;QACD,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,eAAe,CAAC,IAAI,CAAC,EAAE,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC;YACjG,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;QACtE,CAAC;QACD,OAAO,YAAY,CAAC;IACtB,CAAC;CACF;AAED,OAAO,EAAE,YAAY,IAAI,YAAY,EAAE,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deciding when GUARDIAN-provided account state may replace the local store.
|
|
3
|
+
*
|
|
4
|
+
* Both entry points that pull an account from GUARDIAN need this: `syncState`,
|
|
5
|
+
* which refreshes an account already in hand, and `MultisigClient.load`, which
|
|
6
|
+
* rebuilds one. Sharing the rule is the point. Deciding it twice is how the two
|
|
7
|
+
* paths came to disagree, with `load` keeping whatever the store held whenever
|
|
8
|
+
* it held anything, so a caller that had touched the account before read stale
|
|
9
|
+
* state with no error.
|
|
10
|
+
*/
|
|
11
|
+
import { Account, AccountId } from '@miden-sdk/miden-sdk';
|
|
12
|
+
import type { ResolvedRpcConfig } from '../rpc/config.js';
|
|
13
|
+
/**
|
|
14
|
+
* The account's commitment as the node reports it, or `null` when the account
|
|
15
|
+
* is not deployed yet. An undeployed account is not an error: it has no
|
|
16
|
+
* on-chain commitment to disagree with.
|
|
17
|
+
*/
|
|
18
|
+
export declare function readOnChainCommitment(midenRpcEndpoint: string, accountId: AccountId, rpcConfig: ResolvedRpcConfig): Promise<string | null>;
|
|
19
|
+
/**
|
|
20
|
+
* Decide whether GUARDIAN-provided state may overwrite the local store.
|
|
21
|
+
*
|
|
22
|
+
* Returns `false`, rather than throwing, when the GUARDIAN state is simply
|
|
23
|
+
* *behind* local (lower nonce). That happens whenever the execution delta the
|
|
24
|
+
* client pushed has not been canonicalized by GUARDIAN's background worker yet
|
|
25
|
+
* (see OpenZeppelin/guardian#316), or permanently if that candidate was
|
|
26
|
+
* discarded (#312 / #319). In that case the local account is already ahead and
|
|
27
|
+
* is independently verifiable against chain (`verifyStateCommitment`), so it is
|
|
28
|
+
* authoritative and must be kept, not clobbered; the caller keeps local and
|
|
29
|
+
* refreshes config from it.
|
|
30
|
+
*
|
|
31
|
+
* Still throws for genuine divergence: an incoming state at the *same* nonce as
|
|
32
|
+
* local but a different commitment, or an incoming state whose commitment does
|
|
33
|
+
* not match the on-chain commitment.
|
|
34
|
+
*
|
|
35
|
+
* Callers must only reach here once they know the two states differ. At equal
|
|
36
|
+
* nonce this treats the pair as divergent, which is true only when the
|
|
37
|
+
* commitments already disagree.
|
|
38
|
+
*/
|
|
39
|
+
export declare function isSafeToAdoptGuardianState(params: {
|
|
40
|
+
accountId: string;
|
|
41
|
+
incomingAccount: Account;
|
|
42
|
+
localAccount?: Account;
|
|
43
|
+
readCommitment: () => Promise<string | null>;
|
|
44
|
+
}): Promise<boolean>;
|
|
45
|
+
//# sourceMappingURL=adopt.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adopt.d.ts","sourceRoot":"","sources":["../../src/state/adopt.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,OAAO,EAAE,SAAS,EAAuB,MAAM,sBAAsB,CAAC;AAG/E,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAK1D;;;;GAIG;AACH,wBAAsB,qBAAqB,CACzC,gBAAgB,EAAE,MAAM,EACxB,SAAS,EAAE,SAAS,EACpB,SAAS,EAAE,iBAAiB,GAC3B,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAwBxB;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAsB,0BAA0B,CAAC,MAAM,EAAE;IACvD,SAAS,EAAE,MAAM,CAAC;IAClB,eAAe,EAAE,OAAO,CAAC;IACzB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,cAAc,EAAE,MAAM,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;CAC9C,GAAG,OAAO,CAAC,OAAO,CAAC,CAoDnB"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deciding when GUARDIAN-provided account state may replace the local store.
|
|
3
|
+
*
|
|
4
|
+
* Both entry points that pull an account from GUARDIAN need this: `syncState`,
|
|
5
|
+
* which refreshes an account already in hand, and `MultisigClient.load`, which
|
|
6
|
+
* rebuilds one. Sharing the rule is the point. Deciding it twice is how the two
|
|
7
|
+
* paths came to disagree, with `load` keeping whatever the store held whenever
|
|
8
|
+
* it held anything, so a caller that had touched the account before read stale
|
|
9
|
+
* state with no error.
|
|
10
|
+
*/
|
|
11
|
+
import { Endpoint, RpcClient } from '@miden-sdk/miden-sdk';
|
|
12
|
+
import { retryRpcRead } from '../rpc/retry.js';
|
|
13
|
+
import { normalizeHexWord } from '../utils/encoding.js';
|
|
14
|
+
const ZERO_COMMITMENT = `0x${'0'.repeat(64)}`;
|
|
15
|
+
/**
|
|
16
|
+
* The account's commitment as the node reports it, or `null` when the account
|
|
17
|
+
* is not deployed yet. An undeployed account is not an error: it has no
|
|
18
|
+
* on-chain commitment to disagree with.
|
|
19
|
+
*/
|
|
20
|
+
export async function readOnChainCommitment(midenRpcEndpoint, accountId, rpcConfig) {
|
|
21
|
+
const rpcClient = new RpcClient(new Endpoint(midenRpcEndpoint));
|
|
22
|
+
try {
|
|
23
|
+
const accountDetails = await retryRpcRead(() => rpcClient.getAccountDetails(accountId), rpcConfig);
|
|
24
|
+
if (!accountDetails) {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
const commitment = normalizeHexWord(accountDetails.commitment().toHex());
|
|
28
|
+
return commitment === ZERO_COMMITMENT ? null : commitment;
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
32
|
+
if (message.includes('null pointer passed to rust') ||
|
|
33
|
+
message.includes('No account header record found for given ID') ||
|
|
34
|
+
message.toLowerCase().includes('not found')) {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
throw error;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Decide whether GUARDIAN-provided state may overwrite the local store.
|
|
42
|
+
*
|
|
43
|
+
* Returns `false`, rather than throwing, when the GUARDIAN state is simply
|
|
44
|
+
* *behind* local (lower nonce). That happens whenever the execution delta the
|
|
45
|
+
* client pushed has not been canonicalized by GUARDIAN's background worker yet
|
|
46
|
+
* (see OpenZeppelin/guardian#316), or permanently if that candidate was
|
|
47
|
+
* discarded (#312 / #319). In that case the local account is already ahead and
|
|
48
|
+
* is independently verifiable against chain (`verifyStateCommitment`), so it is
|
|
49
|
+
* authoritative and must be kept, not clobbered; the caller keeps local and
|
|
50
|
+
* refreshes config from it.
|
|
51
|
+
*
|
|
52
|
+
* Still throws for genuine divergence: an incoming state at the *same* nonce as
|
|
53
|
+
* local but a different commitment, or an incoming state whose commitment does
|
|
54
|
+
* not match the on-chain commitment.
|
|
55
|
+
*
|
|
56
|
+
* Callers must only reach here once they know the two states differ. At equal
|
|
57
|
+
* nonce this treats the pair as divergent, which is true only when the
|
|
58
|
+
* commitments already disagree.
|
|
59
|
+
*/
|
|
60
|
+
export async function isSafeToAdoptGuardianState(params) {
|
|
61
|
+
const { accountId, incomingAccount, localAccount, readCommitment } = params;
|
|
62
|
+
if (localAccount) {
|
|
63
|
+
const localNonce = localAccount.nonce().asInt();
|
|
64
|
+
const incomingNonce = incomingAccount.nonce().asInt();
|
|
65
|
+
if (incomingNonce < localNonce) {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
if (incomingNonce === localNonce) {
|
|
69
|
+
throw new Error(`Refusing to overwrite local state: incoming nonce ${incomingNonce.toString()} equals local nonce ${localNonce.toString()} but commitments differ for account ${accountId}`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
const onChainCommitment = await readCommitment();
|
|
73
|
+
if (!onChainCommitment) {
|
|
74
|
+
// No on-chain commitment means the account is not deployed, and an
|
|
75
|
+
// undeployed account has nothing to disagree with. That reading is only
|
|
76
|
+
// safe when the account has never transacted: `readOnChainCommitment`
|
|
77
|
+
// reports a missing account by matching `not found` in the error text, and
|
|
78
|
+
// a proxy or gateway 404 says exactly that. An account with a non-zero
|
|
79
|
+
// nonce has transacted, so it is deployed, so this is an RPC failure rather
|
|
80
|
+
// than an undeployed account, and adopting on it would skip the commitment
|
|
81
|
+
// check entirely.
|
|
82
|
+
// Keyed on the *local* nonce only. An account this client has transacted is
|
|
83
|
+
// deployed, so a node reporting nothing for it is an RPC failure rather
|
|
84
|
+
// than an undeployed account, and adopting there would skip the check
|
|
85
|
+
// against chain. The incoming nonce is GUARDIAN's claim rather than
|
|
86
|
+
// evidence, and `syncState` legitimately meets a higher incoming nonce with
|
|
87
|
+
// no local history; the caller that has no local record at all applies its
|
|
88
|
+
// own rule.
|
|
89
|
+
const transacted = localAccount?.nonce().asInt() ?? BigInt(0);
|
|
90
|
+
if (transacted > BigInt(0)) {
|
|
91
|
+
throw new Error(`Refusing to overwrite local state: account ${accountId} has transacted (nonce ${transacted.toString()}) but the node reported no on-chain commitment, so the incoming state could not be checked against chain`);
|
|
92
|
+
}
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
const incomingCommitment = normalizeHexWord(incomingAccount.to_commitment().toHex());
|
|
96
|
+
if (incomingCommitment !== onChainCommitment) {
|
|
97
|
+
throw new Error(`Refusing to overwrite local state: incoming commitment does not match on-chain commitment for account ${accountId}`);
|
|
98
|
+
}
|
|
99
|
+
return true;
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=adopt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adopt.js","sourceRoot":"","sources":["../../src/state/adopt.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAsB,QAAQ,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAE/E,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAExD,MAAM,eAAe,GAAG,KAAK,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC;AAE9C;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,qBAAqB,CACzC,gBAAwB,EACxB,SAAoB,EACpB,SAA4B;IAE5B,MAAM,SAAS,GAAG,IAAI,SAAS,CAAC,IAAI,QAAQ,CAAC,gBAAgB,CAAC,CAAC,CAAC;IAEhE,IAAI,CAAC;QACH,MAAM,cAAc,GAAG,MAAM,YAAY,CACvC,GAAG,EAAE,CAAC,SAAS,CAAC,iBAAiB,CAAC,SAAS,CAAC,EAC5C,SAAS,CACV,CAAC;QACF,IAAI,CAAC,cAAc,EAAE,CAAC;YACpB,OAAO,IAAI,CAAC;QACd,CAAC;QACD,M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AAM,cAAc,EAAE,CAAC;IACjD,IAAI,CAAC,iBAAiB,EAAE,CAAC;QACvB,mEAAmE;QACnE,wEAAwE;QACxE,sEAAsE;QACtE,2EAA2E;QAC3E,uEAAuE;QACvE,4EAA4E;QAC5E,2EAA2E;QAC3E,kBAAkB;QAClB,4EAA4E;QAC5E,wEAAwE;QACxE,sEAAsE;QACtE,oEAAoE;QACpE,4EAA4E;QAC5E,2EAA2E;QAC3E,YAAY;QACZ,MAAM,UAAU,GAAG,YAAY,EAAE,KAAK,EAAE,CAAC,KAAK,EAAE,IAAI,MAAM,CAAC,CAAC,CAAC,CAAC;QAC9D,IAAI,UAAU,GAAG,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;YAC3B,MAAM,IAAI,KAAK,CACb,8CAA8C,SAAS,0BAA0B,UAAU,CAAC,QAAQ,EAAE,0GAA0G,CACjN,CAAC;QACJ,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,kBAAkB,GAAG,gBAAgB,CAAC,eAAe,CAAC,aAAa,EAAE,CAAC,KAAK,EAAE,CAAC,CAAC;IACrF,IAAI,kBAAkB,KAAK,iBAAiB,EAAE,CAAC;QAC7C,MAAM,IAAI,KAAK,CACb,yGAAyG,SAAS,EAAE,CACrH,CAAC;IACJ,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { TransactionRequest, TransactionRequestBuilder, Word } from '@miden-sdk/miden-sdk';
|
|
2
|
+
import { type RawClientSource } from '../raw-client.js';
|
|
3
|
+
import type { MultisigRequestOptions } from './options.js';
|
|
4
|
+
/**
|
|
5
|
+
* A request under construction that already carries the multisig auth args,
|
|
6
|
+
* and the salt they commit to as normalized hex.
|
|
7
|
+
*/
|
|
8
|
+
export interface MultisigRequestDraft {
|
|
9
|
+
builder: TransactionRequestBuilder;
|
|
10
|
+
saltHex: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Starts a request carrying the multisig auth args for `options.accountId`:
|
|
14
|
+
* the three-word preimage in the advice map and its commitment as the auth
|
|
15
|
+
* arg, which miden-client then leaves alone.
|
|
16
|
+
*
|
|
17
|
+
* The salt is `options.salt` or a fresh one. `approvalExpirationDelta` left
|
|
18
|
+
* out means the approval never expires, the upstream default. `boundBlockNum`
|
|
19
|
+
* left out binds the store's sync height, which is what a proposer wants; a
|
|
20
|
+
* rebuild pins the proposal's anchor block and the expiration the summary
|
|
21
|
+
* already binds.
|
|
22
|
+
*
|
|
23
|
+
* The salt is moved across the WASM boundary, so a handle is built here from
|
|
24
|
+
* the hex rather than taken from the caller, and nothing frees it afterwards.
|
|
25
|
+
*/
|
|
26
|
+
export declare function multisigRequestBuilder(client: RawClientSource, options: MultisigRequestOptions): Promise<MultisigRequestDraft>;
|
|
27
|
+
/**
|
|
28
|
+
* The furthest a transaction may expire after its reference block
|
|
29
|
+
* (`MAX_EXPIRATION_BLOCK_DELTA` in the transaction kernel). The auth procedure
|
|
30
|
+
* clamps the approval expiration it applies to this, so a longer approval would
|
|
31
|
+
* outlive the transaction it authorizes: the summary would still say "valid"
|
|
32
|
+
* while the node already refuses the submission as expired.
|
|
33
|
+
*/
|
|
34
|
+
export declare const MAX_APPROVAL_EXPIRATION_DELTA = 65535;
|
|
35
|
+
/**
|
|
36
|
+
* Builds the request and hands back the salt it commits to as a fresh handle
|
|
37
|
+
* the caller owns. Refuses a request that carries no auth arg:
|
|
38
|
+
* `feeAwareTransactionRequestBuilder` hands back an untouched builder for an
|
|
39
|
+
* account it cannot classify as a multisig, typically one the client's store
|
|
40
|
+
* does not hold, and such a request would only fail later, inside the VM,
|
|
41
|
+
* while the auth procedure pipes a preimage that is not there.
|
|
42
|
+
*/
|
|
43
|
+
export declare function buildMultisigRequest(builder: TransactionRequestBuilder, saltHex: string, accountId: string): {
|
|
44
|
+
request: TransactionRequest;
|
|
45
|
+
salt: Word;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* The block a multisig request's summary binds, read from the auth-args
|
|
49
|
+
* preimage the request carries. `undefined` when the request carries none.
|
|
50
|
+
*/
|
|
51
|
+
export declare function requestBoundBlockNum(request: TransactionRequest): number | undefined;
|
|
52
|
+
/**
|
|
53
|
+
* The salt a multisig request's summary binds, read from the auth-args
|
|
54
|
+
* preimage the request carries. `undefined` when the request carries none.
|
|
55
|
+
*/
|
|
56
|
+
export declare function requestSaltHex(request: TransactionRequest): string | undefined;
|
|
57
|
+
//# sourceMappingURL=authArgs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authArgs.d.ts","sourceRoot":"","sources":["../../src/transaction/authArgs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAQ,kBAAkB,EAAE,yBAAyB,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAGtG,OAAO,EAA0C,KAAK,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAGhG,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAU3D;;;GAGG;AACH,MAAM,WAAW,oBAAoB;IACnC,OAAO,EAAE,yBAAyB,CAAC;IACnC,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAsB,sBAAsB,CAC1C,MAAM,EAAE,eAAe,EACvB,OAAO,EAAE,sBAAsB,GAC9B,OAAO,CAAC,oBAAoB,CAAC,CAqB/B;AAED;;;;;;GAMG;AACH,eAAO,MAAM,6BAA6B,QAAS,CAAC;AAmBpD;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,yBAAyB,EAClC,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,GAChB;IAAE,OAAO,EAAE,kBAAkB,CAAC;IAAC,IAAI,EAAE,IAAI,CAAA;CAAE,CAM7C;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,kBAAkB,GAAG,MAAM,GAAG,SAAS,CAGpF;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,kBAAkB,GAAG,MAAM,GAAG,SAAS,CAQ9E"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { AccountId, Word as WordType } from '@miden-sdk/miden-sdk';
|
|
2
|
+
import { MultisigAuthArgsMissingError } from '../multisig/authArgErrors.js';
|
|
3
|
+
import { getRawMidenClient, isPublicMidenClient } from '../raw-client.js';
|
|
4
|
+
import { normalizeHexWord } from '../utils/encoding.js';
|
|
5
|
+
import { randomWord } from '../utils/random.js';
|
|
6
|
+
/**
|
|
7
|
+
* Layout of the multisig auth-args preimage the auth arg commits to, in felts:
|
|
8
|
+
* `[bound_block_num, approval_expiration_block_num, 0, 0, SALT, CONVERSION_INFO]`.
|
|
9
|
+
*/
|
|
10
|
+
const AUTH_ARGS_BOUND_BLOCK_INDEX = 0;
|
|
11
|
+
const AUTH_ARGS_SALT_OFFSET = 4;
|
|
12
|
+
const AUTH_ARGS_NUM_ELEMENTS = 12;
|
|
13
|
+
/**
|
|
14
|
+
* Starts a request carrying the multisig auth args for `options.accountId`:
|
|
15
|
+
* the three-word preimage in the advice map and its commitment as the auth
|
|
16
|
+
* arg, which miden-client then leaves alone.
|
|
17
|
+
*
|
|
18
|
+
* The salt is `options.salt` or a fresh one. `approvalExpirationDelta` left
|
|
19
|
+
* out means the approval never expires, the upstream default. `boundBlockNum`
|
|
20
|
+
* left out binds the store's sync height, which is what a proposer wants; a
|
|
21
|
+
* rebuild pins the proposal's anchor block and the expiration the summary
|
|
22
|
+
* already binds.
|
|
23
|
+
*
|
|
24
|
+
* The salt is moved across the WASM boundary, so a handle is built here from
|
|
25
|
+
* the hex rather than taken from the caller, and nothing frees it afterwards.
|
|
26
|
+
*/
|
|
27
|
+
export async function multisigRequestBuilder(client, options) {
|
|
28
|
+
const { accountId, boundBlockNum, approvalExpirationDelta, midenRpcEndpoint } = options;
|
|
29
|
+
assertApprovalExpirationDelta(approvalExpirationDelta);
|
|
30
|
+
const saltHex = normalizeHexWord(options.salt ? options.salt.toHex() : randomWord().toHex());
|
|
31
|
+
const salt = WordType.fromHex(saltHex);
|
|
32
|
+
if (isPublicMidenClient(client)) {
|
|
33
|
+
const builder = await client.feeAwareTransactionRequestBuilder(accountId, {
|
|
34
|
+
feeConversionSalt: salt,
|
|
35
|
+
boundBlockNum,
|
|
36
|
+
approvalExpirationDelta,
|
|
37
|
+
});
|
|
38
|
+
return { builder, saltHex };
|
|
39
|
+
}
|
|
40
|
+
const rawClient = await getRawMidenClient(client, midenRpcEndpoint);
|
|
41
|
+
const builder = await rawClient.feeAwareTransactionRequestBuilder(AccountId.fromHex(accountId), approvalExpirationDelta ?? null, salt, boundBlockNum ?? null);
|
|
42
|
+
return { builder, saltHex };
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* The furthest a transaction may expire after its reference block
|
|
46
|
+
* (`MAX_EXPIRATION_BLOCK_DELTA` in the transaction kernel). The auth procedure
|
|
47
|
+
* clamps the approval expiration it applies to this, so a longer approval would
|
|
48
|
+
* outlive the transaction it authorizes: the summary would still say "valid"
|
|
49
|
+
* while the node already refuses the submission as expired.
|
|
50
|
+
*/
|
|
51
|
+
export const MAX_APPROVAL_EXPIRATION_DELTA = 65_535;
|
|
52
|
+
/**
|
|
53
|
+
* Zero is not "no expiration": the kernel reads it as expired at the bound
|
|
54
|
+
* block and rejects the transaction. Refused here, where the caller can see why,
|
|
55
|
+
* together with a delta the auth procedure would silently clamp.
|
|
56
|
+
*/
|
|
57
|
+
function assertApprovalExpirationDelta(delta) {
|
|
58
|
+
if (delta === undefined) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
if (!Number.isInteger(delta) || delta < 1 || delta > MAX_APPROVAL_EXPIRATION_DELTA) {
|
|
62
|
+
throw new Error(`approvalExpirationDelta must be a whole number of blocks between 1 and ${MAX_APPROVAL_EXPIRATION_DELTA}, ` +
|
|
63
|
+
`got ${delta}; omit it for an approval that does not expire`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Builds the request and hands back the salt it commits to as a fresh handle
|
|
68
|
+
* the caller owns. Refuses a request that carries no auth arg:
|
|
69
|
+
* `feeAwareTransactionRequestBuilder` hands back an untouched builder for an
|
|
70
|
+
* account it cannot classify as a multisig, typically one the client's store
|
|
71
|
+
* does not hold, and such a request would only fail later, inside the VM,
|
|
72
|
+
* while the auth procedure pipes a preimage that is not there.
|
|
73
|
+
*/
|
|
74
|
+
export function buildMultisigRequest(builder, saltHex, accountId) {
|
|
75
|
+
const request = builder.build();
|
|
76
|
+
if (!request.authArg()) {
|
|
77
|
+
throw new MultisigAuthArgsMissingError(accountId);
|
|
78
|
+
}
|
|
79
|
+
return { request, salt: WordType.fromHex(saltHex) };
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* The block a multisig request's summary binds, read from the auth-args
|
|
83
|
+
* preimage the request carries. `undefined` when the request carries none.
|
|
84
|
+
*/
|
|
85
|
+
export function requestBoundBlockNum(request) {
|
|
86
|
+
const preimage = authArgsPreimage(request);
|
|
87
|
+
return preimage ? Number(preimage[AUTH_ARGS_BOUND_BLOCK_INDEX].asInt()) : undefined;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* The salt a multisig request's summary binds, read from the auth-args
|
|
91
|
+
* preimage the request carries. `undefined` when the request carries none.
|
|
92
|
+
*/
|
|
93
|
+
export function requestSaltHex(request) {
|
|
94
|
+
const preimage = authArgsPreimage(request);
|
|
95
|
+
if (!preimage) {
|
|
96
|
+
return undefined;
|
|
97
|
+
}
|
|
98
|
+
return WordType.newFromFelts(preimage.slice(AUTH_ARGS_SALT_OFFSET, AUTH_ARGS_SALT_OFFSET + 4)).toHex();
|
|
99
|
+
}
|
|
100
|
+
function authArgsPreimage(request) {
|
|
101
|
+
const authArg = request.authArg();
|
|
102
|
+
if (!authArg) {
|
|
103
|
+
return undefined;
|
|
104
|
+
}
|
|
105
|
+
const felts = request.adviceMap().get(authArg);
|
|
106
|
+
return felts && felts.length === AUTH_ARGS_NUM_ELEMENTS ? felts : undefined;
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=authArgs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authArgs.js","sourceRoot":"","sources":["../../src/transaction/authArgs.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,IAAI,IAAI,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AACnE,OAAO,EAAE,4BAA4B,EAAE,MAAM,8BAA8B,CAAC;AAC5E,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAwB,MAAM,kBAAkB,CAAC;AAChG,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAGhD;;;GAGG;AACH,MAAM,2BAA2B,GAAG,CAAC,CAAC;AACtC,MAAM,qBAAqB,GAAG,CAAC,CAAC;AAChC,MAAM,sBAAsB,GAAG,EAAE,CAAC;AAWlC;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAC1C,MAAuB,EACvB,OAA+B;IAE/B,MAAM,EAAE,SAAS,EAAE,aAAa,EAAE,uBAAuB,EAAE,gBAAgB,EAAE,GAAG,OAAO,CAAC;IACxF,6BAA6B,CAAC,uBAAuB,CAAC,CAAC;IACvD,MAAM,OAAO,GAAG,gBAAgB,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,UAAU,EAAE,CAAC,KAAK,EAAE,CAAC,CAAC;IAC7F,MAAM,IAAI,GAAG,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IACvC,IAAI,mBAAmB,CAAC,MAAM,CAAC,EAAE,CAAC;QAChC,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,iCAAiC,C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;AACH,MAAM,UAAU,oBAAoB,CAAC,OAA2B;IAC9D,MAAM,QAAQ,GAAG,gBAAgB,CAAC,OAAO,CAAC,CAAC;IAC3C,OAAO,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,2BAA2B,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AACtF,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,cAAc,CAAC,OAA2B;IACxD,MAAM,QAAQ,GAAG,gBAAgB,CAAC,OAAO,CAAC,CAAC;IAC3C,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,OAAO,QAAQ,CAAC,YAAY,CAC1B,QAAQ,CAAC,KAAK,CAAC,qBAAqB,EAAE,qBAAqB,GAAG,CAAC,CAAC,CACjE,CAAC,KAAK,EAAE,CAAC;AACZ,CAAC;AAED,SAAS,gBAAgB,CAAC,OAA2B;IACnD,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;IAClC,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,MAAM,KAAK,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAC/C,OAAO,KAAK,IAAI,KAAK,CAAC,MAAM,KAAK,sBAAsB,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;AAC9E,CAAC"}
|
|
@@ -1,22 +1,26 @@
|
|
|
1
1
|
import type { MidenClient, Note, TransactionRequest, WasmWebClient, Word } from '@miden-sdk/miden-sdk';
|
|
2
|
-
import type {
|
|
2
|
+
import type { MidenClientMultisigRequestOptions, MultisigRequestOptions } from './options.js';
|
|
3
3
|
/**
|
|
4
4
|
* Build a consume-notes request from loaded `Note` objects (no local-store
|
|
5
5
|
* read). v2 verification path for issue #229.
|
|
6
6
|
*/
|
|
7
|
-
export declare function buildConsumeNotesTransactionRequestFromNotes(notes: Note[], options
|
|
7
|
+
export declare function buildConsumeNotesTransactionRequestFromNotes(client: MidenClient, notes: Note[], options: MidenClientMultisigRequestOptions): Promise<{
|
|
8
8
|
request: TransactionRequest;
|
|
9
9
|
salt: Word;
|
|
10
|
-
}
|
|
10
|
+
}>;
|
|
11
|
+
export declare function buildConsumeNotesTransactionRequestFromNotes(client: WasmWebClient, notes: Note[], options: MultisigRequestOptions): Promise<{
|
|
12
|
+
request: TransactionRequest;
|
|
13
|
+
salt: Word;
|
|
14
|
+
}>;
|
|
11
15
|
/**
|
|
12
16
|
* Legacy/creation adapter: fetches notes from the local store and delegates
|
|
13
17
|
* to the from-notes variant. v2 verification MUST NOT call this.
|
|
14
18
|
*/
|
|
15
|
-
export declare function buildConsumeNotesTransactionRequest(client: MidenClient, noteIds: string[], options:
|
|
19
|
+
export declare function buildConsumeNotesTransactionRequest(client: MidenClient, noteIds: string[], options: MidenClientMultisigRequestOptions): Promise<{
|
|
16
20
|
request: TransactionRequest;
|
|
17
21
|
salt: Word;
|
|
18
22
|
}>;
|
|
19
|
-
export declare function buildConsumeNotesTransactionRequest(client: WasmWebClient, noteIds: string[], options
|
|
23
|
+
export declare function buildConsumeNotesTransactionRequest(client: WasmWebClient, noteIds: string[], options: MultisigRequestOptions): Promise<{
|
|
20
24
|
request: TransactionRequest;
|
|
21
25
|
salt: Word;
|
|
22
26
|
}>;
|