@0xbow/privacy-pools-core-sdk 0.1.21 → 0.1.22
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.
- package/README.md +4 -4
- package/dist/esm/{fetchArtifacts.esm-CXLPgzhJ.js → fetchArtifacts.esm-C3KANIm5.js} +2 -2
- package/dist/esm/{fetchArtifacts.esm-CXLPgzhJ.js.map → fetchArtifacts.esm-C3KANIm5.js.map} +1 -1
- package/dist/esm/{fetchArtifacts.node-B3pPMuWd.js → fetchArtifacts.node-CR3h_DU5.js} +2 -2
- package/dist/esm/{fetchArtifacts.node-B3pPMuWd.js.map → fetchArtifacts.node-CR3h_DU5.js.map} +1 -1
- package/dist/esm/{index-C_oO7cOn.js → index-BF3CAXoY.js} +400 -67
- package/dist/esm/index-BF3CAXoY.js.map +1 -0
- package/dist/esm/index.mjs +1 -1
- package/dist/index.d.mts +185 -46
- package/dist/node/{fetchArtifacts.esm-DoJiimN3.js → fetchArtifacts.esm-DX6UV_rS.js} +2 -2
- package/dist/node/{fetchArtifacts.esm-DoJiimN3.js.map → fetchArtifacts.esm-DX6UV_rS.js.map} +1 -1
- package/dist/node/{fetchArtifacts.node-B4Ey9DOV.js → fetchArtifacts.node-CD4Svkkc.js} +2 -2
- package/dist/node/{fetchArtifacts.node-B4Ey9DOV.js.map → fetchArtifacts.node-CD4Svkkc.js.map} +1 -1
- package/dist/node/{index-CwopFzOC.js → index-C0m_hCj-.js} +400 -67
- package/dist/node/index-C0m_hCj-.js.map +1 -0
- package/dist/node/index.mjs +1 -1
- package/dist/types/core/account.service.d.ts +116 -4
- package/dist/types/core/contracts.service.d.ts +9 -1
- package/dist/types/core/sdk.d.ts +2 -1
- package/dist/types/core/withdrawal.service.d.ts +2 -2
- package/dist/types/errors/account.error.d.ts +2 -0
- package/dist/types/errors/base.error.d.ts +1 -0
- package/dist/types/errors/events.error.d.ts +9 -0
- package/dist/types/{fetchArtifacts.esm-CxFhH8oR.js → fetchArtifacts.esm-BgiOz4v6.js} +1 -1
- package/dist/types/{fetchArtifacts.node-Cqk_Z-mS.js → fetchArtifacts.node-t3dhlGoF.js} +1 -1
- package/dist/types/{index-CIvuCHHq.js → index-oyPK96A0.js} +399 -66
- package/dist/types/index.js +1 -1
- package/dist/types/interfaces/contracts.interface.d.ts +7 -0
- package/dist/types/types/events.d.ts +11 -1
- package/package.json +2 -2
- package/src/core/account.service.ts +458 -61
- package/src/core/contracts.service.ts +35 -0
- package/src/core/data.service.ts +2 -3
- package/src/core/sdk.ts +2 -1
- package/src/core/withdrawal.service.ts +25 -9
- package/src/crypto.ts +11 -2
- package/src/errors/account.error.ts +14 -0
- package/src/errors/base.error.ts +5 -0
- package/src/errors/events.error.ts +38 -0
- package/src/interfaces/contracts.interface.ts +8 -0
- package/src/types/events.ts +15 -1
- package/dist/esm/index-C_oO7cOn.js.map +0 -1
- package/dist/node/index-CwopFzOC.js.map +0 -1
package/dist/node/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { n as AccountError, A as AccountService, B as BlockchainProvider, o as CircuitName, j as Circuits, C as CommitmentService, m as ContractError, k as ContractInteractionsService, D as DataService, E as ErrorCode, I as InvalidRpcUrl, P as PrivacyPoolSDK, l as ProofError, S as SDKError, W as WithdrawalService, e as bigintToHash, f as bigintToHex, i as calculateContext, a as generateDepositSecrets, g as generateMasterKeys, d as generateMerkleProof, b as generateWithdrawalSecrets, c as getCommitment, h as hashPrecommitment } from './index-
|
|
1
|
+
export { n as AccountError, A as AccountService, B as BlockchainProvider, o as CircuitName, j as Circuits, C as CommitmentService, m as ContractError, k as ContractInteractionsService, D as DataService, E as ErrorCode, I as InvalidRpcUrl, P as PrivacyPoolSDK, l as ProofError, S as SDKError, W as WithdrawalService, e as bigintToHash, f as bigintToHex, i as calculateContext, a as generateDepositSecrets, g as generateMasterKeys, d as generateMerkleProof, b as generateWithdrawalSecrets, c as getCommitment, h as hashPrecommitment } from './index-C0m_hCj-.js';
|
|
2
2
|
import 'viem/accounts';
|
|
3
3
|
import 'buffer';
|
|
4
4
|
import 'http';
|
|
@@ -2,7 +2,12 @@ import { Hash, Secret } from "../types/commitment.js";
|
|
|
2
2
|
import { Hex } from "viem";
|
|
3
3
|
import { DataService } from "./data.service.js";
|
|
4
4
|
import { AccountCommitment, PoolAccount, PoolInfo, PrivacyPoolAccount } from "../types/account.js";
|
|
5
|
-
import { RagequitEvent } from "../types/events.js";
|
|
5
|
+
import { DepositEvent, PoolEventsError, PoolEventsResult, RagequitEvent, WithdrawalEvent } from "../types/events.js";
|
|
6
|
+
type AccountServiceConfig = {
|
|
7
|
+
mnemonic: string;
|
|
8
|
+
} | {
|
|
9
|
+
account: PrivacyPoolAccount;
|
|
10
|
+
};
|
|
6
11
|
/**
|
|
7
12
|
* Service responsible for managing privacy pool accounts and their associated commitments.
|
|
8
13
|
* Handles account initialization, deposit/withdrawal tracking, and history synchronization.
|
|
@@ -19,12 +24,13 @@ export declare class AccountService {
|
|
|
19
24
|
* Creates a new AccountService instance.
|
|
20
25
|
*
|
|
21
26
|
* @param dataService - Service for fetching on-chain events
|
|
22
|
-
* @param
|
|
23
|
-
* @param mnemonic - Optional mnemonic for deterministic key generation
|
|
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
|
|
24
30
|
*
|
|
25
31
|
* @throws {AccountError} If account initialization fails
|
|
26
32
|
*/
|
|
27
|
-
constructor(dataService: DataService,
|
|
33
|
+
constructor(dataService: DataService, config: AccountServiceConfig);
|
|
28
34
|
/**
|
|
29
35
|
* Initializes a new account from a mnemonic phrase.
|
|
30
36
|
*
|
|
@@ -193,6 +199,111 @@ export declare class AccountService {
|
|
|
193
199
|
*/
|
|
194
200
|
addRagequitToAccount(label: Hash, ragequit: RagequitEvent): PoolAccount;
|
|
195
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
|
|
196
307
|
* Retrieves the history of deposits and withdrawals for the given pools.
|
|
197
308
|
*
|
|
198
309
|
* @param pools - Array of pool configurations to sync history for
|
|
@@ -231,3 +342,4 @@ export declare class AccountService {
|
|
|
231
342
|
*/
|
|
232
343
|
private _processWithdrawalsAndRagequits;
|
|
233
344
|
}
|
|
345
|
+
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Address, Chain, Hex } from "viem";
|
|
2
2
|
import { Withdrawal, WithdrawalProof } from "../types/withdrawal.js";
|
|
3
|
-
import { ContractInteractions, TransactionResponse } from "../interfaces/contracts.interface.js";
|
|
3
|
+
import { AssetConfig, ContractInteractions, TransactionResponse } from "../interfaces/contracts.interface.js";
|
|
4
4
|
import { CommitmentProof, Hash } from "../types/commitment.js";
|
|
5
5
|
export declare class ContractInteractionsService implements ContractInteractions {
|
|
6
6
|
private publicClient;
|
|
@@ -80,6 +80,14 @@ export declare class ContractInteractionsService implements ContractInteractions
|
|
|
80
80
|
* @returns The size of the state tree as a bigint.
|
|
81
81
|
*/
|
|
82
82
|
getStateSize(privacyPoolAddress: Address): Promise<bigint>;
|
|
83
|
+
/**
|
|
84
|
+
* Retrieves data from the corresponding asset
|
|
85
|
+
*
|
|
86
|
+
* @param assetAddress - The asset contract address.
|
|
87
|
+
* @returns AssetConfig - An object containing the privacy pool address, minimum deposit amount, vetting fee and maximum relaying fee.
|
|
88
|
+
* @throws ContractError if the asset does not exist in the pool.
|
|
89
|
+
*/
|
|
90
|
+
getAssetConfig(assetAddress: Address): Promise<AssetConfig>;
|
|
83
91
|
/**
|
|
84
92
|
* Retrieves data about a specific scope, including the associated privacy pool
|
|
85
93
|
* and the asset used in that pool.
|
package/dist/types/core/sdk.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { Commitment, CommitmentProof } from "../types/commitment.js";
|
|
|
3
3
|
import { WithdrawalProof, WithdrawalProofInput } from "../types/withdrawal.js";
|
|
4
4
|
import { ContractInteractionsService } from "./contracts.service.js";
|
|
5
5
|
import { Hex, Address, Chain } from "viem";
|
|
6
|
+
import { AccountCommitment } from "../types/account.js";
|
|
6
7
|
/**
|
|
7
8
|
* Main SDK class providing access to all privacy pool functionality.
|
|
8
9
|
* Uses Poseidon hash for all commitment operations.
|
|
@@ -34,7 +35,7 @@ export declare class PrivacyPoolSDK {
|
|
|
34
35
|
* @param input - Input parameters for the withdrawal
|
|
35
36
|
* @param withdrawal - Withdrawal details
|
|
36
37
|
*/
|
|
37
|
-
proveWithdrawal(commitment: Commitment, input: WithdrawalProofInput): Promise<WithdrawalProof>;
|
|
38
|
+
proveWithdrawal(commitment: Commitment | AccountCommitment, input: WithdrawalProofInput): Promise<WithdrawalProof>;
|
|
38
39
|
/**
|
|
39
40
|
* Verifies a withdrawal proof.
|
|
40
41
|
*
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CircuitsInterface } from "../interfaces/circuits.interface.js";
|
|
2
|
-
import { Commitment } from "../types/commitment.js";
|
|
3
2
|
import { WithdrawalProof, WithdrawalProofInput } from "../types/withdrawal.js";
|
|
3
|
+
import { AccountCommitment, Commitment } from "../index.js";
|
|
4
4
|
/**
|
|
5
5
|
* Service responsible for handling withdrawal-related operations.
|
|
6
6
|
*/
|
|
@@ -16,7 +16,7 @@ export declare class WithdrawalService {
|
|
|
16
16
|
* @returns Promise resolving to withdrawal payload
|
|
17
17
|
* @throws {ProofError} If proof generation fails
|
|
18
18
|
*/
|
|
19
|
-
proveWithdrawal(commitment: Commitment, input: WithdrawalProofInput): Promise<WithdrawalProof>;
|
|
19
|
+
proveWithdrawal(commitment: Commitment | AccountCommitment, input: WithdrawalProofInput): Promise<WithdrawalProof>;
|
|
20
20
|
/**
|
|
21
21
|
* Verifies a withdrawal proof.
|
|
22
22
|
*
|
|
@@ -5,4 +5,6 @@ export declare class AccountError extends SDKError {
|
|
|
5
5
|
static commitmentNotFound(hash: Hash | string): AccountError;
|
|
6
6
|
static invalidPoolAccount(): AccountError;
|
|
7
7
|
static accountInitializationFailed(reason: string): AccountError;
|
|
8
|
+
static duplicatePools(scope: bigint): AccountError;
|
|
9
|
+
static invalidIndex(index: bigint): AccountError;
|
|
8
10
|
}
|
|
@@ -49,4 +49,5 @@ export declare class ProofError extends SDKError {
|
|
|
49
49
|
export declare class ContractError extends SDKError {
|
|
50
50
|
constructor(message: string, code?: ErrorCode, details?: Record<string, unknown>);
|
|
51
51
|
static scopeNotFound(scope: bigint): ContractError;
|
|
52
|
+
static assetNotFound(address: string): ContractError;
|
|
52
53
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ErrorCode } from "./base.error.js";
|
|
2
|
+
import { DataError } from "./data.error.js";
|
|
3
|
+
import { Hash } from "../types/commitment.js";
|
|
4
|
+
export declare class EventError extends DataError {
|
|
5
|
+
constructor(message: string, code?: ErrorCode, details?: Record<string, unknown>);
|
|
6
|
+
static depositEventError(chainId: number, scope: Hash, error: Error): EventError;
|
|
7
|
+
static withdrawalEventError(chainId: number, scope: Hash, error: Error): EventError;
|
|
8
|
+
static ragequitEventError(chainId: number, scope: Hash, error: Error): EventError;
|
|
9
|
+
}
|