@miden-sdk/miden-sdk 0.14.5 → 0.14.9

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 (55) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +148 -18
  3. package/dist/mt/Cargo-DKB2aRX-.js +25826 -0
  4. package/dist/mt/Cargo-DKB2aRX-.js.map +1 -0
  5. package/dist/{api-types.d.ts → mt/api-types.d.ts} +18 -3
  6. package/dist/mt/assets/miden_client_web.wasm +0 -0
  7. package/dist/mt/crates/miden_client_web.d.ts +4726 -0
  8. package/dist/{docs-entry.d.ts → mt/docs-entry.d.ts} +2 -2
  9. package/dist/mt/eager.js +35 -0
  10. package/dist/mt/eager.js.map +1 -0
  11. package/dist/{index.d.ts → mt/index.d.ts} +9 -7
  12. package/dist/mt/index.js +3371 -0
  13. package/dist/mt/index.js.map +1 -0
  14. package/dist/{wasm.js → mt/wasm.js} +1 -1
  15. package/dist/mt/wasm.js.map +1 -0
  16. package/dist/mt/workerHelpers.js +28 -0
  17. package/dist/mt/workers/Cargo-DKB2aRX--C6T4l3AF.js +25827 -0
  18. package/dist/mt/workers/Cargo-DKB2aRX--C6T4l3AF.js.map +1 -0
  19. package/dist/mt/workers/assets/miden_client_web.wasm +0 -0
  20. package/dist/mt/workers/web-client-methods-worker.js +26560 -0
  21. package/dist/mt/workers/web-client-methods-worker.js.map +1 -0
  22. package/dist/{workers → mt/workers}/web-client-methods-worker.module.js +17 -1
  23. package/dist/mt/workers/web-client-methods-worker.module.js.map +1 -0
  24. package/dist/mt/workers/workerHelpers.js +28 -0
  25. package/dist/{Cargo-M3382VZc.js → st/Cargo-jOTNoFyS.js} +6714 -5926
  26. package/dist/st/Cargo-jOTNoFyS.js.map +1 -0
  27. package/dist/st/api-types.d.ts +1051 -0
  28. package/dist/{workers → st}/assets/miden_client_web.wasm +0 -0
  29. package/dist/{crates → st/crates}/miden_client_web.d.ts +31 -0
  30. package/dist/st/docs-entry.d.ts +35 -0
  31. package/dist/{eager.js → st/eager.js} +1 -1
  32. package/dist/st/eager.js.map +1 -0
  33. package/dist/st/index.d.ts +89 -0
  34. package/dist/{index.js → st/index.js} +126 -13
  35. package/dist/st/index.js.map +1 -0
  36. package/dist/st/wasm.js +23 -0
  37. package/dist/st/wasm.js.map +1 -0
  38. package/dist/{workers/Cargo-M3382VZc-Dfw4tXwh.js → st/workers/Cargo-jOTNoFyS-DRTcF6wf.js} +6714 -5926
  39. package/dist/st/workers/Cargo-jOTNoFyS-DRTcF6wf.js.map +1 -0
  40. package/dist/{assets → st/workers/assets}/miden_client_web.wasm +0 -0
  41. package/dist/{workers → st/workers}/web-client-methods-worker.js +6731 -5926
  42. package/dist/st/workers/web-client-methods-worker.js.map +1 -0
  43. package/dist/st/workers/web-client-methods-worker.module.js +571 -0
  44. package/dist/st/workers/web-client-methods-worker.module.js.map +1 -0
  45. package/lazy/package.json +4 -0
  46. package/mt/lazy/package.json +4 -0
  47. package/mt/package.json +4 -0
  48. package/package.json +66 -44
  49. package/dist/Cargo-M3382VZc.js.map +0 -1
  50. package/dist/eager.js.map +0 -1
  51. package/dist/index.js.map +0 -1
  52. package/dist/wasm.js.map +0 -1
  53. package/dist/workers/Cargo-M3382VZc-Dfw4tXwh.js.map +0 -1
  54. package/dist/workers/web-client-methods-worker.js.map +0 -1
  55. package/dist/workers/web-client-methods-worker.module.js.map +0 -1
@@ -0,0 +1,1051 @@
1
+ // Import types needed for type references in the public API
2
+ import type {
3
+ SyncSummary,
4
+ TransactionProver,
5
+ Account,
6
+ AccountHeader,
7
+ AccountId,
8
+ AccountFile,
9
+ AccountCode,
10
+ AccountStorage,
11
+ AssetVault,
12
+ Word,
13
+ Felt,
14
+ TransactionId,
15
+ TransactionRequest,
16
+ TransactionResult,
17
+ TransactionSummary,
18
+ TransactionRecord,
19
+ InputNoteRecord,
20
+ OutputNoteRecord,
21
+ NoteId,
22
+ NoteFile,
23
+ NoteTag,
24
+ Note,
25
+ OutputNote,
26
+ NoteExportFormat,
27
+ StorageSlot,
28
+ AccountComponent,
29
+ AuthSecretKey,
30
+ AccountStorageRequirements,
31
+ TransactionScript,
32
+ NoteScript,
33
+ AdviceInputs,
34
+ FeltArray,
35
+ } from "./crates/miden_client_web.js";
36
+
37
+ // Import the full namespace for the MidenArrayConstructors type
38
+ import type * as WasmExports from "./crates/miden_client_web.js";
39
+
40
+ // Source of truth for standalone-wrapper return types. By deriving them from
41
+ // the wasm-bindgen-generated namespace (rather than hand-writing `: Note`),
42
+ // the declarations below cannot drift from the actual runtime behavior — the
43
+ // exact class of bug behind #2042. Any forwarder-style wrapper should follow
44
+ // the same pattern: `ReturnType<WasmModule["Class"]["method"]>`.
45
+ type WasmModule = typeof import("./crates/miden_client_web.js");
46
+
47
+ // ════════════════════════════════════════════════════════════════
48
+ // Callback types for external keystore support
49
+ // ════════════════════════════════════════════════════════════════
50
+
51
+ export type GetKeyCallback = (
52
+ pubKey: Uint8Array
53
+ ) => Promise<Uint8Array | null | undefined> | Uint8Array | null | undefined;
54
+
55
+ export type InsertKeyCallback = (
56
+ pubKey: Uint8Array,
57
+ secretKey: Uint8Array
58
+ ) => Promise<void> | void;
59
+
60
+ export type SignCallback = (
61
+ pubKey: Uint8Array,
62
+ signingInputs: Uint8Array
63
+ ) => Promise<Uint8Array> | Uint8Array;
64
+
65
+ type MidenArrayConstructors = {
66
+ [K in keyof typeof WasmExports as K extends `${string}Array`
67
+ ? K
68
+ : never]: (typeof WasmExports)[K];
69
+ };
70
+
71
+ export declare const MidenArrays: MidenArrayConstructors;
72
+
73
+ // ════════════════════════════════════════════════════════════════
74
+ // Constants
75
+ // ════════════════════════════════════════════════════════════════
76
+
77
+ /**
78
+ * User-friendly auth scheme constants for MidenClient options.
79
+ * Use `AuthScheme.Falcon` or `AuthScheme.ECDSA` instead of raw strings.
80
+ */
81
+ export declare const AuthScheme: {
82
+ readonly Falcon: "falcon";
83
+ readonly ECDSA: "ecdsa";
84
+ };
85
+
86
+ /**
87
+ * Union of all string values in the AuthScheme const. Merges with the
88
+ * `AuthScheme` value so `authScheme?: AuthScheme` resolves to
89
+ * `"falcon" | "ecdsa"` in type position while `AuthScheme.Falcon` /
90
+ * `AuthScheme.ECDSA` still work in value position.
91
+ */
92
+ export type AuthScheme = (typeof AuthScheme)[keyof typeof AuthScheme];
93
+
94
+ /** @deprecated Alias for `AuthScheme` (the string union). */
95
+ export type AuthSchemeType = AuthScheme;
96
+
97
+ /**
98
+ * Resolves an `AuthScheme` string to the numeric value expected by low-level
99
+ * wasm-bindgen methods such as
100
+ * `AccountComponent.createAuthComponentFromCommitment(commitment, scheme)`.
101
+ *
102
+ * @param scheme - `AuthScheme.Falcon` or `AuthScheme.ECDSA`. Defaults to `"falcon"`.
103
+ * @returns The numeric AuthScheme enum value.
104
+ */
105
+ export declare function resolveAuthScheme(scheme?: AuthScheme): number;
106
+
107
+ /**
108
+ * User-friendly note visibility constants.
109
+ * Use `NoteVisibility.Public` or `NoteVisibility.Private` instead of raw strings.
110
+ */
111
+ export declare const NoteVisibility: {
112
+ readonly Public: "public";
113
+ readonly Private: "private";
114
+ };
115
+
116
+ /** Union of valid NoteVisibility string values. */
117
+ export type NoteVisibility = "public" | "private";
118
+
119
+ /**
120
+ * User-friendly storage mode constants.
121
+ * Use `StorageMode.Public`, `StorageMode.Private`, or `StorageMode.Network` instead of raw strings.
122
+ */
123
+ export declare const StorageMode: {
124
+ readonly Public: "public";
125
+ readonly Private: "private";
126
+ readonly Network: "network";
127
+ };
128
+
129
+ /** Union of valid StorageMode string values. */
130
+ export type StorageMode = "public" | "private" | "network";
131
+
132
+ /**
133
+ * Library linking mode for script compilation.
134
+ * Use `Linking.Dynamic` or `Linking.Static` instead of raw strings.
135
+ */
136
+ export declare const Linking: {
137
+ readonly Dynamic: "dynamic";
138
+ readonly Static: "static";
139
+ };
140
+
141
+ /** Union of valid Linking string values. */
142
+ export type Linking = "dynamic" | "static";
143
+
144
+ /**
145
+ * Union of all values in the AccountType const.
146
+ */
147
+ export type AccountType = (typeof AccountType)[keyof typeof AccountType];
148
+
149
+ /**
150
+ * Account type constants with numeric values matching the WASM `AccountType` enum.
151
+ * Includes SDK-friendly aliases (e.g. `MutableWallet`) that map to the same
152
+ * numeric values. These values work with both `accounts.create()` and the
153
+ * low-level `AccountBuilder.accountType()`.
154
+ */
155
+ export declare const AccountType: {
156
+ // WASM-compatible values
157
+ readonly FungibleFaucet: 0;
158
+ readonly NonFungibleFaucet: 1;
159
+ readonly RegularAccountImmutableCode: 2;
160
+ readonly RegularAccountUpdatableCode: 3;
161
+ // SDK-friendly aliases
162
+ readonly MutableWallet: 3;
163
+ readonly ImmutableWallet: 2;
164
+ readonly ImmutableContract: 2;
165
+ readonly MutableContract: 3;
166
+ };
167
+
168
+ /** Union of valid AccountType numeric values. */
169
+ export type AccountTypeValue = 0 | 1 | 2 | 3;
170
+
171
+ // ════════════════════════════════════════════════════════════════
172
+ // Client options
173
+ // ════════════════════════════════════════════════════════════════
174
+
175
+ export interface ClientOptions {
176
+ /**
177
+ * RPC endpoint. Accepts shorthands or a raw URL:
178
+ * - `"testnet"` — Miden testnet RPC (`https://rpc.testnet.miden.io`)
179
+ * - `"devnet"` — Miden devnet RPC (`https://rpc.devnet.miden.io`)
180
+ * - `"localhost"` / `"local"` — local node (`http://localhost:57291`)
181
+ * - any other string — treated as a raw RPC endpoint URL
182
+ * Defaults to the SDK testnet RPC if omitted.
183
+ */
184
+ rpcUrl?: "testnet" | "devnet" | "localhost" | "local" | (string & {});
185
+ /**
186
+ * Note transport endpoint. Accepts shorthands or a raw URL:
187
+ * - `"testnet"` — Miden testnet transport (`https://transport.miden.io`)
188
+ * - `"devnet"` — Miden devnet transport (`https://transport.devnet.miden.io`)
189
+ * - any other string — treated as a raw note transport endpoint URL
190
+ */
191
+ noteTransportUrl?: "testnet" | "devnet" | (string & {});
192
+ /**
193
+ * Prover to use for transactions. Accepts shorthands or a raw URL:
194
+ * - `"local"` — local (in-browser) prover
195
+ * - `"devnet"` — Miden devnet remote prover
196
+ * - `"testnet"` — Miden testnet remote prover
197
+ * - any other string — treated as a raw remote prover URL
198
+ */
199
+ proverUrl?: "local" | "devnet" | "testnet" | (string & {});
200
+ /** Hashed to 32 bytes via SHA-256. */
201
+ seed?: string | Uint8Array;
202
+ /** Store isolation key. */
203
+ storeName?: string;
204
+ /** Sync state on creation (default: false). */
205
+ autoSync?: boolean;
206
+ /** External keystore callbacks. */
207
+ keystore?: {
208
+ getKey: GetKeyCallback;
209
+ insertKey: InsertKeyCallback;
210
+ sign: SignCallback;
211
+ };
212
+ /**
213
+ * Enable the Web Worker shim that runs WASM calls off the main thread.
214
+ * Defaults to `true` — leave it that way in browsers/extensions so the UI
215
+ * stays responsive while WASM is busy.
216
+ *
217
+ * Set to `false` when:
218
+ * - You pass a `CallbackProver` via `TransactionProver.newCallbackProver(jsFn)`.
219
+ * The worker boundary serializes the prover with `TransactionProver.serialize()`,
220
+ * which has no encoding for the callback variant and silently downgrades
221
+ * to `"local"` — your callback would never fire.
222
+ * - You're embedding the client in a single-WebView native shell (iOS/Android
223
+ * Capacitor host, Tauri, Electron preload), where the UI thread isn't
224
+ * competing with the WASM thread anyway.
225
+ */
226
+ useWorker?: boolean;
227
+ }
228
+
229
+ // ════════════════════════════════════════════════════════════════
230
+ // Shared types
231
+ // ════════════════════════════════════════════════════════════════
232
+
233
+ /**
234
+ * An account reference: hex string, bech32 string, Account, AccountHeader, or AccountId object.
235
+ * All ID fields throughout the SDK accept any of these forms.
236
+ */
237
+ export type AccountRef = string | Account | AccountHeader | AccountId;
238
+
239
+ /** Represents an amount of a specific token (identified by its faucet account). */
240
+ export interface Asset {
241
+ /** Token identifier (faucet account ID). */
242
+ token: AccountRef;
243
+ /** Auto-converted to bigint internally. */
244
+ amount: number | bigint;
245
+ }
246
+
247
+ /**
248
+ * A note reference: hex note ID string, NoteId object, InputNoteRecord, or Note object.
249
+ */
250
+ export type NoteInput = string | NoteId | Note | InputNoteRecord;
251
+
252
+ // ════════════════════════════════════════════════════════════════
253
+ // Account types
254
+ // ════════════════════════════════════════════════════════════════
255
+
256
+ /** Create a wallet, faucet, or contract. Discriminated by `type` field. */
257
+ export type CreateAccountOptions =
258
+ | WalletCreateOptions
259
+ | FaucetCreateOptions
260
+ | ContractCreateOptions;
261
+
262
+ export interface WalletCreateOptions {
263
+ /** Account type. Defaults to `AccountType.MutableWallet`. */
264
+ type?: AccountTypeValue;
265
+ storage?: StorageMode;
266
+ auth?: AuthSchemeType;
267
+ seed?: string | Uint8Array;
268
+ }
269
+
270
+ export interface FaucetCreateOptions {
271
+ /** Use `AccountType.FungibleFaucet` or `AccountType.NonFungibleFaucet`. */
272
+ type: AccountTypeValue;
273
+ symbol: string;
274
+ decimals: number;
275
+ maxSupply: number | bigint;
276
+ storage?: StorageMode;
277
+ auth?: AuthSchemeType;
278
+ }
279
+
280
+ export interface ContractCreateOptions {
281
+ /** Use `AccountType.ImmutableContract` or `AccountType.MutableContract`. */
282
+ type?: AccountTypeValue;
283
+ /** Raw 32-byte seed (Uint8Array). Required. */
284
+ seed: Uint8Array;
285
+ /** Auth secret key. Required. */
286
+ auth: AuthSecretKey;
287
+ /** Pre-compiled AccountComponent instances. Required for contracts. */
288
+ components: AccountComponent[];
289
+ /** Storage mode. Defaults to "public" for contracts. */
290
+ storage?: StorageMode;
291
+ }
292
+
293
+ export interface AccountDetails {
294
+ account: Account;
295
+ vault: AssetVault;
296
+ storage: AccountStorage;
297
+ code: AccountCode | null;
298
+ keys: Word[];
299
+ }
300
+
301
+ /**
302
+ * Discriminated union for account import.
303
+ *
304
+ * - `AccountRef` (string, AccountId, Account, AccountHeader) — Import a public account by ID (fetches state from the network).
305
+ * - `{ file: AccountFile }` — Import from a previously exported account file (works for both public and private accounts).
306
+ * - `{ seed, type?, auth? }` — Reconstruct a **public** account from its init seed. **Does not work for private accounts** — use the account file workflow instead.
307
+ */
308
+ export type ImportAccountInput =
309
+ | AccountRef
310
+ | { file: AccountFile }
311
+ | {
312
+ seed: Uint8Array;
313
+ /** Account type. Defaults to `AccountType.MutableWallet`. */
314
+ type?: AccountTypeValue;
315
+ auth?: AuthSchemeType;
316
+ };
317
+
318
+ export interface InsertAccountOptions {
319
+ /** The pre-built account to insert. */
320
+ account: Account;
321
+ /** Whether to overwrite an existing account with the same ID. Defaults to `false`. */
322
+ overwrite?: boolean;
323
+ }
324
+
325
+ /** Options for accounts.export(). Exists for forward-compatible extensibility. */
326
+ export interface ExportAccountOptions {}
327
+
328
+ // ════════════════════════════════════════════════════════════════
329
+ // Transaction types
330
+ // ════════════════════════════════════════════════════════════════
331
+
332
+ export interface TransactionOptions {
333
+ waitForConfirmation?: boolean;
334
+ /**
335
+ * Wall-clock polling timeout in milliseconds for waitFor() (default: 60_000).
336
+ * This is NOT a block height. For block-height-based parameters, see
337
+ * `reclaimAfter` and `timelockUntil` on SendOptions.
338
+ */
339
+ timeout?: number;
340
+ /** Override default prover. */
341
+ prover?: TransactionProver;
342
+ }
343
+
344
+ export interface SendOptionsDefault extends TransactionOptions {
345
+ account: AccountRef;
346
+ to: AccountRef;
347
+ token: AccountRef;
348
+ amount: number | bigint;
349
+ type?: NoteVisibility;
350
+ returnNote?: false;
351
+ /** Block height after which the sender can reclaim the note. This is a block number, not wall-clock time. */
352
+ reclaimAfter?: number;
353
+ /** Block height until which the note is timelocked. This is a block number, not wall-clock time. */
354
+ timelockUntil?: number;
355
+ }
356
+
357
+ export interface SendOptionsReturnNote extends TransactionOptions {
358
+ account: AccountRef;
359
+ to: AccountRef;
360
+ token: AccountRef;
361
+ amount: number | bigint;
362
+ type?: NoteVisibility;
363
+ returnNote: true;
364
+ }
365
+
366
+ /** @deprecated Use SendOptionsDefault or SendOptionsReturnNote instead */
367
+ export type SendOptions = SendOptionsDefault | SendOptionsReturnNote;
368
+
369
+ export interface SendResult {
370
+ txId: TransactionId;
371
+ note: Note | null;
372
+ result: TransactionResult;
373
+ }
374
+
375
+ /** Result of methods that previously returned bare TransactionId. */
376
+ export interface TransactionSubmitResult {
377
+ txId: TransactionId;
378
+ result: TransactionResult;
379
+ }
380
+
381
+ export interface MintOptions extends TransactionOptions {
382
+ /** Faucet (executing account). */
383
+ account: AccountRef;
384
+ /** Recipient account. */
385
+ to: AccountRef;
386
+ /** Amount to mint. */
387
+ amount: number | bigint;
388
+ /** Note visibility. Defaults to "public". */
389
+ type?: NoteVisibility;
390
+ }
391
+
392
+ export interface ConsumeOptions extends TransactionOptions {
393
+ account: AccountRef;
394
+ notes: NoteInput | NoteInput[];
395
+ }
396
+
397
+ export interface ConsumeAllOptions extends TransactionOptions {
398
+ account: AccountRef;
399
+ maxNotes?: number;
400
+ }
401
+
402
+ export interface SwapOptions extends TransactionOptions {
403
+ account: AccountRef;
404
+ offer: Asset;
405
+ request: Asset;
406
+ type?: NoteVisibility;
407
+ paybackType?: NoteVisibility;
408
+ }
409
+
410
+ export interface ExecuteOptions extends TransactionOptions {
411
+ /** Account executing the custom script. */
412
+ account: AccountRef;
413
+ /** Compiled TransactionScript. */
414
+ script: TransactionScript;
415
+ /** Foreign accounts referenced by the script. */
416
+ foreignAccounts?: (
417
+ | AccountRef
418
+ | { id: AccountRef; storage?: AccountStorageRequirements }
419
+ )[];
420
+ }
421
+
422
+ export interface ExecuteProgramOptions {
423
+ /** Account to execute the program against. */
424
+ account: AccountRef;
425
+ /** Compiled TransactionScript to execute. */
426
+ script: TransactionScript;
427
+ /** Advice inputs for the execution. Defaults to empty. */
428
+ adviceInputs?: AdviceInputs;
429
+ /** Foreign accounts referenced by the script. */
430
+ foreignAccounts?: (
431
+ | AccountRef
432
+ | { id: AccountRef; storage?: AccountStorageRequirements }
433
+ )[];
434
+ }
435
+
436
+ export interface PreviewSendOptions {
437
+ operation: "send";
438
+ account: AccountRef;
439
+ to: AccountRef;
440
+ token: AccountRef;
441
+ amount: number | bigint;
442
+ type?: NoteVisibility;
443
+ reclaimAfter?: number;
444
+ timelockUntil?: number;
445
+ }
446
+
447
+ export interface PreviewMintOptions {
448
+ operation: "mint";
449
+ account: AccountRef;
450
+ to: AccountRef;
451
+ amount: number | bigint;
452
+ type?: NoteVisibility;
453
+ }
454
+
455
+ export interface PreviewConsumeOptions {
456
+ operation: "consume";
457
+ account: AccountRef;
458
+ notes: NoteInput | NoteInput[];
459
+ }
460
+
461
+ export interface PreviewSwapOptions {
462
+ operation: "swap";
463
+ account: AccountRef;
464
+ offer: Asset;
465
+ request: Asset;
466
+ type?: NoteVisibility;
467
+ paybackType?: NoteVisibility;
468
+ }
469
+
470
+ export type PreviewOptions =
471
+ | PreviewSendOptions
472
+ | PreviewMintOptions
473
+ | PreviewConsumeOptions
474
+ | PreviewSwapOptions;
475
+
476
+ /** Status values reported during waitFor polling. */
477
+ export type WaitStatus = "pending" | "submitted" | "committed";
478
+
479
+ export interface WaitOptions {
480
+ /** Wall-clock polling timeout in ms (default: 60_000). Set to 0 to disable timeout and poll indefinitely. */
481
+ timeout?: number;
482
+ /** Polling interval in ms (default: 5_000). */
483
+ interval?: number;
484
+ onProgress?: (status: WaitStatus) => void;
485
+ }
486
+
487
+ /** Result of consumeAll — includes count of remaining notes for pagination. */
488
+ export interface ConsumeAllResult {
489
+ txId: TransactionId | null;
490
+ consumed: number;
491
+ remaining: number;
492
+ result?: TransactionResult;
493
+ }
494
+
495
+ /**
496
+ * Discriminated union for transaction queries.
497
+ * Mirrors the underlying WASM TransactionFilter enum.
498
+ */
499
+ export type TransactionQuery =
500
+ | { status: "uncommitted" }
501
+ | { ids: (string | TransactionId)[] }
502
+ | { expiredBefore: number };
503
+
504
+ // ════════════════════════════════════════════════════════════════
505
+ // Note types
506
+ // ════════════════════════════════════════════════════════════════
507
+
508
+ /** Discriminated union for note queries. */
509
+ export type NoteQuery =
510
+ | {
511
+ status:
512
+ | "consumed"
513
+ | "committed"
514
+ | "expected"
515
+ | "processing"
516
+ | "unverified";
517
+ }
518
+ | { ids: (string | NoteId)[] };
519
+
520
+ /** Options for standalone note creation utilities. */
521
+ export interface NoteOptions {
522
+ from: AccountRef;
523
+ to: AccountRef;
524
+ assets: Asset | Asset[];
525
+ type?: NoteVisibility;
526
+ attachment?: Felt[];
527
+ }
528
+
529
+ export interface P2IDEOptions extends NoteOptions {
530
+ reclaimAfter?: number;
531
+ timelockUntil?: number;
532
+ }
533
+
534
+ export interface ExportNoteOptions {
535
+ /** Export format. Defaults to NoteExportFormat.Full. Use the NoteExportFormat enum. */
536
+ format?: NoteExportFormat;
537
+ }
538
+
539
+ export interface FetchPrivateNotesOptions {
540
+ mode?: "incremental" | "all";
541
+ }
542
+
543
+ export interface SendPrivateOptions {
544
+ note: NoteInput;
545
+ to: AccountRef;
546
+ }
547
+
548
+ export interface MockOptions {
549
+ seed?: string | Uint8Array;
550
+ serializedMockChain?: Uint8Array;
551
+ serializedNoteTransport?: Uint8Array;
552
+ }
553
+
554
+ /** Versioned store snapshot for backup/restore. */
555
+ export interface StoreSnapshot {
556
+ version: number;
557
+ data: unknown;
558
+ }
559
+
560
+ // ════════════════════════════════════════════════════════════════
561
+ // Swap tag options
562
+ // ════════════════════════════════════════════════════════════════
563
+
564
+ export interface BuildSwapTagOptions {
565
+ type?: NoteVisibility;
566
+ offer: Asset;
567
+ request: Asset;
568
+ }
569
+
570
+ // ════════════════════════════════════════════════════════════════
571
+ // Resource interfaces
572
+ // ════════════════════════════════════════════════════════════════
573
+
574
+ export interface AccountsResource {
575
+ /**
576
+ * Create a new wallet, faucet, or contract account. Defaults to a mutable
577
+ * wallet if no options are provided.
578
+ *
579
+ * @param options - Account creation options discriminated by `type` field.
580
+ */
581
+ create(options?: CreateAccountOptions): Promise<Account>;
582
+ /**
583
+ * Insert a pre-built account into the local store. Useful for external signer
584
+ * integrations that construct accounts via `AccountBuilder` with custom auth commitments.
585
+ *
586
+ * @param options - Insert options.
587
+ */
588
+ insert(options: InsertAccountOptions): Promise<void>;
589
+ /**
590
+ * Retrieve an account by ID. Returns `null` if not found in the local store.
591
+ *
592
+ * @param accountId - The account to retrieve.
593
+ */
594
+ get(accountId: AccountRef): Promise<Account | null>;
595
+ /**
596
+ * Retrieve an account locally, or import it from the network if not found.
597
+ *
598
+ * @param accountId - The account to retrieve or import.
599
+ */
600
+ getOrImport(accountId: AccountRef): Promise<Account>;
601
+ /**
602
+ * List all accounts in the local store.
603
+ */
604
+ list(): Promise<AccountHeader[]>;
605
+ /**
606
+ * Retrieve detailed account information including vault, storage, code, and keys.
607
+ *
608
+ * @param accountId - The account to retrieve details for.
609
+ */
610
+ getDetails(accountId: AccountRef): Promise<AccountDetails>;
611
+ /**
612
+ * Get the balance of a specific token for an account.
613
+ *
614
+ * @param accountId - The account to check.
615
+ * @param tokenId - The faucet account that identifies the token.
616
+ */
617
+ getBalance(accountId: AccountRef, tokenId: AccountRef): Promise<bigint>;
618
+
619
+ /**
620
+ * Import an account from the network by ID, from an exported file, or
621
+ * reconstruct from a seed.
622
+ *
623
+ * @param input - Account reference, file, or seed-based import options.
624
+ */
625
+ import(input: ImportAccountInput): Promise<Account>;
626
+ /**
627
+ * Export an account to an {@link AccountFile} for backup or transfer.
628
+ *
629
+ * @param accountId - The account to export.
630
+ * @param options - Export options (reserved for future use).
631
+ */
632
+ export(
633
+ accountId: AccountRef,
634
+ options?: ExportAccountOptions
635
+ ): Promise<AccountFile>;
636
+
637
+ /**
638
+ * Associate a Bech32 address with an account.
639
+ *
640
+ * @param accountId - The account to add the address to.
641
+ * @param address - The Bech32 address string.
642
+ */
643
+ addAddress(accountId: AccountRef, address: string): Promise<void>;
644
+ /**
645
+ * Remove a Bech32 address from an account.
646
+ *
647
+ * @param accountId - The account to remove the address from.
648
+ * @param address - The Bech32 address string to remove.
649
+ */
650
+ removeAddress(accountId: AccountRef, address: string): Promise<void>;
651
+ }
652
+
653
+ export interface TransactionsResource {
654
+ /**
655
+ * Send tokens to another account by creating a pay-to-ID note. Set
656
+ * `returnNote: true` to get the created note back.
657
+ *
658
+ * @param options - Send options including sender, recipient, token, and amount.
659
+ */
660
+ send(
661
+ options: SendOptionsDefault
662
+ ): Promise<{ txId: TransactionId; note: null; result: TransactionResult }>;
663
+ send(
664
+ options: SendOptionsReturnNote
665
+ ): Promise<{ txId: TransactionId; note: Note; result: TransactionResult }>;
666
+ send(options: SendOptions): Promise<SendResult>;
667
+ /**
668
+ * Mint new tokens from a faucet account.
669
+ *
670
+ * @param options - Mint options including the faucet, recipient, and amount.
671
+ */
672
+ mint(options: MintOptions): Promise<TransactionSubmitResult>;
673
+ /**
674
+ * Consume one or more notes for an account.
675
+ *
676
+ * @param options - Consume options including the account and notes to consume.
677
+ */
678
+ consume(options: ConsumeOptions): Promise<TransactionSubmitResult>;
679
+ /**
680
+ * Execute an atomic swap between two assets.
681
+ *
682
+ * @param options - Swap options including the account, offered asset, and requested asset.
683
+ */
684
+ swap(options: SwapOptions): Promise<TransactionSubmitResult>;
685
+ /**
686
+ * Consume all available notes for an account, up to an optional limit.
687
+ * Returns the count of remaining notes for pagination.
688
+ *
689
+ * @param options - Options including the account and optional max notes limit.
690
+ */
691
+ consumeAll(options: ConsumeAllOptions): Promise<ConsumeAllResult>;
692
+ /**
693
+ * Execute a custom transaction script with optional foreign account references.
694
+ *
695
+ * @param options - Execute options including the account, compiled script, and foreign accounts.
696
+ */
697
+ execute(options: ExecuteOptions): Promise<TransactionSubmitResult>;
698
+
699
+ /**
700
+ * Dry-run a transaction to preview its effects without submitting it to
701
+ * the network.
702
+ *
703
+ * @param options - Preview options discriminated by `operation` field.
704
+ */
705
+ preview(options: PreviewOptions): Promise<TransactionSummary>;
706
+
707
+ /**
708
+ * Submit a pre-built TransactionRequest. Note: WASM requires accountId
709
+ * separately, so `account` is the first argument.
710
+ *
711
+ * @param account - The account executing the transaction.
712
+ * @param request - The pre-built transaction request.
713
+ * @param options - Optional transaction options (prover, confirmation).
714
+ */
715
+ submit(
716
+ account: AccountRef,
717
+ request: TransactionRequest,
718
+ options?: TransactionOptions
719
+ ): Promise<TransactionSubmitResult>;
720
+
721
+ /** Execute a program (view call) and return the resulting stack output. */
722
+ executeProgram(options: ExecuteProgramOptions): Promise<FeltArray>;
723
+
724
+ /**
725
+ * List transactions, optionally filtered by status, IDs, or expiration.
726
+ *
727
+ * @param query - Optional filter for transaction status, IDs, or expiration.
728
+ */
729
+ list(query?: TransactionQuery): Promise<TransactionRecord[]>;
730
+
731
+ /**
732
+ * Poll until a transaction is confirmed on-chain. Throws on rejection
733
+ * or timeout.
734
+ *
735
+ * @param txId - The transaction ID to wait for.
736
+ * @param options - Optional polling timeout, interval, and progress callback.
737
+ */
738
+ waitFor(txId: string | TransactionId, options?: WaitOptions): Promise<void>;
739
+ }
740
+
741
+ export interface NotesResource {
742
+ /**
743
+ * List received (input) notes, optionally filtered by status or IDs.
744
+ *
745
+ * @param query - Optional filter by note status or note IDs.
746
+ */
747
+ list(query?: NoteQuery): Promise<InputNoteRecord[]>;
748
+ /**
749
+ * Retrieve a note by ID. Returns `null` if not found.
750
+ *
751
+ * @param noteId - The note to retrieve.
752
+ */
753
+ get(noteId: NoteInput): Promise<InputNoteRecord | null>;
754
+
755
+ /**
756
+ * List sent (output) notes, optionally filtered by status or IDs.
757
+ *
758
+ * @param query - Optional filter by note status or note IDs.
759
+ */
760
+ listSent(query?: NoteQuery): Promise<OutputNoteRecord[]>;
761
+
762
+ /**
763
+ * List notes that are available for consumption by a specific account.
764
+ *
765
+ * @param options - Options containing the account to check availability for.
766
+ */
767
+ listAvailable(options: { account: AccountRef }): Promise<InputNoteRecord[]>;
768
+
769
+ /**
770
+ * Import a note from a {@link NoteFile}.
771
+ *
772
+ * @param noteFile - The note file to import.
773
+ */
774
+ import(noteFile: NoteFile): Promise<NoteId>;
775
+ /**
776
+ * Export a note to a {@link NoteFile} for transfer or backup.
777
+ *
778
+ * @param noteId - The note to export.
779
+ * @param options - Optional export format options.
780
+ */
781
+ export(noteId: NoteInput, options?: ExportNoteOptions): Promise<NoteFile>;
782
+
783
+ /**
784
+ * Fetch private notes from the note transport service.
785
+ *
786
+ * @param options - Optional fetch mode: `"incremental"` (default) or `"all"`.
787
+ */
788
+ fetchPrivate(options?: FetchPrivateNotesOptions): Promise<void>;
789
+ /**
790
+ * Send a private note to a recipient via the note transport service.
791
+ *
792
+ * @param options - Options including the note and the recipient.
793
+ */
794
+ sendPrivate(options: SendPrivateOptions): Promise<void>;
795
+ }
796
+
797
+ // ════════════════════════════════════════════════════════════════
798
+ // Compiler types
799
+ // ════════════════════════════════════════════════════════════════
800
+
801
+ export interface CompileComponentOptions {
802
+ /** MASM source code for the component. */
803
+ code: string;
804
+ /** Initial storage slots for the component. */
805
+ slots?: StorageSlot[];
806
+ /**
807
+ * When true, the component accepts all input types for Falcon-signed
808
+ * transactions by automatically adding `exec.auth::auth_tx_rpo_falcon512`
809
+ * to a library context. Default: true.
810
+ *
811
+ * **BREAKING (v0.12):** This flag was added in v0.12 and defaults to `true`.
812
+ * Set to `false` if you compile a component that already includes its own
813
+ * auth transaction kernel invocation or intentionally omits one.
814
+ */
815
+ supportAllTypes?: boolean;
816
+ }
817
+
818
+ export interface CompileTxScriptLibrary {
819
+ /** MASM namespace for the library (e.g. "counter::module"). */
820
+ namespace: string;
821
+ /** MASM source code for the library. */
822
+ code: string;
823
+ /**
824
+ * `Linking.Dynamic` (default) — procedures are linked via DYNCALL at runtime.
825
+ * `Linking.Static` — procedures are inlined at compile time.
826
+ */
827
+ linking?: Linking;
828
+ }
829
+
830
+ export interface CompileTxScriptOptions {
831
+ /** MASM source code for the transaction script. */
832
+ code: string;
833
+ /** Component libraries to link. */
834
+ libraries?: CompileTxScriptLibrary[];
835
+ }
836
+
837
+ export interface CompileNoteScriptOptions {
838
+ /** MASM source code for the note script. */
839
+ code: string;
840
+ /** Component libraries to link. */
841
+ libraries?: CompileTxScriptLibrary[];
842
+ }
843
+
844
+ export declare class CompilerResource {
845
+ /**
846
+ * Create a standalone `CompilerResource` over a WASM `WebClient` proxy.
847
+ *
848
+ * Normally accessed as `client.compile` on a `MidenClient`; construct
849
+ * directly only when you need the compiler surface without the full
850
+ * `MidenClient` wrapper (e.g. inside a framework-specific hook).
851
+ *
852
+ * @param inner - The WASM `WebClient` (e.g. the `WasmWebClient` proxy).
853
+ * @param getWasm - Async accessor for the WASM module, used to reach
854
+ * `AccountComponent.compile` at runtime. `getWasmOrThrow` satisfies this.
855
+ * @param client - Optional wrapper with `assertNotTerminated()`; used
856
+ * internally by `MidenClient` and may be omitted by external callers.
857
+ */
858
+ constructor(
859
+ inner: WasmExports.WebClient,
860
+ getWasm: () => Promise<typeof WasmExports>,
861
+ client?: { assertNotTerminated(): void } | null
862
+ );
863
+
864
+ /**
865
+ * Compile MASM source into an AccountComponent.
866
+ *
867
+ * @param options - Component source code, storage slots, and auth options.
868
+ */
869
+ component(options: CompileComponentOptions): Promise<AccountComponent>;
870
+ /**
871
+ * Compile MASM source into a TransactionScript.
872
+ *
873
+ * @param options - Script source code and optional libraries to link.
874
+ */
875
+ txScript(options: CompileTxScriptOptions): Promise<TransactionScript>;
876
+ /**
877
+ * Compile MASM source into a NoteScript.
878
+ *
879
+ * @param options - Script source code and optional libraries to link.
880
+ */
881
+ noteScript(options: CompileNoteScriptOptions): Promise<NoteScript>;
882
+ }
883
+
884
+ export interface TagsResource {
885
+ /**
886
+ * Add a note tag to listen for during sync.
887
+ *
888
+ * @param tag - The numeric note tag to register.
889
+ */
890
+ add(tag: number): Promise<void>;
891
+ /**
892
+ * Remove a note tag so it is no longer tracked during sync.
893
+ *
894
+ * @param tag - The numeric note tag to unregister.
895
+ */
896
+ remove(tag: number): Promise<void>;
897
+ /**
898
+ * List all registered note tags.
899
+ */
900
+ list(): Promise<number[]>;
901
+ }
902
+
903
+ export interface SettingsResource {
904
+ /**
905
+ * Get a setting value by key. Returns `null` if not found.
906
+ *
907
+ * @param key - The setting key.
908
+ */
909
+ get<T = unknown>(key: string): Promise<T | null>;
910
+ /**
911
+ * Set a setting value.
912
+ *
913
+ * @param key - The setting key.
914
+ * @param value - The value to store.
915
+ */
916
+ set(key: string, value: unknown): Promise<void>;
917
+ /**
918
+ * Remove a setting.
919
+ *
920
+ * @param key - The setting key to remove.
921
+ */
922
+ remove(key: string): Promise<void>;
923
+ /**
924
+ * List all setting keys.
925
+ */
926
+ listKeys(): Promise<string[]>;
927
+ }
928
+
929
+ export interface KeystoreResource {
930
+ /** Inserts a secret key into the keystore, associating it with the given account ID. */
931
+ insert(accountId: AccountId, secretKey: AuthSecretKey): Promise<void>;
932
+ /** Retrieves a secret key by its public key commitment. Returns null if not found. */
933
+ get(pubKeyCommitment: Word): Promise<AuthSecretKey | null>;
934
+ /** Removes a key from the keystore by its public key commitment. */
935
+ remove(pubKeyCommitment: Word): Promise<void>;
936
+ /** Returns all public key commitments associated with the given account ID. */
937
+ getCommitments(accountId: AccountId): Promise<Word[]>;
938
+ /** Returns the account ID associated with a public key commitment, or null if not found. */
939
+ getAccountId(pubKeyCommitment: Word): Promise<AccountId | null>;
940
+ }
941
+
942
+ // ════════════════════════════════════════════════════════════════
943
+ // MidenClient
944
+ // ════════════════════════════════════════════════════════════════
945
+
946
+ export declare class MidenClient {
947
+ /** Creates and initializes a new MidenClient. */
948
+ static create(options?: ClientOptions): Promise<MidenClient>;
949
+ /** Creates a client preconfigured for testnet (rpc, prover, note transport, autoSync). */
950
+ static createTestnet(options?: ClientOptions): Promise<MidenClient>;
951
+ /** Creates a client preconfigured for devnet (rpc, prover, note transport, autoSync). */
952
+ static createDevnet(options?: ClientOptions): Promise<MidenClient>;
953
+ /** Creates a mock client for testing. */
954
+ static createMock(options?: MockOptions): Promise<MidenClient>;
955
+ /**
956
+ * Resolves once the WASM module is initialized and safe to use.
957
+ *
958
+ * Idempotent and shared across callers — concurrent invocations await the
959
+ * same in-flight promise, and post-init callers resolve immediately.
960
+ * Primarily useful on the `/lazy` entry (Next.js / Capacitor) where no
961
+ * top-level await runs at import time; harmless on the eager entry.
962
+ */
963
+ static ready(): Promise<void>;
964
+
965
+ readonly accounts: AccountsResource;
966
+ readonly transactions: TransactionsResource;
967
+ readonly notes: NotesResource;
968
+ readonly tags: TagsResource;
969
+ readonly settings: SettingsResource;
970
+ readonly compile: CompilerResource;
971
+ readonly keystore: KeystoreResource;
972
+
973
+ /** Syncs the client state with the Miden node. */
974
+ sync(options?: { timeout?: number }): Promise<SyncSummary>;
975
+ /** Returns the current sync height. */
976
+ getSyncHeight(): Promise<number>;
977
+ /**
978
+ * Resolves once every serialized WASM call that was already on the
979
+ * internal call chain when `waitForIdle()` was called (execute, submit,
980
+ * prove, apply, sync, or account creation) has settled. Use this from
981
+ * callers that need to perform a non-WASM-side action — e.g. clearing
982
+ * an in-memory auth key on wallet lock — after the kernel finishes, so
983
+ * its auth callback doesn't race with the key being cleared. Does NOT
984
+ * wait for calls enqueued after `waitForIdle()` returns.
985
+ *
986
+ * Caveat for `sync`: a `syncState` blocked on its sync lock (Web
987
+ * Locks) has not yet reached the internal chain, so `waitForIdle`
988
+ * does not await it. Other serialized methods are always observed.
989
+ *
990
+ * Returns immediately if nothing was in flight.
991
+ */
992
+ waitForIdle(): Promise<void>;
993
+ /**
994
+ * Returns the raw JS value that the most recent sign-callback invocation
995
+ * threw, or `null` if the last sign call succeeded (or no call has
996
+ * happened yet). Useful for recovering structured metadata (e.g. a
997
+ * `reason: 'locked'` property) that the kernel-level `auth::request`
998
+ * diagnostic would otherwise erase.
999
+ */
1000
+ lastAuthError(): unknown;
1001
+ /** Returns the client-level default prover. */
1002
+ readonly defaultProver: TransactionProver | null;
1003
+ /** Terminates the underlying Web Worker. After this, all method calls throw. */
1004
+ terminate(): void;
1005
+
1006
+ /** Returns the identifier of the underlying store (e.g. IndexedDB database name, file path). */
1007
+ storeIdentifier(): string;
1008
+
1009
+ /** Advances the mock chain by one block. Only available on mock clients. */
1010
+ proveBlock(): void;
1011
+ /** Returns true if this client uses a mock chain. */
1012
+ usesMockChain(): boolean;
1013
+ /** Serializes the mock chain state for snapshot/restore in tests. */
1014
+ serializeMockChain(): Uint8Array;
1015
+ /** Serializes the mock note transport node state. */
1016
+ serializeMockNoteTransportNode(): Uint8Array;
1017
+
1018
+ [Symbol.dispose](): void;
1019
+ [Symbol.asyncDispose](): Promise<void>;
1020
+ }
1021
+
1022
+ // ════════════════════════════════════════════════════════════════
1023
+ // Standalone utilities (tree-shakeable)
1024
+ // ════════════════════════════════════════════════════════════════
1025
+
1026
+ /** Creates a P2ID (Pay-to-ID) note. */
1027
+ export declare function createP2IDNote(
1028
+ options: NoteOptions
1029
+ ): ReturnType<WasmModule["Note"]["createP2IDNote"]>;
1030
+
1031
+ /** Creates a P2IDE (Pay-to-ID with Expiration) note. */
1032
+ export declare function createP2IDENote(
1033
+ options: P2IDEOptions
1034
+ ): ReturnType<WasmModule["Note"]["createP2IDENote"]>;
1035
+
1036
+ /** Builds a swap tag for note matching. Returns a NoteTag (use `.asU32()` for the numeric value). */
1037
+ export declare function buildSwapTag(
1038
+ options: BuildSwapTagOptions
1039
+ ): ReturnType<WasmModule["WebClient"]["buildSwapTag"]>;
1040
+
1041
+ /** Exports the entire contents of an IndexedDB store as a JSON string. */
1042
+ export declare function exportStore(storeName: string): Promise<string>;
1043
+
1044
+ /** Imports store contents from a JSON string, replacing all existing data. */
1045
+ export declare function importStore(
1046
+ storeName: string,
1047
+ storeDump: string
1048
+ ): Promise<void>;
1049
+
1050
+ /** Returns the initialized WASM module. Throws if WASM is unavailable. */
1051
+ export declare function getWasmOrThrow(): Promise<typeof WasmExports>;