@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.
- package/LICENSE +21 -0
- package/README.md +148 -18
- package/dist/mt/Cargo-DKB2aRX-.js +25826 -0
- package/dist/mt/Cargo-DKB2aRX-.js.map +1 -0
- package/dist/{api-types.d.ts → mt/api-types.d.ts} +18 -3
- package/dist/mt/assets/miden_client_web.wasm +0 -0
- package/dist/mt/crates/miden_client_web.d.ts +4726 -0
- package/dist/{docs-entry.d.ts → mt/docs-entry.d.ts} +2 -2
- package/dist/mt/eager.js +35 -0
- package/dist/mt/eager.js.map +1 -0
- package/dist/{index.d.ts → mt/index.d.ts} +9 -7
- package/dist/mt/index.js +3371 -0
- package/dist/mt/index.js.map +1 -0
- package/dist/{wasm.js → mt/wasm.js} +1 -1
- package/dist/mt/wasm.js.map +1 -0
- package/dist/mt/workerHelpers.js +28 -0
- package/dist/mt/workers/Cargo-DKB2aRX--C6T4l3AF.js +25827 -0
- package/dist/mt/workers/Cargo-DKB2aRX--C6T4l3AF.js.map +1 -0
- package/dist/mt/workers/assets/miden_client_web.wasm +0 -0
- package/dist/mt/workers/web-client-methods-worker.js +26560 -0
- package/dist/mt/workers/web-client-methods-worker.js.map +1 -0
- package/dist/{workers → mt/workers}/web-client-methods-worker.module.js +17 -1
- package/dist/mt/workers/web-client-methods-worker.module.js.map +1 -0
- package/dist/mt/workers/workerHelpers.js +28 -0
- package/dist/{Cargo-M3382VZc.js → st/Cargo-jOTNoFyS.js} +6714 -5926
- package/dist/st/Cargo-jOTNoFyS.js.map +1 -0
- package/dist/st/api-types.d.ts +1051 -0
- package/dist/{workers → st}/assets/miden_client_web.wasm +0 -0
- package/dist/{crates → st/crates}/miden_client_web.d.ts +31 -0
- package/dist/st/docs-entry.d.ts +35 -0
- package/dist/{eager.js → st/eager.js} +1 -1
- package/dist/st/eager.js.map +1 -0
- package/dist/st/index.d.ts +89 -0
- package/dist/{index.js → st/index.js} +126 -13
- package/dist/st/index.js.map +1 -0
- package/dist/st/wasm.js +23 -0
- package/dist/st/wasm.js.map +1 -0
- package/dist/{workers/Cargo-M3382VZc-Dfw4tXwh.js → st/workers/Cargo-jOTNoFyS-DRTcF6wf.js} +6714 -5926
- package/dist/st/workers/Cargo-jOTNoFyS-DRTcF6wf.js.map +1 -0
- package/dist/{assets → st/workers/assets}/miden_client_web.wasm +0 -0
- package/dist/{workers → st/workers}/web-client-methods-worker.js +6731 -5926
- package/dist/st/workers/web-client-methods-worker.js.map +1 -0
- package/dist/st/workers/web-client-methods-worker.module.js +571 -0
- package/dist/st/workers/web-client-methods-worker.module.js.map +1 -0
- package/lazy/package.json +4 -0
- package/mt/lazy/package.json +4 -0
- package/mt/package.json +4 -0
- package/package.json +66 -44
- package/dist/Cargo-M3382VZc.js.map +0 -1
- package/dist/eager.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/wasm.js.map +0 -1
- package/dist/workers/Cargo-M3382VZc-Dfw4tXwh.js.map +0 -1
- package/dist/workers/web-client-methods-worker.js.map +0 -1
- package/dist/workers/web-client-methods-worker.module.js.map +0 -1
|
Binary file
|
|
@@ -3885,6 +3885,28 @@ export class TransactionProver {
|
|
|
3885
3885
|
* Returns the endpoint if this is a remote prover.
|
|
3886
3886
|
*/
|
|
3887
3887
|
endpoint(): string | undefined;
|
|
3888
|
+
/**
|
|
3889
|
+
* Creates a prover that delegates `prove()` to a JavaScript callback.
|
|
3890
|
+
*
|
|
3891
|
+
* The callback receives the serialized [`TransactionInputs`] as a
|
|
3892
|
+
* `Uint8Array` and must return a `Promise<Uint8Array>` resolving to a
|
|
3893
|
+
* serialized [`ProvenTransaction`] (same encoding the gRPC remote
|
|
3894
|
+
* prover uses: `tx_inputs.to_bytes()` in, `ProvenTransaction::read_from_bytes`
|
|
3895
|
+
* out).
|
|
3896
|
+
*
|
|
3897
|
+
* Use case: routing prove to a native iOS / Android plugin
|
|
3898
|
+
* (`@miden/native-prover`) so mobile builds skip WASM prove entirely
|
|
3899
|
+
* — `WKWebView` can't be made cross-origin-isolated reliably and the
|
|
3900
|
+
* MT WASM bundle can't instantiate without `SharedArrayBuffer`, so the
|
|
3901
|
+
* host wraps a native Rust prover (built with the same `miden_tx`
|
|
3902
|
+
* crate) and exposes a JS-shaped callback over the Capacitor bridge.
|
|
3903
|
+
*
|
|
3904
|
+
* The SDK does NOT serialize the prover for persistence across
|
|
3905
|
+
* reloads (unlike `newRemoteProver`), since the callback is a
|
|
3906
|
+
* runtime JS reference. Hosts must recreate the prover on every
|
|
3907
|
+
* page load.
|
|
3908
|
+
*/
|
|
3909
|
+
static newCallbackProver(callback: Function): TransactionProver;
|
|
3888
3910
|
/**
|
|
3889
3911
|
* Creates a prover that uses the local proving backend.
|
|
3890
3912
|
*/
|
|
@@ -4651,6 +4673,15 @@ export { exportStore2 as exportStore }
|
|
|
4651
4673
|
*/
|
|
4652
4674
|
export function importStore(store_name: string, store_dump: string): Promise<void>;
|
|
4653
4675
|
|
|
4676
|
+
/**
|
|
4677
|
+
* Single-threaded version of `parallel_sum_bench` for direct comparison.
|
|
4678
|
+
* Same workload, plain `iter()` — bypasses rayon entirely. Needs to live
|
|
4679
|
+
* on the WASM side rather than be reimplemented in JS so the workload is
|
|
4680
|
+
* bit-for-bit identical to `parallel_sum_bench` (same libm, same FP
|
|
4681
|
+
* determinism, same constant-folding resistance).
|
|
4682
|
+
*/
|
|
4683
|
+
export function sequentialSumBench(n: bigint): bigint;
|
|
4684
|
+
|
|
4654
4685
|
/**
|
|
4655
4686
|
* Initializes the `tracing` subscriber that routes Rust log output to the
|
|
4656
4687
|
* browser console via `console.log` / `console.warn` / `console.error`.
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeDoc entry point — curated subset of the public API.
|
|
3
|
+
* Only types listed here (or transitively referenced) appear in generated docs.
|
|
4
|
+
* Runtime consumers should import from index.d.ts, not this file.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
// Curated WASM re-exports: only types referenced in the public API
|
|
8
|
+
export {
|
|
9
|
+
Account,
|
|
10
|
+
AccountCode,
|
|
11
|
+
AccountFile,
|
|
12
|
+
AccountHeader,
|
|
13
|
+
AccountId,
|
|
14
|
+
AccountStorage,
|
|
15
|
+
AssetVault,
|
|
16
|
+
Felt,
|
|
17
|
+
InputNoteRecord,
|
|
18
|
+
Note,
|
|
19
|
+
NoteExportFormat,
|
|
20
|
+
NoteFile,
|
|
21
|
+
NoteId,
|
|
22
|
+
NoteTag,
|
|
23
|
+
RawOutputNote,
|
|
24
|
+
OutputNoteRecord,
|
|
25
|
+
SyncSummary,
|
|
26
|
+
TransactionId,
|
|
27
|
+
TransactionProver,
|
|
28
|
+
TransactionRecord,
|
|
29
|
+
TransactionRequest,
|
|
30
|
+
TransactionSummary,
|
|
31
|
+
Word,
|
|
32
|
+
} from "./crates/miden_client_web.js";
|
|
33
|
+
|
|
34
|
+
// All simplified API types
|
|
35
|
+
export * from "./api-types.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getWasmOrThrow } from './index.js';
|
|
2
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-
|
|
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, sequentialSumBench, setupLogging } from './Cargo-jOTNoFyS.js';
|
|
4
4
|
import './wasm.js';
|
|
5
5
|
|
|
6
6
|
// Eager entry point for @miden-sdk/miden-sdk.
|
|
@@ -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;;;;"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// Re-export everything from the WASM module
|
|
2
|
+
export * from "./crates/miden_client_web.js";
|
|
3
|
+
|
|
4
|
+
// Re-export all simplified API types
|
|
5
|
+
export * from "./api-types.js";
|
|
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.js";
|
|
13
|
+
|
|
14
|
+
// Import types needed for the @internal class declarations below
|
|
15
|
+
import type {
|
|
16
|
+
WebClient as WasmWebClientBase,
|
|
17
|
+
SyncSummary,
|
|
18
|
+
} from "./crates/miden_client_web.js";
|
|
19
|
+
import type {
|
|
20
|
+
GetKeyCallback,
|
|
21
|
+
InsertKeyCallback,
|
|
22
|
+
SignCallback,
|
|
23
|
+
} from "./api-types.js";
|
|
24
|
+
|
|
25
|
+
export type LogLevel =
|
|
26
|
+
| "error"
|
|
27
|
+
| "warn"
|
|
28
|
+
| "info"
|
|
29
|
+
| "debug"
|
|
30
|
+
| "trace"
|
|
31
|
+
| "off"
|
|
32
|
+
| "none";
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Initializes the tracing subscriber that routes Rust log output to the
|
|
36
|
+
* browser console. Call once per thread (main thread / Web Worker).
|
|
37
|
+
* Subsequent calls on the same thread are harmless no-ops.
|
|
38
|
+
*
|
|
39
|
+
* @param logLevel - The maximum log level to display.
|
|
40
|
+
*/
|
|
41
|
+
export declare function setupLogging(logLevel: LogLevel): void;
|
|
42
|
+
|
|
43
|
+
// ════════════════════════════════════════════════════════════════
|
|
44
|
+
// Internal exports (not public API — for tests and advanced usage)
|
|
45
|
+
// ════════════════════════════════════════════════════════════════
|
|
46
|
+
|
|
47
|
+
/** @internal Low-level WebClient wrapper. Use MidenClient instead. */
|
|
48
|
+
export declare class WasmWebClient extends WasmWebClientBase {
|
|
49
|
+
static createClient(
|
|
50
|
+
rpcUrl?: string,
|
|
51
|
+
noteTransportUrl?: string,
|
|
52
|
+
seed?: Uint8Array,
|
|
53
|
+
storeName?: string,
|
|
54
|
+
logLevel?: LogLevel,
|
|
55
|
+
useWorker?: boolean
|
|
56
|
+
): Promise<WasmWebClient>;
|
|
57
|
+
|
|
58
|
+
static createClientWithExternalKeystore(
|
|
59
|
+
rpcUrl?: string,
|
|
60
|
+
noteTransportUrl?: string,
|
|
61
|
+
seed?: Uint8Array,
|
|
62
|
+
storeName?: string,
|
|
63
|
+
getKeyCb?: GetKeyCallback,
|
|
64
|
+
insertKeyCb?: InsertKeyCallback,
|
|
65
|
+
signCb?: SignCallback,
|
|
66
|
+
logLevel?: LogLevel,
|
|
67
|
+
useWorker?: boolean
|
|
68
|
+
): Promise<WasmWebClient>;
|
|
69
|
+
|
|
70
|
+
syncState(): Promise<SyncSummary>;
|
|
71
|
+
syncStateWithTimeout(timeoutMs: number): Promise<SyncSummary>;
|
|
72
|
+
setSignCb(signCb: SignCallback | null | undefined): void;
|
|
73
|
+
onStateChanged(callback: (event: any) => void): (() => void) | undefined;
|
|
74
|
+
terminate(): void;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** @internal Low-level MockWebClient wrapper. Use MidenClient.createMock() instead. */
|
|
78
|
+
export declare class MockWasmWebClient extends WasmWebClient {
|
|
79
|
+
static createClient(
|
|
80
|
+
serializedMockChain?: Uint8Array,
|
|
81
|
+
serializedMockNoteTransportNode?: Uint8Array,
|
|
82
|
+
seed?: Uint8Array,
|
|
83
|
+
logLevel?: LogLevel
|
|
84
|
+
): Promise<MockWasmWebClient>;
|
|
85
|
+
|
|
86
|
+
proveBlock(): void;
|
|
87
|
+
serializeMockChain(): Uint8Array;
|
|
88
|
+
serializeMockNoteTransportNode(): Uint8Array;
|
|
89
|
+
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import loadWasm from './wasm.js';
|
|
2
|
-
import { AccountArray as AccountArray$1, AccountIdArray as AccountIdArray$1, FeltArray as FeltArray$1, ForeignAccountArray as ForeignAccountArray$1, NoteAndArgsArray as NoteAndArgsArray$1, NoteArray as NoteArray$1, NoteIdAndArgsArray as NoteIdAndArgsArray$1, NoteRecipientArray as NoteRecipientArray$1, OutputNoteArray as OutputNoteArray$1, StorageSlotArray as StorageSlotArray$1, TransactionScriptInputPairArray as TransactionScriptInputPairArray$1 } from './Cargo-
|
|
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-
|
|
2
|
+
import { AccountArray as AccountArray$1, AccountIdArray as AccountIdArray$1, FeltArray as FeltArray$1, ForeignAccountArray as ForeignAccountArray$1, NoteAndArgsArray as NoteAndArgsArray$1, NoteArray as NoteArray$1, NoteIdAndArgsArray as NoteIdAndArgsArray$1, NoteRecipientArray as NoteRecipientArray$1, OutputNoteArray as OutputNoteArray$1, StorageSlotArray as StorageSlotArray$1, TransactionScriptInputPairArray as TransactionScriptInputPairArray$1 } from './Cargo-jOTNoFyS.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, sequentialSumBench, setupLogging } from './Cargo-jOTNoFyS.js';
|
|
4
4
|
|
|
5
5
|
const WorkerAction = Object.freeze({
|
|
6
6
|
INIT: "init",
|
|
7
7
|
INIT_MOCK: "initMock",
|
|
8
|
+
INIT_THREAD_POOL: "initThreadPool",
|
|
8
9
|
CALL_METHOD: "callMethod",
|
|
9
10
|
EXECUTE_CALLBACK: "executeCallback",
|
|
10
11
|
});
|
|
@@ -109,6 +110,7 @@ async function acquireSyncLock(dbId, timeoutMs = 0) {
|
|
|
109
110
|
}
|
|
110
111
|
|
|
111
112
|
const onResult = (result) => {
|
|
113
|
+
/* v8 ignore next 1 -- timeoutId only set when timeoutMs>0 AND another sync is in progress; combo rare in tests */
|
|
112
114
|
if (timeoutId) clearTimeout(timeoutId);
|
|
113
115
|
resolve({ acquired: false, coalescedResult: result });
|
|
114
116
|
};
|
|
@@ -154,6 +156,7 @@ async function acquireSyncLock(dbId, timeoutMs = 0) {
|
|
|
154
156
|
|
|
155
157
|
navigator.locks
|
|
156
158
|
.request(lockName, { mode: "exclusive" }, async () => {
|
|
159
|
+
/* v8 ignore next 3 -- race: lock granted after timeout or newer generation */
|
|
157
160
|
if (timedOut || state.syncGeneration !== currentGeneration) {
|
|
158
161
|
return;
|
|
159
162
|
}
|
|
@@ -166,6 +169,9 @@ async function acquireSyncLock(dbId, timeoutMs = 0) {
|
|
|
166
169
|
});
|
|
167
170
|
})
|
|
168
171
|
.catch((err) => {
|
|
172
|
+
/* v8 ignore next 5 -- catch path requires Web Locks rejection combined with
|
|
173
|
+
optional timeout; tested via "rejects when Web Locks request rejects" but
|
|
174
|
+
the timeoutId-set branch needs Web Locks + timeout simultaneously */
|
|
169
175
|
if (timeoutId) clearTimeout(timeoutId);
|
|
170
176
|
if (state.syncGeneration === currentGeneration) {
|
|
171
177
|
state.inProgress = false;
|
|
@@ -1553,6 +1559,52 @@ class MidenClient {
|
|
|
1553
1559
|
this.keystore = new KeystoreResource(inner, this);
|
|
1554
1560
|
}
|
|
1555
1561
|
|
|
1562
|
+
/**
|
|
1563
|
+
* Escape hatch: runs `fn` with exclusive access to the proxied JS
|
|
1564
|
+
* WebClient that backs this MidenClient.
|
|
1565
|
+
*
|
|
1566
|
+
* The proxy forwards missing properties to the underlying wasm-bindgen
|
|
1567
|
+
* `WebClient`, so `fn` can reach lower-level methods like
|
|
1568
|
+
* `executeTransaction`, `proveTransaction[WithProver]`,
|
|
1569
|
+
* `submitProvenTransaction`, `applyTransaction`,
|
|
1570
|
+
* `newSendTransactionRequest`, `newConsumeTransactionRequest`, etc.
|
|
1571
|
+
*
|
|
1572
|
+
* Intended for advanced consumers that need to split the bundled
|
|
1573
|
+
* execute → prove → submit → apply pipeline across contexts — for example,
|
|
1574
|
+
* a Chrome MV3 extension that runs `executeTransaction` in its service
|
|
1575
|
+
* worker, dispatches the prove step to a `chrome.offscreen` document
|
|
1576
|
+
* (where wasm-bindgen-rayon can spawn a real thread pool), then runs
|
|
1577
|
+
* `submitProvenTransaction` + `applyTransaction` back in the SW.
|
|
1578
|
+
*
|
|
1579
|
+
* The callback runs inside `_serializeWasmCall`, so the WASM RefCell is
|
|
1580
|
+
* held for the duration of `fn`. Concurrent SDK calls (sync, other
|
|
1581
|
+
* transactions, etc.) queue on the same chain and run after `fn`
|
|
1582
|
+
* settles. Without this serialization, raw inner-client access would
|
|
1583
|
+
* race the proxy's chain and trip wasm-bindgen's "recursive use of an
|
|
1584
|
+
* object detected" panic.
|
|
1585
|
+
*
|
|
1586
|
+
* Stability: marked `@internal`. The shape of the proxied client is
|
|
1587
|
+
* intentionally not part of the documented public API and may change
|
|
1588
|
+
* between SDK versions. If you depend on this method, pin the SDK
|
|
1589
|
+
* version and test the lower-level surface carefully on each upgrade.
|
|
1590
|
+
* If your use case is common enough to warrant a stable public API,
|
|
1591
|
+
* file an issue.
|
|
1592
|
+
*
|
|
1593
|
+
* @internal
|
|
1594
|
+
* @template T
|
|
1595
|
+
* @param {(inner: object) => Promise<T>} fn - Async callback receiving
|
|
1596
|
+
* the proxied JS WebClient. Must not return references that escape
|
|
1597
|
+
* the callback's lifetime (the lock is released on settle).
|
|
1598
|
+
* @returns {Promise<T>} The resolved value of `fn`.
|
|
1599
|
+
*/
|
|
1600
|
+
_withInnerWebClient(fn) {
|
|
1601
|
+
this.assertNotTerminated();
|
|
1602
|
+
if (typeof fn !== "function") {
|
|
1603
|
+
throw new TypeError("_withInnerWebClient: fn must be a function");
|
|
1604
|
+
}
|
|
1605
|
+
return this.#inner._serializeWasmCall(() => fn(this.#inner));
|
|
1606
|
+
}
|
|
1607
|
+
|
|
1556
1608
|
/**
|
|
1557
1609
|
* Creates and initializes a new MidenClient.
|
|
1558
1610
|
*
|
|
@@ -1581,6 +1633,13 @@ class MidenClient {
|
|
|
1581
1633
|
const rpcUrl = resolveRpcUrl(options?.rpcUrl);
|
|
1582
1634
|
const noteTransportUrl = resolveNoteTransportUrl(options?.noteTransportUrl);
|
|
1583
1635
|
|
|
1636
|
+
// `useWorker: false` opts out of the Web Worker shim that wraps every
|
|
1637
|
+
// WASM call. The shim exists to keep the main thread responsive in
|
|
1638
|
+
// browser/extension contexts, but it serializes the prover via
|
|
1639
|
+
// `TransactionProver.serialize()` — a format that has no encoding for
|
|
1640
|
+
// `newCallbackProver(jsFn)` and silently downgrades it to `"local"`.
|
|
1641
|
+
// Mobile/Tauri/native-prover consumers must pass `useWorker: false`.
|
|
1642
|
+
const useWorker = options?.useWorker;
|
|
1584
1643
|
let inner;
|
|
1585
1644
|
if (options?.keystore) {
|
|
1586
1645
|
inner = await WebClientClass.createClientWithExternalKeystore(
|
|
@@ -1590,14 +1649,18 @@ class MidenClient {
|
|
|
1590
1649
|
options?.storeName,
|
|
1591
1650
|
options.keystore.getKey,
|
|
1592
1651
|
options.keystore.insertKey,
|
|
1593
|
-
options.keystore.sign
|
|
1652
|
+
options.keystore.sign,
|
|
1653
|
+
undefined,
|
|
1654
|
+
useWorker
|
|
1594
1655
|
);
|
|
1595
1656
|
} else {
|
|
1596
1657
|
inner = await WebClientClass.createClient(
|
|
1597
1658
|
rpcUrl,
|
|
1598
1659
|
noteTransportUrl,
|
|
1599
1660
|
seed,
|
|
1600
|
-
options?.storeName
|
|
1661
|
+
options?.storeName,
|
|
1662
|
+
undefined,
|
|
1663
|
+
useWorker
|
|
1601
1664
|
);
|
|
1602
1665
|
}
|
|
1603
1666
|
|
|
@@ -2341,6 +2404,15 @@ class WebClient {
|
|
|
2341
2404
|
* @param {string | undefined} [logLevel] - Optional log verbosity level
|
|
2342
2405
|
* ("error", "warn", "info", "debug", "trace", "off", or "none").
|
|
2343
2406
|
* When set, Rust tracing output is routed to the browser console.
|
|
2407
|
+
* @param {boolean} [useWorker=true] - When `false`, skip the Web Worker shim
|
|
2408
|
+
* and call the wasm-bindgen `WebClient` directly on the current thread.
|
|
2409
|
+
* The worker exists to keep the main thread responsive during WASM work
|
|
2410
|
+
* in browser/extension contexts, but it serializes the prover argument
|
|
2411
|
+
* via `TransactionProver.serialize()` — a format that has no encoding
|
|
2412
|
+
* for `newCallbackProver(jsFn)` and silently downgrades it to `"local"`.
|
|
2413
|
+
* Consumers that hand a `CallbackProver` (e.g. native iOS/Android plug-in
|
|
2414
|
+
* provers in Capacitor apps, or any other JS-side prover bridge) need
|
|
2415
|
+
* `useWorker: false` so the prover handle reaches the WASM binding intact.
|
|
2344
2416
|
*/
|
|
2345
2417
|
constructor(
|
|
2346
2418
|
rpcUrl,
|
|
@@ -2350,7 +2422,8 @@ class WebClient {
|
|
|
2350
2422
|
getKeyCb,
|
|
2351
2423
|
insertKeyCb,
|
|
2352
2424
|
signCb,
|
|
2353
|
-
logLevel
|
|
2425
|
+
logLevel,
|
|
2426
|
+
useWorker = true
|
|
2354
2427
|
) {
|
|
2355
2428
|
this.rpcUrl = rpcUrl;
|
|
2356
2429
|
this.noteTransportUrl = noteTransportUrl;
|
|
@@ -2360,9 +2433,12 @@ class WebClient {
|
|
|
2360
2433
|
this.insertKeyCb = insertKeyCb;
|
|
2361
2434
|
this.signCb = signCb;
|
|
2362
2435
|
this.logLevel = logLevel;
|
|
2436
|
+
this.useWorker = useWorker !== false;
|
|
2363
2437
|
|
|
2364
|
-
// Check if Web Workers are available
|
|
2365
|
-
|
|
2438
|
+
// Check if Web Workers are available AND the caller didn't opt out via
|
|
2439
|
+
// `useWorker: false`. The opt-out is load-bearing for `CallbackProver`
|
|
2440
|
+
// consumers — see the constructor doc above.
|
|
2441
|
+
if (this.useWorker && typeof Worker !== "undefined") {
|
|
2366
2442
|
console.log("WebClient: Web Workers are available.");
|
|
2367
2443
|
// Pick between the module and classic worker variants at runtime — see
|
|
2368
2444
|
// `WebClient.workerMode` below. Both branches keep the
|
|
@@ -2476,8 +2552,12 @@ class WebClient {
|
|
|
2476
2552
|
// Once the worker script has loaded, initialize the worker.
|
|
2477
2553
|
this.loaded.then(() => this.initializeWorker());
|
|
2478
2554
|
} else {
|
|
2479
|
-
console.log(
|
|
2480
|
-
|
|
2555
|
+
console.log(
|
|
2556
|
+
this.useWorker
|
|
2557
|
+
? "WebClient: Web Workers are not available."
|
|
2558
|
+
: "WebClient: Web Worker shim disabled by caller (useWorker=false)."
|
|
2559
|
+
);
|
|
2560
|
+
// Worker not available or explicitly disabled; set up fallback values.
|
|
2481
2561
|
this.worker = null;
|
|
2482
2562
|
this.pendingRequests = null;
|
|
2483
2563
|
this.loaded = Promise.resolve();
|
|
@@ -2548,6 +2628,22 @@ class WebClient {
|
|
|
2548
2628
|
// More context here:
|
|
2549
2629
|
// https://github.com/0xMiden/miden-client/pull/1645?notification_referrer_id=NT_kwHOA1yg7NoAJVJlcG9zaXRvcnk7NjU5MzQzNzAyO0lzc3VlOzM3OTY4OTU1Nzk¬ifications_query=is%3Aunread#discussion_r2696075480
|
|
2550
2630
|
initializeWorker() {
|
|
2631
|
+
// Pass `numThreads` to the worker so it can call `wasm.initThreadPool(n)`
|
|
2632
|
+
// inside its OWN WASM instance — the SDK worker's instance is separate
|
|
2633
|
+
// from the main thread's, and rayon's global pool is per-instance.
|
|
2634
|
+
// Default: navigator.hardwareConcurrency (or 1 if unavailable for any
|
|
2635
|
+
// reason — e.g. the page isn't crossOriginIsolated, in which case the
|
|
2636
|
+
// worker will skip pool init and parallelism falls back to sequential).
|
|
2637
|
+
let numThreads = 1;
|
|
2638
|
+
try {
|
|
2639
|
+
if (
|
|
2640
|
+
typeof self !== "undefined" &&
|
|
2641
|
+
self.crossOriginIsolated &&
|
|
2642
|
+
navigator?.hardwareConcurrency
|
|
2643
|
+
) {
|
|
2644
|
+
numThreads = navigator.hardwareConcurrency;
|
|
2645
|
+
}
|
|
2646
|
+
} catch {}
|
|
2551
2647
|
this.worker.postMessage({
|
|
2552
2648
|
action: WorkerAction.INIT,
|
|
2553
2649
|
args: [
|
|
@@ -2559,6 +2655,7 @@ class WebClient {
|
|
|
2559
2655
|
!!this.insertKeyCb,
|
|
2560
2656
|
!!this.signCb,
|
|
2561
2657
|
this.logLevel,
|
|
2658
|
+
numThreads,
|
|
2562
2659
|
],
|
|
2563
2660
|
});
|
|
2564
2661
|
}
|
|
@@ -2587,9 +2684,19 @@ class WebClient {
|
|
|
2587
2684
|
* @param {string} seed - The seed for the account.
|
|
2588
2685
|
* @param {string | undefined} network - Optional name for the store. Setting this allows multiple clients to be used in the same browser.
|
|
2589
2686
|
* @param {string | undefined} logLevel - Optional log verbosity level ("error", "warn", "info", "debug", "trace", "off", or "none").
|
|
2687
|
+
* @param {boolean} [useWorker=true] - When `false`, bypass the Web Worker shim
|
|
2688
|
+
* and run WASM calls on the current thread. Required for `CallbackProver`
|
|
2689
|
+
* consumers (the worker path serializes the prover and loses the callback).
|
|
2590
2690
|
* @returns {Promise<WebClient>} The fully initialized WebClient.
|
|
2591
2691
|
*/
|
|
2592
|
-
static async createClient(
|
|
2692
|
+
static async createClient(
|
|
2693
|
+
rpcUrl,
|
|
2694
|
+
noteTransportUrl,
|
|
2695
|
+
seed,
|
|
2696
|
+
network,
|
|
2697
|
+
logLevel,
|
|
2698
|
+
useWorker = true
|
|
2699
|
+
) {
|
|
2593
2700
|
// Construct the instance (synchronously).
|
|
2594
2701
|
const instance = new WebClient(
|
|
2595
2702
|
rpcUrl,
|
|
@@ -2599,7 +2706,8 @@ class WebClient {
|
|
|
2599
2706
|
undefined,
|
|
2600
2707
|
undefined,
|
|
2601
2708
|
undefined,
|
|
2602
|
-
logLevel
|
|
2709
|
+
logLevel,
|
|
2710
|
+
useWorker
|
|
2603
2711
|
);
|
|
2604
2712
|
|
|
2605
2713
|
// Set up logging on the main thread before creating the client.
|
|
@@ -2630,6 +2738,9 @@ class WebClient {
|
|
|
2630
2738
|
* @param {Function | undefined} insertKeyCb - The insert key callback.
|
|
2631
2739
|
* @param {Function | undefined} signCb - The sign callback.
|
|
2632
2740
|
* @param {string | undefined} logLevel - Optional log verbosity level ("error", "warn", "info", "debug", "trace", "off", or "none").
|
|
2741
|
+
* @param {boolean} [useWorker=true] - When `false`, bypass the Web Worker shim
|
|
2742
|
+
* and run WASM calls on the current thread. Required for `CallbackProver`
|
|
2743
|
+
* consumers (the worker path serializes the prover and loses the callback).
|
|
2633
2744
|
* @returns {Promise<WebClient>} The fully initialized WebClient.
|
|
2634
2745
|
*/
|
|
2635
2746
|
static async createClientWithExternalKeystore(
|
|
@@ -2640,7 +2751,8 @@ class WebClient {
|
|
|
2640
2751
|
getKeyCb,
|
|
2641
2752
|
insertKeyCb,
|
|
2642
2753
|
signCb,
|
|
2643
|
-
logLevel
|
|
2754
|
+
logLevel,
|
|
2755
|
+
useWorker = true
|
|
2644
2756
|
) {
|
|
2645
2757
|
// Construct the instance (synchronously).
|
|
2646
2758
|
const instance = new WebClient(
|
|
@@ -2651,7 +2763,8 @@ class WebClient {
|
|
|
2651
2763
|
getKeyCb,
|
|
2652
2764
|
insertKeyCb,
|
|
2653
2765
|
signCb,
|
|
2654
|
-
logLevel
|
|
2766
|
+
logLevel,
|
|
2767
|
+
useWorker
|
|
2655
2768
|
);
|
|
2656
2769
|
|
|
2657
2770
|
// Set up logging on the main thread before creating the client.
|