@miden-sdk/react 0.14.0 → 0.14.2

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
@@ -393,6 +393,7 @@ account.bech32id(); // "miden1qy35..."
393
393
  | `useConsume()` | `TransactionResult` | Claim notes |
394
394
  | `useSwap()` | `TransactionResult` | Atomic swap |
395
395
  | `useTransaction()` | `TransactionResult` | Custom transaction |
396
+ | `useCompile()` | `{ component, txScript, noteScript }` | Compile MASM into `AccountComponent` / `TransactionScript` / `NoteScript` |
396
397
 
397
398
  ## Type Imports
398
399
 
package/README.md CHANGED
@@ -952,6 +952,51 @@ function CustomTransactionButton({ accountId }: { accountId: string }) {
952
952
  }
953
953
  ```
954
954
 
955
+ #### `useCompile()`
956
+
957
+ Compile MASM source into an `AccountComponent`, `TransactionScript`, or
958
+ `NoteScript`. Mirrors `MidenClient.compile` from `@miden-sdk/miden-sdk`, so the
959
+ shape is identical whether you're in a React app or calling the SDK directly.
960
+
961
+ Returns three async methods, one per output type:
962
+
963
+ | Method | Input | Output |
964
+ |---|---|---|
965
+ | `component(options)` | `{ code, slots?, supportAllTypes? }` | `AccountComponent` |
966
+ | `txScript(options)` | `{ code, libraries? }` | `TransactionScript` |
967
+ | `noteScript(options)` | `{ code, libraries? }` | `NoteScript` |
968
+
969
+ Each `libraries` entry takes `{ namespace, code, linking? }`. `linking` accepts
970
+ the `Linking` enum (`Linking.Dynamic`, `Linking.Static`) or the raw strings
971
+ `"dynamic"` / `"static"`. Dynamic is the default and matches the FPI pattern
972
+ used in the tutorials.
973
+
974
+ ```tsx
975
+ import { useCompile } from '@miden-sdk/react';
976
+ import { Linking } from '@miden-sdk/miden-sdk';
977
+
978
+ function ScriptBuilder({ libSource, noteSource }: { libSource: string; noteSource: string }) {
979
+ const { noteScript, isReady } = useCompile();
980
+
981
+ const handleBuild = async () => {
982
+ const script = await noteScript({
983
+ code: noteSource,
984
+ libraries: [
985
+ { namespace: 'my_lib::module', code: libSource, linking: Linking.Dynamic },
986
+ ],
987
+ });
988
+ // pass `script` to useTransaction, useExecuteProgram, or your own flow
989
+ };
990
+
991
+ return <button onClick={handleBuild} disabled={!isReady}>Compile</button>;
992
+ }
993
+ ```
994
+
995
+ Compile is local and synchronous in practice — the hook doesn't expose
996
+ `isLoading` / `stage` / `error` state. Errors from the underlying compiler
997
+ (bad MASM, unresolved imports) throw from the returned promise; handle them
998
+ with regular `try`/`catch`.
999
+
955
1000
  #### `useExecuteProgram()`
956
1001
 
957
1002
  Execute a program (view call) against an account and read the resulting stack
package/dist/index.d.mts 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, TransactionId, TransactionFilter, TransactionRecord, TransactionProver, NoteAttachment } from '@miden-sdk/miden-sdk';
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';
5
5
  export { Account, AccountFile, AccountHeader, AccountId, AccountStorageMode, AuthScheme, ConsumableNoteRecord, InputNoteRecord, Note, NoteType, TransactionFilter, TransactionId, TransactionRecord, TransactionRequest, WasmWebClient as WebClient } from '@miden-sdk/miden-sdk';
6
6
 
7
7
  declare module "@miden-sdk/miden-sdk" {
@@ -1168,6 +1168,33 @@ interface UseExecuteProgramResult {
1168
1168
  }
1169
1169
  declare function useExecuteProgram(): UseExecuteProgramResult;
1170
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
+
1171
1198
  /**
1172
1199
  * Hook to manage a session wallet lifecycle: create -> fund -> consume.
1173
1200
  *
@@ -1467,4 +1494,4 @@ declare function createMidenStorage(prefix: string): {
1467
1494
  clear(): void;
1468
1495
  };
1469
1496
 
1470
- 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 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, 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 };
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 };
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, TransactionId, TransactionFilter, TransactionRecord, TransactionProver, NoteAttachment } from '@miden-sdk/miden-sdk';
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';
5
5
  export { Account, AccountFile, AccountHeader, AccountId, AccountStorageMode, AuthScheme, ConsumableNoteRecord, InputNoteRecord, Note, NoteType, TransactionFilter, TransactionId, TransactionRecord, TransactionRequest, WasmWebClient as WebClient } from '@miden-sdk/miden-sdk';
6
6
 
7
7
  declare module "@miden-sdk/miden-sdk" {
@@ -1168,6 +1168,33 @@ interface UseExecuteProgramResult {
1168
1168
  }
1169
1169
  declare function useExecuteProgram(): UseExecuteProgramResult;
1170
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
+
1171
1198
  /**
1172
1199
  * Hook to manage a session wallet lifecycle: create -> fund -> consume.
1173
1200
  *
@@ -1467,4 +1494,4 @@ declare function createMidenStorage(prefix: string): {
1467
1494
  clear(): void;
1468
1495
  };
1469
1496
 
1470
- 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 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, 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 };
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 };
package/dist/index.js CHANGED
@@ -55,6 +55,7 @@ __export(index_exports, {
55
55
  useAccount: () => useAccount,
56
56
  useAccounts: () => useAccounts,
57
57
  useAssetMetadata: () => useAssetMetadata,
58
+ useCompile: () => useCompile,
58
59
  useConsume: () => useConsume,
59
60
  useCreateFaucet: () => useCreateFaucet,
60
61
  useCreateWallet: () => useCreateWallet,
@@ -2285,7 +2286,9 @@ function useSend() {
2285
2286
  noteType,
2286
2287
  new import_miden_sdk16.NoteAttachment()
2287
2288
  );
2288
- const txRequest = new import_miden_sdk16.TransactionRequestBuilder().withOwnOutputNotes(new import_miden_sdk16.NoteArray([p2idNote])).build();
2289
+ const ownOutputs = new import_miden_sdk16.NoteArray();
2290
+ ownOutputs.push(p2idNote);
2291
+ const txRequest = new import_miden_sdk16.TransactionRequestBuilder().withOwnOutputNotes(ownOutputs).build();
2289
2292
  const execFromId = parseAccountId(options.from);
2290
2293
  const txId = prover ? await client.submitNewTransactionWithProver(
2291
2294
  execFromId,
@@ -3097,26 +3100,56 @@ function useExecuteProgram() {
3097
3100
  };
3098
3101
  }
3099
3102
 
3100
- // src/hooks/useSessionAccount.ts
3103
+ // src/hooks/useCompile.ts
3101
3104
  var import_react23 = require("react");
3102
3105
  var import_miden_sdk22 = require("@miden-sdk/miden-sdk");
3106
+ function useCompile() {
3107
+ const { client, isReady } = useMiden();
3108
+ const resource = (0, import_react23.useMemo)(
3109
+ () => client && isReady ? new import_miden_sdk22.CompilerResource(client, import_miden_sdk22.getWasmOrThrow) : null,
3110
+ [client, isReady]
3111
+ );
3112
+ const requireResource = (0, import_react23.useCallback)(() => {
3113
+ if (!resource) {
3114
+ throw new Error("Miden client is not ready");
3115
+ }
3116
+ return resource;
3117
+ }, [resource]);
3118
+ const component = (0, import_react23.useCallback)(
3119
+ async (options) => requireResource().component(options),
3120
+ [requireResource]
3121
+ );
3122
+ const txScript = (0, import_react23.useCallback)(
3123
+ async (options) => requireResource().txScript(options),
3124
+ [requireResource]
3125
+ );
3126
+ const noteScript = (0, import_react23.useCallback)(
3127
+ async (options) => requireResource().noteScript(options),
3128
+ [requireResource]
3129
+ );
3130
+ return { component, txScript, noteScript, isReady };
3131
+ }
3132
+
3133
+ // src/hooks/useSessionAccount.ts
3134
+ var import_react24 = require("react");
3135
+ var import_miden_sdk23 = require("@miden-sdk/miden-sdk");
3103
3136
  function useSessionAccount(options) {
3104
3137
  const { client, isReady, sync } = useMiden();
3105
3138
  const setAccounts = useMidenStore((state) => state.setAccounts);
3106
- const [sessionAccountId, setSessionAccountId] = (0, import_react23.useState)(null);
3107
- const [step, setStep] = (0, import_react23.useState)("idle");
3108
- const [error, setError] = (0, import_react23.useState)(null);
3109
- const cancelledRef = (0, import_react23.useRef)(false);
3110
- const isBusyRef = (0, import_react23.useRef)(false);
3139
+ const [sessionAccountId, setSessionAccountId] = (0, import_react24.useState)(null);
3140
+ const [step, setStep] = (0, import_react24.useState)("idle");
3141
+ const [error, setError] = (0, import_react24.useState)(null);
3142
+ const cancelledRef = (0, import_react24.useRef)(false);
3143
+ const isBusyRef = (0, import_react24.useRef)(false);
3111
3144
  const storagePrefix = options.storagePrefix ?? "miden-session";
3112
3145
  const pollIntervalMs = options.pollIntervalMs ?? 3e3;
3113
3146
  const maxWaitMs = options.maxWaitMs ?? 6e4;
3114
3147
  const storageMode = options.walletOptions?.storageMode ?? "public";
3115
3148
  const mutable = options.walletOptions?.mutable ?? DEFAULTS.WALLET_MUTABLE;
3116
3149
  const authScheme = options.walletOptions?.authScheme ?? DEFAULTS.AUTH_SCHEME;
3117
- const fundRef = (0, import_react23.useRef)(options.fund);
3150
+ const fundRef = (0, import_react24.useRef)(options.fund);
3118
3151
  fundRef.current = options.fund;
3119
- (0, import_react23.useEffect)(() => {
3152
+ (0, import_react24.useEffect)(() => {
3120
3153
  try {
3121
3154
  const stored = localStorage.getItem(`${storagePrefix}:accountId`);
3122
3155
  const storedReady = localStorage.getItem(`${storagePrefix}:ready`);
@@ -3133,7 +3166,7 @@ function useSessionAccount(options) {
3133
3166
  localStorage.removeItem(`${storagePrefix}:ready`);
3134
3167
  }
3135
3168
  }, [storagePrefix]);
3136
- const initialize = (0, import_react23.useCallback)(async () => {
3169
+ const initialize = (0, import_react24.useCallback)(async () => {
3137
3170
  if (!client || !isReady) {
3138
3171
  throw new Error("Miden client is not ready");
3139
3172
  }
@@ -3202,7 +3235,7 @@ function useSessionAccount(options) {
3202
3235
  maxWaitMs,
3203
3236
  setAccounts
3204
3237
  ]);
3205
- const reset = (0, import_react23.useCallback)(() => {
3238
+ const reset = (0, import_react24.useCallback)(() => {
3206
3239
  cancelledRef.current = true;
3207
3240
  isBusyRef.current = false;
3208
3241
  setSessionAccountId(null);
@@ -3223,11 +3256,11 @@ function useSessionAccount(options) {
3223
3256
  function getStorageMode3(mode) {
3224
3257
  switch (mode) {
3225
3258
  case "private":
3226
- return import_miden_sdk22.AccountStorageMode.private();
3259
+ return import_miden_sdk23.AccountStorageMode.private();
3227
3260
  case "public":
3228
- return import_miden_sdk22.AccountStorageMode.public();
3261
+ return import_miden_sdk23.AccountStorageMode.public();
3229
3262
  default:
3230
- return import_miden_sdk22.AccountStorageMode.public();
3263
+ return import_miden_sdk23.AccountStorageMode.public();
3231
3264
  }
3232
3265
  }
3233
3266
  async function waitAndConsume(client, walletId, pollIntervalMs, maxWaitMs, cancelledRef) {
@@ -3251,13 +3284,13 @@ async function waitAndConsume(client, walletId, pollIntervalMs, maxWaitMs, cance
3251
3284
  }
3252
3285
 
3253
3286
  // src/hooks/useExportStore.ts
3254
- var import_react24 = require("react");
3255
- var import_miden_sdk23 = require("@miden-sdk/miden-sdk");
3287
+ var import_react25 = require("react");
3288
+ var import_miden_sdk24 = require("@miden-sdk/miden-sdk");
3256
3289
  function useExportStore() {
3257
3290
  const { client, isReady, runExclusive } = useMiden();
3258
- const [isExporting, setIsExporting] = (0, import_react24.useState)(false);
3259
- const [error, setError] = (0, import_react24.useState)(null);
3260
- const exportStore = (0, import_react24.useCallback)(async () => {
3291
+ const [isExporting, setIsExporting] = (0, import_react25.useState)(false);
3292
+ const [error, setError] = (0, import_react25.useState)(null);
3293
+ const exportStore = (0, import_react25.useCallback)(async () => {
3261
3294
  if (!client || !isReady) {
3262
3295
  throw new Error("Miden client is not ready");
3263
3296
  }
@@ -3265,7 +3298,7 @@ function useExportStore() {
3265
3298
  setError(null);
3266
3299
  try {
3267
3300
  const storeName = client.storeIdentifier();
3268
- const snapshot = await runExclusive(() => (0, import_miden_sdk23.exportStore)(storeName));
3301
+ const snapshot = await runExclusive(() => (0, import_miden_sdk24.exportStore)(storeName));
3269
3302
  return snapshot;
3270
3303
  } catch (err) {
3271
3304
  const error2 = err instanceof Error ? err : new Error(String(err));
@@ -3275,7 +3308,7 @@ function useExportStore() {
3275
3308
  setIsExporting(false);
3276
3309
  }
3277
3310
  }, [client, isReady, runExclusive]);
3278
- const reset = (0, import_react24.useCallback)(() => {
3311
+ const reset = (0, import_react25.useCallback)(() => {
3279
3312
  setIsExporting(false);
3280
3313
  setError(null);
3281
3314
  }, []);
@@ -3288,13 +3321,13 @@ function useExportStore() {
3288
3321
  }
3289
3322
 
3290
3323
  // src/hooks/useImportStore.ts
3291
- var import_react25 = require("react");
3292
- var import_miden_sdk24 = require("@miden-sdk/miden-sdk");
3324
+ var import_react26 = require("react");
3325
+ var import_miden_sdk25 = require("@miden-sdk/miden-sdk");
3293
3326
  function useImportStore() {
3294
3327
  const { client, isReady, runExclusive, sync } = useMiden();
3295
- const [isImporting, setIsImporting] = (0, import_react25.useState)(false);
3296
- const [error, setError] = (0, import_react25.useState)(null);
3297
- const importStore = (0, import_react25.useCallback)(
3328
+ const [isImporting, setIsImporting] = (0, import_react26.useState)(false);
3329
+ const [error, setError] = (0, import_react26.useState)(null);
3330
+ const importStore = (0, import_react26.useCallback)(
3298
3331
  async (storeDump, storeName, options) => {
3299
3332
  if (!client || !isReady) {
3300
3333
  throw new Error("Miden client is not ready");
@@ -3302,7 +3335,7 @@ function useImportStore() {
3302
3335
  setIsImporting(true);
3303
3336
  setError(null);
3304
3337
  try {
3305
- await runExclusive(() => (0, import_miden_sdk24.importStore)(storeName, storeDump));
3338
+ await runExclusive(() => (0, import_miden_sdk25.importStore)(storeName, storeDump));
3306
3339
  if (!options?.skipSync) {
3307
3340
  await sync();
3308
3341
  }
@@ -3316,7 +3349,7 @@ function useImportStore() {
3316
3349
  },
3317
3350
  [client, isReady, runExclusive, sync]
3318
3351
  );
3319
- const reset = (0, import_react25.useCallback)(() => {
3352
+ const reset = (0, import_react26.useCallback)(() => {
3320
3353
  setIsImporting(false);
3321
3354
  setError(null);
3322
3355
  }, []);
@@ -3329,13 +3362,13 @@ function useImportStore() {
3329
3362
  }
3330
3363
 
3331
3364
  // src/hooks/useImportNote.ts
3332
- var import_react26 = require("react");
3333
- var import_miden_sdk25 = require("@miden-sdk/miden-sdk");
3365
+ var import_react27 = require("react");
3366
+ var import_miden_sdk26 = require("@miden-sdk/miden-sdk");
3334
3367
  function useImportNote() {
3335
3368
  const { client, isReady, runExclusive, sync } = useMiden();
3336
- const [isImporting, setIsImporting] = (0, import_react26.useState)(false);
3337
- const [error, setError] = (0, import_react26.useState)(null);
3338
- const importNote = (0, import_react26.useCallback)(
3369
+ const [isImporting, setIsImporting] = (0, import_react27.useState)(false);
3370
+ const [error, setError] = (0, import_react27.useState)(null);
3371
+ const importNote = (0, import_react27.useCallback)(
3339
3372
  async (noteBytes) => {
3340
3373
  if (!client || !isReady) {
3341
3374
  throw new Error("Miden client is not ready");
@@ -3343,7 +3376,7 @@ function useImportNote() {
3343
3376
  setIsImporting(true);
3344
3377
  setError(null);
3345
3378
  try {
3346
- const noteFile = import_miden_sdk25.NoteFile.deserialize(noteBytes);
3379
+ const noteFile = import_miden_sdk26.NoteFile.deserialize(noteBytes);
3347
3380
  const noteId = await runExclusive(
3348
3381
  () => client.importNoteFile(noteFile)
3349
3382
  );
@@ -3359,7 +3392,7 @@ function useImportNote() {
3359
3392
  },
3360
3393
  [client, isReady, runExclusive, sync]
3361
3394
  );
3362
- const reset = (0, import_react26.useCallback)(() => {
3395
+ const reset = (0, import_react27.useCallback)(() => {
3363
3396
  setIsImporting(false);
3364
3397
  setError(null);
3365
3398
  }, []);
@@ -3372,13 +3405,13 @@ function useImportNote() {
3372
3405
  }
3373
3406
 
3374
3407
  // src/hooks/useExportNote.ts
3375
- var import_react27 = require("react");
3376
- var import_miden_sdk26 = require("@miden-sdk/miden-sdk");
3408
+ var import_react28 = require("react");
3409
+ var import_miden_sdk27 = require("@miden-sdk/miden-sdk");
3377
3410
  function useExportNote() {
3378
3411
  const { client, isReady, runExclusive } = useMiden();
3379
- const [isExporting, setIsExporting] = (0, import_react27.useState)(false);
3380
- const [error, setError] = (0, import_react27.useState)(null);
3381
- const exportNote = (0, import_react27.useCallback)(
3412
+ const [isExporting, setIsExporting] = (0, import_react28.useState)(false);
3413
+ const [error, setError] = (0, import_react28.useState)(null);
3414
+ const exportNote = (0, import_react28.useCallback)(
3382
3415
  async (noteId) => {
3383
3416
  if (!client || !isReady) {
3384
3417
  throw new Error("Miden client is not ready");
@@ -3387,7 +3420,7 @@ function useExportNote() {
3387
3420
  setError(null);
3388
3421
  try {
3389
3422
  const noteFile = await runExclusive(
3390
- () => client.exportNoteFile(noteId, import_miden_sdk26.NoteExportFormat.Full)
3423
+ () => client.exportNoteFile(noteId, import_miden_sdk27.NoteExportFormat.Full)
3391
3424
  );
3392
3425
  return noteFile.serialize();
3393
3426
  } catch (err) {
@@ -3400,7 +3433,7 @@ function useExportNote() {
3400
3433
  },
3401
3434
  [client, isReady, runExclusive]
3402
3435
  );
3403
- const reset = (0, import_react27.useCallback)(() => {
3436
+ const reset = (0, import_react28.useCallback)(() => {
3404
3437
  setIsExporting(false);
3405
3438
  setError(null);
3406
3439
  }, []);
@@ -3413,12 +3446,12 @@ function useExportNote() {
3413
3446
  }
3414
3447
 
3415
3448
  // src/hooks/useSyncControl.ts
3416
- var import_react28 = require("react");
3449
+ var import_react29 = require("react");
3417
3450
  function useSyncControl() {
3418
3451
  const isPaused = useMidenStore((state) => state.syncPaused);
3419
3452
  const setSyncPaused = useMidenStore((state) => state.setSyncPaused);
3420
- const pauseSync = (0, import_react28.useCallback)(() => setSyncPaused(true), [setSyncPaused]);
3421
- const resumeSync = (0, import_react28.useCallback)(() => setSyncPaused(false), [setSyncPaused]);
3453
+ const pauseSync = (0, import_react29.useCallback)(() => setSyncPaused(true), [setSyncPaused]);
3454
+ const resumeSync = (0, import_react29.useCallback)(() => setSyncPaused(false), [setSyncPaused]);
3422
3455
  return {
3423
3456
  pauseSync,
3424
3457
  resumeSync,
@@ -3602,6 +3635,7 @@ installAccountBech32();
3602
3635
  useAccount,
3603
3636
  useAccounts,
3604
3637
  useAssetMetadata,
3638
+ useCompile,
3605
3639
  useConsume,
3606
3640
  useCreateFaucet,
3607
3641
  useCreateWallet,
package/dist/index.mjs CHANGED
@@ -2239,7 +2239,9 @@ function useSend() {
2239
2239
  noteType,
2240
2240
  new NoteAttachment2()
2241
2241
  );
2242
- const txRequest = new TransactionRequestBuilder().withOwnOutputNotes(new NoteArray([p2idNote])).build();
2242
+ const ownOutputs = new NoteArray();
2243
+ ownOutputs.push(p2idNote);
2244
+ const txRequest = new TransactionRequestBuilder().withOwnOutputNotes(ownOutputs).build();
2243
2245
  const execFromId = parseAccountId(options.from);
2244
2246
  const txId = prover ? await client.submitNewTransactionWithProver(
2245
2247
  execFromId,
@@ -3064,8 +3066,38 @@ function useExecuteProgram() {
3064
3066
  };
3065
3067
  }
3066
3068
 
3069
+ // src/hooks/useCompile.ts
3070
+ import { useCallback as useCallback21, useMemo as useMemo8 } from "react";
3071
+ import { CompilerResource, getWasmOrThrow } from "@miden-sdk/miden-sdk";
3072
+ function useCompile() {
3073
+ const { client, isReady } = useMiden();
3074
+ const resource = useMemo8(
3075
+ () => client && isReady ? new CompilerResource(client, getWasmOrThrow) : null,
3076
+ [client, isReady]
3077
+ );
3078
+ const requireResource = useCallback21(() => {
3079
+ if (!resource) {
3080
+ throw new Error("Miden client is not ready");
3081
+ }
3082
+ return resource;
3083
+ }, [resource]);
3084
+ const component = useCallback21(
3085
+ async (options) => requireResource().component(options),
3086
+ [requireResource]
3087
+ );
3088
+ const txScript = useCallback21(
3089
+ async (options) => requireResource().txScript(options),
3090
+ [requireResource]
3091
+ );
3092
+ const noteScript = useCallback21(
3093
+ async (options) => requireResource().noteScript(options),
3094
+ [requireResource]
3095
+ );
3096
+ return { component, txScript, noteScript, isReady };
3097
+ }
3098
+
3067
3099
  // src/hooks/useSessionAccount.ts
3068
- import { useCallback as useCallback21, useEffect as useEffect9, useRef as useRef8, useState as useState17 } from "react";
3100
+ import { useCallback as useCallback22, useEffect as useEffect9, useRef as useRef8, useState as useState17 } from "react";
3069
3101
  import { AccountStorageMode as AccountStorageMode3 } from "@miden-sdk/miden-sdk";
3070
3102
  function useSessionAccount(options) {
3071
3103
  const { client, isReady, sync } = useMiden();
@@ -3100,7 +3132,7 @@ function useSessionAccount(options) {
3100
3132
  localStorage.removeItem(`${storagePrefix}:ready`);
3101
3133
  }
3102
3134
  }, [storagePrefix]);
3103
- const initialize = useCallback21(async () => {
3135
+ const initialize = useCallback22(async () => {
3104
3136
  if (!client || !isReady) {
3105
3137
  throw new Error("Miden client is not ready");
3106
3138
  }
@@ -3169,7 +3201,7 @@ function useSessionAccount(options) {
3169
3201
  maxWaitMs,
3170
3202
  setAccounts
3171
3203
  ]);
3172
- const reset = useCallback21(() => {
3204
+ const reset = useCallback22(() => {
3173
3205
  cancelledRef.current = true;
3174
3206
  isBusyRef.current = false;
3175
3207
  setSessionAccountId(null);
@@ -3218,13 +3250,13 @@ async function waitAndConsume(client, walletId, pollIntervalMs, maxWaitMs, cance
3218
3250
  }
3219
3251
 
3220
3252
  // src/hooks/useExportStore.ts
3221
- import { useCallback as useCallback22, useState as useState18 } from "react";
3253
+ import { useCallback as useCallback23, useState as useState18 } from "react";
3222
3254
  import { exportStore as sdkExportStore } from "@miden-sdk/miden-sdk";
3223
3255
  function useExportStore() {
3224
3256
  const { client, isReady, runExclusive } = useMiden();
3225
3257
  const [isExporting, setIsExporting] = useState18(false);
3226
3258
  const [error, setError] = useState18(null);
3227
- const exportStore = useCallback22(async () => {
3259
+ const exportStore = useCallback23(async () => {
3228
3260
  if (!client || !isReady) {
3229
3261
  throw new Error("Miden client is not ready");
3230
3262
  }
@@ -3242,7 +3274,7 @@ function useExportStore() {
3242
3274
  setIsExporting(false);
3243
3275
  }
3244
3276
  }, [client, isReady, runExclusive]);
3245
- const reset = useCallback22(() => {
3277
+ const reset = useCallback23(() => {
3246
3278
  setIsExporting(false);
3247
3279
  setError(null);
3248
3280
  }, []);
@@ -3255,13 +3287,13 @@ function useExportStore() {
3255
3287
  }
3256
3288
 
3257
3289
  // src/hooks/useImportStore.ts
3258
- import { useCallback as useCallback23, useState as useState19 } from "react";
3290
+ import { useCallback as useCallback24, useState as useState19 } from "react";
3259
3291
  import { importStore as sdkImportStore } from "@miden-sdk/miden-sdk";
3260
3292
  function useImportStore() {
3261
3293
  const { client, isReady, runExclusive, sync } = useMiden();
3262
3294
  const [isImporting, setIsImporting] = useState19(false);
3263
3295
  const [error, setError] = useState19(null);
3264
- const importStore = useCallback23(
3296
+ const importStore = useCallback24(
3265
3297
  async (storeDump, storeName, options) => {
3266
3298
  if (!client || !isReady) {
3267
3299
  throw new Error("Miden client is not ready");
@@ -3283,7 +3315,7 @@ function useImportStore() {
3283
3315
  },
3284
3316
  [client, isReady, runExclusive, sync]
3285
3317
  );
3286
- const reset = useCallback23(() => {
3318
+ const reset = useCallback24(() => {
3287
3319
  setIsImporting(false);
3288
3320
  setError(null);
3289
3321
  }, []);
@@ -3296,13 +3328,13 @@ function useImportStore() {
3296
3328
  }
3297
3329
 
3298
3330
  // src/hooks/useImportNote.ts
3299
- import { useCallback as useCallback24, useState as useState20 } from "react";
3331
+ import { useCallback as useCallback25, useState as useState20 } from "react";
3300
3332
  import { NoteFile } from "@miden-sdk/miden-sdk";
3301
3333
  function useImportNote() {
3302
3334
  const { client, isReady, runExclusive, sync } = useMiden();
3303
3335
  const [isImporting, setIsImporting] = useState20(false);
3304
3336
  const [error, setError] = useState20(null);
3305
- const importNote = useCallback24(
3337
+ const importNote = useCallback25(
3306
3338
  async (noteBytes) => {
3307
3339
  if (!client || !isReady) {
3308
3340
  throw new Error("Miden client is not ready");
@@ -3326,7 +3358,7 @@ function useImportNote() {
3326
3358
  },
3327
3359
  [client, isReady, runExclusive, sync]
3328
3360
  );
3329
- const reset = useCallback24(() => {
3361
+ const reset = useCallback25(() => {
3330
3362
  setIsImporting(false);
3331
3363
  setError(null);
3332
3364
  }, []);
@@ -3339,13 +3371,13 @@ function useImportNote() {
3339
3371
  }
3340
3372
 
3341
3373
  // src/hooks/useExportNote.ts
3342
- import { useCallback as useCallback25, useState as useState21 } from "react";
3374
+ import { useCallback as useCallback26, useState as useState21 } from "react";
3343
3375
  import { NoteExportFormat } from "@miden-sdk/miden-sdk";
3344
3376
  function useExportNote() {
3345
3377
  const { client, isReady, runExclusive } = useMiden();
3346
3378
  const [isExporting, setIsExporting] = useState21(false);
3347
3379
  const [error, setError] = useState21(null);
3348
- const exportNote = useCallback25(
3380
+ const exportNote = useCallback26(
3349
3381
  async (noteId) => {
3350
3382
  if (!client || !isReady) {
3351
3383
  throw new Error("Miden client is not ready");
@@ -3367,7 +3399,7 @@ function useExportNote() {
3367
3399
  },
3368
3400
  [client, isReady, runExclusive]
3369
3401
  );
3370
- const reset = useCallback25(() => {
3402
+ const reset = useCallback26(() => {
3371
3403
  setIsExporting(false);
3372
3404
  setError(null);
3373
3405
  }, []);
@@ -3380,12 +3412,12 @@ function useExportNote() {
3380
3412
  }
3381
3413
 
3382
3414
  // src/hooks/useSyncControl.ts
3383
- import { useCallback as useCallback26 } from "react";
3415
+ import { useCallback as useCallback27 } from "react";
3384
3416
  function useSyncControl() {
3385
3417
  const isPaused = useMidenStore((state) => state.syncPaused);
3386
3418
  const setSyncPaused = useMidenStore((state) => state.setSyncPaused);
3387
- const pauseSync = useCallback26(() => setSyncPaused(true), [setSyncPaused]);
3388
- const resumeSync = useCallback26(() => setSyncPaused(false), [setSyncPaused]);
3419
+ const pauseSync = useCallback27(() => setSyncPaused(true), [setSyncPaused]);
3420
+ const resumeSync = useCallback27(() => setSyncPaused(false), [setSyncPaused]);
3389
3421
  return {
3390
3422
  pauseSync,
3391
3423
  resumeSync,
@@ -3568,6 +3600,7 @@ export {
3568
3600
  useAccount,
3569
3601
  useAccounts,
3570
3602
  useAssetMetadata,
3603
+ useCompile,
3571
3604
  useConsume,
3572
3605
  useCreateFaucet,
3573
3606
  useCreateWallet,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@miden-sdk/react",
3
- "version": "0.14.0",
3
+ "version": "0.14.2",
4
4
  "description": "React hooks library for Miden Web Client",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -28,7 +28,7 @@
28
28
  "test:all": "VITE_CJS_IGNORE_WARNING=1 vitest run && playwright test"
29
29
  },
30
30
  "peerDependencies": {
31
- "@miden-sdk/miden-sdk": "^0.14.0",
31
+ "@miden-sdk/miden-sdk": "^0.14.2",
32
32
  "react": ">=18.0.0"
33
33
  },
34
34
  "dependencies": {