@0xbow/privacy-pools-core-sdk 0.0.0-3dpf8pk

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 (117) hide show
  1. package/README.md +73 -0
  2. package/dist/esm/fetchArtifacts.esm-DTr__iP-.js +18 -0
  3. package/dist/esm/fetchArtifacts.esm-DTr__iP-.js.map +1 -0
  4. package/dist/esm/fetchArtifacts.node-BLw8nwbt.js +31 -0
  5. package/dist/esm/fetchArtifacts.node-BLw8nwbt.js.map +1 -0
  6. package/dist/esm/index-Derz3sX9.js +73457 -0
  7. package/dist/esm/index-Derz3sX9.js.map +1 -0
  8. package/dist/esm/index.mjs +7 -0
  9. package/dist/esm/index.mjs.map +1 -0
  10. package/dist/index.d.mts +1326 -0
  11. package/dist/node/fetchArtifacts.esm-ZwE-hqnx.js +35 -0
  12. package/dist/node/fetchArtifacts.esm-ZwE-hqnx.js.map +1 -0
  13. package/dist/node/fetchArtifacts.node-CY8wLnXd.js +48 -0
  14. package/dist/node/fetchArtifacts.node-CY8wLnXd.js.map +1 -0
  15. package/dist/node/index-B804ILXn.js +80507 -0
  16. package/dist/node/index-B804ILXn.js.map +1 -0
  17. package/dist/node/index.mjs +24 -0
  18. package/dist/node/index.mjs.map +1 -0
  19. package/dist/types/abi/ERC20.d.ts +38 -0
  20. package/dist/types/abi/IEntrypoint.d.ts +823 -0
  21. package/dist/types/abi/IPrivacyPool.d.ts +51 -0
  22. package/dist/types/circuits/circuits.impl.d.ts +120 -0
  23. package/dist/types/circuits/circuits.interface.d.ts +129 -0
  24. package/dist/types/circuits/fetchArtifacts.d.ts +1 -0
  25. package/dist/types/circuits/fetchArtifacts.esm.d.ts +1 -0
  26. package/dist/types/circuits/fetchArtifacts.node.d.ts +1 -0
  27. package/dist/types/circuits/index.d.ts +2 -0
  28. package/dist/types/constants.d.ts +2 -0
  29. package/dist/types/core/account.service.d.ts +355 -0
  30. package/dist/types/core/bruteForce.service.d.ts +61 -0
  31. package/dist/types/core/commitment.service.d.ts +30 -0
  32. package/dist/types/core/contracts.service.d.ts +114 -0
  33. package/dist/types/core/data.service.d.ts +72 -0
  34. package/dist/types/core/sdk.d.ts +45 -0
  35. package/dist/types/core/withdrawal.service.d.ts +32 -0
  36. package/dist/types/crypto.d.ts +67 -0
  37. package/dist/types/dirname.helper.d.ts +2 -0
  38. package/dist/types/errors/account.error.d.ts +10 -0
  39. package/dist/types/errors/base.error.d.ts +53 -0
  40. package/dist/types/errors/data.error.d.ts +7 -0
  41. package/dist/types/errors/events.error.d.ts +9 -0
  42. package/dist/types/exceptions/circuitInitialization.exception.d.ts +3 -0
  43. package/dist/types/exceptions/fetchArtifacts.exception.d.ts +3 -0
  44. package/dist/types/exceptions/index.d.ts +4 -0
  45. package/dist/types/exceptions/invalidRpcUrl.exception.d.ts +3 -0
  46. package/dist/types/exceptions/privacyPool.exception.d.ts +13 -0
  47. package/dist/types/external.d.ts +7 -0
  48. package/dist/types/fetchArtifacts.esm-m-j0Hu4b.js +34 -0
  49. package/dist/types/fetchArtifacts.node-CGJMDWIh.js +47 -0
  50. package/dist/types/filename.helper.d.ts +2 -0
  51. package/dist/types/index-B6kM6ceO.js +80520 -0
  52. package/dist/types/index.d.ts +14 -0
  53. package/dist/types/index.js +23 -0
  54. package/dist/types/interfaces/blockchainProvider.interface.d.ts +12 -0
  55. package/dist/types/interfaces/circuits.interface.d.ts +30 -0
  56. package/dist/types/interfaces/contracts.interface.d.ts +35 -0
  57. package/dist/types/interfaces/index.d.ts +1 -0
  58. package/dist/types/internal.d.ts +6 -0
  59. package/dist/types/keys.d.ts +18 -0
  60. package/dist/types/providers/blockchainProvider.d.ts +8 -0
  61. package/dist/types/providers/index.d.ts +1 -0
  62. package/dist/types/types/account.d.ts +31 -0
  63. package/dist/types/types/commitment.d.ts +48 -0
  64. package/dist/types/types/events.d.ts +72 -0
  65. package/dist/types/types/index.d.ts +4 -0
  66. package/dist/types/types/keys.d.ts +5 -0
  67. package/dist/types/types/rateLimit.d.ts +51 -0
  68. package/dist/types/types/withdrawal.d.ts +30 -0
  69. package/dist/types/utils/logger.d.ts +22 -0
  70. package/package.json +84 -0
  71. package/src/abi/ERC20.ts +222 -0
  72. package/src/abi/IEntrypoint.ts +1059 -0
  73. package/src/abi/IPrivacyPool.ts +576 -0
  74. package/src/circuits/circuits.impl.ts +232 -0
  75. package/src/circuits/circuits.interface.ts +166 -0
  76. package/src/circuits/fetchArtifacts.esm.ts +12 -0
  77. package/src/circuits/fetchArtifacts.node.ts +23 -0
  78. package/src/circuits/fetchArtifacts.ts +7 -0
  79. package/src/circuits/index.ts +2 -0
  80. package/src/constants.ts +3 -0
  81. package/src/core/account.service.ts +1343 -0
  82. package/src/core/bruteForce.service.ts +120 -0
  83. package/src/core/commitment.service.ts +84 -0
  84. package/src/core/contracts.service.ts +442 -0
  85. package/src/core/data.service.ts +608 -0
  86. package/src/core/sdk.ts +92 -0
  87. package/src/core/withdrawal.service.ts +126 -0
  88. package/src/crypto.ts +226 -0
  89. package/src/dirname.helper.ts +4 -0
  90. package/src/errors/account.error.ts +49 -0
  91. package/src/errors/base.error.ts +125 -0
  92. package/src/errors/data.error.ts +34 -0
  93. package/src/errors/events.error.ts +38 -0
  94. package/src/exceptions/circuitInitialization.exception.ts +6 -0
  95. package/src/exceptions/fetchArtifacts.exception.ts +7 -0
  96. package/src/exceptions/index.ts +4 -0
  97. package/src/exceptions/invalidRpcUrl.exception.ts +6 -0
  98. package/src/exceptions/privacyPool.exception.ts +19 -0
  99. package/src/external.ts +13 -0
  100. package/src/filename.helper.ts +4 -0
  101. package/src/index.ts +25 -0
  102. package/src/interfaces/blockchainProvider.interface.ts +13 -0
  103. package/src/interfaces/circuits.interface.ts +34 -0
  104. package/src/interfaces/contracts.interface.ts +66 -0
  105. package/src/interfaces/index.ts +1 -0
  106. package/src/internal.ts +6 -0
  107. package/src/keys.ts +42 -0
  108. package/src/providers/blockchainProvider.ts +26 -0
  109. package/src/providers/index.ts +1 -0
  110. package/src/types/account.ts +35 -0
  111. package/src/types/commitment.ts +50 -0
  112. package/src/types/events.ts +82 -0
  113. package/src/types/index.ts +4 -0
  114. package/src/types/keys.ts +6 -0
  115. package/src/types/rateLimit.ts +66 -0
  116. package/src/types/withdrawal.ts +33 -0
  117. package/src/utils/logger.ts +56 -0
@@ -0,0 +1,1326 @@
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
+ interface MasterKeys {
83
+ masterNullifier: Secret;
84
+ masterSecret: Secret;
85
+ }
86
+
87
+ /**
88
+ * Configuration options for rate-limited log fetching
89
+ */
90
+ interface LogFetchConfig {
91
+ /**
92
+ * Maximum number of blocks to fetch in a single RPC call.
93
+ * Default: 10000 (typical limit for most RPC providers)
94
+ */
95
+ blockChunkSize: number;
96
+ /**
97
+ * Maximum number of concurrent log fetch operations.
98
+ * Default: 3
99
+ */
100
+ concurrency: number;
101
+ /**
102
+ * Delay in milliseconds between chunk requests (for additional throttling).
103
+ * Default: 0 (no delay)
104
+ */
105
+ chunkDelayMs: number;
106
+ /**
107
+ * Whether to retry failed chunk fetches.
108
+ * Default: true
109
+ */
110
+ retryOnFailure: boolean;
111
+ /**
112
+ * Maximum number of retries for a failed chunk.
113
+ * Default: 3
114
+ */
115
+ maxRetries: number;
116
+ /**
117
+ * Base delay for exponential backoff on retries (ms).
118
+ * Default: 1000
119
+ */
120
+ retryBaseDelayMs: number;
121
+ }
122
+ /**
123
+ * Default log fetch configuration
124
+ */
125
+ declare const DEFAULT_LOG_FETCH_CONFIG: LogFetchConfig;
126
+ /**
127
+ * Per-chain log fetch configuration map
128
+ * Maps chainId to its specific LogFetchConfig
129
+ */
130
+ type ChainLogFetchConfig = Map<number, Partial<LogFetchConfig>>;
131
+ /**
132
+ * Block range for chunked fetching
133
+ */
134
+ interface BlockRange {
135
+ fromBlock: bigint;
136
+ toBlock: bigint;
137
+ }
138
+
139
+ /**
140
+ * Generates two master keys based on some provided seed or a random value.
141
+ *
142
+ * @param {Hex} seed - The optional seed.
143
+ * @returns {MasterKeys} The master key pair.
144
+ */
145
+ declare function generateMasterKeys(mnemonic: string): MasterKeys;
146
+ /**
147
+ * Generates a nullifier and secret pair for a deposit commitment.
148
+ *
149
+ * @param {MasterKeys} keys - The master keys pair.
150
+ * @param {Hash} scope - The pool scope.
151
+ * @param {bigint} index - The pool account index for the scope.
152
+ * @returns {Secret, Secret} The commitment nullifier and secret pair.
153
+ */
154
+ declare function generateDepositSecrets(keys: MasterKeys, scope: Hash, index: bigint): {
155
+ nullifier: Secret;
156
+ secret: Secret;
157
+ };
158
+ /**
159
+ * Generates a nullifier and secret pair for a withdrawal commitment.
160
+ *
161
+ * @param {MasterKeys} keys - The master keys pair.
162
+ * @param {Hash} label - The deposit commitment label.
163
+ * @param {bigint} index - The withdrawal index for the pool account.
164
+ * @returns {Secret, Secret} The commitment nullifier and secret pair.
165
+ */
166
+ declare function generateWithdrawalSecrets(keys: MasterKeys, label: Hash, index: bigint): {
167
+ nullifier: Secret;
168
+ secret: Secret;
169
+ };
170
+ /**
171
+ * Computes a Poseidon hash for the given nullifier and secret.
172
+ *
173
+ * @param {Secret} nullifier - The nullifier to hash.
174
+ * @param {Secret} secret - The secret to hash.
175
+ * @returns {Hash} The Poseidon hash.
176
+ */
177
+ declare function hashPrecommitment(nullifier: Secret, secret: Secret): Hash;
178
+ /**
179
+ * Generates a commitment using the given parameters.
180
+ *
181
+ * @param {bigint} value - The value associated with the commitment.
182
+ * @param {bigint} label - The label used for the commitment.
183
+ * @param {Secret} nullifier - The nullifier used in the precommitment.
184
+ * @param {Secret} secret - The secret used in the precommitment.
185
+ * @returns {Commitment} The generated commitment object.
186
+ */
187
+ declare function getCommitment(value: bigint, label: bigint, nullifier: Secret, secret: Secret): Commitment;
188
+ /**
189
+ * Generates a Merkle inclusion proof for a given leaf in a set of leaves.
190
+ *
191
+ * @param {bigint[]} leaves - Array of leaves for the Lean Incremental Merkle tree.
192
+ * @param {bigint} leaf - The specific leaf to generate the inclusion proof for.
193
+ * @returns {LeanIMTMerkleProof<bigint>} A lean incremental Merkle tree inclusion proof.
194
+ * @throws {Error} If the leaf is not found in the leaves array.
195
+ */
196
+ declare function generateMerkleProof(leaves: bigint[], leaf: bigint): LeanIMTMerkleProof<bigint>;
197
+ declare function bigintToHash(value: bigint): Hash;
198
+ declare function bigintToHex(num: bigint | string | undefined): Hex;
199
+ /**
200
+ * Calculates the context hash for a withdrawal.
201
+ */
202
+ declare function calculateContext(withdrawal: Withdrawal, scope: Hash): string;
203
+
204
+ declare class InvalidRpcUrl extends Error {
205
+ constructor(url: string);
206
+ }
207
+
208
+ /**
209
+ * Represents an interface for a blockchain provider.
210
+ */
211
+ interface IBlockchainProvider {
212
+ /**
213
+ * Retrieves the balance of the specified address.
214
+ * @param {Address} address The address for which to retrieve the balance.
215
+ * @returns {Promise<bigint>} A Promise that resolves to the balance of the address.
216
+ */
217
+ getBalance(address: Address): Promise<bigint>;
218
+ }
219
+
220
+ declare class BlockchainProvider implements IBlockchainProvider {
221
+ private client;
222
+ constructor(rpcUrl: string);
223
+ /** @inheritdoc */
224
+ getBalance(address: Address): Promise<bigint>;
225
+ }
226
+
227
+ /**
228
+ * Enum representing available versions of circuit artifacts.
229
+ */
230
+ declare enum Version {
231
+ /**
232
+ * The latest version of the circuit artifacts.
233
+ */
234
+ Latest = "latest"
235
+ }
236
+ /**
237
+ * Type representing a version string, which is a string literal derived from the Version enum.
238
+ */
239
+ type VersionString = `${Version}`;
240
+ /**
241
+ * Enum representing the names of available circuits.
242
+ */
243
+ declare enum CircuitName$1 {
244
+ /**
245
+ * Circuit for commitments.
246
+ */
247
+ Commitment = "commitment",
248
+ /**
249
+ * Circuit for Merkle tree operations.
250
+ */
251
+ MerkleTree = "merkleTree",
252
+ /**
253
+ * Circuit for withdrawal operations.
254
+ */
255
+ Withdraw = "withdraw"
256
+ }
257
+ /**
258
+ * Type representing a circuit name string, which is a string literal derived from the CircuitName enum.
259
+ */
260
+ type CircuitNameString = `${CircuitName$1}`;
261
+ /**
262
+ * Interface representing the artifacts associated with a circuit.
263
+ */
264
+ interface CircuitArtifacts {
265
+ /**
266
+ * The precompiled wasm file for the circuit.
267
+ * @type {Uint8Array}
268
+ */
269
+ wasm: Uint8Array;
270
+ /**
271
+ * The verification key for the circuit.
272
+ * @type {Uint8Array}
273
+ */
274
+ vkey: Uint8Array;
275
+ /**
276
+ * The proving key for the circuit.
277
+ * @type {Uint8Array}
278
+ */
279
+ zkey: Uint8Array;
280
+ }
281
+ /**
282
+ * Type representing the mapping of circuit name strings to their associated circuit artifacts.
283
+ */
284
+ interface Binaries {
285
+ commitment: CircuitArtifacts;
286
+ withdraw: CircuitArtifacts;
287
+ merkleTree?: CircuitArtifacts;
288
+ }
289
+ /**
290
+ * Interface defining the methods required for managing circuits and their artifacts.
291
+ */
292
+ interface CircuitsInterface$1 {
293
+ /**
294
+ * Downloads all artifacts for the specified version of circuits.
295
+ * @param {VersionString} version - The version of the artifacts to download.
296
+ * @returns {Promise<Binaries>} A promise that resolves to the binaries containing all circuit artifacts.
297
+ * @async
298
+ */
299
+ downloadArtifacts(version: VersionString): Promise<Binaries>;
300
+ /**
301
+ * Initializes the artifacts for the specified version of circuits.
302
+ * @param {VersionString} version - The version of the artifacts to initialize.
303
+ * @returns {Promise<void>} A promise that resolves when initialization is complete.
304
+ * @async
305
+ */
306
+ initArtifacts(version: VersionString): Promise<void>;
307
+ /**
308
+ * Retrieves the verification key for a specified circuit.
309
+ * @param {CircuitNameString} circuitName - The name of the circuit.
310
+ * @param {VersionString} [version] - The version of the artifacts (defaults to the latest).
311
+ * @returns {Promise<Uint8Array>} A promise that resolves to the verification key.
312
+ * @async
313
+ */
314
+ getVerificationKey(circuitName: CircuitNameString, version?: VersionString): Promise<Uint8Array>;
315
+ /**
316
+ * Retrieves the proving key for a specified circuit.
317
+ * @param {CircuitNameString} circuitName - The name of the circuit.
318
+ * @param {VersionString} [version] - The version of the artifacts (defaults to the latest).
319
+ * @returns {Promise<Uint8Array>} A promise that resolves to the proving key.
320
+ * @async
321
+ */
322
+ getProvingKey(circuitName: CircuitNameString, version?: VersionString): Promise<Uint8Array>;
323
+ /**
324
+ * Retrieves the wasm file for a specified circuit.
325
+ * @param {CircuitNameString} circuitName - The name of the circuit.
326
+ * @param {VersionString} [version] - The version of the artifacts (defaults to the latest).
327
+ * @returns {Promise<Uint8Array>} A promise that resolves to the wasm file.
328
+ * @async
329
+ */
330
+ getWasm(circuitName: CircuitNameString, version?: VersionString): Promise<Uint8Array>;
331
+ }
332
+
333
+ interface CircuitOptions {
334
+ baseUrl?: string;
335
+ browser?: boolean;
336
+ }
337
+ /**
338
+ * Class representing circuit management and artifact handling.
339
+ * Implements the CircuitsInterface.
340
+ */
341
+ declare class Circuits implements CircuitsInterface$1 {
342
+ /**
343
+ * Indicates whether the circuits have been initialized.
344
+ * @type {boolean}
345
+ * @protected
346
+ */
347
+ protected initialized: boolean;
348
+ /**
349
+ * The version of the circuit artifacts being used.
350
+ * @type {VersionString}
351
+ * @protected
352
+ */
353
+ protected version: VersionString;
354
+ /**
355
+ * The binaries containing circuit artifacts such as wasm, vkey, and zkey files.
356
+ * @type {Binaries}
357
+ * @protected
358
+ */
359
+ protected binaries: Binaries;
360
+ /**
361
+ * The base URL for fetching circuit artifacts.
362
+ * @type {string}
363
+ * @protected
364
+ */
365
+ protected baseUrl: string;
366
+ protected readonly browser: boolean;
367
+ /**
368
+ * Constructor to initialize the Circuits class with an optional custom base URL.
369
+ * @param {string} [options.baseUrl] - The base URL for fetching circuit artifacts (optional).
370
+ * @param {boolean} [options.browser] - Controls how the circuits will be loaded, using either `fetch` if true or `fs` otherwise. Defaults to true.
371
+ */
372
+ constructor(options?: CircuitOptions);
373
+ /**
374
+ * Determines whether the environment is a browser.
375
+ * @returns {boolean} True if running in a browser environment, false otherwise.
376
+ * @protected
377
+ */
378
+ _browser(): boolean;
379
+ /**
380
+ * Initializes the circuit manager with binaries and a version.
381
+ * @param {Binaries} binaries - The binaries containing circuit artifacts.
382
+ * @param {VersionString} version - The version of the circuit artifacts.
383
+ * @protected
384
+ */
385
+ protected _initialize(binaries: Binaries, version: VersionString): void;
386
+ /**
387
+ * Handles initialization of circuit artifacts, fetching them if necessary.
388
+ * @param {VersionString} [version=Version.latest] - The version of the circuit artifacts.
389
+ * @throws {CircuitInitialization} If an error occurs during initialization.
390
+ * @protected
391
+ * @async
392
+ */
393
+ protected _handleInitialization(version?: VersionString): Promise<void>;
394
+ /**
395
+ * Fetches a versioned artifact from a given path.
396
+ * @param {string} artifactPath - The path to the artifact.
397
+ * @param {VersionString} version - The version of the artifact.
398
+ * @returns {Promise<Uint8Array>} A promise that resolves to the artifact as a Uint8Array.
399
+ * @throws {FetchArtifact} If the artifact cannot be fetched.
400
+ * @protected
401
+ * @async
402
+ */
403
+ _fetchVersionedArtifact(artifactPath: string): Promise<Uint8Array>;
404
+ /**
405
+ * Downloads and returns the circuit artifacts for a specific circuit.
406
+ * @param {CircuitNameString} circuitName - The name of the circuit.
407
+ * @returns {Promise<CircuitArtifacts>} A promise that resolves to the circuit artifacts.
408
+ * @protected
409
+ * @async
410
+ */
411
+ _downloadCircuitArtifacts(circuitName: CircuitNameString): Promise<CircuitArtifacts>;
412
+ /**
413
+ * Downloads all circuit artifacts for the specified version.
414
+ * @param {VersionString} version - The version of the artifacts.
415
+ * @returns {Promise<Binaries>} A promise that resolves to the binaries containing all circuit artifacts.
416
+ * @async
417
+ */
418
+ downloadArtifacts(version: VersionString): Promise<Binaries>;
419
+ /**
420
+ * Initializes the circuit artifacts for the specified version.
421
+ * @param {VersionString} version - The version of the artifacts.
422
+ * @returns {Promise<void>} A promise that resolves when initialization is complete.
423
+ * @async
424
+ */
425
+ initArtifacts(version: VersionString): Promise<void>;
426
+ /**
427
+ * Retrieves the verification key for a specified circuit.
428
+ * @param {CircuitNameString} circuitName - The name of the circuit.
429
+ * @param {VersionString} [version=Version.latest] - The version of the artifacts.
430
+ * @returns {Promise<Uint8Array>} A promise that resolves to the verification key.
431
+ * @async
432
+ */
433
+ getVerificationKey(circuitName: CircuitNameString, version?: VersionString): Promise<Uint8Array>;
434
+ /**
435
+ * Retrieves the proving key for a specified circuit.
436
+ * @param {CircuitNameString} circuitName - The name of the circuit.
437
+ * @param {VersionString} [version=Version.latest] - The version of the artifacts.
438
+ * @returns {Promise<Uint8Array>} A promise that resolves to the proving key.
439
+ * @async
440
+ */
441
+ getProvingKey(circuitName: CircuitNameString, version?: VersionString): Promise<Uint8Array>;
442
+ /**
443
+ * Retrieves the wasm file for a specified circuit.
444
+ * @param {CircuitNameString} circuitName - The name of the circuit.
445
+ * @param {VersionString} [version=Version.latest] - The version of the artifacts.
446
+ * @returns {Promise<Uint8Array>} A promise that resolves to the wasm file.
447
+ * @async
448
+ */
449
+ getWasm(circuitName: CircuitNameString, version?: VersionString): Promise<Uint8Array>;
450
+ }
451
+
452
+ interface AssetConfig {
453
+ pool: Address;
454
+ minimumDepositAmount: bigint;
455
+ vettingFeeBPS: bigint;
456
+ maxRelayFeeBPS: bigint;
457
+ }
458
+ interface TransactionResponse {
459
+ hash: string;
460
+ wait: () => Promise<void>;
461
+ }
462
+ interface ContractInteractions {
463
+ depositERC20(asset: Address, amount: bigint, precommitment: bigint): Promise<TransactionResponse>;
464
+ depositETH(amount: bigint, precommitment: bigint): Promise<TransactionResponse>;
465
+ withdraw(withdrawal: Withdrawal, withdrawalProof: WithdrawalProof, scope: Hash): Promise<TransactionResponse>;
466
+ relay(withdrawal: Withdrawal, withdrawalProof: WithdrawalProof, scope: Hash): Promise<TransactionResponse>;
467
+ ragequit(commitmentProof: CommitmentProof, privacyPoolAddress: Address): Promise<TransactionResponse>;
468
+ getScope(privacyPoolAddress: Address): Promise<bigint>;
469
+ getStateRoot(privacyPoolAddress: Address): Promise<bigint>;
470
+ getStateSize(privacyPoolAddress: Address): Promise<bigint>;
471
+ getAssetConfig(assetAddress: Address): Promise<AssetConfig>;
472
+ getScopeData(scope: bigint): Promise<{
473
+ poolAddress: Address | null;
474
+ assetAddress: Address | null;
475
+ }>;
476
+ approveERC20(spenderAddress: Address, tokenAddress: Address, amount: bigint): Promise<TransactionResponse>;
477
+ }
478
+
479
+ declare class ContractInteractionsService implements ContractInteractions {
480
+ private publicClient;
481
+ private walletClient;
482
+ private entrypointAddress;
483
+ private account;
484
+ /**
485
+ * Initializes the contract interactions service.
486
+ *
487
+ * @param rpcUrl - The RPC endpoint URL for the blockchain network.
488
+ * @param chain - The blockchain network configuration.
489
+ * @param entrypointAddress - The address of the entrypoint contract.
490
+ * @param accountPrivateKey - The private key used for signing transactions.
491
+ */
492
+ constructor(rpcUrl: string, chain: Chain, entrypointAddress: Address, accountPrivateKey: Hex);
493
+ /**
494
+ * Deposits ERC20 tokens into the privacy pool.
495
+ *
496
+ * @param asset - The address of the ERC20 token.
497
+ * @param amount - The amount of tokens to deposit.
498
+ * @param precommitment - The precommitment value.
499
+ * @returns Transaction response containing the transaction hash.
500
+ */
501
+ depositERC20(asset: Address, amount: bigint, precommitment: bigint): Promise<TransactionResponse>;
502
+ /**
503
+ * Deposits ETH into the privacy pool.
504
+ *
505
+ * @param amount - The amount of ETH to deposit.
506
+ * @param precommitment - The precommitment value.
507
+ * @returns Transaction response containing the transaction hash.
508
+ */
509
+ depositETH(amount: bigint, precommitment: bigint): Promise<TransactionResponse>;
510
+ /**
511
+ * Withdraws funds from the privacy pool.
512
+ *
513
+ * @param withdrawal - The withdrawal object containing recipient details and amount.
514
+ * @param withdrawalProof - The cryptographic proof verifying the withdrawal.
515
+ * @returns Transaction response containing the transaction hash.
516
+ */
517
+ withdraw(withdrawal: Withdrawal, withdrawalProof: WithdrawalProof, scope: Hash): Promise<TransactionResponse>;
518
+ /**
519
+ * Relays a withdrawal transaction to the entrypoint contract.
520
+ * This function is used to facilitate relayer transactions.
521
+ *
522
+ * @param withdrawal - The withdrawal data structure.
523
+ * @param withdrawalProof - The cryptographic proof required for withdrawal.
524
+ * @returns Transaction response containing hash and wait function.
525
+ */
526
+ relay(withdrawal: Withdrawal, withdrawalProof: WithdrawalProof, scope: Hash): Promise<TransactionResponse>;
527
+ /**
528
+ * Executes a ragequit operation, allowing a user to exit the pool
529
+ * by nullifying their commitment and proving their withdrawal.
530
+ *
531
+ * @param commitmentProof - The cryptographic proof of the commitment.
532
+ * @param privacyPoolAddress - The address of the privacy pool contract.
533
+ * @returns Transaction response containing hash and wait function.
534
+ */
535
+ ragequit(commitmentProof: CommitmentProof, privacyPoolAddress: Address): Promise<TransactionResponse>;
536
+ /**
537
+ * Retrieves the scope identifier of a given privacy pool.
538
+ *
539
+ * @param privacyPoolAddress - The address of the privacy pool contract.
540
+ * @returns The scope identifier as a bigint.
541
+ */
542
+ getScope(privacyPoolAddress: Address): Promise<bigint>;
543
+ /**
544
+ * Retrieves the latest state root of the privacy pool from the entrypoint contract.
545
+ *
546
+ * @param privacyPoolAddress - The address of the privacy pool contract.
547
+ * @returns The latest state root as a bigint.
548
+ */
549
+ getStateRoot(privacyPoolAddress: Address): Promise<bigint>;
550
+ /**
551
+ * Retrieves the current state size of the privacy pool.
552
+ *
553
+ * @param privacyPoolAddress - The address of the privacy pool contract.
554
+ * @returns The size of the state tree as a bigint.
555
+ */
556
+ getStateSize(privacyPoolAddress: Address): Promise<bigint>;
557
+ /**
558
+ * Retrieves data from the corresponding asset
559
+ *
560
+ * @param assetAddress - The asset contract address.
561
+ * @returns AssetConfig - An object containing the privacy pool address, minimum deposit amount, vetting fee and maximum relaying fee.
562
+ * @throws ContractError if the asset does not exist in the pool.
563
+ */
564
+ getAssetConfig(assetAddress: Address): Promise<AssetConfig>;
565
+ /**
566
+ * Retrieves data about a specific scope, including the associated privacy pool
567
+ * and the asset used in that pool.
568
+ *
569
+ * @param scope - The scope identifier to look up.
570
+ * @returns An object containing the privacy pool address and asset address.
571
+ * @throws ContractError if the scope does not exist.
572
+ */
573
+ getScopeData(scope: bigint): Promise<{
574
+ poolAddress: Address;
575
+ assetAddress: Address;
576
+ }>;
577
+ /**
578
+ * Approves the entrypoint contract to spend a specified amount of ERC20 tokens.
579
+ *
580
+ * @param spenderAddress - The address of the entity that will be approved to spend tokens.
581
+ * @param tokenAddress - The address of the ERC20 token contract.
582
+ * @param amount - The amount of tokens to approve.
583
+ * @returns Transaction response containing hash and wait function.
584
+ */
585
+ approveERC20(spenderAddress: Address, tokenAddress: Address, amount: bigint): Promise<TransactionResponse>;
586
+ private formatProof;
587
+ private executeTransaction;
588
+ }
589
+
590
+ /**
591
+ * Available circuit types in the system.
592
+ */
593
+ declare enum CircuitName {
594
+ Commitment = "commitment",
595
+ Withdraw = "withdraw"
596
+ }
597
+ /**
598
+ * Type for circuit input signals.
599
+ */
600
+ type CircuitSignals = {
601
+ [key: string]: bigint | bigint[] | string;
602
+ };
603
+ /**
604
+ * Interface for accessing circuit-related resources.
605
+ */
606
+ interface CircuitsInterface {
607
+ /**
608
+ * Gets the WASM binary for a circuit.
609
+ */
610
+ getWasm(name: CircuitName): Promise<Uint8Array>;
611
+ /**
612
+ * Gets the proving key for a circuit.
613
+ */
614
+ getProvingKey(name: CircuitName): Promise<Uint8Array>;
615
+ /**
616
+ * Gets the verification key for a circuit.
617
+ */
618
+ getVerificationKey(name: CircuitName): Promise<Uint8Array>;
619
+ }
620
+
621
+ /**
622
+ * Represents a deposit event from a privacy pool
623
+ */
624
+ interface DepositEvent {
625
+ depositor: string;
626
+ commitment: Hash;
627
+ label: Hash;
628
+ value: bigint;
629
+ precommitment: Hash;
630
+ blockNumber: bigint;
631
+ transactionHash: Hex;
632
+ }
633
+ /**
634
+ * Represents a withdrawal event from a privacy pool
635
+ */
636
+ interface WithdrawalEvent {
637
+ withdrawn: bigint;
638
+ spentNullifier: Hash;
639
+ newCommitment: Hash;
640
+ blockNumber: bigint;
641
+ transactionHash: Hex;
642
+ }
643
+ /**
644
+ * Represents a ragequit event from a privacy pool
645
+ */
646
+ interface RagequitEvent {
647
+ ragequitter: string;
648
+ commitment: Hash;
649
+ label: Hash;
650
+ value: bigint;
651
+ blockNumber: bigint;
652
+ transactionHash: Hex;
653
+ }
654
+ /**
655
+ * Configuration for a chain's data provider
656
+ */
657
+ interface ChainConfig {
658
+ chainId: number;
659
+ privacyPoolAddress: Address;
660
+ startBlock: bigint;
661
+ rpcUrl: string;
662
+ }
663
+ /**
664
+ * Event filter options
665
+ */
666
+ interface EventFilterOptions {
667
+ fromBlock?: bigint;
668
+ toBlock?: bigint;
669
+ depositor?: string;
670
+ limit?: number;
671
+ skip?: number;
672
+ }
673
+ /**
674
+ * Collection of pool events
675
+ */
676
+ interface PoolEvents {
677
+ deposits: DepositEvent[];
678
+ withdrawals: WithdrawalEvent[];
679
+ }
680
+ interface PoolEventsSuccess {
681
+ depositEvents: Map<Hash, DepositEvent>;
682
+ withdrawalEvents: Map<Hash, WithdrawalEvent>;
683
+ ragequitEvents: Map<Hash, RagequitEvent>;
684
+ }
685
+ interface PoolEventsError {
686
+ reason: string;
687
+ scope: Hash;
688
+ }
689
+ type PoolEventsResult = Map<Hash, PoolEventsSuccess | PoolEventsError>;
690
+ type ProcessedDepositEventsResult = Map<Hash, DepositEvent>;
691
+
692
+ interface PoolAccount {
693
+ label: Hash;
694
+ deposit: AccountCommitment;
695
+ children: AccountCommitment[];
696
+ ragequit?: RagequitEvent;
697
+ }
698
+ interface AccountCommitment {
699
+ hash: Hash;
700
+ value: bigint;
701
+ label: Hash;
702
+ nullifier: Secret;
703
+ secret: Secret;
704
+ blockNumber: bigint;
705
+ timestamp?: bigint;
706
+ txHash: Hex;
707
+ }
708
+ interface PrivacyPoolAccount {
709
+ masterKeys: [masterNullifier: Secret, masterSecret: Secret];
710
+ poolAccounts: Map<Hash, PoolAccount[]>;
711
+ creationTimestamp?: bigint;
712
+ lastUpdateTimestamp?: bigint;
713
+ }
714
+ interface PoolInfo {
715
+ chainId: number;
716
+ address: Hex;
717
+ scope: Hash;
718
+ deploymentBlock: bigint;
719
+ }
720
+
721
+ /**
722
+ * Main SDK class providing access to all privacy pool functionality.
723
+ * Uses Poseidon hash for all commitment operations.
724
+ */
725
+ declare class PrivacyPoolSDK {
726
+ private readonly commitmentService;
727
+ private readonly withdrawalService;
728
+ constructor(circuits: CircuitsInterface);
729
+ createContractInstance(rpcUrl: string, chain: Chain, entrypointAddress: Address, privateKey: Hex): ContractInteractionsService;
730
+ /**
731
+ * Generates a commitment proof.
732
+ *
733
+ * @param value - Value to commit
734
+ * @param label - Label for the commitment
735
+ * @param nullifier - Nullifier for the commitment
736
+ * @param secret - Secret for the commitment
737
+ */
738
+ proveCommitment(value: bigint, label: bigint, nullifier: bigint, secret: bigint): Promise<CommitmentProof>;
739
+ /**
740
+ * Verifies a commitment proof.
741
+ *
742
+ * @param proof - The proof to verify
743
+ */
744
+ verifyCommitment(proof: CommitmentProof): Promise<boolean>;
745
+ /**
746
+ * Generates a withdrawal proof.
747
+ *
748
+ * @param commitment - Commitment to withdraw
749
+ * @param input - Input parameters for the withdrawal
750
+ * @param withdrawal - Withdrawal details
751
+ */
752
+ proveWithdrawal(commitment: Commitment | AccountCommitment, input: WithdrawalProofInput): Promise<WithdrawalProof>;
753
+ /**
754
+ * Verifies a withdrawal proof.
755
+ *
756
+ * @param withdrawalProof - The withdrawal payload to verify
757
+ */
758
+ verifyWithdrawal(withdrawalProof: WithdrawalProof): Promise<boolean>;
759
+ }
760
+
761
+ /**
762
+ * Unified error codes for the SDK.
763
+ */
764
+ declare enum ErrorCode {
765
+ UNKNOWN = "UNKNOWN",
766
+ INVALID_INPUT = "INVALID_INPUT",
767
+ OPERATION_FAILED = "OPERATION_FAILED",
768
+ NETWORK_ERROR = "NETWORK_ERROR",
769
+ PROOF_GENERATION_FAILED = "PROOF_GENERATION_FAILED",
770
+ PROOF_VERIFICATION_FAILED = "PROOF_VERIFICATION_FAILED",
771
+ INVALID_PROOF = "INVALID_PROOF",
772
+ INVALID_PUBLIC_SIGNALS = "INVALID_PUBLIC_SIGNALS",
773
+ CIRCUIT_ERROR = "CIRCUIT_ERROR",
774
+ CONTRACT_ERROR = "CONTRACT_ERROR",
775
+ CRYPTO_ERROR = "CRYPTO_ERROR",
776
+ MERKLE_ERROR = "MERKLE_ERROR"
777
+ }
778
+ /**
779
+ * Base error class for the SDK.
780
+ * All other error classes should extend this.
781
+ */
782
+ declare class SDKError extends Error {
783
+ readonly code: ErrorCode;
784
+ readonly details?: Record<string, unknown> | undefined;
785
+ constructor(message: string, code?: ErrorCode, details?: Record<string, unknown> | undefined);
786
+ /**
787
+ * Creates a JSON representation of the error.
788
+ */
789
+ toJSON(): Record<string, unknown>;
790
+ }
791
+ /**
792
+ * Specialized error class for proof-related operations.
793
+ */
794
+ declare class ProofError extends SDKError {
795
+ constructor(message: string, code?: ErrorCode, details?: Record<string, unknown>);
796
+ /**
797
+ * Creates an error for proof generation failures.
798
+ */
799
+ static generationFailed(details?: Record<string, unknown>): ProofError;
800
+ /**
801
+ * Creates an error for proof verification failures.
802
+ */
803
+ static verificationFailed(details?: Record<string, unknown>): ProofError;
804
+ /**
805
+ * Creates an error for invalid proof format.
806
+ */
807
+ static invalidProof(details?: Record<string, unknown>): ProofError;
808
+ }
809
+ declare class ContractError extends SDKError {
810
+ constructor(message: string, code?: ErrorCode, details?: Record<string, unknown>);
811
+ static scopeNotFound(scope: bigint): ContractError;
812
+ static assetNotFound(address: string): ContractError;
813
+ }
814
+
815
+ declare class AccountError extends SDKError {
816
+ constructor(message: string, code?: ErrorCode, details?: Record<string, unknown>);
817
+ static commitmentNotFound(hash: Hash | string): AccountError;
818
+ static invalidPoolAccount(): AccountError;
819
+ static accountInitializationFailed(reason: string): AccountError;
820
+ static duplicatePools(scope: bigint): AccountError;
821
+ static invalidIndex(index: bigint): AccountError;
822
+ }
823
+
824
+ /**
825
+ * Service responsible for handling commitment-related operations.
826
+ * All hash operations use Poseidon for ZK-friendly hashing.
827
+ */
828
+ declare class CommitmentService {
829
+ private readonly circuits;
830
+ constructor(circuits: CircuitsInterface);
831
+ /**
832
+ * Generates a zero-knowledge proof for a commitment using Poseidon hash.
833
+ *
834
+ * @param value - The value being committed to
835
+ * @param label - Label associated with the commitment
836
+ * @param nullifier - Unique nullifier for the commitment
837
+ * @param secret - Secret key for the commitment
838
+ * @returns Promise resolving to proof and public signals
839
+ * @throws {ProofError} If proof generation fails
840
+ */
841
+ proveCommitment(value: bigint, label: bigint, nullifier: bigint, secret: bigint): Promise<CommitmentProof>;
842
+ /**
843
+ * Verifies a commitment proof.
844
+ *
845
+ * @param proof - The commitment proof to verify
846
+ * @param publicSignals - Public signals associated with the proof
847
+ * @returns Promise resolving to boolean indicating proof validity
848
+ * @throws {ProofError} If verification fails
849
+ */
850
+ verifyCommitment({ proof, publicSignals, }: CommitmentProof): Promise<boolean>;
851
+ }
852
+
853
+ /**
854
+ * Service responsible for handling withdrawal-related operations.
855
+ */
856
+ declare class WithdrawalService {
857
+ private readonly circuits;
858
+ constructor(circuits: CircuitsInterface);
859
+ /**
860
+ * Generates a withdrawal proof.
861
+ *
862
+ * @param commitment - Commitment to withdraw
863
+ * @param input - Input parameters for the withdrawal
864
+ * @param withdrawal - Withdrawal details
865
+ * @returns Promise resolving to withdrawal payload
866
+ * @throws {ProofError} If proof generation fails
867
+ */
868
+ proveWithdrawal(commitment: Commitment | AccountCommitment, input: WithdrawalProofInput): Promise<WithdrawalProof>;
869
+ /**
870
+ * Verifies a withdrawal proof.
871
+ *
872
+ * @param withdrawalPayload - The withdrawal payload to verify
873
+ * @returns Promise resolving to boolean indicating proof validity
874
+ * @throws {ProofError} If verification fails
875
+ */
876
+ verifyWithdrawal(withdrawalPayload: WithdrawalProof): Promise<boolean>;
877
+ /**
878
+ * Prepares input signals for the withdrawal circuit.
879
+ */
880
+ private prepareInputSignals;
881
+ }
882
+
883
+ /**
884
+ * Service responsible for fetching and managing privacy pool events across multiple chains.
885
+ * Handles event retrieval, parsing, and validation for deposits, withdrawals, and ragequits.
886
+ *
887
+ * @remarks
888
+ * This service uses viem's PublicClient to efficiently fetch and process blockchain events.
889
+ * It supports multiple chains and provides robust error handling and validation.
890
+ * All uint256 values from events are handled as bigints, with Hash type assertions for commitment-related fields.
891
+ */
892
+ declare class DataService {
893
+ private readonly chainConfigs;
894
+ private readonly clients;
895
+ private readonly logger;
896
+ private readonly logFetchConfigs;
897
+ /**
898
+ * Initialize the data service with chain configurations
899
+ *
900
+ * @param chainConfigs - Array of chain configurations containing chainId, RPC URL, and API key
901
+ * @param logFetchConfig - Per-chain configuration for rate-limited log fetching as a Map<chainId, config>.
902
+ * Each chain can have its own specific settings (e.g., different block chunk sizes).
903
+ * @throws {DataError} If client initialization fails for any chain
904
+ */
905
+ constructor(chainConfigs: ChainConfig[], logFetchConfig?: ChainLogFetchConfig);
906
+ /**
907
+ * Get deposit events for a specific chain
908
+ *
909
+ * @param pool - Pool info containing chainId, address, and deployment block
910
+ * @returns Array of deposit events with properly typed fields (bigint for numbers, Hash for commitments)
911
+ * @throws {DataError} If client is not configured, network error occurs, or event data is invalid
912
+ */
913
+ getDeposits(pool: PoolInfo): Promise<DepositEvent[]>;
914
+ /**
915
+ * Get withdrawal events for a specific chain
916
+ *
917
+ * @param pool - Pool info containing chainId, address, and deployment block
918
+ * @param fromBlock - Optional starting block (defaults to pool deployment block)
919
+ * @returns Array of withdrawal events with properly typed fields (bigint for numbers, Hash for commitments)
920
+ * @throws {DataError} If client is not configured, network error occurs, or event data is invalid
921
+ */
922
+ getWithdrawals(pool: PoolInfo, fromBlock?: bigint): Promise<WithdrawalEvent[]>;
923
+ /**
924
+ * Get ragequit events for a specific chain
925
+ *
926
+ * @param pool - Pool info containing chainId, address, and deployment block
927
+ * @param fromBlock - Optional starting block (defaults to pool deployment block)
928
+ * @returns Array of ragequit events with properly typed fields (bigint for numbers, Hash for commitments)
929
+ * @throws {DataError} If client is not configured, network error occurs, or event data is invalid
930
+ */
931
+ getRagequits(pool: PoolInfo, fromBlock?: bigint): Promise<RagequitEvent[]>;
932
+ /**
933
+ * Gets the current block number for a chain
934
+ */
935
+ private getCurrentBlock;
936
+ /**
937
+ * Generates block ranges for chunked fetching
938
+ */
939
+ private generateBlockRanges;
940
+ /**
941
+ * Fetches logs for a single block range with retry logic
942
+ */
943
+ private fetchLogsWithRetry;
944
+ /**
945
+ * Helper to add delay between requests
946
+ */
947
+ private sleep;
948
+ private getClientForChain;
949
+ private getConfigForChain;
950
+ private getLogFetchConfigForChain;
951
+ }
952
+
953
+ type AccountServiceConfig = {
954
+ mnemonic: string;
955
+ poolConcurrency?: number;
956
+ } | {
957
+ account: PrivacyPoolAccount;
958
+ poolConcurrency?: number;
959
+ };
960
+ /**
961
+ * Service responsible for managing privacy pool accounts and their associated commitments.
962
+ * Handles account initialization, deposit/withdrawal tracking, and history synchronization.
963
+ *
964
+ * @remarks
965
+ * This service maintains the state of all pool accounts and their commitments across different
966
+ * chains and scopes. It uses deterministic key generation to recover account state from a mnemonic.
967
+ */
968
+ declare class AccountService {
969
+ private readonly dataService;
970
+ account: PrivacyPoolAccount;
971
+ private readonly logger;
972
+ private readonly poolConcurrency;
973
+ /**
974
+ * Creates a new AccountService instance.
975
+ *
976
+ * @param dataService - Service for fetching on-chain events
977
+ * @param config - Configuration for the account service (either mnemonic or existing account)
978
+ * @param config.mnemonic - Optional mnemonic for deterministic key generation
979
+ * @param config.account - Optional existing account to initialize with
980
+ * @param config.poolConcurrency - Optional maximum number of pools to fetch events for concurrently (default: 2)
981
+ *
982
+ * @throws {AccountError} If account initialization fails
983
+ */
984
+ constructor(dataService: DataService, config: AccountServiceConfig);
985
+ /**
986
+ * Initializes a new account from a mnemonic phrase.
987
+ *
988
+ * @param mnemonic - The mnemonic phrase to derive keys from
989
+ * @returns A new PrivacyPoolAccount with derived master keys
990
+ *
991
+ * @remarks
992
+ * This method derives two master keys from the mnemonic:
993
+ * 1. A master nullifier key from account index 0
994
+ * 2. A master secret key from account index 1
995
+ * These keys are used to deterministically generate nullifiers and secrets for deposits and withdrawals.
996
+ *
997
+ * @throws {AccountError} If account initialization fails
998
+ * @private
999
+ */
1000
+ private _initializeAccount;
1001
+ /**
1002
+ * Generates a deterministic nullifier for a deposit.
1003
+ *
1004
+ * @param scope - The scope of the pool
1005
+ * @param index - The index of the deposit
1006
+ * @returns A deterministic nullifier for the deposit
1007
+ * @private
1008
+ */
1009
+ private _genDepositNullifier;
1010
+ /**
1011
+ * Generates a deterministic secret for a deposit.
1012
+ *
1013
+ * @param scope - The scope of the pool
1014
+ * @param index - The index of the deposit
1015
+ * @returns A deterministic secret for the deposit
1016
+ * @private
1017
+ */
1018
+ private _genDepositSecret;
1019
+ /**
1020
+ * Generates a deterministic nullifier for a withdrawal.
1021
+ *
1022
+ * @param label - The label of the commitment
1023
+ * @param index - The index of the withdrawal
1024
+ * @returns A deterministic nullifier for the withdrawal
1025
+ * @private
1026
+ */
1027
+ private _genWithdrawalNullifier;
1028
+ /**
1029
+ * Generates a deterministic secret for a withdrawal.
1030
+ *
1031
+ * @param label - The label of the commitment
1032
+ * @param index - The index of the withdrawal
1033
+ * @returns A deterministic secret for the withdrawal
1034
+ * @private
1035
+ */
1036
+ private _genWithdrawalSecret;
1037
+ /**
1038
+ * Hashes a commitment using the Poseidon hash function.
1039
+ *
1040
+ * @param value - The value of the commitment
1041
+ * @param label - The label of the commitment
1042
+ * @param precommitment - The precommitment hash
1043
+ * @returns The commitment hash
1044
+ * @private
1045
+ */
1046
+ private _hashCommitment;
1047
+ /**
1048
+ * Hashes a precommitment using the Poseidon hash function.
1049
+ *
1050
+ * @param nullifier - The nullifier for the commitment
1051
+ * @param secret - The secret for the commitment
1052
+ * @returns The precommitment hash
1053
+ * @private
1054
+ */
1055
+ private _hashPrecommitment;
1056
+ /**
1057
+ * Gets all spendable commitments across all pools.
1058
+ *
1059
+ * @returns A map of scope to array of spendable commitments
1060
+ *
1061
+ * @remarks
1062
+ * A commitment is considered spendable if:
1063
+ * 1. It has a non-zero value
1064
+ * 2. The account it belongs to has not been ragequit
1065
+ */
1066
+ getSpendableCommitments(): Map<bigint, AccountCommitment[]>;
1067
+ /**
1068
+ * Creates nullifier and secret for a new deposit
1069
+ *
1070
+ * @param scope - The scope of the pool to deposit into
1071
+ * @param index - Optional index for deterministic generation
1072
+ * @returns The nullifier, secret, and precommitment for the deposit
1073
+ *
1074
+ * @remarks
1075
+ * If no index is provided, it uses the current number of accounts for the scope.
1076
+ * The precommitment is a hash of the nullifier and secret, used in the deposit process.
1077
+ */
1078
+ createDepositSecrets(scope: Hash, index?: bigint): {
1079
+ nullifier: Secret;
1080
+ secret: Secret;
1081
+ precommitment: Hash;
1082
+ };
1083
+ /**
1084
+ * Creates nullifier and secret for spending a commitment
1085
+ *
1086
+ * @param commitment - The commitment to spend
1087
+ * @returns The nullifier and secret for the new commitment
1088
+ *
1089
+ * @remarks
1090
+ * The index used for generating the withdrawal nullifier and secret is based on
1091
+ * the number of children the account already has, ensuring each withdrawal has
1092
+ * a unique nullifier.
1093
+ *
1094
+ * @throws {AccountError} If no account is found for the commitment
1095
+ */
1096
+ createWithdrawalSecrets(commitment: AccountCommitment): {
1097
+ nullifier: Secret;
1098
+ secret: Secret;
1099
+ };
1100
+ /**
1101
+ * Adds a new pool account after depositing
1102
+ *
1103
+ * @param scope - The scope of the pool
1104
+ * @param value - The deposit value
1105
+ * @param nullifier - The nullifier used for the deposit
1106
+ * @param secret - The secret used for the deposit
1107
+ * @param label - The label for the commitment
1108
+ * @param blockNumber - The block number of the deposit
1109
+ * @param txHash - The transaction hash of the deposit
1110
+ * @returns The new pool account
1111
+ *
1112
+ * @remarks
1113
+ * This method creates a new account with the deposit commitment and adds it to the
1114
+ * pool accounts map under the specified scope. The commitment hash is calculated
1115
+ * from the value, label, and precommitment.
1116
+ */
1117
+ addPoolAccount(scope: Hash, value: bigint, nullifier: Secret, secret: Secret, label: Hash, blockNumber: bigint, txHash: Hex): PoolAccount;
1118
+ /**
1119
+ * Adds a new commitment to the account after spending
1120
+ *
1121
+ * @param parentCommitment - The commitment that was spent
1122
+ * @param value - The remaining value after spending
1123
+ * @param nullifier - The nullifier used for spending
1124
+ * @param secret - The secret used for spending
1125
+ * @param blockNumber - The block number of the withdrawal
1126
+ * @param txHash - The transaction hash of the withdrawal
1127
+ * @returns The new commitment
1128
+ *
1129
+ * @remarks
1130
+ * This method finds the account containing the parent commitment, creates a new
1131
+ * commitment with the provided parameters, and adds it to the account's children.
1132
+ * The new commitment inherits the label from the parent commitment.
1133
+ *
1134
+ * @throws {AccountError} If no account is found for the commitment
1135
+ */
1136
+ addWithdrawalCommitment(parentCommitment: AccountCommitment, value: bigint, nullifier: Secret, secret: Secret, blockNumber: bigint, txHash: Hex): AccountCommitment;
1137
+ /**
1138
+ * Adds a ragequit event to an existing pool account
1139
+ *
1140
+ * @param label - The label of the account to add the ragequit to
1141
+ * @param ragequit - The ragequit event to add
1142
+ * @returns The updated pool account
1143
+ *
1144
+ * @remarks
1145
+ * When an account has a ragequit event, it can no longer be spent.
1146
+ * This method finds the account with the matching label and attaches
1147
+ * the ragequit event to it.
1148
+ *
1149
+ * @throws {AccountError} If no account is found with the given label
1150
+ */
1151
+ addRagequitToAccount(label: Hash, ragequit: RagequitEvent): PoolAccount;
1152
+ /**
1153
+ * Fetches deposit events for a given pool and returns a map of precommitments to their events for efficient lookup
1154
+ *
1155
+ * @param pool - The pool to fetch deposit events for
1156
+ *
1157
+ * @returns A map of precommitments to their events
1158
+ */
1159
+ getDepositEvents(pool: PoolInfo): Promise<Map<Hash, DepositEvent>>;
1160
+ /**
1161
+ * Fetches withdrawal events for a given pool and returns a map of spent nullifiers to their events for efficient lookup
1162
+ *
1163
+ * @param pool - The pool to fetch withdrawal events for
1164
+ *
1165
+ * @returns A map of spent nullifiers to their events
1166
+ */
1167
+ getWithdrawalEvents(pool: PoolInfo): Promise<Map<Hash, WithdrawalEvent>>;
1168
+ /**
1169
+ * Fetches ragequit events for a given pool and returns a map of ragequit labels to their events for efficient lookup
1170
+ *
1171
+ * @param pool - The pool to fetch ragequit events for
1172
+ *
1173
+ * @returns A map of ragequit labels to their events
1174
+ */
1175
+ getRagequitEvents(pool: PoolInfo): Promise<Map<Hash, RagequitEvent>>;
1176
+ /**
1177
+ * Fetches events for a given set of pools
1178
+ *
1179
+ * @param pools - The pools to fetch events for
1180
+ *
1181
+ * @returns A map of pool scopes to their events
1182
+ */
1183
+ getEvents(pools: PoolInfo[]): Promise<PoolEventsResult>;
1184
+ /**
1185
+ * Processes deposit events for a given scope and adds them to the account
1186
+ * Deterministically generate deposit secrets and check if they match on-chain deposits
1187
+ *
1188
+ * @param scope - The scope of the pool
1189
+ * @param depositEvents - The map of deposit events
1190
+ *
1191
+ */
1192
+ private _processDepositEvents;
1193
+ /**
1194
+ * Processes withdrawal events for a given scope and adds them to the account
1195
+ *
1196
+ * @param scope - The scope of the pool
1197
+ * @param withdrawalEvents - The map of withdrawal events
1198
+ *
1199
+ * @remarks
1200
+ * This method performs the following steps for each pool:
1201
+ * 1. Identifies the earliest deposit block for each scope
1202
+ * 2. For each account, reconstructs the withdrawal history by:
1203
+ * - Generating nullifiers sequentially
1204
+ * - Matching them against on-chain events
1205
+ * - Adding matched withdrawals to the account state
1206
+ *
1207
+ * @throws {DataError} If event fetching fails
1208
+ * @private
1209
+ *
1210
+ */
1211
+ private _processWithdrawalEvents;
1212
+ /**
1213
+ * Processes ragequit events for a given scope and adds them to the account
1214
+ *
1215
+ * @param scope - The scope of the pool
1216
+ * @param ragequitEvents - The map of ragequit events
1217
+ *
1218
+ * @remarks
1219
+ * This method performs the following steps for each pool:
1220
+ * 1. Adds ragequit events to accounts if found
1221
+ *
1222
+ * @throws {DataError} If event fetching fails
1223
+ * @private
1224
+ *
1225
+ */
1226
+ private _processRagequitEvents;
1227
+ /**
1228
+ * Initializes an AccountService instance with events for a given set of pools
1229
+ *
1230
+ * @param dataService - The data service to use for fetching events
1231
+ * @param source - The source to use for initializing the account. Either a mnemonic or an existing account service instance
1232
+ * @param pools - The pools to fetch events for
1233
+ *
1234
+ * @remarks
1235
+ * This method performs the following steps for each pool:
1236
+ * 1. Fetches deposit, withdrawal, and ragequit events for each pool
1237
+ * 2. Processes deposit events and creates pool accounts
1238
+ * 3. Processes withdrawal events and adds commitments to pool accounts
1239
+ * 4. Processes ragequit events and adds ragequit to pool accounts
1240
+ *
1241
+ * @returns The initialized AccountService instance and array of errors if any pool events fetching fails
1242
+ *
1243
+ * if any pool events fetching fails, the account will be initialized without the events for that pool
1244
+ * user can then call to this method again with the same account and missing pools to fetch the missing events
1245
+ *
1246
+ * @throws {AccountError} If account state reconstruction fails or if duplicate pools are found
1247
+ */
1248
+ static initializeWithEvents(dataService: DataService, source: {
1249
+ mnemonic: string;
1250
+ } | {
1251
+ service: AccountService;
1252
+ }, pools: PoolInfo[]): Promise<{
1253
+ account: AccountService;
1254
+ errors: PoolEventsError[];
1255
+ }>;
1256
+ /**
1257
+ * @deprecated Use `initializeWithEvents` for instantiating an account with history reconstruction
1258
+ * Retrieves the history of deposits and withdrawals for the given pools.
1259
+ *
1260
+ * @param pools - Array of pool configurations to sync history for
1261
+ *
1262
+ * @remarks
1263
+ * This method performs the following steps:
1264
+ * 1. Initializes pool accounts for each pool if they don't exist
1265
+ * 2. For each pool, fetches deposit events and reconstructs accounts
1266
+ * 3. Processes withdrawals and ragequits to update account state
1267
+ *
1268
+ * The account reconstruction is deterministic based on the master keys,
1269
+ * allowing the full state to be recovered from on-chain events.
1270
+ *
1271
+ * @throws {DataError} If event fetching fails
1272
+ * @throws {AccountError} If account state reconstruction fails
1273
+ */
1274
+ retrieveHistory(pools: PoolInfo[]): Promise<void>;
1275
+ /**
1276
+ * Processes withdrawal events for all pools and updates account state.
1277
+ *
1278
+ * @param pools - Array of pool configurations to process withdrawals for
1279
+ *
1280
+ * @remarks
1281
+ * This method performs the following steps for each pool:
1282
+ * 1. Identifies the earliest deposit block for each scope
1283
+ * 2. Fetches withdrawal and ragequit events from that block
1284
+ * 3. Maps withdrawals by nullifier hash and ragequits by label for efficient lookup
1285
+ * 4. For each account, reconstructs the withdrawal history by:
1286
+ * - Generating nullifiers sequentially
1287
+ * - Matching them against on-chain events
1288
+ * - Adding matched withdrawals to the account state
1289
+ * 5. Adds ragequit events to accounts if found
1290
+ *
1291
+ * @throws {DataError} If event fetching fails
1292
+ * @private
1293
+ */
1294
+ private _processWithdrawalsAndRagequits;
1295
+ /**
1296
+ * Logs a structured diagnostic summary of the current account state.
1297
+ * Only public, non-sensitive on-chain data is included.
1298
+ * Call this after initializeWithEvents to produce a full dump for investigation.
1299
+ */
1300
+ diagnosticSummary(): void;
1301
+ }
1302
+
1303
+ declare enum LogLevel {
1304
+ DEBUG = 0,
1305
+ INFO = 1,
1306
+ WARN = 2,
1307
+ ERROR = 3
1308
+ }
1309
+ interface LoggerOptions {
1310
+ level?: LogLevel;
1311
+ prefix?: string;
1312
+ enabled?: boolean;
1313
+ }
1314
+ declare class Logger {
1315
+ private level;
1316
+ private prefix;
1317
+ private enabled;
1318
+ constructor(options?: LoggerOptions);
1319
+ private formatMessage;
1320
+ debug(message: string, ...args: unknown[]): void;
1321
+ info(message: string, ...args: unknown[]): void;
1322
+ warn(message: string, ...args: unknown[]): void;
1323
+ error(message: string, error?: Error, ...args: unknown[]): void;
1324
+ }
1325
+
1326
+ export { type AccountCommitment, AccountError, AccountService, type BlockRange, BlockchainProvider, type ChainConfig, type ChainLogFetchConfig, CircuitName, type CircuitSignals, Circuits, type CircuitsInterface, type Commitment, type CommitmentPreimage, type CommitmentProof, CommitmentService, ContractError, ContractInteractionsService, DEFAULT_LOG_FETCH_CONFIG, DataService, type DepositEvent, ErrorCode, type EventFilterOptions, type Hash, type IBlockchainProvider, InvalidRpcUrl, type LogFetchConfig, LogLevel, Logger, type MasterKeys, type PoolAccount, type PoolEvents, type PoolEventsError, type PoolEventsResult, type PoolEventsSuccess, type PoolInfo, type Precommitment, type PrivacyPoolAccount, PrivacyPoolSDK, type ProcessedDepositEventsResult, ProofError, type RagequitEvent, SDKError, type Secret, type Withdrawal, type WithdrawalEvent, type WithdrawalProof, type WithdrawalProofInput, WithdrawalService, bigintToHash, bigintToHex, calculateContext, generateDepositSecrets, generateMasterKeys, generateMerkleProof, generateWithdrawalSecrets, getCommitment, hashPrecommitment };