@miden-sdk/miden-sdk 0.14.3 → 0.14.5

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.
@@ -84,9 +84,25 @@ export declare const AuthScheme: {
84
84
  };
85
85
 
86
86
  /**
87
- * Union of all values in the AuthScheme const.
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.
88
91
  */
89
- export type AuthSchemeType = (typeof AuthScheme)[keyof typeof AuthScheme];
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;
90
106
 
91
107
  /**
92
108
  * User-friendly note visibility constants.
@@ -921,6 +937,15 @@ export declare class MidenClient {
921
937
  static createDevnet(options?: ClientOptions): Promise<MidenClient>;
922
938
  /** Creates a mock client for testing. */
923
939
  static createMock(options?: MockOptions): Promise<MidenClient>;
940
+ /**
941
+ * Resolves once the WASM module is initialized and safe to use.
942
+ *
943
+ * Idempotent and shared across callers — concurrent invocations await the
944
+ * same in-flight promise, and post-init callers resolve immediately.
945
+ * Primarily useful on the `/lazy` entry (Next.js / Capacitor) where no
946
+ * top-level await runs at import time; harmless on the eager entry.
947
+ */
948
+ static ready(): Promise<void>;
924
949
 
925
950
  readonly accounts: AccountsResource;
926
951
  readonly transactions: TransactionsResource;
@@ -934,6 +959,30 @@ export declare class MidenClient {
934
959
  sync(options?: { timeout?: number }): Promise<SyncSummary>;
935
960
  /** Returns the current sync height. */
936
961
  getSyncHeight(): Promise<number>;
962
+ /**
963
+ * Resolves once every serialized WASM call that was already on the
964
+ * internal call chain when `waitForIdle()` was called (execute, submit,
965
+ * prove, apply, sync, or account creation) has settled. Use this from
966
+ * callers that need to perform a non-WASM-side action — e.g. clearing
967
+ * an in-memory auth key on wallet lock — after the kernel finishes, so
968
+ * its auth callback doesn't race with the key being cleared. Does NOT
969
+ * wait for calls enqueued after `waitForIdle()` returns.
970
+ *
971
+ * Caveat for `sync`: a `syncState` blocked on its sync lock (Web
972
+ * Locks) has not yet reached the internal chain, so `waitForIdle`
973
+ * does not await it. Other serialized methods are always observed.
974
+ *
975
+ * Returns immediately if nothing was in flight.
976
+ */
977
+ waitForIdle(): Promise<void>;
978
+ /**
979
+ * Returns the raw JS value that the most recent sign-callback invocation
980
+ * threw, or `null` if the last sign call succeeded (or no call has
981
+ * happened yet). Useful for recovering structured metadata (e.g. a
982
+ * `reason: 'locked'` property) that the kernel-level `auth::request`
983
+ * diagnostic would otherwise erase.
984
+ */
985
+ lastAuthError(): unknown;
937
986
  /** Returns the client-level default prover. */
938
987
  readonly defaultProver: TransactionProver | null;
939
988
  /** Terminates the underlying Web Worker. After this, all method calls throw. */
Binary file
@@ -121,6 +121,14 @@ export class AccountArray {
121
121
  length(): number;
122
122
  constructor(elements?: Account[] | null);
123
123
  push(element: Account): void;
124
+ /**
125
+ * Replace the element at `index`. Borrows + clones the input
126
+ * (mirrors `push`), so the caller's JS handle remains valid
127
+ * after the call. Without this borrow, passing `elem` by
128
+ * value would move the underlying Rust value out of the
129
+ * caller's JS handle and any subsequent method on it would
130
+ * panic with `"null pointer passed to rust"`.
131
+ */
124
132
  replaceAt(index: number, elem: Account): void;
125
133
  }
126
134
 
@@ -445,6 +453,14 @@ export class AccountIdArray {
445
453
  length(): number;
446
454
  constructor(elements?: AccountId[] | null);
447
455
  push(element: AccountId): void;
456
+ /**
457
+ * Replace the element at `index`. Borrows + clones the input
458
+ * (mirrors `push`), so the caller's JS handle remains valid
459
+ * after the call. Without this borrow, passing `elem` by
460
+ * value would move the underlying Rust value out of the
461
+ * caller's JS handle and any subsequent method on it would
462
+ * panic with `"null pointer passed to rust"`.
463
+ */
448
464
  replaceAt(index: number, elem: AccountId): void;
449
465
  }
450
466
 
@@ -1005,6 +1021,15 @@ export class BlockHeader {
1005
1021
  * Returns the commitment to the block contents.
1006
1022
  */
1007
1023
  commitment(): Word;
1024
+ /**
1025
+ * Returns the account ID of the fungible faucet whose assets are accepted as the native
1026
+ * asset of the blockchain (i.e. the asset used for paying transaction verification fees).
1027
+ *
1028
+ * This is stored on-chain as part of the block's fee parameters, which means consumers can
1029
+ * discover the native faucet by reading any block header rather than hardcoding it per
1030
+ * network.
1031
+ */
1032
+ nativeAssetId(): AccountId;
1008
1033
  /**
1009
1034
  * Returns the note commitment root.
1010
1035
  */
@@ -1313,6 +1338,14 @@ export class FeltArray {
1313
1338
  length(): number;
1314
1339
  constructor(elements?: Felt[] | null);
1315
1340
  push(element: Felt): void;
1341
+ /**
1342
+ * Replace the element at `index`. Borrows + clones the input
1343
+ * (mirrors `push`), so the caller's JS handle remains valid
1344
+ * after the call. Without this borrow, passing `elem` by
1345
+ * value would move the underlying Rust value out of the
1346
+ * caller's JS handle and any subsequent method on it would
1347
+ * panic with `"null pointer passed to rust"`.
1348
+ */
1316
1349
  replaceAt(index: number, elem: Felt): void;
1317
1350
  }
1318
1351
 
@@ -1453,6 +1486,14 @@ export class ForeignAccountArray {
1453
1486
  length(): number;
1454
1487
  constructor(elements?: ForeignAccount[] | null);
1455
1488
  push(element: ForeignAccount): void;
1489
+ /**
1490
+ * Replace the element at `index`. Borrows + clones the input
1491
+ * (mirrors `push`), so the caller's JS handle remains valid
1492
+ * after the call. Without this borrow, passing `elem` by
1493
+ * value would move the underlying Rust value out of the
1494
+ * caller's JS handle and any subsequent method on it would
1495
+ * panic with `"null pointer passed to rust"`.
1496
+ */
1456
1497
  replaceAt(index: number, elem: ForeignAccount): void;
1457
1498
  }
1458
1499
 
@@ -2103,6 +2144,14 @@ export class NoteAndArgsArray {
2103
2144
  length(): number;
2104
2145
  constructor(elements?: NoteAndArgs[] | null);
2105
2146
  push(element: NoteAndArgs): void;
2147
+ /**
2148
+ * Replace the element at `index`. Borrows + clones the input
2149
+ * (mirrors `push`), so the caller's JS handle remains valid
2150
+ * after the call. Without this borrow, passing `elem` by
2151
+ * value would move the underlying Rust value out of the
2152
+ * caller's JS handle and any subsequent method on it would
2153
+ * panic with `"null pointer passed to rust"`.
2154
+ */
2106
2155
  replaceAt(index: number, elem: NoteAndArgs): void;
2107
2156
  }
2108
2157
 
@@ -2124,6 +2173,14 @@ export class NoteArray {
2124
2173
  length(): number;
2125
2174
  constructor(elements?: Note[] | null);
2126
2175
  push(element: Note): void;
2176
+ /**
2177
+ * Replace the element at `index`. Borrows + clones the input
2178
+ * (mirrors `push`), so the caller's JS handle remains valid
2179
+ * after the call. Without this borrow, passing `elem` by
2180
+ * value would move the underlying Rust value out of the
2181
+ * caller's JS handle and any subsequent method on it would
2182
+ * panic with `"null pointer passed to rust"`.
2183
+ */
2127
2184
  replaceAt(index: number, elem: Note): void;
2128
2185
  }
2129
2186
 
@@ -2362,6 +2419,14 @@ export class NoteDetailsAndTagArray {
2362
2419
  length(): number;
2363
2420
  constructor(elements?: NoteDetailsAndTag[] | null);
2364
2421
  push(element: NoteDetailsAndTag): void;
2422
+ /**
2423
+ * Replace the element at `index`. Borrows + clones the input
2424
+ * (mirrors `push`), so the caller's JS handle remains valid
2425
+ * after the call. Without this borrow, passing `elem` by
2426
+ * value would move the underlying Rust value out of the
2427
+ * caller's JS handle and any subsequent method on it would
2428
+ * panic with `"null pointer passed to rust"`.
2429
+ */
2365
2430
  replaceAt(index: number, elem: NoteDetailsAndTag): void;
2366
2431
  }
2367
2432
 
@@ -2588,6 +2653,14 @@ export class NoteIdAndArgsArray {
2588
2653
  length(): number;
2589
2654
  constructor(elements?: NoteIdAndArgs[] | null);
2590
2655
  push(element: NoteIdAndArgs): void;
2656
+ /**
2657
+ * Replace the element at `index`. Borrows + clones the input
2658
+ * (mirrors `push`), so the caller's JS handle remains valid
2659
+ * after the call. Without this borrow, passing `elem` by
2660
+ * value would move the underlying Rust value out of the
2661
+ * caller's JS handle and any subsequent method on it would
2662
+ * panic with `"null pointer passed to rust"`.
2663
+ */
2591
2664
  replaceAt(index: number, elem: NoteIdAndArgs): void;
2592
2665
  }
2593
2666
 
@@ -2722,6 +2795,14 @@ export class NoteRecipientArray {
2722
2795
  length(): number;
2723
2796
  constructor(elements?: NoteRecipient[] | null);
2724
2797
  push(element: NoteRecipient): void;
2798
+ /**
2799
+ * Replace the element at `index`. Borrows + clones the input
2800
+ * (mirrors `push`), so the caller's JS handle remains valid
2801
+ * after the call. Without this borrow, passing `elem` by
2802
+ * value would move the underlying Rust value out of the
2803
+ * caller's JS handle and any subsequent method on it would
2804
+ * panic with `"null pointer passed to rust"`.
2805
+ */
2725
2806
  replaceAt(index: number, elem: NoteRecipient): void;
2726
2807
  }
2727
2808
 
@@ -2943,6 +3024,14 @@ export class OutputNoteArray {
2943
3024
  length(): number;
2944
3025
  constructor(elements?: OutputNote[] | null);
2945
3026
  push(element: OutputNote): void;
3027
+ /**
3028
+ * Replace the element at `index`. Borrows + clones the input
3029
+ * (mirrors `push`), so the caller's JS handle remains valid
3030
+ * after the call. Without this borrow, passing `elem` by
3031
+ * value would move the underlying Rust value out of the
3032
+ * caller's JS handle and any subsequent method on it would
3033
+ * panic with `"null pointer passed to rust"`.
3034
+ */
2946
3035
  replaceAt(index: number, elem: OutputNote): void;
2947
3036
  }
2948
3037
 
@@ -3609,6 +3698,14 @@ export class StorageSlotArray {
3609
3698
  length(): number;
3610
3699
  constructor(elements?: StorageSlot[] | null);
3611
3700
  push(element: StorageSlot): void;
3701
+ /**
3702
+ * Replace the element at `index`. Borrows + clones the input
3703
+ * (mirrors `push`), so the caller's JS handle remains valid
3704
+ * after the call. Without this borrow, passing `elem` by
3705
+ * value would move the underlying Rust value out of the
3706
+ * caller's JS handle and any subsequent method on it would
3707
+ * panic with `"null pointer passed to rust"`.
3708
+ */
3612
3709
  replaceAt(index: number, elem: StorageSlot): void;
3613
3710
  }
3614
3711
 
@@ -4056,6 +4153,14 @@ export class TransactionScriptInputPairArray {
4056
4153
  length(): number;
4057
4154
  constructor(elements?: TransactionScriptInputPair[] | null);
4058
4155
  push(element: TransactionScriptInputPair): void;
4156
+ /**
4157
+ * Replace the element at `index`. Borrows + clones the input
4158
+ * (mirrors `push`), so the caller's JS handle remains valid
4159
+ * after the call. Without this borrow, passing `elem` by
4160
+ * value would move the underlying Rust value out of the
4161
+ * caller's JS handle and any subsequent method on it would
4162
+ * panic with `"null pointer passed to rust"`.
4163
+ */
4059
4164
  replaceAt(index: number, elem: TransactionScriptInputPair): void;
4060
4165
  }
4061
4166
 
@@ -4316,6 +4421,31 @@ export class WebClient {
4316
4421
  importNoteFile(note_file: NoteFile): Promise<NoteId>;
4317
4422
  importPublicAccountFromSeed(init_seed: Uint8Array, mutable: boolean, auth_scheme: AuthScheme): Promise<Account>;
4318
4423
  insertAccountAddress(account_id: AccountId, address: Address): Promise<void>;
4424
+ /**
4425
+ * Returns the raw JS value that the most recent sign-callback invocation
4426
+ * threw, or `null` if the last sign call succeeded (or no call has
4427
+ * happened yet).
4428
+ *
4429
+ * Combined with the serialized-call discipline enforced at the JS
4430
+ * `WebClient` wrapper, this lets a caller that caught a failed
4431
+ * `executeTransaction` / `submitNewTransaction` recover the original
4432
+ * JS error the signing callback threw — preserving any structured
4433
+ * metadata (e.g. a `reason: 'locked'` property) that the kernel-level
4434
+ * `auth::request` diagnostic would otherwise have erased.
4435
+ *
4436
+ * # Usage (TS)
4437
+ * ```ts
4438
+ * try {
4439
+ * await client.submitNewTransaction(acc, req);
4440
+ * } catch (e) {
4441
+ * const authErr = client.lastAuthError();
4442
+ * if (authErr && authErr.reason === 'locked') {
4443
+ * // wait for unlock, then retry
4444
+ * }
4445
+ * }
4446
+ * ```
4447
+ */
4448
+ lastAuthError(): any;
4319
4449
  /**
4320
4450
  * Returns all the existing setting keys from the store.
4321
4451
  */
@@ -4338,10 +4468,20 @@ export class WebClient {
4338
4468
  newWallet(storage_mode: AccountStorageMode, mutable: boolean, auth_scheme: AuthScheme, init_seed?: Uint8Array | null): Promise<Account>;
4339
4469
  proveBlock(): void;
4340
4470
  /**
4341
- * Generates a transaction proof using either the provided prover or the client's default
4342
- * prover if none is supplied.
4471
+ * Generates a transaction proof using the client's default (local) prover.
4343
4472
  */
4344
- proveTransaction(transaction_result: TransactionResult, prover?: TransactionProver | null): Promise<ProvenTransaction>;
4473
+ proveTransaction(transaction_result: TransactionResult): Promise<ProvenTransaction>;
4474
+ /**
4475
+ * Generates a transaction proof using the provided prover.
4476
+ *
4477
+ * Takes the prover by reference so the JS-side handle is NOT consumed
4478
+ * by wasm-bindgen. Taking `TransactionProver` by value would transfer
4479
+ * ownership on each call, invalidating the JS object's internal WASM
4480
+ * handle; after one use, subsequent calls from JS would pass a dangling
4481
+ * handle that wasm-bindgen interprets as `None`, silently falling back
4482
+ * to the local prover.
4483
+ */
4484
+ proveTransactionWithProver(transaction_result: TransactionResult, prover: TransactionProver): Promise<ProvenTransaction>;
4345
4485
  /**
4346
4486
  * Prunes historical account states for the specified account up to the given nonce.
4347
4487
  *
package/dist/eager.js ADDED
@@ -0,0 +1,35 @@
1
+ import { getWasmOrThrow } from './index.js';
2
+ export { AccountArray, AccountIdArray, AccountType, AuthScheme, CompilerResource, FeltArray, ForeignAccountArray, Linking, MidenArrays, MidenClient, MockWasmWebClient, NoteAndArgsArray, NoteArray, NoteIdAndArgsArray, NoteRecipientArray, NoteVisibility, OutputNoteArray, StorageMode, StorageSlotArray, TransactionScriptInputPairArray, WasmWebClient, buildSwapTag, createP2IDENote, createP2IDNote, resolveAuthScheme } from './index.js';
3
+ export { Account, AccountBuilder, AccountBuilderResult, AccountCode, AccountComponent, AccountComponentCode, AccountDelta, AccountFile, AccountHeader, AccountId, AccountInterface, AccountProof, AccountReader, AccountStatus, AccountStorage, AccountStorageDelta, AccountStorageMode, AccountStorageRequirements, AccountVaultDelta, Address, AdviceInputs, AdviceMap, AssetVault, AuthFalcon512RpoMultisigConfig, AuthSecretKey, BasicFungibleFaucetComponent, BlockHeader, CodeBuilder, CommittedNote, ConsumableNoteRecord, Endpoint, ExecutedTransaction, Felt, FetchedAccount, FetchedNote, FlattenedU8Vec, ForeignAccount, FungibleAsset, FungibleAssetDelta, FungibleAssetDeltaItem, GetProceduresResultItem, InputNote, InputNoteRecord, InputNoteState, InputNotes, IntoUnderlyingByteSource, IntoUnderlyingSink, IntoUnderlyingSource, JsAccountUpdate, JsStateSyncUpdate, JsStorageMapEntry, JsStorageSlot, JsVaultAsset, Library, MerklePath, NetworkId, NetworkType, Note, NoteAndArgs, NoteAssets, NoteAttachment, NoteAttachmentKind, NoteAttachmentScheme, NoteConsumability, NoteConsumptionStatus, NoteDetails, NoteDetailsAndTag, NoteDetailsAndTagArray, NoteExecutionHint, NoteExportFormat, NoteFile, NoteFilter, NoteFilterTypes, NoteHeader, NoteId, NoteIdAndArgs, NoteInclusionProof, NoteLocation, NoteMetadata, NoteRecipient, NoteScript, NoteStorage, NoteSyncBlock, NoteSyncInfo, NoteTag, NoteType, OutputNote, OutputNoteRecord, OutputNoteState, OutputNotes, Package, PartialNote, Poseidon2, ProcedureThreshold, Program, ProvenTransaction, PublicKey, RpcClient, Rpo256, SerializedInputNoteData, SerializedOutputNoteData, SerializedTransactionData, Signature, SigningInputs, SigningInputsType, SlotAndKeys, SparseMerklePath, StorageMap, StorageMapEntry, StorageMapInfo, StorageMapUpdate, StorageSlot, SyncSummary, TestUtils, TokenSymbol, TransactionArgs, TransactionFilter, TransactionId, TransactionProver, TransactionRecord, TransactionRequest, TransactionRequestBuilder, TransactionResult, TransactionScript, TransactionScriptInputPair, TransactionStatus, TransactionStoreUpdate, TransactionSummary, WebClient, WebKeystoreApi, Word, createAuthFalcon512RpoMultisig, exportStore, importStore, initSync, setupLogging } from './Cargo-M3382VZc.js';
4
+ import './wasm.js';
5
+
6
+ // Eager entry point for @miden-sdk/miden-sdk.
7
+ //
8
+ // Awaits WASM initialization at module top level, so importing this module
9
+ // guarantees that any wasm-bindgen constructor (`new RpcClient(...)`,
10
+ // `AccountId.fromHex(...)`, `TransactionProver.newRemoteProver(...)`, etc.)
11
+ // is safe to call synchronously on the next line. No explicit
12
+ // `await MidenClient.ready()` / `isReady` gate is required.
13
+ //
14
+ // This is the default entry (`@miden-sdk/miden-sdk` → `./dist/eager.js`).
15
+ //
16
+ // When NOT to use this entry:
17
+ // - **Capacitor mobile apps** (Miden Wallet iOS/Android): Capacitor's
18
+ // `capacitor://localhost` scheme handler interacts poorly with top-level
19
+ // await in the main WKWebView. Verified empirically: TLA in a Capacitor
20
+ // host WKWebView hangs module evaluation indefinitely, while the same
21
+ // TLA in the dApp-browser WKWebView (vanilla HTTPS) resolves in <100ms.
22
+ // - **Next.js / SSR**: TLA blocks server-side module evaluation.
23
+ // - **Framework adapters (@miden-sdk/react, etc.)**: they manage readiness
24
+ // via their own state machine (e.g. `isReady`) and should not impose
25
+ // TLA on consumer bundles.
26
+ //
27
+ // For those contexts, import from `@miden-sdk/miden-sdk/lazy` — identical
28
+ // API surface, no top-level await, callers are responsible for awaiting
29
+ // `MidenClient.ready()` (or the equivalent) before touching wasm-bindgen
30
+ // types.
31
+
32
+ await getWasmOrThrow();
33
+
34
+ export { getWasmOrThrow };
35
+ //# sourceMappingURL=eager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"eager.js","sources":["../js/eager.js"],"sourcesContent":["// Eager entry point for @miden-sdk/miden-sdk.\n//\n// Awaits WASM initialization at module top level, so importing this module\n// guarantees that any wasm-bindgen constructor (`new RpcClient(...)`,\n// `AccountId.fromHex(...)`, `TransactionProver.newRemoteProver(...)`, etc.)\n// is safe to call synchronously on the next line. No explicit\n// `await MidenClient.ready()` / `isReady` gate is required.\n//\n// This is the default entry (`@miden-sdk/miden-sdk` → `./dist/eager.js`).\n//\n// When NOT to use this entry:\n// - **Capacitor mobile apps** (Miden Wallet iOS/Android): Capacitor's\n// `capacitor://localhost` scheme handler interacts poorly with top-level\n// await in the main WKWebView. Verified empirically: TLA in a Capacitor\n// host WKWebView hangs module evaluation indefinitely, while the same\n// TLA in the dApp-browser WKWebView (vanilla HTTPS) resolves in <100ms.\n// - **Next.js / SSR**: TLA blocks server-side module evaluation.\n// - **Framework adapters (@miden-sdk/react, etc.)**: they manage readiness\n// via their own state machine (e.g. `isReady`) and should not impose\n// TLA on consumer bundles.\n//\n// For those contexts, import from `@miden-sdk/miden-sdk/lazy` — identical\n// API surface, no top-level await, callers are responsible for awaiting\n// `MidenClient.ready()` (or the equivalent) before touching wasm-bindgen\n// types.\nimport { getWasmOrThrow } from \"./index.js\";\n\nawait getWasmOrThrow();\n\nexport * from \"./index.js\";\n"],"names":[],"mappings":";;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA,MAAM,cAAc,EAAE;;;;"}
package/dist/index.d.ts CHANGED
@@ -4,6 +4,13 @@ export * from "./crates/miden_client_web";
4
4
  // Re-export all simplified API types
5
5
  export * from "./api-types";
6
6
 
7
+ // Explicit re-export to shadow the wasm-bindgen `AuthScheme` enum declared
8
+ // in `./crates/miden_client_web` with the user-facing string constant plus
9
+ // merged string-union type from `./api-types`. Without this, `export *`
10
+ // makes the name ambiguous and TypeScript resolves to the crates enum,
11
+ // breaking `AuthScheme.Falcon` / `AuthScheme.ECDSA` lookups.
12
+ export { AuthScheme, resolveAuthScheme } from "./api-types";
13
+
7
14
  // Import types needed for the @internal class declarations below
8
15
  import type {
9
16
  WebClient as WasmWebClientBase,