@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.
Files changed (52) hide show
  1. package/README.md +0 -152
  2. package/dist/mt/{Cargo-CnGom-_z.js → Cargo-DKsyWYgG.js} +700 -1245
  3. package/dist/mt/Cargo-DKsyWYgG.js.map +1 -0
  4. package/dist/mt/api-types.d.ts +38 -370
  5. package/dist/mt/assets/miden_client_web.wasm +0 -0
  6. package/dist/mt/crates/miden_client_web.d.ts +179 -402
  7. package/dist/mt/docs-entry.d.ts +3 -9
  8. package/dist/mt/eager.js +1 -1
  9. package/dist/mt/index.d.ts +0 -3
  10. package/dist/mt/index.js +53 -701
  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-CnGom-_z-X_3VwTbo.js → Cargo-DKsyWYgG-DfOhgt23.js} +700 -1245
  15. package/dist/mt/workers/Cargo-DKsyWYgG-DfOhgt23.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 +703 -1251
  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-DR9fiMbE.js → Cargo-LwITdlzJ.js} +695 -1237
  23. package/dist/st/Cargo-LwITdlzJ.js.map +1 -0
  24. package/dist/st/api-types.d.ts +38 -370
  25. package/dist/st/assets/miden_client_web.wasm +0 -0
  26. package/dist/st/crates/miden_client_web.d.ts +179 -402
  27. package/dist/st/docs-entry.d.ts +3 -9
  28. package/dist/st/eager.js +1 -1
  29. package/dist/st/index.d.ts +0 -3
  30. package/dist/st/index.js +53 -701
  31. package/dist/st/index.js.map +1 -1
  32. package/dist/st/wasm.js +1 -1
  33. package/dist/st/workers/{Cargo-DR9fiMbE-C0G0clA_.js → Cargo-LwITdlzJ-Dyl2bCwN.js} +695 -1237
  34. package/dist/st/workers/Cargo-LwITdlzJ-Dyl2bCwN.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 +698 -1243
  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/client.js +2 -4
  41. package/js/node/client-factory.js +4 -11
  42. package/js/node/napi-compat.js +1 -0
  43. package/js/node-index.js +11 -11
  44. package/js/resources/compiler.js +23 -12
  45. package/js/resources/transactions.js +24 -540
  46. package/js/standalone.js +3 -61
  47. package/package.json +4 -4
  48. package/dist/mt/Cargo-CnGom-_z.js.map +0 -1
  49. package/dist/mt/workers/Cargo-CnGom-_z-X_3VwTbo.js.map +0 -1
  50. package/dist/st/Cargo-DR9fiMbE.js.map +0 -1
  51. package/dist/st/workers/Cargo-DR9fiMbE-C0G0clA_.js.map +0 -1
  52. package/js/resources/pswap.js +0 -132
package/dist/st/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import loadWasm from './wasm.js';
2
- export { Account, AccountArray, AccountBuilder, AccountBuilderResult, AccountCode, AccountComponent, AccountComponentCode, AccountDelta, AccountFile, AccountHeader, AccountId, AccountIdArray, AccountInterface, AccountProof, AccountReader, AccountStatus, AccountStorage, AccountStorageDelta, AccountStorageMode, AccountStorageRequirements, AccountVaultDelta, Address, AdviceInputs, AdviceMap, AssetCallbackFlag, AssetVault, AuthFalcon512RpoMultisigConfig, AuthSecretKey, BasicFungibleFaucetComponent, BlockHeader, CodeBuilder, CommittedNote, ConsumableNoteRecord, Endpoint, EthAddress, ExecutedTransaction, Felt, FeltArray, FetchedAccount, FetchedNote, FlattenedU8Vec, ForeignAccount, ForeignAccountArray, FungibleAsset, FungibleAssetDelta, FungibleAssetDeltaItem, GetProceduresResultItem, InputNote, InputNoteRecord, InputNoteState, InputNotes, IntoUnderlyingByteSource, IntoUnderlyingSink, IntoUnderlyingSource, JsAccountUpdate, JsSettingMutation, JsStateSyncUpdate, JsStorageMapEntry, JsStorageSlot, JsVaultAsset, Library, MerklePath, NetworkAccountTarget, NetworkId, NetworkNoteStatusInfo, NetworkType, Note, NoteAndArgs, NoteAndArgsArray, NoteArray, NoteAssets, NoteAttachment, NoteAttachmentScheme, NoteConsumability, NoteConsumptionStatus, NoteDetails, NoteDetailsAndTag, NoteDetailsAndTagArray, NoteExecutionHint, NoteExportFormat, NoteFile, NoteFilter, NoteFilterTypes, NoteHeader, NoteId, NoteIdAndArgs, NoteIdAndArgsArray, NoteInclusionProof, NoteLocation, NoteMetadata, NoteRecipient, NoteRecipientArray, NoteScript, NoteStorage, NoteSyncBlock, NoteSyncInfo, NoteTag, NoteType, OutputNote, OutputNoteArray, OutputNoteRecord, OutputNoteState, OutputNotes, Package, PartialNote, Poseidon2, ProcedureThreshold, Program, ProvenTransaction, PswapLineageRecord, PswapLineageState, PublicKey, RpcClient, Rpo256, SerializedInputNoteData, SerializedOutputNoteData, SerializedTransactionData, Signature, SigningInputs, SigningInputsType, SlotAndKeys, SparseMerklePath, StorageMap, StorageMapEntry, StorageMapEntryJs, StorageMapInfo, StorageMapUpdate, StorageSlot, StorageSlotArray, SyncSummary, TestUtils, TokenSymbol, TransactionArgs, TransactionFilter, TransactionId, TransactionProver, TransactionRecord, TransactionRequest, TransactionRequestBuilder, TransactionResult, TransactionScript, TransactionScriptInputPair, TransactionScriptInputPairArray, TransactionStatus, TransactionStoreUpdate, TransactionSummary, WebClient, WebKeystoreApi, Word, createAuthFalcon512RpoMultisig, exportStore, importStore, initSync, sequentialSumBench, setupLogging } from './Cargo-DR9fiMbE.js';
2
+ export { Account, AccountArray, AccountBuilder, AccountBuilderResult, AccountCode, AccountComponent, AccountComponentCode, AccountDelta, AccountFile, AccountHeader, AccountId, AccountIdArray, AccountInterface, AccountPatch, AccountProof, AccountReader, AccountStatus, AccountStorage, AccountStorageMode, AccountStoragePatch, AccountStorageRequirements, AccountVaultDelta, AccountVaultPatch, Address, AdviceInputs, AdviceMap, AssetVault, AuthFalcon512RpoMultisigConfig, AuthSecretKey, BasicFungibleFaucetComponent, BlockHeader, CodeBuilder, CommittedNote, ConsumableNoteRecord, Endpoint, ExecutedTransaction, Felt, FeltArray, FetchedAccount, FetchedNote, FlattenedU8Vec, ForeignAccount, ForeignAccountArray, FungibleAsset, FungibleAssetDelta, FungibleAssetDeltaItem, GetProceduresResultItem, InputNote, InputNoteRecord, InputNoteState, InputNotes, IntoUnderlyingByteSource, IntoUnderlyingSink, IntoUnderlyingSource, JsAccountUpdate, JsSettingMutation, JsStateSyncUpdate, JsStorageMapEntry, JsStorageSlot, JsVaultAsset, Library, MerklePath, NetworkId, NetworkNoteStatusInfo, NetworkType, Note, NoteAndArgs, NoteAndArgsArray, NoteArray, NoteAssets, NoteAttachment, NoteAttachmentScheme, NoteConsumability, NoteConsumptionStatus, NoteDetails, NoteDetailsAndTag, NoteDetailsAndTagArray, NoteExecutionHint, NoteExportFormat, NoteFile, NoteFilter, NoteFilterTypes, NoteHeader, NoteId, NoteIdAndArgs, NoteIdAndArgsArray, NoteInclusionProof, NoteLocation, NoteMetadata, NoteRecipient, NoteRecipientArray, NoteScript, NoteStorage, NoteSyncBlock, NoteSyncInfo, NoteTag, NoteType, OutputNote, OutputNoteArray, OutputNoteRecord, OutputNoteState, OutputNotes, Package, PartialNote, Poseidon2, ProcedureThreshold, Program, ProvenTransaction, PublicKey, RpcClient, Rpo256, SerializedInputNoteData, SerializedOutputNoteData, SerializedTransactionData, Signature, SigningInputs, SigningInputsType, SlotAndKeys, SparseMerklePath, StorageMap, StorageMapEntry, StorageMapEntryJs, StorageMapInfo, StorageMapUpdate, StorageSlot, StorageSlotArray, SyncSummary, TestUtils, TokenSymbol, TransactionArgs, TransactionFilter, TransactionId, TransactionProver, TransactionRecord, TransactionRequest, TransactionRequestBuilder, TransactionResult, TransactionScript, TransactionScriptInputPair, TransactionScriptInputPairArray, TransactionStatus, TransactionStoreUpdate, TransactionSummary, WebClient, WebKeystoreApi, Word, createAuthFalcon512RpoMultisig, exportStore, importStore, initSync, sequentialSumBench, setupLogging } from './Cargo-LwITdlzJ.js';
3
3
 
4
4
  const WorkerAction = Object.freeze({
5
5
  INIT: "init",
@@ -547,26 +547,6 @@ class AccountsResource {
547
547
  }
548
548
  }
549
549
 
550
- /**
551
- * Prove an executed transaction, resolving the prover exactly the way the
552
- * one-shot `submit()` pipeline does: the per-call prover if given, else the
553
- * client's default prover, else the built-in local prover. Shared by
554
- * {@link TransactionExecution.prove} and the internal pipeline so the two can
555
- * never drift.
556
- *
557
- * @param {*} inner - The WASM WebClient.
558
- * @param {*} defaultProver - The client's configured default prover, or null.
559
- * @param {*} result - The execution result to prove.
560
- * @param {{ prover?: * }} [opts] - Optional per-call prover override.
561
- * @returns {Promise<*>} The proven transaction.
562
- */
563
- async function proveResult(inner, defaultProver, result, opts) {
564
- const prover = opts?.prover ?? defaultProver;
565
- return prover
566
- ? await inner.proveTransaction(result, prover)
567
- : await inner.proveTransaction(result);
568
- }
569
-
570
550
  class TransactionsResource {
571
551
  #inner;
572
552
  #getWasm;
@@ -642,97 +622,6 @@ class TransactionsResource {
642
622
  return { txId, note: null, result };
643
623
  }
644
624
 
645
- /**
646
- * Builds a Public custom-script note carrying a NetworkAccountTarget
647
- * attachment, submits it as an own output note, and optionally waits for
648
- * confirmation. Provide exactly one of `recipient` or `script`.
649
- */
650
- async createNetworkNote(opts) {
651
- this.#client.assertNotTerminated();
652
- const wasm = await this.#getWasm();
653
-
654
- if (opts.recipient && opts.script) {
655
- throw new Error(
656
- "createNetworkNote requires exactly one of `recipient` or `script`, not both."
657
- );
658
- }
659
-
660
- const senderId = resolveAccountRef(opts.account, wasm);
661
-
662
- const target =
663
- opts.target instanceof wasm.NetworkAccountTarget
664
- ? opts.target
665
- : new wasm.NetworkAccountTarget(
666
- resolveAccountRef(opts.target, wasm),
667
- opts.executionHint
668
- );
669
-
670
- const noteAssets = opts.assets
671
- ? new wasm.NoteAssets(
672
- (Array.isArray(opts.assets) ? opts.assets : [opts.assets]).map(
673
- (a) =>
674
- new wasm.FungibleAsset(
675
- resolveAccountRef(a.token, wasm),
676
- BigInt(a.amount)
677
- )
678
- )
679
- )
680
- : new wasm.NoteAssets();
681
-
682
- const metadata = new wasm.NoteMetadata(
683
- senderId,
684
- wasm.NoteType.Public,
685
- wasm.NoteTag.withAccountTarget(target.targetId())
686
- );
687
-
688
- let recipient = opts.recipient;
689
- if (!recipient) {
690
- if (!opts.script) {
691
- throw new Error(
692
- "createNetworkNote requires either `recipient` or `script`."
693
- );
694
- }
695
- const storage = new wasm.NoteStorage(
696
- new wasm.FeltArray(
697
- (opts.inputs ?? []).map((value) => new wasm.Felt(value))
698
- )
699
- );
700
- recipient = wasm.NoteRecipient.fromScript(opts.script, storage);
701
- }
702
-
703
- const attachments = [target.toAttachment()];
704
- if (opts.attachment) {
705
- attachments.push(new wasm.NoteAttachment(opts.attachment));
706
- }
707
-
708
- const note = wasm.Note.withAttachments(
709
- noteAssets,
710
- metadata,
711
- recipient,
712
- attachments
713
- );
714
-
715
- // NoteArray constructor consumes its elements; use push(&note) to keep
716
- // `note` valid so we can return it to the caller.
717
- const ownOutputs = new wasm.NoteArray();
718
- ownOutputs.push(note);
719
- const request = new wasm.TransactionRequestBuilder()
720
- .withOwnOutputNotes(ownOutputs)
721
- .build();
722
-
723
- const { txId, result } = await this.#submitOrSubmitWithProver(
724
- senderId,
725
- request,
726
- opts.prover
727
- );
728
-
729
- if (opts.waitForConfirmation) {
730
- await this.waitFor(txId.toHex(), { timeout: opts.timeout });
731
- }
732
-
733
- return { txId, note, result };
734
- }
735
-
736
625
  async mint(opts) {
737
626
  this.#client.assertNotTerminated();
738
627
  const wasm = await this.#getWasm();
@@ -751,24 +640,6 @@ class TransactionsResource {
751
640
  return { txId, result };
752
641
  }
753
642
 
754
- async bridge(opts) {
755
- this.#client.assertNotTerminated();
756
- const wasm = await this.#getWasm();
757
- const { accountId, request } = await this.#buildB2AggRequest(opts, wasm);
758
-
759
- const { txId, result } = await this.#submitOrSubmitWithProver(
760
- accountId,
761
- request,
762
- opts.prover
763
- );
764
-
765
- if (opts.waitForConfirmation) {
766
- await this.waitFor(txId.toHex(), { timeout: opts.timeout });
767
- }
768
-
769
- return { txId, result };
770
- }
771
-
772
643
  async consume(opts) {
773
644
  this.#client.assertNotTerminated();
774
645
  const wasm = await this.#getWasm();
@@ -915,6 +786,14 @@ class TransactionsResource {
915
786
  return { txId, result };
916
787
  }
917
788
 
789
+ /**
790
+ * Dry-run a transaction to obtain the TransactionSummary pending
791
+ * authorization (e.g. a multisig below its signing threshold). Rejects
792
+ * with an error carrying `code: "TRANSACTION_ALREADY_AUTHORIZED"` (on
793
+ * Node.js the code prefixes the message instead) when the transaction
794
+ * executes successfully, since a fully authorized transaction produces
795
+ * no summary. See {@link PreviewOptions}.
796
+ */
918
797
  async preview(opts) {
919
798
  this.#client.assertNotTerminated();
920
799
  const wasm = await this.#getWasm();
@@ -931,10 +810,6 @@ class TransactionsResource {
931
810
  ({ accountId, request } = await this.#buildMintRequest(opts, wasm));
932
811
  break;
933
812
  }
934
- case "bridge": {
935
- ({ accountId, request } = await this.#buildB2AggRequest(opts, wasm));
936
- break;
937
- }
938
813
  case "consume": {
939
814
  ({ accountId, request } = await this.#buildConsumeRequest(opts, wasm));
940
815
  break;
@@ -979,163 +854,6 @@ class TransactionsResource {
979
854
  async execute(opts) {
980
855
  this.#client.assertNotTerminated();
981
856
  const wasm = await this.#getWasm();
982
- const { accountId, request } = this.#buildExecuteRequest(opts, wasm);
983
-
984
- const { txId, result } = await this.#submitOrSubmitWithProver(
985
- accountId,
986
- request,
987
- opts.prover
988
- );
989
-
990
- if (opts.waitForConfirmation) {
991
- await this.waitFor(txId.toHex(), { timeout: opts.timeout });
992
- }
993
-
994
- return { txId, result };
995
- }
996
-
997
- /**
998
- * Submit a heterogeneous batch of operations against a single account. All
999
- * operations are executed, proven individually and as a batch, and submitted
1000
- * atomically — either every tx in the batch lands or none does.
1001
- *
1002
- * @param {BatchOptions} opts - Batch options including the account, operations array, and confirmation settings.
1003
- * @returns {Promise<BatchSubmitResult>} The block number the batch was accepted into.
1004
- */
1005
- async batch(opts) {
1006
- this.#client.assertNotTerminated();
1007
- const wasm = await this.#getWasm();
1008
-
1009
- if (!opts || !opts.account) {
1010
- throw new Error("batch: `account` is required");
1011
- }
1012
- if (!Array.isArray(opts.operations) || opts.operations.length === 0) {
1013
- throw new Error("batch: `operations` must be a non-empty array");
1014
- }
1015
-
1016
- // Build each TransactionRequest. Per-op builders all use the batch-level
1017
- // `account` — V1 only supports same-account batches, mirroring the Rust
1018
- // constraint. We forward `opts.account` into each per-op options object so
1019
- // the existing builders' `resolveAccountRef` produces fresh AccountIds
1020
- // when needed.
1021
- const requests = [];
1022
- for (let i = 0; i < opts.operations.length; i++) {
1023
- const op = opts.operations[i];
1024
- let built;
1025
- switch (op?.kind) {
1026
- case "send":
1027
- built = await this.#buildSendRequest(
1028
- { ...op, account: opts.account },
1029
- wasm
1030
- );
1031
- break;
1032
- case "mint":
1033
- built = await this.#buildMintRequest(
1034
- { ...op, account: opts.account },
1035
- wasm
1036
- );
1037
- break;
1038
- case "consume":
1039
- built = await this.#buildConsumeRequest(
1040
- { ...op, account: opts.account },
1041
- wasm
1042
- );
1043
- break;
1044
- case "swap":
1045
- built = await this.#buildSwapRequest(
1046
- { ...op, account: opts.account },
1047
- wasm
1048
- );
1049
- break;
1050
- case "execute":
1051
- built = this.#buildExecuteRequest(
1052
- { ...op, account: opts.account },
1053
- wasm
1054
- );
1055
- break;
1056
- case "custom":
1057
- if (!op.request) {
1058
- throw new Error(
1059
- `batch: operation[${i}] of kind "custom" is missing \`request\``
1060
- );
1061
- }
1062
- built = { request: op.request };
1063
- break;
1064
- default:
1065
- throw new Error(
1066
- `batch: operation[${i}] has unknown kind "${op?.kind}"`
1067
- );
1068
- }
1069
- requests.push(built.request);
1070
- }
1071
-
1072
- return this.submitBatch(opts.account, requests, opts);
1073
- }
1074
-
1075
- /**
1076
- * Submit pre-built TransactionRequests as an atomic batch. Lower-level
1077
- * counterpart of `batch()` — for callers that already have built requests in
1078
- * hand. Equivalent to `submit()` but plural.
1079
- *
1080
- * @param {AccountRef} account - The account executing the batch.
1081
- * @param {TransactionRequest[]} requests - Pre-built transaction requests.
1082
- * @param {object} [options] - Optional settings (waitForConfirmation, timeout).
1083
- * The batch is proved with the client's configured prover; the V1 batch API
1084
- * has no per-call prover override.
1085
- * @returns {Promise<BatchSubmitResult>} The block number the batch was accepted into.
1086
- */
1087
- async submitBatch(account, requests, options) {
1088
- this.#client.assertNotTerminated();
1089
- const wasm = await this.#getWasm();
1090
-
1091
- if (!Array.isArray(requests) || requests.length === 0) {
1092
- throw new Error("submitBatch: `requests` must be a non-empty array");
1093
- }
1094
-
1095
- const accountId = resolveAccountRef(account, wasm);
1096
- const blockNumber = await this.#inner.submitNewTransactionBatch(
1097
- accountId,
1098
- requests.map((r) => r.serialize())
1099
- );
1100
-
1101
- if (options?.waitForConfirmation) {
1102
- await this.#waitForBlock(blockNumber, options);
1103
- }
1104
-
1105
- return { blockNumber };
1106
- }
1107
-
1108
- /**
1109
- * Polls until the local sync height reaches `blockNumber` or the timeout
1110
- * expires. The Rust V1 batch API returns only a block number — there are no
1111
- * per-tx ids to poll on, so we wait on the chain height instead.
1112
- *
1113
- * @param {number} blockNumber - The block height to wait for.
1114
- * @param {object} [opts] - Polling options (timeout, interval).
1115
- */
1116
- async #waitForBlock(blockNumber, opts) {
1117
- const timeout = opts?.timeout ?? 60_000;
1118
- const interval = opts?.interval ?? 5_000;
1119
- const start = Date.now();
1120
-
1121
- while (true) {
1122
- if (timeout > 0 && Date.now() - start >= timeout) {
1123
- throw new Error(
1124
- `Batch confirmation timed out after ${timeout}ms (waiting for block ${blockNumber})`
1125
- );
1126
- }
1127
- try {
1128
- await this.#inner.syncStateWithTimeout(0);
1129
- } catch {
1130
- // sync may fail transiently; continue polling
1131
- }
1132
- const height = await this.#inner.getSyncHeight();
1133
- if (height >= blockNumber) return;
1134
- await new Promise((resolve) => setTimeout(resolve, interval));
1135
- }
1136
- }
1137
-
1138
- #buildExecuteRequest(opts, wasm) {
1139
857
  const accountId = resolveAccountRef(opts.account, wasm);
1140
858
 
1141
859
  let builder = new wasm.TransactionRequestBuilder().withCustomScript(
@@ -1163,7 +881,18 @@ class TransactionsResource {
1163
881
  );
1164
882
  }
1165
883
 
1166
- return { accountId, request: builder.build() };
884
+ const request = builder.build();
885
+ const { txId, result } = await this.#submitOrSubmitWithProver(
886
+ accountId,
887
+ request,
888
+ opts.prover
889
+ );
890
+
891
+ if (opts.waitForConfirmation) {
892
+ await this.waitFor(txId.toHex(), { timeout: opts.timeout });
893
+ }
894
+
895
+ return { txId, result };
1167
896
  }
1168
897
 
1169
898
  async executeProgram(opts) {
@@ -1208,65 +937,6 @@ class TransactionsResource {
1208
937
  );
1209
938
  }
1210
939
 
1211
- /**
1212
- * Execute a transaction request locally — nothing is proven, submitted, or
1213
- * persisted. Returns a {@link TransactionExecution} handle; advance the
1214
- * lifecycle by chaining `.prove()` → `.submit()` → `.apply()`, benchmarking
1215
- * or error-handling each stage independently. Use {@link submit} to run every
1216
- * stage in one call.
1217
- *
1218
- * ```ts
1219
- * const executed = await client.transactions.executeRequest(account, request);
1220
- * const proven = await executed.prove({ prover });
1221
- * const submitted = await proven.submit();
1222
- * await submitted.apply();
1223
- * ```
1224
- *
1225
- * The stages are NOT atomic as a group: awaiting other mutating calls on the
1226
- * same account between them can interleave state. Drive the chain as an
1227
- * uninterrupted sequence per account.
1228
- *
1229
- * @param {AccountRef} account - The account executing the transaction.
1230
- * @param {TransactionRequest} request - The pre-built transaction request.
1231
- * @returns {Promise<TransactionExecution>} A handle to the executed
1232
- * transaction, ready to prove.
1233
- */
1234
- async executeRequest(account, request) {
1235
- this.#client.assertNotTerminated();
1236
- const wasm = await this.#getWasm();
1237
- const accountId = resolveAccountRef(account, wasm);
1238
- const result = await this.#inner.executeTransaction(accountId, request);
1239
- return new TransactionExecution(this.#inner, this.#client, this, result);
1240
- }
1241
-
1242
- /**
1243
- * Submit a proof produced somewhere that shares nothing with this client —
1244
- * e.g. a detached prover that never saw the local store. Returns a
1245
- * {@link TransactionSubmission} handle; call `.apply()` on it to persist
1246
- * locally. For the in-process flow prefer
1247
- * `executeRequest(...)` → `.prove()` → `.submit()`, which threads the proof
1248
- * and result for you.
1249
- *
1250
- * @param {ProvenTransaction} proof - A proof for `result`, proven elsewhere.
1251
- * @param {TransactionResult} result - The matching execution result.
1252
- * @returns {Promise<TransactionSubmission>} A handle to the submitted
1253
- * transaction, ready to apply.
1254
- */
1255
- async submitProven(proof, result) {
1256
- this.#client.assertNotTerminated();
1257
- const blockNumber = await this.#inner.submitProvenTransaction(
1258
- proof,
1259
- result
1260
- );
1261
- return new TransactionSubmission(
1262
- this.#inner,
1263
- this.#client,
1264
- this,
1265
- result,
1266
- blockNumber
1267
- );
1268
- }
1269
-
1270
940
  async list(query) {
1271
941
  this.#client.assertNotTerminated();
1272
942
  const wasm = await this.#getWasm();
@@ -1395,24 +1065,6 @@ class TransactionsResource {
1395
1065
  return { accountId, request };
1396
1066
  }
1397
1067
 
1398
- async #buildB2AggRequest(opts, wasm) {
1399
- const accountId = resolveAccountRef(opts.account, wasm);
1400
- const bridgeAccountId = resolveAccountRef(opts.bridgeAccount, wasm);
1401
- const faucetId = resolveAccountRef(opts.token, wasm);
1402
- const amount = BigInt(opts.amount);
1403
- const destinationAddress = wasm.EthAddress.fromHex(opts.destinationAddress);
1404
-
1405
- const request = await this.#inner.newB2AggTransactionRequest(
1406
- accountId,
1407
- bridgeAccountId,
1408
- faucetId,
1409
- amount,
1410
- opts.destinationNetwork,
1411
- destinationAddress
1412
- );
1413
- return { accountId, request };
1414
- }
1415
-
1416
1068
  async #buildConsumeRequest(opts, wasm) {
1417
1069
  const accountId = resolveAccountRef(opts.account, wasm);
1418
1070
  const noteInputs = Array.isArray(opts.notes) ? opts.notes : [opts.notes];
@@ -1557,12 +1209,10 @@ class TransactionsResource {
1557
1209
 
1558
1210
  async #submitOrSubmitWithProver(accountId, request, perCallProver) {
1559
1211
  const result = await this.#inner.executeTransaction(accountId, request);
1560
- const proven = await proveResult(
1561
- this.#inner,
1562
- this.#client.defaultProver,
1563
- result,
1564
- { prover: perCallProver }
1565
- );
1212
+ const prover = perCallProver ?? this.#client.defaultProver;
1213
+ const proven = prover
1214
+ ? await this.#inner.proveTransaction(result, prover)
1215
+ : await this.#inner.proveTransaction(result);
1566
1216
  const txId = result.id();
1567
1217
  const height = await this.#inner.submitProvenTransaction(proven, result);
1568
1218
  await this.#inner.applyTransaction(result, height);
@@ -1570,172 +1220,6 @@ class TransactionsResource {
1570
1220
  }
1571
1221
  }
1572
1222
 
1573
- /**
1574
- * A locally-executed transaction — nothing proven, submitted, or persisted yet.
1575
- * First stage of the manual transaction lifecycle, returned by
1576
- * {@link TransactionsResource.executeRequest}. Advance it with {@link prove}.
1577
- */
1578
- class TransactionExecution {
1579
- #inner;
1580
- #client;
1581
- #resource;
1582
- #result;
1583
-
1584
- constructor(inner, client, resource, result) {
1585
- this.#inner = inner;
1586
- this.#client = client;
1587
- this.#resource = resource;
1588
- this.#result = result;
1589
- }
1590
-
1591
- /** The raw execution artifact (account delta, output notes, …). */
1592
- get result() {
1593
- return this.#result;
1594
- }
1595
-
1596
- /** The executed transaction's id. */
1597
- get id() {
1598
- return this.#result.id();
1599
- }
1600
-
1601
- /**
1602
- * Prove this execution. Uses the per-call prover when provided, falling back
1603
- * to the client's default prover (or the built-in local prover). Pure
1604
- * computation — touches neither the network nor the local store.
1605
- *
1606
- * A `TransactionProver` is consumed by the call: build (or clone) a fresh
1607
- * prover per `prove()`. Reusing an already-passed prover silently falls back
1608
- * to the built-in local prover.
1609
- *
1610
- * @param {ProveOptions} [opts] - Optional per-call prover override.
1611
- * @returns {Promise<TransactionProof>} A handle to the proven transaction,
1612
- * ready to submit.
1613
- */
1614
- async prove(opts) {
1615
- this.#client.assertNotTerminated();
1616
- const proven = await proveResult(
1617
- this.#inner,
1618
- this.#client.defaultProver,
1619
- this.#result,
1620
- opts
1621
- );
1622
- return new TransactionProof(
1623
- this.#inner,
1624
- this.#client,
1625
- this.#resource,
1626
- proven,
1627
- this.#result
1628
- );
1629
- }
1630
- }
1631
-
1632
- /**
1633
- * A proven transaction, ready for the network. Second stage of the manual
1634
- * transaction lifecycle, returned by {@link TransactionExecution.prove}.
1635
- * Advance it with {@link submit}.
1636
- */
1637
- class TransactionProof {
1638
- #inner;
1639
- #client;
1640
- #resource;
1641
- #proof;
1642
- #result;
1643
-
1644
- constructor(inner, client, resource, proof, result) {
1645
- this.#inner = inner;
1646
- this.#client = client;
1647
- this.#resource = resource;
1648
- this.#proof = proof;
1649
- this.#result = result;
1650
- }
1651
-
1652
- /** The raw proof — e.g. to serialize and submit from a different client. */
1653
- get proof() {
1654
- return this.#proof;
1655
- }
1656
-
1657
- /** The execution result this proof was produced from. */
1658
- get result() {
1659
- return this.#result;
1660
- }
1661
-
1662
- /**
1663
- * Submit the proof to the network. Does NOT persist locally — call
1664
- * {@link TransactionSubmission.apply} on the returned handle; skipping it
1665
- * leaves the local store out of sync until the next full sync.
1666
- *
1667
- * @returns {Promise<TransactionSubmission>} A handle to the submitted
1668
- * transaction, ready to apply.
1669
- */
1670
- async submit() {
1671
- this.#client.assertNotTerminated();
1672
- const blockNumber = await this.#inner.submitProvenTransaction(
1673
- this.#proof,
1674
- this.#result
1675
- );
1676
- return new TransactionSubmission(
1677
- this.#inner,
1678
- this.#client,
1679
- this.#resource,
1680
- this.#result,
1681
- blockNumber
1682
- );
1683
- }
1684
- }
1685
-
1686
- /**
1687
- * A submitted transaction. Final stage of the manual transaction lifecycle,
1688
- * returned by {@link TransactionProof.submit}. Persist it locally with
1689
- * {@link apply}, or block until it commits with {@link waitForConfirmation}.
1690
- */
1691
- class TransactionSubmission {
1692
- #inner;
1693
- #client;
1694
- #resource;
1695
- #result;
1696
- #blockNumber;
1697
-
1698
- constructor(inner, client, resource, result, blockNumber) {
1699
- this.#inner = inner;
1700
- this.#client = client;
1701
- this.#resource = resource;
1702
- this.#result = result;
1703
- this.#blockNumber = blockNumber;
1704
- }
1705
-
1706
- /** The block height the transaction was submitted at. */
1707
- get blockNumber() {
1708
- return this.#blockNumber;
1709
- }
1710
-
1711
- /** The execution result that was submitted. */
1712
- get result() {
1713
- return this.#result;
1714
- }
1715
-
1716
- /**
1717
- * Persist the transaction into the local store, firing registered
1718
- * transaction observers (e.g. PSWAP lineage tracking). Until this runs the
1719
- * local store is unaware of the transaction.
1720
- *
1721
- * @returns {Promise<TransactionStoreUpdate>} The pre-apply store update.
1722
- */
1723
- async apply() {
1724
- this.#client.assertNotTerminated();
1725
- return await this.#inner.applyTransaction(this.#result, this.#blockNumber);
1726
- }
1727
-
1728
- /**
1729
- * Poll local sync height until the transaction commits on-chain. Convenience
1730
- * wrapper over {@link TransactionsResource.waitFor}.
1731
- *
1732
- * @param {WaitOptions} [opts] - Polling options (timeout, interval, onProgress).
1733
- */
1734
- async waitForConfirmation(opts) {
1735
- return await this.#resource.waitFor(this.#result.id().toHex(), opts);
1736
- }
1737
- }
1738
-
1739
1223
  class NotesResource {
1740
1224
  #inner;
1741
1225
  #getWasm;
@@ -1932,22 +1416,25 @@ class CompilerResource {
1932
1416
  /**
1933
1417
  * Compiles MASM code + slots into an AccountComponent ready for accounts.create().
1934
1418
  *
1935
- * @param {{ code: string, slots: StorageSlot[], supportAllTypes?: boolean }} opts
1419
+ * @param {{ code: string, namespace?: string, slots: StorageSlot[], supportAllTypes?: boolean }} opts
1936
1420
  * @returns {Promise<AccountComponent>}
1937
1421
  */
1938
- async component({ code, slots = [], supportAllTypes = true }) {
1422
+ async component({ code, namespace, slots = [], supportAllTypes = true }) {
1939
1423
  this.#client?.assertNotTerminated();
1940
1424
  const wasm = await this.#getWasm();
1941
1425
  const builder = await this.#inner.createCodeBuilder();
1942
- const compiled = builder.compileAccountComponentCode(code);
1426
+ const compiled = namespace
1427
+ ? builder.compileAccountComponentCodeWithPath(namespace, code)
1428
+ : builder.compileAccountComponentCode(code);
1943
1429
  const component = wasm.AccountComponent.compile(compiled, slots);
1944
1430
  return supportAllTypes ? component.withSupportsAllTypes() : component;
1945
1431
  }
1946
1432
 
1947
1433
  /**
1948
- * Compiles a transaction script, optionally linking named libraries inline.
1434
+ * Compiles a transaction script, optionally linking named libraries inline or linking the exact
1435
+ * code installed by an AccountComponent.
1949
1436
  *
1950
- * @param {{ code: string, libraries?: Array<{ namespace: string, code: string, linking?: "dynamic" | "static" }> }} opts
1437
+ * @param {{ code: string, libraries?: Array<Library | { namespace: string, code: string, linking?: "dynamic" | "static" } | { component: AccountComponent, linking?: "dynamic" | "static" }> }} opts
1951
1438
  * @returns {Promise<TransactionScript>}
1952
1439
  */
1953
1440
  async txScript({ code, libraries = [] }) {
@@ -1960,9 +1447,10 @@ class CompilerResource {
1960
1447
  }
1961
1448
 
1962
1449
  /**
1963
- * Compiles a note script, optionally linking named libraries inline.
1450
+ * Compiles a note script, optionally linking named libraries inline or linking the exact code
1451
+ * installed by an AccountComponent.
1964
1452
  *
1965
- * @param {{ code: string, libraries?: Array<{ namespace: string, code: string, linking?: "dynamic" | "static" }> }} opts
1453
+ * @param {{ code: string, libraries?: Array<Library | { namespace: string, code: string, linking?: "dynamic" | "static" } | { component: AccountComponent, linking?: "dynamic" | "static" }> }} opts
1966
1454
  * @returns {Promise<NoteScript>}
1967
1455
  */
1968
1456
  async noteScript({ code, libraries = [] }) {
@@ -1974,13 +1462,20 @@ class CompilerResource {
1974
1462
  }
1975
1463
  }
1976
1464
 
1977
- // Builds and links each library entry against `builder`. Inline
1978
- // `{ namespace, code, linking? }` entries are built via `buildLibrary` and
1979
- // linked according to `linking` (defaulting to dynamic, matching tutorial
1980
- // behavior). Pre-built library objects are linked dynamically.
1465
+ // Builds and links each library entry against `builder`. Account component entries use the exact
1466
+ // compiled code installed by the component. Inline `{ namespace, code, linking? }` entries are
1467
+ // built via `buildLibrary`. Linking defaults to dynamic, matching tutorial behavior. Pre-built
1468
+ // library objects are also linked dynamically.
1981
1469
  function linkLibraries(builder, libraries) {
1982
1470
  for (const lib of libraries) {
1983
- if (lib && typeof lib.namespace === "string") {
1471
+ if (lib && lib.component) {
1472
+ const componentCode = lib.component.componentCode();
1473
+ if (lib.linking === "static") {
1474
+ builder.linkStaticAccountComponentCode(componentCode);
1475
+ } else {
1476
+ builder.linkDynamicAccountComponentCode(componentCode);
1477
+ }
1478
+ } else if (lib && typeof lib.namespace === "string") {
1984
1479
  const built = builder.buildLibrary(lib.namespace, lib.code);
1985
1480
  if (lib.linking === "static") {
1986
1481
  builder.linkStaticLibrary(built);
@@ -2048,137 +1543,6 @@ class KeystoreResource {
2048
1543
  }
2049
1544
  }
2050
1545
 
2051
- /**
2052
- * Coerce an `orderId` (string | bigint) to a decimal string for the WASM
2053
- * `u64` parse on the other side.
2054
- *
2055
- * A PSWAP `orderId` is `u64`-shaped and routinely exceeds
2056
- * `Number.MAX_SAFE_INTEGER` (`2^53 - 1`). JS `number` cannot represent the
2057
- * full u64 range without silent precision loss, so it is not accepted — pass
2058
- * `orderId` as a `bigint` or `string` instead.
2059
- *
2060
- * @param {string | bigint} orderId
2061
- * @returns {string}
2062
- */
2063
- function normalizeOrderId(orderId) {
2064
- if (typeof orderId === "bigint") return orderId.toString();
2065
- if (typeof orderId === "string") return orderId;
2066
- throw new TypeError(
2067
- `PSWAP orderId must be a string or bigint; got ${typeof orderId}`
2068
- );
2069
- }
2070
-
2071
- /**
2072
- * PswapResource surfaces partial-swap (PSWAP) lineage tracking and creator-side
2073
- * cancellation keyed by a lineage's stable order id.
2074
- *
2075
- * A PSWAP note can be filled by many consumers; each fill advances the lineage
2076
- * to a new remainder note. The client persists that chain locally as it syncs,
2077
- * and the reader methods here expose it. {@link PswapResource#cancelByOrder}
2078
- * reclaims the unfilled offered asset on the current tip of an active lineage,
2079
- * resolving the creator account from the tracked record so the caller only
2080
- * needs the order id.
2081
- */
2082
- class PswapResource {
2083
- #inner;
2084
- #getWasm;
2085
- #client;
2086
-
2087
- constructor(inner, getWasm, client) {
2088
- this.#inner = inner;
2089
- this.#getWasm = getWasm;
2090
- this.#client = client;
2091
- }
2092
-
2093
- /**
2094
- * Returns every PSWAP lineage tracked by this client.
2095
- *
2096
- * @returns {Promise<PswapLineageRecord[]>} All tracked lineages.
2097
- */
2098
- async lineages() {
2099
- this.#client.assertNotTerminated();
2100
- return await this.#inner.getPswapLineages();
2101
- }
2102
-
2103
- /**
2104
- * Returns lineages created by a specific local account.
2105
- *
2106
- * @param {AccountRef} account - Creator account (hex, bech32, Account, or AccountId).
2107
- * @returns {Promise<PswapLineageRecord[]>} Lineages created by the account.
2108
- */
2109
- async lineagesFor(account) {
2110
- this.#client.assertNotTerminated();
2111
- const wasm = await this.#getWasm();
2112
- const accountId = resolveAccountRef(account, wasm);
2113
- return await this.#inner.getPswapLineagesFor(accountId);
2114
- }
2115
-
2116
- /**
2117
- * Returns the lineage for one order, or null if not tracked.
2118
- *
2119
- * @param {string | bigint} orderId - Stable order id. Pass as a `string` or
2120
- * `bigint` for the full `u64` range; `number` is rejected because it cannot
2121
- * represent ids above `Number.MAX_SAFE_INTEGER` without precision loss.
2122
- * @returns {Promise<PswapLineageRecord | null>} The lineage, or null.
2123
- */
2124
- async lineage(orderId) {
2125
- this.#client.assertNotTerminated();
2126
- const result = await this.#inner.getPswapLineage(normalizeOrderId(orderId));
2127
- return result ?? null;
2128
- }
2129
-
2130
- /**
2131
- * Builds and submits a transaction reclaiming the unfilled offered asset on
2132
- * the current tip of an Active lineage. The creator account is resolved from
2133
- * the tracked lineage, so only the order id is required. Runs through the
2134
- * same execute/prove/submit path as the other transaction helpers.
2135
- *
2136
- * Throws before submitting any transaction when:
2137
- * - no lineage is tracked for `orderId`, OR
2138
- * - the lineage is in a terminal state (`FullyFilled` or `Reclaimed`,
2139
- * guarded by the `buildPswapCancelByOrder` binding).
2140
- *
2141
- * Concurrency: the lineage-read, build, and submit steps below are not
2142
- * atomic against external fills. If another consumer — or this client's own
2143
- * in-flight tx — advances the lineage tip between the build and submit, the
2144
- * cancel will target an already-consumed note and the kernel will reject
2145
- * it with a "note already nullified" error. Treat that as a signal to
2146
- * re-read the lineage and retry against the new tip.
2147
- *
2148
- * @param {PswapCancelByOrderOptions} opts - Order id and optional tx options.
2149
- * @returns {Promise<TransactionSubmitResult>} The submitted transaction.
2150
- */
2151
- async cancelByOrder(opts) {
2152
- this.#client.assertNotTerminated();
2153
- const orderId = normalizeOrderId(opts.orderId);
2154
-
2155
- // Fetch the lineage for the creator account (the cancel's submitter).
2156
- // The terminal-state guard is authoritative in the `buildPswapCancelByOrder`
2157
- // binding below, so it is not repeated here.
2158
- const lineage = await this.#inner.getPswapLineage(orderId);
2159
- if (!lineage) {
2160
- throw new Error(`No PSWAP lineage tracked for order ${orderId}`);
2161
- }
2162
- const accountId = lineage.creatorAccountId();
2163
-
2164
- const request = await this.#inner.buildPswapCancelByOrder(orderId);
2165
-
2166
- const { txId, result } = await this.#client.transactions.submit(
2167
- accountId,
2168
- request,
2169
- { prover: opts.prover }
2170
- );
2171
-
2172
- if (opts.waitForConfirmation) {
2173
- await this.#client.transactions.waitFor(txId.toHex(), {
2174
- timeout: opts.timeout,
2175
- });
2176
- }
2177
-
2178
- return { txId, result };
2179
- }
2180
- }
2181
-
2182
1546
  /**
2183
1547
  * MidenClient wraps the existing proxy-wrapped WebClient with a resource-based API.
2184
1548
  *
@@ -2209,7 +1573,6 @@ class MidenClient {
2209
1573
  this.settings = new SettingsResource(inner, getWasm, this);
2210
1574
  this.compile = new CompilerResource(inner, getWasm, this);
2211
1575
  this.keystore = new KeystoreResource(inner, this);
2212
- this.pswap = new PswapResource(inner, getWasm, this);
2213
1576
  }
2214
1577
 
2215
1578
  /**
@@ -2331,7 +1694,7 @@ class MidenClient {
2331
1694
  options.keystore.getKey,
2332
1695
  options.keystore.insertKey,
2333
1696
  options.keystore.sign,
2334
- options?.debugMode,
1697
+ undefined,
2335
1698
  useWorker
2336
1699
  );
2337
1700
  } else {
@@ -2340,7 +1703,7 @@ class MidenClient {
2340
1703
  noteTransportUrl,
2341
1704
  seed,
2342
1705
  options?.storeName,
2343
- options?.debugMode,
1706
+ undefined,
2344
1707
  useWorker
2345
1708
  );
2346
1709
  }
@@ -2783,6 +2146,9 @@ function buildSwapTag(opts) {
2783
2146
 
2784
2147
  function buildNoteAssets(assets, wasm) {
2785
2148
  const assetArray = Array.isArray(assets) ? assets : [assets];
2149
+ if (assetArray.length === 0) {
2150
+ throw new TypeError("P2ID and P2IDE notes require at least one asset");
2151
+ }
2786
2152
  const fungibleAssets = assetArray.map((asset) => {
2787
2153
  const faucetId = resolveAccountRef(asset.token, wasm);
2788
2154
  return new wasm.FungibleAsset(faucetId, BigInt(asset.amount));
@@ -3011,17 +2377,6 @@ class StorageResult {
3011
2377
  return this.#word.toFelts();
3012
2378
  }
3013
2379
 
3014
- /**
3015
- * Returns all four elements of the stored Word as a BigUint64Array.
3016
- * Pass-through to Word.toU64s() — ensures code that expects a Word-like
3017
- * object (e.g., `result.toU64s()[0]`) works on StorageResult.
3018
- * @returns {BigUint64Array}
3019
- */
3020
- toU64s() {
3021
- if (!this.#word) return new BigUint64Array();
3022
- return this.#word.toU64s();
3023
- }
3024
-
3025
2380
  /**
3026
2381
  * The first Felt of the stored Word.
3027
2382
  * Returns the WASM Felt object — use .asInt() to get its BigInt value.
@@ -3170,11 +2525,9 @@ const Linking = Object.freeze({
3170
2525
  // (e.g. newSwapTransactionRequest, newPswapCreateTransactionRequest) are
3171
2526
  // `async fn` in Rust because they take the client's RNG via an async lock.
3172
2527
  const SYNC_METHODS = new Set([
3173
- "buildPswapCancelByOrder",
3174
2528
  "buildSwapTag",
3175
2529
  "createCodeBuilder",
3176
2530
  "lastAuthError",
3177
- "newB2AggTransactionRequest",
3178
2531
  "newConsumeTransactionRequest",
3179
2532
  "newMintTransactionRequest",
3180
2533
  "newPswapCancelTransactionRequest",
@@ -3185,7 +2538,6 @@ const SYNC_METHODS = new Set([
3185
2538
  "proveBlock",
3186
2539
  "serializeMockChain",
3187
2540
  "serializeMockNoteTransportNode",
3188
- "setDebugMode",
3189
2541
  "storeIdentifier",
3190
2542
  "usesMockChain",
3191
2543
  ]);