@miden-sdk/miden-sdk 0.15.0-alpha.4 → 0.15.0-alpha.6

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 (59) hide show
  1. package/README.md +139 -9
  2. package/dist/mt/Cargo-C9UbiAcT.js +26202 -0
  3. package/dist/mt/Cargo-C9UbiAcT.js.map +1 -0
  4. package/dist/{api-types.d.ts → mt/api-types.d.ts} +160 -6
  5. package/dist/mt/assets/miden_client_web.wasm +0 -0
  6. package/dist/mt/crates/miden_client_web.d.ts +4821 -0
  7. package/dist/mt/eager.js +38 -0
  8. package/dist/mt/eager.js.map +1 -0
  9. package/dist/{index.d.ts → mt/index.d.ts} +6 -3
  10. package/dist/mt/index.js +3811 -0
  11. package/dist/mt/index.js.map +1 -0
  12. package/dist/{wasm.js → mt/wasm.js} +1 -1
  13. package/dist/mt/wasm.js.map +1 -0
  14. package/dist/mt/workerHelpers.js +28 -0
  15. package/dist/mt/workers/Cargo-C9UbiAcT-Z344cyB1.js +26203 -0
  16. package/dist/mt/workers/Cargo-C9UbiAcT-Z344cyB1.js.map +1 -0
  17. package/dist/mt/workers/assets/miden_client_web.wasm +0 -0
  18. package/dist/mt/workers/web-client-methods-worker.js +26996 -0
  19. package/dist/mt/workers/web-client-methods-worker.js.map +1 -0
  20. package/dist/{workers → mt/workers}/web-client-methods-worker.module.js +71 -2
  21. package/dist/mt/workers/web-client-methods-worker.module.js.map +1 -0
  22. package/dist/mt/workers/workerHelpers.js +28 -0
  23. package/dist/{Cargo-CVlXCH_2.js → st/Cargo-OZMlHpic.js} +721 -496
  24. package/dist/st/Cargo-OZMlHpic.js.map +1 -0
  25. package/dist/st/api-types.d.ts +1144 -0
  26. package/dist/{workers → st}/assets/miden_client_web.wasm +0 -0
  27. package/dist/{crates → st/crates}/miden_client_web.d.ts +357 -197
  28. package/dist/st/docs-entry.d.ts +38 -0
  29. package/dist/{eager.js → st/eager.js} +2 -2
  30. package/dist/st/eager.js.map +1 -0
  31. package/dist/st/index.d.ts +183 -0
  32. package/dist/{index.js → st/index.js} +723 -284
  33. package/dist/st/index.js.map +1 -0
  34. package/dist/st/wasm.js +23 -0
  35. package/dist/st/wasm.js.map +1 -0
  36. package/dist/{workers/Cargo-CVlXCH_2-CWA-5vlh.js → st/workers/Cargo-OZMlHpic-DZjvJlWc.js} +721 -496
  37. package/dist/st/workers/Cargo-OZMlHpic-DZjvJlWc.js.map +1 -0
  38. package/dist/{assets → st/workers/assets}/miden_client_web.wasm +0 -0
  39. package/dist/{workers → st/workers}/web-client-methods-worker.js +792 -498
  40. package/dist/st/workers/web-client-methods-worker.js.map +1 -0
  41. package/dist/st/workers/web-client-methods-worker.module.js +628 -0
  42. package/dist/st/workers/web-client-methods-worker.module.js.map +1 -0
  43. package/js/client.js +190 -7
  44. package/js/node/napi-compat.js +22 -3
  45. package/js/node-index.js +0 -1
  46. package/js/resources/accounts.js +4 -6
  47. package/js/resources/transactions.js +138 -1
  48. package/lazy/package.json +2 -2
  49. package/mt/lazy/package.json +4 -0
  50. package/mt/package.json +4 -0
  51. package/package.json +30 -15
  52. package/dist/Cargo-CVlXCH_2.js.map +0 -1
  53. package/dist/eager.js.map +0 -1
  54. package/dist/index.js.map +0 -1
  55. package/dist/wasm.js.map +0 -1
  56. package/dist/workers/Cargo-CVlXCH_2-CWA-5vlh.js.map +0 -1
  57. package/dist/workers/web-client-methods-worker.js.map +0 -1
  58. package/dist/workers/web-client-methods-worker.module.js.map +0 -1
  59. /package/dist/{docs-entry.d.ts → mt/docs-entry.d.ts} +0 -0
@@ -102,16 +102,20 @@ export type NoteVisibility = "public" | "private";
102
102
 
103
103
  /**
104
104
  * User-friendly storage mode constants.
105
- * Use `StorageMode.Public`, `StorageMode.Private`, or `StorageMode.Network` instead of raw strings.
105
+ * Use `StorageMode.Public` or `StorageMode.Private` instead of raw strings.
106
+ *
107
+ * The `"network"` storage mode was removed in the migration to miden-client
108
+ * PR #2214 — the 0.15 protocol surface no longer has a separate
109
+ * network-account flag (network execution is now driven by the calling
110
+ * surface, not the account's storage mode).
106
111
  */
107
112
  export declare const StorageMode: {
108
113
  readonly Public: "public";
109
114
  readonly Private: "private";
110
- readonly Network: "network";
111
115
  };
112
116
 
113
117
  /** Union of valid StorageMode string values. */
114
- export type StorageMode = "public" | "private" | "network";
118
+ export type StorageMode = "public" | "private";
115
119
 
116
120
  /**
117
121
  * Library linking mode for script compilation.
@@ -195,6 +199,21 @@ export interface ClientOptions {
195
199
  insertKey: InsertKeyCallback;
196
200
  sign: SignCallback;
197
201
  };
202
+ /**
203
+ * Enable the Web Worker shim that runs WASM calls off the main thread.
204
+ * Defaults to `true` — leave it that way in browsers/extensions so the UI
205
+ * stays responsive while WASM is busy.
206
+ *
207
+ * Set to `false` when:
208
+ * - You pass a `CallbackProver` via `TransactionProver.newCallbackProver(jsFn)`.
209
+ * The worker boundary serializes the prover with `TransactionProver.serialize()`,
210
+ * which has no encoding for the callback variant and silently downgrades
211
+ * to `"local"` — your callback would never fire.
212
+ * - You're embedding the client in a single-WebView native shell (iOS/Android
213
+ * Capacitor host, Tauri, Electron preload), where the UI thread isn't
214
+ * competing with the WASM thread anyway.
215
+ */
216
+ useWorker?: boolean;
198
217
  }
199
218
 
200
219
  // ════════════════════════════════════════════════════════════════
@@ -241,6 +260,8 @@ export interface WalletCreateOptions {
241
260
  export interface FaucetCreateOptions {
242
261
  /** Use `AccountType.FungibleFaucet` or `AccountType.NonFungibleFaucet`. */
243
262
  type: AccountTypeValue;
263
+ /** Human-readable token name. Defaults to `symbol` when omitted. */
264
+ name?: string;
244
265
  symbol: string;
245
266
  decimals: number;
246
267
  maxSupply: number | bigint;
@@ -378,6 +399,41 @@ export interface SwapOptions extends TransactionOptions {
378
399
  paybackType?: NoteVisibility;
379
400
  }
380
401
 
402
+ /**
403
+ * Options for {@link TransactionsResource.pswapCreate}. V1 PSWAP notes carry
404
+ * no attachment, so there is no `attachment` field.
405
+ */
406
+ export interface PswapCreateOptions extends TransactionOptions {
407
+ /** Account that creates the partial-swap (PSWAP) note. */
408
+ account: AccountRef;
409
+ /** Fungible asset offered by the creator. */
410
+ offer: Asset;
411
+ /** Fungible asset requested in exchange. */
412
+ request: Asset;
413
+ /** Visibility of the PSWAP note itself. */
414
+ type?: NoteVisibility;
415
+ /** Visibility of the payback note fillers emit to the creator. Defaults to `public`. */
416
+ paybackType?: NoteVisibility;
417
+ }
418
+
419
+ export interface PswapConsumeOptions extends TransactionOptions {
420
+ /** Consumer account filling the PSWAP note. */
421
+ account: AccountRef;
422
+ /** PSWAP note to consume — accepts a note id (hex), `NoteId`, `InputNoteRecord`, or `Note`. */
423
+ note: NoteInput;
424
+ /** Requested-asset amount the consumer supplies from its own vault; a partial amount emits a remainder PSWAP note. */
425
+ fillAmount: number | bigint;
426
+ /** Requested-asset amount supplied by other in-flight notes in the same tx. Defaults to `0`; leave unset normally. */
427
+ noteFillAmount?: number | bigint;
428
+ }
429
+
430
+ export interface PswapCancelOptions extends TransactionOptions {
431
+ /** Creator account reclaiming the offered asset. */
432
+ account: AccountRef;
433
+ /** PSWAP note to cancel — accepts a note id (hex), `NoteId`, `InputNoteRecord`, or `Note`. */
434
+ note: NoteInput;
435
+ }
436
+
381
437
  export interface ExecuteOptions extends TransactionOptions {
382
438
  /** Account executing the custom script. */
383
439
  account: AccountRef;
@@ -438,6 +494,29 @@ export interface PreviewSwapOptions {
438
494
  paybackType?: NoteVisibility;
439
495
  }
440
496
 
497
+ export interface PreviewPswapCreateOptions {
498
+ operation: "pswapCreate";
499
+ account: AccountRef;
500
+ offer: Asset;
501
+ request: Asset;
502
+ type?: NoteVisibility;
503
+ paybackType?: NoteVisibility;
504
+ }
505
+
506
+ export interface PreviewPswapConsumeOptions {
507
+ operation: "pswapConsume";
508
+ account: AccountRef;
509
+ note: NoteInput;
510
+ fillAmount: number | bigint;
511
+ noteFillAmount?: number | bigint;
512
+ }
513
+
514
+ export interface PreviewPswapCancelOptions {
515
+ operation: "pswapCancel";
516
+ account: AccountRef;
517
+ note: NoteInput;
518
+ }
519
+
441
520
  export interface PreviewCustomOptions {
442
521
  operation: "custom";
443
522
  account: AccountRef;
@@ -449,6 +528,9 @@ export type PreviewOptions =
449
528
  | PreviewMintOptions
450
529
  | PreviewConsumeOptions
451
530
  | PreviewSwapOptions
531
+ | PreviewPswapCreateOptions
532
+ | PreviewPswapConsumeOptions
533
+ | PreviewPswapCancelOptions
452
534
  | PreviewCustomOptions;
453
535
 
454
536
  /** Status values reported during waitFor polling. */
@@ -654,6 +736,31 @@ export interface TransactionsResource {
654
736
  * @param options - Swap options including the account, offered asset, and requested asset.
655
737
  */
656
738
  swap(options: SwapOptions): Promise<TransactionSubmitResult>;
739
+ /**
740
+ * Create a partial-swap (PSWAP) note offering one fungible asset for
741
+ * another. Unlike `swap`, the resulting note can be filled by multiple
742
+ * consumers; each fill emits a payback note to the creator and, on a
743
+ * partial fill, a remainder PSWAP note carrying the unfilled amount.
744
+ *
745
+ * @param options - Creator, offered asset, requested asset, and visibility.
746
+ */
747
+ pswapCreate(options: PswapCreateOptions): Promise<TransactionSubmitResult>;
748
+ /**
749
+ * Consume (fully or partially fill) an existing PSWAP note. The consumer
750
+ * supplies `fillAmount` of the requested asset and receives a proportional
751
+ * share of the offered asset. A full fill (`fillAmount` equal to the
752
+ * note's requested amount) produces only the payback note; a partial fill
753
+ * also produces a remainder PSWAP note.
754
+ *
755
+ * @param options - Consumer account, PSWAP note, and fill amount.
756
+ */
757
+ pswapConsume(options: PswapConsumeOptions): Promise<TransactionSubmitResult>;
758
+ /**
759
+ * Cancel a PSWAP note as the creator and reclaim the offered asset.
760
+ *
761
+ * @param options - Creator account and PSWAP note to cancel.
762
+ */
763
+ pswapCancel(options: PswapCancelOptions): Promise<TransactionSubmitResult>;
657
764
  /**
658
765
  * Consume all available notes for an account, up to an optional limit.
659
766
  * Returns the count of remaining notes for pagination.
@@ -742,8 +849,13 @@ export interface NotesResource {
742
849
  * Import a note from a {@link NoteFile}.
743
850
  *
744
851
  * @param noteFile - The note file to import.
852
+ * @returns The imported note's id (hex) when the file carries metadata (a
853
+ * note id or a full note with proof); for a details-only file, which has no
854
+ * note id yet, the note's details commitment (hex) is returned instead.
855
+ * In both cases the value is a hex string, not a `NoteId` object — pass it
856
+ * to {@link NoteId.fromHex} if a `NoteId` instance is required.
745
857
  */
746
- import(noteFile: NoteFile): Promise<NoteId>;
858
+ import(noteFile: NoteFile): Promise<string>;
747
859
  /**
748
860
  * Export a note to a {@link NoteFile} for transfer or backup.
749
861
  *
@@ -924,6 +1036,15 @@ export declare class MidenClient {
924
1036
  static createDevnet(options?: ClientOptions): Promise<MidenClient>;
925
1037
  /** Creates a mock client for testing. */
926
1038
  static createMock(options?: MockOptions): Promise<MidenClient>;
1039
+ /**
1040
+ * Resolves once the WASM module is initialized and safe to use.
1041
+ *
1042
+ * Idempotent and shared across callers — concurrent invocations await the
1043
+ * same in-flight promise, and post-init callers resolve immediately.
1044
+ * Primarily useful on the `/lazy` entry (Next.js / Capacitor) where no
1045
+ * top-level await runs at import time; harmless on the eager entry.
1046
+ */
1047
+ static ready(): Promise<void>;
927
1048
 
928
1049
  readonly accounts: AccountsResource;
929
1050
  readonly transactions: TransactionsResource;
@@ -933,10 +1054,43 @@ export declare class MidenClient {
933
1054
  readonly compile: CompilerResource;
934
1055
  readonly keystore: KeystoreResource;
935
1056
 
936
- /** Syncs the client state with the Miden node. */
937
- sync(options?: { timeout?: number }): Promise<SyncSummary>;
1057
+ /** Syncs the client: fetches private notes from the Note Transport Layer, then syncs on-chain state. Fails fast on either. */
1058
+ sync(): Promise<SyncSummary>;
1059
+ /** Syncs on-chain state only (no NTL fetch). */
1060
+ syncChain(): Promise<SyncSummary>;
1061
+ /** Fetches private notes from the Note Transport Layer. */
1062
+ syncNoteTransport(): Promise<void>;
938
1063
  /** Returns the current sync height. */
939
1064
  getSyncHeight(): Promise<number>;
1065
+ /**
1066
+ * Resolves once every serialized WASM call that was already on the
1067
+ * internal call chain when `waitForIdle()` was called (execute, submit,
1068
+ * prove, apply, sync, or account creation) has settled. Use this from
1069
+ * callers that need to perform a non-WASM-side action — e.g. clearing
1070
+ * an in-memory auth key on wallet lock — after the kernel finishes, so
1071
+ * its auth callback doesn't race with the key being cleared. Does NOT
1072
+ * wait for calls enqueued after `waitForIdle()` returns.
1073
+ *
1074
+ * Caveat for `sync`: a `syncState` blocked on its sync lock (Web
1075
+ * Locks) has not yet reached the internal chain, so `waitForIdle`
1076
+ * does not await it. Other serialized methods are always observed.
1077
+ *
1078
+ * Returns immediately if nothing was in flight.
1079
+ */
1080
+ waitForIdle(): Promise<void>;
1081
+ /**
1082
+ * Returns the raw JS value that the most recent sign-callback invocation
1083
+ * threw, or `null` if the last sign call succeeded (or no call has
1084
+ * happened yet). Useful for recovering structured metadata (e.g. a
1085
+ * `reason: 'locked'` property) that the kernel-level `auth::request`
1086
+ * diagnostic would otherwise erase.
1087
+ *
1088
+ * Meaningful only with `useWorker: false` (the worker shim's keystore
1089
+ * lives in the worker WASM instance, so this reads `null` there). On
1090
+ * the Node.js binding it always returns `null` — signing goes through
1091
+ * the filesystem keystore, never a JS callback.
1092
+ */
1093
+ lastAuthError(): unknown;
940
1094
  /** Returns the client-level default prover. */
941
1095
  readonly defaultProver: TransactionProver | null;
942
1096
  /** Terminates the underlying Web Worker. After this, all method calls throw. */