@miden-sdk/miden-sdk 0.15.7 → 0.16.0-alpha.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.
- package/README.md +0 -152
- package/dist/mt/{Cargo-CnGom-_z.js → Cargo-DKsyWYgG.js} +700 -1245
- package/dist/mt/Cargo-DKsyWYgG.js.map +1 -0
- package/dist/mt/api-types.d.ts +38 -370
- package/dist/mt/assets/miden_client_web.wasm +0 -0
- package/dist/mt/crates/miden_client_web.d.ts +179 -402
- package/dist/mt/docs-entry.d.ts +3 -9
- package/dist/mt/eager.js +1 -1
- package/dist/mt/index.d.ts +0 -3
- package/dist/mt/index.js +53 -701
- package/dist/mt/index.js.map +1 -1
- package/dist/mt/wasm.js +1 -1
- package/dist/mt/workerHelpers.js +1 -1
- package/dist/mt/workers/{Cargo-CnGom-_z-X_3VwTbo.js → Cargo-DKsyWYgG-DfOhgt23.js} +700 -1245
- package/dist/mt/workers/Cargo-DKsyWYgG-DfOhgt23.js.map +1 -0
- package/dist/mt/workers/assets/miden_client_web.wasm +0 -0
- package/dist/mt/workers/web-client-methods-worker.js +703 -1251
- package/dist/mt/workers/web-client-methods-worker.js.map +1 -1
- package/dist/mt/workers/web-client-methods-worker.module.js +1 -1
- package/dist/mt/workers/web-client-methods-worker.module.js.map +1 -1
- package/dist/mt/workers/workerHelpers.js +1 -1
- package/dist/st/{Cargo-DR9fiMbE.js → Cargo-LwITdlzJ.js} +695 -1237
- package/dist/st/Cargo-LwITdlzJ.js.map +1 -0
- package/dist/st/api-types.d.ts +38 -370
- package/dist/st/assets/miden_client_web.wasm +0 -0
- package/dist/st/crates/miden_client_web.d.ts +179 -402
- package/dist/st/docs-entry.d.ts +3 -9
- package/dist/st/eager.js +1 -1
- package/dist/st/index.d.ts +0 -3
- package/dist/st/index.js +53 -701
- package/dist/st/index.js.map +1 -1
- package/dist/st/wasm.js +1 -1
- package/dist/st/workers/{Cargo-DR9fiMbE-C0G0clA_.js → Cargo-LwITdlzJ-Dyl2bCwN.js} +695 -1237
- package/dist/st/workers/Cargo-LwITdlzJ-Dyl2bCwN.js.map +1 -0
- package/dist/st/workers/assets/miden_client_web.wasm +0 -0
- package/dist/st/workers/web-client-methods-worker.js +698 -1243
- package/dist/st/workers/web-client-methods-worker.js.map +1 -1
- package/dist/st/workers/web-client-methods-worker.module.js +1 -1
- package/dist/st/workers/web-client-methods-worker.module.js.map +1 -1
- package/js/client.js +2 -4
- package/js/node/client-factory.js +4 -11
- package/js/node/napi-compat.js +1 -0
- package/js/node-index.js +11 -11
- package/js/resources/compiler.js +23 -12
- package/js/resources/transactions.js +24 -540
- package/js/standalone.js +3 -61
- package/package.json +4 -4
- package/dist/mt/Cargo-CnGom-_z.js.map +0 -1
- package/dist/mt/workers/Cargo-CnGom-_z-X_3VwTbo.js.map +0 -1
- package/dist/st/Cargo-DR9fiMbE.js.map +0 -1
- package/dist/st/workers/Cargo-DR9fiMbE-C0G0clA_.js.map +0 -1
- package/js/resources/pswap.js +0 -132
|
@@ -4,26 +4,6 @@ import {
|
|
|
4
4
|
resolveTransactionIdHex,
|
|
5
5
|
} from "../utils.js";
|
|
6
6
|
|
|
7
|
-
/**
|
|
8
|
-
* Prove an executed transaction, resolving the prover exactly the way the
|
|
9
|
-
* one-shot `submit()` pipeline does: the per-call prover if given, else the
|
|
10
|
-
* client's default prover, else the built-in local prover. Shared by
|
|
11
|
-
* {@link TransactionExecution.prove} and the internal pipeline so the two can
|
|
12
|
-
* never drift.
|
|
13
|
-
*
|
|
14
|
-
* @param {*} inner - The WASM WebClient.
|
|
15
|
-
* @param {*} defaultProver - The client's configured default prover, or null.
|
|
16
|
-
* @param {*} result - The execution result to prove.
|
|
17
|
-
* @param {{ prover?: * }} [opts] - Optional per-call prover override.
|
|
18
|
-
* @returns {Promise<*>} The proven transaction.
|
|
19
|
-
*/
|
|
20
|
-
async function proveResult(inner, defaultProver, result, opts) {
|
|
21
|
-
const prover = opts?.prover ?? defaultProver;
|
|
22
|
-
return prover
|
|
23
|
-
? await inner.proveTransaction(result, prover)
|
|
24
|
-
: await inner.proveTransaction(result);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
7
|
export class TransactionsResource {
|
|
28
8
|
#inner;
|
|
29
9
|
#getWasm;
|
|
@@ -99,97 +79,6 @@ export class TransactionsResource {
|
|
|
99
79
|
return { txId, note: null, result };
|
|
100
80
|
}
|
|
101
81
|
|
|
102
|
-
/**
|
|
103
|
-
* Builds a Public custom-script note carrying a NetworkAccountTarget
|
|
104
|
-
* attachment, submits it as an own output note, and optionally waits for
|
|
105
|
-
* confirmation. Provide exactly one of `recipient` or `script`.
|
|
106
|
-
*/
|
|
107
|
-
async createNetworkNote(opts) {
|
|
108
|
-
this.#client.assertNotTerminated();
|
|
109
|
-
const wasm = await this.#getWasm();
|
|
110
|
-
|
|
111
|
-
if (opts.recipient && opts.script) {
|
|
112
|
-
throw new Error(
|
|
113
|
-
"createNetworkNote requires exactly one of `recipient` or `script`, not both."
|
|
114
|
-
);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
const senderId = resolveAccountRef(opts.account, wasm);
|
|
118
|
-
|
|
119
|
-
const target =
|
|
120
|
-
opts.target instanceof wasm.NetworkAccountTarget
|
|
121
|
-
? opts.target
|
|
122
|
-
: new wasm.NetworkAccountTarget(
|
|
123
|
-
resolveAccountRef(opts.target, wasm),
|
|
124
|
-
opts.executionHint
|
|
125
|
-
);
|
|
126
|
-
|
|
127
|
-
const noteAssets = opts.assets
|
|
128
|
-
? new wasm.NoteAssets(
|
|
129
|
-
(Array.isArray(opts.assets) ? opts.assets : [opts.assets]).map(
|
|
130
|
-
(a) =>
|
|
131
|
-
new wasm.FungibleAsset(
|
|
132
|
-
resolveAccountRef(a.token, wasm),
|
|
133
|
-
BigInt(a.amount)
|
|
134
|
-
)
|
|
135
|
-
)
|
|
136
|
-
)
|
|
137
|
-
: new wasm.NoteAssets();
|
|
138
|
-
|
|
139
|
-
const metadata = new wasm.NoteMetadata(
|
|
140
|
-
senderId,
|
|
141
|
-
wasm.NoteType.Public,
|
|
142
|
-
wasm.NoteTag.withAccountTarget(target.targetId())
|
|
143
|
-
);
|
|
144
|
-
|
|
145
|
-
let recipient = opts.recipient;
|
|
146
|
-
if (!recipient) {
|
|
147
|
-
if (!opts.script) {
|
|
148
|
-
throw new Error(
|
|
149
|
-
"createNetworkNote requires either `recipient` or `script`."
|
|
150
|
-
);
|
|
151
|
-
}
|
|
152
|
-
const storage = new wasm.NoteStorage(
|
|
153
|
-
new wasm.FeltArray(
|
|
154
|
-
(opts.inputs ?? []).map((value) => new wasm.Felt(value))
|
|
155
|
-
)
|
|
156
|
-
);
|
|
157
|
-
recipient = wasm.NoteRecipient.fromScript(opts.script, storage);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
const attachments = [target.toAttachment()];
|
|
161
|
-
if (opts.attachment) {
|
|
162
|
-
attachments.push(new wasm.NoteAttachment(opts.attachment));
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
const note = wasm.Note.withAttachments(
|
|
166
|
-
noteAssets,
|
|
167
|
-
metadata,
|
|
168
|
-
recipient,
|
|
169
|
-
attachments
|
|
170
|
-
);
|
|
171
|
-
|
|
172
|
-
// NoteArray constructor consumes its elements; use push(¬e) to keep
|
|
173
|
-
// `note` valid so we can return it to the caller.
|
|
174
|
-
const ownOutputs = new wasm.NoteArray();
|
|
175
|
-
ownOutputs.push(note);
|
|
176
|
-
const request = new wasm.TransactionRequestBuilder()
|
|
177
|
-
.withOwnOutputNotes(ownOutputs)
|
|
178
|
-
.build();
|
|
179
|
-
|
|
180
|
-
const { txId, result } = await this.#submitOrSubmitWithProver(
|
|
181
|
-
senderId,
|
|
182
|
-
request,
|
|
183
|
-
opts.prover
|
|
184
|
-
);
|
|
185
|
-
|
|
186
|
-
if (opts.waitForConfirmation) {
|
|
187
|
-
await this.waitFor(txId.toHex(), { timeout: opts.timeout });
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
return { txId, note, result };
|
|
191
|
-
}
|
|
192
|
-
|
|
193
82
|
async mint(opts) {
|
|
194
83
|
this.#client.assertNotTerminated();
|
|
195
84
|
const wasm = await this.#getWasm();
|
|
@@ -208,24 +97,6 @@ export class TransactionsResource {
|
|
|
208
97
|
return { txId, result };
|
|
209
98
|
}
|
|
210
99
|
|
|
211
|
-
async bridge(opts) {
|
|
212
|
-
this.#client.assertNotTerminated();
|
|
213
|
-
const wasm = await this.#getWasm();
|
|
214
|
-
const { accountId, request } = await this.#buildB2AggRequest(opts, wasm);
|
|
215
|
-
|
|
216
|
-
const { txId, result } = await this.#submitOrSubmitWithProver(
|
|
217
|
-
accountId,
|
|
218
|
-
request,
|
|
219
|
-
opts.prover
|
|
220
|
-
);
|
|
221
|
-
|
|
222
|
-
if (opts.waitForConfirmation) {
|
|
223
|
-
await this.waitFor(txId.toHex(), { timeout: opts.timeout });
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
return { txId, result };
|
|
227
|
-
}
|
|
228
|
-
|
|
229
100
|
async consume(opts) {
|
|
230
101
|
this.#client.assertNotTerminated();
|
|
231
102
|
const wasm = await this.#getWasm();
|
|
@@ -372,6 +243,14 @@ export class TransactionsResource {
|
|
|
372
243
|
return { txId, result };
|
|
373
244
|
}
|
|
374
245
|
|
|
246
|
+
/**
|
|
247
|
+
* Dry-run a transaction to obtain the TransactionSummary pending
|
|
248
|
+
* authorization (e.g. a multisig below its signing threshold). Rejects
|
|
249
|
+
* with an error carrying `code: "TRANSACTION_ALREADY_AUTHORIZED"` (on
|
|
250
|
+
* Node.js the code prefixes the message instead) when the transaction
|
|
251
|
+
* executes successfully, since a fully authorized transaction produces
|
|
252
|
+
* no summary. See {@link PreviewOptions}.
|
|
253
|
+
*/
|
|
375
254
|
async preview(opts) {
|
|
376
255
|
this.#client.assertNotTerminated();
|
|
377
256
|
const wasm = await this.#getWasm();
|
|
@@ -388,10 +267,6 @@ export class TransactionsResource {
|
|
|
388
267
|
({ accountId, request } = await this.#buildMintRequest(opts, wasm));
|
|
389
268
|
break;
|
|
390
269
|
}
|
|
391
|
-
case "bridge": {
|
|
392
|
-
({ accountId, request } = await this.#buildB2AggRequest(opts, wasm));
|
|
393
|
-
break;
|
|
394
|
-
}
|
|
395
270
|
case "consume": {
|
|
396
271
|
({ accountId, request } = await this.#buildConsumeRequest(opts, wasm));
|
|
397
272
|
break;
|
|
@@ -436,163 +311,6 @@ export class TransactionsResource {
|
|
|
436
311
|
async execute(opts) {
|
|
437
312
|
this.#client.assertNotTerminated();
|
|
438
313
|
const wasm = await this.#getWasm();
|
|
439
|
-
const { accountId, request } = this.#buildExecuteRequest(opts, wasm);
|
|
440
|
-
|
|
441
|
-
const { txId, result } = await this.#submitOrSubmitWithProver(
|
|
442
|
-
accountId,
|
|
443
|
-
request,
|
|
444
|
-
opts.prover
|
|
445
|
-
);
|
|
446
|
-
|
|
447
|
-
if (opts.waitForConfirmation) {
|
|
448
|
-
await this.waitFor(txId.toHex(), { timeout: opts.timeout });
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
return { txId, result };
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
/**
|
|
455
|
-
* Submit a heterogeneous batch of operations against a single account. All
|
|
456
|
-
* operations are executed, proven individually and as a batch, and submitted
|
|
457
|
-
* atomically — either every tx in the batch lands or none does.
|
|
458
|
-
*
|
|
459
|
-
* @param {BatchOptions} opts - Batch options including the account, operations array, and confirmation settings.
|
|
460
|
-
* @returns {Promise<BatchSubmitResult>} The block number the batch was accepted into.
|
|
461
|
-
*/
|
|
462
|
-
async batch(opts) {
|
|
463
|
-
this.#client.assertNotTerminated();
|
|
464
|
-
const wasm = await this.#getWasm();
|
|
465
|
-
|
|
466
|
-
if (!opts || !opts.account) {
|
|
467
|
-
throw new Error("batch: `account` is required");
|
|
468
|
-
}
|
|
469
|
-
if (!Array.isArray(opts.operations) || opts.operations.length === 0) {
|
|
470
|
-
throw new Error("batch: `operations` must be a non-empty array");
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
// Build each TransactionRequest. Per-op builders all use the batch-level
|
|
474
|
-
// `account` — V1 only supports same-account batches, mirroring the Rust
|
|
475
|
-
// constraint. We forward `opts.account` into each per-op options object so
|
|
476
|
-
// the existing builders' `resolveAccountRef` produces fresh AccountIds
|
|
477
|
-
// when needed.
|
|
478
|
-
const requests = [];
|
|
479
|
-
for (let i = 0; i < opts.operations.length; i++) {
|
|
480
|
-
const op = opts.operations[i];
|
|
481
|
-
let built;
|
|
482
|
-
switch (op?.kind) {
|
|
483
|
-
case "send":
|
|
484
|
-
built = await this.#buildSendRequest(
|
|
485
|
-
{ ...op, account: opts.account },
|
|
486
|
-
wasm
|
|
487
|
-
);
|
|
488
|
-
break;
|
|
489
|
-
case "mint":
|
|
490
|
-
built = await this.#buildMintRequest(
|
|
491
|
-
{ ...op, account: opts.account },
|
|
492
|
-
wasm
|
|
493
|
-
);
|
|
494
|
-
break;
|
|
495
|
-
case "consume":
|
|
496
|
-
built = await this.#buildConsumeRequest(
|
|
497
|
-
{ ...op, account: opts.account },
|
|
498
|
-
wasm
|
|
499
|
-
);
|
|
500
|
-
break;
|
|
501
|
-
case "swap":
|
|
502
|
-
built = await this.#buildSwapRequest(
|
|
503
|
-
{ ...op, account: opts.account },
|
|
504
|
-
wasm
|
|
505
|
-
);
|
|
506
|
-
break;
|
|
507
|
-
case "execute":
|
|
508
|
-
built = this.#buildExecuteRequest(
|
|
509
|
-
{ ...op, account: opts.account },
|
|
510
|
-
wasm
|
|
511
|
-
);
|
|
512
|
-
break;
|
|
513
|
-
case "custom":
|
|
514
|
-
if (!op.request) {
|
|
515
|
-
throw new Error(
|
|
516
|
-
`batch: operation[${i}] of kind "custom" is missing \`request\``
|
|
517
|
-
);
|
|
518
|
-
}
|
|
519
|
-
built = { request: op.request };
|
|
520
|
-
break;
|
|
521
|
-
default:
|
|
522
|
-
throw new Error(
|
|
523
|
-
`batch: operation[${i}] has unknown kind "${op?.kind}"`
|
|
524
|
-
);
|
|
525
|
-
}
|
|
526
|
-
requests.push(built.request);
|
|
527
|
-
}
|
|
528
|
-
|
|
529
|
-
return this.submitBatch(opts.account, requests, opts);
|
|
530
|
-
}
|
|
531
|
-
|
|
532
|
-
/**
|
|
533
|
-
* Submit pre-built TransactionRequests as an atomic batch. Lower-level
|
|
534
|
-
* counterpart of `batch()` — for callers that already have built requests in
|
|
535
|
-
* hand. Equivalent to `submit()` but plural.
|
|
536
|
-
*
|
|
537
|
-
* @param {AccountRef} account - The account executing the batch.
|
|
538
|
-
* @param {TransactionRequest[]} requests - Pre-built transaction requests.
|
|
539
|
-
* @param {object} [options] - Optional settings (waitForConfirmation, timeout).
|
|
540
|
-
* The batch is proved with the client's configured prover; the V1 batch API
|
|
541
|
-
* has no per-call prover override.
|
|
542
|
-
* @returns {Promise<BatchSubmitResult>} The block number the batch was accepted into.
|
|
543
|
-
*/
|
|
544
|
-
async submitBatch(account, requests, options) {
|
|
545
|
-
this.#client.assertNotTerminated();
|
|
546
|
-
const wasm = await this.#getWasm();
|
|
547
|
-
|
|
548
|
-
if (!Array.isArray(requests) || requests.length === 0) {
|
|
549
|
-
throw new Error("submitBatch: `requests` must be a non-empty array");
|
|
550
|
-
}
|
|
551
|
-
|
|
552
|
-
const accountId = resolveAccountRef(account, wasm);
|
|
553
|
-
const blockNumber = await this.#inner.submitNewTransactionBatch(
|
|
554
|
-
accountId,
|
|
555
|
-
requests.map((r) => r.serialize())
|
|
556
|
-
);
|
|
557
|
-
|
|
558
|
-
if (options?.waitForConfirmation) {
|
|
559
|
-
await this.#waitForBlock(blockNumber, options);
|
|
560
|
-
}
|
|
561
|
-
|
|
562
|
-
return { blockNumber };
|
|
563
|
-
}
|
|
564
|
-
|
|
565
|
-
/**
|
|
566
|
-
* Polls until the local sync height reaches `blockNumber` or the timeout
|
|
567
|
-
* expires. The Rust V1 batch API returns only a block number — there are no
|
|
568
|
-
* per-tx ids to poll on, so we wait on the chain height instead.
|
|
569
|
-
*
|
|
570
|
-
* @param {number} blockNumber - The block height to wait for.
|
|
571
|
-
* @param {object} [opts] - Polling options (timeout, interval).
|
|
572
|
-
*/
|
|
573
|
-
async #waitForBlock(blockNumber, opts) {
|
|
574
|
-
const timeout = opts?.timeout ?? 60_000;
|
|
575
|
-
const interval = opts?.interval ?? 5_000;
|
|
576
|
-
const start = Date.now();
|
|
577
|
-
|
|
578
|
-
while (true) {
|
|
579
|
-
if (timeout > 0 && Date.now() - start >= timeout) {
|
|
580
|
-
throw new Error(
|
|
581
|
-
`Batch confirmation timed out after ${timeout}ms (waiting for block ${blockNumber})`
|
|
582
|
-
);
|
|
583
|
-
}
|
|
584
|
-
try {
|
|
585
|
-
await this.#inner.syncStateWithTimeout(0);
|
|
586
|
-
} catch {
|
|
587
|
-
// sync may fail transiently; continue polling
|
|
588
|
-
}
|
|
589
|
-
const height = await this.#inner.getSyncHeight();
|
|
590
|
-
if (height >= blockNumber) return;
|
|
591
|
-
await new Promise((resolve) => setTimeout(resolve, interval));
|
|
592
|
-
}
|
|
593
|
-
}
|
|
594
|
-
|
|
595
|
-
#buildExecuteRequest(opts, wasm) {
|
|
596
314
|
const accountId = resolveAccountRef(opts.account, wasm);
|
|
597
315
|
|
|
598
316
|
let builder = new wasm.TransactionRequestBuilder().withCustomScript(
|
|
@@ -620,7 +338,18 @@ export class TransactionsResource {
|
|
|
620
338
|
);
|
|
621
339
|
}
|
|
622
340
|
|
|
623
|
-
|
|
341
|
+
const request = builder.build();
|
|
342
|
+
const { txId, result } = await this.#submitOrSubmitWithProver(
|
|
343
|
+
accountId,
|
|
344
|
+
request,
|
|
345
|
+
opts.prover
|
|
346
|
+
);
|
|
347
|
+
|
|
348
|
+
if (opts.waitForConfirmation) {
|
|
349
|
+
await this.waitFor(txId.toHex(), { timeout: opts.timeout });
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
return { txId, result };
|
|
624
353
|
}
|
|
625
354
|
|
|
626
355
|
async executeProgram(opts) {
|
|
@@ -665,65 +394,6 @@ export class TransactionsResource {
|
|
|
665
394
|
);
|
|
666
395
|
}
|
|
667
396
|
|
|
668
|
-
/**
|
|
669
|
-
* Execute a transaction request locally — nothing is proven, submitted, or
|
|
670
|
-
* persisted. Returns a {@link TransactionExecution} handle; advance the
|
|
671
|
-
* lifecycle by chaining `.prove()` → `.submit()` → `.apply()`, benchmarking
|
|
672
|
-
* or error-handling each stage independently. Use {@link submit} to run every
|
|
673
|
-
* stage in one call.
|
|
674
|
-
*
|
|
675
|
-
* ```ts
|
|
676
|
-
* const executed = await client.transactions.executeRequest(account, request);
|
|
677
|
-
* const proven = await executed.prove({ prover });
|
|
678
|
-
* const submitted = await proven.submit();
|
|
679
|
-
* await submitted.apply();
|
|
680
|
-
* ```
|
|
681
|
-
*
|
|
682
|
-
* The stages are NOT atomic as a group: awaiting other mutating calls on the
|
|
683
|
-
* same account between them can interleave state. Drive the chain as an
|
|
684
|
-
* uninterrupted sequence per account.
|
|
685
|
-
*
|
|
686
|
-
* @param {AccountRef} account - The account executing the transaction.
|
|
687
|
-
* @param {TransactionRequest} request - The pre-built transaction request.
|
|
688
|
-
* @returns {Promise<TransactionExecution>} A handle to the executed
|
|
689
|
-
* transaction, ready to prove.
|
|
690
|
-
*/
|
|
691
|
-
async executeRequest(account, request) {
|
|
692
|
-
this.#client.assertNotTerminated();
|
|
693
|
-
const wasm = await this.#getWasm();
|
|
694
|
-
const accountId = resolveAccountRef(account, wasm);
|
|
695
|
-
const result = await this.#inner.executeTransaction(accountId, request);
|
|
696
|
-
return new TransactionExecution(this.#inner, this.#client, this, result);
|
|
697
|
-
}
|
|
698
|
-
|
|
699
|
-
/**
|
|
700
|
-
* Submit a proof produced somewhere that shares nothing with this client —
|
|
701
|
-
* e.g. a detached prover that never saw the local store. Returns a
|
|
702
|
-
* {@link TransactionSubmission} handle; call `.apply()` on it to persist
|
|
703
|
-
* locally. For the in-process flow prefer
|
|
704
|
-
* `executeRequest(...)` → `.prove()` → `.submit()`, which threads the proof
|
|
705
|
-
* and result for you.
|
|
706
|
-
*
|
|
707
|
-
* @param {ProvenTransaction} proof - A proof for `result`, proven elsewhere.
|
|
708
|
-
* @param {TransactionResult} result - The matching execution result.
|
|
709
|
-
* @returns {Promise<TransactionSubmission>} A handle to the submitted
|
|
710
|
-
* transaction, ready to apply.
|
|
711
|
-
*/
|
|
712
|
-
async submitProven(proof, result) {
|
|
713
|
-
this.#client.assertNotTerminated();
|
|
714
|
-
const blockNumber = await this.#inner.submitProvenTransaction(
|
|
715
|
-
proof,
|
|
716
|
-
result
|
|
717
|
-
);
|
|
718
|
-
return new TransactionSubmission(
|
|
719
|
-
this.#inner,
|
|
720
|
-
this.#client,
|
|
721
|
-
this,
|
|
722
|
-
result,
|
|
723
|
-
blockNumber
|
|
724
|
-
);
|
|
725
|
-
}
|
|
726
|
-
|
|
727
397
|
async list(query) {
|
|
728
398
|
this.#client.assertNotTerminated();
|
|
729
399
|
const wasm = await this.#getWasm();
|
|
@@ -852,24 +522,6 @@ export class TransactionsResource {
|
|
|
852
522
|
return { accountId, request };
|
|
853
523
|
}
|
|
854
524
|
|
|
855
|
-
async #buildB2AggRequest(opts, wasm) {
|
|
856
|
-
const accountId = resolveAccountRef(opts.account, wasm);
|
|
857
|
-
const bridgeAccountId = resolveAccountRef(opts.bridgeAccount, wasm);
|
|
858
|
-
const faucetId = resolveAccountRef(opts.token, wasm);
|
|
859
|
-
const amount = BigInt(opts.amount);
|
|
860
|
-
const destinationAddress = wasm.EthAddress.fromHex(opts.destinationAddress);
|
|
861
|
-
|
|
862
|
-
const request = await this.#inner.newB2AggTransactionRequest(
|
|
863
|
-
accountId,
|
|
864
|
-
bridgeAccountId,
|
|
865
|
-
faucetId,
|
|
866
|
-
amount,
|
|
867
|
-
opts.destinationNetwork,
|
|
868
|
-
destinationAddress
|
|
869
|
-
);
|
|
870
|
-
return { accountId, request };
|
|
871
|
-
}
|
|
872
|
-
|
|
873
525
|
async #buildConsumeRequest(opts, wasm) {
|
|
874
526
|
const accountId = resolveAccountRef(opts.account, wasm);
|
|
875
527
|
const noteInputs = Array.isArray(opts.notes) ? opts.notes : [opts.notes];
|
|
@@ -1014,181 +666,13 @@ export class TransactionsResource {
|
|
|
1014
666
|
|
|
1015
667
|
async #submitOrSubmitWithProver(accountId, request, perCallProver) {
|
|
1016
668
|
const result = await this.#inner.executeTransaction(accountId, request);
|
|
1017
|
-
const
|
|
1018
|
-
|
|
1019
|
-
this.#
|
|
1020
|
-
result
|
|
1021
|
-
{ prover: perCallProver }
|
|
1022
|
-
);
|
|
669
|
+
const prover = perCallProver ?? this.#client.defaultProver;
|
|
670
|
+
const proven = prover
|
|
671
|
+
? await this.#inner.proveTransaction(result, prover)
|
|
672
|
+
: await this.#inner.proveTransaction(result);
|
|
1023
673
|
const txId = result.id();
|
|
1024
674
|
const height = await this.#inner.submitProvenTransaction(proven, result);
|
|
1025
675
|
await this.#inner.applyTransaction(result, height);
|
|
1026
676
|
return { txId, result };
|
|
1027
677
|
}
|
|
1028
678
|
}
|
|
1029
|
-
|
|
1030
|
-
/**
|
|
1031
|
-
* A locally-executed transaction — nothing proven, submitted, or persisted yet.
|
|
1032
|
-
* First stage of the manual transaction lifecycle, returned by
|
|
1033
|
-
* {@link TransactionsResource.executeRequest}. Advance it with {@link prove}.
|
|
1034
|
-
*/
|
|
1035
|
-
class TransactionExecution {
|
|
1036
|
-
#inner;
|
|
1037
|
-
#client;
|
|
1038
|
-
#resource;
|
|
1039
|
-
#result;
|
|
1040
|
-
|
|
1041
|
-
constructor(inner, client, resource, result) {
|
|
1042
|
-
this.#inner = inner;
|
|
1043
|
-
this.#client = client;
|
|
1044
|
-
this.#resource = resource;
|
|
1045
|
-
this.#result = result;
|
|
1046
|
-
}
|
|
1047
|
-
|
|
1048
|
-
/** The raw execution artifact (account delta, output notes, …). */
|
|
1049
|
-
get result() {
|
|
1050
|
-
return this.#result;
|
|
1051
|
-
}
|
|
1052
|
-
|
|
1053
|
-
/** The executed transaction's id. */
|
|
1054
|
-
get id() {
|
|
1055
|
-
return this.#result.id();
|
|
1056
|
-
}
|
|
1057
|
-
|
|
1058
|
-
/**
|
|
1059
|
-
* Prove this execution. Uses the per-call prover when provided, falling back
|
|
1060
|
-
* to the client's default prover (or the built-in local prover). Pure
|
|
1061
|
-
* computation — touches neither the network nor the local store.
|
|
1062
|
-
*
|
|
1063
|
-
* A `TransactionProver` is consumed by the call: build (or clone) a fresh
|
|
1064
|
-
* prover per `prove()`. Reusing an already-passed prover silently falls back
|
|
1065
|
-
* to the built-in local prover.
|
|
1066
|
-
*
|
|
1067
|
-
* @param {ProveOptions} [opts] - Optional per-call prover override.
|
|
1068
|
-
* @returns {Promise<TransactionProof>} A handle to the proven transaction,
|
|
1069
|
-
* ready to submit.
|
|
1070
|
-
*/
|
|
1071
|
-
async prove(opts) {
|
|
1072
|
-
this.#client.assertNotTerminated();
|
|
1073
|
-
const proven = await proveResult(
|
|
1074
|
-
this.#inner,
|
|
1075
|
-
this.#client.defaultProver,
|
|
1076
|
-
this.#result,
|
|
1077
|
-
opts
|
|
1078
|
-
);
|
|
1079
|
-
return new TransactionProof(
|
|
1080
|
-
this.#inner,
|
|
1081
|
-
this.#client,
|
|
1082
|
-
this.#resource,
|
|
1083
|
-
proven,
|
|
1084
|
-
this.#result
|
|
1085
|
-
);
|
|
1086
|
-
}
|
|
1087
|
-
}
|
|
1088
|
-
|
|
1089
|
-
/**
|
|
1090
|
-
* A proven transaction, ready for the network. Second stage of the manual
|
|
1091
|
-
* transaction lifecycle, returned by {@link TransactionExecution.prove}.
|
|
1092
|
-
* Advance it with {@link submit}.
|
|
1093
|
-
*/
|
|
1094
|
-
class TransactionProof {
|
|
1095
|
-
#inner;
|
|
1096
|
-
#client;
|
|
1097
|
-
#resource;
|
|
1098
|
-
#proof;
|
|
1099
|
-
#result;
|
|
1100
|
-
|
|
1101
|
-
constructor(inner, client, resource, proof, result) {
|
|
1102
|
-
this.#inner = inner;
|
|
1103
|
-
this.#client = client;
|
|
1104
|
-
this.#resource = resource;
|
|
1105
|
-
this.#proof = proof;
|
|
1106
|
-
this.#result = result;
|
|
1107
|
-
}
|
|
1108
|
-
|
|
1109
|
-
/** The raw proof — e.g. to serialize and submit from a different client. */
|
|
1110
|
-
get proof() {
|
|
1111
|
-
return this.#proof;
|
|
1112
|
-
}
|
|
1113
|
-
|
|
1114
|
-
/** The execution result this proof was produced from. */
|
|
1115
|
-
get result() {
|
|
1116
|
-
return this.#result;
|
|
1117
|
-
}
|
|
1118
|
-
|
|
1119
|
-
/**
|
|
1120
|
-
* Submit the proof to the network. Does NOT persist locally — call
|
|
1121
|
-
* {@link TransactionSubmission.apply} on the returned handle; skipping it
|
|
1122
|
-
* leaves the local store out of sync until the next full sync.
|
|
1123
|
-
*
|
|
1124
|
-
* @returns {Promise<TransactionSubmission>} A handle to the submitted
|
|
1125
|
-
* transaction, ready to apply.
|
|
1126
|
-
*/
|
|
1127
|
-
async submit() {
|
|
1128
|
-
this.#client.assertNotTerminated();
|
|
1129
|
-
const blockNumber = await this.#inner.submitProvenTransaction(
|
|
1130
|
-
this.#proof,
|
|
1131
|
-
this.#result
|
|
1132
|
-
);
|
|
1133
|
-
return new TransactionSubmission(
|
|
1134
|
-
this.#inner,
|
|
1135
|
-
this.#client,
|
|
1136
|
-
this.#resource,
|
|
1137
|
-
this.#result,
|
|
1138
|
-
blockNumber
|
|
1139
|
-
);
|
|
1140
|
-
}
|
|
1141
|
-
}
|
|
1142
|
-
|
|
1143
|
-
/**
|
|
1144
|
-
* A submitted transaction. Final stage of the manual transaction lifecycle,
|
|
1145
|
-
* returned by {@link TransactionProof.submit}. Persist it locally with
|
|
1146
|
-
* {@link apply}, or block until it commits with {@link waitForConfirmation}.
|
|
1147
|
-
*/
|
|
1148
|
-
class TransactionSubmission {
|
|
1149
|
-
#inner;
|
|
1150
|
-
#client;
|
|
1151
|
-
#resource;
|
|
1152
|
-
#result;
|
|
1153
|
-
#blockNumber;
|
|
1154
|
-
|
|
1155
|
-
constructor(inner, client, resource, result, blockNumber) {
|
|
1156
|
-
this.#inner = inner;
|
|
1157
|
-
this.#client = client;
|
|
1158
|
-
this.#resource = resource;
|
|
1159
|
-
this.#result = result;
|
|
1160
|
-
this.#blockNumber = blockNumber;
|
|
1161
|
-
}
|
|
1162
|
-
|
|
1163
|
-
/** The block height the transaction was submitted at. */
|
|
1164
|
-
get blockNumber() {
|
|
1165
|
-
return this.#blockNumber;
|
|
1166
|
-
}
|
|
1167
|
-
|
|
1168
|
-
/** The execution result that was submitted. */
|
|
1169
|
-
get result() {
|
|
1170
|
-
return this.#result;
|
|
1171
|
-
}
|
|
1172
|
-
|
|
1173
|
-
/**
|
|
1174
|
-
* Persist the transaction into the local store, firing registered
|
|
1175
|
-
* transaction observers (e.g. PSWAP lineage tracking). Until this runs the
|
|
1176
|
-
* local store is unaware of the transaction.
|
|
1177
|
-
*
|
|
1178
|
-
* @returns {Promise<TransactionStoreUpdate>} The pre-apply store update.
|
|
1179
|
-
*/
|
|
1180
|
-
async apply() {
|
|
1181
|
-
this.#client.assertNotTerminated();
|
|
1182
|
-
return await this.#inner.applyTransaction(this.#result, this.#blockNumber);
|
|
1183
|
-
}
|
|
1184
|
-
|
|
1185
|
-
/**
|
|
1186
|
-
* Poll local sync height until the transaction commits on-chain. Convenience
|
|
1187
|
-
* wrapper over {@link TransactionsResource.waitFor}.
|
|
1188
|
-
*
|
|
1189
|
-
* @param {WaitOptions} [opts] - Polling options (timeout, interval, onProgress).
|
|
1190
|
-
*/
|
|
1191
|
-
async waitForConfirmation(opts) {
|
|
1192
|
-
return await this.#resource.waitFor(this.#result.id().toHex(), opts);
|
|
1193
|
-
}
|
|
1194
|
-
}
|
package/js/standalone.js
CHANGED
|
@@ -101,70 +101,12 @@ export function buildSwapTag(opts) {
|
|
|
101
101
|
|
|
102
102
|
function buildNoteAssets(assets, wasm) {
|
|
103
103
|
const assetArray = Array.isArray(assets) ? assets : [assets];
|
|
104
|
+
if (assetArray.length === 0) {
|
|
105
|
+
throw new TypeError("P2ID and P2IDE notes require at least one asset");
|
|
106
|
+
}
|
|
104
107
|
const fungibleAssets = assetArray.map((asset) => {
|
|
105
108
|
const faucetId = resolveAccountRef(asset.token, wasm);
|
|
106
109
|
return new wasm.FungibleAsset(faucetId, BigInt(asset.amount));
|
|
107
110
|
});
|
|
108
111
|
return new wasm.NoteAssets(fungibleAssets);
|
|
109
112
|
}
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* Builds a Public custom-script note carrying a NetworkAccountTarget attachment
|
|
113
|
-
* (does not submit). Provide exactly one of `recipient` or `script`.
|
|
114
|
-
*
|
|
115
|
-
* @param {NetworkNoteOptions} opts
|
|
116
|
-
* @returns {Note}
|
|
117
|
-
*/
|
|
118
|
-
export function buildNetworkNote(opts) {
|
|
119
|
-
const wasm = getWasm();
|
|
120
|
-
if (opts.recipient && opts.script) {
|
|
121
|
-
throw new Error(
|
|
122
|
-
"buildNetworkNote requires exactly one of `recipient` or `script`, not both."
|
|
123
|
-
);
|
|
124
|
-
}
|
|
125
|
-
const sender = resolveAccountRef(opts.account, wasm);
|
|
126
|
-
|
|
127
|
-
const target =
|
|
128
|
-
opts.target instanceof wasm.NetworkAccountTarget
|
|
129
|
-
? opts.target
|
|
130
|
-
: new wasm.NetworkAccountTarget(
|
|
131
|
-
resolveAccountRef(opts.target, wasm),
|
|
132
|
-
opts.executionHint
|
|
133
|
-
);
|
|
134
|
-
|
|
135
|
-
const noteAssets = opts.assets
|
|
136
|
-
? buildNoteAssets(opts.assets, wasm)
|
|
137
|
-
: new wasm.NoteAssets();
|
|
138
|
-
|
|
139
|
-
const metadata = new wasm.NoteMetadata(
|
|
140
|
-
sender,
|
|
141
|
-
wasm.NoteType.Public,
|
|
142
|
-
wasm.NoteTag.withAccountTarget(target.targetId())
|
|
143
|
-
);
|
|
144
|
-
|
|
145
|
-
const recipient = opts.recipient ?? buildRecipient(opts, wasm);
|
|
146
|
-
|
|
147
|
-
const attachments = [target.toAttachment()];
|
|
148
|
-
if (opts.attachment) {
|
|
149
|
-
attachments.push(new wasm.NoteAttachment(opts.attachment));
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
return wasm.Note.withAttachments(
|
|
153
|
-
noteAssets,
|
|
154
|
-
metadata,
|
|
155
|
-
recipient,
|
|
156
|
-
attachments
|
|
157
|
-
);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
function buildRecipient(opts, wasm) {
|
|
161
|
-
if (!opts.script) {
|
|
162
|
-
throw new Error(
|
|
163
|
-
"buildNetworkNote requires either `recipient` or `script`."
|
|
164
|
-
);
|
|
165
|
-
}
|
|
166
|
-
const storage = new wasm.NoteStorage(
|
|
167
|
-
new wasm.FeltArray((opts.inputs ?? []).map((value) => new wasm.Felt(value)))
|
|
168
|
-
);
|
|
169
|
-
return wasm.NoteRecipient.fromScript(opts.script, storage);
|
|
170
|
-
}
|