@0xbow/privacy-pools-core-sdk 0.0.0-b21c14ba

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