@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.
Files changed (151) hide show
  1. package/README.md +171 -46
  2. package/dist/account/builder.d.ts +4 -4
  3. package/dist/account/builder.d.ts.map +1 -1
  4. package/dist/account/builder.js +17 -7
  5. package/dist/account/builder.js.map +1 -1
  6. package/dist/account/layout.d.ts +5 -5
  7. package/dist/account/layout.d.ts.map +1 -1
  8. package/dist/account/layout.js +5 -5
  9. package/dist/account/layout.js.map +1 -1
  10. package/dist/client.d.ts +18 -1
  11. package/dist/client.d.ts.map +1 -1
  12. package/dist/client.js +79 -6
  13. package/dist/client.js.map +1 -1
  14. package/dist/index.d.ts +6 -6
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +5 -5
  17. package/dist/index.js.map +1 -1
  18. package/dist/multisig/authArgErrors.d.ts +28 -31
  19. package/dist/multisig/authArgErrors.d.ts.map +1 -1
  20. package/dist/multisig/authArgErrors.js +42 -46
  21. package/dist/multisig/authArgErrors.js.map +1 -1
  22. package/dist/multisig/consumeNotesErrors.d.ts +13 -1
  23. package/dist/multisig/consumeNotesErrors.d.ts.map +1 -1
  24. package/dist/multisig/consumeNotesErrors.js +17 -0
  25. package/dist/multisig/consumeNotesErrors.js.map +1 -1
  26. package/dist/multisig/signing.d.ts +1 -1
  27. package/dist/multisig/signing.d.ts.map +1 -1
  28. package/dist/multisig/signing.js +8 -3
  29. package/dist/multisig/signing.js.map +1 -1
  30. package/dist/multisig.d.ts +145 -18
  31. package/dist/multisig.d.ts.map +1 -1
  32. package/dist/multisig.js +493 -162
  33. package/dist/multisig.js.map +1 -1
  34. package/dist/procedures.d.ts +7 -7
  35. package/dist/procedures.js +7 -7
  36. package/dist/proposal/factory.d.ts.map +1 -1
  37. package/dist/proposal/factory.js +7 -0
  38. package/dist/proposal/factory.js.map +1 -1
  39. package/dist/prover/workflow.d.ts +7 -3
  40. package/dist/prover/workflow.d.ts.map +1 -1
  41. package/dist/prover/workflow.js +7 -5
  42. package/dist/prover/workflow.js.map +1 -1
  43. package/dist/raw-client.d.ts +1 -0
  44. package/dist/raw-client.d.ts.map +1 -1
  45. package/dist/raw-client.js +10 -2
  46. package/dist/raw-client.js.map +1 -1
  47. package/dist/recovery/publicNoteBackfill.js +1 -1
  48. package/dist/recovery/publicNoteBackfill.js.map +1 -1
  49. package/dist/retry/classify.d.ts +3 -0
  50. package/dist/retry/classify.d.ts.map +1 -1
  51. package/dist/retry/classify.js +2 -2
  52. package/dist/retry/classify.js.map +1 -1
  53. package/dist/signer.d.ts +1 -0
  54. package/dist/signer.d.ts.map +1 -1
  55. package/dist/signer.js +1 -0
  56. package/dist/signer.js.map +1 -1
  57. package/dist/signers/index.d.ts +1 -0
  58. package/dist/signers/index.d.ts.map +1 -1
  59. package/dist/signers/index.js +1 -0
  60. package/dist/signers/index.js.map +1 -1
  61. package/dist/signers/ledger.d.ts +25 -0
  62. package/dist/signers/ledger.d.ts.map +1 -0
  63. package/dist/signers/ledger.js +96 -0
  64. package/dist/signers/ledger.js.map +1 -0
  65. package/dist/state/adopt.d.ts +45 -0
  66. package/dist/state/adopt.d.ts.map +1 -0
  67. package/dist/state/adopt.js +101 -0
  68. package/dist/state/adopt.js.map +1 -0
  69. package/dist/transaction/authArgs.d.ts +57 -0
  70. package/dist/transaction/authArgs.d.ts.map +1 -0
  71. package/dist/transaction/authArgs.js +108 -0
  72. package/dist/transaction/authArgs.js.map +1 -0
  73. package/dist/transaction/consumeNotes.d.ts +9 -5
  74. package/dist/transaction/consumeNotes.d.ts.map +1 -1
  75. package/dist/transaction/consumeNotes.js +8 -23
  76. package/dist/transaction/consumeNotes.js.map +1 -1
  77. package/dist/transaction/noteAuthentication.d.ts +39 -0
  78. package/dist/transaction/noteAuthentication.d.ts.map +1 -0
  79. package/dist/transaction/noteAuthentication.js +94 -0
  80. package/dist/transaction/noteAuthentication.js.map +1 -0
  81. package/dist/transaction/options.d.ts +25 -0
  82. package/dist/transaction/options.d.ts.map +1 -1
  83. package/dist/transaction/p2id.d.ts +3 -2
  84. package/dist/transaction/p2id.d.ts.map +1 -1
  85. package/dist/transaction/p2id.js +36 -27
  86. package/dist/transaction/p2id.js.map +1 -1
  87. package/dist/transaction/summary.d.ts +126 -22
  88. package/dist/transaction/summary.d.ts.map +1 -1
  89. package/dist/transaction/summary.js +164 -22
  90. package/dist/transaction/summary.js.map +1 -1
  91. package/dist/transaction/updateGuardian.d.ts +3 -3
  92. package/dist/transaction/updateGuardian.d.ts.map +1 -1
  93. package/dist/transaction/updateGuardian.js +5 -16
  94. package/dist/transaction/updateGuardian.js.map +1 -1
  95. package/dist/transaction/updateProcedureThreshold.d.ts +3 -3
  96. package/dist/transaction/updateProcedureThreshold.d.ts.map +1 -1
  97. package/dist/transaction/updateProcedureThreshold.js +6 -16
  98. package/dist/transaction/updateProcedureThreshold.js.map +1 -1
  99. package/dist/transaction/updateSigners.d.ts +3 -3
  100. package/dist/transaction/updateSigners.d.ts.map +1 -1
  101. package/dist/transaction/updateSigners.js +9 -16
  102. package/dist/transaction/updateSigners.js.map +1 -1
  103. package/dist/transaction.d.ts +3 -2
  104. package/dist/transaction.d.ts.map +1 -1
  105. package/dist/transaction.js +3 -2
  106. package/dist/transaction.js.map +1 -1
  107. package/dist/types/proposal.d.ts +37 -5
  108. package/dist/types/proposal.d.ts.map +1 -1
  109. package/dist/types/proposal.js +8 -0
  110. package/dist/types/proposal.js.map +1 -1
  111. package/dist/utils/eip712.d.ts +80 -0
  112. package/dist/utils/eip712.d.ts.map +1 -0
  113. package/dist/utils/eip712.js +49 -0
  114. package/dist/utils/eip712.js.map +1 -0
  115. package/dist/utils/signature.d.ts +4 -0
  116. package/dist/utils/signature.d.ts.map +1 -1
  117. package/dist/utils/signature.js +49 -1
  118. package/dist/utils/signature.js.map +1 -1
  119. package/package.json +11 -6
  120. package/src/account/builder.ts +18 -7
  121. package/src/account/layout.ts +5 -5
  122. package/src/client.ts +94 -6
  123. package/src/index.ts +24 -3
  124. package/src/multisig/authArgErrors.ts +47 -53
  125. package/src/multisig/consumeNotesErrors.ts +20 -1
  126. package/src/multisig/signing.ts +8 -2
  127. package/src/multisig.ts +614 -205
  128. package/src/procedures.ts +7 -7
  129. package/src/proposal/factory.ts +7 -0
  130. package/src/prover/workflow.ts +7 -10
  131. package/src/raw-client.ts +11 -7
  132. package/src/recovery/publicNoteBackfill.ts +1 -1
  133. package/src/retry/classify.ts +3 -3
  134. package/src/signer.ts +1 -0
  135. package/src/signers/index.ts +1 -0
  136. package/src/signers/ledger.ts +122 -0
  137. package/src/state/adopt.ts +132 -0
  138. package/src/transaction/authArgs.ts +142 -0
  139. package/src/transaction/consumeNotes.ts +23 -30
  140. package/src/transaction/noteAuthentication.ts +136 -0
  141. package/src/transaction/options.ts +27 -0
  142. package/src/transaction/p2id.ts +45 -34
  143. package/src/transaction/summary.ts +239 -30
  144. package/src/transaction/updateGuardian.ts +8 -22
  145. package/src/transaction/updateProcedureThreshold.ts +8 -20
  146. package/src/transaction/updateSigners.ts +11 -22
  147. package/src/transaction.ts +18 -1
  148. package/src/types/proposal.ts +36 -5
  149. package/src/utils/eip712.ts +57 -0
  150. package/src/utils/signature.ts +57 -0
  151. package/src/prover/test-node.d.ts +0 -6
@@ -1,16 +1,12 @@
1
- //! Typed failures for auth-arg recovery.
2
- //!
3
- //! The surface lands here deliberately ahead of the code that raises it: nothing in this
4
- //! change constructs these, and the proposal paths that do arrive in the PR that commits
5
- //! the anchored fee faucet. Landing the codes first keeps them out of that PR's diff and
6
- //! lets a caller pin `code` before the raiser exists — `public-api.test.ts` covers the
7
- //! barrel so a dropped re-export is caught either way.
1
+ //! Typed failures a caller branches on rather than reports: each means the proposal or
2
+ //! request itself is unusable, as against a transport or WASM failure a retry might clear.
3
+ //! `public-api.test.ts` covers the barrel so a dropped re-export is caught.
8
4
 
9
5
  /** Stable error identifiers for auth-arg recovery failures. */
10
6
  export type AuthArgErrorCode =
11
- | 'proposal_auth_arg_unresolvable'
12
7
  | 'proposal_salt_malformed'
13
- | 'fee_faucet_anchor_mismatch';
8
+ | 'multisig_auth_args_missing'
9
+ | 'bound_block_not_declared';
14
10
 
15
11
  /** How much of an untrusted value an error message will quote. */
16
12
  const MAX_QUOTED_CHARS = 80;
@@ -56,11 +52,10 @@ function coerceForMessage(value: unknown): string {
56
52
  * A proposal's recorded salt is not a readable 32-byte word, so no rebuild can
57
53
  * use it.
58
54
  *
59
- * Coded for the same reason as {@link ProposalAuthArgUnresolvableError}, and
60
- * recoverable in the same one place: a `switch_guardian`'s salt is served by the
61
- * GUARDIAN being switched away from, which can make it unreadable as easily as
62
- * it can make it wrong. Treating only the latter as recoverable would leave that
63
- * GUARDIAN able to strand a fully signed switch.
55
+ * Coded because `switch_guardian` recovery acts on it rather than reporting it:
56
+ * the salt is served by the GUARDIAN being switched away from, which can make it
57
+ * unreadable, and treating that as fatal would leave that GUARDIAN able to strand
58
+ * a fully signed switch.
64
59
  */
65
60
  export class ProposalSaltMalformedError extends Error {
66
61
  readonly code: AuthArgErrorCode = 'proposal_salt_malformed';
@@ -90,49 +85,48 @@ export class ProposalSaltMalformedError extends Error {
90
85
  }
91
86
 
92
87
  /**
93
- * A proposal's signed auth arg is not the fee-conversion commitment its recorded
94
- * salt and anchored fee faucet derive, so no reconstruction from that salt
95
- * succeeds. Raised before the rebuild, so the proposal fails on the value that is
96
- * actually wrong rather than on an `ERR_FEE_CONVERSION_INFO_MISSING` abort at
97
- * proving.
98
- *
99
- * `switch_guardian` is the exception, and deliberately so: it rebuilds from the
100
- * summary's own auth arg, which reproduces the signed word but not the fee
101
- * preimage behind it, so it executes only on a zero-fee chain.
102
- *
103
- * Coded because one caller acts on it rather than reporting it:
104
- * `switch_guardian` recovery falls back to the summary's own auth arg when it
105
- * sees this or {@link ProposalSaltMalformedError}, and must not extend that
106
- * treatment to an unreadable anchor or a WASM failure.
88
+ * A request built for `accountId` came back without the multisig auth args.
89
+ * `feeAwareTransactionRequestBuilder` only attaches them to an account it can
90
+ * classify as a multisig, so this means the account is not in the client's
91
+ * store or its code is not the guarded-multisig component this client knows.
92
+ * Raised at build time: the alternative is an abort inside the auth procedure
93
+ * while it pipes a preimage the advice map does not hold.
107
94
  */
108
- export class ProposalAuthArgUnresolvableError extends Error {
109
- readonly code: AuthArgErrorCode = 'proposal_auth_arg_unresolvable';
110
- readonly proposalId: string;
111
- readonly signedAuthArgHex: string;
112
- readonly saltHex: string;
113
- readonly feeFaucetIdHex: string;
95
+ export class MultisigAuthArgsMissingError extends Error {
96
+ readonly code: AuthArgErrorCode = 'multisig_auth_args_missing';
97
+ readonly accountId: string;
114
98
 
115
- constructor(details: {
116
- proposalId: string;
117
- signedAuthArgHex: string;
118
- saltHex: string;
119
- feeFaucetIdHex: string;
120
- }) {
99
+ constructor(accountId: string) {
121
100
  super(
122
- `Proposal ${quoteUntrusted(details.proposalId)} auth arg ` +
123
- `${quoteUntrusted(details.signedAuthArgHex)} is not the fee-conversion commitment to ` +
124
- `its metadata salt ${quoteUntrusted(details.saltHex)} under fee faucet ` +
125
- `${quoteUntrusted(details.feeFaucetIdHex)}, so the signed transaction summary cannot ` +
126
- `be reproduced ` +
127
- 'from that salt, and the proposal cannot be executed. Recreate the proposal and ' +
128
- 'collect signatures again, and have the original dropped server-side — while ' +
129
- 'GUARDIAN keeps serving it, syncing this account keeps failing on it',
101
+ `Account ${quoteUntrusted(accountId)} received no multisig auth args: the client does ` +
102
+ 'not hold it as a guarded-multisig account, so a request built for it cannot be ' +
103
+ 'authenticated. Import or create the account in this client first',
130
104
  );
131
- this.name = 'ProposalAuthArgUnresolvableError';
132
- this.proposalId = details.proposalId;
133
- this.signedAuthArgHex = details.signedAuthArgHex;
134
- this.saltHex = details.saltHex;
135
- this.feeFaucetIdHex = details.feeFaucetIdHex;
105
+ this.name = 'MultisigAuthArgsMissingError';
106
+ this.accountId = accountId;
136
107
  }
137
108
  }
138
109
 
110
+ /**
111
+ * A multisig request does not list the block its auth args bind among the
112
+ * blocks it declares through `withBlockNumbers`. A proposal executes at the
113
+ * chain tip, where the auth procedure can read the bound block only from the
114
+ * transaction's partial blockchain, so such a request fails in the VM with
115
+ * `failed to lookup value in Merkle store` once the chain moves past that
116
+ * block. `feeAwareTransactionRequestBuilder` declares it; a request whose auth
117
+ * args are attached by hand has to call `withBlockNumbers([boundBlockNum])`.
118
+ */
119
+ export class BoundBlockNotDeclaredError extends Error {
120
+ readonly code: AuthArgErrorCode = 'bound_block_not_declared';
121
+ readonly boundBlockNum: number;
122
+
123
+ constructor(boundBlockNum: number) {
124
+ super(
125
+ `The transaction request binds block ${boundBlockNum} in its multisig auth args but does ` +
126
+ 'not declare it, so it cannot execute at a later chain tip. Build it with ' +
127
+ `feeAwareTransactionRequestBuilder or add withBlockNumbers([${boundBlockNum}])`,
128
+ );
129
+ this.name = 'BoundBlockNotDeclaredError';
130
+ this.boundBlockNum = boundBlockNum;
131
+ }
132
+ }
@@ -8,7 +8,8 @@ export type ConsumeNotesErrorCode =
8
8
  | 'consume_notes_note_binding_mismatch'
9
9
  | 'consume_notes_unsupported_metadata_version'
10
10
  | 'consume_notes_metadata_oversize'
11
- | 'consume_notes_legacy_note_missing';
11
+ | 'consume_notes_legacy_note_missing'
12
+ | 'consume_notes_note_not_authenticated';
12
13
 
13
14
  /**
14
15
  * v2 metadata's embedded `notes` array did not match its declared
@@ -72,3 +73,21 @@ export class LegacyConsumeNotesNoteMissingError extends Error {
72
73
  this.noteId = noteId;
73
74
  }
74
75
  }
76
+
77
+ /**
78
+ * A note a `consume_notes` proposal consumes could not be authenticated
79
+ * (its inclusion proof fetched from the node and imported into the local
80
+ * store). The signed summary commits to authenticated consumption, so an
81
+ * unauthenticated rebuild would never match it (issue #409).
82
+ */
83
+ export class ConsumeNoteNotAuthenticatedError extends Error {
84
+ readonly code: ConsumeNotesErrorCode = 'consume_notes_note_not_authenticated';
85
+ readonly noteId: string;
86
+ readonly reason: string;
87
+ constructor(noteId: string, reason: string) {
88
+ super(`consume_notes: note ${noteId} could not be authenticated: ${reason}`);
89
+ this.name = 'ConsumeNoteNotAuthenticatedError';
90
+ this.noteId = noteId;
91
+ this.reason = reason;
92
+ }
93
+ }
@@ -5,12 +5,18 @@ export function toGuardianSignature(
5
5
  scheme: SignatureScheme,
6
6
  signatureHex: string,
7
7
  publicKey?: string,
8
+ messageFormat?: 'eip712',
8
9
  ): ProposalSignature {
9
10
  if (scheme === 'ecdsa') {
10
11
  if (!publicKey) {
11
12
  throw new Error('ECDSA signature requires publicKey');
12
13
  }
13
- return { scheme: 'ecdsa', signature: signatureHex, publicKey };
14
+ return {
15
+ scheme: 'ecdsa',
16
+ signature: signatureHex,
17
+ publicKey,
18
+ ...(messageFormat ? { messageFormat } : {}),
19
+ };
14
20
  }
15
21
  return { scheme: 'falcon', signature: signatureHex };
16
22
  }
@@ -20,5 +26,5 @@ export async function buildGuardianSignatureFromSigner(
20
26
  commitment: string,
21
27
  ): Promise<ProposalSignature> {
22
28
  const signatureHex = await signer.signCommitment(commitment);
23
- return toGuardianSignature(signer.scheme, signatureHex, signer.publicKey);
29
+ return toGuardianSignature(signer.scheme, signatureHex, signer.publicKey, signer.proposalMessageFormat);
24
30
  }