@miden-sdk/react 0.14.3 → 0.14.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/README.md +58 -0
- package/dist/index.d.mts +6 -6
- package/dist/index.d.ts +6 -6
- package/dist/index.js +166 -147
- package/dist/index.mjs +51 -23
- package/dist/lazy.d.mts +1497 -0
- package/dist/lazy.d.ts +1497 -0
- package/dist/lazy.js +3686 -0
- package/dist/lazy.mjs +3660 -0
- package/package.json +9 -4
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;
|
|
@@ -259,7 +259,7 @@ interface CreateWalletOptions {
|
|
|
259
259
|
storageMode?: StorageMode;
|
|
260
260
|
/** Whether code can be updated. Default: true */
|
|
261
261
|
mutable?: boolean;
|
|
262
|
-
/** Auth scheme. Default: AuthScheme.
|
|
262
|
+
/** Auth scheme. Default: `AuthScheme.Falcon` */
|
|
263
263
|
authScheme?: AuthScheme;
|
|
264
264
|
/** Initial seed for deterministic account ID */
|
|
265
265
|
initSeed?: Uint8Array;
|
|
@@ -273,7 +273,7 @@ interface CreateFaucetOptions {
|
|
|
273
273
|
maxSupply: bigint | number;
|
|
274
274
|
/** Storage mode. Default: private */
|
|
275
275
|
storageMode?: StorageMode;
|
|
276
|
-
/** Auth scheme. Default: AuthScheme.
|
|
276
|
+
/** Auth scheme. Default: `AuthScheme.Falcon` */
|
|
277
277
|
authScheme?: AuthScheme;
|
|
278
278
|
}
|
|
279
279
|
type ImportAccountOptions = {
|
|
@@ -505,7 +505,7 @@ declare const DEFAULTS: {
|
|
|
505
505
|
readonly AUTO_SYNC_INTERVAL: 15000;
|
|
506
506
|
readonly STORAGE_MODE: "private";
|
|
507
507
|
readonly WALLET_MUTABLE: true;
|
|
508
|
-
readonly AUTH_SCHEME:
|
|
508
|
+
readonly AUTH_SCHEME: "falcon";
|
|
509
509
|
readonly NOTE_TYPE: "private";
|
|
510
510
|
readonly FAUCET_DECIMALS: 8;
|
|
511
511
|
};
|
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;
|
|
@@ -259,7 +259,7 @@ interface CreateWalletOptions {
|
|
|
259
259
|
storageMode?: StorageMode;
|
|
260
260
|
/** Whether code can be updated. Default: true */
|
|
261
261
|
mutable?: boolean;
|
|
262
|
-
/** Auth scheme. Default: AuthScheme.
|
|
262
|
+
/** Auth scheme. Default: `AuthScheme.Falcon` */
|
|
263
263
|
authScheme?: AuthScheme;
|
|
264
264
|
/** Initial seed for deterministic account ID */
|
|
265
265
|
initSeed?: Uint8Array;
|
|
@@ -273,7 +273,7 @@ interface CreateFaucetOptions {
|
|
|
273
273
|
maxSupply: bigint | number;
|
|
274
274
|
/** Storage mode. Default: private */
|
|
275
275
|
storageMode?: StorageMode;
|
|
276
|
-
/** Auth scheme. Default: AuthScheme.
|
|
276
|
+
/** Auth scheme. Default: `AuthScheme.Falcon` */
|
|
277
277
|
authScheme?: AuthScheme;
|
|
278
278
|
}
|
|
279
279
|
type ImportAccountOptions = {
|
|
@@ -505,7 +505,7 @@ declare const DEFAULTS: {
|
|
|
505
505
|
readonly AUTO_SYNC_INTERVAL: 15000;
|
|
506
506
|
readonly STORAGE_MODE: "private";
|
|
507
507
|
readonly WALLET_MUTABLE: true;
|
|
508
|
-
readonly AUTH_SCHEME:
|
|
508
|
+
readonly AUTH_SCHEME: "falcon";
|
|
509
509
|
readonly NOTE_TYPE: "private";
|
|
510
510
|
readonly FAUCET_DECIMALS: 8;
|
|
511
511
|
};
|