@miden-sdk/react 0.15.3 → 0.15.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CLAUDE.md CHANGED
@@ -149,6 +149,38 @@ await mint({
149
149
  });
150
150
  ```
151
151
 
152
+ ### Bridge Out (AggLayer)
153
+ ```tsx
154
+ const { bridge } = useBridge();
155
+
156
+ // Emits a public B2AGG note that the bridge account consumes, burning the
157
+ // asset so it can be claimed at the destination Ethereum address.
158
+ await bridge({
159
+ from: senderAccountId,
160
+ bridgeAccount: bridgeAccountId,
161
+ assetId: tokenFaucetId,
162
+ amount: 100n,
163
+ destinationNetwork: 1, // AggLayer-assigned network id
164
+ destinationAddress: "0x000000000000000000000000000000000000dEaD",
165
+ });
166
+ ```
167
+
168
+ ### Create a Network Note
169
+ ```tsx
170
+ const { createNetworkNote } = useCreateNetworkNote();
171
+
172
+ // Builds a Public custom-script note carrying a NetworkAccountTarget
173
+ // attachment; the targeted network account auto-consumes it on-chain.
174
+ // Provide exactly one of `script` or `recipient`.
175
+ const { txId, note } = await createNetworkNote({
176
+ accountId: senderAccountId,
177
+ target: networkAccountId,
178
+ script: myNoteScript, // or: recipient: myRecipient
179
+ });
180
+
181
+ note.isNetworkNote(); // true
182
+ ```
183
+
152
184
  ### Create Faucet
153
185
  ```tsx
154
186
  const { createFaucet } = useCreateFaucet();
@@ -410,6 +442,8 @@ Query hooks return `{ ...data, isLoading, error, refetch }`. Mutation hooks retu
410
442
  | `useSend()` | `send({ from, to, assetId, amount, noteType })` | `SendResult` (with `txId`, `note`) |
411
443
  | `useMultiSend()` | `multiSend({ from, recipients })` | `TransactionResult` |
412
444
  | `useMint()` | `mint({ faucetId, to, amount })` | `TransactionResult` |
445
+ | `useBridge()` | `bridge({ from, bridgeAccount, assetId, amount, destinationNetwork, destinationAddress })` | `TransactionResult` (emits an AggLayer B2AGG bridge-out note) |
446
+ | `useCreateNetworkNote()` | `createNetworkNote({ accountId, target, script \| recipient, ... })` | `NetworkNoteResult` (`{ txId, note }`; note satisfies `note.isNetworkNote()`) |
413
447
  | `useConsume()` | `consume({ accountId, notes })` | `TransactionResult` |
414
448
  | `useSwap()` | `swap({ ... })` | `TransactionResult` |
415
449
  | `usePswapCreate()` | `pswapCreate({ accountId, offeredFaucetId, offeredAmount, requestedFaucetId, requestedAmount, ... })` | `TransactionResult` (creates partial-swap note) |
package/README.md CHANGED
@@ -12,6 +12,8 @@ React hooks library for the Miden Web Client. Provides a simple, ergonomic inter
12
12
  - **Note Attachments** - Send and read arbitrary data payloads on notes via `useSend()` and `readNoteAttachment()`
13
13
  - **Temporal Note Tracking** - `useNoteStream()` tracks when notes first appear, with built-in filtering, handled-note exclusion, and phase snapshots
14
14
  - **Session Wallets** - `useSessionAccount()` manages the create-fund-consume lifecycle for temporary wallets
15
+ - **AggLayer Bridge-Out** - `useBridge()` emits a B2AGG note to bridge a fungible asset out to another network via the AggLayer
16
+ - **Network Notes** - `useCreateNetworkNote()` creates custom-script network notes
15
17
  - **Concurrency Safety** - Transaction hooks prevent double-sends with built-in concurrency guards
16
18
  - **Auto Pre-Sync** - Transaction hooks sync before executing by default (opt out with `skipSync`)
17
19
  - **WASM Error Wrapping** - Cryptic WASM errors are intercepted and replaced with actionable messages
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import * as react from 'react';
3
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, NoteInput, PswapLineageRecord, TransactionId, TransactionFilter, TransactionRecord, TransactionProver, CompileComponentOptions, CompileTxScriptOptions, CompileNoteScriptOptions, NoteScript, NoteAttachment } from '@miden-sdk/miden-sdk';
4
+ import { AccountId, Account, AccountHeader, AccountStorageMode, AccountComponent, NoteId, InputNoteRecord, Note, StorageMode, AuthScheme, NoteExecutionHint, NoteRecipient, NoteScript, TransactionScript, AdviceInputs, AccountStorageRequirements, TransactionRequest, WasmWebClient, AccountFile, NoteVisibility, ConsumableNoteRecord, NoteInput, PswapLineageRecord, TransactionId, TransactionFilter, TransactionRecord, TransactionProver, CompileComponentOptions, CompileTxScriptOptions, CompileNoteScriptOptions, NoteAttachment } from '@miden-sdk/miden-sdk';
5
5
  export { Account, AccountFile, AccountHeader, AccountId, AccountStorageMode, AuthScheme, ConsumableNoteRecord, InputNoteRecord, Note, NoteType, PswapLineageRecord, TransactionFilter, TransactionId, TransactionRecord, TransactionRequest, WasmWebClient as WebClient } from '@miden-sdk/miden-sdk';
6
6
 
7
7
  declare module "@miden-sdk/miden-sdk" {
@@ -392,6 +392,46 @@ interface MintOptions {
392
392
  /** Note type. Default: private */
393
393
  noteType?: NoteVisibility;
394
394
  }
395
+ interface CreateNetworkNoteOptions {
396
+ /** Account that creates, funds, and submits the note (executing sender). */
397
+ accountId: AccountRef;
398
+ /** The network account the note targets. */
399
+ target: AccountRef;
400
+ /** Execution hint. Defaults to `always`. */
401
+ executionHint?: NoteExecutionHint;
402
+ /** Recipient carrying the custom script (advanced; else pass `script`). */
403
+ recipient?: NoteRecipient;
404
+ /** Custom consumption script; the recipient is built for you. */
405
+ script?: NoteScript;
406
+ /** Note storage / inputs the script reads (used with `script`). */
407
+ inputs?: bigint[];
408
+ /** Single asset to lock into the note. Optional — omit for a zero-asset note. */
409
+ assetId?: AccountRef;
410
+ /** Amount for `assetId`. */
411
+ amount?: bigint | number;
412
+ /** Extra attachment payload appended after the NetworkAccountTarget. */
413
+ attachment?: bigint[] | Uint8Array | number[];
414
+ }
415
+ interface NetworkNoteResult {
416
+ txId: string;
417
+ note: Note;
418
+ }
419
+ interface BridgeOptions {
420
+ /** Account that creates and funds the bridge note (the sender) */
421
+ from: AccountRef;
422
+ /** Bridge account that consumes the note and burns the bridged assets */
423
+ bridgeAccount: AccountRef;
424
+ /** Faucet/token ID of the fungible asset to bridge */
425
+ assetId: AccountRef;
426
+ /** Amount of the asset to bridge */
427
+ amount: bigint | number;
428
+ /** AggLayer-assigned network ID of the destination chain */
429
+ destinationNetwork: number;
430
+ /** Destination Ethereum address on the destination network (0x-prefixed hex) */
431
+ destinationAddress: string;
432
+ /** Skip auto-sync after bridging. Default: false */
433
+ skipSync?: boolean;
434
+ }
395
435
  interface ConsumeOptions {
396
436
  /** Account ID that will consume the notes */
397
437
  accountId: string;
@@ -1174,6 +1214,61 @@ interface UseMintResult {
1174
1214
  */
1175
1215
  declare function useMint(): UseMintResult;
1176
1216
 
1217
+ interface UseBridgeResult {
1218
+ /** Bridge a fungible asset out to another network via the AggLayer */
1219
+ bridge: (options: BridgeOptions) => Promise<TransactionResult>;
1220
+ /** The transaction result */
1221
+ result: TransactionResult | null;
1222
+ /** Whether the transaction is in progress */
1223
+ isLoading: boolean;
1224
+ /** Current stage of the transaction */
1225
+ stage: TransactionStage;
1226
+ /** Error if transaction failed */
1227
+ error: Error | null;
1228
+ /** Reset the hook state */
1229
+ reset: () => void;
1230
+ }
1231
+ /**
1232
+ * Hook to bridge a fungible asset out to another network via the AggLayer.
1233
+ *
1234
+ * Emits a single public B2AGG (Bridge-to-AggLayer) note that the bridge account consumes,
1235
+ * burning the asset so it can be claimed at the destination Ethereum address on the destination
1236
+ * network. The sender account executes the transaction that emits the note.
1237
+ *
1238
+ * Returns `{ bridge, result, isLoading, stage, error, reset }`. `bridge` resolves to a
1239
+ * `TransactionResult` (`{ transactionId }`) and rejects on failure.
1240
+ *
1241
+ * @example
1242
+ * ```tsx
1243
+ * function BridgeButton({ from, bridgeAccount, assetId }: Props) {
1244
+ * const { bridge, isLoading, stage, error } = useBridge();
1245
+ *
1246
+ * const handleBridge = async () => {
1247
+ * try {
1248
+ * const result = await bridge({
1249
+ * from,
1250
+ * bridgeAccount,
1251
+ * assetId,
1252
+ * amount: 100n,
1253
+ * destinationNetwork: 1,
1254
+ * destinationAddress: "0x000000000000000000000000000000000000dEaD",
1255
+ * });
1256
+ * console.log("Bridged! TX:", result.transactionId);
1257
+ * } catch (err) {
1258
+ * console.error("Bridge failed:", err);
1259
+ * }
1260
+ * };
1261
+ *
1262
+ * return (
1263
+ * <button onClick={handleBridge} disabled={isLoading}>
1264
+ * {isLoading ? stage : "Bridge"}
1265
+ * </button>
1266
+ * );
1267
+ * }
1268
+ * ```
1269
+ */
1270
+ declare function useBridge(): UseBridgeResult;
1271
+
1177
1272
  interface UseConsumeResult {
1178
1273
  /** Consume one or more notes */
1179
1274
  consume: (options: ConsumeOptions) => Promise<TransactionResult>;
@@ -1421,6 +1516,22 @@ interface UsePswapCancelByOrderResult {
1421
1516
  */
1422
1517
  declare function usePswapCancelByOrder(): UsePswapCancelByOrderResult;
1423
1518
 
1519
+ interface UseCreateNetworkNoteResult {
1520
+ /** Build + submit a Public custom-script network note. */
1521
+ createNetworkNote: (options: CreateNetworkNoteOptions) => Promise<NetworkNoteResult>;
1522
+ result: NetworkNoteResult | null;
1523
+ isLoading: boolean;
1524
+ stage: TransactionStage;
1525
+ error: Error | null;
1526
+ reset: () => void;
1527
+ }
1528
+ /**
1529
+ * Hook that builds a Public custom-script note carrying a `NetworkAccountTarget`
1530
+ * attachment and submits it as an own output note, so a public network account
1531
+ * auto-consumes it. Provide exactly one of `recipient` or `script`.
1532
+ */
1533
+ declare function useCreateNetworkNote(): UseCreateNetworkNoteResult;
1534
+
1424
1535
  interface UseTransactionResult {
1425
1536
  /** Execute a transaction request end-to-end */
1426
1537
  execute: (options: ExecuteTransactionOptions) => Promise<TransactionResult>;
@@ -1840,4 +1951,4 @@ declare function createMidenStorage(prefix: string): {
1840
1951
  clear(): void;
1841
1952
  };
1842
1953
 
1843
- 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 PswapCancelByOrderOptions, type PswapCancelOptions, type PswapConsumeOptions, type PswapCreateOptions, type PswapLineageResult, type PswapLineagesResult, 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 UsePswapCancelByOrderResult, type UsePswapCancelResult, type UsePswapConsumeResult, type UsePswapCreateResult, type UsePswapLineageResult, type UsePswapLineagesForResult, type UsePswapLineagesResult, 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, ensureAccountBech32, formatAssetAmount, formatNoteSummary, getNoteSummary, installAccountBech32, 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, usePswapCancel, usePswapCancelByOrder, usePswapConsume, usePswapCreate, usePswapLineage, usePswapLineages, usePswapLineagesFor, useSend, useSessionAccount, useSigner, useSwap, useSyncControl, useSyncState, useTransaction, useTransactionHistory, useWaitForCommit, useWaitForNotes, waitForWalletDetection, wrapWasmError };
1954
+ export { type AccountRef, type AccountResult, type AccountsResult, type AssetBalance, type AssetMetadata, type BridgeOptions, type ConsumeOptions, type CreateFaucetOptions, type CreateNetworkNoteOptions, 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 NetworkNoteResult, type NoteAsset, type NoteAttachmentData, type NoteSummary, type NotesFilter, type NotesResult, type ProverConfig, type ProverTarget, type ProverUrls, type PswapCancelByOrderOptions, type PswapCancelOptions, type PswapConsumeOptions, type PswapCreateOptions, type PswapLineageResult, type PswapLineagesResult, 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 UseBridgeResult, type UseCompileResult, type UseConsumeResult, type UseCreateFaucetResult, type UseCreateNetworkNoteResult, type UseCreateWalletResult, type UseExecuteProgramResult, type UseExportNoteResult, type UseExportStoreResult, type UseImportAccountResult, type UseImportNoteResult, type UseImportStoreResult, type UseMintResult, type UseMultiSendResult, type UseNoteStreamOptions, type UseNoteStreamReturn, type UsePswapCancelByOrderResult, type UsePswapCancelResult, type UsePswapConsumeResult, type UsePswapCreateResult, type UsePswapLineageResult, type UsePswapLineagesForResult, type UsePswapLineagesResult, 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, ensureAccountBech32, formatAssetAmount, formatNoteSummary, getNoteSummary, installAccountBech32, migrateStorage, normalizeAccountId, parseAssetAmount, readNoteAttachment, toBech32AccountId, useAccount, useAccounts, useAssetMetadata, useBridge, useCompile, useConsume, useCreateFaucet, useCreateNetworkNote, useCreateWallet, useExecuteProgram, useExportNote, useExportStore, useImportAccount, useImportNote, useImportStore, useMiden, useMidenClient, useMint, useMultiSend, useMultiSigner, useNoteStream, useNotes, usePswapCancel, usePswapCancelByOrder, usePswapConsume, usePswapCreate, usePswapLineage, usePswapLineages, usePswapLineagesFor, useSend, useSessionAccount, useSigner, useSwap, useSyncControl, useSyncState, useTransaction, useTransactionHistory, useWaitForCommit, useWaitForNotes, waitForWalletDetection, wrapWasmError };