@cloak.dev/sdk 0.2.11 → 0.2.12

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/CHANGELOG.md CHANGED
@@ -7,6 +7,21 @@ the README's "Version and compatibility" section and in the git history.
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.2.12]
11
+
12
+ ### Fixed
13
+
14
+ * A proof no longer fails with "Failed to execute 'postMessage' on 'Worker': Data cannot be cloned, out of
15
+ memory" when the browser cannot hold one prover worker per core. On that error the SDK frees the
16
+ workers, retries with 4, and if that also runs out of memory proves single-threaded. Previously
17
+ every retry in the same tab failed the same way, because the workers are cached for the page's
18
+ lifetime. Other proving errors are thrown unchanged.
19
+
20
+ ### Changed
21
+
22
+ * The `Network` type and note validation no longer accept `"devnet"`; the accepted values are
23
+ `"localnet"`, `"testnet"` and `"mainnet"`.
24
+
10
25
  ## [0.2.11]
11
26
 
12
27
  ### Fixed
package/README.md CHANGED
@@ -5,13 +5,13 @@ per-mint pool, send privately inside the pool, withdraw to any address, or swap
5
5
  USDC/USDT with the output landing in a public token account. Groth16 proofs are generated
6
6
  client-side (snarkjs) and verified on-chain by the Cloak program.
7
7
 
8
- Version 0.2.11 targets the mainnet program deployed on 2026-08-24 and the ceremony-frozen
8
+ Version 0.2.12 targets the mainnet program deployed on 2026-08-24 and the ceremony-frozen
9
9
  `cloak-transaction-0.2.0` circuit bundle. See [Version and compatibility](#version-and-compatibility).
10
10
 
11
11
  ## Installation
12
12
 
13
13
  ```bash
14
- npm install @cloak.dev/sdk@^0.2.11
14
+ npm install @cloak.dev/sdk@^0.2.12
15
15
  ```
16
16
 
17
17
  The SDK is built on [`@solana/kit`](https://github.com/anza-xyz/kit) and re-exports the pieces an
@@ -73,22 +73,27 @@ registration step (some of the shipped examples set it on a local fork); it is n
73
73
  Do not expose `programId`, the relay URL or the circuits base as end-user input. Wallet adapters are
74
74
  the in-app signer; keypair files belong to scripts only.
75
75
 
76
- ### Devnet and local
76
+ ### Mainnet only
77
77
 
78
- The same SDK runs against a devnet or local deployment by pointing the three coordinates at it:
78
+ Cloak runs on Solana mainnet only. Test with small amounts (the
79
+ minimum deposit is 0.01 SOL). The published package talks to the mainnet program and
80
+ `https://api.cloak.ag` and nothing else.
81
+
82
+ ### Local fork (SDK contributors)
83
+
84
+ The shipped examples and scripts default to a local mainnet fork (`http://127.0.0.1:8899`) with a
85
+ local relay (`http://127.0.0.1:5500`), configured through environment variables they read
86
+ themselves:
79
87
 
80
88
  ```bash
81
- SOLANA_RPC_URL=https://api.devnet.solana.com # or http://127.0.0.1:8899 for a local fork
82
- CLOAK_RELAY_URL=<endpoint serving that deployment> # read by examples/ and scripts/, NOT by the SDK
83
- CLOAK_PROGRAM_ID=<program id of that deployment> # examples read this; pass it as programId in your code
89
+ SOLANA_RPC_URL=http://127.0.0.1:8899
90
+ CLOAK_RELAY_URL=http://127.0.0.1:5500 # read by examples/ and scripts/, NOT by the SDK
91
+ CLOAK_PROGRAM_ID=<program id of the local deployment>
84
92
  ```
85
93
 
86
- `CLOAK_RELAY_URL` configures the shipped examples and scripts, which pass its value as `relayUrl`.
87
- The SDK itself does not read it: the endpoint a build may talk to comes from `src/config/relay.ts`,
88
- so pointing at a devnet or local deployment means editing that file in a checkout and building it.
89
-
90
- The shipped examples default to a local fork (`http://127.0.0.1:8899`) with a local relay
91
- (`http://127.0.0.1:5500`); see [Examples](#examples).
94
+ The SDK itself does not read `CLOAK_RELAY_URL`: the endpoint a build may talk to comes from
95
+ `src/config/relay.ts`, so running against a local deployment means editing that file in a checkout
96
+ and building it, as described above. See [Examples](#examples).
92
97
 
93
98
  ## Quick start: private SOL send (single file, keypair)
94
99
 
@@ -131,8 +136,10 @@ async function main() {
131
136
  const amount = BigInt(lamportsArg);
132
137
 
133
138
  // The wallet's long-lived UTXO keypair and its viewing base (nk). A real wallet derives the
134
- // keypair from its seed (deriveUtxoKeypairFromSpendKey); a throwaway keypair keeps this script
135
- // self-contained.
139
+ // keypair from a seed it stores (deriveSpendKey(seed) -> deriveUtxoKeypairFromSpendKey); a
140
+ // throwaway keypair keeps this script self-contained. Throwaway means exactly that: if the run
141
+ // stops between the deposit and the withdrawal, the key is gone and so is the deposited note.
142
+ // Never use one for more than test amounts.
136
143
  const owner = await generateUtxoKeypair();
137
144
  const nk = getNkFromUtxoPrivateKey(owner.privateKey);
138
145
 
@@ -225,6 +232,7 @@ await transact(params, {
225
232
  walletPublicKey: signer.address,
226
233
  chainNoteViewingKeyNk: nk,
227
234
  chainNoteSalt: noteSalt,
235
+ ownerUtxoKeypair: owner, // the user's seed-derived UTXO keypair; it owns the note
228
236
  });
229
237
  ```
230
238
 
@@ -251,6 +259,7 @@ await transact(
251
259
  signMessage: (message) => wallet.signMessage(message),
252
260
  walletPublicKey: signer.address, // becomes the authenticated sender
253
261
  chainNoteViewingKeyNk: nk,
262
+ ownerUtxoKeypair: owner, // mandatory on every spend flow: it owns any change
254
263
  },
255
264
  );
256
265
  ```
@@ -790,7 +799,7 @@ relay endpoint and the localhost-RPC check.
790
799
 
791
800
  ## Version and compatibility
792
801
 
793
- - SDK 0.2.11 pairs with the mainnet program at `zh1eLd6rSphLejbFfJEneUwzHRfMKxgzrgkfwA6qRkW`
802
+ - SDK 0.2.12 pairs with the mainnet program at `zh1eLd6rSphLejbFfJEneUwzHRfMKxgzrgkfwA6qRkW`
794
803
  (deployed 2026-08-24) and the 0.2.0 circuit bundle — the program and circuit bundle are unchanged
795
804
  since 0.2.0; only the SDK package version has moved. The 0.2.5 flows were exercised on mainnet on
796
805
  2026-08-25: deposit, private send and withdraw on SOL, USDC and USDT; swaps SOL to USDC and USDT;
@@ -821,6 +830,9 @@ relay endpoint and the localhost-RPC check.
821
830
  [CHANGELOG.md](CHANGELOG.md)).
822
831
  - 0.2.11 lets that bridge send a transaction the wallet added its own instructions to (Solflare's
823
832
  guard instructions); 0.2.10 refused it (see [CHANGELOG.md](CHANGELOG.md)).
833
+ - 0.2.12 retries a proof with fewer workers, then single-threaded, when the browser runs out of
834
+ memory handing data to the prover workers; it changes no wire format, hash or signature (see
835
+ [CHANGELOG.md](CHANGELOG.md)).
824
836
  - Proofs generated with the 0.1.x circuits are rejected by the mainnet program. SDK 0.1.x builds
825
837
  (which ship the 0.1.0 bundle) are not usable against it; upgrade to 0.2.x.
826
838
  - The note-based `CloakSDK` class is removed in 0.2.0. It targeted the pre-0.2.0 instruction layout
package/dist/index.cjs CHANGED
@@ -979,8 +979,8 @@ function validateNote(note) {
979
979
  if (typeof note.timestamp !== "number" || note.timestamp <= 0) {
980
980
  throw new Error("Timestamp must be a positive number");
981
981
  }
982
- if (!["localnet", "devnet", "testnet", "mainnet"].includes(note.network)) {
983
- throw new Error("Network must be localnet, devnet, testnet, or mainnet");
982
+ if (!["localnet", "testnet", "mainnet"].includes(note.network)) {
983
+ throw new Error("Network must be localnet, testnet, or mainnet");
984
984
  }
985
985
  if (note.depositSignature !== void 0 && typeof note.depositSignature !== "string") {
986
986
  throw new Error("Deposit signature must be a string");
@@ -1206,9 +1206,6 @@ function detectNetworkFromRpcUrl(rpcUrl) {
1206
1206
  if (lowerUrl.includes("testnet") || lowerUrl.includes("api.testnet")) {
1207
1207
  return "testnet";
1208
1208
  }
1209
- if (lowerUrl.includes("devnet") || lowerUrl.includes("api.devnet")) {
1210
- return "devnet";
1211
- }
1212
1209
  if (lowerUrl.includes("localhost") || lowerUrl.includes("127.0.0.1") || lowerUrl.includes("local")) {
1213
1210
  return "localnet";
1214
1211
  }
@@ -1218,8 +1215,6 @@ function getRpcUrlForNetwork(network) {
1218
1215
  switch (network) {
1219
1216
  case "mainnet":
1220
1217
  return "https://api.mainnet-beta.solana.com";
1221
- case "devnet":
1222
- return "https://api.devnet.solana.com";
1223
1218
  case "localnet":
1224
1219
  return "http://localhost:8899";
1225
1220
  default:
@@ -1234,11 +1229,11 @@ function isValidRpcUrl(url) {
1234
1229
  return false;
1235
1230
  }
1236
1231
  }
1237
- function getExplorerUrl(signature, network = "devnet") {
1232
+ function getExplorerUrl(signature, network = "mainnet") {
1238
1233
  const cluster = network === "mainnet" ? "" : `?cluster=${network}`;
1239
1234
  return `https://explorer.solana.com/tx/${signature}${cluster}`;
1240
1235
  }
1241
- function getAddressExplorerUrl(address2, network = "devnet") {
1236
+ function getAddressExplorerUrl(address2, network = "mainnet") {
1242
1237
  const cluster = network === "mainnet" ? "" : `?cluster=${network}`;
1243
1238
  return `https://explorer.solana.com/address/${address2}${cluster}`;
1244
1239
  }
@@ -4467,10 +4462,6 @@ function buildRangeRiskScoreJob(OracleJob, walletAddress) {
4467
4462
  });
4468
4463
  }
4469
4464
  async function getQueue(sb, rpcUrl) {
4470
- const network = detectNetworkFromRpcUrl(rpcUrl);
4471
- if (network === "devnet") {
4472
- return await sb.getDefaultDevnetQueue(rpcUrl);
4473
- }
4474
4465
  return await sb.getDefaultQueue(rpcUrl);
4475
4466
  }
4476
4467
  async function fetchRiskQuoteIx(connection, wallet, rangeApiKey) {
@@ -7415,13 +7406,62 @@ async function generateTransactionProof(inputs, onProgress) {
7415
7406
  onProgress?.(10);
7416
7407
  onProgress?.(30);
7417
7408
  const { wasmPath: wasmInput, zkeyPath: zkeyInput } = await resolveTransactionCircuitFiles();
7418
- const { proof, publicSignals } = await snarkjs.groth16.fullProve(
7419
- inputs,
7420
- wasmInput,
7421
- zkeyInput
7422
- );
7409
+ let result;
7410
+ try {
7411
+ result = await snarkjs.groth16.fullProve(inputs, wasmInput, zkeyInput);
7412
+ } catch (err) {
7413
+ if (!isProverOutOfMemory(err)) throw err;
7414
+ await terminateThreadedCurve();
7415
+ try {
7416
+ result = await withReportedCores(
7417
+ REDUCED_PROVER_WORKERS,
7418
+ () => snarkjs.groth16.fullProve(inputs, wasmInput, zkeyInput)
7419
+ );
7420
+ } catch (retryErr) {
7421
+ if (!isProverOutOfMemory(retryErr)) throw retryErr;
7422
+ await terminateThreadedCurve();
7423
+ result = await snarkjs.groth16.fullProve(inputs, wasmInput, zkeyInput, void 0, void 0, {
7424
+ singleThread: true
7425
+ });
7426
+ }
7427
+ }
7423
7428
  onProgress?.(100);
7424
- return { proof, publicSignals };
7429
+ return { proof: result.proof, publicSignals: result.publicSignals };
7430
+ }
7431
+ function isProverOutOfMemory(err) {
7432
+ const name = err?.name;
7433
+ const message = String(err?.message ?? err ?? "");
7434
+ if (name === "DataCloneError") return true;
7435
+ if (/out of memory/i.test(message)) return true;
7436
+ return name === "RangeError" && /(allocat|array buffer|memory)/i.test(message);
7437
+ }
7438
+ var REDUCED_PROVER_WORKERS = 4;
7439
+ async function withReportedCores(cores, fn) {
7440
+ const nav = globalThis.navigator;
7441
+ const reported = nav?.hardwareConcurrency;
7442
+ let shadowed = false;
7443
+ if (nav && typeof reported === "number" && reported > cores) {
7444
+ try {
7445
+ Object.defineProperty(nav, "hardwareConcurrency", { value: cores, configurable: true });
7446
+ shadowed = true;
7447
+ } catch {
7448
+ }
7449
+ }
7450
+ try {
7451
+ return await fn();
7452
+ } finally {
7453
+ if (shadowed) delete nav.hardwareConcurrency;
7454
+ }
7455
+ }
7456
+ async function terminateThreadedCurve() {
7457
+ const g = globalThis;
7458
+ const curve = g.curve_bn128;
7459
+ if (!curve) return;
7460
+ try {
7461
+ await curve.terminate?.();
7462
+ } catch {
7463
+ }
7464
+ g.curve_bn128 = null;
7425
7465
  }
7426
7466
  function proofToBytesLocal(proof) {
7427
7467
  const result = new Uint8Array(256);
@@ -15779,7 +15819,7 @@ async function withShieldRetries(attempt, hooks = {}) {
15779
15819
  }
15780
15820
 
15781
15821
  // src/index.ts
15782
- var VERSION = "0.2.11";
15822
+ var VERSION = "0.2.12";
15783
15823
  var SCANNER_SUPPORTS_TRANSACT_SWAP = true;
15784
15824
  // Annotate the CommonJS export names for ESM import in node:
15785
15825
  0 && (module.exports = {
package/dist/index.d.cts CHANGED
@@ -84,7 +84,7 @@ interface EncryptedMetadataBundle {
84
84
  /**
85
85
  * Supported Solana networks
86
86
  */
87
- type Network = "localnet" | "devnet" | "mainnet" | "testnet";
87
+ type Network = "localnet" | "mainnet" | "testnet";
88
88
  /**
89
89
  * Minimal wallet adapter interface
90
90
  * Compatible with @solana/wallet-adapter-base
@@ -1449,7 +1449,7 @@ declare function validateTransfers(recipients: Array<{
1449
1449
  * Detect network from RPC URL
1450
1450
  *
1451
1451
  * Attempts to detect the Solana network from common RPC URL patterns.
1452
- * Falls back to devnet if unable to detect.
1452
+ * Falls back to mainnet if unable to detect.
1453
1453
  */
1454
1454
  declare function detectNetworkFromRpcUrl(rpcUrl?: string): Network;
1455
1455
  /**
@@ -6559,7 +6559,7 @@ declare function withShieldRetries<T>(attempt: (attemptNo: number) => Promise<T>
6559
6559
  * @packageDocumentation
6560
6560
  */
6561
6561
 
6562
- declare const VERSION = "0.2.11";
6562
+ declare const VERSION = "0.2.12";
6563
6563
  /** True when scanner supports TransactSwap (tag 1). Check this to verify the correct SDK bundle is loaded. */
6564
6564
  declare const SCANNER_SUPPORTS_TRANSACT_SWAP = true;
6565
6565
 
package/dist/index.d.ts CHANGED
@@ -84,7 +84,7 @@ interface EncryptedMetadataBundle {
84
84
  /**
85
85
  * Supported Solana networks
86
86
  */
87
- type Network = "localnet" | "devnet" | "mainnet" | "testnet";
87
+ type Network = "localnet" | "mainnet" | "testnet";
88
88
  /**
89
89
  * Minimal wallet adapter interface
90
90
  * Compatible with @solana/wallet-adapter-base
@@ -1449,7 +1449,7 @@ declare function validateTransfers(recipients: Array<{
1449
1449
  * Detect network from RPC URL
1450
1450
  *
1451
1451
  * Attempts to detect the Solana network from common RPC URL patterns.
1452
- * Falls back to devnet if unable to detect.
1452
+ * Falls back to mainnet if unable to detect.
1453
1453
  */
1454
1454
  declare function detectNetworkFromRpcUrl(rpcUrl?: string): Network;
1455
1455
  /**
@@ -6559,7 +6559,7 @@ declare function withShieldRetries<T>(attempt: (attemptNo: number) => Promise<T>
6559
6559
  * @packageDocumentation
6560
6560
  */
6561
6561
 
6562
- declare const VERSION = "0.2.11";
6562
+ declare const VERSION = "0.2.12";
6563
6563
  /** True when scanner supports TransactSwap (tag 1). Check this to verify the correct SDK bundle is loaded. */
6564
6564
  declare const SCANNER_SUPPORTS_TRANSACT_SWAP = true;
6565
6565
 
package/dist/index.js CHANGED
@@ -86,8 +86,8 @@ function validateNote(note) {
86
86
  if (typeof note.timestamp !== "number" || note.timestamp <= 0) {
87
87
  throw new Error("Timestamp must be a positive number");
88
88
  }
89
- if (!["localnet", "devnet", "testnet", "mainnet"].includes(note.network)) {
90
- throw new Error("Network must be localnet, devnet, testnet, or mainnet");
89
+ if (!["localnet", "testnet", "mainnet"].includes(note.network)) {
90
+ throw new Error("Network must be localnet, testnet, or mainnet");
91
91
  }
92
92
  if (note.depositSignature !== void 0 && typeof note.depositSignature !== "string") {
93
93
  throw new Error("Deposit signature must be a string");
@@ -309,9 +309,6 @@ function detectNetworkFromRpcUrl(rpcUrl) {
309
309
  if (lowerUrl.includes("testnet") || lowerUrl.includes("api.testnet")) {
310
310
  return "testnet";
311
311
  }
312
- if (lowerUrl.includes("devnet") || lowerUrl.includes("api.devnet")) {
313
- return "devnet";
314
- }
315
312
  if (lowerUrl.includes("localhost") || lowerUrl.includes("127.0.0.1") || lowerUrl.includes("local")) {
316
313
  return "localnet";
317
314
  }
@@ -321,8 +318,6 @@ function getRpcUrlForNetwork(network) {
321
318
  switch (network) {
322
319
  case "mainnet":
323
320
  return "https://api.mainnet-beta.solana.com";
324
- case "devnet":
325
- return "https://api.devnet.solana.com";
326
321
  case "localnet":
327
322
  return "http://localhost:8899";
328
323
  default:
@@ -337,11 +332,11 @@ function isValidRpcUrl(url) {
337
332
  return false;
338
333
  }
339
334
  }
340
- function getExplorerUrl(signature, network = "devnet") {
335
+ function getExplorerUrl(signature, network = "mainnet") {
341
336
  const cluster = network === "mainnet" ? "" : `?cluster=${network}`;
342
337
  return `https://explorer.solana.com/tx/${signature}${cluster}`;
343
338
  }
344
- function getAddressExplorerUrl(address2, network = "devnet") {
339
+ function getAddressExplorerUrl(address2, network = "mainnet") {
345
340
  const cluster = network === "mainnet" ? "" : `?cluster=${network}`;
346
341
  return `https://explorer.solana.com/address/${address2}${cluster}`;
347
342
  }
@@ -3579,10 +3574,6 @@ function buildRangeRiskScoreJob(OracleJob, walletAddress) {
3579
3574
  });
3580
3575
  }
3581
3576
  async function getQueue(sb, rpcUrl) {
3582
- const network = detectNetworkFromRpcUrl(rpcUrl);
3583
- if (network === "devnet") {
3584
- return await sb.getDefaultDevnetQueue(rpcUrl);
3585
- }
3586
3577
  return await sb.getDefaultQueue(rpcUrl);
3587
3578
  }
3588
3579
  async function fetchRiskQuoteIx(connection, wallet, rangeApiKey) {
@@ -6517,13 +6508,62 @@ async function generateTransactionProof(inputs, onProgress) {
6517
6508
  onProgress?.(10);
6518
6509
  onProgress?.(30);
6519
6510
  const { wasmPath: wasmInput, zkeyPath: zkeyInput } = await resolveTransactionCircuitFiles();
6520
- const { proof, publicSignals } = await snarkjs.groth16.fullProve(
6521
- inputs,
6522
- wasmInput,
6523
- zkeyInput
6524
- );
6511
+ let result;
6512
+ try {
6513
+ result = await snarkjs.groth16.fullProve(inputs, wasmInput, zkeyInput);
6514
+ } catch (err) {
6515
+ if (!isProverOutOfMemory(err)) throw err;
6516
+ await terminateThreadedCurve();
6517
+ try {
6518
+ result = await withReportedCores(
6519
+ REDUCED_PROVER_WORKERS,
6520
+ () => snarkjs.groth16.fullProve(inputs, wasmInput, zkeyInput)
6521
+ );
6522
+ } catch (retryErr) {
6523
+ if (!isProverOutOfMemory(retryErr)) throw retryErr;
6524
+ await terminateThreadedCurve();
6525
+ result = await snarkjs.groth16.fullProve(inputs, wasmInput, zkeyInput, void 0, void 0, {
6526
+ singleThread: true
6527
+ });
6528
+ }
6529
+ }
6525
6530
  onProgress?.(100);
6526
- return { proof, publicSignals };
6531
+ return { proof: result.proof, publicSignals: result.publicSignals };
6532
+ }
6533
+ function isProverOutOfMemory(err) {
6534
+ const name = err?.name;
6535
+ const message = String(err?.message ?? err ?? "");
6536
+ if (name === "DataCloneError") return true;
6537
+ if (/out of memory/i.test(message)) return true;
6538
+ return name === "RangeError" && /(allocat|array buffer|memory)/i.test(message);
6539
+ }
6540
+ var REDUCED_PROVER_WORKERS = 4;
6541
+ async function withReportedCores(cores, fn) {
6542
+ const nav = globalThis.navigator;
6543
+ const reported = nav?.hardwareConcurrency;
6544
+ let shadowed = false;
6545
+ if (nav && typeof reported === "number" && reported > cores) {
6546
+ try {
6547
+ Object.defineProperty(nav, "hardwareConcurrency", { value: cores, configurable: true });
6548
+ shadowed = true;
6549
+ } catch {
6550
+ }
6551
+ }
6552
+ try {
6553
+ return await fn();
6554
+ } finally {
6555
+ if (shadowed) delete nav.hardwareConcurrency;
6556
+ }
6557
+ }
6558
+ async function terminateThreadedCurve() {
6559
+ const g = globalThis;
6560
+ const curve = g.curve_bn128;
6561
+ if (!curve) return;
6562
+ try {
6563
+ await curve.terminate?.();
6564
+ } catch {
6565
+ }
6566
+ g.curve_bn128 = null;
6527
6567
  }
6528
6568
  function proofToBytesLocal(proof) {
6529
6569
  const result = new Uint8Array(256);
@@ -14872,7 +14912,7 @@ async function withShieldRetries(attempt, hooks = {}) {
14872
14912
  }
14873
14913
 
14874
14914
  // src/index.ts
14875
- var VERSION = "0.2.11";
14915
+ var VERSION = "0.2.12";
14876
14916
  var SCANNER_SUPPORTS_TRANSACT_SWAP = true;
14877
14917
  export {
14878
14918
  AccountRole,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloak.dev/sdk",
3
3
  "description": "Shield, send, and swap on Solana privately — TypeScript SDK with UTXO-based zero-knowledge transactions",
4
- "version": "0.2.11",
4
+ "version": "0.2.12",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
7
7
  "module": "dist/index.js",