@0xbow/privacy-pools-core-sdk 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. package/README.md +73 -0
  2. package/dist/esm/ccip-nJye9Itm.js +166 -0
  3. package/dist/esm/ccip-nJye9Itm.js.map +1 -0
  4. package/dist/esm/index-DAWUECi8.js +84043 -0
  5. package/dist/esm/index-DAWUECi8.js.map +1 -0
  6. package/dist/esm/index.mjs +4 -0
  7. package/dist/esm/index.mjs.map +1 -0
  8. package/dist/index.d.mts +666 -0
  9. package/dist/node/artifacts/commitment.vkey +114 -0
  10. package/dist/node/artifacts/commitment.wasm +0 -0
  11. package/dist/node/artifacts/commitment.zkey +0 -0
  12. package/dist/node/artifacts/merkleTree.vkey +269 -0
  13. package/dist/node/artifacts/merkleTree.wasm +0 -0
  14. package/dist/node/artifacts/merkleTree.zkey +0 -0
  15. package/dist/node/artifacts/withdraw.vkey +129 -0
  16. package/dist/node/artifacts/withdraw.wasm +0 -0
  17. package/dist/node/artifacts/withdraw.zkey +0 -0
  18. package/dist/node/ccip-lPhPeJab.js +183 -0
  19. package/dist/node/ccip-lPhPeJab.js.map +1 -0
  20. package/dist/node/index-BiU5Ef8Z.js +90625 -0
  21. package/dist/node/index-BiU5Ef8Z.js.map +1 -0
  22. package/dist/node/index.mjs +21 -0
  23. package/dist/node/index.mjs.map +1 -0
  24. package/dist/types/abi/ERC20.d.ts +38 -0
  25. package/dist/types/abi/IEntrypoint.d.ts +794 -0
  26. package/dist/types/abi/IPrivacyPool.d.ts +51 -0
  27. package/dist/types/ccip-BZzz1Y5w.js +182 -0
  28. package/dist/types/circuits/circuits.impl.d.ts +108 -0
  29. package/dist/types/circuits/circuits.interface.d.ts +127 -0
  30. package/dist/types/circuits/index.d.ts +2 -0
  31. package/dist/types/constants.d.ts +2 -0
  32. package/dist/types/core/bruteForce.service.d.ts +61 -0
  33. package/dist/types/core/commitment.service.d.ts +30 -0
  34. package/dist/types/core/contracts.service.d.ts +106 -0
  35. package/dist/types/core/sdk.d.ts +44 -0
  36. package/dist/types/core/withdrawal.service.d.ts +32 -0
  37. package/dist/types/crypto.d.ts +45 -0
  38. package/dist/types/dirname.helper.d.ts +2 -0
  39. package/dist/types/errors/base.error.d.ts +52 -0
  40. package/dist/types/exceptions/circuitInitialization.exception.d.ts +3 -0
  41. package/dist/types/exceptions/fetchArtifacts.exception.d.ts +3 -0
  42. package/dist/types/exceptions/index.d.ts +4 -0
  43. package/dist/types/exceptions/invalidRpcUrl.exception.d.ts +3 -0
  44. package/dist/types/exceptions/privacyPool.exception.d.ts +13 -0
  45. package/dist/types/external.d.ts +7 -0
  46. package/dist/types/filename.helper.d.ts +2 -0
  47. package/dist/types/index-D-_1h8-n.js +90638 -0
  48. package/dist/types/index.d.ts +10 -0
  49. package/dist/types/index.js +20 -0
  50. package/dist/types/interfaces/blockchainProvider.interface.d.ts +12 -0
  51. package/dist/types/interfaces/circuits.interface.d.ts +30 -0
  52. package/dist/types/interfaces/contracts.interface.d.ts +28 -0
  53. package/dist/types/interfaces/index.d.ts +1 -0
  54. package/dist/types/internal.d.ts +6 -0
  55. package/dist/types/providers/blockchainProvider.d.ts +8 -0
  56. package/dist/types/providers/index.d.ts +1 -0
  57. package/dist/types/types/commitment.d.ts +48 -0
  58. package/dist/types/types/index.d.ts +2 -0
  59. package/dist/types/types/withdrawal.d.ts +30 -0
  60. package/package.json +81 -0
  61. package/src/abi/ERC20.ts +222 -0
  62. package/src/abi/IEntrypoint.ts +627 -0
  63. package/src/abi/IPrivacyPool.ts +386 -0
  64. package/src/circuits/circuits.impl.ts +213 -0
  65. package/src/circuits/circuits.interface.ts +162 -0
  66. package/src/circuits/index.ts +2 -0
  67. package/src/constants.ts +3 -0
  68. package/src/core/bruteForce.service.ts +120 -0
  69. package/src/core/commitment.service.ts +84 -0
  70. package/src/core/contracts.service.ts +407 -0
  71. package/src/core/sdk.ts +91 -0
  72. package/src/core/withdrawal.service.ts +110 -0
  73. package/src/crypto.ts +156 -0
  74. package/src/dirname.helper.ts +4 -0
  75. package/src/errors/base.error.ts +120 -0
  76. package/src/exceptions/circuitInitialization.exception.ts +6 -0
  77. package/src/exceptions/fetchArtifacts.exception.ts +7 -0
  78. package/src/exceptions/index.ts +4 -0
  79. package/src/exceptions/invalidRpcUrl.exception.ts +6 -0
  80. package/src/exceptions/privacyPool.exception.ts +19 -0
  81. package/src/external.ts +13 -0
  82. package/src/filename.helper.ts +4 -0
  83. package/src/index.ts +18 -0
  84. package/src/interfaces/blockchainProvider.interface.ts +13 -0
  85. package/src/interfaces/circuits.interface.ts +34 -0
  86. package/src/interfaces/contracts.interface.ts +58 -0
  87. package/src/interfaces/index.ts +1 -0
  88. package/src/internal.ts +6 -0
  89. package/src/providers/blockchainProvider.ts +26 -0
  90. package/src/providers/index.ts +1 -0
  91. package/src/types/commitment.ts +50 -0
  92. package/src/types/index.ts +2 -0
  93. package/src/types/withdrawal.ts +33 -0
@@ -0,0 +1,4 @@
1
+ export { o as BlockchainProvider, u as CircuitName, p as Circuits, C as CommitmentService, t as ContractError, q as ContractInteractionsService, E as ErrorCode, I as InvalidRpcUrl, P as PrivacyPoolSDK, r as ProofError, S as SDKError, W as WithdrawalService, l as bigintToHash, m as bigintToHex, n as calculateContext, k as generateMerkleProof, f as generateSecrets, j as getCommitment, h as hashPrecommitment } from './index-DAWUECi8.js';
2
+ import 'buffer';
3
+ import 'assert';
4
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
@@ -0,0 +1,666 @@
1
+ import { Groth16Proof, PublicSignals } from 'snarkjs';
2
+ import { Address, Hex, Chain } from 'viem';
3
+ export { Address } from 'viem';
4
+ import { LeanIMTMerkleProof } from '@zk-kit/lean-imt';
5
+ export { LeanIMTMerkleProof } from '@zk-kit/lean-imt';
6
+
7
+ /**
8
+ * Represents a hash value in the system.
9
+ * This is a branded type to ensure type safety.
10
+ */
11
+ type Hash = bigint & {
12
+ readonly __brand: unique symbol;
13
+ };
14
+ /**
15
+ * Represents a secret value in the system.
16
+ * This is a branded type to ensure type safety.
17
+ */
18
+ type Secret = bigint & {
19
+ readonly __brand: unique symbol;
20
+ };
21
+ /**
22
+ * Represents a precommitment structure containing the hash, nullifier, and secret.
23
+ * All hashes are computed using Poseidon.
24
+ */
25
+ interface Precommitment {
26
+ readonly hash: Hash;
27
+ readonly nullifier: Secret;
28
+ readonly secret: Secret;
29
+ }
30
+ /**
31
+ * Represents the preimage of a commitment containing the value, label, and precommitment.
32
+ */
33
+ interface CommitmentPreimage {
34
+ readonly value: bigint;
35
+ readonly label: bigint;
36
+ readonly precommitment: Precommitment;
37
+ }
38
+ /**
39
+ * Represents a complete commitment structure.
40
+ * All hashes are computed using Poseidon.
41
+ */
42
+ interface Commitment {
43
+ readonly hash: Hash;
44
+ readonly nullifierHash: Hash;
45
+ readonly preimage: CommitmentPreimage;
46
+ }
47
+ /**
48
+ * Represents the result of a commitment proof operation.
49
+ */
50
+ interface CommitmentProof {
51
+ readonly proof: Groth16Proof;
52
+ readonly publicSignals: PublicSignals;
53
+ }
54
+
55
+ /**
56
+ * Represents a withdrawal request in the system.
57
+ */
58
+ interface Withdrawal {
59
+ readonly processooor: Address;
60
+ readonly data: Hex;
61
+ }
62
+ interface WithdrawalProof {
63
+ readonly proof: Groth16Proof;
64
+ readonly publicSignals: PublicSignals;
65
+ }
66
+ /**
67
+ * Input parameters required for withdrawal proof generation.
68
+ */
69
+ interface WithdrawalProofInput {
70
+ readonly context: bigint;
71
+ readonly withdrawalAmount: bigint;
72
+ readonly stateMerkleProof: LeanIMTMerkleProof<bigint>;
73
+ readonly aspMerkleProof: LeanIMTMerkleProof<bigint>;
74
+ readonly stateRoot: Hash;
75
+ readonly stateTreeDepth: bigint;
76
+ readonly aspRoot: Hash;
77
+ readonly aspTreeDepth: bigint;
78
+ readonly newSecret: Secret;
79
+ readonly newNullifier: Secret;
80
+ }
81
+
82
+ /**
83
+ * Generates random nullifier and secret.
84
+ *
85
+ * @returns {{ nullifier: Secret, secret: Secret }} Randomly generated secrets.
86
+ */
87
+ declare function generateSecrets(): {
88
+ nullifier: Secret;
89
+ secret: Secret;
90
+ };
91
+ /**
92
+ * Computes a Poseidon hash for the given nullifier and secret.
93
+ *
94
+ * @param {Secret} nullifier - The nullifier to hash.
95
+ * @param {Secret} secret - The secret to hash.
96
+ * @returns {Hash} The Poseidon hash.
97
+ */
98
+ declare function hashPrecommitment(nullifier: Secret, secret: Secret): Hash;
99
+ /**
100
+ * Generates a commitment using the given parameters.
101
+ *
102
+ * @param {bigint} value - The value associated with the commitment.
103
+ * @param {bigint} label - The label used for the commitment.
104
+ * @param {Secret} nullifier - The nullifier used in the precommitment.
105
+ * @param {Secret} secret - The secret used in the precommitment.
106
+ * @returns {Commitment} The generated commitment object.
107
+ */
108
+ declare function getCommitment(value: bigint, label: bigint, nullifier: Secret, secret: Secret): Commitment;
109
+ /**
110
+ * Generates a Merkle inclusion proof for a given leaf in a set of leaves.
111
+ *
112
+ * @param {bigint[]} leaves - Array of leaves for the Lean Incremental Merkle tree.
113
+ * @param {bigint} leaf - The specific leaf to generate the inclusion proof for.
114
+ * @returns {LeanIMTMerkleProof<bigint>} A lean incremental Merkle tree inclusion proof.
115
+ * @throws {Error} If the leaf is not found in the leaves array.
116
+ */
117
+ declare function generateMerkleProof(leaves: bigint[], leaf: bigint): LeanIMTMerkleProof<bigint>;
118
+ declare function bigintToHash(value: bigint): Hash;
119
+ declare function bigintToHex(num: bigint | string | undefined): Hex;
120
+ /**
121
+ * Calculates the context hash for a withdrawal.
122
+ */
123
+ declare function calculateContext(withdrawal: Withdrawal, scope: Hash): string;
124
+
125
+ declare class InvalidRpcUrl extends Error {
126
+ constructor(url: string);
127
+ }
128
+
129
+ /**
130
+ * Represents an interface for a blockchain provider.
131
+ */
132
+ interface IBlockchainProvider {
133
+ /**
134
+ * Retrieves the balance of the specified address.
135
+ * @param {Address} address The address for which to retrieve the balance.
136
+ * @returns {Promise<bigint>} A Promise that resolves to the balance of the address.
137
+ */
138
+ getBalance(address: Address): Promise<bigint>;
139
+ }
140
+
141
+ declare class BlockchainProvider implements IBlockchainProvider {
142
+ private client;
143
+ constructor(rpcUrl: string);
144
+ /** @inheritdoc */
145
+ getBalance(address: Address): Promise<bigint>;
146
+ }
147
+
148
+ /**
149
+ * Enum representing available versions of circuit artifacts.
150
+ */
151
+ declare enum Version {
152
+ /**
153
+ * The latest version of the circuit artifacts.
154
+ */
155
+ Latest = "latest"
156
+ }
157
+ /**
158
+ * Type representing a version string, which is a string literal derived from the Version enum.
159
+ */
160
+ type VersionString = `${Version}`;
161
+ /**
162
+ * Enum representing the names of available circuits.
163
+ */
164
+ declare enum CircuitName$1 {
165
+ /**
166
+ * Circuit for commitments.
167
+ */
168
+ Commitment = "commitment",
169
+ /**
170
+ * Circuit for Merkle tree operations.
171
+ */
172
+ MerkleTree = "merkleTree",
173
+ /**
174
+ * Circuit for withdrawal operations.
175
+ */
176
+ Withdraw = "withdraw"
177
+ }
178
+ /**
179
+ * Type representing a circuit name string, which is a string literal derived from the CircuitName enum.
180
+ */
181
+ type CircuitNameString = `${CircuitName$1}`;
182
+ /**
183
+ * Interface representing the artifacts associated with a circuit.
184
+ */
185
+ interface CircuitArtifacts {
186
+ /**
187
+ * The precompiled wasm file for the circuit.
188
+ * @type {Uint8Array}
189
+ */
190
+ wasm: Uint8Array;
191
+ /**
192
+ * The verification key for the circuit.
193
+ * @type {Uint8Array}
194
+ */
195
+ vkey: Uint8Array;
196
+ /**
197
+ * The proving key for the circuit.
198
+ * @type {Uint8Array}
199
+ */
200
+ zkey: Uint8Array;
201
+ }
202
+ /**
203
+ * Type representing the mapping of circuit name strings to their associated circuit artifacts.
204
+ */
205
+ type Binaries = {
206
+ [key in CircuitNameString]: CircuitArtifacts;
207
+ };
208
+ /**
209
+ * Interface defining the methods required for managing circuits and their artifacts.
210
+ */
211
+ interface CircuitsInterface$1 {
212
+ /**
213
+ * Downloads all artifacts for the specified version of circuits.
214
+ * @param {VersionString} version - The version of the artifacts to download.
215
+ * @returns {Promise<Binaries>} A promise that resolves to the binaries containing all circuit artifacts.
216
+ * @async
217
+ */
218
+ downloadArtifacts(version: VersionString): Promise<Binaries>;
219
+ /**
220
+ * Initializes the artifacts for the specified version of circuits.
221
+ * @param {VersionString} version - The version of the artifacts to initialize.
222
+ * @returns {Promise<void>} A promise that resolves when initialization is complete.
223
+ * @async
224
+ */
225
+ initArtifacts(version: VersionString): Promise<void>;
226
+ /**
227
+ * Retrieves the verification key for a specified circuit.
228
+ * @param {CircuitNameString} circuitName - The name of the circuit.
229
+ * @param {VersionString} [version] - The version of the artifacts (defaults to the latest).
230
+ * @returns {Promise<Uint8Array>} A promise that resolves to the verification key.
231
+ * @async
232
+ */
233
+ getVerificationKey(circuitName: CircuitNameString, version?: VersionString): Promise<Uint8Array>;
234
+ /**
235
+ * Retrieves the proving key for a specified circuit.
236
+ * @param {CircuitNameString} circuitName - The name of the circuit.
237
+ * @param {VersionString} [version] - The version of the artifacts (defaults to the latest).
238
+ * @returns {Promise<Uint8Array>} A promise that resolves to the proving key.
239
+ * @async
240
+ */
241
+ getProvingKey(circuitName: CircuitNameString, version?: VersionString): Promise<Uint8Array>;
242
+ /**
243
+ * Retrieves the wasm file for a specified circuit.
244
+ * @param {CircuitNameString} circuitName - The name of the circuit.
245
+ * @param {VersionString} [version] - The version of the artifacts (defaults to the latest).
246
+ * @returns {Promise<Uint8Array>} A promise that resolves to the wasm file.
247
+ * @async
248
+ */
249
+ getWasm(circuitName: CircuitNameString, version?: VersionString): Promise<Uint8Array>;
250
+ }
251
+
252
+ /**
253
+ * Class representing circuit management and artifact handling.
254
+ * Implements the CircuitsInterface.
255
+ */
256
+ declare class Circuits implements CircuitsInterface$1 {
257
+ /**
258
+ * Indicates whether the circuits have been initialized.
259
+ * @type {boolean}
260
+ * @protected
261
+ */
262
+ protected initialized: boolean;
263
+ /**
264
+ * The version of the circuit artifacts being used.
265
+ * @type {VersionString}
266
+ * @protected
267
+ */
268
+ protected version: VersionString;
269
+ /**
270
+ * The binaries containing circuit artifacts such as wasm, vkey, and zkey files.
271
+ * @type {Binaries}
272
+ * @protected
273
+ */
274
+ protected binaries: Binaries;
275
+ /**
276
+ * The base URL for fetching circuit artifacts.
277
+ * @type {string}
278
+ * @protected
279
+ */
280
+ protected baseUrl: string;
281
+ /**
282
+ * Determines whether the environment is a browser.
283
+ * @returns {boolean} True if running in a browser environment, false otherwise.
284
+ * @protected
285
+ */
286
+ _browser(): boolean;
287
+ /**
288
+ * Initializes the circuit manager with binaries and a version.
289
+ * @param {Binaries} binaries - The binaries containing circuit artifacts.
290
+ * @param {VersionString} version - The version of the circuit artifacts.
291
+ * @protected
292
+ */
293
+ protected _initialize(binaries: Binaries, version: VersionString): void;
294
+ /**
295
+ * Handles initialization of circuit artifacts, fetching them if necessary.
296
+ * @param {VersionString} [version=Version.latest] - The version of the circuit artifacts.
297
+ * @throws {CircuitInitialization} If an error occurs during initialization.
298
+ * @protected
299
+ * @async
300
+ */
301
+ protected _handleInitialization(version?: VersionString): Promise<void>;
302
+ /**
303
+ * Fetches a versioned artifact from a given path.
304
+ * @param {string} artifactPath - The path to the artifact.
305
+ * @param {VersionString} version - The version of the artifact.
306
+ * @returns {Promise<Uint8Array>} A promise that resolves to the artifact as a Uint8Array.
307
+ * @throws {FetchArtifact} If the artifact cannot be fetched.
308
+ * @protected
309
+ * @async
310
+ */
311
+ _fetchVersionedArtifact(artifactPath: string): Promise<Uint8Array>;
312
+ /**
313
+ * Downloads and returns the circuit artifacts for a specific circuit.
314
+ * @param {CircuitNameString} circuitName - The name of the circuit.
315
+ * @returns {Promise<CircuitArtifacts>} A promise that resolves to the circuit artifacts.
316
+ * @protected
317
+ * @async
318
+ */
319
+ _downloadCircuitArtifacts(circuitName: CircuitNameString): Promise<CircuitArtifacts>;
320
+ /**
321
+ * Downloads all circuit artifacts for the specified version.
322
+ * @param {VersionString} version - The version of the artifacts.
323
+ * @returns {Promise<Binaries>} A promise that resolves to the binaries containing all circuit artifacts.
324
+ * @async
325
+ */
326
+ downloadArtifacts(version: VersionString): Promise<Binaries>;
327
+ /**
328
+ * Initializes the circuit artifacts for the specified version.
329
+ * @param {VersionString} version - The version of the artifacts.
330
+ * @returns {Promise<void>} A promise that resolves when initialization is complete.
331
+ * @async
332
+ */
333
+ initArtifacts(version: VersionString): Promise<void>;
334
+ /**
335
+ * Retrieves the verification key for a specified circuit.
336
+ * @param {CircuitNameString} circuitName - The name of the circuit.
337
+ * @param {VersionString} [version=Version.latest] - The version of the artifacts.
338
+ * @returns {Promise<Uint8Array>} A promise that resolves to the verification key.
339
+ * @async
340
+ */
341
+ getVerificationKey(circuitName: CircuitNameString, version?: VersionString): Promise<Uint8Array>;
342
+ /**
343
+ * Retrieves the proving key for a specified circuit.
344
+ * @param {CircuitNameString} circuitName - The name of the circuit.
345
+ * @param {VersionString} [version=Version.latest] - The version of the artifacts.
346
+ * @returns {Promise<Uint8Array>} A promise that resolves to the proving key.
347
+ * @async
348
+ */
349
+ getProvingKey(circuitName: CircuitNameString, version?: VersionString): Promise<Uint8Array>;
350
+ /**
351
+ * Retrieves the wasm file for a specified circuit.
352
+ * @param {CircuitNameString} circuitName - The name of the circuit.
353
+ * @param {VersionString} [version=Version.latest] - The version of the artifacts.
354
+ * @returns {Promise<Uint8Array>} A promise that resolves to the wasm file.
355
+ * @async
356
+ */
357
+ getWasm(circuitName: CircuitNameString, version?: VersionString): Promise<Uint8Array>;
358
+ }
359
+
360
+ interface TransactionResponse {
361
+ hash: string;
362
+ wait: () => Promise<void>;
363
+ }
364
+ interface ContractInteractions {
365
+ depositERC20(asset: Address, amount: bigint, precommitment: bigint): Promise<TransactionResponse>;
366
+ depositETH(amount: bigint, precommitment: bigint): Promise<TransactionResponse>;
367
+ withdraw(withdrawal: Withdrawal, withdrawalProof: WithdrawalProof, scope: Hash): Promise<TransactionResponse>;
368
+ relay(withdrawal: Withdrawal, withdrawalProof: WithdrawalProof, scope: Hash): Promise<TransactionResponse>;
369
+ ragequit(commitmentProof: CommitmentProof, privacyPoolAddress: Address): Promise<TransactionResponse>;
370
+ getScope(privacyPoolAddress: Address): Promise<bigint>;
371
+ getStateRoot(privacyPoolAddress: Address): Promise<bigint>;
372
+ getStateSize(privacyPoolAddress: Address): Promise<bigint>;
373
+ getScopeData(scope: bigint): Promise<{
374
+ poolAddress: Address | null;
375
+ assetAddress: Address | null;
376
+ }>;
377
+ approveERC20(spenderAddress: Address, tokenAddress: Address, amount: bigint): Promise<TransactionResponse>;
378
+ }
379
+
380
+ declare class ContractInteractionsService implements ContractInteractions {
381
+ private publicClient;
382
+ private walletClient;
383
+ private entrypointAddress;
384
+ private account;
385
+ /**
386
+ * Initializes the contract interactions service.
387
+ *
388
+ * @param rpcUrl - The RPC endpoint URL for the blockchain network.
389
+ * @param chain - The blockchain network configuration.
390
+ * @param entrypointAddress - The address of the entrypoint contract.
391
+ * @param accountPrivateKey - The private key used for signing transactions.
392
+ */
393
+ constructor(rpcUrl: string, chain: Chain, entrypointAddress: Address, accountPrivateKey: Hex);
394
+ /**
395
+ * Deposits ERC20 tokens into the privacy pool.
396
+ *
397
+ * @param asset - The address of the ERC20 token.
398
+ * @param amount - The amount of tokens to deposit.
399
+ * @param precommitment - The precommitment value.
400
+ * @returns Transaction response containing the transaction hash.
401
+ */
402
+ depositERC20(asset: Address, amount: bigint, precommitment: bigint): Promise<TransactionResponse>;
403
+ /**
404
+ * Deposits ETH into the privacy pool.
405
+ *
406
+ * @param amount - The amount of ETH to deposit.
407
+ * @param precommitment - The precommitment value.
408
+ * @returns Transaction response containing the transaction hash.
409
+ */
410
+ depositETH(amount: bigint, precommitment: bigint): Promise<TransactionResponse>;
411
+ /**
412
+ * Withdraws funds from the privacy pool.
413
+ *
414
+ * @param withdrawal - The withdrawal object containing recipient details and amount.
415
+ * @param withdrawalProof - The cryptographic proof verifying the withdrawal.
416
+ * @returns Transaction response containing the transaction hash.
417
+ */
418
+ withdraw(withdrawal: Withdrawal, withdrawalProof: WithdrawalProof, scope: Hash): Promise<TransactionResponse>;
419
+ /**
420
+ * Relays a withdrawal transaction to the entrypoint contract.
421
+ * This function is used to facilitate relayer transactions.
422
+ *
423
+ * @param withdrawal - The withdrawal data structure.
424
+ * @param withdrawalProof - The cryptographic proof required for withdrawal.
425
+ * @returns Transaction response containing hash and wait function.
426
+ */
427
+ relay(withdrawal: Withdrawal, withdrawalProof: WithdrawalProof, scope: Hash): Promise<TransactionResponse>;
428
+ /**
429
+ * Executes a ragequit operation, allowing a user to exit the pool
430
+ * by nullifying their commitment and proving their withdrawal.
431
+ *
432
+ * @param commitmentProof - The cryptographic proof of the commitment.
433
+ * @param privacyPoolAddress - The address of the privacy pool contract.
434
+ * @returns Transaction response containing hash and wait function.
435
+ */
436
+ ragequit(commitmentProof: CommitmentProof, privacyPoolAddress: Address): Promise<TransactionResponse>;
437
+ /**
438
+ * Retrieves the scope identifier of a given privacy pool.
439
+ *
440
+ * @param privacyPoolAddress - The address of the privacy pool contract.
441
+ * @returns The scope identifier as a bigint.
442
+ */
443
+ getScope(privacyPoolAddress: Address): Promise<bigint>;
444
+ /**
445
+ * Retrieves the latest state root of the privacy pool from the entrypoint contract.
446
+ *
447
+ * @param privacyPoolAddress - The address of the privacy pool contract.
448
+ * @returns The latest state root as a bigint.
449
+ */
450
+ getStateRoot(privacyPoolAddress: Address): Promise<bigint>;
451
+ /**
452
+ * Retrieves the current state size of the privacy pool.
453
+ *
454
+ * @param privacyPoolAddress - The address of the privacy pool contract.
455
+ * @returns The size of the state tree as a bigint.
456
+ */
457
+ getStateSize(privacyPoolAddress: Address): Promise<bigint>;
458
+ /**
459
+ * Retrieves data about a specific scope, including the associated privacy pool
460
+ * and the asset used in that pool.
461
+ *
462
+ * @param scope - The scope identifier to look up.
463
+ * @returns An object containing the privacy pool address and asset address.
464
+ * @throws ContractError if the scope does not exist.
465
+ */
466
+ getScopeData(scope: bigint): Promise<{
467
+ poolAddress: Address;
468
+ assetAddress: Address;
469
+ }>;
470
+ /**
471
+ * Approves the entrypoint contract to spend a specified amount of ERC20 tokens.
472
+ *
473
+ * @param spenderAddress - The address of the entity that will be approved to spend tokens.
474
+ * @param tokenAddress - The address of the ERC20 token contract.
475
+ * @param amount - The amount of tokens to approve.
476
+ * @returns Transaction response containing hash and wait function.
477
+ */
478
+ approveERC20(spenderAddress: Address, tokenAddress: Address, amount: bigint): Promise<TransactionResponse>;
479
+ private formatProof;
480
+ private executeTransaction;
481
+ }
482
+
483
+ /**
484
+ * Available circuit types in the system.
485
+ */
486
+ declare enum CircuitName {
487
+ Commitment = "commitment",
488
+ Withdraw = "withdraw"
489
+ }
490
+ /**
491
+ * Type for circuit input signals.
492
+ */
493
+ type CircuitSignals = {
494
+ [key: string]: bigint | bigint[] | string;
495
+ };
496
+ /**
497
+ * Interface for accessing circuit-related resources.
498
+ */
499
+ interface CircuitsInterface {
500
+ /**
501
+ * Gets the WASM binary for a circuit.
502
+ */
503
+ getWasm(name: CircuitName): Promise<Uint8Array>;
504
+ /**
505
+ * Gets the proving key for a circuit.
506
+ */
507
+ getProvingKey(name: CircuitName): Promise<Uint8Array>;
508
+ /**
509
+ * Gets the verification key for a circuit.
510
+ */
511
+ getVerificationKey(name: CircuitName): Promise<Uint8Array>;
512
+ }
513
+
514
+ /**
515
+ * Main SDK class providing access to all privacy pool functionality.
516
+ * Uses Poseidon hash for all commitment operations.
517
+ */
518
+ declare class PrivacyPoolSDK {
519
+ private readonly commitmentService;
520
+ private readonly withdrawalService;
521
+ constructor(circuits: CircuitsInterface);
522
+ createContractInstance(rpcUrl: string, chain: Chain, entrypointAddress: Address, privateKey: Hex): ContractInteractionsService;
523
+ /**
524
+ * Generates a commitment proof.
525
+ *
526
+ * @param value - Value to commit
527
+ * @param label - Label for the commitment
528
+ * @param nullifier - Nullifier for the commitment
529
+ * @param secret - Secret for the commitment
530
+ */
531
+ proveCommitment(value: bigint, label: bigint, nullifier: bigint, secret: bigint): Promise<CommitmentProof>;
532
+ /**
533
+ * Verifies a commitment proof.
534
+ *
535
+ * @param proof - The proof to verify
536
+ */
537
+ verifyCommitment(proof: CommitmentProof): Promise<boolean>;
538
+ /**
539
+ * Generates a withdrawal proof.
540
+ *
541
+ * @param commitment - Commitment to withdraw
542
+ * @param input - Input parameters for the withdrawal
543
+ * @param withdrawal - Withdrawal details
544
+ */
545
+ proveWithdrawal(commitment: Commitment, input: WithdrawalProofInput): Promise<WithdrawalProof>;
546
+ /**
547
+ * Verifies a withdrawal proof.
548
+ *
549
+ * @param withdrawalProof - The withdrawal payload to verify
550
+ */
551
+ verifyWithdrawal(withdrawalProof: WithdrawalProof): Promise<boolean>;
552
+ }
553
+
554
+ /**
555
+ * Unified error codes for the SDK.
556
+ */
557
+ declare enum ErrorCode {
558
+ UNKNOWN = "UNKNOWN",
559
+ INVALID_INPUT = "INVALID_INPUT",
560
+ OPERATION_FAILED = "OPERATION_FAILED",
561
+ NETWORK_ERROR = "NETWORK_ERROR",
562
+ PROOF_GENERATION_FAILED = "PROOF_GENERATION_FAILED",
563
+ PROOF_VERIFICATION_FAILED = "PROOF_VERIFICATION_FAILED",
564
+ INVALID_PROOF = "INVALID_PROOF",
565
+ INVALID_PUBLIC_SIGNALS = "INVALID_PUBLIC_SIGNALS",
566
+ CIRCUIT_ERROR = "CIRCUIT_ERROR",
567
+ CONTRACT_ERROR = "CONTRACT_ERROR",
568
+ CRYPTO_ERROR = "CRYPTO_ERROR",
569
+ MERKLE_ERROR = "MERKLE_ERROR"
570
+ }
571
+ /**
572
+ * Base error class for the SDK.
573
+ * All other error classes should extend this.
574
+ */
575
+ declare class SDKError extends Error {
576
+ readonly code: ErrorCode;
577
+ readonly details?: Record<string, unknown> | undefined;
578
+ constructor(message: string, code?: ErrorCode, details?: Record<string, unknown> | undefined);
579
+ /**
580
+ * Creates a JSON representation of the error.
581
+ */
582
+ toJSON(): Record<string, unknown>;
583
+ }
584
+ /**
585
+ * Specialized error class for proof-related operations.
586
+ */
587
+ declare class ProofError extends SDKError {
588
+ constructor(message: string, code?: ErrorCode, details?: Record<string, unknown>);
589
+ /**
590
+ * Creates an error for proof generation failures.
591
+ */
592
+ static generationFailed(details?: Record<string, unknown>): ProofError;
593
+ /**
594
+ * Creates an error for proof verification failures.
595
+ */
596
+ static verificationFailed(details?: Record<string, unknown>): ProofError;
597
+ /**
598
+ * Creates an error for invalid proof format.
599
+ */
600
+ static invalidProof(details?: Record<string, unknown>): ProofError;
601
+ }
602
+ declare class ContractError extends SDKError {
603
+ constructor(message: string, code?: ErrorCode, details?: Record<string, unknown>);
604
+ static scopeNotFound(scope: bigint): ContractError;
605
+ }
606
+
607
+ /**
608
+ * Service responsible for handling commitment-related operations.
609
+ * All hash operations use Poseidon for ZK-friendly hashing.
610
+ */
611
+ declare class CommitmentService {
612
+ private readonly circuits;
613
+ constructor(circuits: CircuitsInterface);
614
+ /**
615
+ * Generates a zero-knowledge proof for a commitment using Poseidon hash.
616
+ *
617
+ * @param value - The value being committed to
618
+ * @param label - Label associated with the commitment
619
+ * @param nullifier - Unique nullifier for the commitment
620
+ * @param secret - Secret key for the commitment
621
+ * @returns Promise resolving to proof and public signals
622
+ * @throws {ProofError} If proof generation fails
623
+ */
624
+ proveCommitment(value: bigint, label: bigint, nullifier: bigint, secret: bigint): Promise<CommitmentProof>;
625
+ /**
626
+ * Verifies a commitment proof.
627
+ *
628
+ * @param proof - The commitment proof to verify
629
+ * @param publicSignals - Public signals associated with the proof
630
+ * @returns Promise resolving to boolean indicating proof validity
631
+ * @throws {ProofError} If verification fails
632
+ */
633
+ verifyCommitment({ proof, publicSignals, }: CommitmentProof): Promise<boolean>;
634
+ }
635
+
636
+ /**
637
+ * Service responsible for handling withdrawal-related operations.
638
+ */
639
+ declare class WithdrawalService {
640
+ private readonly circuits;
641
+ constructor(circuits: CircuitsInterface);
642
+ /**
643
+ * Generates a withdrawal proof.
644
+ *
645
+ * @param commitment - Commitment to withdraw
646
+ * @param input - Input parameters for the withdrawal
647
+ * @param withdrawal - Withdrawal details
648
+ * @returns Promise resolving to withdrawal payload
649
+ * @throws {ProofError} If proof generation fails
650
+ */
651
+ proveWithdrawal(commitment: Commitment, input: WithdrawalProofInput): Promise<WithdrawalProof>;
652
+ /**
653
+ * Verifies a withdrawal proof.
654
+ *
655
+ * @param withdrawalPayload - The withdrawal payload to verify
656
+ * @returns Promise resolving to boolean indicating proof validity
657
+ * @throws {ProofError} If verification fails
658
+ */
659
+ verifyWithdrawal(withdrawalPayload: WithdrawalProof): Promise<boolean>;
660
+ /**
661
+ * Prepares input signals for the withdrawal circuit.
662
+ */
663
+ private prepareInputSignals;
664
+ }
665
+
666
+ export { BlockchainProvider, CircuitName, type CircuitSignals, Circuits, type CircuitsInterface, type Commitment, type CommitmentPreimage, type CommitmentProof, CommitmentService, ContractError, ContractInteractionsService, ErrorCode, type Hash, type IBlockchainProvider, InvalidRpcUrl, type Precommitment, PrivacyPoolSDK, ProofError, SDKError, type Secret, type Withdrawal, type WithdrawalProof, type WithdrawalProofInput, WithdrawalService, bigintToHash, bigintToHex, calculateContext, generateMerkleProof, generateSecrets, getCommitment, hashPrecommitment };