@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,51 @@
1
+ export declare const IPrivacyPoolABI: ({
2
+ type: string;
3
+ name: string;
4
+ inputs: {
5
+ name: string;
6
+ type: string;
7
+ internalType: string;
8
+ }[];
9
+ outputs: {
10
+ name: string;
11
+ type: string;
12
+ internalType: string;
13
+ }[];
14
+ stateMutability: string;
15
+ anonymous?: undefined;
16
+ } | {
17
+ type: string;
18
+ name: string;
19
+ inputs: {
20
+ name: string;
21
+ type: string;
22
+ internalType: string;
23
+ components: {
24
+ name: string;
25
+ type: string;
26
+ internalType: string;
27
+ }[];
28
+ }[];
29
+ outputs: never[];
30
+ stateMutability: string;
31
+ anonymous?: undefined;
32
+ } | {
33
+ type: string;
34
+ name: string;
35
+ inputs: {
36
+ name: string;
37
+ type: string;
38
+ indexed: boolean;
39
+ internalType: string;
40
+ }[];
41
+ anonymous: boolean;
42
+ outputs?: undefined;
43
+ stateMutability?: undefined;
44
+ } | {
45
+ type: string;
46
+ name: string;
47
+ inputs: never[];
48
+ outputs?: undefined;
49
+ stateMutability?: undefined;
50
+ anonymous?: undefined;
51
+ })[];
@@ -0,0 +1,120 @@
1
+ import { Binaries, CircuitArtifacts, CircuitNameString, CircuitsInterface, VersionString } from "./circuits.interface.js";
2
+ interface CircuitOptions {
3
+ baseUrl?: string;
4
+ browser?: boolean;
5
+ }
6
+ /**
7
+ * Class representing circuit management and artifact handling.
8
+ * Implements the CircuitsInterface.
9
+ */
10
+ export declare class Circuits implements CircuitsInterface {
11
+ /**
12
+ * Indicates whether the circuits have been initialized.
13
+ * @type {boolean}
14
+ * @protected
15
+ */
16
+ protected initialized: boolean;
17
+ /**
18
+ * The version of the circuit artifacts being used.
19
+ * @type {VersionString}
20
+ * @protected
21
+ */
22
+ protected version: VersionString;
23
+ /**
24
+ * The binaries containing circuit artifacts such as wasm, vkey, and zkey files.
25
+ * @type {Binaries}
26
+ * @protected
27
+ */
28
+ protected binaries: Binaries;
29
+ /**
30
+ * The base URL for fetching circuit artifacts.
31
+ * @type {string}
32
+ * @protected
33
+ */
34
+ protected baseUrl: string;
35
+ protected readonly browser: boolean;
36
+ /**
37
+ * Constructor to initialize the Circuits class with an optional custom base URL.
38
+ * @param {string} [options.baseUrl] - The base URL for fetching circuit artifacts (optional).
39
+ * @param {boolean} [options.browser] - Controls how the circuits will be loaded, using either `fetch` if true or `fs` otherwise. Defaults to true.
40
+ */
41
+ constructor(options?: CircuitOptions);
42
+ /**
43
+ * Determines whether the environment is a browser.
44
+ * @returns {boolean} True if running in a browser environment, false otherwise.
45
+ * @protected
46
+ */
47
+ _browser(): boolean;
48
+ /**
49
+ * Initializes the circuit manager with binaries and a version.
50
+ * @param {Binaries} binaries - The binaries containing circuit artifacts.
51
+ * @param {VersionString} version - The version of the circuit artifacts.
52
+ * @protected
53
+ */
54
+ protected _initialize(binaries: Binaries, version: VersionString): void;
55
+ /**
56
+ * Handles initialization of circuit artifacts, fetching them if necessary.
57
+ * @param {VersionString} [version=Version.latest] - The version of the circuit artifacts.
58
+ * @throws {CircuitInitialization} If an error occurs during initialization.
59
+ * @protected
60
+ * @async
61
+ */
62
+ protected _handleInitialization(version?: VersionString): Promise<void>;
63
+ /**
64
+ * Fetches a versioned artifact from a given path.
65
+ * @param {string} artifactPath - The path to the artifact.
66
+ * @param {VersionString} version - The version of the artifact.
67
+ * @returns {Promise<Uint8Array>} A promise that resolves to the artifact as a Uint8Array.
68
+ * @throws {FetchArtifact} If the artifact cannot be fetched.
69
+ * @protected
70
+ * @async
71
+ */
72
+ _fetchVersionedArtifact(artifactPath: string): Promise<Uint8Array>;
73
+ /**
74
+ * Downloads and returns the circuit artifacts for a specific circuit.
75
+ * @param {CircuitNameString} circuitName - The name of the circuit.
76
+ * @returns {Promise<CircuitArtifacts>} A promise that resolves to the circuit artifacts.
77
+ * @protected
78
+ * @async
79
+ */
80
+ _downloadCircuitArtifacts(circuitName: CircuitNameString): Promise<CircuitArtifacts>;
81
+ /**
82
+ * Downloads all circuit artifacts for the specified version.
83
+ * @param {VersionString} version - The version of the artifacts.
84
+ * @returns {Promise<Binaries>} A promise that resolves to the binaries containing all circuit artifacts.
85
+ * @async
86
+ */
87
+ downloadArtifacts(version: VersionString): Promise<Binaries>;
88
+ /**
89
+ * Initializes the circuit artifacts for the specified version.
90
+ * @param {VersionString} version - The version of the artifacts.
91
+ * @returns {Promise<void>} A promise that resolves when initialization is complete.
92
+ * @async
93
+ */
94
+ initArtifacts(version: VersionString): Promise<void>;
95
+ /**
96
+ * Retrieves the verification key for a specified circuit.
97
+ * @param {CircuitNameString} circuitName - The name of the circuit.
98
+ * @param {VersionString} [version=Version.latest] - The version of the artifacts.
99
+ * @returns {Promise<Uint8Array>} A promise that resolves to the verification key.
100
+ * @async
101
+ */
102
+ getVerificationKey(circuitName: CircuitNameString, version?: VersionString): Promise<Uint8Array>;
103
+ /**
104
+ * Retrieves the proving key for a specified circuit.
105
+ * @param {CircuitNameString} circuitName - The name of the circuit.
106
+ * @param {VersionString} [version=Version.latest] - The version of the artifacts.
107
+ * @returns {Promise<Uint8Array>} A promise that resolves to the proving key.
108
+ * @async
109
+ */
110
+ getProvingKey(circuitName: CircuitNameString, version?: VersionString): Promise<Uint8Array>;
111
+ /**
112
+ * Retrieves the wasm file for a specified circuit.
113
+ * @param {CircuitNameString} circuitName - The name of the circuit.
114
+ * @param {VersionString} [version=Version.latest] - The version of the artifacts.
115
+ * @returns {Promise<Uint8Array>} A promise that resolves to the wasm file.
116
+ * @async
117
+ */
118
+ getWasm(circuitName: CircuitNameString, version?: VersionString): Promise<Uint8Array>;
119
+ }
120
+ export {};
@@ -0,0 +1,129 @@
1
+ /**
2
+ * Enum representing available versions of circuit artifacts.
3
+ */
4
+ export declare enum Version {
5
+ /**
6
+ * The latest version of the circuit artifacts.
7
+ */
8
+ Latest = "latest"
9
+ }
10
+ /**
11
+ * Type representing a version string, which is a string literal derived from the Version enum.
12
+ */
13
+ export type VersionString = `${Version}`;
14
+ /**
15
+ * Enum representing the names of available circuits.
16
+ */
17
+ export declare enum CircuitName {
18
+ /**
19
+ * Circuit for commitments.
20
+ */
21
+ Commitment = "commitment",
22
+ /**
23
+ * Circuit for Merkle tree operations.
24
+ */
25
+ MerkleTree = "merkleTree",
26
+ /**
27
+ * Circuit for withdrawal operations.
28
+ */
29
+ Withdraw = "withdraw"
30
+ }
31
+ /**
32
+ * Type representing a circuit name string, which is a string literal derived from the CircuitName enum.
33
+ */
34
+ export type CircuitNameString = `${CircuitName}`;
35
+ /**
36
+ * Interface representing the artifacts associated with a circuit.
37
+ */
38
+ export interface CircuitArtifacts {
39
+ /**
40
+ * The precompiled wasm file for the circuit.
41
+ * @type {Uint8Array}
42
+ */
43
+ wasm: Uint8Array;
44
+ /**
45
+ * The verification key for the circuit.
46
+ * @type {Uint8Array}
47
+ */
48
+ vkey: Uint8Array;
49
+ /**
50
+ * The proving key for the circuit.
51
+ * @type {Uint8Array}
52
+ */
53
+ zkey: Uint8Array;
54
+ }
55
+ /**
56
+ * Type representing the mapping of circuit names to their respective asset file paths.
57
+ */
58
+ export type Circ2Asset = {
59
+ [key in CircuitName]: {
60
+ /**
61
+ * The filename of the compiled wasm file.
62
+ */
63
+ wasm: string;
64
+ /**
65
+ * The filename of the verification key file.
66
+ */
67
+ vkey: string;
68
+ /**
69
+ * The filename of the proving key file.
70
+ */
71
+ zkey: string;
72
+ };
73
+ };
74
+ /**
75
+ * Mapping of circuit names to their respective asset file paths.
76
+ * @const
77
+ */
78
+ export declare const circuitToAsset: Circ2Asset;
79
+ /**
80
+ * Type representing the mapping of circuit name strings to their associated circuit artifacts.
81
+ */
82
+ export interface Binaries {
83
+ commitment: CircuitArtifacts;
84
+ withdraw: CircuitArtifacts;
85
+ merkleTree?: CircuitArtifacts;
86
+ }
87
+ /**
88
+ * Interface defining the methods required for managing circuits and their artifacts.
89
+ */
90
+ export interface CircuitsInterface {
91
+ /**
92
+ * Downloads all artifacts for the specified version of circuits.
93
+ * @param {VersionString} version - The version of the artifacts to download.
94
+ * @returns {Promise<Binaries>} A promise that resolves to the binaries containing all circuit artifacts.
95
+ * @async
96
+ */
97
+ downloadArtifacts(version: VersionString): Promise<Binaries>;
98
+ /**
99
+ * Initializes the artifacts for the specified version of circuits.
100
+ * @param {VersionString} version - The version of the artifacts to initialize.
101
+ * @returns {Promise<void>} A promise that resolves when initialization is complete.
102
+ * @async
103
+ */
104
+ initArtifacts(version: VersionString): Promise<void>;
105
+ /**
106
+ * Retrieves the verification key for a specified circuit.
107
+ * @param {CircuitNameString} circuitName - The name of the circuit.
108
+ * @param {VersionString} [version] - The version of the artifacts (defaults to the latest).
109
+ * @returns {Promise<Uint8Array>} A promise that resolves to the verification key.
110
+ * @async
111
+ */
112
+ getVerificationKey(circuitName: CircuitNameString, version?: VersionString): Promise<Uint8Array>;
113
+ /**
114
+ * Retrieves the proving key for a specified circuit.
115
+ * @param {CircuitNameString} circuitName - The name of the circuit.
116
+ * @param {VersionString} [version] - The version of the artifacts (defaults to the latest).
117
+ * @returns {Promise<Uint8Array>} A promise that resolves to the proving key.
118
+ * @async
119
+ */
120
+ getProvingKey(circuitName: CircuitNameString, version?: VersionString): Promise<Uint8Array>;
121
+ /**
122
+ * Retrieves the wasm file for a specified circuit.
123
+ * @param {CircuitNameString} circuitName - The name of the circuit.
124
+ * @param {VersionString} [version] - The version of the artifacts (defaults to the latest).
125
+ * @returns {Promise<Uint8Array>} A promise that resolves to the wasm file.
126
+ * @async
127
+ */
128
+ getWasm(circuitName: CircuitNameString, version?: VersionString): Promise<Uint8Array>;
129
+ }
@@ -0,0 +1 @@
1
+ export declare function importFetchVersionedArtifact(isBrowser: boolean): Promise<typeof import("./fetchArtifacts.esm.js")>;
@@ -0,0 +1 @@
1
+ export declare function fetchVersionedArtifact(artifactUrl: URL): Promise<Uint8Array>;
@@ -0,0 +1 @@
1
+ export declare function fetchVersionedArtifact(artifactUrl: URL): Promise<Uint8Array>;
@@ -0,0 +1,2 @@
1
+ export { Circuits } from "./circuits.impl.js";
2
+ export type { CircuitsInterface } from "./circuits.interface.js";
@@ -0,0 +1,2 @@
1
+ export declare const SNARK_SCALAR_FIELD_STRING = "21888242871839275222246405745257275088548364400416034343698204186575808495617";
2
+ export declare const SNARK_SCALAR_FIELD: bigint;
@@ -0,0 +1,355 @@
1
+ import { Hash, Secret } from "../types/commitment.js";
2
+ import { Hex } from "viem";
3
+ import { DataService } from "./data.service.js";
4
+ import { AccountCommitment, PoolAccount, PoolInfo, PrivacyPoolAccount } from "../types/account.js";
5
+ import { DepositEvent, PoolEventsError, PoolEventsResult, RagequitEvent, WithdrawalEvent } from "../types/events.js";
6
+ type AccountServiceConfig = {
7
+ mnemonic: string;
8
+ poolConcurrency?: number;
9
+ } | {
10
+ account: PrivacyPoolAccount;
11
+ poolConcurrency?: number;
12
+ };
13
+ /**
14
+ * Service responsible for managing privacy pool accounts and their associated commitments.
15
+ * Handles account initialization, deposit/withdrawal tracking, and history synchronization.
16
+ *
17
+ * @remarks
18
+ * This service maintains the state of all pool accounts and their commitments across different
19
+ * chains and scopes. It uses deterministic key generation to recover account state from a mnemonic.
20
+ */
21
+ export declare class AccountService {
22
+ private readonly dataService;
23
+ account: PrivacyPoolAccount;
24
+ private readonly logger;
25
+ private readonly poolConcurrency;
26
+ /**
27
+ * Creates a new AccountService instance.
28
+ *
29
+ * @param dataService - Service for fetching on-chain events
30
+ * @param config - Configuration for the account service (either mnemonic or existing account)
31
+ * @param config.mnemonic - Optional mnemonic for deterministic key generation
32
+ * @param config.account - Optional existing account to initialize with
33
+ * @param config.poolConcurrency - Optional maximum number of pools to fetch events for concurrently (default: 2)
34
+ *
35
+ * @throws {AccountError} If account initialization fails
36
+ */
37
+ constructor(dataService: DataService, config: AccountServiceConfig);
38
+ /**
39
+ * Initializes a new account from a mnemonic phrase.
40
+ *
41
+ * @param mnemonic - The mnemonic phrase to derive keys from
42
+ * @returns A new PrivacyPoolAccount with derived master keys
43
+ *
44
+ * @remarks
45
+ * This method derives two master keys from the mnemonic:
46
+ * 1. A master nullifier key from account index 0
47
+ * 2. A master secret key from account index 1
48
+ * These keys are used to deterministically generate nullifiers and secrets for deposits and withdrawals.
49
+ *
50
+ * @throws {AccountError} If account initialization fails
51
+ * @private
52
+ */
53
+ private _initializeAccount;
54
+ /**
55
+ * Generates a deterministic nullifier for a deposit.
56
+ *
57
+ * @param scope - The scope of the pool
58
+ * @param index - The index of the deposit
59
+ * @returns A deterministic nullifier for the deposit
60
+ * @private
61
+ */
62
+ private _genDepositNullifier;
63
+ /**
64
+ * Generates a deterministic secret for a deposit.
65
+ *
66
+ * @param scope - The scope of the pool
67
+ * @param index - The index of the deposit
68
+ * @returns A deterministic secret for the deposit
69
+ * @private
70
+ */
71
+ private _genDepositSecret;
72
+ /**
73
+ * Generates a deterministic nullifier for a withdrawal.
74
+ *
75
+ * @param label - The label of the commitment
76
+ * @param index - The index of the withdrawal
77
+ * @returns A deterministic nullifier for the withdrawal
78
+ * @private
79
+ */
80
+ private _genWithdrawalNullifier;
81
+ /**
82
+ * Generates a deterministic secret for a withdrawal.
83
+ *
84
+ * @param label - The label of the commitment
85
+ * @param index - The index of the withdrawal
86
+ * @returns A deterministic secret for the withdrawal
87
+ * @private
88
+ */
89
+ private _genWithdrawalSecret;
90
+ /**
91
+ * Hashes a commitment using the Poseidon hash function.
92
+ *
93
+ * @param value - The value of the commitment
94
+ * @param label - The label of the commitment
95
+ * @param precommitment - The precommitment hash
96
+ * @returns The commitment hash
97
+ * @private
98
+ */
99
+ private _hashCommitment;
100
+ /**
101
+ * Hashes a precommitment using the Poseidon hash function.
102
+ *
103
+ * @param nullifier - The nullifier for the commitment
104
+ * @param secret - The secret for the commitment
105
+ * @returns The precommitment hash
106
+ * @private
107
+ */
108
+ private _hashPrecommitment;
109
+ /**
110
+ * Gets all spendable commitments across all pools.
111
+ *
112
+ * @returns A map of scope to array of spendable commitments
113
+ *
114
+ * @remarks
115
+ * A commitment is considered spendable if:
116
+ * 1. It has a non-zero value
117
+ * 2. The account it belongs to has not been ragequit
118
+ */
119
+ getSpendableCommitments(): Map<bigint, AccountCommitment[]>;
120
+ /**
121
+ * Creates nullifier and secret for a new deposit
122
+ *
123
+ * @param scope - The scope of the pool to deposit into
124
+ * @param index - Optional index for deterministic generation
125
+ * @returns The nullifier, secret, and precommitment for the deposit
126
+ *
127
+ * @remarks
128
+ * If no index is provided, it uses the current number of accounts for the scope.
129
+ * The precommitment is a hash of the nullifier and secret, used in the deposit process.
130
+ */
131
+ createDepositSecrets(scope: Hash, index?: bigint): {
132
+ nullifier: Secret;
133
+ secret: Secret;
134
+ precommitment: Hash;
135
+ };
136
+ /**
137
+ * Creates nullifier and secret for spending a commitment
138
+ *
139
+ * @param commitment - The commitment to spend
140
+ * @returns The nullifier and secret for the new commitment
141
+ *
142
+ * @remarks
143
+ * The index used for generating the withdrawal nullifier and secret is based on
144
+ * the number of children the account already has, ensuring each withdrawal has
145
+ * a unique nullifier.
146
+ *
147
+ * @throws {AccountError} If no account is found for the commitment
148
+ */
149
+ createWithdrawalSecrets(commitment: AccountCommitment): {
150
+ nullifier: Secret;
151
+ secret: Secret;
152
+ };
153
+ /**
154
+ * Adds a new pool account after depositing
155
+ *
156
+ * @param scope - The scope of the pool
157
+ * @param value - The deposit value
158
+ * @param nullifier - The nullifier used for the deposit
159
+ * @param secret - The secret used for the deposit
160
+ * @param label - The label for the commitment
161
+ * @param blockNumber - The block number of the deposit
162
+ * @param txHash - The transaction hash of the deposit
163
+ * @returns The new pool account
164
+ *
165
+ * @remarks
166
+ * This method creates a new account with the deposit commitment and adds it to the
167
+ * pool accounts map under the specified scope. The commitment hash is calculated
168
+ * from the value, label, and precommitment.
169
+ */
170
+ addPoolAccount(scope: Hash, value: bigint, nullifier: Secret, secret: Secret, label: Hash, blockNumber: bigint, txHash: Hex): PoolAccount;
171
+ /**
172
+ * Adds a new commitment to the account after spending
173
+ *
174
+ * @param parentCommitment - The commitment that was spent
175
+ * @param value - The remaining value after spending
176
+ * @param nullifier - The nullifier used for spending
177
+ * @param secret - The secret used for spending
178
+ * @param blockNumber - The block number of the withdrawal
179
+ * @param txHash - The transaction hash of the withdrawal
180
+ * @returns The new commitment
181
+ *
182
+ * @remarks
183
+ * This method finds the account containing the parent commitment, creates a new
184
+ * commitment with the provided parameters, and adds it to the account's children.
185
+ * The new commitment inherits the label from the parent commitment.
186
+ *
187
+ * @throws {AccountError} If no account is found for the commitment
188
+ */
189
+ addWithdrawalCommitment(parentCommitment: AccountCommitment, value: bigint, nullifier: Secret, secret: Secret, blockNumber: bigint, txHash: Hex): AccountCommitment;
190
+ /**
191
+ * Adds a ragequit event to an existing pool account
192
+ *
193
+ * @param label - The label of the account to add the ragequit to
194
+ * @param ragequit - The ragequit event to add
195
+ * @returns The updated pool account
196
+ *
197
+ * @remarks
198
+ * When an account has a ragequit event, it can no longer be spent.
199
+ * This method finds the account with the matching label and attaches
200
+ * the ragequit event to it.
201
+ *
202
+ * @throws {AccountError} If no account is found with the given label
203
+ */
204
+ addRagequitToAccount(label: Hash, ragequit: RagequitEvent): PoolAccount;
205
+ /**
206
+ * Fetches deposit events for a given pool and returns a map of precommitments to their events for efficient lookup
207
+ *
208
+ * @param pool - The pool to fetch deposit events for
209
+ *
210
+ * @returns A map of precommitments to their events
211
+ */
212
+ getDepositEvents(pool: PoolInfo): Promise<Map<Hash, DepositEvent>>;
213
+ /**
214
+ * Fetches withdrawal events for a given pool and returns a map of spent nullifiers to their events for efficient lookup
215
+ *
216
+ * @param pool - The pool to fetch withdrawal events for
217
+ *
218
+ * @returns A map of spent nullifiers to their events
219
+ */
220
+ getWithdrawalEvents(pool: PoolInfo): Promise<Map<Hash, WithdrawalEvent>>;
221
+ /**
222
+ * Fetches ragequit events for a given pool and returns a map of ragequit labels to their events for efficient lookup
223
+ *
224
+ * @param pool - The pool to fetch ragequit events for
225
+ *
226
+ * @returns A map of ragequit labels to their events
227
+ */
228
+ getRagequitEvents(pool: PoolInfo): Promise<Map<Hash, RagequitEvent>>;
229
+ /**
230
+ * Fetches events for a given set of pools
231
+ *
232
+ * @param pools - The pools to fetch events for
233
+ *
234
+ * @returns A map of pool scopes to their events
235
+ */
236
+ getEvents(pools: PoolInfo[]): Promise<PoolEventsResult>;
237
+ /**
238
+ * Processes deposit events for a given scope and adds them to the account
239
+ * Deterministically generate deposit secrets and check if they match on-chain deposits
240
+ *
241
+ * @param scope - The scope of the pool
242
+ * @param depositEvents - The map of deposit events
243
+ *
244
+ */
245
+ private _processDepositEvents;
246
+ /**
247
+ * Processes withdrawal events for a given scope and adds them to the account
248
+ *
249
+ * @param scope - The scope of the pool
250
+ * @param withdrawalEvents - The map of withdrawal events
251
+ *
252
+ * @remarks
253
+ * This method performs the following steps for each pool:
254
+ * 1. Identifies the earliest deposit block for each scope
255
+ * 2. For each account, reconstructs the withdrawal history by:
256
+ * - Generating nullifiers sequentially
257
+ * - Matching them against on-chain events
258
+ * - Adding matched withdrawals to the account state
259
+ *
260
+ * @throws {DataError} If event fetching fails
261
+ * @private
262
+ *
263
+ */
264
+ private _processWithdrawalEvents;
265
+ /**
266
+ * Processes ragequit events for a given scope and adds them to the account
267
+ *
268
+ * @param scope - The scope of the pool
269
+ * @param ragequitEvents - The map of ragequit events
270
+ *
271
+ * @remarks
272
+ * This method performs the following steps for each pool:
273
+ * 1. Adds ragequit events to accounts if found
274
+ *
275
+ * @throws {DataError} If event fetching fails
276
+ * @private
277
+ *
278
+ */
279
+ private _processRagequitEvents;
280
+ /**
281
+ * Initializes an AccountService instance with events for a given set of pools
282
+ *
283
+ * @param dataService - The data service to use for fetching events
284
+ * @param source - The source to use for initializing the account. Either a mnemonic or an existing account service instance
285
+ * @param pools - The pools to fetch events for
286
+ *
287
+ * @remarks
288
+ * This method performs the following steps for each pool:
289
+ * 1. Fetches deposit, withdrawal, and ragequit events for each pool
290
+ * 2. Processes deposit events and creates pool accounts
291
+ * 3. Processes withdrawal events and adds commitments to pool accounts
292
+ * 4. Processes ragequit events and adds ragequit to pool accounts
293
+ *
294
+ * @returns The initialized AccountService instance and array of errors if any pool events fetching fails
295
+ *
296
+ * if any pool events fetching fails, the account will be initialized without the events for that pool
297
+ * user can then call to this method again with the same account and missing pools to fetch the missing events
298
+ *
299
+ * @throws {AccountError} If account state reconstruction fails or if duplicate pools are found
300
+ */
301
+ static initializeWithEvents(dataService: DataService, source: {
302
+ mnemonic: string;
303
+ } | {
304
+ service: AccountService;
305
+ }, pools: PoolInfo[]): Promise<{
306
+ account: AccountService;
307
+ errors: PoolEventsError[];
308
+ }>;
309
+ /**
310
+ * @deprecated Use `initializeWithEvents` for instantiating an account with history reconstruction
311
+ * Retrieves the history of deposits and withdrawals for the given pools.
312
+ *
313
+ * @param pools - Array of pool configurations to sync history for
314
+ *
315
+ * @remarks
316
+ * This method performs the following steps:
317
+ * 1. Initializes pool accounts for each pool if they don't exist
318
+ * 2. For each pool, fetches deposit events and reconstructs accounts
319
+ * 3. Processes withdrawals and ragequits to update account state
320
+ *
321
+ * The account reconstruction is deterministic based on the master keys,
322
+ * allowing the full state to be recovered from on-chain events.
323
+ *
324
+ * @throws {DataError} If event fetching fails
325
+ * @throws {AccountError} If account state reconstruction fails
326
+ */
327
+ retrieveHistory(pools: PoolInfo[]): Promise<void>;
328
+ /**
329
+ * Processes withdrawal events for all pools and updates account state.
330
+ *
331
+ * @param pools - Array of pool configurations to process withdrawals for
332
+ *
333
+ * @remarks
334
+ * This method performs the following steps for each pool:
335
+ * 1. Identifies the earliest deposit block for each scope
336
+ * 2. Fetches withdrawal and ragequit events from that block
337
+ * 3. Maps withdrawals by nullifier hash and ragequits by label for efficient lookup
338
+ * 4. For each account, reconstructs the withdrawal history by:
339
+ * - Generating nullifiers sequentially
340
+ * - Matching them against on-chain events
341
+ * - Adding matched withdrawals to the account state
342
+ * 5. Adds ragequit events to accounts if found
343
+ *
344
+ * @throws {DataError} If event fetching fails
345
+ * @private
346
+ */
347
+ private _processWithdrawalsAndRagequits;
348
+ /**
349
+ * Logs a structured diagnostic summary of the current account state.
350
+ * Only public, non-sensitive on-chain data is included.
351
+ * Call this after initializeWithEvents to produce a full dump for investigation.
352
+ */
353
+ diagnosticSummary(): void;
354
+ }
355
+ export {};