@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,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,345 @@
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
+ } | {
9
+ account: PrivacyPoolAccount;
10
+ };
11
+ /**
12
+ * Service responsible for managing privacy pool accounts and their associated commitments.
13
+ * Handles account initialization, deposit/withdrawal tracking, and history synchronization.
14
+ *
15
+ * @remarks
16
+ * This service maintains the state of all pool accounts and their commitments across different
17
+ * chains and scopes. It uses deterministic key generation to recover account state from a mnemonic.
18
+ */
19
+ export declare class AccountService {
20
+ private readonly dataService;
21
+ account: PrivacyPoolAccount;
22
+ private readonly logger;
23
+ /**
24
+ * Creates a new AccountService instance.
25
+ *
26
+ * @param dataService - Service for fetching on-chain events
27
+ * @param config - Configuration for the account service (either mnemonic or existing account)
28
+ * @param config.mnemonic - Optional mnemonic for deterministic key generation
29
+ * @param config.account - Optional existing account to initialize with
30
+ *
31
+ * @throws {AccountError} If account initialization fails
32
+ */
33
+ constructor(dataService: DataService, config: AccountServiceConfig);
34
+ /**
35
+ * Initializes a new account from a mnemonic phrase.
36
+ *
37
+ * @param mnemonic - The mnemonic phrase to derive keys from
38
+ * @returns A new PrivacyPoolAccount with derived master keys
39
+ *
40
+ * @remarks
41
+ * This method derives two master keys from the mnemonic:
42
+ * 1. A master nullifier key from account index 0
43
+ * 2. A master secret key from account index 1
44
+ * These keys are used to deterministically generate nullifiers and secrets for deposits and withdrawals.
45
+ *
46
+ * @throws {AccountError} If account initialization fails
47
+ * @private
48
+ */
49
+ private _initializeAccount;
50
+ /**
51
+ * Generates a deterministic nullifier for a deposit.
52
+ *
53
+ * @param scope - The scope of the pool
54
+ * @param index - The index of the deposit
55
+ * @returns A deterministic nullifier for the deposit
56
+ * @private
57
+ */
58
+ private _genDepositNullifier;
59
+ /**
60
+ * Generates a deterministic secret for a deposit.
61
+ *
62
+ * @param scope - The scope of the pool
63
+ * @param index - The index of the deposit
64
+ * @returns A deterministic secret for the deposit
65
+ * @private
66
+ */
67
+ private _genDepositSecret;
68
+ /**
69
+ * Generates a deterministic nullifier for a withdrawal.
70
+ *
71
+ * @param label - The label of the commitment
72
+ * @param index - The index of the withdrawal
73
+ * @returns A deterministic nullifier for the withdrawal
74
+ * @private
75
+ */
76
+ private _genWithdrawalNullifier;
77
+ /**
78
+ * Generates a deterministic secret for a withdrawal.
79
+ *
80
+ * @param label - The label of the commitment
81
+ * @param index - The index of the withdrawal
82
+ * @returns A deterministic secret for the withdrawal
83
+ * @private
84
+ */
85
+ private _genWithdrawalSecret;
86
+ /**
87
+ * Hashes a commitment using the Poseidon hash function.
88
+ *
89
+ * @param value - The value of the commitment
90
+ * @param label - The label of the commitment
91
+ * @param precommitment - The precommitment hash
92
+ * @returns The commitment hash
93
+ * @private
94
+ */
95
+ private _hashCommitment;
96
+ /**
97
+ * Hashes a precommitment using the Poseidon hash function.
98
+ *
99
+ * @param nullifier - The nullifier for the commitment
100
+ * @param secret - The secret for the commitment
101
+ * @returns The precommitment hash
102
+ * @private
103
+ */
104
+ private _hashPrecommitment;
105
+ /**
106
+ * Gets all spendable commitments across all pools.
107
+ *
108
+ * @returns A map of scope to array of spendable commitments
109
+ *
110
+ * @remarks
111
+ * A commitment is considered spendable if:
112
+ * 1. It has a non-zero value
113
+ * 2. The account it belongs to has not been ragequit
114
+ */
115
+ getSpendableCommitments(): Map<bigint, AccountCommitment[]>;
116
+ /**
117
+ * Creates nullifier and secret for a new deposit
118
+ *
119
+ * @param scope - The scope of the pool to deposit into
120
+ * @param index - Optional index for deterministic generation
121
+ * @returns The nullifier, secret, and precommitment for the deposit
122
+ *
123
+ * @remarks
124
+ * If no index is provided, it uses the current number of accounts for the scope.
125
+ * The precommitment is a hash of the nullifier and secret, used in the deposit process.
126
+ */
127
+ createDepositSecrets(scope: Hash, index?: bigint): {
128
+ nullifier: Secret;
129
+ secret: Secret;
130
+ precommitment: Hash;
131
+ };
132
+ /**
133
+ * Creates nullifier and secret for spending a commitment
134
+ *
135
+ * @param commitment - The commitment to spend
136
+ * @returns The nullifier and secret for the new commitment
137
+ *
138
+ * @remarks
139
+ * The index used for generating the withdrawal nullifier and secret is based on
140
+ * the number of children the account already has, ensuring each withdrawal has
141
+ * a unique nullifier.
142
+ *
143
+ * @throws {AccountError} If no account is found for the commitment
144
+ */
145
+ createWithdrawalSecrets(commitment: AccountCommitment): {
146
+ nullifier: Secret;
147
+ secret: Secret;
148
+ };
149
+ /**
150
+ * Adds a new pool account after depositing
151
+ *
152
+ * @param scope - The scope of the pool
153
+ * @param value - The deposit value
154
+ * @param nullifier - The nullifier used for the deposit
155
+ * @param secret - The secret used for the deposit
156
+ * @param label - The label for the commitment
157
+ * @param blockNumber - The block number of the deposit
158
+ * @param txHash - The transaction hash of the deposit
159
+ * @returns The new pool account
160
+ *
161
+ * @remarks
162
+ * This method creates a new account with the deposit commitment and adds it to the
163
+ * pool accounts map under the specified scope. The commitment hash is calculated
164
+ * from the value, label, and precommitment.
165
+ */
166
+ addPoolAccount(scope: Hash, value: bigint, nullifier: Secret, secret: Secret, label: Hash, blockNumber: bigint, txHash: Hex): PoolAccount;
167
+ /**
168
+ * Adds a new commitment to the account after spending
169
+ *
170
+ * @param parentCommitment - The commitment that was spent
171
+ * @param value - The remaining value after spending
172
+ * @param nullifier - The nullifier used for spending
173
+ * @param secret - The secret used for spending
174
+ * @param blockNumber - The block number of the withdrawal
175
+ * @param txHash - The transaction hash of the withdrawal
176
+ * @returns The new commitment
177
+ *
178
+ * @remarks
179
+ * This method finds the account containing the parent commitment, creates a new
180
+ * commitment with the provided parameters, and adds it to the account's children.
181
+ * The new commitment inherits the label from the parent commitment.
182
+ *
183
+ * @throws {AccountError} If no account is found for the commitment
184
+ */
185
+ addWithdrawalCommitment(parentCommitment: AccountCommitment, value: bigint, nullifier: Secret, secret: Secret, blockNumber: bigint, txHash: Hex): AccountCommitment;
186
+ /**
187
+ * Adds a ragequit event to an existing pool account
188
+ *
189
+ * @param label - The label of the account to add the ragequit to
190
+ * @param ragequit - The ragequit event to add
191
+ * @returns The updated pool account
192
+ *
193
+ * @remarks
194
+ * When an account has a ragequit event, it can no longer be spent.
195
+ * This method finds the account with the matching label and attaches
196
+ * the ragequit event to it.
197
+ *
198
+ * @throws {AccountError} If no account is found with the given label
199
+ */
200
+ addRagequitToAccount(label: Hash, ragequit: RagequitEvent): PoolAccount;
201
+ /**
202
+ * Fetches deposit events for a given pool and returns a map of precommitments to their events for efficient lookup
203
+ *
204
+ * @param pool - The pool to fetch deposit events for
205
+ *
206
+ * @returns A map of precommitments to their events
207
+ */
208
+ getDepositEvents(pool: PoolInfo): Promise<Map<Hash, DepositEvent>>;
209
+ /**
210
+ * Fetches withdrawal events for a given pool and returns a map of spent nullifiers to their events for efficient lookup
211
+ *
212
+ * @param pool - The pool to fetch withdrawal events for
213
+ *
214
+ * @returns A map of spent nullifiers to their events
215
+ */
216
+ getWithdrawalEvents(pool: PoolInfo): Promise<Map<Hash, WithdrawalEvent>>;
217
+ /**
218
+ * Fetches ragequit events for a given pool and returns a map of ragequit labels to their events for efficient lookup
219
+ *
220
+ * @param pool - The pool to fetch ragequit events for
221
+ *
222
+ * @returns A map of ragequit labels to their events
223
+ */
224
+ getRagequitEvents(pool: PoolInfo): Promise<Map<Hash, RagequitEvent>>;
225
+ /**
226
+ * Fetches events for a given set of pools
227
+ *
228
+ * @param pools - The pools to fetch events for
229
+ *
230
+ * @returns A map of pool scopes to their events
231
+ */
232
+ getEvents(pools: PoolInfo[]): Promise<PoolEventsResult>;
233
+ /**
234
+ * Processes deposit events for a given scope and adds them to the account
235
+ * Deterministically generate deposit secrets and check if they match on-chain deposits
236
+ *
237
+ * @param scope - The scope of the pool
238
+ * @param depositEvents - The map of deposit events
239
+ *
240
+ */
241
+ private _processDepositEvents;
242
+ /**
243
+ * Processes withdrawal events for a given scope and adds them to the account
244
+ *
245
+ * @param scope - The scope of the pool
246
+ * @param withdrawalEvents - The map of withdrawal events
247
+ *
248
+ * @remarks
249
+ * This method performs the following steps for each pool:
250
+ * 1. Identifies the earliest deposit block for each scope
251
+ * 2. For each account, reconstructs the withdrawal history by:
252
+ * - Generating nullifiers sequentially
253
+ * - Matching them against on-chain events
254
+ * - Adding matched withdrawals to the account state
255
+ *
256
+ * @throws {DataError} If event fetching fails
257
+ * @private
258
+ *
259
+ */
260
+ private _processWithdrawalEvents;
261
+ /**
262
+ * Processes ragequit events for a given scope and adds them to the account
263
+ *
264
+ * @param scope - The scope of the pool
265
+ * @param ragequitEvents - The map of ragequit events
266
+ *
267
+ * @remarks
268
+ * This method performs the following steps for each pool:
269
+ * 1. Adds ragequit events to accounts if found
270
+ *
271
+ * @throws {DataError} If event fetching fails
272
+ * @private
273
+ *
274
+ */
275
+ private _processRagequitEvents;
276
+ /**
277
+ * Initializes an AccountService instance with events for a given set of pools
278
+ *
279
+ * @param dataService - The data service to use for fetching events
280
+ * @param source - The source to use for initializing the account. Either a mnemonic or an existing account service instance
281
+ * @param pools - The pools to fetch events for
282
+ *
283
+ * @remarks
284
+ * This method performs the following steps for each pool:
285
+ * 1. Fetches deposit, withdrawal, and ragequit events for each pool
286
+ * 2. Processes deposit events and creates pool accounts
287
+ * 3. Processes withdrawal events and adds commitments to pool accounts
288
+ * 4. Processes ragequit events and adds ragequit to pool accounts
289
+ *
290
+ * @returns The initialized AccountService instance and array of errors if any pool events fetching fails
291
+ *
292
+ * if any pool events fetching fails, the account will be initialized without the events for that pool
293
+ * user can then call to this method again with the same account and missing pools to fetch the missing events
294
+ *
295
+ * @throws {AccountError} If account state reconstruction fails or if duplicate pools are found
296
+ */
297
+ static initializeWithEvents(dataService: DataService, source: {
298
+ mnemonic: string;
299
+ } | {
300
+ service: AccountService;
301
+ }, pools: PoolInfo[]): Promise<{
302
+ account: AccountService;
303
+ errors: PoolEventsError[];
304
+ }>;
305
+ /**
306
+ * @deprecated Use `initializeWithEvents` for instantiating an account with history reconstruction
307
+ * Retrieves the history of deposits and withdrawals for the given pools.
308
+ *
309
+ * @param pools - Array of pool configurations to sync history for
310
+ *
311
+ * @remarks
312
+ * This method performs the following steps:
313
+ * 1. Initializes pool accounts for each pool if they don't exist
314
+ * 2. For each pool, fetches deposit events and reconstructs accounts
315
+ * 3. Processes withdrawals and ragequits to update account state
316
+ *
317
+ * The account reconstruction is deterministic based on the master keys,
318
+ * allowing the full state to be recovered from on-chain events.
319
+ *
320
+ * @throws {DataError} If event fetching fails
321
+ * @throws {AccountError} If account state reconstruction fails
322
+ */
323
+ retrieveHistory(pools: PoolInfo[]): Promise<void>;
324
+ /**
325
+ * Processes withdrawal events for all pools and updates account state.
326
+ *
327
+ * @param pools - Array of pool configurations to process withdrawals for
328
+ *
329
+ * @remarks
330
+ * This method performs the following steps for each pool:
331
+ * 1. Identifies the earliest deposit block for each scope
332
+ * 2. Fetches withdrawal and ragequit events from that block
333
+ * 3. Maps withdrawals by nullifier hash and ragequits by label for efficient lookup
334
+ * 4. For each account, reconstructs the withdrawal history by:
335
+ * - Generating nullifiers sequentially
336
+ * - Matching them against on-chain events
337
+ * - Adding matched withdrawals to the account state
338
+ * 5. Adds ragequit events to accounts if found
339
+ *
340
+ * @throws {DataError} If event fetching fails
341
+ * @private
342
+ */
343
+ private _processWithdrawalsAndRagequits;
344
+ }
345
+ export {};