@miden-sdk/miden-sdk 0.15.2 → 0.15.4

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 (46) hide show
  1. package/README.md +69 -0
  2. package/dist/mt/{Cargo-BbpPeJYa.js → Cargo-DjVnfWKi.js} +424 -88
  3. package/dist/mt/Cargo-DjVnfWKi.js.map +1 -0
  4. package/dist/mt/api-types.d.ts +130 -0
  5. package/dist/mt/assets/miden_client_web.wasm +0 -0
  6. package/dist/mt/crates/miden_client_web.d.ts +93 -3
  7. package/dist/mt/docs-entry.d.ts +2 -0
  8. package/dist/mt/eager.js +1 -1
  9. package/dist/mt/index.d.ts +3 -0
  10. package/dist/mt/index.js +211 -13
  11. package/dist/mt/index.js.map +1 -1
  12. package/dist/mt/wasm.js +1 -1
  13. package/dist/mt/workerHelpers.js +1 -1
  14. package/dist/mt/workers/{Cargo-BbpPeJYa-BlSVzh6v.js → Cargo-DjVnfWKi-DvLbB_Zb.js} +424 -88
  15. package/dist/mt/workers/Cargo-DjVnfWKi-DvLbB_Zb.js.map +1 -0
  16. package/dist/mt/workers/assets/miden_client_web.wasm +0 -0
  17. package/dist/mt/workers/web-client-methods-worker.js +425 -88
  18. package/dist/mt/workers/web-client-methods-worker.js.map +1 -1
  19. package/dist/mt/workers/web-client-methods-worker.module.js +1 -1
  20. package/dist/mt/workers/web-client-methods-worker.module.js.map +1 -1
  21. package/dist/mt/workers/workerHelpers.js +1 -1
  22. package/dist/st/{Cargo-Dlo4tWNG.js → Cargo-Cwpuvlbc.js} +433 -98
  23. package/dist/st/Cargo-Cwpuvlbc.js.map +1 -0
  24. package/dist/st/api-types.d.ts +130 -0
  25. package/dist/st/assets/miden_client_web.wasm +0 -0
  26. package/dist/st/crates/miden_client_web.d.ts +93 -3
  27. package/dist/st/docs-entry.d.ts +2 -0
  28. package/dist/st/eager.js +1 -1
  29. package/dist/st/index.d.ts +3 -0
  30. package/dist/st/index.js +211 -13
  31. package/dist/st/index.js.map +1 -1
  32. package/dist/st/wasm.js +1 -1
  33. package/dist/st/workers/{Cargo-Dlo4tWNG-BPaiqKyy.js → Cargo-Cwpuvlbc-B0V_MEMU.js} +433 -98
  34. package/dist/st/workers/Cargo-Cwpuvlbc-B0V_MEMU.js.map +1 -0
  35. package/dist/st/workers/assets/miden_client_web.wasm +0 -0
  36. package/dist/st/workers/web-client-methods-worker.js +434 -98
  37. package/dist/st/workers/web-client-methods-worker.js.map +1 -1
  38. package/dist/st/workers/web-client-methods-worker.module.js +1 -1
  39. package/dist/st/workers/web-client-methods-worker.module.js.map +1 -1
  40. package/js/node-index.js +150 -40
  41. package/js/resources/transactions.js +198 -12
  42. package/package.json +6 -4
  43. package/dist/mt/Cargo-BbpPeJYa.js.map +0 -1
  44. package/dist/mt/workers/Cargo-BbpPeJYa-BlSVzh6v.js.map +0 -1
  45. package/dist/st/Cargo-Dlo4tWNG.js.map +0 -1
  46. package/dist/st/workers/Cargo-Dlo4tWNG-BPaiqKyy.js.map +0 -1
@@ -97,6 +97,24 @@ export class TransactionsResource {
97
97
  return { txId, result };
98
98
  }
99
99
 
100
+ async bridge(opts) {
101
+ this.#client.assertNotTerminated();
102
+ const wasm = await this.#getWasm();
103
+ const { accountId, request } = await this.#buildB2AggRequest(opts, wasm);
104
+
105
+ const { txId, result } = await this.#submitOrSubmitWithProver(
106
+ accountId,
107
+ request,
108
+ opts.prover
109
+ );
110
+
111
+ if (opts.waitForConfirmation) {
112
+ await this.waitFor(txId.toHex(), { timeout: opts.timeout });
113
+ }
114
+
115
+ return { txId, result };
116
+ }
117
+
100
118
  async consume(opts) {
101
119
  this.#client.assertNotTerminated();
102
120
  const wasm = await this.#getWasm();
@@ -259,6 +277,10 @@ export class TransactionsResource {
259
277
  ({ accountId, request } = await this.#buildMintRequest(opts, wasm));
260
278
  break;
261
279
  }
280
+ case "bridge": {
281
+ ({ accountId, request } = await this.#buildB2AggRequest(opts, wasm));
282
+ break;
283
+ }
262
284
  case "consume": {
263
285
  ({ accountId, request } = await this.#buildConsumeRequest(opts, wasm));
264
286
  break;
@@ -303,6 +325,163 @@ export class TransactionsResource {
303
325
  async execute(opts) {
304
326
  this.#client.assertNotTerminated();
305
327
  const wasm = await this.#getWasm();
328
+ const { accountId, request } = this.#buildExecuteRequest(opts, wasm);
329
+
330
+ const { txId, result } = await this.#submitOrSubmitWithProver(
331
+ accountId,
332
+ request,
333
+ opts.prover
334
+ );
335
+
336
+ if (opts.waitForConfirmation) {
337
+ await this.waitFor(txId.toHex(), { timeout: opts.timeout });
338
+ }
339
+
340
+ return { txId, result };
341
+ }
342
+
343
+ /**
344
+ * Submit a heterogeneous batch of operations against a single account. All
345
+ * operations are executed, proven individually and as a batch, and submitted
346
+ * atomically — either every tx in the batch lands or none does.
347
+ *
348
+ * @param {BatchOptions} opts - Batch options including the account, operations array, and confirmation settings.
349
+ * @returns {Promise<BatchSubmitResult>} The block number the batch was accepted into.
350
+ */
351
+ async batch(opts) {
352
+ this.#client.assertNotTerminated();
353
+ const wasm = await this.#getWasm();
354
+
355
+ if (!opts || !opts.account) {
356
+ throw new Error("batch: `account` is required");
357
+ }
358
+ if (!Array.isArray(opts.operations) || opts.operations.length === 0) {
359
+ throw new Error("batch: `operations` must be a non-empty array");
360
+ }
361
+
362
+ // Build each TransactionRequest. Per-op builders all use the batch-level
363
+ // `account` — V1 only supports same-account batches, mirroring the Rust
364
+ // constraint. We forward `opts.account` into each per-op options object so
365
+ // the existing builders' `resolveAccountRef` produces fresh AccountIds
366
+ // when needed.
367
+ const requests = [];
368
+ for (let i = 0; i < opts.operations.length; i++) {
369
+ const op = opts.operations[i];
370
+ let built;
371
+ switch (op?.kind) {
372
+ case "send":
373
+ built = await this.#buildSendRequest(
374
+ { ...op, account: opts.account },
375
+ wasm
376
+ );
377
+ break;
378
+ case "mint":
379
+ built = await this.#buildMintRequest(
380
+ { ...op, account: opts.account },
381
+ wasm
382
+ );
383
+ break;
384
+ case "consume":
385
+ built = await this.#buildConsumeRequest(
386
+ { ...op, account: opts.account },
387
+ wasm
388
+ );
389
+ break;
390
+ case "swap":
391
+ built = await this.#buildSwapRequest(
392
+ { ...op, account: opts.account },
393
+ wasm
394
+ );
395
+ break;
396
+ case "execute":
397
+ built = this.#buildExecuteRequest(
398
+ { ...op, account: opts.account },
399
+ wasm
400
+ );
401
+ break;
402
+ case "custom":
403
+ if (!op.request) {
404
+ throw new Error(
405
+ `batch: operation[${i}] of kind "custom" is missing \`request\``
406
+ );
407
+ }
408
+ built = { request: op.request };
409
+ break;
410
+ default:
411
+ throw new Error(
412
+ `batch: operation[${i}] has unknown kind "${op?.kind}"`
413
+ );
414
+ }
415
+ requests.push(built.request);
416
+ }
417
+
418
+ return this.submitBatch(opts.account, requests, opts);
419
+ }
420
+
421
+ /**
422
+ * Submit pre-built TransactionRequests as an atomic batch. Lower-level
423
+ * counterpart of `batch()` — for callers that already have built requests in
424
+ * hand. Equivalent to `submit()` but plural.
425
+ *
426
+ * @param {AccountRef} account - The account executing the batch.
427
+ * @param {TransactionRequest[]} requests - Pre-built transaction requests.
428
+ * @param {object} [options] - Optional settings (waitForConfirmation, timeout).
429
+ * The batch is proved with the client's configured prover; the V1 batch API
430
+ * has no per-call prover override.
431
+ * @returns {Promise<BatchSubmitResult>} The block number the batch was accepted into.
432
+ */
433
+ async submitBatch(account, requests, options) {
434
+ this.#client.assertNotTerminated();
435
+ const wasm = await this.#getWasm();
436
+
437
+ if (!Array.isArray(requests) || requests.length === 0) {
438
+ throw new Error("submitBatch: `requests` must be a non-empty array");
439
+ }
440
+
441
+ const accountId = resolveAccountRef(account, wasm);
442
+ const blockNumber = await this.#inner.submitNewTransactionBatch(
443
+ accountId,
444
+ requests.map((r) => r.serialize())
445
+ );
446
+
447
+ if (options?.waitForConfirmation) {
448
+ await this.#waitForBlock(blockNumber, options);
449
+ }
450
+
451
+ return { blockNumber };
452
+ }
453
+
454
+ /**
455
+ * Polls until the local sync height reaches `blockNumber` or the timeout
456
+ * expires. The Rust V1 batch API returns only a block number — there are no
457
+ * per-tx ids to poll on, so we wait on the chain height instead.
458
+ *
459
+ * @param {number} blockNumber - The block height to wait for.
460
+ * @param {object} [opts] - Polling options (timeout, interval).
461
+ */
462
+ async #waitForBlock(blockNumber, opts) {
463
+ const timeout = opts?.timeout ?? 60_000;
464
+ const interval = opts?.interval ?? 5_000;
465
+ const start = Date.now();
466
+
467
+ while (true) {
468
+ if (timeout > 0 && Date.now() - start >= timeout) {
469
+ throw new Error(
470
+ `Batch confirmation timed out after ${timeout}ms (waiting for block ${blockNumber})`
471
+ );
472
+ }
473
+ try {
474
+ await this.#inner.syncStateWithTimeout(0);
475
+ } catch {
476
+ // sync may fail transiently; continue polling
477
+ }
478
+ const height = await this.#inner.getSyncHeight();
479
+ if (height >= blockNumber) return;
480
+ await new Promise((resolve) => setTimeout(resolve, interval));
481
+ }
482
+ }
483
+
484
+ #buildExecuteRequest(opts, wasm) {
306
485
  const accountId = resolveAccountRef(opts.account, wasm);
307
486
 
308
487
  let builder = new wasm.TransactionRequestBuilder().withCustomScript(
@@ -330,18 +509,7 @@ export class TransactionsResource {
330
509
  );
331
510
  }
332
511
 
333
- const request = builder.build();
334
- const { txId, result } = await this.#submitOrSubmitWithProver(
335
- accountId,
336
- request,
337
- opts.prover
338
- );
339
-
340
- if (opts.waitForConfirmation) {
341
- await this.waitFor(txId.toHex(), { timeout: opts.timeout });
342
- }
343
-
344
- return { txId, result };
512
+ return { accountId, request: builder.build() };
345
513
  }
346
514
 
347
515
  async executeProgram(opts) {
@@ -514,6 +682,24 @@ export class TransactionsResource {
514
682
  return { accountId, request };
515
683
  }
516
684
 
685
+ async #buildB2AggRequest(opts, wasm) {
686
+ const accountId = resolveAccountRef(opts.account, wasm);
687
+ const bridgeAccountId = resolveAccountRef(opts.bridgeAccount, wasm);
688
+ const faucetId = resolveAccountRef(opts.token, wasm);
689
+ const amount = BigInt(opts.amount);
690
+ const destinationAddress = wasm.EthAddress.fromHex(opts.destinationAddress);
691
+
692
+ const request = await this.#inner.newB2AggTransactionRequest(
693
+ accountId,
694
+ bridgeAccountId,
695
+ faucetId,
696
+ amount,
697
+ opts.destinationNetwork,
698
+ destinationAddress
699
+ );
700
+ return { accountId, request };
701
+ }
702
+
517
703
  async #buildConsumeRequest(opts, wasm) {
518
704
  const accountId = resolveAccountRef(opts.account, wasm);
519
705
  const noteInputs = Array.isArray(opts.notes) ? opts.notes : [opts.notes];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@miden-sdk/miden-sdk",
3
- "version": "0.15.2",
3
+ "version": "0.15.4",
4
4
  "description": "Miden Wasm SDK",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -83,9 +83,9 @@
83
83
  "glob": "^11.0.0"
84
84
  },
85
85
  "optionalDependencies": {
86
- "@miden-sdk/node-darwin-arm64": "0.15.2",
87
- "@miden-sdk/node-darwin-x64": "0.15.2",
88
- "@miden-sdk/node-linux-x64-gnu": "0.15.2"
86
+ "@miden-sdk/node-darwin-arm64": "0.15.4",
87
+ "@miden-sdk/node-darwin-x64": "0.15.4",
88
+ "@miden-sdk/node-linux-x64-gnu": "0.15.4"
89
89
  },
90
90
  "scripts": {
91
91
  "build-rust-client-js": "pnpm --filter web_store run build",
@@ -97,6 +97,8 @@
97
97
  "check:wasm-types": "node ./scripts/check-bindgen-types.js",
98
98
  "check:method-classification": "node ./scripts/check-method-classification.js",
99
99
  "check:standalone-types": "node ./scripts/check-standalone-types.js",
100
+ "gen:node-reexports": "node ./scripts/gen-node-reexports.js",
101
+ "check:node-reexports": "node ./scripts/gen-node-reexports.js --check",
100
102
  "test:install": "pnpm exec playwright install --with-deps",
101
103
  "test:install:ci": "pnpm exec playwright install --with-deps chromium",
102
104
  "test": "pnpm exec playwright test",