@miden-sdk/miden-sdk 0.15.0-alpha.4 → 0.15.0-alpha.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.
Files changed (59) hide show
  1. package/README.md +139 -9
  2. package/dist/mt/Cargo-smJQCGjz.js +26146 -0
  3. package/dist/mt/Cargo-smJQCGjz.js.map +1 -0
  4. package/dist/{api-types.d.ts → mt/api-types.d.ts} +154 -4
  5. package/dist/mt/assets/miden_client_web.wasm +0 -0
  6. package/dist/mt/crates/miden_client_web.d.ts +4791 -0
  7. package/dist/mt/eager.js +38 -0
  8. package/dist/mt/eager.js.map +1 -0
  9. package/dist/{index.d.ts → mt/index.d.ts} +4 -2
  10. package/dist/mt/index.js +3778 -0
  11. package/dist/mt/index.js.map +1 -0
  12. package/dist/{wasm.js → mt/wasm.js} +1 -1
  13. package/dist/mt/wasm.js.map +1 -0
  14. package/dist/mt/workerHelpers.js +28 -0
  15. package/dist/mt/workers/Cargo-smJQCGjz-q4GYXDiD.js +26147 -0
  16. package/dist/mt/workers/Cargo-smJQCGjz-q4GYXDiD.js.map +1 -0
  17. package/dist/mt/workers/assets/miden_client_web.wasm +0 -0
  18. package/dist/mt/workers/web-client-methods-worker.js +26885 -0
  19. package/dist/mt/workers/web-client-methods-worker.js.map +1 -0
  20. package/dist/{workers → mt/workers}/web-client-methods-worker.module.js +17 -1
  21. package/dist/mt/workers/web-client-methods-worker.module.js.map +1 -0
  22. package/dist/mt/workers/workerHelpers.js +28 -0
  23. package/dist/{Cargo-CVlXCH_2.js → st/Cargo-CG4XszZo.js} +698 -495
  24. package/dist/st/Cargo-CG4XszZo.js.map +1 -0
  25. package/dist/st/api-types.d.ts +1140 -0
  26. package/dist/{workers → st}/assets/miden_client_web.wasm +0 -0
  27. package/dist/{crates → st/crates}/miden_client_web.d.ts +342 -196
  28. package/dist/st/docs-entry.d.ts +38 -0
  29. package/dist/{eager.js → st/eager.js} +1 -1
  30. package/dist/st/eager.js.map +1 -0
  31. package/dist/st/index.d.ts +182 -0
  32. package/dist/{index.js → st/index.js} +425 -19
  33. package/dist/st/index.js.map +1 -0
  34. package/dist/st/wasm.js +23 -0
  35. package/dist/st/wasm.js.map +1 -0
  36. package/dist/{workers/Cargo-CVlXCH_2-CWA-5vlh.js → st/workers/Cargo-CG4XszZo-S7EHAZSa.js} +698 -495
  37. package/dist/st/workers/Cargo-CG4XszZo-S7EHAZSa.js.map +1 -0
  38. package/dist/{assets → st/workers/assets}/miden_client_web.wasm +0 -0
  39. package/dist/{workers → st/workers}/web-client-methods-worker.js +715 -496
  40. package/dist/st/workers/web-client-methods-worker.js.map +1 -0
  41. package/dist/st/workers/web-client-methods-worker.module.js +575 -0
  42. package/dist/st/workers/web-client-methods-worker.module.js.map +1 -0
  43. package/js/client.js +166 -2
  44. package/js/node/napi-compat.js +15 -0
  45. package/js/node-index.js +0 -1
  46. package/js/resources/accounts.js +4 -6
  47. package/js/resources/transactions.js +134 -0
  48. package/lazy/package.json +2 -2
  49. package/mt/lazy/package.json +4 -0
  50. package/mt/package.json +4 -0
  51. package/package.json +30 -15
  52. package/dist/Cargo-CVlXCH_2.js.map +0 -1
  53. package/dist/eager.js.map +0 -1
  54. package/dist/index.js.map +0 -1
  55. package/dist/wasm.js.map +0 -1
  56. package/dist/workers/Cargo-CVlXCH_2-CWA-5vlh.js.map +0 -1
  57. package/dist/workers/web-client-methods-worker.js.map +0 -1
  58. package/dist/workers/web-client-methods-worker.module.js.map +0 -1
  59. /package/dist/{docs-entry.d.ts → mt/docs-entry.d.ts} +0 -0
package/README.md CHANGED
@@ -65,23 +65,127 @@ pnpm 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`
68
+ ## Entry Points: Eager / Lazy × ST / MT
69
69
 
70
- The SDK ships two entry points with an identical public API. They differ only in **when** the WASM module is initialized.
70
+ The SDK ships **four** entry points with an identical public API. They vary along two orthogonal axes:
71
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 |
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
- 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.
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 entry does not run any top-level await. This matters in two environments that hang on TLA:
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 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.
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