@miden-sdk/miden-sdk 0.14.5 → 0.14.9
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/LICENSE +21 -0
- package/README.md +148 -18
- package/dist/mt/Cargo-DKB2aRX-.js +25826 -0
- package/dist/mt/Cargo-DKB2aRX-.js.map +1 -0
- package/dist/{api-types.d.ts → mt/api-types.d.ts} +18 -3
- package/dist/mt/assets/miden_client_web.wasm +0 -0
- package/dist/mt/crates/miden_client_web.d.ts +4726 -0
- package/dist/{docs-entry.d.ts → mt/docs-entry.d.ts} +2 -2
- package/dist/mt/eager.js +35 -0
- package/dist/mt/eager.js.map +1 -0
- package/dist/{index.d.ts → mt/index.d.ts} +9 -7
- package/dist/mt/index.js +3371 -0
- package/dist/mt/index.js.map +1 -0
- package/dist/{wasm.js → mt/wasm.js} +1 -1
- package/dist/mt/wasm.js.map +1 -0
- package/dist/mt/workerHelpers.js +28 -0
- package/dist/mt/workers/Cargo-DKB2aRX--C6T4l3AF.js +25827 -0
- package/dist/mt/workers/Cargo-DKB2aRX--C6T4l3AF.js.map +1 -0
- package/dist/mt/workers/assets/miden_client_web.wasm +0 -0
- package/dist/mt/workers/web-client-methods-worker.js +26560 -0
- package/dist/mt/workers/web-client-methods-worker.js.map +1 -0
- package/dist/{workers → mt/workers}/web-client-methods-worker.module.js +17 -1
- package/dist/mt/workers/web-client-methods-worker.module.js.map +1 -0
- package/dist/mt/workers/workerHelpers.js +28 -0
- package/dist/{Cargo-M3382VZc.js → st/Cargo-jOTNoFyS.js} +6714 -5926
- package/dist/st/Cargo-jOTNoFyS.js.map +1 -0
- package/dist/st/api-types.d.ts +1051 -0
- package/dist/{workers → st}/assets/miden_client_web.wasm +0 -0
- package/dist/{crates → st/crates}/miden_client_web.d.ts +31 -0
- package/dist/st/docs-entry.d.ts +35 -0
- package/dist/{eager.js → st/eager.js} +1 -1
- package/dist/st/eager.js.map +1 -0
- package/dist/st/index.d.ts +89 -0
- package/dist/{index.js → st/index.js} +126 -13
- package/dist/st/index.js.map +1 -0
- package/dist/st/wasm.js +23 -0
- package/dist/st/wasm.js.map +1 -0
- package/dist/{workers/Cargo-M3382VZc-Dfw4tXwh.js → st/workers/Cargo-jOTNoFyS-DRTcF6wf.js} +6714 -5926
- package/dist/st/workers/Cargo-jOTNoFyS-DRTcF6wf.js.map +1 -0
- package/dist/{assets → st/workers/assets}/miden_client_web.wasm +0 -0
- package/dist/{workers → st/workers}/web-client-methods-worker.js +6731 -5926
- package/dist/st/workers/web-client-methods-worker.js.map +1 -0
- package/dist/st/workers/web-client-methods-worker.module.js +571 -0
- package/dist/st/workers/web-client-methods-worker.module.js.map +1 -0
- package/lazy/package.json +4 -0
- package/mt/lazy/package.json +4 -0
- package/mt/package.json +4 -0
- package/package.json +66 -44
- package/dist/Cargo-M3382VZc.js.map +0 -1
- package/dist/eager.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/wasm.js.map +0 -1
- package/dist/workers/Cargo-M3382VZc-Dfw4tXwh.js.map +0 -1
- package/dist/workers/web-client-methods-worker.js.map +0 -1
- package/dist/workers/web-client-methods-worker.module.js.map +0 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Miden
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -46,7 +46,7 @@ npm i @miden-sdk/miden-sdk
|
|
|
46
46
|
Or using Yarn:
|
|
47
47
|
|
|
48
48
|
```javascript
|
|
49
|
-
|
|
49
|
+
pnpm add @miden-sdk/miden-sdk
|
|
50
50
|
```
|
|
51
51
|
|
|
52
52
|
### Pre-release ("next") Version
|
|
@@ -60,28 +60,132 @@ npm i @miden-sdk/miden-sdk@next
|
|
|
60
60
|
Or with Yarn:
|
|
61
61
|
|
|
62
62
|
```javascript
|
|
63
|
-
|
|
63
|
+
pnpm add @miden-sdk/miden-sdk@next
|
|
64
64
|
```
|
|
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
|
|
68
|
+
## Entry Points: Eager / Lazy × ST / MT
|
|
69
69
|
|
|
70
|
-
The SDK ships
|
|
70
|
+
The SDK ships **four** entry points with an identical public API. They vary along two orthogonal axes:
|
|
71
71
|
|
|
72
|
-
|
|
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 |
|
|
72
|
+
- **WASM init timing** — _eager_ awaits at module load (top-level `await`); _lazy_ leaves init to an explicit `MidenClient.ready()` or first awaiting SDK method.
|
|
73
|
+
- **WASM threading model** — _ST_ (single-threaded) loads in any browser context; _MT_ (multi-threaded, `wasm-bindgen-rayon`) parallelizes proving across hardware threads but **requires the page to be cross-origin-isolated**.
|
|
76
74
|
|
|
77
|
-
|
|
75
|
+
| Import path | Timing | Threading | When WASM initializes | Hosting requirement |
|
|
76
|
+
| ----------------------------------- | ------ | --------- | ------------------------------------ | -------------------------------------- |
|
|
77
|
+
| `@miden-sdk/miden-sdk` | eager | ST | At module evaluation (TLA) | None — works anywhere |
|
|
78
|
+
| `@miden-sdk/miden-sdk/lazy` | lazy | ST | On `ready()` / first `await` | None — works anywhere |
|
|
79
|
+
| `@miden-sdk/miden-sdk/mt` | eager | **MT** | At module evaluation (TLA) | Cross-origin isolation (see below) |
|
|
80
|
+
| `@miden-sdk/miden-sdk/mt/lazy` | lazy | **MT** | On `ready()` / first `await` | Cross-origin isolation (see below) |
|
|
78
81
|
|
|
79
|
-
The lazy
|
|
82
|
+
The default subpaths (`/`, `/lazy`) ship the single-threaded WASM and load in any browser context. The `/mt` family enables wasm-bindgen-rayon, which gives ~3–5× faster `proveTransactionWithProver` on commodity laptops at the cost of a hard hosting requirement.
|
|
83
|
+
|
|
84
|
+
### Threading model — when to pick `/mt`
|
|
85
|
+
|
|
86
|
+
The MT build can ONLY load on a page where `self.crossOriginIsolated === true`, i.e. the host has set:
|
|
87
|
+
|
|
88
|
+
```
|
|
89
|
+
Cross-Origin-Opener-Policy: same-origin
|
|
90
|
+
Cross-Origin-Embedder-Policy: require-corp
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
Without those response headers, the browser refuses to construct `WebAssembly.Memory({ shared: true })` and the `/mt` WASM fails to instantiate at module load. The default ST subpaths don't depend on shared memory and have no such requirement.
|
|
94
|
+
|
|
95
|
+
Pick MT when:
|
|
96
|
+
|
|
97
|
+
- Your dApp does local (non-delegated) proving and you control the hosting headers.
|
|
98
|
+
- You're shipping the SDK inside a Chrome extension or other host whose manifest already sets COOP/COEP.
|
|
99
|
+
|
|
100
|
+
Pick ST when:
|
|
101
|
+
|
|
102
|
+
- You don't control the response headers (third-party host, CDN that won't set them).
|
|
103
|
+
- You're using delegated proving exclusively — the network round-trip dwarfs any local-prove speedup.
|
|
104
|
+
- You're targeting Capacitor / native WebViews — they don't expose cross-origin isolation by default.
|
|
105
|
+
|
|
106
|
+
### Setting cross-origin isolation headers
|
|
107
|
+
|
|
108
|
+
If you import `/mt` or `/mt/lazy`, the page hosting the SDK must respond with the COOP/COEP headers above. Common setups:
|
|
109
|
+
|
|
110
|
+
**Vite dev server**
|
|
111
|
+
|
|
112
|
+
```ts
|
|
113
|
+
// vite.config.ts
|
|
114
|
+
export default {
|
|
115
|
+
server: {
|
|
116
|
+
headers: {
|
|
117
|
+
"Cross-Origin-Opener-Policy": "same-origin",
|
|
118
|
+
"Cross-Origin-Embedder-Policy": "require-corp",
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
**Next.js**
|
|
125
|
+
|
|
126
|
+
```js
|
|
127
|
+
// next.config.mjs
|
|
128
|
+
export default {
|
|
129
|
+
async headers() {
|
|
130
|
+
return [
|
|
131
|
+
{
|
|
132
|
+
source: "/(.*)",
|
|
133
|
+
headers: [
|
|
134
|
+
{ key: "Cross-Origin-Opener-Policy", value: "same-origin" },
|
|
135
|
+
{ key: "Cross-Origin-Embedder-Policy", value: "require-corp" },
|
|
136
|
+
],
|
|
137
|
+
},
|
|
138
|
+
];
|
|
139
|
+
},
|
|
140
|
+
};
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
**Express / generic Node**
|
|
144
|
+
|
|
145
|
+
```js
|
|
146
|
+
app.use((_, res, next) => {
|
|
147
|
+
res.setHeader("Cross-Origin-Opener-Policy", "same-origin");
|
|
148
|
+
res.setHeader("Cross-Origin-Embedder-Policy", "require-corp");
|
|
149
|
+
next();
|
|
150
|
+
});
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
**Chrome / Firefox extension manifests (MV3)**
|
|
154
|
+
|
|
155
|
+
```json
|
|
156
|
+
{
|
|
157
|
+
"cross_origin_opener_policy": { "value": "same-origin" },
|
|
158
|
+
"cross_origin_embedder_policy": { "value": "require-corp" }
|
|
159
|
+
}
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
**Caveat — COEP side effects.** `require-corp` blocks any cross-origin resource (images, fonts, iframes, scripts) that doesn't carry `Cross-Origin-Resource-Policy: cross-origin` or appropriate CORS. If your page loads remote avatars, embeds YouTube, pulls fonts from Google, etc., those break unless you serve them from same-origin or add the right headers. This is a deployment decision; opt in only when you understand the resource graph.
|
|
163
|
+
|
|
164
|
+
If you cannot set these headers (CDN, hosting provider that doesn't allow header injection), the COI service-worker shim pattern (`gzuidhof/coi-serviceworker`) lets a small same-origin SW intercept fetches and re-inject the headers on the way back. We don't bundle this with the SDK because installing a service worker into a consumer's app is intrusive — adopt it deliberately if you need it.
|
|
165
|
+
|
|
166
|
+
### `initThreadPool(n)` — required once for MT
|
|
167
|
+
|
|
168
|
+
Every MT entry re-exports `initThreadPool` from wasm-bindgen-rayon. **Consumers must `await` it once before any prove call** (typically at app startup, or just before the first transaction):
|
|
169
|
+
|
|
170
|
+
```ts
|
|
171
|
+
import { MidenClient, initThreadPool } from "@miden-sdk/miden-sdk/mt/lazy";
|
|
172
|
+
|
|
173
|
+
await MidenClient.ready();
|
|
174
|
+
await initThreadPool(navigator.hardwareConcurrency); // size to physical threads
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
Without this call, the rayon global thread pool spawns zero workers on `wasm32` and every `par_iter(...)` falls through to a sequential loop — i.e. you've shipped multi-threaded WASM that runs single-threaded. The ST entries don't expose `initThreadPool` (no thread pool to bring up).
|
|
178
|
+
|
|
179
|
+
### Timing model — eager vs lazy
|
|
180
|
+
|
|
181
|
+
The eager entries await WASM at module top level via a small shim, 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.
|
|
182
|
+
|
|
183
|
+
The lazy entries do not run any top-level await. This matters in two environments that hang on TLA:
|
|
80
184
|
|
|
81
185
|
- **Next.js / SSR** — TLA blocks server-side module evaluation.
|
|
82
186
|
- **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
187
|
|
|
84
|
-
On
|
|
188
|
+
On a lazy entry, callers are responsible for awaiting initialization before calling any bare 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
189
|
|
|
86
190
|
### Eager usage (default)
|
|
87
191
|
|
|
@@ -113,6 +217,32 @@ await client.sync();
|
|
|
113
217
|
|
|
114
218
|
`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
219
|
|
|
220
|
+
### Multi-threaded usage (`/mt` or `/mt/lazy`)
|
|
221
|
+
|
|
222
|
+
The MT entries enable wasm-bindgen-rayon for ~3–5× faster `proveTransactionWithProver` on hardware-multi-threaded machines. Same shape as ST, plus `initThreadPool` once at startup:
|
|
223
|
+
|
|
224
|
+
```typescript
|
|
225
|
+
// Use the lazy MT entry for environments that hang on TLA (Next.js, Capacitor):
|
|
226
|
+
import { MidenClient, initThreadPool } from "@miden-sdk/miden-sdk/mt/lazy";
|
|
227
|
+
|
|
228
|
+
await MidenClient.ready();
|
|
229
|
+
await initThreadPool(navigator.hardwareConcurrency); // bring up the rayon pool ONCE
|
|
230
|
+
|
|
231
|
+
const client = await MidenClient.createTestnet();
|
|
232
|
+
// All subsequent prove calls dispatch across threads automatically.
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
Or eager:
|
|
236
|
+
|
|
237
|
+
```typescript
|
|
238
|
+
import { MidenClient, initThreadPool } from "@miden-sdk/miden-sdk/mt";
|
|
239
|
+
|
|
240
|
+
await initThreadPool(navigator.hardwareConcurrency);
|
|
241
|
+
const client = await MidenClient.createTestnet();
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
Reminder: the `/mt` entries fail to load on pages without cross-origin isolation. See "Setting cross-origin isolation headers" above. If `self.crossOriginIsolated === false` at the time of import, you'll see a `WebAssembly.Memory: shared memory requires crossOriginIsolated` (or similar) thrown out of `__wbg_init`.
|
|
245
|
+
|
|
116
246
|
### Next.js example
|
|
117
247
|
|
|
118
248
|
```tsx
|
|
@@ -156,8 +286,8 @@ Use `/lazy` from anywhere inside a Capacitor iOS/Android host (the main WKWebVie
|
|
|
156
286
|
If you're interested in contributing to the web client and need to build it locally, you can do so via:
|
|
157
287
|
|
|
158
288
|
```
|
|
159
|
-
|
|
160
|
-
|
|
289
|
+
pnpm install
|
|
290
|
+
pnpm build
|
|
161
291
|
```
|
|
162
292
|
|
|
163
293
|
This will:
|
|
@@ -170,7 +300,7 @@ This will:
|
|
|
170
300
|
To run integration tests after building, use:
|
|
171
301
|
|
|
172
302
|
```
|
|
173
|
-
|
|
303
|
+
pnpm test
|
|
174
304
|
```
|
|
175
305
|
|
|
176
306
|
This runs a suite of integration tests to verify the SDK’s functionality in a web context.
|
|
@@ -184,12 +314,12 @@ Follow the steps below to produce the contents that get published to npm (`dist/
|
|
|
184
314
|
- Install Node.js ≥18 and Yarn.
|
|
185
315
|
2. **Install dependencies**
|
|
186
316
|
```bash
|
|
187
|
-
|
|
317
|
+
pnpm install
|
|
188
318
|
```
|
|
189
319
|
This installs both the JavaScript tooling and the `@wasm-tool/rollup-plugin-rust` dependency that compiles the Rust crate.
|
|
190
320
|
3. **Build the package**
|
|
191
321
|
```bash
|
|
192
|
-
|
|
322
|
+
pnpm build
|
|
193
323
|
```
|
|
194
324
|
The `build` script (see `package.json`) performs the following:
|
|
195
325
|
- Removes the previous `dist/` directory (`rimraf dist`).
|
|
@@ -202,14 +332,14 @@ Follow the steps below to produce the contents that get published to npm (`dist/
|
|
|
202
332
|
- `dist/index.d.ts` and the rest of the `.d.ts` files provide the TypeScript surface.
|
|
203
333
|
Use `npm pack` if you want to preview the exact tarball that would be published.
|
|
204
334
|
|
|
205
|
-
> Tip: during development you can set `MIDEN_WEB_DEV=true` before running `
|
|
335
|
+
> Tip: during development you can set `MIDEN_WEB_DEV=true` before running `pnpm build` (or run `npm run build-dev`) to skip the clean step and keep extra debugging metadata in the bundled output. This debugging metadata also includes debug symbols for the generated wasm binary
|
|
206
336
|
|
|
207
337
|
### Checking the generated TypeScript bindings
|
|
208
338
|
|
|
209
339
|
The script at `crates/web-client/scripts/check-bindgen-types.js` verifies that every type exported by the generated wasm bindings (`dist/crates/miden_client_web.d.ts`) is re-exported from the public declarations (`js/types/index.d.ts`). Run it after a build with:
|
|
210
340
|
|
|
211
341
|
```
|
|
212
|
-
|
|
342
|
+
pnpm check:wasm-types
|
|
213
343
|
```
|
|
214
344
|
|
|
215
345
|
`WebClient` is intentionally excluded because the wrapper defines its own implementation. If the check reports missing exports, update `js/types/index.d.ts` so consumers get the full generated surface.
|