@veil-cash/sdk 0.6.2 → 0.6.4

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/src/transfer.ts CHANGED
@@ -140,6 +140,7 @@ export async function buildTransferProof(
140
140
  senderKeypair,
141
141
  pool = 'eth',
142
142
  rpcUrl,
143
+ provingKeyPath,
143
144
  onProgress,
144
145
  } = options;
145
146
 
@@ -246,6 +247,7 @@ export async function buildTransferProof(
246
247
  recipient: '0x0000000000000000000000000000000000000000',
247
248
  relayer: '0x0000000000000000000000000000000000000000',
248
249
  onProgress,
250
+ provingKeyPath,
249
251
  });
250
252
 
251
253
  return {
@@ -338,9 +340,10 @@ export async function mergeUtxos(options: {
338
340
  keypair: Keypair;
339
341
  pool?: RelayPool;
340
342
  rpcUrl?: string;
343
+ provingKeyPath?: import('./prover.js').ProvingKeyPath;
341
344
  onProgress?: (stage: string, detail?: string) => void;
342
345
  }): Promise<TransferResult> {
343
- const { amount, keypair, pool = 'eth', rpcUrl, onProgress } = options;
346
+ const { amount, keypair, pool = 'eth', rpcUrl, provingKeyPath, onProgress } = options;
344
347
 
345
348
  const poolConfig = POOL_CONFIG[pool];
346
349
  const poolAddress = getPoolAddress(pool);
@@ -432,6 +435,7 @@ export async function mergeUtxos(options: {
432
435
  recipient: '0x0000000000000000000000000000000000000000',
433
436
  relayer: '0x0000000000000000000000000000000000000000',
434
437
  onProgress,
438
+ provingKeyPath,
435
439
  });
436
440
 
437
441
  // 6. Submit to relay
package/src/types.ts CHANGED
@@ -228,6 +228,13 @@ export interface BuildWithdrawProofOptions {
228
228
  pool?: RelayPool;
229
229
  /** Optional RPC URL */
230
230
  rpcUrl?: string;
231
+ /**
232
+ * Optional proving key directory/base URL or resolver.
233
+ *
234
+ * Browsers default to `/keys`, expecting files like
235
+ * `/keys/transaction2.wasm` and `/keys/transaction2.zkey`.
236
+ */
237
+ provingKeyPath?: import('./prover.js').ProvingKeyPath;
231
238
  /** Progress callback */
232
239
  onProgress?: (stage: string, detail?: string) => void;
233
240
  }
@@ -246,6 +253,13 @@ export interface BuildTransferProofOptions {
246
253
  pool?: RelayPool;
247
254
  /** Optional RPC URL */
248
255
  rpcUrl?: string;
256
+ /**
257
+ * Optional proving key directory/base URL or resolver.
258
+ *
259
+ * Browsers default to `/keys`, expecting files like
260
+ * `/keys/transaction2.wasm` and `/keys/transaction2.zkey`.
261
+ */
262
+ provingKeyPath?: import('./prover.js').ProvingKeyPath;
249
263
  /** Progress callback */
250
264
  onProgress?: (stage: string, detail?: string) => void;
251
265
  }
@@ -461,6 +475,13 @@ export interface SubaccountMergeOptions {
461
475
  rpcUrl?: string;
462
476
  /** Optional relay URL */
463
477
  relayUrl?: string;
478
+ /**
479
+ * Optional proving key directory/base URL or resolver.
480
+ *
481
+ * Browsers default to `/keys`, expecting files like
482
+ * `/keys/transaction2.wasm` and `/keys/transaction2.zkey`.
483
+ */
484
+ provingKeyPath?: import('./prover.js').ProvingKeyPath;
464
485
  /** Progress callback */
465
486
  onProgress?: (stage: string, detail?: string) => void;
466
487
  }
package/src/utils.ts CHANGED
@@ -3,10 +3,10 @@
3
3
  * Poseidon hash, hex conversion, and random number generation
4
4
  */
5
5
 
6
- import * as crypto from 'crypto';
6
+ import { ethers } from 'ethers';
7
+ import { Buffer } from 'buffer';
8
+ import circomlib from 'circomlib';
7
9
 
8
- // eslint-disable-next-line @typescript-eslint/no-require-imports
9
- const circomlib = require('circomlib');
10
10
  const poseidon = circomlib.poseidon;
11
11
 
12
12
  /**
@@ -39,7 +39,15 @@ export const poseidonHash2 = (a: bigint | string | number, b: bigint | string |
39
39
  * @returns Random bigint
40
40
  */
41
41
  export const randomBN = (nbytes: number = 31): bigint => {
42
- const bytes = crypto.randomBytes(nbytes);
42
+ const cryptoApi = (globalThis as unknown as {
43
+ crypto?: { getRandomValues?: <T extends Uint8Array>(array: T) => T };
44
+ }).crypto;
45
+
46
+ if (!cryptoApi?.getRandomValues) {
47
+ throw new Error('Secure random number generation is unavailable in this runtime');
48
+ }
49
+
50
+ const bytes = cryptoApi.getRandomValues(new Uint8Array(nbytes));
43
51
  let hex = '0x';
44
52
  for (let i = 0; i < bytes.length; i++) {
45
53
  hex += bytes[i].toString(16).padStart(2, '0');
@@ -106,7 +114,6 @@ export interface ExtDataInput {
106
114
  */
107
115
  export function getExtDataHash(extData: ExtDataInput): bigint {
108
116
  // Use ethers ABI encoder for Solidity-compatible encoding
109
- const { ethers } = require('ethers');
110
117
  const abi = ethers.AbiCoder.defaultAbiCoder();
111
118
 
112
119
  // Encode the struct exactly as Solidity would
package/src/utxo.ts CHANGED
@@ -3,6 +3,7 @@
3
3
  * Represents a private balance entry that can be spent
4
4
  */
5
5
 
6
+ import { Buffer } from 'buffer';
6
7
  import { Keypair } from './keypair.js';
7
8
  import { poseidonHash, toBuffer, randomBN } from './utils.js';
8
9
 
package/src/withdraw.ts CHANGED
@@ -145,6 +145,7 @@ export async function buildWithdrawProof(
145
145
  keypair,
146
146
  pool = 'eth',
147
147
  rpcUrl,
148
+ provingKeyPath,
148
149
  onProgress,
149
150
  } = options;
150
151
 
@@ -231,6 +232,7 @@ export async function buildWithdrawProof(
231
232
  recipient,
232
233
  relayer: '0x0000000000000000000000000000000000000000',
233
234
  onProgress,
235
+ provingKeyPath,
234
236
  });
235
237
 
236
238
  return {