@miden-sdk/react 0.13.0

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.
@@ -0,0 +1,927 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { ReactNode } from 'react';
3
+ import { Account, AccountHeader, AccountId, TransactionRequest, WebClient, AccountFile, InputNoteRecord, ConsumableNoteRecord, TransactionId, TransactionFilter, TransactionRecord, TransactionProver } from '@miden-sdk/miden-sdk';
4
+ export { Account, AccountFile, AccountHeader, AccountId, AccountStorageMode, ConsumableNoteRecord, InputNoteRecord, NoteType, TransactionFilter, TransactionId, TransactionRecord, TransactionRequest, WebClient } from '@miden-sdk/miden-sdk';
5
+
6
+ declare module "@miden-sdk/miden-sdk" {
7
+ interface Account {
8
+ /** Returns the bech32-encoded account id using the configured network. */
9
+ bech32id(): string;
10
+ }
11
+ }
12
+
13
+ type RpcUrlConfig = string | "devnet" | "testnet" | "localhost" | "local";
14
+ type ProverConfig = "local" | "devnet" | "testnet" | string | {
15
+ url: string;
16
+ timeoutMs?: number | bigint;
17
+ };
18
+ type ProverUrls = {
19
+ devnet?: string;
20
+ testnet?: string;
21
+ };
22
+ interface MidenConfig {
23
+ /** RPC node URL or network name (devnet/testnet/localhost). Defaults to testnet. */
24
+ rpcUrl?: RpcUrlConfig;
25
+ /** Note transport URL for streaming notes. */
26
+ noteTransportUrl?: string;
27
+ /** Auto-sync interval in milliseconds. Set to 0 to disable. Default: 15000ms */
28
+ autoSyncInterval?: number;
29
+ /** Initial seed for deterministic RNG (must be 32 bytes if provided) */
30
+ seed?: Uint8Array;
31
+ /** Transaction prover selection (local/devnet/testnet or a remote URL). */
32
+ prover?: ProverConfig;
33
+ /** Optional override URLs for network provers. */
34
+ proverUrls?: ProverUrls;
35
+ /** Default timeout for remote prover requests in milliseconds. */
36
+ proverTimeoutMs?: number | bigint;
37
+ }
38
+ interface MidenState {
39
+ client: WebClient | null;
40
+ isReady: boolean;
41
+ isInitializing: boolean;
42
+ error: Error | null;
43
+ }
44
+ type TransactionStage = "idle" | "executing" | "proving" | "submitting" | "complete";
45
+ interface QueryResult<T> {
46
+ data: T | null;
47
+ isLoading: boolean;
48
+ error: Error | null;
49
+ refetch: () => Promise<void>;
50
+ }
51
+ interface MutationResult<TData, TVariables> {
52
+ mutate: (variables: TVariables) => Promise<TData>;
53
+ data: TData | null;
54
+ isLoading: boolean;
55
+ stage: TransactionStage;
56
+ error: Error | null;
57
+ reset: () => void;
58
+ }
59
+ interface SyncState {
60
+ syncHeight: number;
61
+ isSyncing: boolean;
62
+ lastSyncTime: number | null;
63
+ error: Error | null;
64
+ }
65
+ interface AccountsResult {
66
+ accounts: AccountHeader[];
67
+ wallets: AccountHeader[];
68
+ faucets: AccountHeader[];
69
+ isLoading: boolean;
70
+ error: Error | null;
71
+ refetch: () => Promise<void>;
72
+ }
73
+ interface AccountResult {
74
+ account: Account | null;
75
+ assets: AssetBalance[];
76
+ isLoading: boolean;
77
+ error: Error | null;
78
+ refetch: () => Promise<void>;
79
+ getBalance: (assetId: string) => bigint;
80
+ }
81
+ interface AssetBalance {
82
+ assetId: string;
83
+ amount: bigint;
84
+ symbol?: string;
85
+ decimals?: number;
86
+ }
87
+ interface NotesFilter {
88
+ status?: "all" | "consumed" | "committed" | "expected" | "processing";
89
+ accountId?: string;
90
+ }
91
+ interface NotesResult {
92
+ notes: InputNoteRecord[];
93
+ consumableNotes: ConsumableNoteRecord[];
94
+ noteSummaries: NoteSummary[];
95
+ consumableNoteSummaries: NoteSummary[];
96
+ isLoading: boolean;
97
+ error: Error | null;
98
+ refetch: () => Promise<void>;
99
+ }
100
+ type TransactionStatus = "pending" | "committed" | "discarded";
101
+ interface TransactionHistoryOptions {
102
+ /** Single transaction ID to look up. */
103
+ id?: string | TransactionId;
104
+ /** List of transaction IDs to look up. */
105
+ ids?: Array<string | TransactionId>;
106
+ /** Custom transaction filter (overrides id/ids). */
107
+ filter?: TransactionFilter;
108
+ /** Refresh after provider syncs. Default: true */
109
+ refreshOnSync?: boolean;
110
+ }
111
+ interface TransactionHistoryResult {
112
+ records: TransactionRecord[];
113
+ /** Convenience record when a single ID is provided. */
114
+ record: TransactionRecord | null;
115
+ /** Convenience status when a single ID is provided. */
116
+ status: TransactionStatus | null;
117
+ isLoading: boolean;
118
+ error: Error | null;
119
+ refetch: () => Promise<void>;
120
+ }
121
+ interface AssetMetadata {
122
+ assetId: string;
123
+ symbol?: string;
124
+ decimals?: number;
125
+ }
126
+ interface NoteAsset {
127
+ assetId: string;
128
+ amount: bigint;
129
+ symbol?: string;
130
+ decimals?: number;
131
+ }
132
+ interface NoteSummary {
133
+ id: string;
134
+ assets: NoteAsset[];
135
+ sender?: string;
136
+ }
137
+ interface CreateWalletOptions {
138
+ /** Storage mode. Default: private */
139
+ storageMode?: "private" | "public" | "network";
140
+ /** Whether code can be updated. Default: true */
141
+ mutable?: boolean;
142
+ /** Auth scheme: 0 = RpoFalcon512, 1 = EcdsaK256Keccak. Default: 0 */
143
+ authScheme?: 0 | 1;
144
+ /** Initial seed for deterministic account ID */
145
+ initSeed?: Uint8Array;
146
+ }
147
+ interface CreateFaucetOptions {
148
+ /** Token symbol (e.g., "TEST") */
149
+ tokenSymbol: string;
150
+ /** Number of decimals. Default: 8 */
151
+ decimals?: number;
152
+ /** Maximum supply */
153
+ maxSupply: bigint;
154
+ /** Storage mode. Default: private */
155
+ storageMode?: "private" | "public" | "network";
156
+ /** Auth scheme: 0 = RpoFalcon512, 1 = EcdsaK256Keccak. Default: 0 */
157
+ authScheme?: 0 | 1;
158
+ }
159
+ type ImportAccountOptions = {
160
+ type: "file";
161
+ file: AccountFile | Uint8Array | ArrayBuffer;
162
+ } | {
163
+ type: "id";
164
+ accountId: string | AccountId;
165
+ } | {
166
+ type: "seed";
167
+ seed: Uint8Array;
168
+ mutable?: boolean;
169
+ authScheme?: 0 | 1;
170
+ };
171
+ interface SendOptions {
172
+ /** Sender account ID */
173
+ from: string;
174
+ /** Recipient account ID */
175
+ to: string;
176
+ /** Asset ID to send (token id) */
177
+ assetId: string;
178
+ /** Amount to send */
179
+ amount: bigint;
180
+ /** Note type. Default: private */
181
+ noteType?: "private" | "public" | "encrypted";
182
+ /** Block height after which sender can reclaim note */
183
+ recallHeight?: number;
184
+ /** Block height after which recipient can consume note */
185
+ timelockHeight?: number;
186
+ }
187
+ interface MultiSendRecipient {
188
+ /** Recipient account ID */
189
+ to: string;
190
+ /** Amount to send */
191
+ amount: bigint;
192
+ }
193
+ interface MultiSendOptions {
194
+ /** Sender account ID */
195
+ from: string;
196
+ /** Asset ID to send (token id) */
197
+ assetId: string;
198
+ /** Recipient list */
199
+ recipients: MultiSendRecipient[];
200
+ /** Note type. Default: private */
201
+ noteType?: "private" | "public" | "encrypted";
202
+ }
203
+ interface InternalTransferOptions {
204
+ /** Sender account ID */
205
+ from: string;
206
+ /** Recipient account ID */
207
+ to: string;
208
+ /** Asset ID to send (token id) */
209
+ assetId: string;
210
+ /** Amount to transfer */
211
+ amount: bigint;
212
+ /** Note type. Default: private */
213
+ noteType?: "private" | "public" | "encrypted";
214
+ }
215
+ interface InternalTransferChainOptions {
216
+ /** Initial sender account ID */
217
+ from: string;
218
+ /** Ordered list of recipient account IDs */
219
+ recipients: string[];
220
+ /** Asset ID to send (token id) */
221
+ assetId: string;
222
+ /** Amount to transfer per hop */
223
+ amount: bigint;
224
+ /** Note type. Default: private */
225
+ noteType?: "private" | "public" | "encrypted";
226
+ }
227
+ interface InternalTransferResult {
228
+ createTransactionId: string;
229
+ consumeTransactionId: string;
230
+ noteId: string;
231
+ }
232
+ interface WaitForCommitOptions {
233
+ /** Timeout in milliseconds. Default: 10000 */
234
+ timeoutMs?: number;
235
+ /** Polling interval in milliseconds. Default: 1000 */
236
+ intervalMs?: number;
237
+ }
238
+ interface WaitForNotesOptions {
239
+ /** Account ID to check for consumable notes */
240
+ accountId: string;
241
+ /** Minimum number of notes to wait for. Default: 1 */
242
+ minCount?: number;
243
+ /** Timeout in milliseconds. Default: 10000 */
244
+ timeoutMs?: number;
245
+ /** Polling interval in milliseconds. Default: 1000 */
246
+ intervalMs?: number;
247
+ }
248
+ interface MintOptions {
249
+ /** Target account to receive minted tokens */
250
+ targetAccountId: string;
251
+ /** Faucet account to mint from */
252
+ faucetId: string;
253
+ /** Amount to mint */
254
+ amount: bigint;
255
+ /** Note type. Default: private */
256
+ noteType?: "private" | "public" | "encrypted";
257
+ }
258
+ interface ConsumeOptions {
259
+ /** Account ID that will consume the notes */
260
+ accountId: string;
261
+ /** List of note IDs to consume */
262
+ noteIds: string[];
263
+ }
264
+ interface SwapOptions {
265
+ /** Account initiating the swap */
266
+ accountId: string;
267
+ /** Faucet ID of the offered asset */
268
+ offeredFaucetId: string;
269
+ /** Amount being offered */
270
+ offeredAmount: bigint;
271
+ /** Faucet ID of the requested asset */
272
+ requestedFaucetId: string;
273
+ /** Amount being requested */
274
+ requestedAmount: bigint;
275
+ /** Note type for swap note. Default: private */
276
+ noteType?: "private" | "public" | "encrypted";
277
+ /** Note type for payback note. Default: private */
278
+ paybackNoteType?: "private" | "public" | "encrypted";
279
+ }
280
+ interface ExecuteTransactionOptions {
281
+ /** Account ID the transaction applies to */
282
+ accountId: string | AccountId;
283
+ /** Transaction request or builder */
284
+ request: TransactionRequest | ((client: WebClient) => TransactionRequest | Promise<TransactionRequest>);
285
+ }
286
+ interface TransactionResult {
287
+ transactionId: string;
288
+ }
289
+ declare const DEFAULTS: {
290
+ readonly RPC_URL: undefined;
291
+ readonly AUTO_SYNC_INTERVAL: 15000;
292
+ readonly STORAGE_MODE: "private";
293
+ readonly WALLET_MUTABLE: true;
294
+ readonly AUTH_SCHEME: 0;
295
+ readonly NOTE_TYPE: "private";
296
+ readonly FAUCET_DECIMALS: 8;
297
+ };
298
+
299
+ type ProverConfigSubset = Pick<MidenConfig, "prover" | "proverUrls" | "proverTimeoutMs">;
300
+ declare function resolveTransactionProver(config: ProverConfigSubset): TransactionProver | null;
301
+
302
+ interface MidenContextValue {
303
+ client: WebClient | null;
304
+ isReady: boolean;
305
+ isInitializing: boolean;
306
+ error: Error | null;
307
+ sync: () => Promise<void>;
308
+ runExclusive: <T>(fn: () => Promise<T>) => Promise<T>;
309
+ prover: ReturnType<typeof resolveTransactionProver>;
310
+ }
311
+ interface MidenProviderProps {
312
+ children: ReactNode;
313
+ config?: MidenConfig;
314
+ /** Custom loading component shown during WASM initialization */
315
+ loadingComponent?: ReactNode;
316
+ /** Custom error component shown if initialization fails */
317
+ errorComponent?: ReactNode | ((error: Error) => ReactNode);
318
+ }
319
+ declare function MidenProvider({ children, config, loadingComponent, errorComponent, }: MidenProviderProps): react_jsx_runtime.JSX.Element;
320
+ declare function useMiden(): MidenContextValue;
321
+ declare function useMidenClient(): WebClient;
322
+
323
+ /**
324
+ * Hook to list all accounts in the client.
325
+ *
326
+ * @example
327
+ * ```tsx
328
+ * function AccountList() {
329
+ * const { accounts, wallets, faucets, isLoading } = useAccounts();
330
+ *
331
+ * if (isLoading) return <div>Loading...</div>;
332
+ *
333
+ * return (
334
+ * <div>
335
+ * <h2>Wallets ({wallets.length})</h2>
336
+ * {wallets.map(w => <div key={w.id().toString()}>{w.id().toString()}</div>)}
337
+ *
338
+ * <h2>Faucets ({faucets.length})</h2>
339
+ * {faucets.map(f => <div key={f.id().toString()}>{f.id().toString()}</div>)}
340
+ * </div>
341
+ * );
342
+ * }
343
+ * ```
344
+ */
345
+ declare function useAccounts(): AccountsResult;
346
+
347
+ /**
348
+ * Hook to get details for a single account.
349
+ *
350
+ * @param accountId - The account ID string or AccountId object
351
+ *
352
+ * @example
353
+ * ```tsx
354
+ * function AccountDetails({ accountId }: { accountId: string }) {
355
+ * const { account, assets, getBalance, isLoading } = useAccount(accountId);
356
+ *
357
+ * if (isLoading) return <div>Loading...</div>;
358
+ * if (!account) return <div>Account not found</div>;
359
+ *
360
+ * return (
361
+ * <div>
362
+ * <h2>Account: {account.id().toString()}</h2>
363
+ * <p>Nonce: {account.nonce().toString()}</p>
364
+ * <h3>Assets</h3>
365
+ * {assets.map(a => (
366
+ * <div key={a.assetId}>
367
+ * {a.assetId}: {a.amount.toString()}
368
+ * </div>
369
+ * ))}
370
+ * <p>USDC Balance: {getBalance('0x...').toString()}</p>
371
+ * </div>
372
+ * );
373
+ * }
374
+ * ```
375
+ */
376
+ declare function useAccount(accountId: string | AccountId | undefined): AccountResult;
377
+
378
+ /**
379
+ * Hook to list notes.
380
+ *
381
+ * @param options - Optional filter options
382
+ *
383
+ * @example
384
+ * ```tsx
385
+ * function NotesList() {
386
+ * const { notes, consumableNotes, isLoading, refetch } = useNotes();
387
+ *
388
+ * if (isLoading) return <div>Loading...</div>;
389
+ *
390
+ * return (
391
+ * <div>
392
+ * <h2>All Notes ({notes.length})</h2>
393
+ * {notes.map(n => (
394
+ * <div key={n.id().toString()}>
395
+ * Note: {n.id().toString()} - {n.isConsumed() ? 'Consumed' : 'Pending'}
396
+ * </div>
397
+ * ))}
398
+ *
399
+ * <h2>Consumable Notes ({consumableNotes.length})</h2>
400
+ * {consumableNotes.map(n => (
401
+ * <div key={n.inputNoteRecord().id().toString()}>
402
+ * {n.inputNoteRecord().id().toString()}
403
+ * </div>
404
+ * ))}
405
+ *
406
+ * <button onClick={refetch}>Refresh</button>
407
+ * </div>
408
+ * );
409
+ * }
410
+ * ```
411
+ */
412
+ declare function useNotes(options?: NotesFilter): NotesResult;
413
+
414
+ /**
415
+ * Hook to query transaction history and track transaction state.
416
+ *
417
+ * @param options - Optional filter options
418
+ *
419
+ * @example
420
+ * ```tsx
421
+ * function HistoryList() {
422
+ * const { records, isLoading } = useTransactionHistory();
423
+ * if (isLoading) return <div>Loading...</div>;
424
+ * return (
425
+ * <ul>
426
+ * {records.map((record) => (
427
+ * <li key={record.id().toHex()}>{record.id().toHex()}</li>
428
+ * ))}
429
+ * </ul>
430
+ * );
431
+ * }
432
+ * ```
433
+ */
434
+ declare function useTransactionHistory(options?: TransactionHistoryOptions): TransactionHistoryResult;
435
+ type UseTransactionHistoryResult = TransactionHistoryResult;
436
+
437
+ interface UseSyncStateResult extends SyncState {
438
+ /** Trigger a manual sync */
439
+ sync: () => Promise<void>;
440
+ }
441
+ /**
442
+ * Hook to access sync state and trigger manual syncs.
443
+ *
444
+ * @example
445
+ * ```tsx
446
+ * function SyncStatus() {
447
+ * const { syncHeight, isSyncing, sync } = useSyncState();
448
+ *
449
+ * return (
450
+ * <div>
451
+ * <p>Block height: {syncHeight}</p>
452
+ * <button onClick={sync} disabled={isSyncing}>
453
+ * {isSyncing ? 'Syncing...' : 'Sync'}
454
+ * </button>
455
+ * </div>
456
+ * );
457
+ * }
458
+ * ```
459
+ */
460
+ declare function useSyncState(): UseSyncStateResult;
461
+
462
+ declare function useAssetMetadata(assetIds?: string[]): {
463
+ assetMetadata: Map<string, AssetMetadata>;
464
+ };
465
+
466
+ interface UseCreateWalletResult {
467
+ /** Create a new wallet with optional configuration */
468
+ createWallet: (options?: CreateWalletOptions) => Promise<Account>;
469
+ /** The created wallet account */
470
+ wallet: Account | null;
471
+ /** Whether wallet creation is in progress */
472
+ isCreating: boolean;
473
+ /** Error if creation failed */
474
+ error: Error | null;
475
+ /** Reset the hook state */
476
+ reset: () => void;
477
+ }
478
+ /**
479
+ * Hook to create a new wallet account.
480
+ *
481
+ * @example
482
+ * ```tsx
483
+ * function CreateWalletButton() {
484
+ * const { createWallet, wallet, isCreating, error } = useCreateWallet();
485
+ *
486
+ * const handleCreate = async () => {
487
+ * const newWallet = await createWallet({
488
+ * storageMode: 'private',
489
+ * mutable: true,
490
+ * });
491
+ * console.log('Created wallet:', newWallet.id().toString());
492
+ * };
493
+ *
494
+ * return (
495
+ * <div>
496
+ * <button onClick={handleCreate} disabled={isCreating}>
497
+ * {isCreating ? 'Creating...' : 'Create Wallet'}
498
+ * </button>
499
+ * {wallet && <p>Created: {wallet.id().toString()}</p>}
500
+ * {error && <p>Error: {error.message}</p>}
501
+ * </div>
502
+ * );
503
+ * }
504
+ * ```
505
+ */
506
+ declare function useCreateWallet(): UseCreateWalletResult;
507
+
508
+ interface UseCreateFaucetResult {
509
+ /** Create a new faucet with the specified options */
510
+ createFaucet: (options: CreateFaucetOptions) => Promise<Account>;
511
+ /** The created faucet account */
512
+ faucet: Account | null;
513
+ /** Whether faucet creation is in progress */
514
+ isCreating: boolean;
515
+ /** Error if creation failed */
516
+ error: Error | null;
517
+ /** Reset the hook state */
518
+ reset: () => void;
519
+ }
520
+ /**
521
+ * Hook to create a new faucet account.
522
+ *
523
+ * @example
524
+ * ```tsx
525
+ * function CreateFaucetButton() {
526
+ * const { createFaucet, faucet, isCreating, error } = useCreateFaucet();
527
+ *
528
+ * const handleCreate = async () => {
529
+ * const newFaucet = await createFaucet({
530
+ * tokenSymbol: 'TEST',
531
+ * decimals: 8,
532
+ * maxSupply: 1000000n * 10n ** 8n, // 1M tokens
533
+ * });
534
+ * console.log('Created faucet:', newFaucet.id().toString());
535
+ * };
536
+ *
537
+ * return (
538
+ * <div>
539
+ * <button onClick={handleCreate} disabled={isCreating}>
540
+ * {isCreating ? 'Creating...' : 'Create Faucet'}
541
+ * </button>
542
+ * {faucet && <p>Created: {faucet.id().toString()}</p>}
543
+ * {error && <p>Error: {error.message}</p>}
544
+ * </div>
545
+ * );
546
+ * }
547
+ * ```
548
+ */
549
+ declare function useCreateFaucet(): UseCreateFaucetResult;
550
+
551
+ interface UseImportAccountResult {
552
+ /** Import an existing account into the client */
553
+ importAccount: (options: ImportAccountOptions) => Promise<Account>;
554
+ /** The imported account */
555
+ account: Account | null;
556
+ /** Whether an import is in progress */
557
+ isImporting: boolean;
558
+ /** Error if import failed */
559
+ error: Error | null;
560
+ /** Reset the hook state */
561
+ reset: () => void;
562
+ }
563
+ /**
564
+ * Hook to import existing accounts into the client.
565
+ *
566
+ * @example
567
+ * ```tsx
568
+ * function ImportAccountButton({ accountId }: { accountId: string }) {
569
+ * const { importAccount, isImporting } = useImportAccount();
570
+ *
571
+ * const handleImport = async () => {
572
+ * const account = await importAccount({
573
+ * type: "id",
574
+ * accountId,
575
+ * });
576
+ * console.log("Imported:", account.id().toString());
577
+ * };
578
+ *
579
+ * return (
580
+ * <button onClick={handleImport} disabled={isImporting}>
581
+ * {isImporting ? "Importing..." : "Import Account"}
582
+ * </button>
583
+ * );
584
+ * }
585
+ * ```
586
+ */
587
+ declare function useImportAccount(): UseImportAccountResult;
588
+
589
+ interface UseSendResult {
590
+ /** Send tokens from one account to another */
591
+ send: (options: SendOptions) => Promise<TransactionResult>;
592
+ /** The transaction result */
593
+ result: TransactionResult | null;
594
+ /** Whether the transaction is in progress */
595
+ isLoading: boolean;
596
+ /** Current stage of the transaction */
597
+ stage: TransactionStage;
598
+ /** Error if transaction failed */
599
+ error: Error | null;
600
+ /** Reset the hook state */
601
+ reset: () => void;
602
+ }
603
+ /**
604
+ * Hook to send tokens between accounts.
605
+ *
606
+ * @example
607
+ * ```tsx
608
+ * function SendButton({ from, to, assetId }: Props) {
609
+ * const { send, isLoading, stage, error } = useSend();
610
+ *
611
+ * const handleSend = async () => {
612
+ * try {
613
+ * const result = await send({
614
+ * from,
615
+ * to,
616
+ * assetId,
617
+ * amount: 100n,
618
+ * });
619
+ * console.log('Transaction ID:', result.transactionId);
620
+ * } catch (err) {
621
+ * console.error('Send failed:', err);
622
+ * }
623
+ * };
624
+ *
625
+ * return (
626
+ * <button onClick={handleSend} disabled={isLoading}>
627
+ * {isLoading ? stage : 'Send'}
628
+ * </button>
629
+ * );
630
+ * }
631
+ * ```
632
+ */
633
+ declare function useSend(): UseSendResult;
634
+
635
+ interface UseMultiSendResult {
636
+ /** Create multiple P2ID output notes in one transaction */
637
+ sendMany: (options: MultiSendOptions) => Promise<TransactionResult>;
638
+ /** The transaction result */
639
+ result: TransactionResult | null;
640
+ /** Whether the transaction is in progress */
641
+ isLoading: boolean;
642
+ /** Current stage of the transaction */
643
+ stage: TransactionStage;
644
+ /** Error if transaction failed */
645
+ error: Error | null;
646
+ /** Reset the hook state */
647
+ reset: () => void;
648
+ }
649
+ /**
650
+ * Hook to create a multi-send transaction (multiple P2ID notes).
651
+ *
652
+ * @example
653
+ * ```tsx
654
+ * function MultiSendButton() {
655
+ * const { sendMany, isLoading, stage } = useMultiSend();
656
+ *
657
+ * const handleSend = async () => {
658
+ * await sendMany({
659
+ * from: "mtst1...",
660
+ * assetId: "0x...",
661
+ * recipients: [
662
+ * { to: "mtst1...", amount: 100n },
663
+ * { to: "0x...", amount: 250n },
664
+ * ],
665
+ * noteType: "public",
666
+ * });
667
+ * };
668
+ *
669
+ * return (
670
+ * <button onClick={handleSend} disabled={isLoading}>
671
+ * {isLoading ? stage : "Multi-send"}
672
+ * </button>
673
+ * );
674
+ * }
675
+ * ```
676
+ */
677
+ declare function useMultiSend(): UseMultiSendResult;
678
+
679
+ interface UseInternalTransferResult {
680
+ /** Create a P2ID note and immediately consume it with another account */
681
+ transfer: (options: InternalTransferOptions) => Promise<InternalTransferResult>;
682
+ /** Perform a chain of P2ID transfers across multiple accounts */
683
+ transferChain: (options: InternalTransferChainOptions) => Promise<InternalTransferResult[]>;
684
+ /** The last transfer result(s) */
685
+ result: InternalTransferResult | InternalTransferResult[] | null;
686
+ /** Whether the transfer is in progress */
687
+ isLoading: boolean;
688
+ /** Current stage of the transfer */
689
+ stage: TransactionStage;
690
+ /** Error if transfer failed */
691
+ error: Error | null;
692
+ /** Reset the hook state */
693
+ reset: () => void;
694
+ }
695
+ /**
696
+ * Hook to create a P2ID note and immediately consume it.
697
+ *
698
+ * @example
699
+ * ```tsx
700
+ * function InternalTransferButton() {
701
+ * const { transfer, isLoading, stage } = useInternalTransfer();
702
+ *
703
+ * const handleTransfer = async () => {
704
+ * await transfer({
705
+ * from: "mtst1...",
706
+ * to: "0x...",
707
+ * assetId: "0x...",
708
+ * amount: 50n,
709
+ * noteType: "public",
710
+ * });
711
+ * };
712
+ *
713
+ * return (
714
+ * <button onClick={handleTransfer} disabled={isLoading}>
715
+ * {isLoading ? stage : "Transfer"}
716
+ * </button>
717
+ * );
718
+ * }
719
+ * ```
720
+ */
721
+ declare function useInternalTransfer(): UseInternalTransferResult;
722
+
723
+ interface UseWaitForCommitResult {
724
+ /** Wait for a transaction to be committed on-chain */
725
+ waitForCommit: (txId: string | TransactionId, options?: WaitForCommitOptions) => Promise<void>;
726
+ }
727
+ declare function useWaitForCommit(): UseWaitForCommitResult;
728
+
729
+ interface UseWaitForNotesResult {
730
+ /** Wait until an account has consumable notes */
731
+ waitForConsumableNotes: (options: WaitForNotesOptions) => Promise<ConsumableNoteRecord[]>;
732
+ }
733
+ declare function useWaitForNotes(): UseWaitForNotesResult;
734
+
735
+ interface UseMintResult {
736
+ /** Mint tokens from a faucet to a target account */
737
+ mint: (options: MintOptions) => Promise<TransactionResult>;
738
+ /** The transaction result */
739
+ result: TransactionResult | null;
740
+ /** Whether the transaction is in progress */
741
+ isLoading: boolean;
742
+ /** Current stage of the transaction */
743
+ stage: TransactionStage;
744
+ /** Error if transaction failed */
745
+ error: Error | null;
746
+ /** Reset the hook state */
747
+ reset: () => void;
748
+ }
749
+ /**
750
+ * Hook to mint tokens from a faucet.
751
+ *
752
+ * @example
753
+ * ```tsx
754
+ * function MintButton({ faucetId, targetAccountId }: Props) {
755
+ * const { mint, isLoading, stage, error } = useMint();
756
+ *
757
+ * const handleMint = async () => {
758
+ * try {
759
+ * const result = await mint({
760
+ * faucetId,
761
+ * targetAccountId,
762
+ * amount: 1000n,
763
+ * });
764
+ * console.log('Minted! TX:', result.transactionId);
765
+ * } catch (err) {
766
+ * console.error('Mint failed:', err);
767
+ * }
768
+ * };
769
+ *
770
+ * return (
771
+ * <button onClick={handleMint} disabled={isLoading}>
772
+ * {isLoading ? stage : 'Mint Tokens'}
773
+ * </button>
774
+ * );
775
+ * }
776
+ * ```
777
+ */
778
+ declare function useMint(): UseMintResult;
779
+
780
+ interface UseConsumeResult {
781
+ /** Consume one or more notes */
782
+ consume: (options: ConsumeOptions) => Promise<TransactionResult>;
783
+ /** The transaction result */
784
+ result: TransactionResult | null;
785
+ /** Whether the transaction is in progress */
786
+ isLoading: boolean;
787
+ /** Current stage of the transaction */
788
+ stage: TransactionStage;
789
+ /** Error if transaction failed */
790
+ error: Error | null;
791
+ /** Reset the hook state */
792
+ reset: () => void;
793
+ }
794
+ /**
795
+ * Hook to consume notes and claim their assets.
796
+ *
797
+ * @example
798
+ * ```tsx
799
+ * function ConsumeNotesButton({ accountId, noteIds }: Props) {
800
+ * const { consume, isLoading, stage, error } = useConsume();
801
+ *
802
+ * const handleConsume = async () => {
803
+ * try {
804
+ * const result = await consume({
805
+ * accountId,
806
+ * noteIds,
807
+ * });
808
+ * console.log('Consumed! TX:', result.transactionId);
809
+ * } catch (err) {
810
+ * console.error('Consume failed:', err);
811
+ * }
812
+ * };
813
+ *
814
+ * return (
815
+ * <button onClick={handleConsume} disabled={isLoading}>
816
+ * {isLoading ? stage : 'Claim Notes'}
817
+ * </button>
818
+ * );
819
+ * }
820
+ * ```
821
+ */
822
+ declare function useConsume(): UseConsumeResult;
823
+
824
+ interface UseSwapResult {
825
+ /** Create an atomic swap offer */
826
+ swap: (options: SwapOptions) => Promise<TransactionResult>;
827
+ /** The transaction result */
828
+ result: TransactionResult | null;
829
+ /** Whether the transaction is in progress */
830
+ isLoading: boolean;
831
+ /** Current stage of the transaction */
832
+ stage: TransactionStage;
833
+ /** Error if transaction failed */
834
+ error: Error | null;
835
+ /** Reset the hook state */
836
+ reset: () => void;
837
+ }
838
+ /**
839
+ * Hook to create atomic swap transactions.
840
+ *
841
+ * @example
842
+ * ```tsx
843
+ * function SwapButton({ accountId }: { accountId: string }) {
844
+ * const { swap, isLoading, stage, error } = useSwap();
845
+ *
846
+ * const handleSwap = async () => {
847
+ * try {
848
+ * const result = await swap({
849
+ * accountId,
850
+ * offeredFaucetId: '0x...', // Token A
851
+ * offeredAmount: 100n,
852
+ * requestedFaucetId: '0x...', // Token B
853
+ * requestedAmount: 50n,
854
+ * });
855
+ * console.log('Swap created! TX:', result.transactionId);
856
+ * } catch (err) {
857
+ * console.error('Swap failed:', err);
858
+ * }
859
+ * };
860
+ *
861
+ * return (
862
+ * <button onClick={handleSwap} disabled={isLoading}>
863
+ * {isLoading ? stage : 'Create Swap'}
864
+ * </button>
865
+ * );
866
+ * }
867
+ * ```
868
+ */
869
+ declare function useSwap(): UseSwapResult;
870
+
871
+ interface UseTransactionResult {
872
+ /** Execute a transaction request end-to-end */
873
+ execute: (options: ExecuteTransactionOptions) => Promise<TransactionResult>;
874
+ /** The transaction result */
875
+ result: TransactionResult | null;
876
+ /** Whether the transaction is in progress */
877
+ isLoading: boolean;
878
+ /** Current stage of the transaction */
879
+ stage: TransactionStage;
880
+ /** Error if transaction failed */
881
+ error: Error | null;
882
+ /** Reset the hook state */
883
+ reset: () => void;
884
+ }
885
+ /**
886
+ * Hook to execute arbitrary transaction requests.
887
+ *
888
+ * @example
889
+ * ```tsx
890
+ * function CustomTransactionButton({ accountId }: { accountId: string }) {
891
+ * const { execute, isLoading, stage } = useTransaction();
892
+ *
893
+ * const handleClick = async () => {
894
+ * await execute({
895
+ * accountId,
896
+ * request: (client) =>
897
+ * client.newSwapTransactionRequest(
898
+ * AccountId.fromHex(accountId),
899
+ * AccountId.fromHex("0x..."),
900
+ * 10n,
901
+ * AccountId.fromHex("0x..."),
902
+ * 5n,
903
+ * NoteType.Private,
904
+ * NoteType.Private
905
+ * ),
906
+ * });
907
+ * };
908
+ *
909
+ * return (
910
+ * <button onClick={handleClick} disabled={isLoading}>
911
+ * {isLoading ? stage : "Run Transaction"}
912
+ * </button>
913
+ * );
914
+ * }
915
+ * ```
916
+ */
917
+ declare function useTransaction(): UseTransactionResult;
918
+
919
+ declare const toBech32AccountId: (accountId: string) => string;
920
+
921
+ declare const formatAssetAmount: (amount: bigint, decimals?: number) => string;
922
+ declare const parseAssetAmount: (input: string, decimals?: number) => bigint;
923
+
924
+ declare const getNoteSummary: (note: ConsumableNoteRecord | InputNoteRecord, getAssetMetadata?: (assetId: string) => AssetMetadata | undefined) => NoteSummary | null;
925
+ declare const formatNoteSummary: (summary: NoteSummary, formatAsset?: (asset: NoteAsset) => string) => string;
926
+
927
+ export { type AccountResult, type AccountsResult, type AssetBalance, type AssetMetadata, type ConsumeOptions, type CreateFaucetOptions, type CreateWalletOptions, DEFAULTS, type ExecuteTransactionOptions, type ImportAccountOptions, type InternalTransferChainOptions, type InternalTransferOptions, type InternalTransferResult, type MidenConfig, MidenProvider, type MidenState, type MintOptions, type MultiSendOptions, type MultiSendRecipient, type MutationResult, type NoteAsset, type NoteSummary, type NotesFilter, type NotesResult, type ProverConfig, type ProverUrls, type QueryResult, type RpcUrlConfig, type SendOptions, type SwapOptions, type SyncState, type TransactionHistoryOptions, type TransactionHistoryResult, type TransactionResult, type TransactionStage, type TransactionStatus, type UseConsumeResult, type UseCreateFaucetResult, type UseCreateWalletResult, type UseImportAccountResult, type UseInternalTransferResult, type UseMintResult, type UseMultiSendResult, type UseSendResult, type UseSwapResult, type UseSyncStateResult, type UseTransactionHistoryResult, type UseTransactionResult, type UseWaitForCommitResult, type UseWaitForNotesResult, type WaitForCommitOptions, type WaitForNotesOptions, formatAssetAmount, formatNoteSummary, getNoteSummary, parseAssetAmount, toBech32AccountId, useAccount, useAccounts, useAssetMetadata, useConsume, useCreateFaucet, useCreateWallet, useImportAccount, useInternalTransfer, useMiden, useMidenClient, useMint, useMultiSend, useNotes, useSend, useSwap, useSyncState, useTransaction, useTransactionHistory, useWaitForCommit, useWaitForNotes };