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

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 (97) hide show
  1. package/README.md +73 -0
  2. package/dist/esm/ccip-nJye9Itm.js +166 -0
  3. package/dist/esm/ccip-nJye9Itm.js.map +1 -0
  4. package/dist/esm/index-DAWUECi8.js +84043 -0
  5. package/dist/esm/index-DAWUECi8.js.map +1 -0
  6. package/dist/esm/index.mjs +4 -0
  7. package/dist/esm/index.mjs.map +1 -0
  8. package/dist/index.d.mts +666 -0
  9. package/dist/node/ccip-lPhPeJab.js +183 -0
  10. package/dist/node/ccip-lPhPeJab.js.map +1 -0
  11. package/dist/node/index-BiU5Ef8Z.js +90625 -0
  12. package/dist/node/index-BiU5Ef8Z.js.map +1 -0
  13. package/dist/node/index.mjs +21 -0
  14. package/dist/node/index.mjs.map +1 -0
  15. package/dist/types/abi/ERC20.d.ts +38 -0
  16. package/dist/types/abi/IEntrypoint.d.ts +794 -0
  17. package/dist/types/abi/IPrivacyPool.d.ts +51 -0
  18. package/dist/types/ccip-BZzz1Y5w.js +182 -0
  19. package/dist/types/circuits/circuits.impl.d.ts +108 -0
  20. package/dist/types/circuits/circuits.interface.d.ts +127 -0
  21. package/dist/types/circuits/index.d.ts +2 -0
  22. package/dist/types/constants.d.ts +2 -0
  23. package/dist/types/core/bruteForce.service.d.ts +61 -0
  24. package/dist/types/core/commitment.service.d.ts +30 -0
  25. package/dist/types/core/contracts.service.d.ts +106 -0
  26. package/dist/types/core/sdk.d.ts +44 -0
  27. package/dist/types/core/withdrawal.service.d.ts +32 -0
  28. package/dist/types/crypto.d.ts +45 -0
  29. package/dist/types/dirname.helper.d.ts +2 -0
  30. package/dist/types/errors/base.error.d.ts +52 -0
  31. package/dist/types/exceptions/circuitInitialization.exception.d.ts +3 -0
  32. package/dist/types/exceptions/fetchArtifacts.exception.d.ts +3 -0
  33. package/dist/types/exceptions/index.d.ts +4 -0
  34. package/dist/types/exceptions/invalidRpcUrl.exception.d.ts +3 -0
  35. package/dist/types/exceptions/privacyPool.exception.d.ts +13 -0
  36. package/dist/types/external.d.ts +7 -0
  37. package/dist/types/filename.helper.d.ts +2 -0
  38. package/dist/types/index-D-_1h8-n.js +90638 -0
  39. package/dist/types/index.d.ts +10 -0
  40. package/dist/types/index.js +20 -0
  41. package/dist/types/interfaces/blockchainProvider.interface.d.ts +12 -0
  42. package/dist/types/interfaces/circuits.interface.d.ts +30 -0
  43. package/dist/types/interfaces/contracts.interface.d.ts +28 -0
  44. package/dist/types/interfaces/index.d.ts +1 -0
  45. package/dist/types/internal.d.ts +6 -0
  46. package/dist/types/providers/blockchainProvider.d.ts +8 -0
  47. package/dist/types/providers/index.d.ts +1 -0
  48. package/dist/types/types/commitment.d.ts +48 -0
  49. package/dist/types/types/index.d.ts +2 -0
  50. package/dist/types/types/withdrawal.d.ts +30 -0
  51. package/package.json +81 -0
  52. package/src/abi/ERC20.ts +222 -0
  53. package/src/abi/IEntrypoint.ts +1059 -0
  54. package/src/abi/IPrivacyPool.ts +576 -0
  55. package/src/circuits/circuits.impl.ts +232 -0
  56. package/src/circuits/circuits.interface.ts +166 -0
  57. package/src/circuits/fetchArtifacts.esm.ts +12 -0
  58. package/src/circuits/fetchArtifacts.node.ts +23 -0
  59. package/src/circuits/fetchArtifacts.ts +7 -0
  60. package/src/circuits/index.ts +2 -0
  61. package/src/constants.ts +3 -0
  62. package/src/core/account.service.ts +1077 -0
  63. package/src/core/bruteForce.service.ts +120 -0
  64. package/src/core/commitment.service.ts +84 -0
  65. package/src/core/contracts.service.ts +442 -0
  66. package/src/core/data.service.ts +272 -0
  67. package/src/core/sdk.ts +92 -0
  68. package/src/core/withdrawal.service.ts +126 -0
  69. package/src/crypto.ts +226 -0
  70. package/src/dirname.helper.ts +4 -0
  71. package/src/errors/account.error.ts +49 -0
  72. package/src/errors/base.error.ts +125 -0
  73. package/src/errors/data.error.ts +34 -0
  74. package/src/errors/events.error.ts +38 -0
  75. package/src/exceptions/circuitInitialization.exception.ts +6 -0
  76. package/src/exceptions/fetchArtifacts.exception.ts +7 -0
  77. package/src/exceptions/index.ts +4 -0
  78. package/src/exceptions/invalidRpcUrl.exception.ts +6 -0
  79. package/src/exceptions/privacyPool.exception.ts +19 -0
  80. package/src/external.ts +13 -0
  81. package/src/filename.helper.ts +4 -0
  82. package/src/index.ts +21 -0
  83. package/src/interfaces/blockchainProvider.interface.ts +13 -0
  84. package/src/interfaces/circuits.interface.ts +34 -0
  85. package/src/interfaces/contracts.interface.ts +66 -0
  86. package/src/interfaces/index.ts +1 -0
  87. package/src/internal.ts +6 -0
  88. package/src/keys.ts +42 -0
  89. package/src/providers/blockchainProvider.ts +26 -0
  90. package/src/providers/index.ts +1 -0
  91. package/src/types/account.ts +35 -0
  92. package/src/types/commitment.ts +50 -0
  93. package/src/types/events.ts +82 -0
  94. package/src/types/index.ts +3 -0
  95. package/src/types/keys.ts +6 -0
  96. package/src/types/withdrawal.ts +33 -0
  97. 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,182 @@
1
+ import { B as BaseError, g as getUrl, s as stringify, d as decodeErrorResult, i as isAddressEqual, c as call, a as concat, e as encodeAbiParameters, H as HttpRequestError, b as isHex } from './index-D-_1h8-n.js';
2
+ import 'buffer';
3
+ import 'http';
4
+ import 'https';
5
+ import 'zlib';
6
+ import 'crypto';
7
+ import 'node:crypto';
8
+ import 'events';
9
+ import 'net';
10
+ import 'tls';
11
+ import 'stream';
12
+ import 'url';
13
+ import 'assert';
14
+ import 'os';
15
+ import 'vm';
16
+ import 'worker_threads';
17
+ import 'fs';
18
+ import 'constants';
19
+ import 'readline';
20
+ import 'path';
21
+
22
+ class OffchainLookupError extends BaseError {
23
+ constructor({ callbackSelector, cause, data, extraData, sender, urls, }) {
24
+ super(cause.shortMessage ||
25
+ 'An error occurred while fetching for an offchain result.', {
26
+ cause,
27
+ metaMessages: [
28
+ ...(cause.metaMessages || []),
29
+ cause.metaMessages?.length ? '' : [],
30
+ 'Offchain Gateway Call:',
31
+ urls && [
32
+ ' Gateway URL(s):',
33
+ ...urls.map((url) => ` ${getUrl(url)}`),
34
+ ],
35
+ ` Sender: ${sender}`,
36
+ ` Data: ${data}`,
37
+ ` Callback selector: ${callbackSelector}`,
38
+ ` Extra data: ${extraData}`,
39
+ ].flat(),
40
+ name: 'OffchainLookupError',
41
+ });
42
+ }
43
+ }
44
+ class OffchainLookupResponseMalformedError extends BaseError {
45
+ constructor({ result, url }) {
46
+ super('Offchain gateway response is malformed. Response data must be a hex value.', {
47
+ metaMessages: [
48
+ `Gateway URL: ${getUrl(url)}`,
49
+ `Response: ${stringify(result)}`,
50
+ ],
51
+ name: 'OffchainLookupResponseMalformedError',
52
+ });
53
+ }
54
+ }
55
+ class OffchainLookupSenderMismatchError extends BaseError {
56
+ constructor({ sender, to }) {
57
+ super('Reverted sender address does not match target contract address (`to`).', {
58
+ metaMessages: [
59
+ `Contract address: ${to}`,
60
+ `OffchainLookup sender address: ${sender}`,
61
+ ],
62
+ name: 'OffchainLookupSenderMismatchError',
63
+ });
64
+ }
65
+ }
66
+
67
+ const offchainLookupSignature = '0x556f1830';
68
+ const offchainLookupAbiItem = {
69
+ name: 'OffchainLookup',
70
+ type: 'error',
71
+ inputs: [
72
+ {
73
+ name: 'sender',
74
+ type: 'address',
75
+ },
76
+ {
77
+ name: 'urls',
78
+ type: 'string[]',
79
+ },
80
+ {
81
+ name: 'callData',
82
+ type: 'bytes',
83
+ },
84
+ {
85
+ name: 'callbackFunction',
86
+ type: 'bytes4',
87
+ },
88
+ {
89
+ name: 'extraData',
90
+ type: 'bytes',
91
+ },
92
+ ],
93
+ };
94
+ async function offchainLookup(client, { blockNumber, blockTag, data, to, }) {
95
+ const { args } = decodeErrorResult({
96
+ data,
97
+ abi: [offchainLookupAbiItem],
98
+ });
99
+ const [sender, urls, callData, callbackSelector, extraData] = args;
100
+ const { ccipRead } = client;
101
+ const ccipRequest_ = ccipRead && typeof ccipRead?.request === 'function'
102
+ ? ccipRead.request
103
+ : ccipRequest;
104
+ try {
105
+ if (!isAddressEqual(to, sender))
106
+ throw new OffchainLookupSenderMismatchError({ sender, to });
107
+ const result = await ccipRequest_({ data: callData, sender, urls });
108
+ const { data: data_ } = await call(client, {
109
+ blockNumber,
110
+ blockTag,
111
+ data: concat([
112
+ callbackSelector,
113
+ encodeAbiParameters([{ type: 'bytes' }, { type: 'bytes' }], [result, extraData]),
114
+ ]),
115
+ to,
116
+ });
117
+ return data_;
118
+ }
119
+ catch (err) {
120
+ throw new OffchainLookupError({
121
+ callbackSelector,
122
+ cause: err,
123
+ data,
124
+ extraData,
125
+ sender,
126
+ urls,
127
+ });
128
+ }
129
+ }
130
+ async function ccipRequest({ data, sender, urls, }) {
131
+ let error = new Error('An unknown error occurred.');
132
+ for (let i = 0; i < urls.length; i++) {
133
+ const url = urls[i];
134
+ const method = url.includes('{data}') ? 'GET' : 'POST';
135
+ const body = method === 'POST' ? { data, sender } : undefined;
136
+ const headers = method === 'POST' ? { 'Content-Type': 'application/json' } : {};
137
+ try {
138
+ const response = await fetch(url.replace('{sender}', sender).replace('{data}', data), {
139
+ body: JSON.stringify(body),
140
+ headers,
141
+ method,
142
+ });
143
+ let result;
144
+ if (response.headers.get('Content-Type')?.startsWith('application/json')) {
145
+ result = (await response.json()).data;
146
+ }
147
+ else {
148
+ result = (await response.text());
149
+ }
150
+ if (!response.ok) {
151
+ error = new HttpRequestError({
152
+ body,
153
+ details: result?.error
154
+ ? stringify(result.error)
155
+ : response.statusText,
156
+ headers: response.headers,
157
+ status: response.status,
158
+ url,
159
+ });
160
+ continue;
161
+ }
162
+ if (!isHex(result)) {
163
+ error = new OffchainLookupResponseMalformedError({
164
+ result,
165
+ url,
166
+ });
167
+ continue;
168
+ }
169
+ return result;
170
+ }
171
+ catch (err) {
172
+ error = new HttpRequestError({
173
+ body,
174
+ details: err.message,
175
+ url,
176
+ });
177
+ }
178
+ }
179
+ throw error;
180
+ }
181
+
182
+ export { ccipRequest, offchainLookup, offchainLookupAbiItem, offchainLookupSignature };
@@ -0,0 +1,108 @@
1
+ import { Binaries, CircuitArtifacts, CircuitNameString, CircuitsInterface, VersionString } from "./circuits.interface.js";
2
+ /**
3
+ * Class representing circuit management and artifact handling.
4
+ * Implements the CircuitsInterface.
5
+ */
6
+ export declare class Circuits implements CircuitsInterface {
7
+ /**
8
+ * Indicates whether the circuits have been initialized.
9
+ * @type {boolean}
10
+ * @protected
11
+ */
12
+ protected initialized: boolean;
13
+ /**
14
+ * The version of the circuit artifacts being used.
15
+ * @type {VersionString}
16
+ * @protected
17
+ */
18
+ protected version: VersionString;
19
+ /**
20
+ * The binaries containing circuit artifacts such as wasm, vkey, and zkey files.
21
+ * @type {Binaries}
22
+ * @protected
23
+ */
24
+ protected binaries: Binaries;
25
+ /**
26
+ * The base URL for fetching circuit artifacts.
27
+ * @type {string}
28
+ * @protected
29
+ */
30
+ protected baseUrl: string;
31
+ /**
32
+ * Determines whether the environment is a browser.
33
+ * @returns {boolean} True if running in a browser environment, false otherwise.
34
+ * @protected
35
+ */
36
+ _browser(): boolean;
37
+ /**
38
+ * Initializes the circuit manager with binaries and a version.
39
+ * @param {Binaries} binaries - The binaries containing circuit artifacts.
40
+ * @param {VersionString} version - The version of the circuit artifacts.
41
+ * @protected
42
+ */
43
+ protected _initialize(binaries: Binaries, version: VersionString): void;
44
+ /**
45
+ * Handles initialization of circuit artifacts, fetching them if necessary.
46
+ * @param {VersionString} [version=Version.latest] - The version of the circuit artifacts.
47
+ * @throws {CircuitInitialization} If an error occurs during initialization.
48
+ * @protected
49
+ * @async
50
+ */
51
+ protected _handleInitialization(version?: VersionString): Promise<void>;
52
+ /**
53
+ * Fetches a versioned artifact from a given path.
54
+ * @param {string} artifactPath - The path to the artifact.
55
+ * @param {VersionString} version - The version of the artifact.
56
+ * @returns {Promise<Uint8Array>} A promise that resolves to the artifact as a Uint8Array.
57
+ * @throws {FetchArtifact} If the artifact cannot be fetched.
58
+ * @protected
59
+ * @async
60
+ */
61
+ _fetchVersionedArtifact(artifactPath: string): Promise<Uint8Array>;
62
+ /**
63
+ * Downloads and returns the circuit artifacts for a specific circuit.
64
+ * @param {CircuitNameString} circuitName - The name of the circuit.
65
+ * @returns {Promise<CircuitArtifacts>} A promise that resolves to the circuit artifacts.
66
+ * @protected
67
+ * @async
68
+ */
69
+ _downloadCircuitArtifacts(circuitName: CircuitNameString): Promise<CircuitArtifacts>;
70
+ /**
71
+ * Downloads all circuit artifacts for the specified version.
72
+ * @param {VersionString} version - The version of the artifacts.
73
+ * @returns {Promise<Binaries>} A promise that resolves to the binaries containing all circuit artifacts.
74
+ * @async
75
+ */
76
+ downloadArtifacts(version: VersionString): Promise<Binaries>;
77
+ /**
78
+ * Initializes the circuit artifacts for the specified version.
79
+ * @param {VersionString} version - The version of the artifacts.
80
+ * @returns {Promise<void>} A promise that resolves when initialization is complete.
81
+ * @async
82
+ */
83
+ initArtifacts(version: VersionString): Promise<void>;
84
+ /**
85
+ * Retrieves the verification key for a specified circuit.
86
+ * @param {CircuitNameString} circuitName - The name of the circuit.
87
+ * @param {VersionString} [version=Version.latest] - The version of the artifacts.
88
+ * @returns {Promise<Uint8Array>} A promise that resolves to the verification key.
89
+ * @async
90
+ */
91
+ getVerificationKey(circuitName: CircuitNameString, version?: VersionString): Promise<Uint8Array>;
92
+ /**
93
+ * Retrieves the proving key for a specified circuit.
94
+ * @param {CircuitNameString} circuitName - The name of the circuit.
95
+ * @param {VersionString} [version=Version.latest] - The version of the artifacts.
96
+ * @returns {Promise<Uint8Array>} A promise that resolves to the proving key.
97
+ * @async
98
+ */
99
+ getProvingKey(circuitName: CircuitNameString, version?: VersionString): Promise<Uint8Array>;
100
+ /**
101
+ * Retrieves the wasm file for a specified circuit.
102
+ * @param {CircuitNameString} circuitName - The name of the circuit.
103
+ * @param {VersionString} [version=Version.latest] - The version of the artifacts.
104
+ * @returns {Promise<Uint8Array>} A promise that resolves to the wasm file.
105
+ * @async
106
+ */
107
+ getWasm(circuitName: CircuitNameString, version?: VersionString): Promise<Uint8Array>;
108
+ }
@@ -0,0 +1,127 @@
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 type Binaries = {
83
+ [key in CircuitNameString]: CircuitArtifacts;
84
+ };
85
+ /**
86
+ * Interface defining the methods required for managing circuits and their artifacts.
87
+ */
88
+ export interface CircuitsInterface {
89
+ /**
90
+ * Downloads all artifacts for the specified version of circuits.
91
+ * @param {VersionString} version - The version of the artifacts to download.
92
+ * @returns {Promise<Binaries>} A promise that resolves to the binaries containing all circuit artifacts.
93
+ * @async
94
+ */
95
+ downloadArtifacts(version: VersionString): Promise<Binaries>;
96
+ /**
97
+ * Initializes the artifacts for the specified version of circuits.
98
+ * @param {VersionString} version - The version of the artifacts to initialize.
99
+ * @returns {Promise<void>} A promise that resolves when initialization is complete.
100
+ * @async
101
+ */
102
+ initArtifacts(version: VersionString): Promise<void>;
103
+ /**
104
+ * Retrieves the verification key for a specified circuit.
105
+ * @param {CircuitNameString} circuitName - The name of the circuit.
106
+ * @param {VersionString} [version] - The version of the artifacts (defaults to the latest).
107
+ * @returns {Promise<Uint8Array>} A promise that resolves to the verification key.
108
+ * @async
109
+ */
110
+ getVerificationKey(circuitName: CircuitNameString, version?: VersionString): Promise<Uint8Array>;
111
+ /**
112
+ * Retrieves the proving key for a specified circuit.
113
+ * @param {CircuitNameString} circuitName - The name of the circuit.
114
+ * @param {VersionString} [version] - The version of the artifacts (defaults to the latest).
115
+ * @returns {Promise<Uint8Array>} A promise that resolves to the proving key.
116
+ * @async
117
+ */
118
+ getProvingKey(circuitName: CircuitNameString, version?: VersionString): Promise<Uint8Array>;
119
+ /**
120
+ * Retrieves the wasm file for a specified circuit.
121
+ * @param {CircuitNameString} circuitName - The name of the circuit.
122
+ * @param {VersionString} [version] - The version of the artifacts (defaults to the latest).
123
+ * @returns {Promise<Uint8Array>} A promise that resolves to the wasm file.
124
+ * @async
125
+ */
126
+ getWasm(circuitName: CircuitNameString, version?: VersionString): Promise<Uint8Array>;
127
+ }
@@ -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,61 @@
1
+ import { Commitment, Hash, Precommitment } from "../types/commitment.js";
2
+ /**
3
+ * Parameters required for brute-force commitment recovery.
4
+ */
5
+ interface BruteForceRecoveryParams {
6
+ /** The target commitment hash to match against */
7
+ commitmentHash: Hash;
8
+ /** Defines the range of values to search within */
9
+ valueRange: {
10
+ min: number;
11
+ max: number;
12
+ step: number;
13
+ };
14
+ /** The precommitment object containing the hash, nullifier, and secret */
15
+ basePrecommitment: Precommitment;
16
+ /** The label used during commitment computation */
17
+ label: bigint;
18
+ /** Optional settings: timeout in milliseconds */
19
+ options?: {
20
+ timeout?: number;
21
+ };
22
+ }
23
+ /**
24
+ * The result of the brute-force commitment recovery process.
25
+ */
26
+ interface RecoveryResult {
27
+ /** Indicates whether the recovery was successful */
28
+ success: boolean;
29
+ /** Contains the found commitment and its value if successful */
30
+ data?: Array<{
31
+ commitment: Commitment;
32
+ value: number;
33
+ }>;
34
+ /** Contains an error code and message if the recovery fails */
35
+ error?: {
36
+ code: string;
37
+ message: string;
38
+ };
39
+ }
40
+ /**
41
+ * Service for brute-force recovering commitments by iterating over possible values.
42
+ * This method is useful when the original commitment value is lost, but the precommitment and hash are known.
43
+ */
44
+ export declare class BruteForceRecoveryService {
45
+ /**
46
+ * Attempts to recover a commitment by brute-forcing through the given value range.
47
+ *
48
+ * @param params - The parameters required for the brute-force search.
49
+ * @returns A `Promise` resolving to a `RecoveryResult` containing either the found commitment or an error.
50
+ */
51
+ bruteForceRecoverCommitment(params: BruteForceRecoveryParams): Promise<RecoveryResult>;
52
+ /**
53
+ * Computes the Poseidon hash of a commitment.
54
+ */
55
+ private computeCommitmentHash;
56
+ /**
57
+ * Determines the number of decimal places in a given number.
58
+ */
59
+ private getDecimalPlaces;
60
+ }
61
+ export {};
@@ -0,0 +1,30 @@
1
+ import { CircuitsInterface } from "../interfaces/circuits.interface.js";
2
+ import { CommitmentProof } from "../types/commitment.js";
3
+ /**
4
+ * Service responsible for handling commitment-related operations.
5
+ * All hash operations use Poseidon for ZK-friendly hashing.
6
+ */
7
+ export declare class CommitmentService {
8
+ private readonly circuits;
9
+ constructor(circuits: CircuitsInterface);
10
+ /**
11
+ * Generates a zero-knowledge proof for a commitment using Poseidon hash.
12
+ *
13
+ * @param value - The value being committed to
14
+ * @param label - Label associated with the commitment
15
+ * @param nullifier - Unique nullifier for the commitment
16
+ * @param secret - Secret key for the commitment
17
+ * @returns Promise resolving to proof and public signals
18
+ * @throws {ProofError} If proof generation fails
19
+ */
20
+ proveCommitment(value: bigint, label: bigint, nullifier: bigint, secret: bigint): Promise<CommitmentProof>;
21
+ /**
22
+ * Verifies a commitment proof.
23
+ *
24
+ * @param proof - The commitment proof to verify
25
+ * @param publicSignals - Public signals associated with the proof
26
+ * @returns Promise resolving to boolean indicating proof validity
27
+ * @throws {ProofError} If verification fails
28
+ */
29
+ verifyCommitment({ proof, publicSignals, }: CommitmentProof): Promise<boolean>;
30
+ }
@@ -0,0 +1,106 @@
1
+ import { Address, Chain, Hex } from "viem";
2
+ import { Withdrawal, WithdrawalProof } from "../types/withdrawal.js";
3
+ import { ContractInteractions, TransactionResponse } from "../interfaces/contracts.interface.js";
4
+ import { CommitmentProof, Hash } from "../types/commitment.js";
5
+ export declare class ContractInteractionsService implements ContractInteractions {
6
+ private publicClient;
7
+ private walletClient;
8
+ private entrypointAddress;
9
+ private account;
10
+ /**
11
+ * Initializes the contract interactions service.
12
+ *
13
+ * @param rpcUrl - The RPC endpoint URL for the blockchain network.
14
+ * @param chain - The blockchain network configuration.
15
+ * @param entrypointAddress - The address of the entrypoint contract.
16
+ * @param accountPrivateKey - The private key used for signing transactions.
17
+ */
18
+ constructor(rpcUrl: string, chain: Chain, entrypointAddress: Address, accountPrivateKey: Hex);
19
+ /**
20
+ * Deposits ERC20 tokens into the privacy pool.
21
+ *
22
+ * @param asset - The address of the ERC20 token.
23
+ * @param amount - The amount of tokens to deposit.
24
+ * @param precommitment - The precommitment value.
25
+ * @returns Transaction response containing the transaction hash.
26
+ */
27
+ depositERC20(asset: Address, amount: bigint, precommitment: bigint): Promise<TransactionResponse>;
28
+ /**
29
+ * Deposits ETH into the privacy pool.
30
+ *
31
+ * @param amount - The amount of ETH to deposit.
32
+ * @param precommitment - The precommitment value.
33
+ * @returns Transaction response containing the transaction hash.
34
+ */
35
+ depositETH(amount: bigint, precommitment: bigint): Promise<TransactionResponse>;
36
+ /**
37
+ * Withdraws funds from the privacy pool.
38
+ *
39
+ * @param withdrawal - The withdrawal object containing recipient details and amount.
40
+ * @param withdrawalProof - The cryptographic proof verifying the withdrawal.
41
+ * @returns Transaction response containing the transaction hash.
42
+ */
43
+ withdraw(withdrawal: Withdrawal, withdrawalProof: WithdrawalProof, scope: Hash): Promise<TransactionResponse>;
44
+ /**
45
+ * Relays a withdrawal transaction to the entrypoint contract.
46
+ * This function is used to facilitate relayer transactions.
47
+ *
48
+ * @param withdrawal - The withdrawal data structure.
49
+ * @param withdrawalProof - The cryptographic proof required for withdrawal.
50
+ * @returns Transaction response containing hash and wait function.
51
+ */
52
+ relay(withdrawal: Withdrawal, withdrawalProof: WithdrawalProof, scope: Hash): Promise<TransactionResponse>;
53
+ /**
54
+ * Executes a ragequit operation, allowing a user to exit the pool
55
+ * by nullifying their commitment and proving their withdrawal.
56
+ *
57
+ * @param commitmentProof - The cryptographic proof of the commitment.
58
+ * @param privacyPoolAddress - The address of the privacy pool contract.
59
+ * @returns Transaction response containing hash and wait function.
60
+ */
61
+ ragequit(commitmentProof: CommitmentProof, privacyPoolAddress: Address): Promise<TransactionResponse>;
62
+ /**
63
+ * Retrieves the scope identifier of a given privacy pool.
64
+ *
65
+ * @param privacyPoolAddress - The address of the privacy pool contract.
66
+ * @returns The scope identifier as a bigint.
67
+ */
68
+ getScope(privacyPoolAddress: Address): Promise<bigint>;
69
+ /**
70
+ * Retrieves the latest state root of the privacy pool from the entrypoint contract.
71
+ *
72
+ * @param privacyPoolAddress - The address of the privacy pool contract.
73
+ * @returns The latest state root as a bigint.
74
+ */
75
+ getStateRoot(privacyPoolAddress: Address): Promise<bigint>;
76
+ /**
77
+ * Retrieves the current state size of the privacy pool.
78
+ *
79
+ * @param privacyPoolAddress - The address of the privacy pool contract.
80
+ * @returns The size of the state tree as a bigint.
81
+ */
82
+ getStateSize(privacyPoolAddress: Address): Promise<bigint>;
83
+ /**
84
+ * Retrieves data about a specific scope, including the associated privacy pool
85
+ * and the asset used in that pool.
86
+ *
87
+ * @param scope - The scope identifier to look up.
88
+ * @returns An object containing the privacy pool address and asset address.
89
+ * @throws ContractError if the scope does not exist.
90
+ */
91
+ getScopeData(scope: bigint): Promise<{
92
+ poolAddress: Address;
93
+ assetAddress: Address;
94
+ }>;
95
+ /**
96
+ * Approves the entrypoint contract to spend a specified amount of ERC20 tokens.
97
+ *
98
+ * @param spenderAddress - The address of the entity that will be approved to spend tokens.
99
+ * @param tokenAddress - The address of the ERC20 token contract.
100
+ * @param amount - The amount of tokens to approve.
101
+ * @returns Transaction response containing hash and wait function.
102
+ */
103
+ approveERC20(spenderAddress: Address, tokenAddress: Address, amount: bigint): Promise<TransactionResponse>;
104
+ private formatProof;
105
+ private executeTransaction;
106
+ }