@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
|
@@ -5,26 +5,31 @@ import type {
|
|
|
5
5
|
WasmWebClient,
|
|
6
6
|
Word,
|
|
7
7
|
} from '@miden-sdk/miden-sdk';
|
|
8
|
-
import {
|
|
9
|
-
NoteAndArgs,
|
|
10
|
-
NoteAndArgsArray,
|
|
11
|
-
TransactionRequestBuilder,
|
|
12
|
-
Word as WordType,
|
|
13
|
-
} from '@miden-sdk/miden-sdk';
|
|
8
|
+
import { NoteAndArgs, NoteAndArgsArray } from '@miden-sdk/miden-sdk';
|
|
14
9
|
import { LegacyConsumeNotesNoteMissingError } from '../multisig/consumeNotesErrors.js';
|
|
15
10
|
import { getRawMidenClient } from '../raw-client.js';
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import type { MidenClientSignatureOptions, SignatureOptions } from './options.js';
|
|
11
|
+
import { buildMultisigRequest, multisigRequestBuilder } from './authArgs.js';
|
|
12
|
+
import type { MidenClientMultisigRequestOptions, MultisigRequestOptions } from './options.js';
|
|
19
13
|
|
|
20
14
|
/**
|
|
21
15
|
* Build a consume-notes request from loaded `Note` objects (no local-store
|
|
22
16
|
* read). v2 verification path for issue #229.
|
|
23
17
|
*/
|
|
24
18
|
export function buildConsumeNotesTransactionRequestFromNotes(
|
|
19
|
+
client: MidenClient,
|
|
20
|
+
notes: Note[],
|
|
21
|
+
options: MidenClientMultisigRequestOptions,
|
|
22
|
+
): Promise<{ request: TransactionRequest; salt: Word }>;
|
|
23
|
+
export function buildConsumeNotesTransactionRequestFromNotes(
|
|
24
|
+
client: WasmWebClient,
|
|
25
25
|
notes: Note[],
|
|
26
|
-
options:
|
|
27
|
-
): { request: TransactionRequest; salt: Word }
|
|
26
|
+
options: MultisigRequestOptions,
|
|
27
|
+
): Promise<{ request: TransactionRequest; salt: Word }>;
|
|
28
|
+
export async function buildConsumeNotesTransactionRequestFromNotes(
|
|
29
|
+
client: MidenClient | WasmWebClient,
|
|
30
|
+
notes: Note[],
|
|
31
|
+
options: MultisigRequestOptions,
|
|
32
|
+
): Promise<{ request: TransactionRequest; salt: Word }> {
|
|
28
33
|
if (notes.length === 0) {
|
|
29
34
|
throw new Error('At least one note is required');
|
|
30
35
|
}
|
|
@@ -34,26 +39,14 @@ export function buildConsumeNotesTransactionRequestFromNotes(
|
|
|
34
39
|
noteAndArgsArray.push(new NoteAndArgs(note, null));
|
|
35
40
|
}
|
|
36
41
|
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
let txBuilder = new TransactionRequestBuilder();
|
|
41
|
-
txBuilder = txBuilder.withInputNotes(noteAndArgsArray);
|
|
42
|
-
txBuilder = txBuilder.withFeeConversionSalt(authSaltForBuilder);
|
|
43
|
-
// Borrows rather than consumes: the glue passes `__wbg_ptr` without taking it,
|
|
44
|
-
// so the handle stays ours to release once the builder has read it.
|
|
45
|
-
authSaltForBuilder.free?.();
|
|
42
|
+
const { builder, saltHex } = await multisigRequestBuilder(client, options);
|
|
43
|
+
let txBuilder = builder.withInputNotes(noteAndArgsArray);
|
|
46
44
|
|
|
47
45
|
if (options.signatureAdviceMap) {
|
|
48
46
|
txBuilder = txBuilder.extendAdviceMap(options.signatureAdviceMap);
|
|
49
47
|
}
|
|
50
48
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
return {
|
|
54
|
-
request: txBuilder.build(),
|
|
55
|
-
salt: authSaltForReturn,
|
|
56
|
-
};
|
|
49
|
+
return buildMultisigRequest(txBuilder, saltHex, options.accountId);
|
|
57
50
|
}
|
|
58
51
|
|
|
59
52
|
/**
|
|
@@ -63,17 +56,17 @@ export function buildConsumeNotesTransactionRequestFromNotes(
|
|
|
63
56
|
export function buildConsumeNotesTransactionRequest(
|
|
64
57
|
client: MidenClient,
|
|
65
58
|
noteIds: string[],
|
|
66
|
-
options:
|
|
59
|
+
options: MidenClientMultisigRequestOptions,
|
|
67
60
|
): Promise<{ request: TransactionRequest; salt: Word }>;
|
|
68
61
|
export function buildConsumeNotesTransactionRequest(
|
|
69
62
|
client: WasmWebClient,
|
|
70
63
|
noteIds: string[],
|
|
71
|
-
options
|
|
64
|
+
options: MultisigRequestOptions,
|
|
72
65
|
): Promise<{ request: TransactionRequest; salt: Word }>;
|
|
73
66
|
export async function buildConsumeNotesTransactionRequest(
|
|
74
67
|
client: MidenClient | WasmWebClient,
|
|
75
68
|
noteIds: string[],
|
|
76
|
-
options:
|
|
69
|
+
options: MultisigRequestOptions,
|
|
77
70
|
): Promise<{ request: TransactionRequest; salt: Word }> {
|
|
78
71
|
if (noteIds.length === 0) {
|
|
79
72
|
throw new Error('At least one note ID is required');
|
|
@@ -89,5 +82,5 @@ export async function buildConsumeNotesTransactionRequest(
|
|
|
89
82
|
notes.push(inputNoteRecord.toNote());
|
|
90
83
|
}
|
|
91
84
|
|
|
92
|
-
return buildConsumeNotesTransactionRequestFromNotes(notes, options);
|
|
85
|
+
return buildConsumeNotesTransactionRequestFromNotes(rawClient, notes, options);
|
|
93
86
|
}
|
|
@@ -0,0 +1,136 @@
|
|
|
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, type Note, type NoteInclusionProof, RpcClient } from '@miden-sdk/miden-sdk';
|
|
17
|
+
|
|
18
|
+
import { ConsumeNoteNotAuthenticatedError } from '../multisig/consumeNotesErrors.js';
|
|
19
|
+
import type { RawClientSource } from '../raw-client.js';
|
|
20
|
+
import { getRawMidenClient } from '../raw-client.js';
|
|
21
|
+
import { importNoteWithProof } from '../recovery/proposalNoteImport.js';
|
|
22
|
+
import { resolveRpcConfig, type RpcConfig } from '../rpc/config.js';
|
|
23
|
+
import { retryRpcRead } from '../rpc/retry.js';
|
|
24
|
+
import { normalizeHexWord } from '../utils/encoding.js';
|
|
25
|
+
|
|
26
|
+
export interface EnsureNotesAuthenticatedOptions {
|
|
27
|
+
/** Miden node RPC endpoint the inclusion proofs are fetched from. */
|
|
28
|
+
midenRpcEndpoint: string;
|
|
29
|
+
/** Retry policy for the proof fetch; defaults to the SDK's RPC defaults. */
|
|
30
|
+
rpc?: RpcConfig;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Makes every note in `notes` an authenticated input note in the client's
|
|
35
|
+
* local store: present, with its on-chain inclusion proof and block header.
|
|
36
|
+
*
|
|
37
|
+
* Notes already authenticated locally are left alone. For the rest the
|
|
38
|
+
* inclusion proofs come from the node in one round trip (the node serves
|
|
39
|
+
* proofs for private notes too) and each note is imported as committed,
|
|
40
|
+
* which also upgrades a proof-less record the store already tracked.
|
|
41
|
+
*
|
|
42
|
+
* @throws {ConsumeNoteNotAuthenticatedError} when a note is not committed on
|
|
43
|
+
* chain yet, the node does not serve its proof, the import fails, or the
|
|
44
|
+
* record still lacks authentication after a sync.
|
|
45
|
+
*/
|
|
46
|
+
export async function ensureNotesAuthenticated(
|
|
47
|
+
midenClient: RawClientSource,
|
|
48
|
+
notes: readonly Note[],
|
|
49
|
+
options: EnsureNotesAuthenticatedOptions,
|
|
50
|
+
): Promise<void> {
|
|
51
|
+
const webClient = await getRawMidenClient(midenClient, options.midenRpcEndpoint);
|
|
52
|
+
const pending = await unauthenticatedNotes(webClient, notes);
|
|
53
|
+
if (pending.length === 0) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const proofs = new Map<string, NoteInclusionProof>();
|
|
58
|
+
try {
|
|
59
|
+
const rpcClient = new RpcClient(new Endpoint(options.midenRpcEndpoint));
|
|
60
|
+
const fetched = await retryRpcRead(
|
|
61
|
+
() => rpcClient.getNotesById(pending.map((note) => note.id())),
|
|
62
|
+
resolveRpcConfig(options.rpc),
|
|
63
|
+
);
|
|
64
|
+
for (const entry of fetched) {
|
|
65
|
+
proofs.set(normalizeHexWord(entry.noteId.toString()), entry.inclusionProof);
|
|
66
|
+
}
|
|
67
|
+
} catch (error) {
|
|
68
|
+
throw new ConsumeNoteNotAuthenticatedError(
|
|
69
|
+
noteIdHex(pending[0]),
|
|
70
|
+
`failed to fetch inclusion proofs from the node: ${errorDetail(error)}`,
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
for (const note of pending) {
|
|
75
|
+
const idHex = noteIdHex(note);
|
|
76
|
+
const proof = proofs.get(idHex);
|
|
77
|
+
if (!proof) {
|
|
78
|
+
throw new ConsumeNoteNotAuthenticatedError(
|
|
79
|
+
idHex,
|
|
80
|
+
'the node has no inclusion proof for it (not committed on chain yet)',
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
const { outcome, wasImported } = await importNoteWithProof(
|
|
84
|
+
webClient,
|
|
85
|
+
'proposal',
|
|
86
|
+
idHex,
|
|
87
|
+
note,
|
|
88
|
+
proof,
|
|
89
|
+
);
|
|
90
|
+
if (!wasImported) {
|
|
91
|
+
throw new ConsumeNoteNotAuthenticatedError(
|
|
92
|
+
idHex,
|
|
93
|
+
`failed to import it with its inclusion proof: ${outcome.reason ?? 'unknown error'}`,
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// The import authenticates a note committed at or below the client's sync
|
|
99
|
+
// height; a newer one lands unverified until a sync fetches its block
|
|
100
|
+
// header. A cosigner that just loaded the account is typically behind the
|
|
101
|
+
// note's block, so sync once and re-check before failing.
|
|
102
|
+
if ((await unauthenticatedNotes(webClient, notes)).length > 0) {
|
|
103
|
+
await webClient.syncState();
|
|
104
|
+
}
|
|
105
|
+
const still = await unauthenticatedNotes(webClient, notes);
|
|
106
|
+
if (still.length > 0) {
|
|
107
|
+
throw new ConsumeNoteNotAuthenticatedError(
|
|
108
|
+
noteIdHex(still[0]),
|
|
109
|
+
'its inclusion proof was imported but the local store could not verify it ' +
|
|
110
|
+
'against the chain even after a sync',
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** The subset of `notes` whose local record is missing or carries no proof. */
|
|
116
|
+
async function unauthenticatedNotes(
|
|
117
|
+
webClient: Awaited<ReturnType<typeof getRawMidenClient>>,
|
|
118
|
+
notes: readonly Note[],
|
|
119
|
+
): Promise<Note[]> {
|
|
120
|
+
const pending: Note[] = [];
|
|
121
|
+
for (const note of notes) {
|
|
122
|
+
const record = await webClient.getInputNote(noteIdHex(note));
|
|
123
|
+
if (!record || !record.isAuthenticated()) {
|
|
124
|
+
pending.push(note);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return pending;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function noteIdHex(note: Note): string {
|
|
131
|
+
return normalizeHexWord(note.id().toString());
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function errorDetail(error: unknown): string {
|
|
135
|
+
return error instanceof Error ? error.message : String(error);
|
|
136
|
+
}
|
|
@@ -6,8 +6,35 @@ export interface SignatureOptions {
|
|
|
6
6
|
signatureAdviceMap?: AdviceMap;
|
|
7
7
|
signatureScheme?: SignatureScheme;
|
|
8
8
|
midenRpcEndpoint?: string;
|
|
9
|
+
/**
|
|
10
|
+
* The block the transaction summary binds. Omitted, the store's sync height,
|
|
11
|
+
* which is right for the party creating a proposal. A cosigner or executor
|
|
12
|
+
* rebuilding a proposal pins it to the proposal's anchor block, or the rebuilt
|
|
13
|
+
* summary can never match the signed one.
|
|
14
|
+
*/
|
|
15
|
+
boundBlockNum?: number;
|
|
16
|
+
/**
|
|
17
|
+
* Blocks after the bound block at which the approvers' signatures stop
|
|
18
|
+
* authorizing the transaction, so it must be included by then. Bound by the
|
|
19
|
+
* summary, so a rebuild must pass the same value. At most 65535 blocks, the
|
|
20
|
+
* furthest a transaction can expire after its reference block; omitted, the
|
|
21
|
+
* approval never expires, which is the upstream default.
|
|
22
|
+
*/
|
|
23
|
+
approvalExpirationDelta?: number;
|
|
9
24
|
}
|
|
10
25
|
|
|
11
26
|
export interface MidenClientSignatureOptions extends SignatureOptions {
|
|
12
27
|
midenRpcEndpoint: string;
|
|
13
28
|
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Options for a request a multisig account executes. The account decides the
|
|
32
|
+
* auth args the request has to carry, so every multisig builder needs it.
|
|
33
|
+
*/
|
|
34
|
+
export interface MultisigRequestOptions extends SignatureOptions {
|
|
35
|
+
accountId: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface MidenClientMultisigRequestOptions extends MultisigRequestOptions {
|
|
39
|
+
midenRpcEndpoint: string;
|
|
40
|
+
}
|
package/src/transaction/p2id.ts
CHANGED
|
@@ -14,10 +14,10 @@ import {
|
|
|
14
14
|
NoteTag,
|
|
15
15
|
NoteType,
|
|
16
16
|
Poseidon2,
|
|
17
|
-
TransactionRequestBuilder,
|
|
18
17
|
Word as WordType,
|
|
19
18
|
} from '@miden-sdk/miden-sdk';
|
|
20
|
-
import {
|
|
19
|
+
import type { RawClientSource } from '../raw-client.js';
|
|
20
|
+
import { buildMultisigRequest, multisigRequestBuilder } from './authArgs.js';
|
|
21
21
|
import { normalizeHexWord } from '../utils/encoding.js';
|
|
22
22
|
import type { SignatureOptions } from './options.js';
|
|
23
23
|
import type { P2idNoteVisibility } from '../types/proposal.js';
|
|
@@ -74,6 +74,36 @@ export function deriveP2idSerialNumber(salt: Word): Word {
|
|
|
74
74
|
]));
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
+
/**
|
|
78
|
+
* P2ID storage since protocol 0.17 rc.5: target account, then a two-felt salt.
|
|
79
|
+
* Zero salt is the upstream default. A secret salt hides the target from
|
|
80
|
+
* guesses against the storage commitment; this builder keeps the note
|
|
81
|
+
* deterministic in the proposal salt, which already derives the serial number.
|
|
82
|
+
*/
|
|
83
|
+
function p2idStorage(recipient: AccountId): Felt[] {
|
|
84
|
+
return [recipient.suffix(), recipient.prefix(), new Felt(0n), new Felt(0n)];
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* P2IDE storage: reclaimer (the sender), target, then reclaim and timelock
|
|
89
|
+
* heights. Zero encodes an unset height. The script requires all six items.
|
|
90
|
+
*/
|
|
91
|
+
function p2ideStorage(
|
|
92
|
+
sender: AccountId,
|
|
93
|
+
recipient: AccountId,
|
|
94
|
+
reclaimHeight: number,
|
|
95
|
+
timelockHeight: number,
|
|
96
|
+
): Felt[] {
|
|
97
|
+
return [
|
|
98
|
+
sender.suffix(),
|
|
99
|
+
sender.prefix(),
|
|
100
|
+
recipient.suffix(),
|
|
101
|
+
recipient.prefix(),
|
|
102
|
+
new Felt(BigInt(reclaimHeight)),
|
|
103
|
+
new Felt(BigInt(timelockHeight)),
|
|
104
|
+
];
|
|
105
|
+
}
|
|
106
|
+
|
|
77
107
|
function buildP2idNote(
|
|
78
108
|
sender: AccountId,
|
|
79
109
|
recipient: AccountId,
|
|
@@ -89,19 +119,10 @@ function buildP2idNote(
|
|
|
89
119
|
const timelockHeight = parseP2ideHeight('timelockHeight', heights.timelockHeight);
|
|
90
120
|
const isP2ide = reclaimHeight !== undefined || timelockHeight !== undefined;
|
|
91
121
|
|
|
92
|
-
// P2IDE storage layout (miden-standards `P2ideNoteStorage`): the P2ID
|
|
93
|
-
// storage plus reclaim/timelock heights as felts, 0 encoding "unset".
|
|
94
122
|
const noteScript = isP2ide ? NoteScript.p2ide() : NoteScript.p2id();
|
|
95
|
-
const storageFelts =
|
|
96
|
-
recipient
|
|
97
|
-
recipient
|
|
98
|
-
];
|
|
99
|
-
if (isP2ide) {
|
|
100
|
-
storageFelts.push(
|
|
101
|
-
new Felt(BigInt(reclaimHeight ?? 0)),
|
|
102
|
-
new Felt(BigInt(timelockHeight ?? 0)),
|
|
103
|
-
);
|
|
104
|
-
}
|
|
123
|
+
const storageFelts = isP2ide
|
|
124
|
+
? p2ideStorage(sender, recipient, reclaimHeight ?? 0, timelockHeight ?? 0)
|
|
125
|
+
: p2idStorage(recipient);
|
|
105
126
|
const noteStorage = new NoteStorage(new FeltArray(storageFelts));
|
|
106
127
|
|
|
107
128
|
const noteRecipient = new NoteRecipient(serialNum, noteScript, noteStorage);
|
|
@@ -141,14 +162,18 @@ export function buildP2idNoteFromMetadata(
|
|
|
141
162
|
return buildP2idNote(sender, recipient, noteAssets, noteType, saltHex, heights);
|
|
142
163
|
}
|
|
143
164
|
|
|
144
|
-
export function buildP2idTransactionRequest(
|
|
165
|
+
export async function buildP2idTransactionRequest(
|
|
166
|
+
client: RawClientSource,
|
|
145
167
|
senderId: string,
|
|
146
168
|
recipientId: string,
|
|
147
169
|
faucetId: string,
|
|
148
170
|
amount: bigint,
|
|
149
171
|
options: P2idTransactionOptions = {},
|
|
150
|
-
): { request: TransactionRequest; salt: Word } {
|
|
151
|
-
const
|
|
172
|
+
): Promise<{ request: TransactionRequest; salt: Word }> {
|
|
173
|
+
const { builder, saltHex } = await multisigRequestBuilder(client, {
|
|
174
|
+
...options,
|
|
175
|
+
accountId: senderId,
|
|
176
|
+
});
|
|
152
177
|
|
|
153
178
|
const note = buildP2idNoteFromMetadata(
|
|
154
179
|
senderId,
|
|
@@ -156,29 +181,15 @@ export function buildP2idTransactionRequest(
|
|
|
156
181
|
faucetId,
|
|
157
182
|
amount,
|
|
158
183
|
options.noteType ?? NoteType.Public,
|
|
159
|
-
|
|
184
|
+
saltHex,
|
|
160
185
|
{ reclaimHeight: options.reclaimHeight, timelockHeight: options.timelockHeight },
|
|
161
186
|
);
|
|
162
187
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
const authSaltForBuilder = WordType.fromHex(normalizeHexWord(authSaltHex));
|
|
166
|
-
|
|
167
|
-
let txBuilder = new TransactionRequestBuilder();
|
|
168
|
-
txBuilder = txBuilder.withOwnOutputNotes(outputNotes);
|
|
169
|
-
txBuilder = txBuilder.withFeeConversionSalt(authSaltForBuilder);
|
|
170
|
-
// Borrows rather than consumes: the glue passes `__wbg_ptr` without taking it,
|
|
171
|
-
// so the handle stays ours to release once the builder has read it.
|
|
172
|
-
authSaltForBuilder.free?.();
|
|
188
|
+
let txBuilder = builder.withOwnOutputNotes(new MidenArrays.NoteArray([note]));
|
|
173
189
|
|
|
174
190
|
if (options.signatureAdviceMap) {
|
|
175
191
|
txBuilder = txBuilder.extendAdviceMap(options.signatureAdviceMap);
|
|
176
192
|
}
|
|
177
193
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
return {
|
|
181
|
-
request: txBuilder.build(),
|
|
182
|
-
salt: authSaltForReturn,
|
|
183
|
-
};
|
|
194
|
+
return buildMultisigRequest(txBuilder, saltHex, senderId);
|
|
184
195
|
}
|