@openzeppelin/miden-multisig-client 0.17.0 → 0.18.0-rc.1

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 (146) hide show
  1. package/README.md +159 -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 +14 -31
  19. package/dist/multisig/authArgErrors.d.ts.map +1 -1
  20. package/dist/multisig/authArgErrors.js +22 -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 +118 -11
  31. package/dist/multisig.d.ts.map +1 -1
  32. package/dist/multisig.js +421 -141
  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/raw-client.d.ts +1 -0
  40. package/dist/raw-client.d.ts.map +1 -1
  41. package/dist/raw-client.js +10 -2
  42. package/dist/raw-client.js.map +1 -1
  43. package/dist/recovery/publicNoteBackfill.js +1 -1
  44. package/dist/recovery/publicNoteBackfill.js.map +1 -1
  45. package/dist/retry/classify.d.ts +3 -0
  46. package/dist/retry/classify.d.ts.map +1 -1
  47. package/dist/retry/classify.js +2 -2
  48. package/dist/retry/classify.js.map +1 -1
  49. package/dist/signer.d.ts +1 -0
  50. package/dist/signer.d.ts.map +1 -1
  51. package/dist/signer.js +1 -0
  52. package/dist/signer.js.map +1 -1
  53. package/dist/signers/index.d.ts +1 -0
  54. package/dist/signers/index.d.ts.map +1 -1
  55. package/dist/signers/index.js +1 -0
  56. package/dist/signers/index.js.map +1 -1
  57. package/dist/signers/ledger.d.ts +25 -0
  58. package/dist/signers/ledger.d.ts.map +1 -0
  59. package/dist/signers/ledger.js +96 -0
  60. package/dist/signers/ledger.js.map +1 -0
  61. package/dist/state/adopt.d.ts +45 -0
  62. package/dist/state/adopt.d.ts.map +1 -0
  63. package/dist/state/adopt.js +101 -0
  64. package/dist/state/adopt.js.map +1 -0
  65. package/dist/transaction/authArgs.d.ts +57 -0
  66. package/dist/transaction/authArgs.d.ts.map +1 -0
  67. package/dist/transaction/authArgs.js +108 -0
  68. package/dist/transaction/authArgs.js.map +1 -0
  69. package/dist/transaction/consumeNotes.d.ts +9 -5
  70. package/dist/transaction/consumeNotes.d.ts.map +1 -1
  71. package/dist/transaction/consumeNotes.js +8 -23
  72. package/dist/transaction/consumeNotes.js.map +1 -1
  73. package/dist/transaction/noteAuthentication.d.ts +39 -0
  74. package/dist/transaction/noteAuthentication.d.ts.map +1 -0
  75. package/dist/transaction/noteAuthentication.js +94 -0
  76. package/dist/transaction/noteAuthentication.js.map +1 -0
  77. package/dist/transaction/options.d.ts +25 -0
  78. package/dist/transaction/options.d.ts.map +1 -1
  79. package/dist/transaction/p2id.d.ts +3 -2
  80. package/dist/transaction/p2id.d.ts.map +1 -1
  81. package/dist/transaction/p2id.js +36 -27
  82. package/dist/transaction/p2id.js.map +1 -1
  83. package/dist/transaction/summary.d.ts +41 -15
  84. package/dist/transaction/summary.d.ts.map +1 -1
  85. package/dist/transaction/summary.js +71 -19
  86. package/dist/transaction/summary.js.map +1 -1
  87. package/dist/transaction/updateGuardian.d.ts +3 -3
  88. package/dist/transaction/updateGuardian.d.ts.map +1 -1
  89. package/dist/transaction/updateGuardian.js +5 -16
  90. package/dist/transaction/updateGuardian.js.map +1 -1
  91. package/dist/transaction/updateProcedureThreshold.d.ts +3 -3
  92. package/dist/transaction/updateProcedureThreshold.d.ts.map +1 -1
  93. package/dist/transaction/updateProcedureThreshold.js +6 -16
  94. package/dist/transaction/updateProcedureThreshold.js.map +1 -1
  95. package/dist/transaction/updateSigners.d.ts +3 -3
  96. package/dist/transaction/updateSigners.d.ts.map +1 -1
  97. package/dist/transaction/updateSigners.js +9 -16
  98. package/dist/transaction/updateSigners.js.map +1 -1
  99. package/dist/transaction.d.ts +3 -2
  100. package/dist/transaction.d.ts.map +1 -1
  101. package/dist/transaction.js +3 -2
  102. package/dist/transaction.js.map +1 -1
  103. package/dist/types/proposal.d.ts +31 -0
  104. package/dist/types/proposal.d.ts.map +1 -1
  105. package/dist/types/proposal.js +8 -0
  106. package/dist/types/proposal.js.map +1 -1
  107. package/dist/utils/eip712.d.ts +80 -0
  108. package/dist/utils/eip712.d.ts.map +1 -0
  109. package/dist/utils/eip712.js +49 -0
  110. package/dist/utils/eip712.js.map +1 -0
  111. package/dist/utils/signature.d.ts +4 -0
  112. package/dist/utils/signature.d.ts.map +1 -1
  113. package/dist/utils/signature.js +49 -1
  114. package/dist/utils/signature.js.map +1 -1
  115. package/package.json +11 -6
  116. package/src/account/builder.ts +18 -7
  117. package/src/account/layout.ts +5 -5
  118. package/src/client.ts +94 -6
  119. package/src/index.ts +21 -3
  120. package/src/multisig/authArgErrors.ts +23 -56
  121. package/src/multisig/consumeNotesErrors.ts +20 -1
  122. package/src/multisig/signing.ts +8 -2
  123. package/src/multisig.ts +530 -183
  124. package/src/procedures.ts +7 -7
  125. package/src/proposal/factory.ts +7 -0
  126. package/src/raw-client.ts +11 -7
  127. package/src/recovery/publicNoteBackfill.ts +1 -1
  128. package/src/retry/classify.ts +3 -3
  129. package/src/signer.ts +1 -0
  130. package/src/signers/index.ts +1 -0
  131. package/src/signers/ledger.ts +122 -0
  132. package/src/state/adopt.ts +132 -0
  133. package/src/transaction/authArgs.ts +142 -0
  134. package/src/transaction/consumeNotes.ts +23 -30
  135. package/src/transaction/noteAuthentication.ts +136 -0
  136. package/src/transaction/options.ts +27 -0
  137. package/src/transaction/p2id.ts +45 -34
  138. package/src/transaction/summary.ts +86 -22
  139. package/src/transaction/updateGuardian.ts +8 -22
  140. package/src/transaction/updateProcedureThreshold.ts +8 -20
  141. package/src/transaction/updateSigners.ts +11 -22
  142. package/src/transaction.ts +12 -1
  143. package/src/types/proposal.ts +30 -0
  144. package/src/utils/eip712.ts +57 -0
  145. package/src/utils/signature.ts +57 -0
  146. package/src/prover/test-node.d.ts +0 -6
@@ -1,13 +1,8 @@
1
- import { NoteAndArgs, NoteAndArgsArray, TransactionRequestBuilder, Word as WordType, } from '@miden-sdk/miden-sdk';
1
+ import { NoteAndArgs, NoteAndArgsArray } from '@miden-sdk/miden-sdk';
2
2
  import { LegacyConsumeNotesNoteMissingError } from '../multisig/consumeNotesErrors.js';
3
3
  import { getRawMidenClient } from '../raw-client.js';
4
- import { normalizeHexWord } from '../utils/encoding.js';
5
- import { randomWord } from '../utils/random.js';
6
- /**
7
- * Build a consume-notes request from loaded `Note` objects (no local-store
8
- * read). v2 verification path for issue #229.
9
- */
10
- export function buildConsumeNotesTransactionRequestFromNotes(notes, options = {}) {
4
+ import { buildMultisigRequest, multisigRequestBuilder } from './authArgs.js';
5
+ export async function buildConsumeNotesTransactionRequestFromNotes(client, notes, options) {
11
6
  if (notes.length === 0) {
12
7
  throw new Error('At least one note is required');
13
8
  }
@@ -15,24 +10,14 @@ export function buildConsumeNotesTransactionRequestFromNotes(notes, options = {}
15
10
  for (const note of notes) {
16
11
  noteAndArgsArray.push(new NoteAndArgs(note, null));
17
12
  }
18
- const authSaltHex = options.salt ? options.salt.toHex() : randomWord().toHex();
19
- const authSaltForBuilder = WordType.fromHex(normalizeHexWord(authSaltHex));
20
- let txBuilder = new TransactionRequestBuilder();
21
- txBuilder = txBuilder.withInputNotes(noteAndArgsArray);
22
- txBuilder = txBuilder.withFeeConversionSalt(authSaltForBuilder);
23
- // Borrows rather than consumes: the glue passes `__wbg_ptr` without taking it,
24
- // so the handle stays ours to release once the builder has read it.
25
- authSaltForBuilder.free?.();
13
+ const { builder, saltHex } = await multisigRequestBuilder(client, options);
14
+ let txBuilder = builder.withInputNotes(noteAndArgsArray);
26
15
  if (options.signatureAdviceMap) {
27
16
  txBuilder = txBuilder.extendAdviceMap(options.signatureAdviceMap);
28
17
  }
29
- const authSaltForReturn = WordType.fromHex(normalizeHexWord(authSaltHex));
30
- return {
31
- request: txBuilder.build(),
32
- salt: authSaltForReturn,
33
- };
18
+ return buildMultisigRequest(txBuilder, saltHex, options.accountId);
34
19
  }
35
- export async function buildConsumeNotesTransactionRequest(client, noteIds, options = {}) {
20
+ export async function buildConsumeNotesTransactionRequest(client, noteIds, options) {
36
21
  if (noteIds.length === 0) {
37
22
  throw new Error('At least one note ID is required');
38
23
  }
@@ -45,6 +30,6 @@ export async function buildConsumeNotesTransactionRequest(client, noteIds, optio
45
30
  }
46
31
  notes.push(inputNoteRecord.toNote());
47
32
  }
48
- return buildConsumeNotesTransactionRequestFromNotes(notes, options);
33
+ return buildConsumeNotesTransactionRequestFromNotes(rawClient, notes, options);
49
34
  }
50
35
  //# sourceMappingURL=consumeNotes.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"consumeNotes.js","sourceRoot":"","sources":["../../src/transaction/consumeNotes.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,WAAW,EACX,gBAAgB,EAChB,yBAAyB,E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AAS,CAAC,CAAC;QAChE,IAAI,CAAC,eAAe,EAAE,CAAC;YACrB,MAAM,IAAI,kCAAkC,CAAC,SAAS,CAAC,CAAC;QAC1D,CAAC;QACD,KAAK,CAAC,IAAI,CAAC,eAAe,CAAC,MAAM,EAAE,CAAC,CAAC;IACvC,CAAC;IAED,OAAO,4CAA4C,CAAC,SAAS,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;AACjF,CAAC"}
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Canonical consumption mode for `consume_notes` proposals: authenticated.
3
+ *
4
+ * miden-client decides per input note, at execution time and from the local
5
+ * store alone, whether it is consumed as *authenticated* (the store holds
6
+ * its inclusion proof) or *unauthenticated* (anything else). The two modes
7
+ * commit differently into the transaction summary,
8
+ * `hash(nullifier || note_id_or_ZERO)`, so the proposer and every verifier
9
+ * must be in the same mode or the summary commitment, and with it the
10
+ * proposal id, differs. That was issue #409's live shape: a cosigner whose
11
+ * fresh store had never seen the notes failed with "metadata does not match
12
+ * tx_summary". Proposal creation and every rebuild call
13
+ * {@link ensureNotesAuthenticated} first, so the executed transaction is the
14
+ * one the cosigners signed regardless of what each store held before.
15
+ */
16
+ import { type Note } from '@miden-sdk/miden-sdk';
17
+ import type { RawClientSource } from '../raw-client.js';
18
+ import { type RpcConfig } from '../rpc/config.js';
19
+ export interface EnsureNotesAuthenticatedOptions {
20
+ /** Miden node RPC endpoint the inclusion proofs are fetched from. */
21
+ midenRpcEndpoint: string;
22
+ /** Retry policy for the proof fetch; defaults to the SDK's RPC defaults. */
23
+ rpc?: RpcConfig;
24
+ }
25
+ /**
26
+ * Makes every note in `notes` an authenticated input note in the client's
27
+ * local store: present, with its on-chain inclusion proof and block header.
28
+ *
29
+ * Notes already authenticated locally are left alone. For the rest the
30
+ * inclusion proofs come from the node in one round trip (the node serves
31
+ * proofs for private notes too) and each note is imported as committed,
32
+ * which also upgrades a proof-less record the store already tracked.
33
+ *
34
+ * @throws {ConsumeNoteNotAuthenticatedError} when a note is not committed on
35
+ * chain yet, the node does not serve its proof, the import fails, or the
36
+ * record still lacks authentication after a sync.
37
+ */
38
+ export declare function ensureNotesAuthenticated(midenClient: RawClientSource, notes: readonly Note[], options: EnsureNotesAuthenticatedOptions): Promise<void>;
39
+ //# sourceMappingURL=noteAuthentication.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"noteAuthentication.d.ts","sourceRoot":"","sources":["../../src/transaction/noteAuthentication.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAY,KAAK,IAAI,EAAsC,MAAM,sBAAsB,CAAC;AAG/F,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAGxD,OAAO,EAAoB,KAAK,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAIpE,MAAM,WAAW,+BAA+B;IAC9C,qEAAqE;IACrE,gBAAgB,EAAE,MAAM,CAAC;IACzB,4EAA4E;IAC5E,GAAG,CAAC,EAAE,SAAS,CAAC;CACjB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,wBAAwB,CAC5C,WAAW,EAAE,eAAe,EAC5B,KAAK,EAAE,SAAS,IAAI,EAAE,EACtB,OAAO,EAAE,+BAA+B,GACvC,OAAO,CAAC,IAAI,CAAC,CA+Df"}
@@ -0,0 +1,94 @@
1
+ /**
2
+ * Canonical consumption mode for `consume_notes` proposals: authenticated.
3
+ *
4
+ * miden-client decides per input note, at execution time and from the local
5
+ * store alone, whether it is consumed as *authenticated* (the store holds
6
+ * its inclusion proof) or *unauthenticated* (anything else). The two modes
7
+ * commit differently into the transaction summary,
8
+ * `hash(nullifier || note_id_or_ZERO)`, so the proposer and every verifier
9
+ * must be in the same mode or the summary commitment, and with it the
10
+ * proposal id, differs. That was issue #409's live shape: a cosigner whose
11
+ * fresh store had never seen the notes failed with "metadata does not match
12
+ * tx_summary". Proposal creation and every rebuild call
13
+ * {@link ensureNotesAuthenticated} first, so the executed transaction is the
14
+ * one the cosigners signed regardless of what each store held before.
15
+ */
16
+ import { Endpoint, RpcClient } from '@miden-sdk/miden-sdk';
17
+ import { ConsumeNoteNotAuthenticatedError } from '../multisig/consumeNotesErrors.js';
18
+ import { getRawMidenClient } from '../raw-client.js';
19
+ import { importNoteWithProof } from '../recovery/proposalNoteImport.js';
20
+ import { resolveRpcConfig } from '../rpc/config.js';
21
+ import { retryRpcRead } from '../rpc/retry.js';
22
+ import { normalizeHexWord } from '../utils/encoding.js';
23
+ /**
24
+ * Makes every note in `notes` an authenticated input note in the client's
25
+ * local store: present, with its on-chain inclusion proof and block header.
26
+ *
27
+ * Notes already authenticated locally are left alone. For the rest the
28
+ * inclusion proofs come from the node in one round trip (the node serves
29
+ * proofs for private notes too) and each note is imported as committed,
30
+ * which also upgrades a proof-less record the store already tracked.
31
+ *
32
+ * @throws {ConsumeNoteNotAuthenticatedError} when a note is not committed on
33
+ * chain yet, the node does not serve its proof, the import fails, or the
34
+ * record still lacks authentication after a sync.
35
+ */
36
+ export async function ensureNotesAuthenticated(midenClient, notes, options) {
37
+ const webClient = await getRawMidenClient(midenClient, options.midenRpcEndpoint);
38
+ const pending = await unauthenticatedNotes(webClient, notes);
39
+ if (pending.length === 0) {
40
+ return;
41
+ }
42
+ const proofs = new Map();
43
+ try {
44
+ const rpcClient = new RpcClient(new Endpoint(options.midenRpcEndpoint));
45
+ const fetched = await retryRpcRead(() => rpcClient.getNotesById(pending.map((note) => note.id())), resolveRpcConfig(options.rpc));
46
+ for (const entry of fetched) {
47
+ proofs.set(normalizeHexWord(entry.noteId.toString()), entry.inclusionProof);
48
+ }
49
+ }
50
+ catch (error) {
51
+ throw new ConsumeNoteNotAuthenticatedError(noteIdHex(pending[0]), `failed to fetch inclusion proofs from the node: ${errorDetail(error)}`);
52
+ }
53
+ for (const note of pending) {
54
+ const idHex = noteIdHex(note);
55
+ const proof = proofs.get(idHex);
56
+ if (!proof) {
57
+ throw new ConsumeNoteNotAuthenticatedError(idHex, 'the node has no inclusion proof for it (not committed on chain yet)');
58
+ }
59
+ const { outcome, wasImported } = await importNoteWithProof(webClient, 'proposal', idHex, note, proof);
60
+ if (!wasImported) {
61
+ throw new ConsumeNoteNotAuthenticatedError(idHex, `failed to import it with its inclusion proof: ${outcome.reason ?? 'unknown error'}`);
62
+ }
63
+ }
64
+ // The import authenticates a note committed at or below the client's sync
65
+ // height; a newer one lands unverified until a sync fetches its block
66
+ // header. A cosigner that just loaded the account is typically behind the
67
+ // note's block, so sync once and re-check before failing.
68
+ if ((await unauthenticatedNotes(webClient, notes)).length > 0) {
69
+ await webClient.syncState();
70
+ }
71
+ const still = await unauthenticatedNotes(webClient, notes);
72
+ if (still.length > 0) {
73
+ throw new ConsumeNoteNotAuthenticatedError(noteIdHex(still[0]), 'its inclusion proof was imported but the local store could not verify it ' +
74
+ 'against the chain even after a sync');
75
+ }
76
+ }
77
+ /** The subset of `notes` whose local record is missing or carries no proof. */
78
+ async function unauthenticatedNotes(webClient, notes) {
79
+ const pending = [];
80
+ for (const note of notes) {
81
+ const record = await webClient.getInputNote(noteIdHex(note));
82
+ if (!record || !record.isAuthenticated()) {
83
+ pending.push(note);
84
+ }
85
+ }
86
+ return pending;
87
+ }
88
+ function noteIdHex(note) {
89
+ return normalizeHexWord(note.id().toString());
90
+ }
91
+ function errorDetail(error) {
92
+ return error instanceof Error ? error.message : String(error);
93
+ }
94
+ //# sourceMappingURL=noteAuthentication.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"noteAuthentication.js","sourceRoot":"","sources":["../../src/transaction/noteAuthentication.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAE,QAAQ,EAAsC,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAE/F,OAAO,EAAE,gCAAgC,EAAE,MAAM,mCAAmC,CAAC;AAErF,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AACxE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EAAE,CAAC;QACzB,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,YAAY,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;QAC7D,IAAI,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,eAAe,EAAE,EAAE,CAAC;YACzC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACrB,CAAC;IACH,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,SAAS,SAAS,CAAC,IAAU;IAC3B,OAAO,gBAAgB,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,QAAQ,EAAE,CAAC,CAAC;AAChD,CAAC;AAED,SAAS,WAAW,CAAC,KAAc;IACjC,OAAO,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAChE,CAAC"}
@@ -5,8 +5,33 @@ export interface SignatureOptions {
5
5
  signatureAdviceMap?: AdviceMap;
6
6
  signatureScheme?: SignatureScheme;
7
7
  midenRpcEndpoint?: string;
8
+ /**
9
+ * The block the transaction summary binds. Omitted, the store's sync height,
10
+ * which is right for the party creating a proposal. A cosigner or executor
11
+ * rebuilding a proposal pins it to the proposal's anchor block, or the rebuilt
12
+ * summary can never match the signed one.
13
+ */
14
+ boundBlockNum?: number;
15
+ /**
16
+ * Blocks after the bound block at which the approvers' signatures stop
17
+ * authorizing the transaction, so it must be included by then. Bound by the
18
+ * summary, so a rebuild must pass the same value. At most 65535 blocks, the
19
+ * furthest a transaction can expire after its reference block; omitted, the
20
+ * approval never expires, which is the upstream default.
21
+ */
22
+ approvalExpirationDelta?: number;
8
23
  }
9
24
  export interface MidenClientSignatureOptions extends SignatureOptions {
10
25
  midenRpcEndpoint: string;
11
26
  }
27
+ /**
28
+ * Options for a request a multisig account executes. The account decides the
29
+ * auth args the request has to carry, so every multisig builder needs it.
30
+ */
31
+ export interface MultisigRequestOptions extends SignatureOptions {
32
+ accountId: string;
33
+ }
34
+ export interface MidenClientMultisigRequestOptions extends MultisigRequestOptions {
35
+ midenRpcEndpoint: string;
36
+ }
12
37
  //# sourceMappingURL=options.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../src/transaction/options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEnD,MAAM,WAAW,gBAAgB;IAC/B,IAAI,CAAC,EAAE,IAAI,CAAC;IACZ,kBAAkB,CAAC,EAAE,SAAS,CAAC;IAC/B,eAAe,CAAC,EAAE,eAAe,CAAC;IAClC,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,MAAM,WAAW,2BAA4B,SAAQ,gBAAgB;IACnE,gBAAgB,EAAE,MAAM,CAAC;CAC1B"}
1
+ {"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../src/transaction/options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEnD,MAAM,WAAW,gBAAgB;IAC/B,IAAI,CAAC,EAAE,IAAI,CAAC;IACZ,kBAAkB,CAAC,EAAE,SAAS,CAAC;IAC/B,eAAe,CAAC,EAAE,eAAe,CAAC;IAClC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B;;;;;OAKG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;;;;;OAMG;IACH,uBAAuB,CAAC,EAAE,MAAM,CAAC;CAClC;AAED,MAAM,WAAW,2BAA4B,SAAQ,gBAAgB;IACnE,gBAAgB,EAAE,MAAM,CAAC;CAC1B;AAED;;;GAGG;AACH,MAAM,WAAW,sBAAuB,SAAQ,gBAAgB;IAC9D,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,iCAAkC,SAAQ,sBAAsB;IAC/E,gBAAgB,EAAE,MAAM,CAAC;CAC1B"}
@@ -1,5 +1,6 @@
1
1
  import type { TransactionRequest, Word } from '@miden-sdk/miden-sdk';
2
2
  import { Note, NoteType } from '@miden-sdk/miden-sdk';
3
+ import type { RawClientSource } from '../raw-client.js';
3
4
  import type { SignatureOptions } from './options.js';
4
5
  import type { P2idNoteVisibility } from '../types/proposal.js';
5
6
  /**
@@ -37,8 +38,8 @@ export declare function deriveP2idSerialNumber(salt: Word): Word;
37
38
  * callback flag is encoded in the faucet account ID.
38
39
  */
39
40
  export declare function buildP2idNoteFromMetadata(senderId: string, recipientId: string, faucetId: string, amount: bigint, noteType: NoteType, saltHex: string, heights?: P2ideHeightOptions): Note;
40
- export declare function buildP2idTransactionRequest(senderId: string, recipientId: string, faucetId: string, amount: bigint, options?: P2idTransactionOptions): {
41
+ export declare function buildP2idTransactionRequest(client: RawClientSource, senderId: string, recipientId: string, faucetId: string, amount: bigint, options?: P2idTransactionOptions): Promise<{
41
42
  request: TransactionRequest;
42
43
  salt: Word;
43
- };
44
+ }>;
44
45
  //# sourceMappingURL=p2id.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"p2id.d.ts","sourceRoot":"","sources":["../../src/transaction/p2id.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AACrE,OAAO,EAML,IAAI,EAOJ,QAAQ,EAIT,MAAM,sBAAsB,CAAC;AAG9B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAG/D;;;;GAIG;AACH,MAAM,WAAW,kBAAkB;IACjC,sEAAsE;IACtE,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,sEAAsE;IACtE,cAAc,CAAC,EAAE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BAAsB,CAAC;AAG/D;;;;GAIG;AACH,MAAM,WAAW,kBAAkB;IACjC,sEAAsE;IACtE,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,sEAAsE;IACtE,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,sBAAuB,SAAQ,gBAAgB,EAAE,kBAAkB;IAClF,qEAAqE;IACrE,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,QAAQ,CAUrE;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,QAAQ,GAAG,SAAS,GAAG,kBAAkB,GAAG,SAAS,CAErG;AAED,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,CAMvD;AAiED;;;;;GAKG;AACH,wBAAgB,yBAAyB,CACvC,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,MAAM,EACf,OAAO,GAAE,kBAAuB,GAC/B,IAAI,CASN;AAED,wBAAsB,2BAA2B,CAC/C,MAAM,EAAE,eAAe,EACvB,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,sBAA2B,GACnC,OAAO,CAAC;IAAE,OAAO,EAAE,kBAAkB,CAAC;IAAC,IAAI,EAAE,IAAI,CAAA;CAAE,CAAC,CAuBtD"}
@@ -1,5 +1,5 @@
1
- import { AccountId, Felt, FeltArray, FungibleAsset, MidenArrays, Note, NoteAssets, NoteMetadata, NoteRecipient, NoteScript, NoteStorage, NoteTag, NoteType, Poseidon2, TransactionRequestBuilder, Word as WordType, } from '@miden-sdk/miden-sdk';
2
- import { randomWord } from '../utils/random.js';
1
+ import { AccountId, Felt, FeltArray, FungibleAsset, MidenArrays, Note, NoteAssets, NoteMetadata, NoteRecipient, NoteScript, NoteStorage, NoteTag, NoteType, Poseidon2, Word as WordType, } from '@miden-sdk/miden-sdk';
2
+ import { buildMultisigRequest, multisigRequestBuilder } from './authArgs.js';
3
3
  import { normalizeHexWord } from '../utils/encoding.js';
4
4
  import { parseP2ideHeight } from '../types/proposal.js';
5
5
  /**
@@ -33,22 +33,39 @@ export function deriveP2idSerialNumber(salt) {
33
33
  ...zeroWord.toFelts(),
34
34
  ]));
35
35
  }
36
+ /**
37
+ * P2ID storage since protocol 0.17 rc.5: target account, then a two-felt salt.
38
+ * Zero salt is the upstream default. A secret salt hides the target from
39
+ * guesses against the storage commitment; this builder keeps the note
40
+ * deterministic in the proposal salt, which already derives the serial number.
41
+ */
42
+ function p2idStorage(recipient) {
43
+ return [recipient.suffix(), recipient.prefix(), new Felt(0n), new Felt(0n)];
44
+ }
45
+ /**
46
+ * P2IDE storage: reclaimer (the sender), target, then reclaim and timelock
47
+ * heights. Zero encodes an unset height. The script requires all six items.
48
+ */
49
+ function p2ideStorage(sender, recipient, reclaimHeight, timelockHeight) {
50
+ return [
51
+ sender.suffix(),
52
+ sender.prefix(),
53
+ recipient.suffix(),
54
+ recipient.prefix(),
55
+ new Felt(BigInt(reclaimHeight)),
56
+ new Felt(BigInt(timelockHeight)),
57
+ ];
58
+ }
36
59
  function buildP2idNote(sender, recipient, noteAssets, noteType, saltHex, heights = {}) {
37
60
  const salt = WordType.fromHex(normalizeHexWord(saltHex));
38
61
  const serialNum = deriveP2idSerialNumber(salt);
39
62
  const reclaimHeight = parseP2ideHeight('reclaimHeight', heights.reclaimHeight);
40
63
  const timelockHeight = parseP2ideHeight('timelockHeight', heights.timelockHeight);
41
64
  const isP2ide = reclaimHeight !== undefined || timelockHeight !== undefined;
42
- // P2IDE storage layout (miden-standards `P2ideNoteStorage`): the P2ID
43
- // storage plus reclaim/timelock heights as felts, 0 encoding "unset".
44
65
  const noteScript = isP2ide ? NoteScript.p2ide() : NoteScript.p2id();
45
- const storageFelts = [
46
- recipient.suffix(),
47
- recipient.prefix(),
48
- ];
49
- if (isP2ide) {
50
- storageFelts.push(new Felt(BigInt(reclaimHeight ?? 0)), new Felt(BigInt(timelockHeight ?? 0)));
51
- }
66
+ const storageFelts = isP2ide
67
+ ? p2ideStorage(sender, recipient, reclaimHeight ?? 0, timelockHeight ?? 0)
68
+ : p2idStorage(recipient);
52
69
  const noteStorage = new NoteStorage(new FeltArray(storageFelts));
53
70
  const noteRecipient = new NoteRecipient(serialNum, noteScript, noteStorage);
54
71
  const noteTag = NoteTag.withAccountTarget(recipient);
@@ -69,24 +86,16 @@ export function buildP2idNoteFromMetadata(senderId, recipientId, faucetId, amoun
69
86
  const noteAssets = new NoteAssets([asset]);
70
87
  return buildP2idNote(sender, recipient, noteAssets, noteType, saltHex, heights);
71
88
  }
72
- export function buildP2idTransactionRequest(senderId, recipientId, faucetId, amount, options = {}) {
73
- const authSaltHex = options.salt ? options.salt.toHex() : randomWord().toHex();
74
- const note = buildP2idNoteFromMetadata(senderId, recipientId, faucetId, amount, options.noteType ?? NoteType.Public, authSaltHex, { reclaimHeight: options.reclaimHeight, timelockHeight: options.timelockHeight });
75
- const outputNotes = new MidenArrays.NoteArray([note]);
76
- const authSaltForBuilder = WordType.fromHex(normalizeHexWord(authSaltHex));
77
- let txBuilder = new TransactionRequestBuilder();
78
- txBuilder = txBuilder.withOwnOutputNotes(outputNotes);
79
- txBuilder = txBuilder.withFeeConversionSalt(authSaltForBuilder);
80
- // Borrows rather than consumes: the glue passes `__wbg_ptr` without taking it,
81
- // so the handle stays ours to release once the builder has read it.
82
- authSaltForBuilder.free?.();
89
+ export async function buildP2idTransactionRequest(client, senderId, recipientId, faucetId, amount, options = {}) {
90
+ const { builder, saltHex } = await multisigRequestBuilder(client, {
91
+ ...options,
92
+ accountId: senderId,
93
+ });
94
+ const note = buildP2idNoteFromMetadata(senderId, recipientId, faucetId, amount, options.noteType ?? NoteType.Public, saltHex, { reclaimHeight: options.reclaimHeight, timelockHeight: options.timelockHeight });
95
+ let txBuilder = builder.withOwnOutputNotes(new MidenArrays.NoteArray([note]));
83
96
  if (options.signatureAdviceMap) {
84
97
  txBuilder = txBuilder.extendAdviceMap(options.signatureAdviceMap);
85
98
  }
86
- const authSaltForReturn = WordType.fromHex(normalizeHexWord(authSaltHex));
87
- return {
88
- request: txBuilder.build(),
89
- salt: authSaltForReturn,
90
- };
99
+ return buildMultisigRequest(txBuilder, saltHex, senderId);
91
100
  }
92
101
  //# sourceMappingURL=p2id.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"p2id.js","sourceRoot":"","sources":["../../src/transaction/p2id.ts"],"names":[],"mappings":"AACA,OAAO,EACL,SAAS,EACT,IAAI,EACJ,SAAS,EACT,aAAa,EACb,WAAW,EACX,IAAI,EACJ,UAAU,EACV,YAAY,EACZ,aAAa,EACb,UAAU,EACV,WAAW,EACX,OAAO,EACP,QAAQ,EACR,SAAS,EACT,yBAAyB,EACzB,IAAI,IAAI,QAAQ,GACjB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAGxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAmBxD;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,KAAyB;IACzD,QAAQ,KAAK,EAAE,CAAC;QACd,KAAK,SAAS,CAAC;QACf,KAAK,QAAQ;YACX,OAAO,QAAQ,CAAC,MAAM,CAAC;QACzB,KAAK,SAAS;YACZ,OAAO,QAAQ,CAAC,OAAO,CAAC;QAC1B;YACE,MAAM,IAAI,KAAK,CAAC,kCAAkC,KAAK,mCAAmC,CAAC,CAAC;IAChG,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,sBAAsB,CAAC,QAA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EAAE,GAAG,MAAM,sBAAsB,CAAC,MAAM,EAAE;QAChE,GAAG,OAAO;QACV,SAAS,EAAE,QAAQ;KACpB,CAAC,CAAC;IAEH,MAAM,IAAI,GAAG,yBAAyB,CACpC,QAAQ,EACR,WAAW,EACX,QAAQ,EACR,MAAM,EACN,OAAO,CAAC,QAAQ,IAAI,QAAQ,CAAC,MAAM,EACnC,OAAO,EACP,EAAE,aAAa,EAAE,OAAO,CAAC,aAAa,EAAE,cAAc,EAAE,OAAO,CAAC,cAAc,EAAE,CACjF,CAAC;IAEF,IAAI,SAAS,GAAG,OAAO,CAAC,kBAAkB,CAAC,IAAI,WAAW,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAE9E,IAAI,OAAO,CAAC,kBAAkB,EAAE,CAAC;QAC/B,SAAS,GAAG,SAAS,CAAC,eAAe,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC;IACpE,CAAC;IAED,OAAO,oBAAoB,CAAC,SAAS,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;AAC5D,CAAC"}
@@ -1,12 +1,31 @@
1
1
  import type { MidenClient, TransactionRequest, TransactionSummary, WasmWebClient } from '@miden-sdk/miden-sdk';
2
2
  import { ChainAnchor, Word } from '@miden-sdk/miden-sdk';
3
+ /**
4
+ * The summary binds the block the request's auth args name, and the anchor
5
+ * the store's sync height at capture. A sync landing between the build and the
6
+ * capture leaves them one block apart, and every cosigner's anchor check would
7
+ * then fail on a proposal nothing else is wrong with. Caught here, before the
8
+ * proposal is pushed, so the proposer rebuilds instead.
9
+ */
10
+ export declare class SummaryAnchorMismatchError extends Error {
11
+ readonly retryable = true;
12
+ constructor(details: {
13
+ anchorCommitmentHex: string;
14
+ summaryBlockCommitmentHex: string;
15
+ });
16
+ }
3
17
  /**
4
18
  * Captures a `ChainAnchor` for the request at the current sync height and
5
19
  * executes the transaction against it to obtain the summary awaiting
6
20
  * authorization. The anchor is returned alongside the summary so the proposer
7
21
  * can ship it with the signed data; cosigners and the executor then reproduce
8
- * the summary — which binds the reference block commitment since protocol
9
- * 0.16 — with {@link executeForSummaryAt} regardless of their own sync height.
22
+ * the summary with {@link executeForSummaryAt} regardless of their own sync
23
+ * height.
24
+ *
25
+ * The request's auth args bind the block its summary commits to, and this
26
+ * package pins that block to the anchor: a proposer builds at the sync height
27
+ * the anchor is captured at, and a rebuild passes the anchor's block number.
28
+ * The check below is what makes the first half hold.
10
29
  */
11
30
  export declare function executeForSummary(client: MidenClient, accountId: string, txRequest: TransactionRequest, midenRpcEndpoint: string): Promise<{
12
31
  summary: TransactionSummary;
@@ -18,7 +37,7 @@ export declare function executeForSummary(client: WasmWebClient, accountId: stri
18
37
  }>;
19
38
  /**
20
39
  * Executes a transaction at the given `ChainAnchor`'s reference block to
21
- * obtain the summary awaiting authorization — the anchored counterpart of
40
+ * obtain the summary awaiting authorization: the anchored counterpart of
22
41
  * {@link executeForSummary} for cosigners and executors holding a proposal's
23
42
  * anchor.
24
43
  */
@@ -36,18 +55,25 @@ export declare function chainAnchorToBase64(anchor: ChainAnchor): string;
36
55
  */
37
56
  export declare function chainAnchorFromBase64(anchorBase64: string): ChainAnchor;
38
57
  /**
39
- * Reads the auth args back out of a transaction summary.
40
- *
41
- * Since miden-protocol 0.16-rc the summary binds seven user-defined elements
42
- * instead of a dedicated salt word. The guarded-multisig auth component zeroes
43
- * the leading three and passes the auth args as the trailing four, so the auth
44
- * args are the tail of `userParams()`.
58
+ * The block a proposal's `chainAnchor` names, which is the block its summary
59
+ * binds: a custom producer rebuilds its request at this block. Decodes the
60
+ * anchor for the one number and frees it.
61
+ */
62
+ export declare function chainAnchorBlockNum(anchorBase64: string): number;
63
+ /**
64
+ * Reads the salt a multisig transaction summary binds.
45
65
  *
46
- * This is the auth-arg word, *not* the proposal salt. When the request declares
47
- * a fee conversion salt, miden-client uses it to commit the native conversion
48
- * info under `hash(CONVERSION_INFO || SALT)`. That commitment is not invertible
49
- * to the salt. Keep the salt alongside the proposal — `ProposalMetadata.saltHex`
50
- * — rather than trying to recover it from the summary.
66
+ * Since protocol 0.17 the multisig auth components bind the salt itself into
67
+ * the summary's user params rather than a commitment derived from it, so the
68
+ * value cosigners signed over is readable again. A proposal still carries the
69
+ * salt in its metadata, because a request has to be rebuilt before any summary
70
+ * exists; this reader is the cross-check that the two agree.
71
+ */
72
+ export declare function summarySalt(summary: TransactionSummary): Word;
73
+ /**
74
+ * Reads the block at which the approvers' signatures stop authorizing the
75
+ * transaction, or `undefined` for an approval that never expires, which is
76
+ * what this package's builders produce.
51
77
  */
52
- export declare function summaryAuthArg(summary: TransactionSummary): Word;
78
+ export declare function summaryApprovalExpirationBlockNum(summary: TransactionSummary): number | undefined;
53
79
  //# sourceMappingURL=summary.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"summary.d.ts","sourceRoot":"","sources":["../../src/transaction/summary.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,kBAAkB,EAClB,kBAAkB,EAClB,aAAa,EACd,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAa,WAAW,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAWpE;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,WAAW,EACnB,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,kBAAkB,EAC7B,gBAAgB,EAAE,MAAM,GACvB,OAAO,CAAC;IAAE,OAAO,EAAE,kBAAkB,CAAC;IAAC,MAAM,EAAE,WAAW,CAAA;CAAE,CAAC,CAAC;AACjE,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,aAAa,EACrB,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,kBAAkB,EAC7B,gBAAgB,CAAC,EAAE,MAAM,GACxB,OAAO,CAAC;IAAE,OAAO,EAAE,kBAAkB,CAAC;IAAC,MAAM,EAAE,WAAW,CAAA;CAAE,CAAC,CAAC;AAcjE;;;;;GAKG;AACH,wBAAgB,mBAAmB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,MAAM,EAAE,WAAW,CAAA;CAAE,CAAC,CAAC;AACjE,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,aAAa,EACrB,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,kBAAkB,EAC7B,gBAAgB,CAAC,EAAE,MAAM,GACxB,OAAO,CAAC;IAAE,OAAO,EAAE,kBAAkB,CAAC;IAAC,MAAM,EAAE,WAAW,CAAA;CAAE,CAAC,CAAC;AA+BjE;;;;;GAKG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,WAAW,EACnB,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,kBAAkB,EAC7B,MAAM,EAAE,WAAW,EACnB,gBAAgB,EAAE,MAAM,GACvB,OAAO,CAAC,kBAAkB,CAAC,CAAC;AAC/B,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,aAAa,EACrB,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,kBAAkB,EAC7B,MAAM,EAAE,WAAW,EACnB,gBAAgB,CAAC,EAAE,MAAM,GACxB,OAAO,CAAC,kBAAkB,CAAC,CAAC;AAa/B;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,WAAW,GAAG,MAAM,CAE/D;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,YAAY,EAAE,MAAM,GAAG,WAAW,CAEvE;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAOhE;AAED;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,kBAAkB,GAAG,IAAI,CAI7D;AAED;;;;GAIG;AACH,wBAAgB,iCAAiC,CAAC,OAAO,EAAE,kBAAkB,GAAG,MAAM,GAAG,SAAS,CAGjG"}
@@ -1,17 +1,51 @@
1
1
  import { AccountId, ChainAnchor, Word } from '@miden-sdk/miden-sdk';
2
2
  import { getRawMidenClient } from '../raw-client.js';
3
- import { base64ToUint8Array, uint8ArrayToBase64 } from '../utils/encoding.js';
3
+ import { base64ToUint8Array, normalizeHexWord, uint8ArrayToBase64 } from '../utils/encoding.js';
4
4
  /**
5
- * Index of the first user param carrying the auth args. The guarded-multisig
6
- * auth component zeroes user params 0-2 and fills 3-6 with the auth args, matching
7
- * `push.0.0.0` ahead of `multisig::auth_tx` in `guarded_multisig.masm`.
5
+ * Layout of the six user params a multisig auth component binds into the
6
+ * transaction summary since protocol 0.17: the approval expiration block (or
7
+ * zero for an approval that never expires), a zero, then the four salt felts.
8
8
  */
9
- const AUTH_ARG_USER_PARAM_OFFSET = 3;
9
+ const APPROVAL_EXPIRATION_USER_PARAM_INDEX = 0;
10
+ const SALT_USER_PARAM_OFFSET = 2;
11
+ /**
12
+ * The summary binds the block the request's auth args name, and the anchor
13
+ * the store's sync height at capture. A sync landing between the build and the
14
+ * capture leaves them one block apart, and every cosigner's anchor check would
15
+ * then fail on a proposal nothing else is wrong with. Caught here, before the
16
+ * proposal is pushed, so the proposer rebuilds instead.
17
+ */
18
+ export class SummaryAnchorMismatchError extends Error {
19
+ retryable = true;
20
+ constructor(details) {
21
+ super(`the transaction summary binds block commitment ${details.summaryBlockCommitmentHex} but ` +
22
+ `the captured chain anchor is ${details.anchorCommitmentHex}; a sync landed between ` +
23
+ 'building the request and capturing its anchor, so rebuild the request and retry');
24
+ this.name = 'SummaryAnchorMismatchError';
25
+ }
26
+ }
10
27
  export async function executeForSummary(client, accountId, txRequest, midenRpcEndpoint) {
11
28
  const acc = AccountId.fromHex(accountId);
12
29
  const rawClient = await getRawMidenClient(client, midenRpcEndpoint);
13
30
  const anchor = await rawClient.chainAnchorForRequest(txRequest);
14
- const summary = await rawClient.executeForSummaryAt(acc, txRequest, anchor);
31
+ let summary;
32
+ try {
33
+ summary = await rawClient.executeForSummaryAt(acc, txRequest, anchor);
34
+ }
35
+ catch (error) {
36
+ anchor.free();
37
+ throw error;
38
+ }
39
+ const anchorCommitment = anchor.commitment();
40
+ const summaryBlockCommitment = summary.blockCommitment();
41
+ const anchorCommitmentHex = normalizeHexWord(anchorCommitment.toHex());
42
+ const summaryBlockCommitmentHex = normalizeHexWord(summaryBlockCommitment.toHex());
43
+ anchorCommitment.free?.();
44
+ summaryBlockCommitment.free?.();
45
+ if (anchorCommitmentHex !== summaryBlockCommitmentHex) {
46
+ anchor.free();
47
+ throw new SummaryAnchorMismatchError({ anchorCommitmentHex, summaryBlockCommitmentHex });
48
+ }
15
49
  return { summary, anchor };
16
50
  }
17
51
  export async function executeForSummaryAt(client, accountId, txRequest, anchor, midenRpcEndpoint) {
@@ -35,20 +69,38 @@ export function chainAnchorFromBase64(anchorBase64) {
35
69
  return ChainAnchor.deserialize(base64ToUint8Array(anchorBase64));
36
70
  }
37
71
  /**
38
- * Reads the auth args back out of a transaction summary.
39
- *
40
- * Since miden-protocol 0.16-rc the summary binds seven user-defined elements
41
- * instead of a dedicated salt word. The guarded-multisig auth component zeroes
42
- * the leading three and passes the auth args as the trailing four, so the auth
43
- * args are the tail of `userParams()`.
72
+ * The block a proposal's `chainAnchor` names, which is the block its summary
73
+ * binds: a custom producer rebuilds its request at this block. Decodes the
74
+ * anchor for the one number and frees it.
75
+ */
76
+ export function chainAnchorBlockNum(anchorBase64) {
77
+ const anchor = chainAnchorFromBase64(anchorBase64);
78
+ try {
79
+ return anchor.blockNum();
80
+ }
81
+ finally {
82
+ anchor.free();
83
+ }
84
+ }
85
+ /**
86
+ * Reads the salt a multisig transaction summary binds.
44
87
  *
45
- * This is the auth-arg word, *not* the proposal salt. When the request declares
46
- * a fee conversion salt, miden-client uses it to commit the native conversion
47
- * info under `hash(CONVERSION_INFO || SALT)`. That commitment is not invertible
48
- * to the salt. Keep the salt alongside the proposal — `ProposalMetadata.saltHex`
49
- * — rather than trying to recover it from the summary.
88
+ * Since protocol 0.17 the multisig auth components bind the salt itself into
89
+ * the summary's user params rather than a commitment derived from it, so the
90
+ * value cosigners signed over is readable again. A proposal still carries the
91
+ * salt in its metadata, because a request has to be rebuilt before any summary
92
+ * exists; this reader is the cross-check that the two agree.
93
+ */
94
+ export function summarySalt(summary) {
95
+ return Word.newFromFelts(summary.userParams().slice(SALT_USER_PARAM_OFFSET, SALT_USER_PARAM_OFFSET + 4));
96
+ }
97
+ /**
98
+ * Reads the block at which the approvers' signatures stop authorizing the
99
+ * transaction, or `undefined` for an approval that never expires, which is
100
+ * what this package's builders produce.
50
101
  */
51
- export function summaryAuthArg(summary) {
52
- return Word.newFromFelts(summary.userParams().slice(AUTH_ARG_USER_PARAM_OFFSET));
102
+ export function summaryApprovalExpirationBlockNum(summary) {
103
+ const value = summary.userParams()[APPROVAL_EXPIRATION_USER_PARAM_INDEX].asInt();
104
+ return value === 0n ? undefined : Number(value);
53
105
  }
54
106
  //# sourceMappingURL=summary.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"summary.js","sourceRoot":"","sources":["../../src/transaction/summary.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AACpE,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE9E;;;;GAIG;AACH,MAAM,0BAA0B,GAAG,CAAC,CAAC;AAsBrC,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,MAAmC,EACnC,SAAiB,EACjB,SAA6B,EAC7B,gBAAyB;IAEzB,MAAM,GAAG,GAAG,SAAS,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IACzC,MAAM,SAAS,GAAG,MAAM,iBAAiB,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;IACpE,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,qBAAqB,CAAC,SAAS,CAAC,CAAC;IAChE,MAAM,OAAO,GAAG,MAAM,SAAS,CAAC,mBAAmB,CAAC,GAAG,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;IAC5E,OAAO,EAAE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