@miden-sdk/react 0.14.2 → 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 CHANGED
@@ -119,6 +119,64 @@ function App() {
119
119
  }
120
120
  ```
121
121
 
122
+ ## Next.js & SSR
123
+
124
+ The React SDK is Next.js-compatible out of the box: it ships two bundle variants built from a single source tree, and both internally import `@miden-sdk/miden-sdk/lazy` — the lazy entry point that does **not** use a top-level `await`. Nothing initializes WASM at module evaluation, so server-side rendering never hangs.
125
+
126
+ - Default (`@miden-sdk/react`) — internally consumes the eager SDK. Use this in plain browser apps, Vite, CRA.
127
+ - `@miden-sdk/react/lazy` — internally consumes the lazy SDK. Use this in Next.js (app router or pages), SSR, or inside a Capacitor iOS/Android WKWebView host (the wallet shell uses this).
128
+
129
+ Both exports have identical APIs. The choice only affects which `@miden-sdk/miden-sdk` variant your bundler ends up resolving.
130
+
131
+ ```tsx
132
+ // Next.js: app/providers.tsx
133
+ "use client";
134
+
135
+ import { MidenProvider } from "@miden-sdk/react/lazy";
136
+
137
+ export function Providers({ children }: { children: React.ReactNode }) {
138
+ return <MidenProvider config={{ rpcUrl: "testnet" }}>{children}</MidenProvider>;
139
+ }
140
+ ```
141
+
142
+ `MidenProvider` gates child rendering on `isReady`, so you don't have to await anything manually in components — hooks already fire only after WASM is initialized.
143
+
144
+ ### Constructing wasm-bindgen types directly in Next.js
145
+
146
+ Hooks accept strings for account IDs, asset IDs, and note IDs (auto-detecting hex vs. bech32) and parse them internally inside async callbacks, so **most apps never touch wasm-bindgen types directly**. If you do need to (e.g. to inspect an ID's prefix/suffix, validate a pasted string, or use a low-level API like `new Felt(…)`), import from `@miden-sdk/miden-sdk/lazy` and gate the call on `isReady`:
147
+
148
+ ```tsx
149
+ import { useEffect, useState } from "react";
150
+ import { useMiden } from "@miden-sdk/react/lazy";
151
+ import { AccountId } from "@miden-sdk/miden-sdk/lazy";
152
+
153
+ function IdInspector({ idString }: { idString: string }) {
154
+ const { isReady } = useMiden();
155
+ const [isFaucet, setIsFaucet] = useState<boolean | null>(null);
156
+
157
+ useEffect(() => {
158
+ if (!isReady) return;
159
+ // AccountId.fromBech32/fromHex is synchronous but touches WASM — run it
160
+ // only after the provider reports ready.
161
+ const id = idString.startsWith("miden1")
162
+ ? AccountId.fromBech32(idString)
163
+ : AccountId.fromHex(idString);
164
+ setIsFaucet(id.isFaucet());
165
+ }, [isReady, idString]);
166
+
167
+ return <span>{isFaucet === null ? "…" : isFaucet ? "faucet" : "wallet"}</span>;
168
+ }
169
+ ```
170
+
171
+ Alternatively, await `MidenClient.ready()` directly — it's idempotent and shares its in-flight promise with `MidenProvider`, so calling it from tutorial helpers or ad-hoc code has no cost:
172
+
173
+ ```ts
174
+ import { MidenClient, AccountId } from "@miden-sdk/miden-sdk/lazy";
175
+
176
+ await MidenClient.ready();
177
+ const id = AccountId.fromBech32("miden1…"); // safe
178
+ ```
179
+
122
180
  ## Hooks Reference
123
181
 
124
182
  ### Core Hooks
package/dist/index.d.mts CHANGED
@@ -1,10 +1,10 @@
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, CompileComponentOptions, CompileTxScriptOptions, CompileNoteScriptOptions, NoteScript, NoteAttachment } from '@miden-sdk/miden-sdk';
5
- export { Account, AccountFile, AccountHeader, AccountId, AccountStorageMode, AuthScheme, ConsumableNoteRecord, InputNoteRecord, Note, NoteType, TransactionFilter, TransactionId, TransactionRecord, TransactionRequest, WasmWebClient as WebClient } 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/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
6
 
7
- declare module "@miden-sdk/miden-sdk" {
7
+ declare module "@miden-sdk/miden-sdk/lazy" {
8
8
  interface Account {
9
9
  /** Returns the bech32-encoded account id using the configured network. */
10
10
  bech32id(): string;
package/dist/index.d.ts CHANGED
@@ -1,10 +1,10 @@
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, CompileComponentOptions, CompileTxScriptOptions, CompileNoteScriptOptions, NoteScript, NoteAttachment } from '@miden-sdk/miden-sdk';
5
- export { Account, AccountFile, AccountHeader, AccountId, AccountStorageMode, AuthScheme, ConsumableNoteRecord, InputNoteRecord, Note, NoteType, TransactionFilter, TransactionId, TransactionRecord, TransactionRequest, WasmWebClient as WebClient } 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/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
6
 
7
- declare module "@miden-sdk/miden-sdk" {
7
+ declare module "@miden-sdk/miden-sdk/lazy" {
8
8
  interface Account {
9
9
  /** Returns the bech32-encoded account id using the configured network. */
10
10
  bech32id(): string;