@cloak.ag/sdk 1.0.7 → 1.0.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/dist/index.cjs CHANGED
@@ -5,9 +5,6 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __getProtoOf = Object.getPrototypeOf;
7
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __esm = (fn, res) => function __init() {
9
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
10
- };
11
8
  var __export = (target, all) => {
12
9
  for (var name in all)
13
10
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -30,7 +27,159 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
30
27
  ));
31
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
32
29
 
30
+ // src/index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ CLOAK_PROGRAM_ID: () => CLOAK_PROGRAM_ID,
34
+ CloakError: () => CloakError,
35
+ CloakSDK: () => CloakSDK,
36
+ DEFAULT_CIRCUITS_URL: () => DEFAULT_CIRCUITS_URL,
37
+ EXPECTED_CIRCUIT_HASHES: () => EXPECTED_CIRCUIT_HASHES,
38
+ FIXED_FEE_LAMPORTS: () => FIXED_FEE_LAMPORTS,
39
+ LAMPORTS_PER_SOL: () => LAMPORTS_PER_SOL,
40
+ LocalStorageAdapter: () => LocalStorageAdapter,
41
+ MemoryStorageAdapter: () => MemoryStorageAdapter,
42
+ RelayService: () => RelayService,
43
+ RootNotFoundError: () => RootNotFoundError,
44
+ ShieldPoolErrors: () => ShieldPoolErrors,
45
+ VARIABLE_FEE_RATE: () => VARIABLE_FEE_RATE,
46
+ VERSION: () => VERSION,
47
+ areCircuitsAvailable: () => areCircuitsAvailable,
48
+ bigintToBytes32: () => bigintToBytes32,
49
+ buildPublicInputsBytes: () => buildPublicInputsBytes,
50
+ bytesToHex: () => bytesToHex,
51
+ calculateFee: () => calculateFee2,
52
+ calculateRelayFee: () => calculateRelayFee,
53
+ cleanupStalePendingOperations: () => cleanupStalePendingOperations,
54
+ clearPendingDeposits: () => clearPendingDeposits,
55
+ clearPendingWithdrawals: () => clearPendingWithdrawals,
56
+ computeCommitment: () => computeCommitment,
57
+ computeMerkleRoot: () => computeMerkleRoot,
58
+ computeNullifier: () => computeNullifier,
59
+ computeNullifierAsync: () => computeNullifierAsync,
60
+ computeNullifierSync: () => computeNullifierSync,
61
+ computeOutputsHash: () => computeOutputsHash,
62
+ computeOutputsHashAsync: () => computeOutputsHashAsync,
63
+ computeOutputsHashSync: () => computeOutputsHashSync,
64
+ computeProofForLatestDeposit: () => computeProofForLatestDeposit,
65
+ computeProofFromChain: () => computeProofFromChain,
66
+ computeSwapOutputsHash: () => computeSwapOutputsHash,
67
+ computeSwapOutputsHashAsync: () => computeSwapOutputsHashAsync,
68
+ computeSwapOutputsHashSync: () => computeSwapOutputsHashSync,
69
+ copyNoteToClipboard: () => copyNoteToClipboard,
70
+ createCloakError: () => createCloakError,
71
+ createDepositInstruction: () => createDepositInstruction,
72
+ createLogger: () => createLogger,
73
+ deriveSpendKey: () => deriveSpendKey,
74
+ deriveViewKey: () => deriveViewKey,
75
+ detectNetworkFromRpcUrl: () => detectNetworkFromRpcUrl,
76
+ downloadNote: () => downloadNote,
77
+ encodeNoteSimple: () => encodeNoteSimple,
78
+ encryptNoteForRecipient: () => encryptNoteForRecipient,
79
+ exportKeys: () => exportKeys,
80
+ exportNote: () => exportNote,
81
+ exportWalletKeys: () => exportWalletKeys,
82
+ filterNotesByNetwork: () => filterNotesByNetwork,
83
+ filterWithdrawableNotes: () => filterWithdrawableNotes,
84
+ findNoteByCommitment: () => findNoteByCommitment,
85
+ formatAmount: () => formatAmount,
86
+ formatErrorForLogging: () => formatErrorForLogging,
87
+ formatSol: () => formatSol,
88
+ generateCloakKeys: () => generateCloakKeys,
89
+ generateCommitment: () => generateCommitment,
90
+ generateCommitmentAsync: () => generateCommitmentAsync,
91
+ generateMasterSeed: () => generateMasterSeed,
92
+ generateNote: () => generateNote,
93
+ generateNoteFromWallet: () => generateNoteFromWallet,
94
+ generateWithdrawRegularProof: () => generateWithdrawRegularProof,
95
+ generateWithdrawSwapProof: () => generateWithdrawSwapProof,
96
+ getAddressExplorerUrl: () => getAddressExplorerUrl,
97
+ getDefaultCircuitsPath: () => getDefaultCircuitsPath,
98
+ getDistributableAmount: () => getDistributableAmount2,
99
+ getExplorerUrl: () => getExplorerUrl,
100
+ getNullifierPDA: () => getNullifierPDA,
101
+ getPendingOperationsSummary: () => getPendingOperationsSummary,
102
+ getPublicKey: () => getPublicKey,
103
+ getPublicViewKey: () => getPublicViewKey,
104
+ getRecipientAmount: () => getRecipientAmount,
105
+ getRpcUrlForNetwork: () => getRpcUrlForNetwork,
106
+ getShieldPoolPDAs: () => getShieldPoolPDAs,
107
+ getSwapStatePDA: () => getSwapStatePDA,
108
+ getViewKey: () => getViewKey,
109
+ hasPendingOperations: () => hasPendingOperations,
110
+ hexToBigint: () => hexToBigint,
111
+ hexToBytes: () => hexToBytes,
112
+ importKeys: () => importKeys,
113
+ importWalletKeys: () => importWalletKeys,
114
+ isDebugEnabled: () => isDebugEnabled,
115
+ isRootNotFoundError: () => isRootNotFoundError,
116
+ isValidHex: () => isValidHex,
117
+ isValidRpcUrl: () => isValidRpcUrl,
118
+ isValidSolanaAddress: () => isValidSolanaAddress,
119
+ isWithdrawable: () => isWithdrawable,
120
+ keypairToAdapter: () => keypairToAdapter,
121
+ loadPendingDeposits: () => loadPendingDeposits,
122
+ loadPendingWithdrawals: () => loadPendingWithdrawals,
123
+ parseAmount: () => parseAmount,
124
+ parseError: () => parseError,
125
+ parseNote: () => parseNote,
126
+ parseTransactionError: () => parseTransactionError,
127
+ poseidonHash: () => poseidonHash,
128
+ prepareEncryptedOutput: () => prepareEncryptedOutput,
129
+ prepareEncryptedOutputForRecipient: () => prepareEncryptedOutputForRecipient,
130
+ proofToBytes: () => proofToBytes,
131
+ pubkeyToLimbs: () => pubkeyToLimbs,
132
+ randomBytes: () => randomBytes,
133
+ readMerkleTreeState: () => readMerkleTreeState,
134
+ removePendingDeposit: () => removePendingDeposit,
135
+ removePendingWithdrawal: () => removePendingWithdrawal,
136
+ savePendingDeposit: () => savePendingDeposit,
137
+ savePendingWithdrawal: () => savePendingWithdrawal,
138
+ scanNotesForWallet: () => scanNotesForWallet,
139
+ sdkLogger: () => sdkLogger,
140
+ sendTransaction: () => sendTransaction,
141
+ serializeNote: () => serializeNote,
142
+ setDebugMode: () => setDebugMode,
143
+ signTransaction: () => signTransaction,
144
+ splitTo2Limbs: () => splitTo2Limbs,
145
+ truncate: () => truncate,
146
+ tryDecryptNote: () => tryDecryptNote,
147
+ updateNoteWithDeposit: () => updateNoteWithDeposit,
148
+ updatePendingDeposit: () => updatePendingDeposit,
149
+ updatePendingWithdrawal: () => updatePendingWithdrawal,
150
+ validateDepositParams: () => validateDepositParams,
151
+ validateNote: () => validateNote,
152
+ validateOutputsSum: () => validateOutputsSum,
153
+ validateTransfers: () => validateTransfers,
154
+ validateWalletConnected: () => validateWalletConnected,
155
+ validateWithdrawableNote: () => validateWithdrawableNote,
156
+ verifyAllCircuits: () => verifyAllCircuits,
157
+ verifyCircuitIntegrity: () => verifyCircuitIntegrity,
158
+ withTiming: () => withTiming
159
+ });
160
+ module.exports = __toCommonJS(index_exports);
161
+
162
+ // src/core/CloakSDK.ts
163
+ var import_web34 = require("@solana/web3.js");
164
+
165
+ // src/core/types.ts
166
+ var CloakError = class extends Error {
167
+ constructor(message, category, retryable = false, originalError) {
168
+ super(message);
169
+ this.category = category;
170
+ this.retryable = retryable;
171
+ this.originalError = originalError;
172
+ this.name = "CloakError";
173
+ }
174
+ };
175
+
176
+ // src/core/keys.ts
177
+ var import_blake3 = require("@noble/hashes/blake3");
178
+ var import_tweetnacl = __toESM(require("tweetnacl"), 1);
179
+
33
180
  // src/utils/crypto.ts
181
+ var import_circomlibjs = require("circomlibjs");
182
+ var poseidon = null;
34
183
  async function getPoseidon() {
35
184
  if (!poseidon) {
36
185
  poseidon = await (0, import_circomlibjs.buildPoseidon)();
@@ -201,6 +350,7 @@ function isValidHex(hex, expectedLength) {
201
350
  }
202
351
  return true;
203
352
  }
353
+ var BN254_MODULUS = BigInt("0x30644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd47");
204
354
  function proofToBytes(proof) {
205
355
  const pi_a_x = BigInt(proof.pi_a[0]);
206
356
  const pi_a_y = BigInt(proof.pi_a[1]);
@@ -291,261 +441,8 @@ function buildPublicInputsBytes(root, nullifier, outputsHash, publicAmount) {
291
441
  result.set(amountBytes, 96);
292
442
  return result;
293
443
  }
294
- var import_circomlibjs, poseidon, BN254_MODULUS;
295
- var init_crypto = __esm({
296
- "src/utils/crypto.ts"() {
297
- "use strict";
298
- import_circomlibjs = require("circomlibjs");
299
- poseidon = null;
300
- BN254_MODULUS = BigInt("0x30644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd47");
301
- }
302
- });
303
-
304
- // src/utils/onchain-proof.ts
305
- var onchain_proof_exports = {};
306
- __export(onchain_proof_exports, {
307
- computeProofForLatestDeposit: () => computeProofForLatestDeposit,
308
- computeProofFromChain: () => computeProofFromChain,
309
- readMerkleTreeState: () => readMerkleTreeState
310
- });
311
- async function ensureZeroValues() {
312
- if (zeroValuesComputed) return;
313
- for (let i = 1; i <= MERKLE_TREE_HEIGHT; i++) {
314
- const prevZeroHex = POSEIDON_ZERO_VALUES[i - 1];
315
- const prevZeroBigInt = BigInt("0x" + prevZeroHex);
316
- const hash = await poseidonHash([prevZeroBigInt, prevZeroBigInt]);
317
- POSEIDON_ZERO_VALUES[i] = hash.toString(16).padStart(64, "0");
318
- }
319
- zeroValuesComputed = true;
320
- }
321
- async function readMerkleTreeState(connection, merkleTreePDA) {
322
- const accountInfo = await connection.getAccountInfo(merkleTreePDA);
323
- if (!accountInfo) {
324
- throw new Error("Merkle tree account not found");
325
- }
326
- const data = accountInfo.data;
327
- const nextIndex = Number(data.readBigUInt64LE(32));
328
- const subtrees = [];
329
- for (let i = 0; i < MERKLE_TREE_HEIGHT; i++) {
330
- const offset = SUBTREES_OFFSET + i * 32;
331
- const subtree = data.slice(offset, offset + 32);
332
- subtrees.push(Buffer.from(subtree).toString("hex"));
333
- }
334
- const root = Buffer.from(data.slice(ROOT_OFFSET, ROOT_OFFSET + 32)).toString("hex");
335
- return { nextIndex, root, subtrees };
336
- }
337
- async function computeProofFromChain(connection, merkleTreePDA, leafIndex) {
338
- await ensureZeroValues();
339
- const { nextIndex, root, subtrees } = await readMerkleTreeState(connection, merkleTreePDA);
340
- if (leafIndex >= nextIndex) {
341
- throw new Error(`Leaf index ${leafIndex} is beyond next_index ${nextIndex}`);
342
- }
343
- const pathElements = [];
344
- const pathIndices = [];
345
- let index = leafIndex;
346
- for (let level = 0; level < MERKLE_TREE_HEIGHT; level++) {
347
- pathIndices.push(index % 2);
348
- if (index % 2 === 0) {
349
- const siblingIndex = index + 1;
350
- const levelNextIndex = Math.ceil(nextIndex / (1 << level));
351
- if (siblingIndex >= levelNextIndex) {
352
- pathElements.push(POSEIDON_ZERO_VALUES[level]);
353
- } else {
354
- pathElements.push(POSEIDON_ZERO_VALUES[level]);
355
- }
356
- } else {
357
- pathElements.push(subtrees[level]);
358
- }
359
- index = Math.floor(index / 2);
360
- }
361
- return { pathElements, pathIndices, root };
362
- }
363
- async function computeProofForLatestDeposit(connection, merkleTreePDA) {
364
- await ensureZeroValues();
365
- const { nextIndex, root, subtrees } = await readMerkleTreeState(connection, merkleTreePDA);
366
- if (nextIndex === 0) {
367
- throw new Error("No leaves in tree");
368
- }
369
- const leafIndex = nextIndex - 1;
370
- const proof = await computeProofInternal(leafIndex, nextIndex, subtrees);
371
- return { ...proof, root, leafIndex };
372
- }
373
- async function computeProofInternal(leafIndex, _nextIndex, subtrees) {
374
- const pathElements = [];
375
- const pathIndices = [];
376
- let index = leafIndex;
377
- for (let level = 0; level < MERKLE_TREE_HEIGHT; level++) {
378
- pathIndices.push(index % 2);
379
- if (index % 2 === 0) {
380
- pathElements.push(POSEIDON_ZERO_VALUES[level]);
381
- } else {
382
- pathElements.push(subtrees[level]);
383
- }
384
- index = Math.floor(index / 2);
385
- }
386
- return { pathElements, pathIndices };
387
- }
388
- var MERKLE_TREE_HEIGHT, SUBTREES_OFFSET, ROOT_OFFSET, POSEIDON_ZERO_VALUES, zeroValuesComputed;
389
- var init_onchain_proof = __esm({
390
- "src/utils/onchain-proof.ts"() {
391
- "use strict";
392
- init_crypto();
393
- MERKLE_TREE_HEIGHT = 32;
394
- SUBTREES_OFFSET = 40;
395
- ROOT_OFFSET = 40 + MERKLE_TREE_HEIGHT * 32;
396
- POSEIDON_ZERO_VALUES = [
397
- "0000000000000000000000000000000000000000000000000000000000000000"
398
- // level 0
399
- ];
400
- zeroValuesComputed = false;
401
- }
402
- });
403
-
404
- // src/index.ts
405
- var index_exports = {};
406
- __export(index_exports, {
407
- CLOAK_PROGRAM_ID: () => CLOAK_PROGRAM_ID,
408
- CloakError: () => CloakError,
409
- CloakSDK: () => CloakSDK,
410
- EXPECTED_CIRCUIT_HASHES: () => EXPECTED_CIRCUIT_HASHES,
411
- FIXED_FEE_LAMPORTS: () => FIXED_FEE_LAMPORTS,
412
- LAMPORTS_PER_SOL: () => LAMPORTS_PER_SOL,
413
- LocalStorageAdapter: () => LocalStorageAdapter,
414
- MemoryStorageAdapter: () => MemoryStorageAdapter,
415
- RelayService: () => RelayService,
416
- RootNotFoundError: () => RootNotFoundError,
417
- ShieldPoolErrors: () => ShieldPoolErrors,
418
- VARIABLE_FEE_RATE: () => VARIABLE_FEE_RATE,
419
- VERSION: () => VERSION,
420
- bigintToBytes32: () => bigintToBytes32,
421
- buildPublicInputsBytes: () => buildPublicInputsBytes,
422
- bytesToHex: () => bytesToHex,
423
- calculateFee: () => calculateFee2,
424
- calculateRelayFee: () => calculateRelayFee,
425
- cleanupStalePendingOperations: () => cleanupStalePendingOperations,
426
- clearPendingDeposits: () => clearPendingDeposits,
427
- clearPendingWithdrawals: () => clearPendingWithdrawals,
428
- computeCommitment: () => computeCommitment,
429
- computeMerkleRoot: () => computeMerkleRoot,
430
- computeNullifier: () => computeNullifier,
431
- computeNullifierAsync: () => computeNullifierAsync,
432
- computeNullifierSync: () => computeNullifierSync,
433
- computeOutputsHash: () => computeOutputsHash,
434
- computeOutputsHashAsync: () => computeOutputsHashAsync,
435
- computeOutputsHashSync: () => computeOutputsHashSync,
436
- computeProofForLatestDeposit: () => computeProofForLatestDeposit,
437
- computeProofFromChain: () => computeProofFromChain,
438
- computeSwapOutputsHash: () => computeSwapOutputsHash,
439
- computeSwapOutputsHashAsync: () => computeSwapOutputsHashAsync,
440
- computeSwapOutputsHashSync: () => computeSwapOutputsHashSync,
441
- copyNoteToClipboard: () => copyNoteToClipboard,
442
- createCloakError: () => createCloakError,
443
- createDepositInstruction: () => createDepositInstruction,
444
- createLogger: () => createLogger,
445
- deriveSpendKey: () => deriveSpendKey,
446
- deriveViewKey: () => deriveViewKey,
447
- detectNetworkFromRpcUrl: () => detectNetworkFromRpcUrl,
448
- downloadNote: () => downloadNote,
449
- encodeNoteSimple: () => encodeNoteSimple,
450
- encryptNoteForRecipient: () => encryptNoteForRecipient,
451
- exportKeys: () => exportKeys,
452
- exportNote: () => exportNote,
453
- exportWalletKeys: () => exportWalletKeys,
454
- filterNotesByNetwork: () => filterNotesByNetwork,
455
- filterWithdrawableNotes: () => filterWithdrawableNotes,
456
- findNoteByCommitment: () => findNoteByCommitment,
457
- formatAmount: () => formatAmount,
458
- formatErrorForLogging: () => formatErrorForLogging,
459
- formatSol: () => formatSol,
460
- generateCloakKeys: () => generateCloakKeys,
461
- generateCommitment: () => generateCommitment,
462
- generateCommitmentAsync: () => generateCommitmentAsync,
463
- generateMasterSeed: () => generateMasterSeed,
464
- generateNote: () => generateNote,
465
- generateNoteFromWallet: () => generateNoteFromWallet,
466
- generateWithdrawRegularProof: () => generateWithdrawRegularProof,
467
- generateWithdrawSwapProof: () => generateWithdrawSwapProof,
468
- getAddressExplorerUrl: () => getAddressExplorerUrl,
469
- getDistributableAmount: () => getDistributableAmount2,
470
- getExplorerUrl: () => getExplorerUrl,
471
- getPendingOperationsSummary: () => getPendingOperationsSummary,
472
- getPublicKey: () => getPublicKey,
473
- getPublicViewKey: () => getPublicViewKey,
474
- getRecipientAmount: () => getRecipientAmount,
475
- getRpcUrlForNetwork: () => getRpcUrlForNetwork,
476
- getShieldPoolPDAs: () => getShieldPoolPDAs,
477
- getViewKey: () => getViewKey,
478
- hasPendingOperations: () => hasPendingOperations,
479
- hexToBigint: () => hexToBigint,
480
- hexToBytes: () => hexToBytes,
481
- importKeys: () => importKeys,
482
- importWalletKeys: () => importWalletKeys,
483
- isDebugEnabled: () => isDebugEnabled,
484
- isRootNotFoundError: () => isRootNotFoundError,
485
- isValidHex: () => isValidHex,
486
- isValidRpcUrl: () => isValidRpcUrl,
487
- isValidSolanaAddress: () => isValidSolanaAddress,
488
- isWithdrawable: () => isWithdrawable,
489
- keypairToAdapter: () => keypairToAdapter,
490
- loadPendingDeposits: () => loadPendingDeposits,
491
- loadPendingWithdrawals: () => loadPendingWithdrawals,
492
- parseAmount: () => parseAmount,
493
- parseError: () => parseError,
494
- parseNote: () => parseNote,
495
- parseTransactionError: () => parseTransactionError,
496
- poseidonHash: () => poseidonHash,
497
- prepareEncryptedOutput: () => prepareEncryptedOutput,
498
- prepareEncryptedOutputForRecipient: () => prepareEncryptedOutputForRecipient,
499
- proofToBytes: () => proofToBytes,
500
- pubkeyToLimbs: () => pubkeyToLimbs,
501
- randomBytes: () => randomBytes,
502
- readMerkleTreeState: () => readMerkleTreeState,
503
- removePendingDeposit: () => removePendingDeposit,
504
- removePendingWithdrawal: () => removePendingWithdrawal,
505
- savePendingDeposit: () => savePendingDeposit,
506
- savePendingWithdrawal: () => savePendingWithdrawal,
507
- scanNotesForWallet: () => scanNotesForWallet,
508
- sdkLogger: () => sdkLogger,
509
- sendTransaction: () => sendTransaction,
510
- serializeNote: () => serializeNote,
511
- setDebugMode: () => setDebugMode,
512
- signTransaction: () => signTransaction,
513
- splitTo2Limbs: () => splitTo2Limbs,
514
- truncate: () => truncate,
515
- tryDecryptNote: () => tryDecryptNote,
516
- updateNoteWithDeposit: () => updateNoteWithDeposit,
517
- updatePendingDeposit: () => updatePendingDeposit,
518
- updatePendingWithdrawal: () => updatePendingWithdrawal,
519
- validateDepositParams: () => validateDepositParams,
520
- validateNote: () => validateNote,
521
- validateOutputsSum: () => validateOutputsSum,
522
- validateTransfers: () => validateTransfers,
523
- validateWalletConnected: () => validateWalletConnected,
524
- validateWithdrawableNote: () => validateWithdrawableNote,
525
- verifyAllCircuits: () => verifyAllCircuits,
526
- verifyCircuitIntegrity: () => verifyCircuitIntegrity,
527
- withTiming: () => withTiming
528
- });
529
- module.exports = __toCommonJS(index_exports);
530
-
531
- // src/core/CloakSDK.ts
532
- var import_web34 = require("@solana/web3.js");
533
-
534
- // src/core/types.ts
535
- var CloakError = class extends Error {
536
- constructor(message, category, retryable = false, originalError) {
537
- super(message);
538
- this.category = category;
539
- this.retryable = retryable;
540
- this.originalError = originalError;
541
- this.name = "CloakError";
542
- }
543
- };
544
444
 
545
445
  // src/core/keys.ts
546
- var import_blake3 = require("@noble/hashes/blake3");
547
- var import_tweetnacl = __toESM(require("tweetnacl"), 1);
548
- init_crypto();
549
446
  function generateMasterSeed() {
550
447
  const seed = new Uint8Array(32);
551
448
  const g = globalThis;
@@ -715,7 +612,6 @@ function getAddressExplorerUrl(address, network = "devnet") {
715
612
  }
716
613
 
717
614
  // src/core/note-manager.ts
718
- init_crypto();
719
615
  async function generateNote(amountLamports, network) {
720
616
  const actualNetwork = network || detectNetworkFromRpcUrl();
721
617
  const skSpend = randomBytes(32);
@@ -934,7 +830,6 @@ var LocalStorageAdapter = class {
934
830
 
935
831
  // src/utils/validation.ts
936
832
  var import_web3 = require("@solana/web3.js");
937
- init_crypto();
938
833
  function isValidSolanaAddress(address) {
939
834
  try {
940
835
  new import_web3.PublicKey(address);
@@ -1052,9 +947,6 @@ function validateTransfers(recipients, totalAmount) {
1052
947
  }
1053
948
  }
1054
949
 
1055
- // src/core/CloakSDK.ts
1056
- init_crypto();
1057
-
1058
950
  // src/utils/errors.ts
1059
951
  var RootNotFoundError = class extends Error {
1060
952
  constructor(message = "Merkle root not found in history") {
@@ -1724,7 +1616,6 @@ function calculateRelayFee(amountLamports, feeBps) {
1724
1616
  }
1725
1617
 
1726
1618
  // src/services/RelayService.ts
1727
- init_crypto();
1728
1619
  var RelayService = class {
1729
1620
  /**
1730
1621
  * Create a new Relay Service client
@@ -2129,30 +2020,84 @@ function getShieldPoolPDAs(programId, mint) {
2129
2020
  treasury
2130
2021
  };
2131
2022
  }
2023
+ function getNullifierPDA(nullifier, programId) {
2024
+ const pid = programId || CLOAK_PROGRAM_ID;
2025
+ if (nullifier.length !== 32) {
2026
+ throw new Error(`Nullifier must be 32 bytes, got ${nullifier.length}`);
2027
+ }
2028
+ return import_web33.PublicKey.findProgramAddressSync(
2029
+ [Buffer.from("nullifier"), Buffer.from(nullifier)],
2030
+ pid
2031
+ );
2032
+ }
2033
+ function getSwapStatePDA(nullifier, programId) {
2034
+ const pid = programId || CLOAK_PROGRAM_ID;
2035
+ if (nullifier.length !== 32) {
2036
+ throw new Error(`Nullifier must be 32 bytes, got ${nullifier.length}`);
2037
+ }
2038
+ return import_web33.PublicKey.findProgramAddressSync(
2039
+ [Buffer.from("swap_state"), Buffer.from(nullifier)],
2040
+ pid
2041
+ );
2042
+ }
2132
2043
 
2133
2044
  // src/utils/proof-generation.ts
2134
2045
  var snarkjs = __toESM(require("snarkjs"), 1);
2135
- init_crypto();
2136
2046
  var IS_REACT_NATIVE = typeof navigator !== "undefined" && navigator.product === "ReactNative";
2137
2047
  var IS_BROWSER = IS_REACT_NATIVE || typeof window !== "undefined" || typeof globalThis !== "undefined" && typeof globalThis.document !== "undefined";
2048
+ var DEFAULT_CIRCUITS_URL = "https://www.cloak.ag/circuits";
2049
+ function isUrl(path) {
2050
+ return path.startsWith("http://") || path.startsWith("https://");
2051
+ }
2052
+ async function fetchFileAsBuffer(url) {
2053
+ const response = await fetch(url);
2054
+ if (!response.ok) {
2055
+ throw new Error(`Failed to fetch ${url}: ${response.status} ${response.statusText}`);
2056
+ }
2057
+ const arrayBuffer = await response.arrayBuffer();
2058
+ return new Uint8Array(arrayBuffer);
2059
+ }
2138
2060
  var _nodePath = null;
2139
2061
  var _nodeFs = null;
2140
2062
  var _nodeCrypto = null;
2063
+ var _fs = null;
2064
+ var _path = null;
2065
+ async function loadNodeModules() {
2066
+ if (_fs && _path) {
2067
+ return { fs: _fs, path: _path };
2068
+ }
2069
+ if (IS_BROWSER) {
2070
+ throw new Error("Node.js modules not available in browser/React Native");
2071
+ }
2072
+ const [fsModule, pathModule] = await Promise.all([
2073
+ import("fs"),
2074
+ import("path")
2075
+ ]);
2076
+ _fs = fsModule;
2077
+ _path = pathModule;
2078
+ return { fs: _fs, path: _path };
2079
+ }
2141
2080
  function nodeRequire(moduleName) {
2142
2081
  if (IS_BROWSER) {
2143
2082
  throw new Error(`Node.js ${moduleName} module not available in browser/React Native`);
2144
2083
  }
2145
- const requireFunc = new Function("moduleName", "return require(moduleName)");
2146
- return requireFunc(moduleName);
2084
+ try {
2085
+ const requireFunc = new Function("moduleName", "return require(moduleName)");
2086
+ return requireFunc(moduleName);
2087
+ } catch {
2088
+ throw new Error(`Cannot load Node.js module ${moduleName} synchronously in ESM. Use async loadNodeModules() instead.`);
2089
+ }
2147
2090
  }
2148
2091
  async function getNodePath() {
2149
2092
  if (_nodePath) return _nodePath;
2150
- _nodePath = nodeRequire("path");
2093
+ const { path } = await loadNodeModules();
2094
+ _nodePath = path;
2151
2095
  return _nodePath;
2152
2096
  }
2153
2097
  async function getNodeFs() {
2154
2098
  if (_nodeFs) return _nodeFs;
2155
- _nodeFs = nodeRequire("fs");
2099
+ const { fs } = await loadNodeModules();
2100
+ _nodeFs = fs;
2156
2101
  return _nodeFs;
2157
2102
  }
2158
2103
  async function getNodeCrypto() {
@@ -2173,29 +2118,41 @@ async function fileExists(filePath) {
2173
2118
  }
2174
2119
  }
2175
2120
  try {
2176
- const nodeFs = nodeRequire("fs");
2177
- return nodeFs.existsSync(filePath);
2121
+ const { fs } = await loadNodeModules();
2122
+ return fs.existsSync(filePath);
2178
2123
  } catch {
2179
2124
  return false;
2180
2125
  }
2181
2126
  }
2182
2127
  async function generateWithdrawRegularProof(inputs, circuitsPath) {
2183
- let wasmPath;
2184
- let zkeyPath;
2128
+ let wasmInput;
2129
+ let zkeyInput;
2130
+ const useUrl = isUrl(circuitsPath);
2185
2131
  if (IS_BROWSER) {
2186
- wasmPath = `${circuitsPath}/withdraw_regular_js/withdraw_regular.wasm`;
2187
- zkeyPath = `${circuitsPath}/withdraw_regular_final.zkey`;
2132
+ wasmInput = `${circuitsPath}/withdraw_regular_js/withdraw_regular.wasm`;
2133
+ zkeyInput = `${circuitsPath}/withdraw_regular_final.zkey`;
2134
+ } else if (useUrl) {
2135
+ const wasmUrl = `${circuitsPath}/withdraw_regular_js/withdraw_regular.wasm`;
2136
+ const zkeyUrl = `${circuitsPath}/withdraw_regular_final.zkey`;
2137
+ const [wasmData, zkeyData] = await Promise.all([
2138
+ fetchFileAsBuffer(wasmUrl),
2139
+ fetchFileAsBuffer(zkeyUrl)
2140
+ ]);
2141
+ wasmInput = wasmData;
2142
+ zkeyInput = zkeyData;
2188
2143
  } else {
2189
- wasmPath = joinPath(circuitsPath, "build", "withdraw_regular_js", "withdraw_regular.wasm");
2190
- zkeyPath = joinPath(circuitsPath, "build", "withdraw_regular_final.zkey");
2144
+ const wasmPath = joinPath(circuitsPath, "build", "withdraw_regular_js", "withdraw_regular.wasm");
2145
+ const zkeyPath = joinPath(circuitsPath, "build", "withdraw_regular_final.zkey");
2191
2146
  const wasmExists = await fileExists(wasmPath);
2192
2147
  const zkeyExists = await fileExists(zkeyPath);
2193
2148
  if (!wasmExists) {
2194
- throw new Error(`Circuit WASM not found at ${wasmPath}. Run 'just circuits-compile' in packages-new/circuits first.`);
2149
+ throw new Error(`Circuit WASM not found at ${wasmPath}. Run 'just circuits-compile' in packages/ first.`);
2195
2150
  }
2196
2151
  if (!zkeyExists) {
2197
2152
  throw new Error(`Circuit zkey not found at ${zkeyPath}. Run circuit setup first.`);
2198
2153
  }
2154
+ wasmInput = wasmPath;
2155
+ zkeyInput = zkeyPath;
2199
2156
  }
2200
2157
  const circuitInputs = {
2201
2158
  // Public signals
@@ -2219,7 +2176,7 @@ async function generateWithdrawRegularProof(inputs, circuitsPath) {
2219
2176
  var_fee: inputs.var_fee.toString(),
2220
2177
  rem: inputs.rem.toString()
2221
2178
  };
2222
- const { proof, publicSignals } = await snarkjs.groth16.fullProve(circuitInputs, wasmPath, zkeyPath);
2179
+ const { proof, publicSignals } = await snarkjs.groth16.fullProve(circuitInputs, wasmInput, zkeyInput);
2223
2180
  const proofBytes = proofToBytes(proof);
2224
2181
  return {
2225
2182
  proof,
@@ -2230,22 +2187,34 @@ async function generateWithdrawRegularProof(inputs, circuitsPath) {
2230
2187
  };
2231
2188
  }
2232
2189
  async function generateWithdrawSwapProof(inputs, circuitsPath) {
2233
- let wasmPath;
2234
- let zkeyPath;
2190
+ let wasmInput;
2191
+ let zkeyInput;
2192
+ const useUrl = isUrl(circuitsPath);
2235
2193
  if (IS_BROWSER) {
2236
- wasmPath = `${circuitsPath}/withdraw_swap_js/withdraw_swap.wasm`;
2237
- zkeyPath = `${circuitsPath}/withdraw_swap_final.zkey`;
2194
+ wasmInput = `${circuitsPath}/withdraw_swap_js/withdraw_swap.wasm`;
2195
+ zkeyInput = `${circuitsPath}/withdraw_swap_final.zkey`;
2196
+ } else if (useUrl) {
2197
+ const wasmUrl = `${circuitsPath}/withdraw_swap_js/withdraw_swap.wasm`;
2198
+ const zkeyUrl = `${circuitsPath}/withdraw_swap_final.zkey`;
2199
+ const [wasmData, zkeyData] = await Promise.all([
2200
+ fetchFileAsBuffer(wasmUrl),
2201
+ fetchFileAsBuffer(zkeyUrl)
2202
+ ]);
2203
+ wasmInput = wasmData;
2204
+ zkeyInput = zkeyData;
2238
2205
  } else {
2239
- wasmPath = joinPath(circuitsPath, "build", "withdraw_swap_js", "withdraw_swap.wasm");
2240
- zkeyPath = joinPath(circuitsPath, "build", "withdraw_swap_final.zkey");
2206
+ const wasmPath = joinPath(circuitsPath, "build", "withdraw_swap_js", "withdraw_swap.wasm");
2207
+ const zkeyPath = joinPath(circuitsPath, "build", "withdraw_swap_final.zkey");
2241
2208
  const wasmExists = await fileExists(wasmPath);
2242
2209
  const zkeyExists = await fileExists(zkeyPath);
2243
2210
  if (!wasmExists) {
2244
- throw new Error(`Circuit WASM not found at ${wasmPath}. Run 'just circuits-compile' in packages-new/circuits first.`);
2211
+ throw new Error(`Circuit WASM not found at ${wasmPath}. Run 'just circuits-compile' in packages/ first.`);
2245
2212
  }
2246
2213
  if (!zkeyExists) {
2247
2214
  throw new Error(`Circuit zkey not found at ${zkeyPath}. Run circuit setup first.`);
2248
2215
  }
2216
+ wasmInput = wasmPath;
2217
+ zkeyInput = zkeyPath;
2249
2218
  }
2250
2219
  const sk = splitTo2Limbs(inputs.sk_spend);
2251
2220
  const r = splitTo2Limbs(inputs.r);
@@ -2274,8 +2243,8 @@ async function generateWithdrawSwapProof(inputs, circuitsPath) {
2274
2243
  };
2275
2244
  const { proof, publicSignals } = await snarkjs.groth16.fullProve(
2276
2245
  circuitInputs,
2277
- wasmPath,
2278
- zkeyPath
2246
+ wasmInput,
2247
+ zkeyInput
2279
2248
  );
2280
2249
  const proofBytes = proofToBytes(proof);
2281
2250
  return {
@@ -2287,8 +2256,14 @@ async function generateWithdrawSwapProof(inputs, circuitsPath) {
2287
2256
  };
2288
2257
  }
2289
2258
  async function areCircuitsAvailable(circuitsPath) {
2259
+ if (!circuitsPath || circuitsPath === "") {
2260
+ return false;
2261
+ }
2262
+ if (isUrl(circuitsPath)) {
2263
+ return true;
2264
+ }
2290
2265
  if (IS_BROWSER) {
2291
- return Boolean(circuitsPath && circuitsPath !== "");
2266
+ return true;
2292
2267
  }
2293
2268
  const wasmPath = joinPath(circuitsPath, "build", "withdraw_regular_js", "withdraw_regular.wasm");
2294
2269
  const zkeyPath = joinPath(circuitsPath, "build", "withdraw_regular_final.zkey");
@@ -2297,22 +2272,25 @@ async function areCircuitsAvailable(circuitsPath) {
2297
2272
  return wasmExists && zkeyExists;
2298
2273
  }
2299
2274
  async function getDefaultCircuitsPath() {
2275
+ if (typeof process !== "undefined" && process.env?.CIRCUITS_PATH) {
2276
+ return process.env.CIRCUITS_PATH;
2277
+ }
2300
2278
  if (IS_BROWSER) {
2301
2279
  return "/circuits";
2302
2280
  }
2303
2281
  if (typeof process === "undefined" || !process.cwd) {
2304
- return "/circuits";
2282
+ return DEFAULT_CIRCUITS_URL;
2305
2283
  }
2306
2284
  let nodePath;
2307
2285
  try {
2308
2286
  nodePath = await getNodePath();
2309
- } catch {
2310
- return "/circuits";
2287
+ } catch (e) {
2288
+ return DEFAULT_CIRCUITS_URL;
2311
2289
  }
2312
2290
  const possiblePaths = [
2313
- nodePath.resolve(process.cwd(), "../../packages-new/circuits"),
2314
- nodePath.resolve(process.cwd(), "../packages-new/circuits"),
2315
- nodePath.resolve(process.cwd(), "packages-new/circuits"),
2291
+ nodePath.resolve(process.cwd(), "../../packages/circuits"),
2292
+ nodePath.resolve(process.cwd(), "../packages/circuits"),
2293
+ nodePath.resolve(process.cwd(), "packages/circuits"),
2316
2294
  nodePath.resolve(process.cwd(), "../../circuits"),
2317
2295
  nodePath.resolve(process.cwd(), "../circuits")
2318
2296
  ];
@@ -2321,7 +2299,7 @@ async function getDefaultCircuitsPath() {
2321
2299
  return p;
2322
2300
  }
2323
2301
  }
2324
- return possiblePaths[0];
2302
+ return DEFAULT_CIRCUITS_URL;
2325
2303
  }
2326
2304
  var EXPECTED_CIRCUIT_HASHES = {
2327
2305
  // SHA-256 of the verification key JSON from withdraw_regular circuit
@@ -2408,9 +2386,6 @@ async function verifyAllCircuits(circuitsPath) {
2408
2386
  return results;
2409
2387
  }
2410
2388
 
2411
- // src/core/CloakSDK.ts
2412
- init_crypto();
2413
-
2414
2389
  // src/utils/logger.ts
2415
2390
  var globalDebugEnabled = false;
2416
2391
  function checkEnvDebug() {
@@ -2498,6 +2473,93 @@ function truncate(str, len = 20) {
2498
2473
  }
2499
2474
  var sdkLogger = createLogger("cloak::sdk");
2500
2475
 
2476
+ // src/utils/onchain-proof.ts
2477
+ var MERKLE_TREE_HEIGHT = 32;
2478
+ var SUBTREES_OFFSET = 40;
2479
+ var ROOT_OFFSET = 40 + MERKLE_TREE_HEIGHT * 32;
2480
+ var POSEIDON_ZERO_VALUES = [
2481
+ "0000000000000000000000000000000000000000000000000000000000000000"
2482
+ // level 0
2483
+ ];
2484
+ var zeroValuesComputed = false;
2485
+ async function ensureZeroValues() {
2486
+ if (zeroValuesComputed) return;
2487
+ for (let i = 1; i <= MERKLE_TREE_HEIGHT; i++) {
2488
+ const prevZeroHex = POSEIDON_ZERO_VALUES[i - 1];
2489
+ const prevZeroBigInt = BigInt("0x" + prevZeroHex);
2490
+ const hash = await poseidonHash([prevZeroBigInt, prevZeroBigInt]);
2491
+ POSEIDON_ZERO_VALUES[i] = hash.toString(16).padStart(64, "0");
2492
+ }
2493
+ zeroValuesComputed = true;
2494
+ }
2495
+ async function readMerkleTreeState(connection, merkleTreePDA) {
2496
+ const accountInfo = await connection.getAccountInfo(merkleTreePDA);
2497
+ if (!accountInfo) {
2498
+ throw new Error("Merkle tree account not found");
2499
+ }
2500
+ const data = accountInfo.data;
2501
+ const nextIndex = Number(data.readBigUInt64LE(32));
2502
+ const subtrees = [];
2503
+ for (let i = 0; i < MERKLE_TREE_HEIGHT; i++) {
2504
+ const offset = SUBTREES_OFFSET + i * 32;
2505
+ const subtree = data.slice(offset, offset + 32);
2506
+ subtrees.push(Buffer.from(subtree).toString("hex"));
2507
+ }
2508
+ const root = Buffer.from(data.slice(ROOT_OFFSET, ROOT_OFFSET + 32)).toString("hex");
2509
+ return { nextIndex, root, subtrees };
2510
+ }
2511
+ async function computeProofFromChain(connection, merkleTreePDA, leafIndex) {
2512
+ await ensureZeroValues();
2513
+ const { nextIndex, root, subtrees } = await readMerkleTreeState(connection, merkleTreePDA);
2514
+ if (leafIndex >= nextIndex) {
2515
+ throw new Error(`Leaf index ${leafIndex} is beyond next_index ${nextIndex}`);
2516
+ }
2517
+ const pathElements = [];
2518
+ const pathIndices = [];
2519
+ let index = leafIndex;
2520
+ for (let level = 0; level < MERKLE_TREE_HEIGHT; level++) {
2521
+ pathIndices.push(index % 2);
2522
+ if (index % 2 === 0) {
2523
+ const siblingIndex = index + 1;
2524
+ const levelNextIndex = Math.ceil(nextIndex / (1 << level));
2525
+ if (siblingIndex >= levelNextIndex) {
2526
+ pathElements.push(POSEIDON_ZERO_VALUES[level]);
2527
+ } else {
2528
+ pathElements.push(POSEIDON_ZERO_VALUES[level]);
2529
+ }
2530
+ } else {
2531
+ pathElements.push(subtrees[level]);
2532
+ }
2533
+ index = Math.floor(index / 2);
2534
+ }
2535
+ return { pathElements, pathIndices, root };
2536
+ }
2537
+ async function computeProofForLatestDeposit(connection, merkleTreePDA) {
2538
+ await ensureZeroValues();
2539
+ const { nextIndex, root, subtrees } = await readMerkleTreeState(connection, merkleTreePDA);
2540
+ if (nextIndex === 0) {
2541
+ throw new Error("No leaves in tree");
2542
+ }
2543
+ const leafIndex = nextIndex - 1;
2544
+ const proof = await computeProofInternal(leafIndex, nextIndex, subtrees);
2545
+ return { ...proof, root, leafIndex };
2546
+ }
2547
+ async function computeProofInternal(leafIndex, _nextIndex, subtrees) {
2548
+ const pathElements = [];
2549
+ const pathIndices = [];
2550
+ let index = leafIndex;
2551
+ for (let level = 0; level < MERKLE_TREE_HEIGHT; level++) {
2552
+ pathIndices.push(index % 2);
2553
+ if (index % 2 === 0) {
2554
+ pathElements.push(POSEIDON_ZERO_VALUES[level]);
2555
+ } else {
2556
+ pathElements.push(subtrees[level]);
2557
+ }
2558
+ index = Math.floor(index / 2);
2559
+ }
2560
+ return { pathElements, pathIndices };
2561
+ }
2562
+
2501
2563
  // src/core/CloakSDK.ts
2502
2564
  var COMPUTE_BUDGET_PROGRAM_ID = new import_web34.PublicKey("ComputeBudget111111111111111111111111111111");
2503
2565
  function createSetLoadedAccountsDataSizeLimitInstruction(bytes) {
@@ -2826,11 +2888,10 @@ var CloakSDK = class {
2826
2888
  }
2827
2889
  let merkleProof;
2828
2890
  try {
2829
- const { computeProofFromChain: computeProofFromChain2 } = await Promise.resolve().then(() => (init_onchain_proof(), onchain_proof_exports));
2830
2891
  const programId2 = this.config.programId || CLOAK_PROGRAM_ID;
2831
2892
  const mintForSOL = new import_web34.PublicKey(new Uint8Array(32));
2832
2893
  const { merkleTree: merkleTreePDA } = getShieldPoolPDAs(programId2, mintForSOL);
2833
- const chainProof = await computeProofFromChain2(connection, merkleTreePDA, leafIndex);
2894
+ const chainProof = await computeProofFromChain(connection, merkleTreePDA, leafIndex);
2834
2895
  merkleProof = {
2835
2896
  pathElements: chainProof.pathElements,
2836
2897
  pathIndices: chainProof.pathIndices
@@ -2950,11 +3011,10 @@ var CloakSDK = class {
2950
3011
  merkleProof = note.merkleProof;
2951
3012
  merkleRoot = note.root;
2952
3013
  } else {
2953
- const { computeProofFromChain: computeProofFromChain2 } = await Promise.resolve().then(() => (init_onchain_proof(), onchain_proof_exports));
2954
3014
  const programId = this.config.programId || CLOAK_PROGRAM_ID;
2955
3015
  const mintForSOL = new import_web34.PublicKey(new Uint8Array(32));
2956
3016
  const { merkleTree: merkleTreePDA } = getShieldPoolPDAs(programId, mintForSOL);
2957
- const chainProof = await computeProofFromChain2(
3017
+ const chainProof = await computeProofFromChain(
2958
3018
  connection,
2959
3019
  merkleTreePDA,
2960
3020
  note.leafIndex
@@ -3276,11 +3336,10 @@ var CloakSDK = class {
3276
3336
  options?.onProgress?.(`proof_refresh_${attempt + 1}`);
3277
3337
  await new Promise((resolve) => setTimeout(resolve, 1e3));
3278
3338
  }
3279
- const { computeProofFromChain: computeProofFromChain2 } = await Promise.resolve().then(() => (init_onchain_proof(), onchain_proof_exports));
3280
3339
  const programId = this.config.programId || CLOAK_PROGRAM_ID;
3281
3340
  const mintForSOL = new import_web34.PublicKey(new Uint8Array(32));
3282
3341
  const { merkleTree: merkleTreePDA } = getShieldPoolPDAs(programId, mintForSOL);
3283
- const chainProof = await computeProofFromChain2(connection, merkleTreePDA, note.leafIndex);
3342
+ const chainProof = await computeProofFromChain(connection, merkleTreePDA, note.leafIndex);
3284
3343
  const merkleProof = {
3285
3344
  pathElements: chainProof.pathElements,
3286
3345
  pathIndices: chainProof.pathIndices
@@ -3450,11 +3509,10 @@ var CloakSDK = class {
3450
3509
  * @returns Merkle proof computed from on-chain data
3451
3510
  */
3452
3511
  async getMerkleProof(connection, leafIndex) {
3453
- const { computeProofFromChain: computeProofFromChain2 } = await Promise.resolve().then(() => (init_onchain_proof(), onchain_proof_exports));
3454
3512
  const programId = this.config.programId || CLOAK_PROGRAM_ID;
3455
3513
  const mintForSOL = new import_web34.PublicKey(new Uint8Array(32));
3456
3514
  const { merkleTree: merkleTreePDA } = getShieldPoolPDAs(programId, mintForSOL);
3457
- const chainProof = await computeProofFromChain2(connection, merkleTreePDA, leafIndex);
3515
+ const chainProof = await computeProofFromChain(connection, merkleTreePDA, leafIndex);
3458
3516
  return {
3459
3517
  pathElements: chainProof.pathElements,
3460
3518
  pathIndices: chainProof.pathIndices,
@@ -3468,11 +3526,10 @@ var CloakSDK = class {
3468
3526
  * @returns Current root hash from on-chain tree
3469
3527
  */
3470
3528
  async getCurrentRoot(connection) {
3471
- const { readMerkleTreeState: readMerkleTreeState2 } = await Promise.resolve().then(() => (init_onchain_proof(), onchain_proof_exports));
3472
3529
  const programId = this.config.programId || CLOAK_PROGRAM_ID;
3473
3530
  const mintForSOL = new import_web34.PublicKey(new Uint8Array(32));
3474
3531
  const { merkleTree: merkleTreePDA } = getShieldPoolPDAs(programId, mintForSOL);
3475
- const state = await readMerkleTreeState2(connection, merkleTreePDA);
3532
+ const state = await readMerkleTreeState(connection, merkleTreePDA);
3476
3533
  return state.root;
3477
3534
  }
3478
3535
  /**
@@ -3624,7 +3681,6 @@ var CloakSDK = class {
3624
3681
  };
3625
3682
 
3626
3683
  // src/core/note.ts
3627
- init_crypto();
3628
3684
  function serializeNote(note, pretty = false) {
3629
3685
  validateNote(note);
3630
3686
  return pretty ? JSON.stringify(note, null, 2) : JSON.stringify(note);
@@ -3657,11 +3713,7 @@ async function copyNoteToClipboard(note) {
3657
3713
  await nav.clipboard.writeText(json);
3658
3714
  }
3659
3715
 
3660
- // src/index.ts
3661
- init_crypto();
3662
-
3663
3716
  // src/helpers/encrypted-output.ts
3664
- init_crypto();
3665
3717
  function prepareEncryptedOutput(note, cloakKeys) {
3666
3718
  const noteData = {
3667
3719
  amount: note.amount,
@@ -3772,9 +3824,6 @@ function keypairToAdapter(keypair) {
3772
3824
  };
3773
3825
  }
3774
3826
 
3775
- // src/index.ts
3776
- init_onchain_proof();
3777
-
3778
3827
  // src/utils/pending-operations.ts
3779
3828
  var PENDING_DEPOSITS_KEY = "cloak_pending_deposits";
3780
3829
  var PENDING_WITHDRAWALS_KEY = "cloak_pending_withdrawals";
@@ -3949,6 +3998,7 @@ var VERSION = "1.0.0";
3949
3998
  CLOAK_PROGRAM_ID,
3950
3999
  CloakError,
3951
4000
  CloakSDK,
4001
+ DEFAULT_CIRCUITS_URL,
3952
4002
  EXPECTED_CIRCUIT_HASHES,
3953
4003
  FIXED_FEE_LAMPORTS,
3954
4004
  LAMPORTS_PER_SOL,
@@ -3959,6 +4009,7 @@ var VERSION = "1.0.0";
3959
4009
  ShieldPoolErrors,
3960
4010
  VARIABLE_FEE_RATE,
3961
4011
  VERSION,
4012
+ areCircuitsAvailable,
3962
4013
  bigintToBytes32,
3963
4014
  buildPublicInputsBytes,
3964
4015
  bytesToHex,
@@ -4008,14 +4059,17 @@ var VERSION = "1.0.0";
4008
4059
  generateWithdrawRegularProof,
4009
4060
  generateWithdrawSwapProof,
4010
4061
  getAddressExplorerUrl,
4062
+ getDefaultCircuitsPath,
4011
4063
  getDistributableAmount,
4012
4064
  getExplorerUrl,
4065
+ getNullifierPDA,
4013
4066
  getPendingOperationsSummary,
4014
4067
  getPublicKey,
4015
4068
  getPublicViewKey,
4016
4069
  getRecipientAmount,
4017
4070
  getRpcUrlForNetwork,
4018
4071
  getShieldPoolPDAs,
4072
+ getSwapStatePDA,
4019
4073
  getViewKey,
4020
4074
  hasPendingOperations,
4021
4075
  hexToBigint,