@miden-sdk/miden-sdk 0.15.6 → 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 -137
  2. package/dist/mt/{workers/Cargo-mvyTli7g-BwMMSyoq.js → Cargo-DKsyWYgG.js} +699 -1202
  3. package/dist/mt/Cargo-DKsyWYgG.js.map +1 -0
  4. package/dist/mt/api-types.d.ts +38 -250
  5. package/dist/mt/assets/miden_client_web.wasm +0 -0
  6. package/dist/mt/crates/miden_client_web.d.ts +179 -370
  7. package/dist/mt/docs-entry.d.ts +3 -6
  8. package/dist/mt/eager.js +1 -1
  9. package/dist/mt/index.d.ts +0 -3
  10. package/dist/mt/index.js +49 -450
  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/{Cargo-mvyTli7g.js → workers/Cargo-DKsyWYgG-DfOhgt23.js} +700 -1201
  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 -1207
  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/{workers/Cargo-Cysp4vto-BIw-TeJn.js → Cargo-LwITdlzJ.js} +694 -1195
  23. package/dist/st/Cargo-LwITdlzJ.js.map +1 -0
  24. package/dist/st/api-types.d.ts +38 -250
  25. package/dist/st/assets/miden_client_web.wasm +0 -0
  26. package/dist/st/crates/miden_client_web.d.ts +179 -370
  27. package/dist/st/docs-entry.d.ts +3 -6
  28. package/dist/st/eager.js +1 -1
  29. package/dist/st/index.d.ts +0 -3
  30. package/dist/st/index.js +49 -450
  31. package/dist/st/index.js.map +1 -1
  32. package/dist/st/wasm.js +1 -1
  33. package/dist/st/{Cargo-Cysp4vto.js → workers/Cargo-LwITdlzJ-Dyl2bCwN.js} +695 -1194
  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 -1200
  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 -10
  44. package/js/resources/compiler.js +23 -12
  45. package/js/resources/transactions.js +20 -289
  46. package/js/standalone.js +3 -61
  47. package/package.json +4 -4
  48. package/dist/mt/Cargo-mvyTli7g.js.map +0 -1
  49. package/dist/mt/workers/Cargo-mvyTli7g-BwMMSyoq.js.map +0 -1
  50. package/dist/st/Cargo-Cysp4vto.js.map +0 -1
  51. package/dist/st/workers/Cargo-Cysp4vto-BIw-TeJn.js.map +0 -1
  52. package/js/resources/pswap.js +0 -132
package/dist/mt/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, 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, initThreadPool, mtProbeAsync, mtProbeSync, parallelSumBench, rayonThreadCount, sequentialSumBench, setupLogging, wbg_rayon_PoolBuilder, wbg_rayon_start_worker } from './Cargo-mvyTli7g.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, initThreadPool, mtProbeAsync, mtProbeSync, parallelSumBench, rayonThreadCount, sequentialSumBench, setupLogging, wbg_rayon_PoolBuilder, wbg_rayon_start_worker } from './Cargo-DKsyWYgG.js';
3
3
 
4
4
  const WorkerAction = Object.freeze({
5
5
  INIT: "init",
@@ -622,97 +622,6 @@ class TransactionsResource {
622
622
  return { txId, note: null, result };
623
623
  }
624
624
 
625
- /**
626
- * Builds a Public custom-script note carrying a NetworkAccountTarget
627
- * attachment, submits it as an own output note, and optionally waits for
628
- * confirmation. Provide exactly one of `recipient` or `script`.
629
- */
630
- async createNetworkNote(opts) {
631
- this.#client.assertNotTerminated();
632
- const wasm = await this.#getWasm();
633
-
634
- if (opts.recipient && opts.script) {
635
- throw new Error(
636
- "createNetworkNote requires exactly one of `recipient` or `script`, not both."
637
- );
638
- }
639
-
640
- const senderId = resolveAccountRef(opts.account, wasm);
641
-
642
- const target =
643
- opts.target instanceof wasm.NetworkAccountTarget
644
- ? opts.target
645
- : new wasm.NetworkAccountTarget(
646
- resolveAccountRef(opts.target, wasm),
647
- opts.executionHint
648
- );
649
-
650
- const noteAssets = opts.assets
651
- ? new wasm.NoteAssets(
652
- (Array.isArray(opts.assets) ? opts.assets : [opts.assets]).map(
653
- (a) =>
654
- new wasm.FungibleAsset(
655
- resolveAccountRef(a.token, wasm),
656
- BigInt(a.amount)
657
- )
658
- )
659
- )
660
- : new wasm.NoteAssets();
661
-
662
- const metadata = new wasm.NoteMetadata(
663
- senderId,
664
- wasm.NoteType.Public,
665
- wasm.NoteTag.withAccountTarget(target.targetId())
666
- );
667
-
668
- let recipient = opts.recipient;
669
- if (!recipient) {
670
- if (!opts.script) {
671
- throw new Error(
672
- "createNetworkNote requires either `recipient` or `script`."
673
- );
674
- }
675
- const storage = new wasm.NoteStorage(
676
- new wasm.FeltArray(
677
- (opts.inputs ?? []).map((value) => new wasm.Felt(value))
678
- )
679
- );
680
- recipient = wasm.NoteRecipient.fromScript(opts.script, storage);
681
- }
682
-
683
- const attachments = [target.toAttachment()];
684
- if (opts.attachment) {
685
- attachments.push(new wasm.NoteAttachment(opts.attachment));
686
- }
687
-
688
- const note = wasm.Note.withAttachments(
689
- noteAssets,
690
- metadata,
691
- recipient,
692
- attachments
693
- );
694
-
695
- // NoteArray constructor consumes its elements; use push(&note) to keep
696
- // `note` valid so we can return it to the caller.
697
- const ownOutputs = new wasm.NoteArray();
698
- ownOutputs.push(note);
699
- const request = new wasm.TransactionRequestBuilder()
700
- .withOwnOutputNotes(ownOutputs)
701
- .build();
702
-
703
- const { txId, result } = await this.#submitOrSubmitWithProver(
704
- senderId,
705
- request,
706
- opts.prover
707
- );
708
-
709
- if (opts.waitForConfirmation) {
710
- await this.waitFor(txId.toHex(), { timeout: opts.timeout });
711
- }
712
-
713
- return { txId, note, result };
714
- }
715
-
716
625
  async mint(opts) {
717
626
  this.#client.assertNotTerminated();
718
627
  const wasm = await this.#getWasm();
@@ -731,24 +640,6 @@ class TransactionsResource {
731
640
  return { txId, result };
732
641
  }
733
642
 
734
- async bridge(opts) {
735
- this.#client.assertNotTerminated();
736
- const wasm = await this.#getWasm();
737
- const { accountId, request } = await this.#buildB2AggRequest(opts, wasm);
738
-
739
- const { txId, result } = await this.#submitOrSubmitWithProver(
740
- accountId,
741
- request,
742
- opts.prover
743
- );
744
-
745
- if (opts.waitForConfirmation) {
746
- await this.waitFor(txId.toHex(), { timeout: opts.timeout });
747
- }
748
-
749
- return { txId, result };
750
- }
751
-
752
643
  async consume(opts) {
753
644
  this.#client.assertNotTerminated();
754
645
  const wasm = await this.#getWasm();
@@ -895,6 +786,14 @@ class TransactionsResource {
895
786
  return { txId, result };
896
787
  }
897
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
+ */
898
797
  async preview(opts) {
899
798
  this.#client.assertNotTerminated();
900
799
  const wasm = await this.#getWasm();
@@ -911,10 +810,6 @@ class TransactionsResource {
911
810
  ({ accountId, request } = await this.#buildMintRequest(opts, wasm));
912
811
  break;
913
812
  }
914
- case "bridge": {
915
- ({ accountId, request } = await this.#buildB2AggRequest(opts, wasm));
916
- break;
917
- }
918
813
  case "consume": {
919
814
  ({ accountId, request } = await this.#buildConsumeRequest(opts, wasm));
920
815
  break;
@@ -959,163 +854,6 @@ class TransactionsResource {
959
854
  async execute(opts) {
960
855
  this.#client.assertNotTerminated();
961
856
  const wasm = await this.#getWasm();
962
- const { accountId, request } = this.#buildExecuteRequest(opts, wasm);
963
-
964
- const { txId, result } = await this.#submitOrSubmitWithProver(
965
- accountId,
966
- request,
967
- opts.prover
968
- );
969
-
970
- if (opts.waitForConfirmation) {
971
- await this.waitFor(txId.toHex(), { timeout: opts.timeout });
972
- }
973
-
974
- return { txId, result };
975
- }
976
-
977
- /**
978
- * Submit a heterogeneous batch of operations against a single account. All
979
- * operations are executed, proven individually and as a batch, and submitted
980
- * atomically — either every tx in the batch lands or none does.
981
- *
982
- * @param {BatchOptions} opts - Batch options including the account, operations array, and confirmation settings.
983
- * @returns {Promise<BatchSubmitResult>} The block number the batch was accepted into.
984
- */
985
- async batch(opts) {
986
- this.#client.assertNotTerminated();
987
- const wasm = await this.#getWasm();
988
-
989
- if (!opts || !opts.account) {
990
- throw new Error("batch: `account` is required");
991
- }
992
- if (!Array.isArray(opts.operations) || opts.operations.length === 0) {
993
- throw new Error("batch: `operations` must be a non-empty array");
994
- }
995
-
996
- // Build each TransactionRequest. Per-op builders all use the batch-level
997
- // `account` — V1 only supports same-account batches, mirroring the Rust
998
- // constraint. We forward `opts.account` into each per-op options object so
999
- // the existing builders' `resolveAccountRef` produces fresh AccountIds
1000
- // when needed.
1001
- const requests = [];
1002
- for (let i = 0; i < opts.operations.length; i++) {
1003
- const op = opts.operations[i];
1004
- let built;
1005
- switch (op?.kind) {
1006
- case "send":
1007
- built = await this.#buildSendRequest(
1008
- { ...op, account: opts.account },
1009
- wasm
1010
- );
1011
- break;
1012
- case "mint":
1013
- built = await this.#buildMintRequest(
1014
- { ...op, account: opts.account },
1015
- wasm
1016
- );
1017
- break;
1018
- case "consume":
1019
- built = await this.#buildConsumeRequest(
1020
- { ...op, account: opts.account },
1021
- wasm
1022
- );
1023
- break;
1024
- case "swap":
1025
- built = await this.#buildSwapRequest(
1026
- { ...op, account: opts.account },
1027
- wasm
1028
- );
1029
- break;
1030
- case "execute":
1031
- built = this.#buildExecuteRequest(
1032
- { ...op, account: opts.account },
1033
- wasm
1034
- );
1035
- break;
1036
- case "custom":
1037
- if (!op.request) {
1038
- throw new Error(
1039
- `batch: operation[${i}] of kind "custom" is missing \`request\``
1040
- );
1041
- }
1042
- built = { request: op.request };
1043
- break;
1044
- default:
1045
- throw new Error(
1046
- `batch: operation[${i}] has unknown kind "${op?.kind}"`
1047
- );
1048
- }
1049
- requests.push(built.request);
1050
- }
1051
-
1052
- return this.submitBatch(opts.account, requests, opts);
1053
- }
1054
-
1055
- /**
1056
- * Submit pre-built TransactionRequests as an atomic batch. Lower-level
1057
- * counterpart of `batch()` — for callers that already have built requests in
1058
- * hand. Equivalent to `submit()` but plural.
1059
- *
1060
- * @param {AccountRef} account - The account executing the batch.
1061
- * @param {TransactionRequest[]} requests - Pre-built transaction requests.
1062
- * @param {object} [options] - Optional settings (waitForConfirmation, timeout).
1063
- * The batch is proved with the client's configured prover; the V1 batch API
1064
- * has no per-call prover override.
1065
- * @returns {Promise<BatchSubmitResult>} The block number the batch was accepted into.
1066
- */
1067
- async submitBatch(account, requests, options) {
1068
- this.#client.assertNotTerminated();
1069
- const wasm = await this.#getWasm();
1070
-
1071
- if (!Array.isArray(requests) || requests.length === 0) {
1072
- throw new Error("submitBatch: `requests` must be a non-empty array");
1073
- }
1074
-
1075
- const accountId = resolveAccountRef(account, wasm);
1076
- const blockNumber = await this.#inner.submitNewTransactionBatch(
1077
- accountId,
1078
- requests.map((r) => r.serialize())
1079
- );
1080
-
1081
- if (options?.waitForConfirmation) {
1082
- await this.#waitForBlock(blockNumber, options);
1083
- }
1084
-
1085
- return { blockNumber };
1086
- }
1087
-
1088
- /**
1089
- * Polls until the local sync height reaches `blockNumber` or the timeout
1090
- * expires. The Rust V1 batch API returns only a block number — there are no
1091
- * per-tx ids to poll on, so we wait on the chain height instead.
1092
- *
1093
- * @param {number} blockNumber - The block height to wait for.
1094
- * @param {object} [opts] - Polling options (timeout, interval).
1095
- */
1096
- async #waitForBlock(blockNumber, opts) {
1097
- const timeout = opts?.timeout ?? 60_000;
1098
- const interval = opts?.interval ?? 5_000;
1099
- const start = Date.now();
1100
-
1101
- while (true) {
1102
- if (timeout > 0 && Date.now() - start >= timeout) {
1103
- throw new Error(
1104
- `Batch confirmation timed out after ${timeout}ms (waiting for block ${blockNumber})`
1105
- );
1106
- }
1107
- try {
1108
- await this.#inner.syncStateWithTimeout(0);
1109
- } catch {
1110
- // sync may fail transiently; continue polling
1111
- }
1112
- const height = await this.#inner.getSyncHeight();
1113
- if (height >= blockNumber) return;
1114
- await new Promise((resolve) => setTimeout(resolve, interval));
1115
- }
1116
- }
1117
-
1118
- #buildExecuteRequest(opts, wasm) {
1119
857
  const accountId = resolveAccountRef(opts.account, wasm);
1120
858
 
1121
859
  let builder = new wasm.TransactionRequestBuilder().withCustomScript(
@@ -1143,7 +881,18 @@ class TransactionsResource {
1143
881
  );
1144
882
  }
1145
883
 
1146
- 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 };
1147
896
  }
1148
897
 
1149
898
  async executeProgram(opts) {
@@ -1316,24 +1065,6 @@ class TransactionsResource {
1316
1065
  return { accountId, request };
1317
1066
  }
1318
1067
 
1319
- async #buildB2AggRequest(opts, wasm) {
1320
- const accountId = resolveAccountRef(opts.account, wasm);
1321
- const bridgeAccountId = resolveAccountRef(opts.bridgeAccount, wasm);
1322
- const faucetId = resolveAccountRef(opts.token, wasm);
1323
- const amount = BigInt(opts.amount);
1324
- const destinationAddress = wasm.EthAddress.fromHex(opts.destinationAddress);
1325
-
1326
- const request = await this.#inner.newB2AggTransactionRequest(
1327
- accountId,
1328
- bridgeAccountId,
1329
- faucetId,
1330
- amount,
1331
- opts.destinationNetwork,
1332
- destinationAddress
1333
- );
1334
- return { accountId, request };
1335
- }
1336
-
1337
1068
  async #buildConsumeRequest(opts, wasm) {
1338
1069
  const accountId = resolveAccountRef(opts.account, wasm);
1339
1070
  const noteInputs = Array.isArray(opts.notes) ? opts.notes : [opts.notes];
@@ -1685,22 +1416,25 @@ class CompilerResource {
1685
1416
  /**
1686
1417
  * Compiles MASM code + slots into an AccountComponent ready for accounts.create().
1687
1418
  *
1688
- * @param {{ code: string, slots: StorageSlot[], supportAllTypes?: boolean }} opts
1419
+ * @param {{ code: string, namespace?: string, slots: StorageSlot[], supportAllTypes?: boolean }} opts
1689
1420
  * @returns {Promise<AccountComponent>}
1690
1421
  */
1691
- async component({ code, slots = [], supportAllTypes = true }) {
1422
+ async component({ code, namespace, slots = [], supportAllTypes = true }) {
1692
1423
  this.#client?.assertNotTerminated();
1693
1424
  const wasm = await this.#getWasm();
1694
1425
  const builder = await this.#inner.createCodeBuilder();
1695
- const compiled = builder.compileAccountComponentCode(code);
1426
+ const compiled = namespace
1427
+ ? builder.compileAccountComponentCodeWithPath(namespace, code)
1428
+ : builder.compileAccountComponentCode(code);
1696
1429
  const component = wasm.AccountComponent.compile(compiled, slots);
1697
1430
  return supportAllTypes ? component.withSupportsAllTypes() : component;
1698
1431
  }
1699
1432
 
1700
1433
  /**
1701
- * 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.
1702
1436
  *
1703
- * @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
1704
1438
  * @returns {Promise<TransactionScript>}
1705
1439
  */
1706
1440
  async txScript({ code, libraries = [] }) {
@@ -1713,9 +1447,10 @@ class CompilerResource {
1713
1447
  }
1714
1448
 
1715
1449
  /**
1716
- * 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.
1717
1452
  *
1718
- * @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
1719
1454
  * @returns {Promise<NoteScript>}
1720
1455
  */
1721
1456
  async noteScript({ code, libraries = [] }) {
@@ -1727,13 +1462,20 @@ class CompilerResource {
1727
1462
  }
1728
1463
  }
1729
1464
 
1730
- // Builds and links each library entry against `builder`. Inline
1731
- // `{ namespace, code, linking? }` entries are built via `buildLibrary` and
1732
- // linked according to `linking` (defaulting to dynamic, matching tutorial
1733
- // 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.
1734
1469
  function linkLibraries(builder, libraries) {
1735
1470
  for (const lib of libraries) {
1736
- 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") {
1737
1479
  const built = builder.buildLibrary(lib.namespace, lib.code);
1738
1480
  if (lib.linking === "static") {
1739
1481
  builder.linkStaticLibrary(built);
@@ -1801,137 +1543,6 @@ class KeystoreResource {
1801
1543
  }
1802
1544
  }
1803
1545
 
1804
- /**
1805
- * Coerce an `orderId` (string | bigint) to a decimal string for the WASM
1806
- * `u64` parse on the other side.
1807
- *
1808
- * A PSWAP `orderId` is `u64`-shaped and routinely exceeds
1809
- * `Number.MAX_SAFE_INTEGER` (`2^53 - 1`). JS `number` cannot represent the
1810
- * full u64 range without silent precision loss, so it is not accepted — pass
1811
- * `orderId` as a `bigint` or `string` instead.
1812
- *
1813
- * @param {string | bigint} orderId
1814
- * @returns {string}
1815
- */
1816
- function normalizeOrderId(orderId) {
1817
- if (typeof orderId === "bigint") return orderId.toString();
1818
- if (typeof orderId === "string") return orderId;
1819
- throw new TypeError(
1820
- `PSWAP orderId must be a string or bigint; got ${typeof orderId}`
1821
- );
1822
- }
1823
-
1824
- /**
1825
- * PswapResource surfaces partial-swap (PSWAP) lineage tracking and creator-side
1826
- * cancellation keyed by a lineage's stable order id.
1827
- *
1828
- * A PSWAP note can be filled by many consumers; each fill advances the lineage
1829
- * to a new remainder note. The client persists that chain locally as it syncs,
1830
- * and the reader methods here expose it. {@link PswapResource#cancelByOrder}
1831
- * reclaims the unfilled offered asset on the current tip of an active lineage,
1832
- * resolving the creator account from the tracked record so the caller only
1833
- * needs the order id.
1834
- */
1835
- class PswapResource {
1836
- #inner;
1837
- #getWasm;
1838
- #client;
1839
-
1840
- constructor(inner, getWasm, client) {
1841
- this.#inner = inner;
1842
- this.#getWasm = getWasm;
1843
- this.#client = client;
1844
- }
1845
-
1846
- /**
1847
- * Returns every PSWAP lineage tracked by this client.
1848
- *
1849
- * @returns {Promise<PswapLineageRecord[]>} All tracked lineages.
1850
- */
1851
- async lineages() {
1852
- this.#client.assertNotTerminated();
1853
- return await this.#inner.getPswapLineages();
1854
- }
1855
-
1856
- /**
1857
- * Returns lineages created by a specific local account.
1858
- *
1859
- * @param {AccountRef} account - Creator account (hex, bech32, Account, or AccountId).
1860
- * @returns {Promise<PswapLineageRecord[]>} Lineages created by the account.
1861
- */
1862
- async lineagesFor(account) {
1863
- this.#client.assertNotTerminated();
1864
- const wasm = await this.#getWasm();
1865
- const accountId = resolveAccountRef(account, wasm);
1866
- return await this.#inner.getPswapLineagesFor(accountId);
1867
- }
1868
-
1869
- /**
1870
- * Returns the lineage for one order, or null if not tracked.
1871
- *
1872
- * @param {string | bigint} orderId - Stable order id. Pass as a `string` or
1873
- * `bigint` for the full `u64` range; `number` is rejected because it cannot
1874
- * represent ids above `Number.MAX_SAFE_INTEGER` without precision loss.
1875
- * @returns {Promise<PswapLineageRecord | null>} The lineage, or null.
1876
- */
1877
- async lineage(orderId) {
1878
- this.#client.assertNotTerminated();
1879
- const result = await this.#inner.getPswapLineage(normalizeOrderId(orderId));
1880
- return result ?? null;
1881
- }
1882
-
1883
- /**
1884
- * Builds and submits a transaction reclaiming the unfilled offered asset on
1885
- * the current tip of an Active lineage. The creator account is resolved from
1886
- * the tracked lineage, so only the order id is required. Runs through the
1887
- * same execute/prove/submit path as the other transaction helpers.
1888
- *
1889
- * Throws before submitting any transaction when:
1890
- * - no lineage is tracked for `orderId`, OR
1891
- * - the lineage is in a terminal state (`FullyFilled` or `Reclaimed`,
1892
- * guarded by the `buildPswapCancelByOrder` binding).
1893
- *
1894
- * Concurrency: the lineage-read, build, and submit steps below are not
1895
- * atomic against external fills. If another consumer — or this client's own
1896
- * in-flight tx — advances the lineage tip between the build and submit, the
1897
- * cancel will target an already-consumed note and the kernel will reject
1898
- * it with a "note already nullified" error. Treat that as a signal to
1899
- * re-read the lineage and retry against the new tip.
1900
- *
1901
- * @param {PswapCancelByOrderOptions} opts - Order id and optional tx options.
1902
- * @returns {Promise<TransactionSubmitResult>} The submitted transaction.
1903
- */
1904
- async cancelByOrder(opts) {
1905
- this.#client.assertNotTerminated();
1906
- const orderId = normalizeOrderId(opts.orderId);
1907
-
1908
- // Fetch the lineage for the creator account (the cancel's submitter).
1909
- // The terminal-state guard is authoritative in the `buildPswapCancelByOrder`
1910
- // binding below, so it is not repeated here.
1911
- const lineage = await this.#inner.getPswapLineage(orderId);
1912
- if (!lineage) {
1913
- throw new Error(`No PSWAP lineage tracked for order ${orderId}`);
1914
- }
1915
- const accountId = lineage.creatorAccountId();
1916
-
1917
- const request = await this.#inner.buildPswapCancelByOrder(orderId);
1918
-
1919
- const { txId, result } = await this.#client.transactions.submit(
1920
- accountId,
1921
- request,
1922
- { prover: opts.prover }
1923
- );
1924
-
1925
- if (opts.waitForConfirmation) {
1926
- await this.#client.transactions.waitFor(txId.toHex(), {
1927
- timeout: opts.timeout,
1928
- });
1929
- }
1930
-
1931
- return { txId, result };
1932
- }
1933
- }
1934
-
1935
1546
  /**
1936
1547
  * MidenClient wraps the existing proxy-wrapped WebClient with a resource-based API.
1937
1548
  *
@@ -1962,7 +1573,6 @@ class MidenClient {
1962
1573
  this.settings = new SettingsResource(inner, getWasm, this);
1963
1574
  this.compile = new CompilerResource(inner, getWasm, this);
1964
1575
  this.keystore = new KeystoreResource(inner, this);
1965
- this.pswap = new PswapResource(inner, getWasm, this);
1966
1576
  }
1967
1577
 
1968
1578
  /**
@@ -2084,7 +1694,7 @@ class MidenClient {
2084
1694
  options.keystore.getKey,
2085
1695
  options.keystore.insertKey,
2086
1696
  options.keystore.sign,
2087
- options?.debugMode,
1697
+ undefined,
2088
1698
  useWorker
2089
1699
  );
2090
1700
  } else {
@@ -2093,7 +1703,7 @@ class MidenClient {
2093
1703
  noteTransportUrl,
2094
1704
  seed,
2095
1705
  options?.storeName,
2096
- options?.debugMode,
1706
+ undefined,
2097
1707
  useWorker
2098
1708
  );
2099
1709
  }
@@ -2536,6 +2146,9 @@ function buildSwapTag(opts) {
2536
2146
 
2537
2147
  function buildNoteAssets(assets, wasm) {
2538
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
+ }
2539
2152
  const fungibleAssets = assetArray.map((asset) => {
2540
2153
  const faucetId = resolveAccountRef(asset.token, wasm);
2541
2154
  return new wasm.FungibleAsset(faucetId, BigInt(asset.amount));
@@ -2764,17 +2377,6 @@ class StorageResult {
2764
2377
  return this.#word.toFelts();
2765
2378
  }
2766
2379
 
2767
- /**
2768
- * Returns all four elements of the stored Word as a BigUint64Array.
2769
- * Pass-through to Word.toU64s() — ensures code that expects a Word-like
2770
- * object (e.g., `result.toU64s()[0]`) works on StorageResult.
2771
- * @returns {BigUint64Array}
2772
- */
2773
- toU64s() {
2774
- if (!this.#word) return new BigUint64Array();
2775
- return this.#word.toU64s();
2776
- }
2777
-
2778
2380
  /**
2779
2381
  * The first Felt of the stored Word.
2780
2382
  * Returns the WASM Felt object — use .asInt() to get its BigInt value.
@@ -2923,11 +2525,9 @@ const Linking = Object.freeze({
2923
2525
  // (e.g. newSwapTransactionRequest, newPswapCreateTransactionRequest) are
2924
2526
  // `async fn` in Rust because they take the client's RNG via an async lock.
2925
2527
  const SYNC_METHODS = new Set([
2926
- "buildPswapCancelByOrder",
2927
2528
  "buildSwapTag",
2928
2529
  "createCodeBuilder",
2929
2530
  "lastAuthError",
2930
- "newB2AggTransactionRequest",
2931
2531
  "newConsumeTransactionRequest",
2932
2532
  "newMintTransactionRequest",
2933
2533
  "newPswapCancelTransactionRequest",
@@ -2938,7 +2538,6 @@ const SYNC_METHODS = new Set([
2938
2538
  "proveBlock",
2939
2539
  "serializeMockChain",
2940
2540
  "serializeMockNoteTransportNode",
2941
- "setDebugMode",
2942
2541
  "storeIdentifier",
2943
2542
  "usesMockChain",
2944
2543
  ]);