@miden-sdk/miden-sdk 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 +86 -0
- package/dist/{Cargo-DanGI-a8.js → Cargo-M3382VZc.js} +227 -113
- package/dist/Cargo-M3382VZc.js.map +1 -0
- package/dist/api-types.d.ts +51 -2
- package/dist/assets/miden_client_web.wasm +0 -0
- package/dist/crates/miden_client_web.d.ts +143 -3
- package/dist/eager.js +35 -0
- package/dist/eager.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +399 -133
- package/dist/index.js.map +1 -1
- package/dist/wasm.js +1 -1
- package/dist/workers/{Cargo-DanGI-a8-DD61BgkT.js → Cargo-M3382VZc-Dfw4tXwh.js} +227 -113
- package/dist/workers/Cargo-M3382VZc-Dfw4tXwh.js.map +1 -0
- package/dist/workers/assets/miden_client_web.wasm +0 -0
- package/dist/workers/web-client-methods-worker.js +240 -122
- package/dist/workers/web-client-methods-worker.js.map +1 -1
- package/dist/workers/web-client-methods-worker.module.js +13 -9
- package/dist/workers/web-client-methods-worker.module.js.map +1 -1
- package/package.json +11 -4
- package/dist/Cargo-DanGI-a8.js.map +0 -1
- package/dist/workers/Cargo-DanGI-a8-DD61BgkT.js.map +0 -1
package/README.md
CHANGED
|
@@ -65,6 +65,92 @@ yarn add @miden-sdk/miden-sdk@next
|
|
|
65
65
|
|
|
66
66
|
> **Note:** The `next` version of the SDK must be used in conjunction with a locally running Miden node built from the `next` branch of the `miden-node` repository. This is necessary because the public testnet runs the stable `main` branch, which may not be compatible with the latest development features in `next`. Instructions to run a local node can be found [here](https://github.com/0xMiden/miden-node/tree/next) on the `next` branch of the `miden-node` repository. Additionally, if you plan to leverage delegated proving in your application, you may need to run a local prover (see [Remote prover instructions](https://github.com/0xMiden/miden-node/tree/next/bin/remote-prover)).
|
|
67
67
|
|
|
68
|
+
## Entry Points: Eager (default) and `/lazy`
|
|
69
|
+
|
|
70
|
+
The SDK ships two entry points with an identical public API. They differ only in **when** the WASM module is initialized.
|
|
71
|
+
|
|
72
|
+
| Import path | When WASM initializes | When to use |
|
|
73
|
+
| ------------------------------ | --------------------------------------------- | -------------------------------------------------------------------------- |
|
|
74
|
+
| `@miden-sdk/miden-sdk` | At module evaluation (top-level `await`) | Plain browser apps, Vite, CRA, esbuild, Webpack client bundles |
|
|
75
|
+
| `@miden-sdk/miden-sdk/lazy` | On first call to `MidenClient.ready()` or any `await`-ing SDK method | Next.js / SSR, Capacitor (iOS/Android WKWebView), framework adapters |
|
|
76
|
+
|
|
77
|
+
The eager entry awaits WASM at module top level via a small shim (`js/eager.js`), so once an `import` statement resolves, any wasm-bindgen constructor (`new Felt(…)`, `AccountId.fromHex(…)`, `TransactionProver.newLocalProver()`, etc.) is safe to call synchronously on the next line. No `await MidenClient.ready()` is required.
|
|
78
|
+
|
|
79
|
+
The lazy entry does not run any top-level await. This matters in two environments that hang on TLA:
|
|
80
|
+
|
|
81
|
+
- **Next.js / SSR** — TLA blocks server-side module evaluation.
|
|
82
|
+
- **Capacitor WKWebView hosts (Miden Wallet iOS/Android)** — the custom `capacitor://localhost` scheme handler interacts poorly with TLA in the main WebView. Verified empirically: the same TLA in a dApp WebView (vanilla HTTPS) resolves in <100ms, but hangs indefinitely in the Capacitor host.
|
|
83
|
+
|
|
84
|
+
On the lazy entry, callers are responsible for awaiting initialization before calling any wasm-bindgen constructor. Every async SDK method (`client.accounts.create()`, `client.transactions.send()`, etc.) awaits internally, so you only need to gate on readiness when you're constructing wasm-bindgen types yourself.
|
|
85
|
+
|
|
86
|
+
### Eager usage (default)
|
|
87
|
+
|
|
88
|
+
```typescript
|
|
89
|
+
// Bundlers resolve `@miden-sdk/miden-sdk` to `./dist/eager.js`.
|
|
90
|
+
// The `import` statement awaits WASM; everything below is safe to call sync.
|
|
91
|
+
import { MidenClient, AccountId, Felt } from "@miden-sdk/miden-sdk";
|
|
92
|
+
|
|
93
|
+
const id = AccountId.fromHex("0x…"); // sync, WASM is already initialized
|
|
94
|
+
const felt = new Felt(42n); // sync
|
|
95
|
+
|
|
96
|
+
const client = await MidenClient.createTestnet();
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### Lazy usage (`/lazy`)
|
|
100
|
+
|
|
101
|
+
```typescript
|
|
102
|
+
import { MidenClient, AccountId, Felt } from "@miden-sdk/miden-sdk/lazy";
|
|
103
|
+
|
|
104
|
+
// Gate any bare wasm-bindgen constructor behind ready():
|
|
105
|
+
await MidenClient.ready();
|
|
106
|
+
const id = AccountId.fromHex("0x…"); // safe after ready()
|
|
107
|
+
const felt = new Felt(42n);
|
|
108
|
+
|
|
109
|
+
// SDK methods that are already async await internally — no ready() needed:
|
|
110
|
+
const client = await MidenClient.createTestnet(); // implicitly initializes WASM
|
|
111
|
+
await client.sync();
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
`MidenClient.ready()` is idempotent and safe to call from multiple places — concurrent callers share the same in-flight promise, and post-init callers resolve immediately from a cached module. `MidenProvider`, tutorial helpers, and application code can all call it without any coordination.
|
|
115
|
+
|
|
116
|
+
### Next.js example
|
|
117
|
+
|
|
118
|
+
```tsx
|
|
119
|
+
// app/page.tsx
|
|
120
|
+
"use client";
|
|
121
|
+
|
|
122
|
+
import { useEffect, useState } from "react";
|
|
123
|
+
import { MidenClient } from "@miden-sdk/miden-sdk/lazy";
|
|
124
|
+
|
|
125
|
+
export default function Page() {
|
|
126
|
+
const [height, setHeight] = useState<number | null>(null);
|
|
127
|
+
|
|
128
|
+
useEffect(() => {
|
|
129
|
+
let cancelled = false;
|
|
130
|
+
(async () => {
|
|
131
|
+
await MidenClient.ready(); // optional here — createTestnet awaits internally
|
|
132
|
+
const client = await MidenClient.createTestnet();
|
|
133
|
+
const syncHeight = await client.getSyncHeight();
|
|
134
|
+
if (!cancelled) setHeight(syncHeight);
|
|
135
|
+
client.terminate();
|
|
136
|
+
})();
|
|
137
|
+
return () => {
|
|
138
|
+
cancelled = true;
|
|
139
|
+
};
|
|
140
|
+
}, []);
|
|
141
|
+
|
|
142
|
+
return <div>Height: {height ?? "…"}</div>;
|
|
143
|
+
}
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
### Capacitor / React Native WebView
|
|
147
|
+
|
|
148
|
+
Use `/lazy` from anywhere inside a Capacitor iOS/Android host (the main WKWebView). TLA hangs the custom scheme handler; the `MidenClient.ready()` gate is the replacement.
|
|
149
|
+
|
|
150
|
+
### Framework adapters
|
|
151
|
+
|
|
152
|
+
`@miden-sdk/react` imports from `/lazy` internally and manages readiness via `isReady`. You can still import wasm-bindgen types from either entry in your own code; see the React SDK README for the recommended pattern.
|
|
153
|
+
|
|
68
154
|
## Building and Testing the Web Client
|
|
69
155
|
|
|
70
156
|
If you're interested in contributing to the web client and need to build it locally, you can do so via:
|