@miden-sdk/react 0.14.3 → 0.14.4
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/README.md +58 -0
- package/dist/index.d.mts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +146 -141
- package/dist/index.mjs +17 -12
- package/dist/lazy.d.mts +1497 -0
- package/dist/lazy.d.ts +1497 -0
- package/dist/lazy.js +3672 -0
- package/dist/lazy.mjs +3637 -0
- package/package.json +9 -4
package/dist/lazy.d.mts
ADDED
|
@@ -0,0 +1,1497 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import * as react from 'react';
|
|
3
|
+
import { ReactNode } from 'react';
|
|
4
|
+
import { AccountId, Account, AccountHeader, AccountStorageMode, AccountComponent, NoteId, InputNoteRecord, Note, StorageMode, AuthScheme, TransactionScript, AdviceInputs, AccountStorageRequirements, TransactionRequest, WasmWebClient, AccountFile, NoteVisibility, ConsumableNoteRecord, TransactionId, TransactionFilter, TransactionRecord, TransactionProver, CompileComponentOptions, CompileTxScriptOptions, CompileNoteScriptOptions, NoteScript, NoteAttachment } from '@miden-sdk/miden-sdk/lazy';
|
|
5
|
+
export { Account, AccountFile, AccountHeader, AccountId, AccountStorageMode, AuthScheme, ConsumableNoteRecord, InputNoteRecord, Note, NoteType, TransactionFilter, TransactionId, TransactionRecord, TransactionRequest, WasmWebClient as WebClient } from '@miden-sdk/miden-sdk/lazy';
|
|
6
|
+
|
|
7
|
+
declare module "@miden-sdk/miden-sdk/lazy" {
|
|
8
|
+
interface Account {
|
|
9
|
+
/** Returns the bech32-encoded account id using the configured network. */
|
|
10
|
+
bech32id(): string;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** Account reference — any account ID form accepted by the React SDK hooks. */
|
|
15
|
+
type AccountRef = string | AccountId | Account | AccountHeader;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Sign callback for WebClient.createClientWithExternalKeystore.
|
|
19
|
+
* Called when a transaction needs to be signed.
|
|
20
|
+
*
|
|
21
|
+
* @param pubKey - Public key commitment bytes
|
|
22
|
+
* @param signingInputs - Serialized signing inputs
|
|
23
|
+
* @returns Promise resolving to the signature bytes
|
|
24
|
+
*/
|
|
25
|
+
type SignCallback = (pubKey: Uint8Array, signingInputs: Uint8Array) => Promise<Uint8Array>;
|
|
26
|
+
/**
|
|
27
|
+
* Get-key callback for WebClient.createClientWithExternalKeystore.
|
|
28
|
+
* Called to retrieve a secret key by its public key commitment.
|
|
29
|
+
*
|
|
30
|
+
* @param pubKey - Public key commitment bytes
|
|
31
|
+
* @returns Promise resolving to the secret key bytes
|
|
32
|
+
*/
|
|
33
|
+
type GetKeyCallback = (pubKey: Uint8Array) => Promise<Uint8Array>;
|
|
34
|
+
/**
|
|
35
|
+
* Insert-key callback for WebClient.createClientWithExternalKeystore.
|
|
36
|
+
* Called when the SDK needs to persist a newly-generated key pair.
|
|
37
|
+
*
|
|
38
|
+
* @param pubKey - Public key commitment bytes
|
|
39
|
+
* @param secretKey - Secret key bytes to store
|
|
40
|
+
*/
|
|
41
|
+
type InsertKeyCallback = (pubKey: Uint8Array, secretKey: Uint8Array) => void;
|
|
42
|
+
/**
|
|
43
|
+
* Account type for signer accounts.
|
|
44
|
+
* Matches the AccountType enum from the SDK.
|
|
45
|
+
*/
|
|
46
|
+
type SignerAccountType = "RegularAccountImmutableCode" | "RegularAccountUpdatableCode" | "FungibleFaucet" | "NonFungibleFaucet";
|
|
47
|
+
/**
|
|
48
|
+
* Account configuration provided by the signer.
|
|
49
|
+
* Used to initialize the account in the client store.
|
|
50
|
+
*/
|
|
51
|
+
interface SignerAccountConfig {
|
|
52
|
+
/** Public key commitment (for auth component) */
|
|
53
|
+
publicKeyCommitment: Uint8Array;
|
|
54
|
+
/** Account type */
|
|
55
|
+
accountType: SignerAccountType;
|
|
56
|
+
/** Storage mode (public/private/network) */
|
|
57
|
+
storageMode: AccountStorageMode;
|
|
58
|
+
/** Optional seed for deterministic account ID */
|
|
59
|
+
accountSeed?: Uint8Array;
|
|
60
|
+
/** Optional custom account components to include in the account (e.g. from a compiled .masp package) */
|
|
61
|
+
customComponents?: AccountComponent[];
|
|
62
|
+
/**
|
|
63
|
+
* Optional existing account ID to import instead of building from scratch.
|
|
64
|
+
* When provided, skips AccountBuilder and imports the account by ID from the chain.
|
|
65
|
+
* Useful for wallets that create accounts externally (e.g., via a vault).
|
|
66
|
+
*/
|
|
67
|
+
importAccountId?: string;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Context value provided by signer providers (Para, Turnkey, MidenFi, etc.).
|
|
71
|
+
* Includes everything needed for MidenProvider to create an external keystore client
|
|
72
|
+
* and for apps to show connect/disconnect UI.
|
|
73
|
+
*/
|
|
74
|
+
interface SignerContextValue {
|
|
75
|
+
/** Sign callback for external keystore */
|
|
76
|
+
signCb: SignCallback;
|
|
77
|
+
/** Optional get-key callback for external keystore (retrieves secret key by public key) */
|
|
78
|
+
getKeyCb?: GetKeyCallback;
|
|
79
|
+
/** Optional insert-key callback for external keystore (persists newly-generated key pair) */
|
|
80
|
+
insertKeyCb?: InsertKeyCallback;
|
|
81
|
+
/** Account config for initialization (only valid when connected) */
|
|
82
|
+
accountConfig: SignerAccountConfig;
|
|
83
|
+
/** Store name suffix for IndexedDB isolation (e.g., "para_walletId") */
|
|
84
|
+
storeName: string;
|
|
85
|
+
/** Display name for UI (e.g., "Para", "Turnkey", "MidenFi") */
|
|
86
|
+
name: string;
|
|
87
|
+
/** Whether the signer is connected and ready */
|
|
88
|
+
isConnected: boolean;
|
|
89
|
+
/** Connect to the signer (triggers auth flow) */
|
|
90
|
+
connect: () => Promise<void>;
|
|
91
|
+
/** Disconnect from the signer */
|
|
92
|
+
disconnect: () => Promise<void>;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* React context for signer - null when no signer provider is present.
|
|
96
|
+
* Signer providers (ParaSignerProvider, TurnkeySignerProvider, etc.) populate this context.
|
|
97
|
+
*/
|
|
98
|
+
declare const SignerContext: react.Context<SignerContextValue | null>;
|
|
99
|
+
/**
|
|
100
|
+
* Hook for apps and MidenProvider to interact with the current signer.
|
|
101
|
+
* Returns null if no signer provider is present (local keystore mode).
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```tsx
|
|
105
|
+
* function ConnectButton() {
|
|
106
|
+
* const signer = useSigner();
|
|
107
|
+
* if (!signer) return null; // Local keystore mode
|
|
108
|
+
*
|
|
109
|
+
* const { isConnected, connect, disconnect, name } = signer;
|
|
110
|
+
* return isConnected
|
|
111
|
+
* ? <button onClick={disconnect}>Disconnect {name}</button>
|
|
112
|
+
* : <button onClick={connect}>Connect with {name}</button>;
|
|
113
|
+
* }
|
|
114
|
+
* ```
|
|
115
|
+
*/
|
|
116
|
+
declare function useSigner(): SignerContextValue | null;
|
|
117
|
+
|
|
118
|
+
type RpcUrlConfig = string | "devnet" | "testnet" | "localhost" | "local";
|
|
119
|
+
/** Single prover target — a well-known name, custom URL, or object with URL + timeout. */
|
|
120
|
+
type ProverTarget = "local" | "localhost" | "devnet" | "testnet" | string | {
|
|
121
|
+
url: string;
|
|
122
|
+
timeoutMs?: number | bigint;
|
|
123
|
+
};
|
|
124
|
+
type ProverConfig = ProverTarget | {
|
|
125
|
+
/** Primary prover to try first */
|
|
126
|
+
primary: ProverTarget;
|
|
127
|
+
/** Fallback prover if primary fails (e.g. "local") */
|
|
128
|
+
fallback?: ProverTarget;
|
|
129
|
+
/** Return true to skip the fallback (e.g. on mobile where local proving is too slow) */
|
|
130
|
+
disableFallback?: () => boolean;
|
|
131
|
+
/** Called when the primary prover fails and the fallback is used */
|
|
132
|
+
onFallback?: () => void;
|
|
133
|
+
};
|
|
134
|
+
type ProverUrls = {
|
|
135
|
+
devnet?: string;
|
|
136
|
+
testnet?: string;
|
|
137
|
+
};
|
|
138
|
+
interface MidenConfig {
|
|
139
|
+
/** RPC node URL or network name (devnet/testnet/localhost). Defaults to testnet. */
|
|
140
|
+
rpcUrl?: RpcUrlConfig;
|
|
141
|
+
/** Note transport URL for streaming notes. */
|
|
142
|
+
noteTransportUrl?: string;
|
|
143
|
+
/** Auto-sync interval in milliseconds. Set to 0 to disable. Default: 15000ms */
|
|
144
|
+
autoSyncInterval?: number;
|
|
145
|
+
/** Initial seed for deterministic RNG (must be 32 bytes if provided) */
|
|
146
|
+
seed?: Uint8Array;
|
|
147
|
+
/** Transaction prover selection (local/devnet/testnet or a remote URL). */
|
|
148
|
+
prover?: ProverConfig;
|
|
149
|
+
/** Optional override URLs for network provers. */
|
|
150
|
+
proverUrls?: ProverUrls;
|
|
151
|
+
/** Default timeout for remote prover requests in milliseconds. */
|
|
152
|
+
proverTimeoutMs?: number | bigint;
|
|
153
|
+
}
|
|
154
|
+
interface MidenState {
|
|
155
|
+
client: WasmWebClient | null;
|
|
156
|
+
isReady: boolean;
|
|
157
|
+
isInitializing: boolean;
|
|
158
|
+
error: Error | null;
|
|
159
|
+
}
|
|
160
|
+
type TransactionStage = "idle" | "executing" | "proving" | "submitting" | "complete";
|
|
161
|
+
interface QueryResult<T> {
|
|
162
|
+
data: T | null;
|
|
163
|
+
isLoading: boolean;
|
|
164
|
+
error: Error | null;
|
|
165
|
+
refetch: () => Promise<void>;
|
|
166
|
+
}
|
|
167
|
+
interface MutationResult<TData, TVariables> {
|
|
168
|
+
mutate: (variables: TVariables) => Promise<TData>;
|
|
169
|
+
data: TData | null;
|
|
170
|
+
isLoading: boolean;
|
|
171
|
+
stage: TransactionStage;
|
|
172
|
+
error: Error | null;
|
|
173
|
+
reset: () => void;
|
|
174
|
+
}
|
|
175
|
+
interface SyncState {
|
|
176
|
+
syncHeight: number;
|
|
177
|
+
isSyncing: boolean;
|
|
178
|
+
lastSyncTime: number | null;
|
|
179
|
+
error: Error | null;
|
|
180
|
+
}
|
|
181
|
+
interface AccountsResult {
|
|
182
|
+
accounts: AccountHeader[];
|
|
183
|
+
wallets: AccountHeader[];
|
|
184
|
+
faucets: AccountHeader[];
|
|
185
|
+
isLoading: boolean;
|
|
186
|
+
error: Error | null;
|
|
187
|
+
refetch: () => Promise<void>;
|
|
188
|
+
}
|
|
189
|
+
interface AccountResult {
|
|
190
|
+
account: Account | null;
|
|
191
|
+
assets: AssetBalance[];
|
|
192
|
+
isLoading: boolean;
|
|
193
|
+
error: Error | null;
|
|
194
|
+
refetch: () => Promise<void>;
|
|
195
|
+
getBalance: (assetId: string) => bigint;
|
|
196
|
+
}
|
|
197
|
+
interface AssetBalance {
|
|
198
|
+
assetId: string;
|
|
199
|
+
amount: bigint;
|
|
200
|
+
symbol?: string;
|
|
201
|
+
decimals?: number;
|
|
202
|
+
}
|
|
203
|
+
interface NotesFilter {
|
|
204
|
+
status?: "all" | "consumed" | "committed" | "expected" | "processing";
|
|
205
|
+
accountId?: AccountRef;
|
|
206
|
+
/** Only notes from this sender (any format, normalized internally) */
|
|
207
|
+
sender?: string;
|
|
208
|
+
/** Exclude these note IDs */
|
|
209
|
+
excludeIds?: string[];
|
|
210
|
+
}
|
|
211
|
+
interface NotesResult {
|
|
212
|
+
notes: InputNoteRecord[];
|
|
213
|
+
consumableNotes: ConsumableNoteRecord[];
|
|
214
|
+
noteSummaries: NoteSummary[];
|
|
215
|
+
consumableNoteSummaries: NoteSummary[];
|
|
216
|
+
isLoading: boolean;
|
|
217
|
+
error: Error | null;
|
|
218
|
+
refetch: () => Promise<void>;
|
|
219
|
+
}
|
|
220
|
+
type TransactionStatus = "pending" | "committed" | "discarded";
|
|
221
|
+
interface TransactionHistoryOptions {
|
|
222
|
+
/** Single transaction ID to look up. */
|
|
223
|
+
id?: string | TransactionId;
|
|
224
|
+
/** List of transaction IDs to look up. */
|
|
225
|
+
ids?: Array<string | TransactionId>;
|
|
226
|
+
/** Custom transaction filter (overrides id/ids). */
|
|
227
|
+
filter?: TransactionFilter;
|
|
228
|
+
/** Refresh after provider syncs. Default: true */
|
|
229
|
+
refreshOnSync?: boolean;
|
|
230
|
+
}
|
|
231
|
+
interface TransactionHistoryResult {
|
|
232
|
+
records: TransactionRecord[];
|
|
233
|
+
/** Convenience record when a single ID is provided. */
|
|
234
|
+
record: TransactionRecord | null;
|
|
235
|
+
/** Convenience status when a single ID is provided. */
|
|
236
|
+
status: TransactionStatus | null;
|
|
237
|
+
isLoading: boolean;
|
|
238
|
+
error: Error | null;
|
|
239
|
+
refetch: () => Promise<void>;
|
|
240
|
+
}
|
|
241
|
+
interface AssetMetadata {
|
|
242
|
+
assetId: string;
|
|
243
|
+
symbol?: string;
|
|
244
|
+
decimals?: number;
|
|
245
|
+
}
|
|
246
|
+
interface NoteAsset {
|
|
247
|
+
assetId: string;
|
|
248
|
+
amount: bigint;
|
|
249
|
+
symbol?: string;
|
|
250
|
+
decimals?: number;
|
|
251
|
+
}
|
|
252
|
+
interface NoteSummary {
|
|
253
|
+
id: string;
|
|
254
|
+
assets: NoteAsset[];
|
|
255
|
+
sender?: string;
|
|
256
|
+
}
|
|
257
|
+
interface CreateWalletOptions {
|
|
258
|
+
/** Storage mode. Default: private */
|
|
259
|
+
storageMode?: StorageMode;
|
|
260
|
+
/** Whether code can be updated. Default: true */
|
|
261
|
+
mutable?: boolean;
|
|
262
|
+
/** Auth scheme. Default: AuthScheme.AuthRpoFalcon512 */
|
|
263
|
+
authScheme?: AuthScheme;
|
|
264
|
+
/** Initial seed for deterministic account ID */
|
|
265
|
+
initSeed?: Uint8Array;
|
|
266
|
+
}
|
|
267
|
+
interface CreateFaucetOptions {
|
|
268
|
+
/** Token symbol (e.g., "TEST") */
|
|
269
|
+
tokenSymbol: string;
|
|
270
|
+
/** Number of decimals. Default: 8 */
|
|
271
|
+
decimals?: number;
|
|
272
|
+
/** Maximum supply */
|
|
273
|
+
maxSupply: bigint | number;
|
|
274
|
+
/** Storage mode. Default: private */
|
|
275
|
+
storageMode?: StorageMode;
|
|
276
|
+
/** Auth scheme. Default: AuthScheme.AuthRpoFalcon512 */
|
|
277
|
+
authScheme?: AuthScheme;
|
|
278
|
+
}
|
|
279
|
+
type ImportAccountOptions = {
|
|
280
|
+
type: "file";
|
|
281
|
+
file: AccountFile | Uint8Array | ArrayBuffer;
|
|
282
|
+
} | {
|
|
283
|
+
type: "id";
|
|
284
|
+
accountId: AccountRef;
|
|
285
|
+
} | {
|
|
286
|
+
type: "seed";
|
|
287
|
+
seed: Uint8Array;
|
|
288
|
+
mutable?: boolean;
|
|
289
|
+
authScheme?: AuthScheme;
|
|
290
|
+
};
|
|
291
|
+
interface SendOptions {
|
|
292
|
+
/** Sender account ID */
|
|
293
|
+
from: AccountRef;
|
|
294
|
+
/** Recipient account ID */
|
|
295
|
+
to: AccountRef;
|
|
296
|
+
/** Asset ID to send (token id) */
|
|
297
|
+
assetId: AccountRef;
|
|
298
|
+
/** Amount to send (ignored when sendAll is true) */
|
|
299
|
+
amount?: bigint | number;
|
|
300
|
+
/** Note type. Default: private */
|
|
301
|
+
noteType?: NoteVisibility;
|
|
302
|
+
/** Block height after which sender can reclaim note */
|
|
303
|
+
recallHeight?: number;
|
|
304
|
+
/** Block height after which recipient can consume note */
|
|
305
|
+
timelockHeight?: number;
|
|
306
|
+
/** Arbitrary data payload attached to the note */
|
|
307
|
+
attachment?: bigint[] | Uint8Array | number[];
|
|
308
|
+
/** Skip auto-sync before send. Default: false */
|
|
309
|
+
skipSync?: boolean;
|
|
310
|
+
/** Send the full balance of this asset. When true, amount is ignored. */
|
|
311
|
+
sendAll?: boolean;
|
|
312
|
+
/** true = build note in JS and return the Note object (e.g. for out-of-band delivery). Default: false */
|
|
313
|
+
returnNote?: boolean;
|
|
314
|
+
}
|
|
315
|
+
interface SendResult {
|
|
316
|
+
txId: string;
|
|
317
|
+
note: Note | null;
|
|
318
|
+
}
|
|
319
|
+
interface MultiSendRecipient {
|
|
320
|
+
/** Recipient account ID */
|
|
321
|
+
to: AccountRef;
|
|
322
|
+
/** Amount to send */
|
|
323
|
+
amount: bigint | number;
|
|
324
|
+
/** Per-recipient note type override */
|
|
325
|
+
noteType?: "private" | "public";
|
|
326
|
+
/** Per-recipient attachment */
|
|
327
|
+
attachment?: bigint[] | Uint8Array | number[];
|
|
328
|
+
}
|
|
329
|
+
interface MultiSendOptions {
|
|
330
|
+
/** Sender account ID */
|
|
331
|
+
from: AccountRef;
|
|
332
|
+
/** Asset ID to send (token id) */
|
|
333
|
+
assetId: AccountRef;
|
|
334
|
+
/** Recipient list */
|
|
335
|
+
recipients: MultiSendRecipient[];
|
|
336
|
+
/** Default note type for all recipients. Default: private */
|
|
337
|
+
noteType?: NoteVisibility;
|
|
338
|
+
/** Skip auto-sync before send. Default: false */
|
|
339
|
+
skipSync?: boolean;
|
|
340
|
+
}
|
|
341
|
+
interface WaitForCommitOptions {
|
|
342
|
+
/** Timeout in milliseconds. Default: 10000 */
|
|
343
|
+
timeoutMs?: number;
|
|
344
|
+
/** Polling interval in milliseconds. Default: 1000 */
|
|
345
|
+
intervalMs?: number;
|
|
346
|
+
}
|
|
347
|
+
interface WaitForNotesOptions {
|
|
348
|
+
/** Account ID to check for consumable notes */
|
|
349
|
+
accountId: AccountRef;
|
|
350
|
+
/** Minimum number of notes to wait for. Default: 1 */
|
|
351
|
+
minCount?: number;
|
|
352
|
+
/** Timeout in milliseconds. Default: 10000 */
|
|
353
|
+
timeoutMs?: number;
|
|
354
|
+
/** Polling interval in milliseconds. Default: 1000 */
|
|
355
|
+
intervalMs?: number;
|
|
356
|
+
}
|
|
357
|
+
interface MintOptions {
|
|
358
|
+
/** Target account to receive minted tokens */
|
|
359
|
+
targetAccountId: AccountRef;
|
|
360
|
+
/** Faucet account to mint from */
|
|
361
|
+
faucetId: AccountRef;
|
|
362
|
+
/** Amount to mint */
|
|
363
|
+
amount: bigint | number;
|
|
364
|
+
/** Note type. Default: private */
|
|
365
|
+
noteType?: NoteVisibility;
|
|
366
|
+
}
|
|
367
|
+
interface ConsumeOptions {
|
|
368
|
+
/** Account ID that will consume the notes */
|
|
369
|
+
accountId: string;
|
|
370
|
+
/** Notes to consume — accepts note IDs (hex strings), NoteId objects, InputNoteRecord, or Note objects */
|
|
371
|
+
notes: (string | NoteId | InputNoteRecord | Note)[];
|
|
372
|
+
}
|
|
373
|
+
interface SwapOptions {
|
|
374
|
+
/** Account initiating the swap */
|
|
375
|
+
accountId: AccountRef;
|
|
376
|
+
/** Faucet ID of the offered asset */
|
|
377
|
+
offeredFaucetId: AccountRef;
|
|
378
|
+
/** Amount being offered */
|
|
379
|
+
offeredAmount: bigint | number;
|
|
380
|
+
/** Faucet ID of the requested asset */
|
|
381
|
+
requestedFaucetId: AccountRef;
|
|
382
|
+
/** Amount being requested */
|
|
383
|
+
requestedAmount: bigint | number;
|
|
384
|
+
/** Note type for swap note. Default: private */
|
|
385
|
+
noteType?: NoteVisibility;
|
|
386
|
+
/** Note type for payback note. Default: private */
|
|
387
|
+
paybackNoteType?: NoteVisibility;
|
|
388
|
+
}
|
|
389
|
+
interface ExecuteTransactionOptions {
|
|
390
|
+
/** Account ID the transaction applies to */
|
|
391
|
+
accountId: AccountRef;
|
|
392
|
+
/** Transaction request or builder */
|
|
393
|
+
request: TransactionRequest | ((client: WasmWebClient) => TransactionRequest | Promise<TransactionRequest>);
|
|
394
|
+
/** Skip auto-sync before transaction. Default: false */
|
|
395
|
+
skipSync?: boolean;
|
|
396
|
+
/**
|
|
397
|
+
* When set, private output notes from this transaction are delivered to the
|
|
398
|
+
* given target account after the transaction is committed. Accepts any
|
|
399
|
+
* AccountRef form (hex string, bech32, AccountId, Account, AccountHeader).
|
|
400
|
+
*/
|
|
401
|
+
privateNoteTarget?: AccountRef;
|
|
402
|
+
}
|
|
403
|
+
interface TransactionResult {
|
|
404
|
+
transactionId: string;
|
|
405
|
+
}
|
|
406
|
+
interface ExecuteProgramOptions {
|
|
407
|
+
/** Account to execute the program against */
|
|
408
|
+
accountId: string | AccountId;
|
|
409
|
+
/** Compiled TransactionScript */
|
|
410
|
+
script: TransactionScript;
|
|
411
|
+
/** Advice inputs (defaults to empty) */
|
|
412
|
+
adviceInputs?: AdviceInputs;
|
|
413
|
+
/** Foreign accounts referenced by the script */
|
|
414
|
+
foreignAccounts?: (string | AccountId | {
|
|
415
|
+
id: string | AccountId;
|
|
416
|
+
storage?: AccountStorageRequirements;
|
|
417
|
+
})[];
|
|
418
|
+
/** Skip auto-sync before execution. Default: false */
|
|
419
|
+
skipSync?: boolean;
|
|
420
|
+
}
|
|
421
|
+
interface ExecuteProgramResult {
|
|
422
|
+
/** The 16-element stack output as bigint array */
|
|
423
|
+
stack: bigint[];
|
|
424
|
+
}
|
|
425
|
+
interface StreamedNote {
|
|
426
|
+
/** Note ID (hex string) */
|
|
427
|
+
id: string;
|
|
428
|
+
/** Sender account ID (bech32 if available) */
|
|
429
|
+
sender: string;
|
|
430
|
+
/** First fungible asset amount (convenience; 0n if no fungible assets) */
|
|
431
|
+
amount: bigint;
|
|
432
|
+
/** All assets on the note */
|
|
433
|
+
assets: NoteAsset[];
|
|
434
|
+
/** The underlying InputNoteRecord for escape-hatch access */
|
|
435
|
+
record: InputNoteRecord;
|
|
436
|
+
/** Timestamp (ms) when this note was first observed by the SDK */
|
|
437
|
+
firstSeenAt: number;
|
|
438
|
+
/** Pre-decoded attachment values, or null if no attachment */
|
|
439
|
+
attachment: bigint[] | null;
|
|
440
|
+
}
|
|
441
|
+
interface UseNoteStreamOptions {
|
|
442
|
+
/** Note status filter. Default: "committed" */
|
|
443
|
+
status?: "all" | "consumed" | "committed" | "expected" | "processing";
|
|
444
|
+
/** Only notes from this sender (any format, normalized internally) */
|
|
445
|
+
sender?: string | null;
|
|
446
|
+
/** Only notes first seen after this timestamp */
|
|
447
|
+
since?: number;
|
|
448
|
+
/** Exclude these note IDs (for cross-phase stale filtering) */
|
|
449
|
+
excludeIds?: Set<string> | string[];
|
|
450
|
+
/** Filter by primary asset amount */
|
|
451
|
+
amountFilter?: (amount: bigint) => boolean;
|
|
452
|
+
}
|
|
453
|
+
interface UseNoteStreamReturn {
|
|
454
|
+
/** Notes matching all filter criteria */
|
|
455
|
+
notes: StreamedNote[];
|
|
456
|
+
/** Most recent note (convenience) */
|
|
457
|
+
latest: StreamedNote | null;
|
|
458
|
+
/** Mark a note as handled (excluded from future renders) */
|
|
459
|
+
markHandled: (noteId: string) => void;
|
|
460
|
+
/** Mark all current notes as handled */
|
|
461
|
+
markAllHandled: () => void;
|
|
462
|
+
/** Snapshot current state for passing to next phase */
|
|
463
|
+
snapshot: () => {
|
|
464
|
+
ids: Set<string>;
|
|
465
|
+
timestamp: number;
|
|
466
|
+
};
|
|
467
|
+
isLoading: boolean;
|
|
468
|
+
error: Error | null;
|
|
469
|
+
}
|
|
470
|
+
interface UseSessionAccountOptions {
|
|
471
|
+
/** Callback to fund the session wallet. Receives the session wallet ID. */
|
|
472
|
+
fund: (sessionAccountId: string) => Promise<void>;
|
|
473
|
+
/** Asset ID of the funding token (reserved for future filtering of consumable notes) */
|
|
474
|
+
assetId?: string;
|
|
475
|
+
/** Wallet creation options */
|
|
476
|
+
walletOptions?: {
|
|
477
|
+
storageMode?: "private" | "public";
|
|
478
|
+
mutable?: boolean;
|
|
479
|
+
authScheme?: AuthScheme;
|
|
480
|
+
};
|
|
481
|
+
/** Polling interval for funding note detection (ms). Default: 3000 */
|
|
482
|
+
pollIntervalMs?: number;
|
|
483
|
+
/** Maximum time to wait for funding note (ms). Default: 60000 */
|
|
484
|
+
maxWaitMs?: number;
|
|
485
|
+
/** localStorage key prefix for persistence. Default: "miden-session" */
|
|
486
|
+
storagePrefix?: string;
|
|
487
|
+
}
|
|
488
|
+
type SessionAccountStep = "idle" | "creating" | "funding" | "consuming" | "ready";
|
|
489
|
+
interface UseSessionAccountReturn {
|
|
490
|
+
/** Start the create->fund->consume flow */
|
|
491
|
+
initialize: () => Promise<void>;
|
|
492
|
+
/** Session wallet ID (bech32), or null if not yet created */
|
|
493
|
+
sessionAccountId: string | null;
|
|
494
|
+
/** Whether the session wallet is funded and ready */
|
|
495
|
+
isReady: boolean;
|
|
496
|
+
/** Current step */
|
|
497
|
+
step: SessionAccountStep;
|
|
498
|
+
/** Error from any step */
|
|
499
|
+
error: Error | null;
|
|
500
|
+
/** Clear all session data and reset */
|
|
501
|
+
reset: () => void;
|
|
502
|
+
}
|
|
503
|
+
declare const DEFAULTS: {
|
|
504
|
+
readonly RPC_URL: undefined;
|
|
505
|
+
readonly AUTO_SYNC_INTERVAL: 15000;
|
|
506
|
+
readonly STORAGE_MODE: "private";
|
|
507
|
+
readonly WALLET_MUTABLE: true;
|
|
508
|
+
readonly AUTH_SCHEME: AuthScheme.AuthRpoFalcon512;
|
|
509
|
+
readonly NOTE_TYPE: "private";
|
|
510
|
+
readonly FAUCET_DECIMALS: 8;
|
|
511
|
+
};
|
|
512
|
+
|
|
513
|
+
type ProverConfigSubset = Pick<MidenConfig, "prover" | "proverUrls" | "proverTimeoutMs">;
|
|
514
|
+
declare function resolveTransactionProver(config: ProverConfigSubset): TransactionProver | null;
|
|
515
|
+
|
|
516
|
+
interface MidenContextValue {
|
|
517
|
+
client: WasmWebClient | null;
|
|
518
|
+
isReady: boolean;
|
|
519
|
+
isInitializing: boolean;
|
|
520
|
+
error: Error | null;
|
|
521
|
+
sync: () => Promise<void>;
|
|
522
|
+
runExclusive: <T>(fn: () => Promise<T>) => Promise<T>;
|
|
523
|
+
prover: ReturnType<typeof resolveTransactionProver>;
|
|
524
|
+
/** Account ID from signer (only set when using external signer) */
|
|
525
|
+
signerAccountId: string | null;
|
|
526
|
+
/** Whether the external signer is connected (null = no signer provider) */
|
|
527
|
+
signerConnected: boolean | null;
|
|
528
|
+
}
|
|
529
|
+
interface MidenProviderProps {
|
|
530
|
+
children: ReactNode;
|
|
531
|
+
config?: MidenConfig;
|
|
532
|
+
/** Custom loading component shown during WASM initialization */
|
|
533
|
+
loadingComponent?: ReactNode;
|
|
534
|
+
/** Custom error component shown if initialization fails */
|
|
535
|
+
errorComponent?: ReactNode | ((error: Error) => ReactNode);
|
|
536
|
+
}
|
|
537
|
+
declare function MidenProvider({ children, config, loadingComponent, errorComponent, }: MidenProviderProps): react_jsx_runtime.JSX.Element;
|
|
538
|
+
declare function useMiden(): MidenContextValue;
|
|
539
|
+
declare function useMidenClient(): WasmWebClient;
|
|
540
|
+
|
|
541
|
+
interface MultiSignerContextValue {
|
|
542
|
+
/** All registered signer providers */
|
|
543
|
+
signers: SignerContextValue[];
|
|
544
|
+
/** The currently active signer (null if none selected) */
|
|
545
|
+
activeSigner: SignerContextValue | null;
|
|
546
|
+
/** Switch to a signer by name and call its connect() */
|
|
547
|
+
connectSigner: (name: string) => Promise<void>;
|
|
548
|
+
/** Disconnect the active signer and revert to local keystore mode */
|
|
549
|
+
disconnectSigner: () => Promise<void>;
|
|
550
|
+
}
|
|
551
|
+
declare function MultiSignerProvider({ children }: {
|
|
552
|
+
children: ReactNode;
|
|
553
|
+
}): react_jsx_runtime.JSX.Element;
|
|
554
|
+
/**
|
|
555
|
+
* Render-less component that registers the nearest ancestor's SignerContext value
|
|
556
|
+
* into the MultiSignerProvider registry.
|
|
557
|
+
*
|
|
558
|
+
* Place one `<SignerSlot />` inside each signer provider:
|
|
559
|
+
* ```tsx
|
|
560
|
+
* <ParaSignerProvider>
|
|
561
|
+
* <SignerSlot />
|
|
562
|
+
* </ParaSignerProvider>
|
|
563
|
+
* ```
|
|
564
|
+
*/
|
|
565
|
+
declare function SignerSlot(): null;
|
|
566
|
+
/**
|
|
567
|
+
* Access the multi-signer context for listing signers, connecting, and disconnecting.
|
|
568
|
+
* Returns null when used outside a `MultiSignerProvider`.
|
|
569
|
+
*/
|
|
570
|
+
declare function useMultiSigner(): MultiSignerContextValue | null;
|
|
571
|
+
|
|
572
|
+
/**
|
|
573
|
+
* Hook to list all accounts in the client.
|
|
574
|
+
*
|
|
575
|
+
* @example
|
|
576
|
+
* ```tsx
|
|
577
|
+
* function AccountList() {
|
|
578
|
+
* const { accounts, wallets, faucets, isLoading } = useAccounts();
|
|
579
|
+
*
|
|
580
|
+
* if (isLoading) return <div>Loading...</div>;
|
|
581
|
+
*
|
|
582
|
+
* return (
|
|
583
|
+
* <div>
|
|
584
|
+
* <h2>Wallets ({wallets.length})</h2>
|
|
585
|
+
* {wallets.map(w => <div key={w.id().toString()}>{w.id().toString()}</div>)}
|
|
586
|
+
*
|
|
587
|
+
* <h2>Faucets ({faucets.length})</h2>
|
|
588
|
+
* {faucets.map(f => <div key={f.id().toString()}>{f.id().toString()}</div>)}
|
|
589
|
+
* </div>
|
|
590
|
+
* );
|
|
591
|
+
* }
|
|
592
|
+
* ```
|
|
593
|
+
*/
|
|
594
|
+
declare function useAccounts(): AccountsResult;
|
|
595
|
+
|
|
596
|
+
/**
|
|
597
|
+
* Hook to get details for a single account.
|
|
598
|
+
*
|
|
599
|
+
* @param accountId - The account ID string or AccountId object
|
|
600
|
+
*
|
|
601
|
+
* @example
|
|
602
|
+
* ```tsx
|
|
603
|
+
* function AccountDetails({ accountId }: { accountId: string }) {
|
|
604
|
+
* const { account, assets, getBalance, isLoading } = useAccount(accountId);
|
|
605
|
+
*
|
|
606
|
+
* if (isLoading) return <div>Loading...</div>;
|
|
607
|
+
* if (!account) return <div>Account not found</div>;
|
|
608
|
+
*
|
|
609
|
+
* return (
|
|
610
|
+
* <div>
|
|
611
|
+
* <h2>Account: {account.id().toString()}</h2>
|
|
612
|
+
* <p>Nonce: {account.nonce().toString()}</p>
|
|
613
|
+
* <h3>Assets</h3>
|
|
614
|
+
* {assets.map(a => (
|
|
615
|
+
* <div key={a.assetId}>
|
|
616
|
+
* {a.assetId}: {a.amount.toString()}
|
|
617
|
+
* </div>
|
|
618
|
+
* ))}
|
|
619
|
+
* <p>USDC Balance: {getBalance('0x...').toString()}</p>
|
|
620
|
+
* </div>
|
|
621
|
+
* );
|
|
622
|
+
* }
|
|
623
|
+
* ```
|
|
624
|
+
*/
|
|
625
|
+
declare function useAccount(accountId: AccountRef | undefined): AccountResult;
|
|
626
|
+
|
|
627
|
+
/**
|
|
628
|
+
* Hook to list notes.
|
|
629
|
+
*
|
|
630
|
+
* @param options - Optional filter options
|
|
631
|
+
*
|
|
632
|
+
* @example
|
|
633
|
+
* ```tsx
|
|
634
|
+
* function NotesList() {
|
|
635
|
+
* const { notes, consumableNotes, isLoading, refetch } = useNotes();
|
|
636
|
+
*
|
|
637
|
+
* if (isLoading) return <div>Loading...</div>;
|
|
638
|
+
*
|
|
639
|
+
* return (
|
|
640
|
+
* <div>
|
|
641
|
+
* <h2>All Notes ({notes.length})</h2>
|
|
642
|
+
* {notes.map(n => (
|
|
643
|
+
* <div key={n.id().toString()}>
|
|
644
|
+
* Note: {n.id().toString()} - {n.isConsumed() ? 'Consumed' : 'Pending'}
|
|
645
|
+
* </div>
|
|
646
|
+
* ))}
|
|
647
|
+
*
|
|
648
|
+
* <h2>Consumable Notes ({consumableNotes.length})</h2>
|
|
649
|
+
* {consumableNotes.map(n => (
|
|
650
|
+
* <div key={n.inputNoteRecord().id().toString()}>
|
|
651
|
+
* {n.inputNoteRecord().id().toString()}
|
|
652
|
+
* </div>
|
|
653
|
+
* ))}
|
|
654
|
+
*
|
|
655
|
+
* <button onClick={refetch}>Refresh</button>
|
|
656
|
+
* </div>
|
|
657
|
+
* );
|
|
658
|
+
* }
|
|
659
|
+
* ```
|
|
660
|
+
*/
|
|
661
|
+
declare function useNotes(options?: NotesFilter): NotesResult;
|
|
662
|
+
|
|
663
|
+
/**
|
|
664
|
+
* Hook for temporal note tracking with a unified model.
|
|
665
|
+
*
|
|
666
|
+
* Replaces the common pattern of `handledNoteIds` refs, deferred baselines,
|
|
667
|
+
* and dual-track note decoding. Returns `StreamedNote` objects that merge
|
|
668
|
+
* summary data with the underlying record and pre-decode attachments.
|
|
669
|
+
*
|
|
670
|
+
* @example
|
|
671
|
+
* ```tsx
|
|
672
|
+
* function IncomingNotes({ opponentId }: { opponentId: string }) {
|
|
673
|
+
* const { notes, latest, markHandled, snapshot } = useNoteStream({
|
|
674
|
+
* sender: opponentId,
|
|
675
|
+
* status: "committed",
|
|
676
|
+
* });
|
|
677
|
+
*
|
|
678
|
+
* useEffect(() => {
|
|
679
|
+
* if (latest) {
|
|
680
|
+
* console.log("New note!", latest.attachment);
|
|
681
|
+
* markHandled(latest.id);
|
|
682
|
+
* }
|
|
683
|
+
* }, [latest, markHandled]);
|
|
684
|
+
*
|
|
685
|
+
* return <div>{notes.length} unhandled notes</div>;
|
|
686
|
+
* }
|
|
687
|
+
* ```
|
|
688
|
+
*/
|
|
689
|
+
declare function useNoteStream(options?: UseNoteStreamOptions): UseNoteStreamReturn;
|
|
690
|
+
|
|
691
|
+
/**
|
|
692
|
+
* Hook to query transaction history and track transaction state.
|
|
693
|
+
*
|
|
694
|
+
* @param options - Optional filter options
|
|
695
|
+
*
|
|
696
|
+
* @example
|
|
697
|
+
* ```tsx
|
|
698
|
+
* function HistoryList() {
|
|
699
|
+
* const { records, isLoading } = useTransactionHistory();
|
|
700
|
+
* if (isLoading) return <div>Loading...</div>;
|
|
701
|
+
* return (
|
|
702
|
+
* <ul>
|
|
703
|
+
* {records.map((record) => (
|
|
704
|
+
* <li key={record.id().toHex()}>{record.id().toHex()}</li>
|
|
705
|
+
* ))}
|
|
706
|
+
* </ul>
|
|
707
|
+
* );
|
|
708
|
+
* }
|
|
709
|
+
* ```
|
|
710
|
+
*/
|
|
711
|
+
declare function useTransactionHistory(options?: TransactionHistoryOptions): TransactionHistoryResult;
|
|
712
|
+
type UseTransactionHistoryResult = TransactionHistoryResult;
|
|
713
|
+
|
|
714
|
+
interface UseSyncStateResult extends SyncState {
|
|
715
|
+
/** Trigger a manual sync */
|
|
716
|
+
sync: () => Promise<void>;
|
|
717
|
+
}
|
|
718
|
+
/**
|
|
719
|
+
* Hook to access sync state and trigger manual syncs.
|
|
720
|
+
*
|
|
721
|
+
* @example
|
|
722
|
+
* ```tsx
|
|
723
|
+
* function SyncStatus() {
|
|
724
|
+
* const { syncHeight, isSyncing, sync } = useSyncState();
|
|
725
|
+
*
|
|
726
|
+
* return (
|
|
727
|
+
* <div>
|
|
728
|
+
* <p>Block height: {syncHeight}</p>
|
|
729
|
+
* <button onClick={sync} disabled={isSyncing}>
|
|
730
|
+
* {isSyncing ? 'Syncing...' : 'Sync'}
|
|
731
|
+
* </button>
|
|
732
|
+
* </div>
|
|
733
|
+
* );
|
|
734
|
+
* }
|
|
735
|
+
* ```
|
|
736
|
+
*/
|
|
737
|
+
declare function useSyncState(): UseSyncStateResult;
|
|
738
|
+
|
|
739
|
+
declare function useAssetMetadata(assetIds?: string[]): {
|
|
740
|
+
assetMetadata: Map<string, AssetMetadata>;
|
|
741
|
+
};
|
|
742
|
+
|
|
743
|
+
interface UseCreateWalletResult {
|
|
744
|
+
/** Create a new wallet with optional configuration */
|
|
745
|
+
createWallet: (options?: CreateWalletOptions) => Promise<Account>;
|
|
746
|
+
/** The created wallet account */
|
|
747
|
+
wallet: Account | null;
|
|
748
|
+
/** Whether wallet creation is in progress */
|
|
749
|
+
isCreating: boolean;
|
|
750
|
+
/** Error if creation failed */
|
|
751
|
+
error: Error | null;
|
|
752
|
+
/** Reset the hook state */
|
|
753
|
+
reset: () => void;
|
|
754
|
+
}
|
|
755
|
+
/**
|
|
756
|
+
* Hook to create a new wallet account.
|
|
757
|
+
*
|
|
758
|
+
* @example
|
|
759
|
+
* ```tsx
|
|
760
|
+
* function CreateWalletButton() {
|
|
761
|
+
* const { createWallet, wallet, isCreating, error } = useCreateWallet();
|
|
762
|
+
*
|
|
763
|
+
* const handleCreate = async () => {
|
|
764
|
+
* const newWallet = await createWallet({
|
|
765
|
+
* storageMode: 'private',
|
|
766
|
+
* mutable: true,
|
|
767
|
+
* });
|
|
768
|
+
* console.log('Created wallet:', newWallet.id().toString());
|
|
769
|
+
* };
|
|
770
|
+
*
|
|
771
|
+
* return (
|
|
772
|
+
* <div>
|
|
773
|
+
* <button onClick={handleCreate} disabled={isCreating}>
|
|
774
|
+
* {isCreating ? 'Creating...' : 'Create Wallet'}
|
|
775
|
+
* </button>
|
|
776
|
+
* {wallet && <p>Created: {wallet.id().toString()}</p>}
|
|
777
|
+
* {error && <p>Error: {error.message}</p>}
|
|
778
|
+
* </div>
|
|
779
|
+
* );
|
|
780
|
+
* }
|
|
781
|
+
* ```
|
|
782
|
+
*/
|
|
783
|
+
declare function useCreateWallet(): UseCreateWalletResult;
|
|
784
|
+
|
|
785
|
+
interface UseCreateFaucetResult {
|
|
786
|
+
/** Create a new faucet with the specified options */
|
|
787
|
+
createFaucet: (options: CreateFaucetOptions) => Promise<Account>;
|
|
788
|
+
/** The created faucet account */
|
|
789
|
+
faucet: Account | null;
|
|
790
|
+
/** Whether faucet creation is in progress */
|
|
791
|
+
isCreating: boolean;
|
|
792
|
+
/** Error if creation failed */
|
|
793
|
+
error: Error | null;
|
|
794
|
+
/** Reset the hook state */
|
|
795
|
+
reset: () => void;
|
|
796
|
+
}
|
|
797
|
+
/**
|
|
798
|
+
* Hook to create a new faucet account.
|
|
799
|
+
*
|
|
800
|
+
* @example
|
|
801
|
+
* ```tsx
|
|
802
|
+
* function CreateFaucetButton() {
|
|
803
|
+
* const { createFaucet, faucet, isCreating, error } = useCreateFaucet();
|
|
804
|
+
*
|
|
805
|
+
* const handleCreate = async () => {
|
|
806
|
+
* const newFaucet = await createFaucet({
|
|
807
|
+
* tokenSymbol: 'TEST',
|
|
808
|
+
* decimals: 8,
|
|
809
|
+
* maxSupply: 1000000n * 10n ** 8n, // 1M tokens
|
|
810
|
+
* });
|
|
811
|
+
* console.log('Created faucet:', newFaucet.id().toString());
|
|
812
|
+
* };
|
|
813
|
+
*
|
|
814
|
+
* return (
|
|
815
|
+
* <div>
|
|
816
|
+
* <button onClick={handleCreate} disabled={isCreating}>
|
|
817
|
+
* {isCreating ? 'Creating...' : 'Create Faucet'}
|
|
818
|
+
* </button>
|
|
819
|
+
* {faucet && <p>Created: {faucet.id().toString()}</p>}
|
|
820
|
+
* {error && <p>Error: {error.message}</p>}
|
|
821
|
+
* </div>
|
|
822
|
+
* );
|
|
823
|
+
* }
|
|
824
|
+
* ```
|
|
825
|
+
*/
|
|
826
|
+
declare function useCreateFaucet(): UseCreateFaucetResult;
|
|
827
|
+
|
|
828
|
+
interface UseImportAccountResult {
|
|
829
|
+
/** Import an existing account into the client */
|
|
830
|
+
importAccount: (options: ImportAccountOptions) => Promise<Account>;
|
|
831
|
+
/** The imported account */
|
|
832
|
+
account: Account | null;
|
|
833
|
+
/** Whether an import is in progress */
|
|
834
|
+
isImporting: boolean;
|
|
835
|
+
/** Error if import failed */
|
|
836
|
+
error: Error | null;
|
|
837
|
+
/** Reset the hook state */
|
|
838
|
+
reset: () => void;
|
|
839
|
+
}
|
|
840
|
+
/**
|
|
841
|
+
* Hook to import existing accounts into the client.
|
|
842
|
+
*
|
|
843
|
+
* @example
|
|
844
|
+
* ```tsx
|
|
845
|
+
* function ImportAccountButton({ accountId }: { accountId: string }) {
|
|
846
|
+
* const { importAccount, isImporting } = useImportAccount();
|
|
847
|
+
*
|
|
848
|
+
* const handleImport = async () => {
|
|
849
|
+
* const account = await importAccount({
|
|
850
|
+
* type: "id",
|
|
851
|
+
* accountId,
|
|
852
|
+
* });
|
|
853
|
+
* console.log("Imported:", account.id().toString());
|
|
854
|
+
* };
|
|
855
|
+
*
|
|
856
|
+
* return (
|
|
857
|
+
* <button onClick={handleImport} disabled={isImporting}>
|
|
858
|
+
* {isImporting ? "Importing..." : "Import Account"}
|
|
859
|
+
* </button>
|
|
860
|
+
* );
|
|
861
|
+
* }
|
|
862
|
+
* ```
|
|
863
|
+
*/
|
|
864
|
+
declare function useImportAccount(): UseImportAccountResult;
|
|
865
|
+
|
|
866
|
+
interface UseSendResult {
|
|
867
|
+
/** Send tokens from one account to another */
|
|
868
|
+
send: (options: SendOptions) => Promise<SendResult>;
|
|
869
|
+
/** The transaction result */
|
|
870
|
+
result: SendResult | null;
|
|
871
|
+
/** Whether the transaction is in progress */
|
|
872
|
+
isLoading: boolean;
|
|
873
|
+
/** Current stage of the transaction */
|
|
874
|
+
stage: TransactionStage;
|
|
875
|
+
/** Error if transaction failed */
|
|
876
|
+
error: Error | null;
|
|
877
|
+
/** Reset the hook state */
|
|
878
|
+
reset: () => void;
|
|
879
|
+
}
|
|
880
|
+
/**
|
|
881
|
+
* Hook to send tokens between accounts.
|
|
882
|
+
*
|
|
883
|
+
* @example
|
|
884
|
+
* ```tsx
|
|
885
|
+
* function SendButton({ from, to, assetId }: Props) {
|
|
886
|
+
* const { send, isLoading, stage, error } = useSend();
|
|
887
|
+
*
|
|
888
|
+
* const handleSend = async () => {
|
|
889
|
+
* try {
|
|
890
|
+
* const result = await send({
|
|
891
|
+
* from,
|
|
892
|
+
* to,
|
|
893
|
+
* assetId,
|
|
894
|
+
* amount: 100n,
|
|
895
|
+
* });
|
|
896
|
+
* console.log('Transaction ID:', result.transactionId);
|
|
897
|
+
* } catch (err) {
|
|
898
|
+
* console.error('Send failed:', err);
|
|
899
|
+
* }
|
|
900
|
+
* };
|
|
901
|
+
*
|
|
902
|
+
* return (
|
|
903
|
+
* <button onClick={handleSend} disabled={isLoading}>
|
|
904
|
+
* {isLoading ? stage : 'Send'}
|
|
905
|
+
* </button>
|
|
906
|
+
* );
|
|
907
|
+
* }
|
|
908
|
+
* ```
|
|
909
|
+
*/
|
|
910
|
+
declare function useSend(): UseSendResult;
|
|
911
|
+
|
|
912
|
+
interface UseMultiSendResult {
|
|
913
|
+
/** Create multiple P2ID output notes in one transaction */
|
|
914
|
+
sendMany: (options: MultiSendOptions) => Promise<TransactionResult>;
|
|
915
|
+
/** The transaction result */
|
|
916
|
+
result: TransactionResult | null;
|
|
917
|
+
/** Whether the transaction is in progress */
|
|
918
|
+
isLoading: boolean;
|
|
919
|
+
/** Current stage of the transaction */
|
|
920
|
+
stage: TransactionStage;
|
|
921
|
+
/** Error if transaction failed */
|
|
922
|
+
error: Error | null;
|
|
923
|
+
/** Reset the hook state */
|
|
924
|
+
reset: () => void;
|
|
925
|
+
}
|
|
926
|
+
/**
|
|
927
|
+
* Hook to create a multi-send transaction (multiple P2ID notes).
|
|
928
|
+
*
|
|
929
|
+
* @example
|
|
930
|
+
* ```tsx
|
|
931
|
+
* function MultiSendButton() {
|
|
932
|
+
* const { sendMany, isLoading, stage } = useMultiSend();
|
|
933
|
+
*
|
|
934
|
+
* const handleSend = async () => {
|
|
935
|
+
* await sendMany({
|
|
936
|
+
* from: "mtst1...",
|
|
937
|
+
* assetId: "0x...",
|
|
938
|
+
* recipients: [
|
|
939
|
+
* { to: "mtst1...", amount: 100n },
|
|
940
|
+
* { to: "0x...", amount: 250n },
|
|
941
|
+
* ],
|
|
942
|
+
* noteType: "public",
|
|
943
|
+
* });
|
|
944
|
+
* };
|
|
945
|
+
*
|
|
946
|
+
* return (
|
|
947
|
+
* <button onClick={handleSend} disabled={isLoading}>
|
|
948
|
+
* {isLoading ? stage : "Multi-send"}
|
|
949
|
+
* </button>
|
|
950
|
+
* );
|
|
951
|
+
* }
|
|
952
|
+
* ```
|
|
953
|
+
*/
|
|
954
|
+
declare function useMultiSend(): UseMultiSendResult;
|
|
955
|
+
|
|
956
|
+
interface UseWaitForCommitResult {
|
|
957
|
+
/** Wait for a transaction to be committed on-chain */
|
|
958
|
+
waitForCommit: (txId: string | TransactionId, options?: WaitForCommitOptions) => Promise<void>;
|
|
959
|
+
}
|
|
960
|
+
declare function useWaitForCommit(): UseWaitForCommitResult;
|
|
961
|
+
|
|
962
|
+
interface UseWaitForNotesResult {
|
|
963
|
+
/** Wait until an account has consumable notes */
|
|
964
|
+
waitForConsumableNotes: (options: WaitForNotesOptions) => Promise<ConsumableNoteRecord[]>;
|
|
965
|
+
}
|
|
966
|
+
declare function useWaitForNotes(): UseWaitForNotesResult;
|
|
967
|
+
|
|
968
|
+
interface UseMintResult {
|
|
969
|
+
/** Mint tokens from a faucet to a target account */
|
|
970
|
+
mint: (options: MintOptions) => Promise<TransactionResult>;
|
|
971
|
+
/** The transaction result */
|
|
972
|
+
result: TransactionResult | null;
|
|
973
|
+
/** Whether the transaction is in progress */
|
|
974
|
+
isLoading: boolean;
|
|
975
|
+
/** Current stage of the transaction */
|
|
976
|
+
stage: TransactionStage;
|
|
977
|
+
/** Error if transaction failed */
|
|
978
|
+
error: Error | null;
|
|
979
|
+
/** Reset the hook state */
|
|
980
|
+
reset: () => void;
|
|
981
|
+
}
|
|
982
|
+
/**
|
|
983
|
+
* Hook to mint tokens from a faucet.
|
|
984
|
+
*
|
|
985
|
+
* @example
|
|
986
|
+
* ```tsx
|
|
987
|
+
* function MintButton({ faucetId, targetAccountId }: Props) {
|
|
988
|
+
* const { mint, isLoading, stage, error } = useMint();
|
|
989
|
+
*
|
|
990
|
+
* const handleMint = async () => {
|
|
991
|
+
* try {
|
|
992
|
+
* const result = await mint({
|
|
993
|
+
* faucetId,
|
|
994
|
+
* targetAccountId,
|
|
995
|
+
* amount: 1000n,
|
|
996
|
+
* });
|
|
997
|
+
* console.log('Minted! TX:', result.transactionId);
|
|
998
|
+
* } catch (err) {
|
|
999
|
+
* console.error('Mint failed:', err);
|
|
1000
|
+
* }
|
|
1001
|
+
* };
|
|
1002
|
+
*
|
|
1003
|
+
* return (
|
|
1004
|
+
* <button onClick={handleMint} disabled={isLoading}>
|
|
1005
|
+
* {isLoading ? stage : 'Mint Tokens'}
|
|
1006
|
+
* </button>
|
|
1007
|
+
* );
|
|
1008
|
+
* }
|
|
1009
|
+
* ```
|
|
1010
|
+
*/
|
|
1011
|
+
declare function useMint(): UseMintResult;
|
|
1012
|
+
|
|
1013
|
+
interface UseConsumeResult {
|
|
1014
|
+
/** Consume one or more notes */
|
|
1015
|
+
consume: (options: ConsumeOptions) => Promise<TransactionResult>;
|
|
1016
|
+
/** The transaction result */
|
|
1017
|
+
result: TransactionResult | null;
|
|
1018
|
+
/** Whether the transaction is in progress */
|
|
1019
|
+
isLoading: boolean;
|
|
1020
|
+
/** Current stage of the transaction */
|
|
1021
|
+
stage: TransactionStage;
|
|
1022
|
+
/** Error if transaction failed */
|
|
1023
|
+
error: Error | null;
|
|
1024
|
+
/** Reset the hook state */
|
|
1025
|
+
reset: () => void;
|
|
1026
|
+
}
|
|
1027
|
+
/**
|
|
1028
|
+
* Hook to consume notes and claim their assets.
|
|
1029
|
+
*
|
|
1030
|
+
* @example
|
|
1031
|
+
* ```tsx
|
|
1032
|
+
* function ConsumeNotesButton({ accountId, notes }: Props) {
|
|
1033
|
+
* const { consume, isLoading, stage, error } = useConsume();
|
|
1034
|
+
*
|
|
1035
|
+
* const handleConsume = async () => {
|
|
1036
|
+
* try {
|
|
1037
|
+
* const result = await consume({
|
|
1038
|
+
* accountId,
|
|
1039
|
+
* notes,
|
|
1040
|
+
* });
|
|
1041
|
+
* console.log('Consumed! TX:', result.transactionId);
|
|
1042
|
+
* } catch (err) {
|
|
1043
|
+
* console.error('Consume failed:', err);
|
|
1044
|
+
* }
|
|
1045
|
+
* };
|
|
1046
|
+
*
|
|
1047
|
+
* return (
|
|
1048
|
+
* <button onClick={handleConsume} disabled={isLoading}>
|
|
1049
|
+
* {isLoading ? stage : 'Claim Notes'}
|
|
1050
|
+
* </button>
|
|
1051
|
+
* );
|
|
1052
|
+
* }
|
|
1053
|
+
* ```
|
|
1054
|
+
*/
|
|
1055
|
+
declare function useConsume(): UseConsumeResult;
|
|
1056
|
+
|
|
1057
|
+
interface UseSwapResult {
|
|
1058
|
+
/** Create an atomic swap offer */
|
|
1059
|
+
swap: (options: SwapOptions) => Promise<TransactionResult>;
|
|
1060
|
+
/** The transaction result */
|
|
1061
|
+
result: TransactionResult | null;
|
|
1062
|
+
/** Whether the transaction is in progress */
|
|
1063
|
+
isLoading: boolean;
|
|
1064
|
+
/** Current stage of the transaction */
|
|
1065
|
+
stage: TransactionStage;
|
|
1066
|
+
/** Error if transaction failed */
|
|
1067
|
+
error: Error | null;
|
|
1068
|
+
/** Reset the hook state */
|
|
1069
|
+
reset: () => void;
|
|
1070
|
+
}
|
|
1071
|
+
/**
|
|
1072
|
+
* Hook to create atomic swap transactions.
|
|
1073
|
+
*
|
|
1074
|
+
* @example
|
|
1075
|
+
* ```tsx
|
|
1076
|
+
* function SwapButton({ accountId }: { accountId: string }) {
|
|
1077
|
+
* const { swap, isLoading, stage, error } = useSwap();
|
|
1078
|
+
*
|
|
1079
|
+
* const handleSwap = async () => {
|
|
1080
|
+
* try {
|
|
1081
|
+
* const result = await swap({
|
|
1082
|
+
* accountId,
|
|
1083
|
+
* offeredFaucetId: '0x...', // Token A
|
|
1084
|
+
* offeredAmount: 100n,
|
|
1085
|
+
* requestedFaucetId: '0x...', // Token B
|
|
1086
|
+
* requestedAmount: 50n,
|
|
1087
|
+
* });
|
|
1088
|
+
* console.log('Swap created! TX:', result.transactionId);
|
|
1089
|
+
* } catch (err) {
|
|
1090
|
+
* console.error('Swap failed:', err);
|
|
1091
|
+
* }
|
|
1092
|
+
* };
|
|
1093
|
+
*
|
|
1094
|
+
* return (
|
|
1095
|
+
* <button onClick={handleSwap} disabled={isLoading}>
|
|
1096
|
+
* {isLoading ? stage : 'Create Swap'}
|
|
1097
|
+
* </button>
|
|
1098
|
+
* );
|
|
1099
|
+
* }
|
|
1100
|
+
* ```
|
|
1101
|
+
*/
|
|
1102
|
+
declare function useSwap(): UseSwapResult;
|
|
1103
|
+
|
|
1104
|
+
interface UseTransactionResult {
|
|
1105
|
+
/** Execute a transaction request end-to-end */
|
|
1106
|
+
execute: (options: ExecuteTransactionOptions) => Promise<TransactionResult>;
|
|
1107
|
+
/** The transaction result */
|
|
1108
|
+
result: TransactionResult | null;
|
|
1109
|
+
/** Whether the transaction is in progress */
|
|
1110
|
+
isLoading: boolean;
|
|
1111
|
+
/** Current stage of the transaction */
|
|
1112
|
+
stage: TransactionStage;
|
|
1113
|
+
/** Error if transaction failed */
|
|
1114
|
+
error: Error | null;
|
|
1115
|
+
/** Reset the hook state */
|
|
1116
|
+
reset: () => void;
|
|
1117
|
+
}
|
|
1118
|
+
/**
|
|
1119
|
+
* Hook to execute arbitrary transaction requests.
|
|
1120
|
+
*
|
|
1121
|
+
* Always uses the 4-step pipeline (execute → prove → submit → apply)
|
|
1122
|
+
* with prover fallback support. When `privateNoteTarget` is set,
|
|
1123
|
+
* additionally waits for commit and delivers private output notes.
|
|
1124
|
+
*
|
|
1125
|
+
* @example
|
|
1126
|
+
* ```tsx
|
|
1127
|
+
* function CustomTransactionButton({ accountId }: { accountId: string }) {
|
|
1128
|
+
* const { execute, isLoading, stage } = useTransaction();
|
|
1129
|
+
*
|
|
1130
|
+
* const handleClick = async () => {
|
|
1131
|
+
* await execute({
|
|
1132
|
+
* accountId,
|
|
1133
|
+
* request: (client) =>
|
|
1134
|
+
* client.newSwapTransactionRequest(
|
|
1135
|
+
* AccountId.fromHex(accountId),
|
|
1136
|
+
* AccountId.fromHex("0x..."),
|
|
1137
|
+
* 10n,
|
|
1138
|
+
* AccountId.fromHex("0x..."),
|
|
1139
|
+
* 5n,
|
|
1140
|
+
* NoteType.Private,
|
|
1141
|
+
* NoteType.Private
|
|
1142
|
+
* ),
|
|
1143
|
+
* privateNoteTarget: "0xrecipient...",
|
|
1144
|
+
* });
|
|
1145
|
+
* };
|
|
1146
|
+
*
|
|
1147
|
+
* return (
|
|
1148
|
+
* <button onClick={handleClick} disabled={isLoading}>
|
|
1149
|
+
* {isLoading ? stage : "Run Transaction"}
|
|
1150
|
+
* </button>
|
|
1151
|
+
* );
|
|
1152
|
+
* }
|
|
1153
|
+
* ```
|
|
1154
|
+
*/
|
|
1155
|
+
declare function useTransaction(): UseTransactionResult;
|
|
1156
|
+
|
|
1157
|
+
interface UseExecuteProgramResult {
|
|
1158
|
+
/** Execute a program (view call) and return the stack output */
|
|
1159
|
+
execute: (options: ExecuteProgramOptions) => Promise<ExecuteProgramResult>;
|
|
1160
|
+
/** The most recent result */
|
|
1161
|
+
result: ExecuteProgramResult | null;
|
|
1162
|
+
/** Whether execution is in progress */
|
|
1163
|
+
isLoading: boolean;
|
|
1164
|
+
/** Error if execution failed */
|
|
1165
|
+
error: Error | null;
|
|
1166
|
+
/** Reset the hook state */
|
|
1167
|
+
reset: () => void;
|
|
1168
|
+
}
|
|
1169
|
+
declare function useExecuteProgram(): UseExecuteProgramResult;
|
|
1170
|
+
|
|
1171
|
+
interface UseCompileResult {
|
|
1172
|
+
/** Compile MASM source into an AccountComponent. */
|
|
1173
|
+
component: (options: CompileComponentOptions) => Promise<AccountComponent>;
|
|
1174
|
+
/** Compile MASM source into a TransactionScript. */
|
|
1175
|
+
txScript: (options: CompileTxScriptOptions) => Promise<TransactionScript>;
|
|
1176
|
+
/** Compile MASM source into a NoteScript. */
|
|
1177
|
+
noteScript: (options: CompileNoteScriptOptions) => Promise<NoteScript>;
|
|
1178
|
+
/** Whether the underlying client is ready to compile. */
|
|
1179
|
+
isReady: boolean;
|
|
1180
|
+
}
|
|
1181
|
+
/**
|
|
1182
|
+
* Hook for compiling MASM source into `AccountComponent`, `TransactionScript`,
|
|
1183
|
+
* or `NoteScript`. Wraps `CompilerResource` from `@miden-sdk/miden-sdk` so the
|
|
1184
|
+
* shape is identical to `MidenClient.compile`.
|
|
1185
|
+
*
|
|
1186
|
+
* @example
|
|
1187
|
+
* ```tsx
|
|
1188
|
+
* const { noteScript, isReady } = useCompile();
|
|
1189
|
+
*
|
|
1190
|
+
* const script = await noteScript({
|
|
1191
|
+
* code: noteSource,
|
|
1192
|
+
* libraries: [{ namespace: "my_lib", code: libSource, linking: Linking.Dynamic }],
|
|
1193
|
+
* });
|
|
1194
|
+
* ```
|
|
1195
|
+
*/
|
|
1196
|
+
declare function useCompile(): UseCompileResult;
|
|
1197
|
+
|
|
1198
|
+
/**
|
|
1199
|
+
* Hook to manage a session wallet lifecycle: create -> fund -> consume.
|
|
1200
|
+
*
|
|
1201
|
+
* Replaces the common 300+ line pattern of creating a temporary wallet,
|
|
1202
|
+
* waiting for funding, and consuming the funding note.
|
|
1203
|
+
*
|
|
1204
|
+
* @example
|
|
1205
|
+
* ```tsx
|
|
1206
|
+
* function SessionWallet() {
|
|
1207
|
+
* const { initialize, sessionAccountId, isReady, step, error, reset } =
|
|
1208
|
+
* useSessionAccount({
|
|
1209
|
+
* fund: async (sessionId) => {
|
|
1210
|
+
* // Send tokens from main wallet to session wallet
|
|
1211
|
+
* await send({ from: mainWalletId, to: sessionId, assetId, amount: 100n });
|
|
1212
|
+
* },
|
|
1213
|
+
* assetId: "0x...",
|
|
1214
|
+
* });
|
|
1215
|
+
*
|
|
1216
|
+
* if (error) return <div>Error: {error.message} <button onClick={reset}>Retry</button></div>;
|
|
1217
|
+
* if (isReady) return <div>Session ready: {sessionAccountId}</div>;
|
|
1218
|
+
*
|
|
1219
|
+
* return (
|
|
1220
|
+
* <button onClick={initialize} disabled={step !== "idle"}>
|
|
1221
|
+
* {step === "idle" ? "Start Session" : step}
|
|
1222
|
+
* </button>
|
|
1223
|
+
* );
|
|
1224
|
+
* }
|
|
1225
|
+
* ```
|
|
1226
|
+
*/
|
|
1227
|
+
declare function useSessionAccount(options: UseSessionAccountOptions): UseSessionAccountReturn;
|
|
1228
|
+
|
|
1229
|
+
interface UseExportStoreResult {
|
|
1230
|
+
/** Export the IndexedDB store as a JSON string */
|
|
1231
|
+
exportStore: () => Promise<string>;
|
|
1232
|
+
/** Whether the export is in progress */
|
|
1233
|
+
isExporting: boolean;
|
|
1234
|
+
/** Error if export failed */
|
|
1235
|
+
error: Error | null;
|
|
1236
|
+
/** Reset the hook state */
|
|
1237
|
+
reset: () => void;
|
|
1238
|
+
}
|
|
1239
|
+
/**
|
|
1240
|
+
* Hook to export the IndexedDB store for backup/restore.
|
|
1241
|
+
*
|
|
1242
|
+
* @example
|
|
1243
|
+
* ```tsx
|
|
1244
|
+
* function BackupButton() {
|
|
1245
|
+
* const { exportStore, isExporting, error } = useExportStore();
|
|
1246
|
+
*
|
|
1247
|
+
* const handleBackup = async () => {
|
|
1248
|
+
* const snapshot = await exportStore();
|
|
1249
|
+
* // Save snapshot to file, encrypted storage, etc.
|
|
1250
|
+
* };
|
|
1251
|
+
*
|
|
1252
|
+
* return (
|
|
1253
|
+
* <button onClick={handleBackup} disabled={isExporting}>
|
|
1254
|
+
* {isExporting ? 'Exporting...' : 'Backup Wallet'}
|
|
1255
|
+
* </button>
|
|
1256
|
+
* );
|
|
1257
|
+
* }
|
|
1258
|
+
* ```
|
|
1259
|
+
*/
|
|
1260
|
+
declare function useExportStore(): UseExportStoreResult;
|
|
1261
|
+
|
|
1262
|
+
interface ImportStoreOptions {
|
|
1263
|
+
/** Skip auto-sync after import. Default: false */
|
|
1264
|
+
skipSync?: boolean;
|
|
1265
|
+
}
|
|
1266
|
+
interface UseImportStoreResult {
|
|
1267
|
+
/** Import a previously exported store dump */
|
|
1268
|
+
importStore: (storeDump: string, storeName: string, options?: ImportStoreOptions) => Promise<void>;
|
|
1269
|
+
/** Whether the import is in progress */
|
|
1270
|
+
isImporting: boolean;
|
|
1271
|
+
/** Error if import failed */
|
|
1272
|
+
error: Error | null;
|
|
1273
|
+
/** Reset the hook state */
|
|
1274
|
+
reset: () => void;
|
|
1275
|
+
}
|
|
1276
|
+
/**
|
|
1277
|
+
* Hook to import a previously exported IndexedDB store for restore.
|
|
1278
|
+
*
|
|
1279
|
+
* @example
|
|
1280
|
+
* ```tsx
|
|
1281
|
+
* function RestoreButton({ snapshot }: { snapshot: string }) {
|
|
1282
|
+
* const { importStore, isImporting, error } = useImportStore();
|
|
1283
|
+
*
|
|
1284
|
+
* const handleRestore = async () => {
|
|
1285
|
+
* await importStore(snapshot, 'RestoredStore');
|
|
1286
|
+
* // Store has been restored — sync or reload
|
|
1287
|
+
* };
|
|
1288
|
+
*
|
|
1289
|
+
* return (
|
|
1290
|
+
* <button onClick={handleRestore} disabled={isImporting}>
|
|
1291
|
+
* {isImporting ? 'Restoring...' : 'Restore Wallet'}
|
|
1292
|
+
* </button>
|
|
1293
|
+
* );
|
|
1294
|
+
* }
|
|
1295
|
+
* ```
|
|
1296
|
+
*/
|
|
1297
|
+
declare function useImportStore(): UseImportStoreResult;
|
|
1298
|
+
|
|
1299
|
+
interface UseImportNoteResult {
|
|
1300
|
+
/** Import a note from serialized bytes (e.g. from QR code or dApp request) */
|
|
1301
|
+
importNote: (noteBytes: Uint8Array) => Promise<string>;
|
|
1302
|
+
/** Whether the import is in progress */
|
|
1303
|
+
isImporting: boolean;
|
|
1304
|
+
/** Error if import failed */
|
|
1305
|
+
error: Error | null;
|
|
1306
|
+
/** Reset the hook state */
|
|
1307
|
+
reset: () => void;
|
|
1308
|
+
}
|
|
1309
|
+
/**
|
|
1310
|
+
* Hook to import a note from serialized NoteFile bytes.
|
|
1311
|
+
*
|
|
1312
|
+
* @example
|
|
1313
|
+
* ```tsx
|
|
1314
|
+
* function ImportNoteButton({ noteBytes }: { noteBytes: Uint8Array }) {
|
|
1315
|
+
* const { importNote, isImporting, error } = useImportNote();
|
|
1316
|
+
*
|
|
1317
|
+
* const handleImport = async () => {
|
|
1318
|
+
* const noteId = await importNote(noteBytes);
|
|
1319
|
+
* console.log('Imported note:', noteId);
|
|
1320
|
+
* };
|
|
1321
|
+
*
|
|
1322
|
+
* return (
|
|
1323
|
+
* <button onClick={handleImport} disabled={isImporting}>
|
|
1324
|
+
* {isImporting ? 'Importing...' : 'Import Note'}
|
|
1325
|
+
* </button>
|
|
1326
|
+
* );
|
|
1327
|
+
* }
|
|
1328
|
+
* ```
|
|
1329
|
+
*/
|
|
1330
|
+
declare function useImportNote(): UseImportNoteResult;
|
|
1331
|
+
|
|
1332
|
+
interface UseExportNoteResult {
|
|
1333
|
+
/** Export a note as serialized bytes */
|
|
1334
|
+
exportNote: (noteId: string) => Promise<Uint8Array>;
|
|
1335
|
+
/** Whether the export is in progress */
|
|
1336
|
+
isExporting: boolean;
|
|
1337
|
+
/** Error if export failed */
|
|
1338
|
+
error: Error | null;
|
|
1339
|
+
/** Reset the hook state */
|
|
1340
|
+
reset: () => void;
|
|
1341
|
+
}
|
|
1342
|
+
/**
|
|
1343
|
+
* Hook to export a note as serialized NoteFile bytes.
|
|
1344
|
+
*
|
|
1345
|
+
* @example
|
|
1346
|
+
* ```tsx
|
|
1347
|
+
* function ExportNoteButton({ noteId }: { noteId: string }) {
|
|
1348
|
+
* const { exportNote, isExporting, error } = useExportNote();
|
|
1349
|
+
*
|
|
1350
|
+
* const handleExport = async () => {
|
|
1351
|
+
* const bytes = await exportNote(noteId);
|
|
1352
|
+
* // Share bytes via QR code, file download, etc.
|
|
1353
|
+
* };
|
|
1354
|
+
*
|
|
1355
|
+
* return (
|
|
1356
|
+
* <button onClick={handleExport} disabled={isExporting}>
|
|
1357
|
+
* {isExporting ? 'Exporting...' : 'Export Note'}
|
|
1358
|
+
* </button>
|
|
1359
|
+
* );
|
|
1360
|
+
* }
|
|
1361
|
+
* ```
|
|
1362
|
+
*/
|
|
1363
|
+
declare function useExportNote(): UseExportNoteResult;
|
|
1364
|
+
|
|
1365
|
+
interface UseSyncControlResult {
|
|
1366
|
+
/** Pause auto-sync. Manual sync via useSyncState().sync() still works. */
|
|
1367
|
+
pauseSync: () => void;
|
|
1368
|
+
/** Resume auto-sync. */
|
|
1369
|
+
resumeSync: () => void;
|
|
1370
|
+
/** Whether auto-sync is currently paused. */
|
|
1371
|
+
isPaused: boolean;
|
|
1372
|
+
}
|
|
1373
|
+
/**
|
|
1374
|
+
* Hook to pause and resume the automatic background sync.
|
|
1375
|
+
*
|
|
1376
|
+
* Useful during long-running operations (e.g. transaction proving) where
|
|
1377
|
+
* sync would compete for the WASM lock, or when the app is in the background.
|
|
1378
|
+
*
|
|
1379
|
+
* @example
|
|
1380
|
+
* ```tsx
|
|
1381
|
+
* function SyncToggle() {
|
|
1382
|
+
* const { pauseSync, resumeSync, isPaused } = useSyncControl();
|
|
1383
|
+
*
|
|
1384
|
+
* return (
|
|
1385
|
+
* <button onClick={isPaused ? resumeSync : pauseSync}>
|
|
1386
|
+
* {isPaused ? 'Resume Sync' : 'Pause Sync'}
|
|
1387
|
+
* </button>
|
|
1388
|
+
* );
|
|
1389
|
+
* }
|
|
1390
|
+
* ```
|
|
1391
|
+
*/
|
|
1392
|
+
declare function useSyncControl(): UseSyncControlResult;
|
|
1393
|
+
|
|
1394
|
+
declare const toBech32AccountId: (accountId: string) => string;
|
|
1395
|
+
|
|
1396
|
+
declare const formatAssetAmount: (amount: bigint | number, decimals?: number) => string;
|
|
1397
|
+
declare const parseAssetAmount: (input: string, decimals?: number) => bigint;
|
|
1398
|
+
|
|
1399
|
+
declare const getNoteSummary: (note: ConsumableNoteRecord | InputNoteRecord, getAssetMetadata?: (assetId: string) => AssetMetadata | undefined) => NoteSummary | null;
|
|
1400
|
+
declare const formatNoteSummary: (summary: NoteSummary, formatAsset?: (asset: NoteAsset) => string) => string;
|
|
1401
|
+
|
|
1402
|
+
/**
|
|
1403
|
+
* Normalize any account ID format (hex, bech32, 0x-prefixed) to bech32.
|
|
1404
|
+
* Returns the original string if conversion fails.
|
|
1405
|
+
*/
|
|
1406
|
+
declare function normalizeAccountId(id: string): string;
|
|
1407
|
+
/**
|
|
1408
|
+
* Compare two account IDs for equality regardless of format (hex vs bech32).
|
|
1409
|
+
* Parses both to AccountId objects and compares their hex representations.
|
|
1410
|
+
*/
|
|
1411
|
+
declare function accountIdsEqual(a: string, b: string): boolean;
|
|
1412
|
+
|
|
1413
|
+
interface NoteAttachmentData {
|
|
1414
|
+
values: bigint[];
|
|
1415
|
+
kind: "word" | "array";
|
|
1416
|
+
}
|
|
1417
|
+
/**
|
|
1418
|
+
* Decode a note's attachment. Returns null if no attachment.
|
|
1419
|
+
*/
|
|
1420
|
+
declare function readNoteAttachment(note: InputNoteRecord): NoteAttachmentData | null;
|
|
1421
|
+
/**
|
|
1422
|
+
* Encode values into a NoteAttachment.
|
|
1423
|
+
* <= 4 values -> Word (avoids miden-standards 0.13.x Array advice-map bug).
|
|
1424
|
+
* > 4 values -> Array.
|
|
1425
|
+
*
|
|
1426
|
+
* Note: Values are padded to word boundaries (multiples of 4) with trailing 0n.
|
|
1427
|
+
* `readNoteAttachment` returns raw values including padding. Consumers should
|
|
1428
|
+
* strip trailing zeros if they need the original unpadded values.
|
|
1429
|
+
*/
|
|
1430
|
+
declare function createNoteAttachment(values: bigint[] | Uint8Array | number[]): NoteAttachment;
|
|
1431
|
+
|
|
1432
|
+
declare function bytesToBigInt(bytes: Uint8Array): bigint;
|
|
1433
|
+
declare function bigIntToBytes(value: bigint, length: number): Uint8Array;
|
|
1434
|
+
declare function concatBytes(...arrays: Uint8Array[]): Uint8Array;
|
|
1435
|
+
|
|
1436
|
+
type MidenErrorCode = "WASM_CLASS_MISMATCH" | "WASM_POINTER_CONSUMED" | "WASM_NOT_INITIALIZED" | "WASM_SYNC_REQUIRED" | "SEND_BUSY" | "OPERATION_BUSY" | "UNKNOWN";
|
|
1437
|
+
declare class MidenError extends Error {
|
|
1438
|
+
readonly code: MidenErrorCode;
|
|
1439
|
+
readonly cause?: unknown;
|
|
1440
|
+
constructor(message: string, options?: {
|
|
1441
|
+
cause?: unknown;
|
|
1442
|
+
code?: MidenErrorCode;
|
|
1443
|
+
});
|
|
1444
|
+
}
|
|
1445
|
+
declare function wrapWasmError(e: unknown): Error;
|
|
1446
|
+
|
|
1447
|
+
/** Minimal adapter shape (duck-typed, no dependency on wallet-adapter-base) */
|
|
1448
|
+
interface WalletAdapterLike {
|
|
1449
|
+
readyState: string;
|
|
1450
|
+
on(event: "readyStateChange", cb: (state: string) => void): void;
|
|
1451
|
+
off(event: "readyStateChange", cb: (state: string) => void): void;
|
|
1452
|
+
}
|
|
1453
|
+
/**
|
|
1454
|
+
* Wait for a wallet adapter to reach "Installed" readyState.
|
|
1455
|
+
* Returns immediately if already installed. Otherwise listens
|
|
1456
|
+
* for readyStateChange events with a timeout.
|
|
1457
|
+
*
|
|
1458
|
+
* @example
|
|
1459
|
+
* ```ts
|
|
1460
|
+
* const adapter = wallets[0].adapter;
|
|
1461
|
+
* await waitForWalletDetection(adapter); // default 5s timeout
|
|
1462
|
+
* await waitForWalletDetection(adapter, 10000); // 10s timeout
|
|
1463
|
+
* ```
|
|
1464
|
+
*/
|
|
1465
|
+
declare function waitForWalletDetection(adapter: WalletAdapterLike, timeoutMs?: number): Promise<void>;
|
|
1466
|
+
|
|
1467
|
+
interface MigrateStorageOptions {
|
|
1468
|
+
/** Current version string to compare against stored version */
|
|
1469
|
+
version: string;
|
|
1470
|
+
/** localStorage key for version tracking. Default: "miden:storageVersion" */
|
|
1471
|
+
versionKey?: string;
|
|
1472
|
+
/** Callback before clearing storage (e.g., to save data) */
|
|
1473
|
+
onBeforeClear?: () => void | Promise<void>;
|
|
1474
|
+
/** Reload page after clearing. Default: true */
|
|
1475
|
+
reloadOnClear?: boolean;
|
|
1476
|
+
}
|
|
1477
|
+
/**
|
|
1478
|
+
* Check if stored version matches current version. If not, clear Miden IndexedDB
|
|
1479
|
+
* databases and localStorage, then optionally reload.
|
|
1480
|
+
* Returns true if migration was triggered.
|
|
1481
|
+
*/
|
|
1482
|
+
declare function migrateStorage(options: MigrateStorageOptions): Promise<boolean>;
|
|
1483
|
+
/**
|
|
1484
|
+
* Clear all Miden-related IndexedDB databases.
|
|
1485
|
+
*/
|
|
1486
|
+
declare function clearMidenStorage(): Promise<void>;
|
|
1487
|
+
/**
|
|
1488
|
+
* Create a namespaced localStorage helper for app state persistence.
|
|
1489
|
+
*/
|
|
1490
|
+
declare function createMidenStorage(prefix: string): {
|
|
1491
|
+
get<T>(key: string): T | null;
|
|
1492
|
+
set<T>(key: string, value: T): void;
|
|
1493
|
+
remove(key: string): void;
|
|
1494
|
+
clear(): void;
|
|
1495
|
+
};
|
|
1496
|
+
|
|
1497
|
+
export { type AccountRef, type AccountResult, type AccountsResult, type AssetBalance, type AssetMetadata, type ConsumeOptions, type CreateFaucetOptions, type CreateWalletOptions, DEFAULTS, type ExecuteProgramOptions, type ExecuteProgramResult, type ExecuteTransactionOptions, type ImportAccountOptions, type ImportStoreOptions, type MidenConfig, MidenError, type MidenErrorCode, MidenProvider, type MidenState, type MigrateStorageOptions, type MintOptions, type MultiSendOptions, type MultiSendRecipient, type MultiSignerContextValue, MultiSignerProvider, type MutationResult, type NoteAsset, type NoteAttachmentData, type NoteSummary, type NotesFilter, type NotesResult, type ProverConfig, type ProverTarget, type ProverUrls, type QueryResult, type RpcUrlConfig, type SendOptions, type SendResult, type SessionAccountStep, type SignCallback, type SignerAccountConfig, type SignerAccountType, SignerContext, type SignerContextValue, SignerSlot, type StreamedNote, type SwapOptions, type SyncState, type TransactionHistoryOptions, type TransactionHistoryResult, type TransactionResult, type TransactionStage, type TransactionStatus, type UseCompileResult, type UseConsumeResult, type UseCreateFaucetResult, type UseCreateWalletResult, type UseExecuteProgramResult, type UseExportNoteResult, type UseExportStoreResult, type UseImportAccountResult, type UseImportNoteResult, type UseImportStoreResult, type UseMintResult, type UseMultiSendResult, type UseNoteStreamOptions, type UseNoteStreamReturn, type UseSendResult, type UseSessionAccountOptions, type UseSessionAccountReturn, type UseSwapResult, type UseSyncControlResult, type UseSyncStateResult, type UseTransactionHistoryResult, type UseTransactionResult, type UseWaitForCommitResult, type UseWaitForNotesResult, type WaitForCommitOptions, type WaitForNotesOptions, type WalletAdapterLike, accountIdsEqual, bigIntToBytes, bytesToBigInt, clearMidenStorage, concatBytes, createMidenStorage, createNoteAttachment, formatAssetAmount, formatNoteSummary, getNoteSummary, migrateStorage, normalizeAccountId, parseAssetAmount, readNoteAttachment, toBech32AccountId, useAccount, useAccounts, useAssetMetadata, useCompile, useConsume, useCreateFaucet, useCreateWallet, useExecuteProgram, useExportNote, useExportStore, useImportAccount, useImportNote, useImportStore, useMiden, useMidenClient, useMint, useMultiSend, useMultiSigner, useNoteStream, useNotes, useSend, useSessionAccount, useSigner, useSwap, useSyncControl, useSyncState, useTransaction, useTransactionHistory, useWaitForCommit, useWaitForNotes, waitForWalletDetection, wrapWasmError };
|