privacycash 1.0.15 → 1.0.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,6 +1,11 @@
1
1
  ## Privacy Cash SDK
2
2
  This is the SDK for Privacy Cash. It has been audited by Zigtur (https://x.com/zigtur).
3
3
 
4
+ ### Disclaimer
5
+ This SDK powers Privacy Cash's frontend, assuming the single wallet use case. If you use it or published npm library from this repo, please fully test and beware of the inherent software risks or potential bugs.
6
+
7
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
8
+
4
9
  ### Usage
5
10
  This SDK provides APIs for developers to interact with Privacy Cash relayers easily. Developers can easily deposit/withdraw/query balances in Privacy Cash solana program.
6
11
 
package/dist/deposit.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { PublicKey, TransactionInstruction, SystemProgram, ComputeBudgetProgram, VersionedTransaction, TransactionMessage, LAMPORTS_PER_SOL } from '@solana/web3.js';
2
2
  import BN from 'bn.js';
3
3
  import { Utxo } from './models/utxo.js';
4
- import { fetchMerkleProof, findCommitmentPDAs, findNullifierPDAs, getExtDataHash, getProgramAccounts, queryRemoteTreeState, findCrossCheckNullifierPDAs } from './utils/utils.js';
4
+ import { fetchMerkleProof, findNullifierPDAs, getExtDataHash, getProgramAccounts, queryRemoteTreeState, findCrossCheckNullifierPDAs } from './utils/utils.js';
5
5
  import { prove, parseProofToBytesArray, parseToBytesArray } from './utils/prover.js';
6
6
  import { MerkleTree } from './utils/merkle_tree.js';
7
7
  import { serializeProofAndExtData } from './utils/encryption.js';
@@ -279,7 +279,6 @@ export async function deposit({ lightWasm, storage, keyBasePath, publicKey, conn
279
279
  // Find PDAs for nullifiers and commitments
280
280
  const { nullifier0PDA, nullifier1PDA } = findNullifierPDAs(proofToSubmit);
281
281
  const { nullifier2PDA, nullifier3PDA } = findCrossCheckNullifierPDAs(proofToSubmit);
282
- const { commitment0PDA, commitment1PDA } = findCommitmentPDAs(proofToSubmit);
283
282
  // Address Lookup Table for transaction size optimization
284
283
  logger.debug('Setting up Address Lookup Table...');
285
284
  const ALT_ADDRESS = new PublicKey('72bpRay17JKp4k8H87p7ieU9C6aRDy5yCqwvtpTN2wuU');
@@ -298,8 +297,6 @@ export async function deposit({ lightWasm, storage, keyBasePath, publicKey, conn
298
297
  { pubkey: nullifier1PDA, isSigner: false, isWritable: true },
299
298
  { pubkey: nullifier2PDA, isSigner: false, isWritable: false },
300
299
  { pubkey: nullifier3PDA, isSigner: false, isWritable: false },
301
- { pubkey: commitment0PDA, isSigner: false, isWritable: true },
302
- { pubkey: commitment1PDA, isSigner: false, isWritable: true },
303
300
  { pubkey: treeTokenAccount, isSigner: false, isWritable: true },
304
301
  { pubkey: globalConfigAccount, isSigner: false, isWritable: false },
305
302
  // recipient - just a placeholder, not actually used for deposits. using an ALT address to save bytes
package/dist/getUtxos.js CHANGED
@@ -254,78 +254,6 @@ export function getBalanceFromUtxos(utxos) {
254
254
  // const remainderLamports = totalBalance.mod(LAMPORTS_PER_SOL);
255
255
  return { lamports: totalBalance.toNumber() };
256
256
  }
257
- async function decrypt_output(encryptedOutput, encryptionService, utxoKeypair, lightWasm, connection) {
258
- let res = { status: 'unDecrypted' };
259
- try {
260
- if (!encryptedOutput) {
261
- return { status: 'skipped' };
262
- }
263
- // Try to decrypt the UTXO
264
- res.utxo = await encryptionService.decryptUtxo(encryptedOutput, lightWasm);
265
- // If we got here, decryption succeeded, so this UTXO belongs to the user
266
- res.status = 'decrypted';
267
- // Get the real index from the on-chain commitment account
268
- try {
269
- if (!res.utxo) {
270
- throw new Error('res.utxo undefined');
271
- }
272
- const commitment = await res.utxo.getCommitment();
273
- // Convert decimal commitment string to byte array (same format as in proofs)
274
- const commitmentBytes = Array.from(leInt2Buff(unstringifyBigInts(commitment), 32)).reverse();
275
- // Derive the commitment PDA (could be either commitment0 or commitment1)
276
- // We'll try both seeds since we don't know which one it is
277
- let commitmentAccount = null;
278
- let realIndex = null;
279
- // Try commitment0 seed
280
- try {
281
- const [commitment0PDA] = PublicKey.findProgramAddressSync([Buffer.from("commitment0"), Buffer.from(commitmentBytes)], PROGRAM_ID);
282
- const account0Info = await connection.getAccountInfo(commitment0PDA);
283
- if (account0Info) {
284
- // Parse the index from the account data according to CommitmentAccount structure:
285
- // 0-8: Anchor discriminator
286
- // 8-40: commitment (32 bytes)
287
- // 40-44: encrypted_output length (4 bytes)
288
- // 44-44+len: encrypted_output data
289
- // 44+len-52+len: index (8 bytes)
290
- const encryptedOutputLength = account0Info.data.readUInt32LE(40);
291
- const indexOffset = 44 + encryptedOutputLength;
292
- const indexBytes = account0Info.data.slice(indexOffset, indexOffset + 8);
293
- realIndex = new BN(indexBytes, 'le').toNumber();
294
- }
295
- }
296
- catch (e) {
297
- // Try commitment1 seed if commitment0 fails
298
- try {
299
- const [commitment1PDA] = PublicKey.findProgramAddressSync([Buffer.from("commitment1"), Buffer.from(commitmentBytes)], PROGRAM_ID);
300
- const account1Info = await connection.getAccountInfo(commitment1PDA);
301
- if (account1Info) {
302
- // Parse the index from the account data according to CommitmentAccount structure
303
- const encryptedOutputLength = account1Info.data.readUInt32LE(40);
304
- const indexOffset = 44 + encryptedOutputLength;
305
- const indexBytes = account1Info.data.slice(indexOffset, indexOffset + 8);
306
- realIndex = new BN(indexBytes, 'le').toNumber();
307
- logger.debug(`Found commitment1 account with index: ${realIndex}`);
308
- }
309
- }
310
- catch (e2) {
311
- logger.debug(`Could not find commitment account for ${commitment}, using encrypted index: ${res.utxo.index}`);
312
- }
313
- }
314
- // Update the UTXO with the real index if we found it
315
- if (realIndex !== null) {
316
- const oldIndex = res.utxo.index;
317
- res.utxo.index = realIndex;
318
- }
319
- }
320
- catch (error) {
321
- logger.debug(`Failed to get real index for UTXO: ${error.message}`);
322
- }
323
- }
324
- catch (error) {
325
- // this UTXO doesn't belong to the user
326
- }
327
- return res;
328
- }
329
257
  async function decrypt_outputs(encryptedOutputs, encryptionService, utxoKeypair, lightWasm) {
330
258
  let results = [];
331
259
  // decript all UTXO
@@ -18,9 +18,12 @@ interface Proof {
18
18
  *
19
19
  * @param input The circuit inputs to generate a proof for
20
20
  * @param keyBasePath The base path for the circuit keys (.wasm and .zkey files)
21
+ * @param options Optional proof generation options (e.g., singleThread for Deno/Bun)
21
22
  * @returns A proof object with formatted proof elements and public signals
22
23
  */
23
- declare function prove(input: any, keyBasePath: string): Promise<{
24
+ declare function prove(input: any, keyBasePath: string, options?: {
25
+ singleThread?: boolean;
26
+ }): Promise<{
24
27
  proof: Proof;
25
28
  publicSignals: string[];
26
29
  }>;
@@ -21,10 +21,34 @@ const utilsTyped = utils;
21
21
  *
22
22
  * @param input The circuit inputs to generate a proof for
23
23
  * @param keyBasePath The base path for the circuit keys (.wasm and .zkey files)
24
+ * @param options Optional proof generation options (e.g., singleThread for Deno/Bun)
24
25
  * @returns A proof object with formatted proof elements and public signals
25
26
  */
26
- async function prove(input, keyBasePath) {
27
- return await groth16Typed.fullProve(utilsTyped.stringifyBigInts(input), `${keyBasePath}.wasm`, `${keyBasePath}.zkey`);
27
+ async function prove(input, keyBasePath, options) {
28
+ // Detect if we should use single-threaded mode (for Deno/Bun compatibility)
29
+ const useSingleThread = options?.singleThread ?? shouldUseSingleThread();
30
+ // Single-thread options need to be passed to BOTH witness calculation AND proving
31
+ const singleThreadOpts = useSingleThread ? { singleThread: true } : undefined;
32
+ // Call fullProve with all parameters:
33
+ // 1. input, 2. wasmFile, 3. zkeyFile, 4. logger, 5. wtnsCalcOptions, 6. proverOptions
34
+ return await groth16Typed.fullProve(utilsTyped.stringifyBigInts(input), `${keyBasePath}.wasm`, `${keyBasePath}.zkey`, undefined, // logger parameter
35
+ singleThreadOpts, // wtnsCalcOptions (5th param) - for witness calculation
36
+ singleThreadOpts // proverOptions (6th param) - for proving
37
+ );
38
+ }
39
+ /**
40
+ * Detect if single-threaded mode should be used
41
+ */
42
+ function shouldUseSingleThread() {
43
+ // @ts-ignore - Deno global
44
+ if (typeof Deno !== 'undefined') {
45
+ return true; // Deno has worker issues
46
+ }
47
+ // @ts-ignore - Bun global
48
+ if (typeof Bun !== 'undefined') {
49
+ return true; // Bun may have worker issues
50
+ }
51
+ return false;
28
52
  }
29
53
  export function parseProofToBytesArray(proof, compressed = false) {
30
54
  const proofJson = JSON.stringify(proof, null, 1);
@@ -48,10 +48,6 @@ export declare function findNullifierPDAs(proof: any): {
48
48
  nullifier0PDA: PublicKey;
49
49
  nullifier1PDA: PublicKey;
50
50
  };
51
- export declare function findCommitmentPDAs(proof: any): {
52
- commitment0PDA: PublicKey;
53
- commitment1PDA: PublicKey;
54
- };
55
51
  export declare function queryRemoteTreeState(): Promise<{
56
52
  root: string;
57
53
  nextIndex: number;
@@ -113,12 +113,6 @@ export function findNullifierPDAs(proof) {
113
113
  const [nullifier1PDA] = PublicKey.findProgramAddressSync([Buffer.from("nullifier1"), Buffer.from(proof.inputNullifiers[1])], PROGRAM_ID);
114
114
  return { nullifier0PDA, nullifier1PDA };
115
115
  }
116
- // Find commitment PDAs for the given proof
117
- export function findCommitmentPDAs(proof) {
118
- const [commitment0PDA] = PublicKey.findProgramAddressSync([Buffer.from("commitment0"), Buffer.from(proof.outputCommitments[0])], PROGRAM_ID);
119
- const [commitment1PDA] = PublicKey.findProgramAddressSync([Buffer.from("commitment1"), Buffer.from(proof.outputCommitments[1])], PROGRAM_ID);
120
- return { commitment0PDA, commitment1PDA };
121
- }
122
116
  // Function to query remote tree state from indexer API
123
117
  export async function queryRemoteTreeState() {
124
118
  try {
package/dist/withdraw.js CHANGED
@@ -6,7 +6,7 @@ import { Utxo } from './models/utxo.js';
6
6
  import { parseProofToBytesArray, parseToBytesArray, prove } from './utils/prover.js';
7
7
  import { ALT_ADDRESS, DEPLOYER_ID, FEE_RECIPIENT, FIELD_SIZE, INDEXER_API_URL, MERKLE_TREE_DEPTH } from './utils/constants.js';
8
8
  import { serializeProofAndExtData } from './utils/encryption.js';
9
- import { fetchMerkleProof, findCommitmentPDAs, findNullifierPDAs, getExtDataHash, getProgramAccounts, queryRemoteTreeState, findCrossCheckNullifierPDAs } from './utils/utils.js';
9
+ import { fetchMerkleProof, findNullifierPDAs, getExtDataHash, getProgramAccounts, queryRemoteTreeState, findCrossCheckNullifierPDAs } from './utils/utils.js';
10
10
  import { getUtxos } from './getUtxos.js';
11
11
  import { logger } from './utils/logger.js';
12
12
  import { getConfig } from './config.js';
@@ -221,7 +221,6 @@ export async function withdraw({ recipient, lightWasm, storage, publicKey, conne
221
221
  // Find PDAs for nullifiers and commitments
222
222
  const { nullifier0PDA, nullifier1PDA } = findNullifierPDAs(proofToSubmit);
223
223
  const { nullifier2PDA, nullifier3PDA } = findCrossCheckNullifierPDAs(proofToSubmit);
224
- const { commitment0PDA, commitment1PDA } = findCommitmentPDAs(proofToSubmit);
225
224
  // Serialize the proof and extData
226
225
  const serializedProof = serializeProofAndExtData(proofToSubmit, extData);
227
226
  logger.debug(`Total instruction data size: ${serializedProof.length} bytes`);
@@ -233,8 +232,6 @@ export async function withdraw({ recipient, lightWasm, storage, publicKey, conne
233
232
  nullifier1PDA: nullifier1PDA.toString(),
234
233
  nullifier2PDA: nullifier2PDA.toString(),
235
234
  nullifier3PDA: nullifier3PDA.toString(),
236
- commitment0PDA: commitment0PDA.toString(),
237
- commitment1PDA: commitment1PDA.toString(),
238
235
  treeTokenAccount: treeTokenAccount.toString(),
239
236
  globalConfigAccount: globalConfigAccount.toString(),
240
237
  recipient: recipient.toString(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "privacycash",
3
- "version": "1.0.15",
3
+ "version": "1.0.17",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "repository": "https://github.com/Privacy-Cash/privacy-cash-sdk",
package/src/deposit.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { Connection, Keypair, PublicKey, TransactionInstruction, SystemProgram, ComputeBudgetProgram, VersionedTransaction, TransactionMessage, LAMPORTS_PER_SOL } from '@solana/web3.js';
2
2
  import BN from 'bn.js';
3
3
  import { Utxo } from './models/utxo.js';
4
- import { fetchMerkleProof, findCommitmentPDAs, findNullifierPDAs, getExtDataHash, getProgramAccounts, queryRemoteTreeState, findCrossCheckNullifierPDAs } from './utils/utils.js';
4
+ import { fetchMerkleProof, findNullifierPDAs, getExtDataHash, getProgramAccounts, queryRemoteTreeState, findCrossCheckNullifierPDAs } from './utils/utils.js';
5
5
  import { prove, parseProofToBytesArray, parseToBytesArray } from './utils/prover.js';
6
6
  import * as hasher from '@lightprotocol/hasher.rs';
7
7
  import { MerkleTree } from './utils/merkle_tree.js';
@@ -344,7 +344,6 @@ export async function deposit({ lightWasm, storage, keyBasePath, publicKey, conn
344
344
  // Find PDAs for nullifiers and commitments
345
345
  const { nullifier0PDA, nullifier1PDA } = findNullifierPDAs(proofToSubmit);
346
346
  const { nullifier2PDA, nullifier3PDA } = findCrossCheckNullifierPDAs(proofToSubmit);
347
- const { commitment0PDA, commitment1PDA } = findCommitmentPDAs(proofToSubmit);
348
347
 
349
348
  // Address Lookup Table for transaction size optimization
350
349
  logger.debug('Setting up Address Lookup Table...');
@@ -368,8 +367,6 @@ export async function deposit({ lightWasm, storage, keyBasePath, publicKey, conn
368
367
  { pubkey: nullifier1PDA, isSigner: false, isWritable: true },
369
368
  { pubkey: nullifier2PDA, isSigner: false, isWritable: false },
370
369
  { pubkey: nullifier3PDA, isSigner: false, isWritable: false },
371
- { pubkey: commitment0PDA, isSigner: false, isWritable: true },
372
- { pubkey: commitment1PDA, isSigner: false, isWritable: true },
373
370
  { pubkey: treeTokenAccount, isSigner: false, isWritable: true },
374
371
  { pubkey: globalConfigAccount, isSigner: false, isWritable: false },
375
372
  // recipient - just a placeholder, not actually used for deposits. using an ALT address to save bytes
package/src/getUtxos.ts CHANGED
@@ -335,99 +335,6 @@ export function getBalanceFromUtxos(utxos: Utxo[]) {
335
335
 
336
336
  // Decrypt single output to Utxo
337
337
  type DecryptRes = { status: 'decrypted' | 'skipped' | 'unDecrypted', utxo?: Utxo, encryptedOutput?: string }
338
- async function decrypt_output(
339
- encryptedOutput: string,
340
- encryptionService: EncryptionService,
341
- utxoKeypair: UtxoKeypair,
342
- lightWasm: any,
343
- connection: Connection
344
- ): Promise<DecryptRes> {
345
- let res: DecryptRes = { status: 'unDecrypted' }
346
- try {
347
- if (!encryptedOutput) {
348
- return { status: 'skipped' }
349
- }
350
-
351
- // Try to decrypt the UTXO
352
- res.utxo = await encryptionService.decryptUtxo(
353
- encryptedOutput,
354
- lightWasm
355
- );
356
-
357
- // If we got here, decryption succeeded, so this UTXO belongs to the user
358
- res.status = 'decrypted'
359
-
360
- // Get the real index from the on-chain commitment account
361
- try {
362
- if (!res.utxo) {
363
- throw new Error('res.utxo undefined')
364
- }
365
- const commitment = await res.utxo.getCommitment();
366
- // Convert decimal commitment string to byte array (same format as in proofs)
367
- const commitmentBytes = Array.from(
368
- leInt2Buff(unstringifyBigInts(commitment), 32)
369
- ).reverse() as number[];
370
-
371
- // Derive the commitment PDA (could be either commitment0 or commitment1)
372
- // We'll try both seeds since we don't know which one it is
373
- let commitmentAccount = null;
374
- let realIndex = null;
375
- // Try commitment0 seed
376
- try {
377
- const [commitment0PDA] = PublicKey.findProgramAddressSync(
378
- [Buffer.from("commitment0"), Buffer.from(commitmentBytes)],
379
- PROGRAM_ID
380
- );
381
-
382
- const account0Info = await connection.getAccountInfo(commitment0PDA);
383
- if (account0Info) {
384
- // Parse the index from the account data according to CommitmentAccount structure:
385
- // 0-8: Anchor discriminator
386
- // 8-40: commitment (32 bytes)
387
- // 40-44: encrypted_output length (4 bytes)
388
- // 44-44+len: encrypted_output data
389
- // 44+len-52+len: index (8 bytes)
390
- const encryptedOutputLength = account0Info.data.readUInt32LE(40);
391
- const indexOffset = 44 + encryptedOutputLength;
392
- const indexBytes = account0Info.data.slice(indexOffset, indexOffset + 8);
393
- realIndex = new BN(indexBytes, 'le').toNumber();
394
- }
395
- } catch (e) {
396
- // Try commitment1 seed if commitment0 fails
397
- try {
398
- const [commitment1PDA] = PublicKey.findProgramAddressSync(
399
- [Buffer.from("commitment1"), Buffer.from(commitmentBytes)],
400
- PROGRAM_ID
401
- );
402
-
403
- const account1Info = await connection.getAccountInfo(commitment1PDA);
404
- if (account1Info) {
405
- // Parse the index from the account data according to CommitmentAccount structure
406
- const encryptedOutputLength = account1Info.data.readUInt32LE(40);
407
- const indexOffset = 44 + encryptedOutputLength;
408
- const indexBytes = account1Info.data.slice(indexOffset, indexOffset + 8);
409
- realIndex = new BN(indexBytes, 'le').toNumber();
410
- logger.debug(`Found commitment1 account with index: ${realIndex}`);
411
- }
412
- } catch (e2) {
413
- logger.debug(`Could not find commitment account for ${commitment}, using encrypted index: ${res.utxo.index}`);
414
- }
415
- }
416
-
417
- // Update the UTXO with the real index if we found it
418
- if (realIndex !== null) {
419
- const oldIndex = res.utxo.index;
420
- res.utxo.index = realIndex;
421
- }
422
-
423
- } catch (error: any) {
424
- logger.debug(`Failed to get real index for UTXO: ${error.message}`);
425
- }
426
- } catch (error: any) {
427
- // this UTXO doesn't belong to the user
428
- }
429
- return res
430
- }
431
338
 
432
339
  async function decrypt_outputs(
433
340
  encryptedOutputs: string[],
@@ -23,7 +23,14 @@ type WtnsModule = {
23
23
  }
24
24
 
25
25
  type Groth16Module = {
26
- fullProve: (input: any, wasmFile: string, zkeyFile: string) => Promise<{ proof: Proof; publicSignals: string[] }>
26
+ fullProve: (
27
+ input: any,
28
+ wasmFile: string,
29
+ zkeyFile: string,
30
+ logger?: any,
31
+ wtnsCalcOptions?: { singleThread?: boolean },
32
+ proverOptions?: { singleThread?: boolean }
33
+ ) => Promise<{ proof: Proof; publicSignals: string[] }>
27
34
  verify: (vkeyData: any, publicSignals: any, proof: Proof) => Promise<boolean>
28
35
  }
29
36
 
@@ -53,23 +60,49 @@ interface ProofResult {
53
60
 
54
61
  /**
55
62
  * Generates a ZK proof using snarkjs and formats it for use on-chain
56
- *
63
+ *
57
64
  * @param input The circuit inputs to generate a proof for
58
65
  * @param keyBasePath The base path for the circuit keys (.wasm and .zkey files)
66
+ * @param options Optional proof generation options (e.g., singleThread for Deno/Bun)
59
67
  * @returns A proof object with formatted proof elements and public signals
60
68
  */
61
- async function prove(input: any, keyBasePath: string): Promise<{
69
+ async function prove(input: any, keyBasePath: string, options?: { singleThread?: boolean }): Promise<{
62
70
  proof: Proof
63
71
  publicSignals: string[];
64
72
  }> {
73
+ // Detect if we should use single-threaded mode (for Deno/Bun compatibility)
74
+ const useSingleThread = options?.singleThread ?? shouldUseSingleThread();
75
+
76
+ // Single-thread options need to be passed to BOTH witness calculation AND proving
77
+ const singleThreadOpts = useSingleThread ? { singleThread: true } : undefined;
65
78
 
79
+ // Call fullProve with all parameters:
80
+ // 1. input, 2. wasmFile, 3. zkeyFile, 4. logger, 5. wtnsCalcOptions, 6. proverOptions
66
81
  return await groth16Typed.fullProve(
67
82
  utilsTyped.stringifyBigInts(input),
68
83
  `${keyBasePath}.wasm`,
69
84
  `${keyBasePath}.zkey`,
85
+ undefined, // logger parameter
86
+ singleThreadOpts, // wtnsCalcOptions (5th param) - for witness calculation
87
+ singleThreadOpts // proverOptions (6th param) - for proving
70
88
  )
71
89
  }
72
90
 
91
+ /**
92
+ * Detect if single-threaded mode should be used
93
+ */
94
+ function shouldUseSingleThread(): boolean {
95
+ // @ts-ignore - Deno global
96
+ if (typeof Deno !== 'undefined') {
97
+ return true; // Deno has worker issues
98
+ }
99
+ // @ts-ignore - Bun global
100
+ if (typeof Bun !== 'undefined') {
101
+ return true; // Bun may have worker issues
102
+ }
103
+ return false;
104
+ }
105
+
73
106
  export function parseProofToBytesArray(
74
107
  proof: Proof,
75
108
  compressed: boolean = false,
@@ -146,20 +146,6 @@ export function findNullifierPDAs(proof: any) {
146
146
  return { nullifier0PDA, nullifier1PDA };
147
147
  }
148
148
 
149
- // Find commitment PDAs for the given proof
150
- export function findCommitmentPDAs(proof: any) {
151
- const [commitment0PDA] = PublicKey.findProgramAddressSync(
152
- [Buffer.from("commitment0"), Buffer.from(proof.outputCommitments[0])],
153
- PROGRAM_ID
154
- );
155
-
156
- const [commitment1PDA] = PublicKey.findProgramAddressSync(
157
- [Buffer.from("commitment1"), Buffer.from(proof.outputCommitments[1])],
158
- PROGRAM_ID
159
- );
160
- return { commitment0PDA, commitment1PDA };
161
- }
162
-
163
149
  // Function to query remote tree state from indexer API
164
150
  export async function queryRemoteTreeState(): Promise<{ root: string, nextIndex: number }> {
165
151
  try {
package/src/withdraw.ts CHANGED
@@ -8,9 +8,9 @@ import { parseProofToBytesArray, parseToBytesArray, prove } from './utils/prover
8
8
 
9
9
  import { ALT_ADDRESS, DEPLOYER_ID, FEE_RECIPIENT, FIELD_SIZE, INDEXER_API_URL, MERKLE_TREE_DEPTH, PROGRAM_ID } from './utils/constants.js';
10
10
  import { EncryptionService, serializeProofAndExtData } from './utils/encryption.js';
11
- import { fetchMerkleProof, findCommitmentPDAs, findNullifierPDAs, getExtDataHash, getProgramAccounts, queryRemoteTreeState, findCrossCheckNullifierPDAs } from './utils/utils.js';
11
+ import { fetchMerkleProof, findNullifierPDAs, getExtDataHash, getProgramAccounts, queryRemoteTreeState, findCrossCheckNullifierPDAs } from './utils/utils.js';
12
12
 
13
- import { getUtxos, isUtxoSpent } from './getUtxos.js';
13
+ import { getUtxos } from './getUtxos.js';
14
14
  import { logger } from './utils/logger.js';
15
15
  import { getConfig } from './config.js';
16
16
  // Indexer API endpoint
@@ -278,7 +278,6 @@ export async function withdraw({ recipient, lightWasm, storage, publicKey, conne
278
278
  // Find PDAs for nullifiers and commitments
279
279
  const { nullifier0PDA, nullifier1PDA } = findNullifierPDAs(proofToSubmit);
280
280
  const { nullifier2PDA, nullifier3PDA } = findCrossCheckNullifierPDAs(proofToSubmit);
281
- const { commitment0PDA, commitment1PDA } = findCommitmentPDAs(proofToSubmit);
282
281
 
283
282
  // Serialize the proof and extData
284
283
  const serializedProof = serializeProofAndExtData(proofToSubmit, extData);
@@ -292,8 +291,6 @@ export async function withdraw({ recipient, lightWasm, storage, publicKey, conne
292
291
  nullifier1PDA: nullifier1PDA.toString(),
293
292
  nullifier2PDA: nullifier2PDA.toString(),
294
293
  nullifier3PDA: nullifier3PDA.toString(),
295
- commitment0PDA: commitment0PDA.toString(),
296
- commitment1PDA: commitment1PDA.toString(),
297
294
  treeTokenAccount: treeTokenAccount.toString(),
298
295
  globalConfigAccount: globalConfigAccount.toString(),
299
296
  recipient: recipient.toString(),