@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.
- package/README.md +73 -0
- package/dist/esm/fetchArtifacts.esm-TV4yMbDL.js +18 -0
- package/dist/esm/fetchArtifacts.esm-TV4yMbDL.js.map +1 -0
- package/dist/esm/fetchArtifacts.node-DC_rCgt3.js +31 -0
- package/dist/esm/fetchArtifacts.node-DC_rCgt3.js.map +1 -0
- package/dist/esm/index-Bw-RoJy9.js +70373 -0
- package/dist/esm/index-Bw-RoJy9.js.map +1 -0
- package/dist/esm/index.mjs +7 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/index.d.mts +1222 -0
- package/dist/node/fetchArtifacts.esm-i9-c1RlE.js +35 -0
- package/dist/node/fetchArtifacts.esm-i9-c1RlE.js.map +1 -0
- package/dist/node/fetchArtifacts.node-C5OS73zV.js +48 -0
- package/dist/node/fetchArtifacts.node-C5OS73zV.js.map +1 -0
- package/dist/node/index-BogHNKL8.js +77423 -0
- package/dist/node/index-BogHNKL8.js.map +1 -0
- package/dist/node/index.mjs +24 -0
- package/dist/node/index.mjs.map +1 -0
- package/dist/types/abi/ERC20.d.ts +38 -0
- package/dist/types/abi/IEntrypoint.d.ts +823 -0
- package/dist/types/abi/IPrivacyPool.d.ts +51 -0
- package/dist/types/circuits/circuits.impl.d.ts +120 -0
- package/dist/types/circuits/circuits.interface.d.ts +129 -0
- package/dist/types/circuits/fetchArtifacts.d.ts +1 -0
- package/dist/types/circuits/fetchArtifacts.esm.d.ts +1 -0
- package/dist/types/circuits/fetchArtifacts.node.d.ts +1 -0
- package/dist/types/circuits/index.d.ts +2 -0
- package/dist/types/constants.d.ts +2 -0
- package/dist/types/core/account.service.d.ts +345 -0
- package/dist/types/core/bruteForce.service.d.ts +61 -0
- package/dist/types/core/commitment.service.d.ts +30 -0
- package/dist/types/core/contracts.service.d.ts +114 -0
- package/dist/types/core/data.service.d.ts +52 -0
- package/dist/types/core/sdk.d.ts +45 -0
- package/dist/types/core/withdrawal.service.d.ts +32 -0
- package/dist/types/crypto.d.ts +67 -0
- package/dist/types/dirname.helper.d.ts +2 -0
- package/dist/types/errors/account.error.d.ts +10 -0
- package/dist/types/errors/base.error.d.ts +53 -0
- package/dist/types/errors/data.error.d.ts +7 -0
- package/dist/types/errors/events.error.d.ts +9 -0
- package/dist/types/exceptions/circuitInitialization.exception.d.ts +3 -0
- package/dist/types/exceptions/fetchArtifacts.exception.d.ts +3 -0
- package/dist/types/exceptions/index.d.ts +4 -0
- package/dist/types/exceptions/invalidRpcUrl.exception.d.ts +3 -0
- package/dist/types/exceptions/privacyPool.exception.d.ts +13 -0
- package/dist/types/external.d.ts +7 -0
- package/dist/types/fetchArtifacts.esm-CwvN5XjW.js +34 -0
- package/dist/types/fetchArtifacts.node-VEzDC3k8.js +47 -0
- package/dist/types/filename.helper.d.ts +2 -0
- package/dist/types/index-CPuQ9H-0.js +77436 -0
- package/dist/types/index.d.ts +13 -0
- package/dist/types/index.js +23 -0
- package/dist/types/interfaces/blockchainProvider.interface.d.ts +12 -0
- package/dist/types/interfaces/circuits.interface.d.ts +30 -0
- package/dist/types/interfaces/contracts.interface.d.ts +35 -0
- package/dist/types/interfaces/index.d.ts +1 -0
- package/dist/types/internal.d.ts +6 -0
- package/dist/types/keys.d.ts +18 -0
- package/dist/types/providers/blockchainProvider.d.ts +8 -0
- package/dist/types/providers/index.d.ts +1 -0
- package/dist/types/types/account.d.ts +31 -0
- package/dist/types/types/commitment.d.ts +48 -0
- package/dist/types/types/events.d.ts +72 -0
- package/dist/types/types/index.d.ts +3 -0
- package/dist/types/types/keys.d.ts +5 -0
- package/dist/types/types/withdrawal.d.ts +30 -0
- package/dist/types/utils/logger.d.ts +22 -0
- package/package.json +81 -0
- package/src/abi/ERC20.ts +222 -0
- package/src/abi/IEntrypoint.ts +1059 -0
- package/src/abi/IPrivacyPool.ts +576 -0
- package/src/circuits/circuits.impl.ts +232 -0
- package/src/circuits/circuits.interface.ts +166 -0
- package/src/circuits/fetchArtifacts.esm.ts +12 -0
- package/src/circuits/fetchArtifacts.node.ts +23 -0
- package/src/circuits/fetchArtifacts.ts +7 -0
- package/src/circuits/index.ts +2 -0
- package/src/constants.ts +3 -0
- package/src/core/account.service.ts +1093 -0
- package/src/core/bruteForce.service.ts +120 -0
- package/src/core/commitment.service.ts +84 -0
- package/src/core/contracts.service.ts +450 -0
- package/src/core/data.service.ts +276 -0
- package/src/core/sdk.ts +92 -0
- package/src/core/withdrawal.service.ts +126 -0
- package/src/crypto.ts +226 -0
- package/src/dirname.helper.ts +4 -0
- package/src/errors/account.error.ts +49 -0
- package/src/errors/base.error.ts +125 -0
- package/src/errors/data.error.ts +34 -0
- package/src/errors/events.error.ts +38 -0
- package/src/exceptions/circuitInitialization.exception.ts +6 -0
- package/src/exceptions/fetchArtifacts.exception.ts +7 -0
- package/src/exceptions/index.ts +4 -0
- package/src/exceptions/invalidRpcUrl.exception.ts +6 -0
- package/src/exceptions/privacyPool.exception.ts +19 -0
- package/src/external.ts +13 -0
- package/src/filename.helper.ts +4 -0
- package/src/index.ts +21 -0
- package/src/interfaces/blockchainProvider.interface.ts +13 -0
- package/src/interfaces/circuits.interface.ts +34 -0
- package/src/interfaces/contracts.interface.ts +66 -0
- package/src/interfaces/index.ts +1 -0
- package/src/internal.ts +6 -0
- package/src/keys.ts +42 -0
- package/src/providers/blockchainProvider.ts +30 -0
- package/src/providers/index.ts +1 -0
- package/src/types/account.ts +35 -0
- package/src/types/commitment.ts +50 -0
- package/src/types/events.ts +82 -0
- package/src/types/index.ts +3 -0
- package/src/types/keys.ts +6 -0
- package/src/types/withdrawal.ts +33 -0
- package/src/utils/logger.ts +56 -0
|
@@ -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,114 @@
|
|
|
1
|
+
import { Address, Chain, Hex } from "viem";
|
|
2
|
+
import { Withdrawal, WithdrawalProof } from "../types/withdrawal.js";
|
|
3
|
+
import { AssetConfig, 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 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>;
|
|
91
|
+
/**
|
|
92
|
+
* Retrieves data about a specific scope, including the associated privacy pool
|
|
93
|
+
* and the asset used in that pool.
|
|
94
|
+
*
|
|
95
|
+
* @param scope - The scope identifier to look up.
|
|
96
|
+
* @returns An object containing the privacy pool address and asset address.
|
|
97
|
+
* @throws ContractError if the scope does not exist.
|
|
98
|
+
*/
|
|
99
|
+
getScopeData(scope: bigint): Promise<{
|
|
100
|
+
poolAddress: Address;
|
|
101
|
+
assetAddress: Address;
|
|
102
|
+
}>;
|
|
103
|
+
/**
|
|
104
|
+
* Approves the entrypoint contract to spend a specified amount of ERC20 tokens.
|
|
105
|
+
*
|
|
106
|
+
* @param spenderAddress - The address of the entity that will be approved to spend tokens.
|
|
107
|
+
* @param tokenAddress - The address of the ERC20 token contract.
|
|
108
|
+
* @param amount - The amount of tokens to approve.
|
|
109
|
+
* @returns Transaction response containing hash and wait function.
|
|
110
|
+
*/
|
|
111
|
+
approveERC20(spenderAddress: Address, tokenAddress: Address, amount: bigint): Promise<TransactionResponse>;
|
|
112
|
+
private formatProof;
|
|
113
|
+
private executeTransaction;
|
|
114
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { ChainConfig, DepositEvent, WithdrawalEvent, RagequitEvent } from "../types/events.js";
|
|
2
|
+
import { PoolInfo } from "../types/account.js";
|
|
3
|
+
/**
|
|
4
|
+
* Service responsible for fetching and managing privacy pool events across multiple chains.
|
|
5
|
+
* Handles event retrieval, parsing, and validation for deposits, withdrawals, and ragequits.
|
|
6
|
+
*
|
|
7
|
+
* @remarks
|
|
8
|
+
* This service uses viem's PublicClient to efficiently fetch and process blockchain events.
|
|
9
|
+
* It supports multiple chains and provides robust error handling and validation.
|
|
10
|
+
* All uint256 values from events are handled as bigints, with Hash type assertions for commitment-related fields.
|
|
11
|
+
*/
|
|
12
|
+
export declare class DataService {
|
|
13
|
+
private readonly chainConfigs;
|
|
14
|
+
private readonly clients;
|
|
15
|
+
private readonly logger;
|
|
16
|
+
/**
|
|
17
|
+
* Initialize the data service with chain configurations
|
|
18
|
+
*
|
|
19
|
+
* @param chainConfigs - Array of chain configurations containing chainId, RPC URL, and API key
|
|
20
|
+
* @throws {DataError} If client initialization fails for any chain
|
|
21
|
+
*/
|
|
22
|
+
constructor(chainConfigs: ChainConfig[]);
|
|
23
|
+
/**
|
|
24
|
+
* Get deposit events for a specific chain
|
|
25
|
+
*
|
|
26
|
+
* @param chainId - Chain ID to fetch events from
|
|
27
|
+
* @param options - Event filter options including fromBlock, toBlock, and other filters
|
|
28
|
+
* @returns Array of deposit events with properly typed fields (bigint for numbers, Hash for commitments)
|
|
29
|
+
* @throws {DataError} If client is not configured, network error occurs, or event data is invalid
|
|
30
|
+
*/
|
|
31
|
+
getDeposits(pool: PoolInfo): Promise<DepositEvent[]>;
|
|
32
|
+
/**
|
|
33
|
+
* Get withdrawal events for a specific chain
|
|
34
|
+
*
|
|
35
|
+
* @param chainId - Chain ID to fetch events from
|
|
36
|
+
* @param options - Event filter options including fromBlock, toBlock, and other filters
|
|
37
|
+
* @returns Array of withdrawal events with properly typed fields (bigint for numbers, Hash for commitments)
|
|
38
|
+
* @throws {DataError} If client is not configured, network error occurs, or event data is invalid
|
|
39
|
+
*/
|
|
40
|
+
getWithdrawals(pool: PoolInfo, fromBlock?: bigint): Promise<WithdrawalEvent[]>;
|
|
41
|
+
/**
|
|
42
|
+
* Get ragequit events for a specific chain
|
|
43
|
+
*
|
|
44
|
+
* @param chainId - Chain ID to fetch events from
|
|
45
|
+
* @param options - Event filter options including fromBlock, toBlock, and other filters
|
|
46
|
+
* @returns Array of ragequit events with properly typed fields (bigint for numbers, Hash for commitments)
|
|
47
|
+
* @throws {DataError} If client is not configured, network error occurs, or event data is invalid
|
|
48
|
+
*/
|
|
49
|
+
getRagequits(pool: PoolInfo, fromBlock?: bigint): Promise<RagequitEvent[]>;
|
|
50
|
+
private getClientForChain;
|
|
51
|
+
private getConfigForChain;
|
|
52
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { CircuitsInterface } from "../interfaces/circuits.interface.js";
|
|
2
|
+
import { Commitment, CommitmentProof } from "../types/commitment.js";
|
|
3
|
+
import { WithdrawalProof, WithdrawalProofInput } from "../types/withdrawal.js";
|
|
4
|
+
import { ContractInteractionsService } from "./contracts.service.js";
|
|
5
|
+
import { Hex, Address, Chain } from "viem";
|
|
6
|
+
import { AccountCommitment } from "../types/account.js";
|
|
7
|
+
/**
|
|
8
|
+
* Main SDK class providing access to all privacy pool functionality.
|
|
9
|
+
* Uses Poseidon hash for all commitment operations.
|
|
10
|
+
*/
|
|
11
|
+
export declare class PrivacyPoolSDK {
|
|
12
|
+
private readonly commitmentService;
|
|
13
|
+
private readonly withdrawalService;
|
|
14
|
+
constructor(circuits: CircuitsInterface);
|
|
15
|
+
createContractInstance(rpcUrl: string, chain: Chain, entrypointAddress: Address, privateKey: Hex): ContractInteractionsService;
|
|
16
|
+
/**
|
|
17
|
+
* Generates a commitment proof.
|
|
18
|
+
*
|
|
19
|
+
* @param value - Value to commit
|
|
20
|
+
* @param label - Label for the commitment
|
|
21
|
+
* @param nullifier - Nullifier for the commitment
|
|
22
|
+
* @param secret - Secret for the commitment
|
|
23
|
+
*/
|
|
24
|
+
proveCommitment(value: bigint, label: bigint, nullifier: bigint, secret: bigint): Promise<CommitmentProof>;
|
|
25
|
+
/**
|
|
26
|
+
* Verifies a commitment proof.
|
|
27
|
+
*
|
|
28
|
+
* @param proof - The proof to verify
|
|
29
|
+
*/
|
|
30
|
+
verifyCommitment(proof: CommitmentProof): Promise<boolean>;
|
|
31
|
+
/**
|
|
32
|
+
* Generates a withdrawal proof.
|
|
33
|
+
*
|
|
34
|
+
* @param commitment - Commitment to withdraw
|
|
35
|
+
* @param input - Input parameters for the withdrawal
|
|
36
|
+
* @param withdrawal - Withdrawal details
|
|
37
|
+
*/
|
|
38
|
+
proveWithdrawal(commitment: Commitment | AccountCommitment, input: WithdrawalProofInput): Promise<WithdrawalProof>;
|
|
39
|
+
/**
|
|
40
|
+
* Verifies a withdrawal proof.
|
|
41
|
+
*
|
|
42
|
+
* @param withdrawalProof - The withdrawal payload to verify
|
|
43
|
+
*/
|
|
44
|
+
verifyWithdrawal(withdrawalProof: WithdrawalProof): Promise<boolean>;
|
|
45
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { CircuitsInterface } from "../interfaces/circuits.interface.js";
|
|
2
|
+
import { WithdrawalProof, WithdrawalProofInput } from "../types/withdrawal.js";
|
|
3
|
+
import { AccountCommitment, Commitment } from "../index.js";
|
|
4
|
+
/**
|
|
5
|
+
* Service responsible for handling withdrawal-related operations.
|
|
6
|
+
*/
|
|
7
|
+
export declare class WithdrawalService {
|
|
8
|
+
private readonly circuits;
|
|
9
|
+
constructor(circuits: CircuitsInterface);
|
|
10
|
+
/**
|
|
11
|
+
* Generates a withdrawal proof.
|
|
12
|
+
*
|
|
13
|
+
* @param commitment - Commitment to withdraw
|
|
14
|
+
* @param input - Input parameters for the withdrawal
|
|
15
|
+
* @param withdrawal - Withdrawal details
|
|
16
|
+
* @returns Promise resolving to withdrawal payload
|
|
17
|
+
* @throws {ProofError} If proof generation fails
|
|
18
|
+
*/
|
|
19
|
+
proveWithdrawal(commitment: Commitment | AccountCommitment, input: WithdrawalProofInput): Promise<WithdrawalProof>;
|
|
20
|
+
/**
|
|
21
|
+
* Verifies a withdrawal proof.
|
|
22
|
+
*
|
|
23
|
+
* @param withdrawalPayload - The withdrawal payload to verify
|
|
24
|
+
* @returns Promise resolving to boolean indicating proof validity
|
|
25
|
+
* @throws {ProofError} If verification fails
|
|
26
|
+
*/
|
|
27
|
+
verifyWithdrawal(withdrawalPayload: WithdrawalProof): Promise<boolean>;
|
|
28
|
+
/**
|
|
29
|
+
* Prepares input signals for the withdrawal circuit.
|
|
30
|
+
*/
|
|
31
|
+
private prepareInputSignals;
|
|
32
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { LeanIMTMerkleProof } from "@zk-kit/lean-imt";
|
|
2
|
+
import { Commitment, Hash, Secret, Withdrawal, MasterKeys } from "./types/index.js";
|
|
3
|
+
import { Hex } from "viem";
|
|
4
|
+
/**
|
|
5
|
+
* Generates two master keys based on some provided seed or a random value.
|
|
6
|
+
*
|
|
7
|
+
* @param {Hex} seed - The optional seed.
|
|
8
|
+
* @returns {MasterKeys} The master key pair.
|
|
9
|
+
*/
|
|
10
|
+
export declare function generateMasterKeys(mnemonic: string): MasterKeys;
|
|
11
|
+
/**
|
|
12
|
+
* Generates a nullifier and secret pair for a deposit commitment.
|
|
13
|
+
*
|
|
14
|
+
* @param {MasterKeys} keys - The master keys pair.
|
|
15
|
+
* @param {Hash} scope - The pool scope.
|
|
16
|
+
* @param {bigint} index - The pool account index for the scope.
|
|
17
|
+
* @returns {Secret, Secret} The commitment nullifier and secret pair.
|
|
18
|
+
*/
|
|
19
|
+
export declare function generateDepositSecrets(keys: MasterKeys, scope: Hash, index: bigint): {
|
|
20
|
+
nullifier: Secret;
|
|
21
|
+
secret: Secret;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Generates a nullifier and secret pair for a withdrawal commitment.
|
|
25
|
+
*
|
|
26
|
+
* @param {MasterKeys} keys - The master keys pair.
|
|
27
|
+
* @param {Hash} label - The deposit commitment label.
|
|
28
|
+
* @param {bigint} index - The withdrawal index for the pool account.
|
|
29
|
+
* @returns {Secret, Secret} The commitment nullifier and secret pair.
|
|
30
|
+
*/
|
|
31
|
+
export declare function generateWithdrawalSecrets(keys: MasterKeys, label: Hash, index: bigint): {
|
|
32
|
+
nullifier: Secret;
|
|
33
|
+
secret: Secret;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Computes a Poseidon hash for the given nullifier and secret.
|
|
37
|
+
*
|
|
38
|
+
* @param {Secret} nullifier - The nullifier to hash.
|
|
39
|
+
* @param {Secret} secret - The secret to hash.
|
|
40
|
+
* @returns {Hash} The Poseidon hash.
|
|
41
|
+
*/
|
|
42
|
+
export declare function hashPrecommitment(nullifier: Secret, secret: Secret): Hash;
|
|
43
|
+
/**
|
|
44
|
+
* Generates a commitment using the given parameters.
|
|
45
|
+
*
|
|
46
|
+
* @param {bigint} value - The value associated with the commitment.
|
|
47
|
+
* @param {bigint} label - The label used for the commitment.
|
|
48
|
+
* @param {Secret} nullifier - The nullifier used in the precommitment.
|
|
49
|
+
* @param {Secret} secret - The secret used in the precommitment.
|
|
50
|
+
* @returns {Commitment} The generated commitment object.
|
|
51
|
+
*/
|
|
52
|
+
export declare function getCommitment(value: bigint, label: bigint, nullifier: Secret, secret: Secret): Commitment;
|
|
53
|
+
/**
|
|
54
|
+
* Generates a Merkle inclusion proof for a given leaf in a set of leaves.
|
|
55
|
+
*
|
|
56
|
+
* @param {bigint[]} leaves - Array of leaves for the Lean Incremental Merkle tree.
|
|
57
|
+
* @param {bigint} leaf - The specific leaf to generate the inclusion proof for.
|
|
58
|
+
* @returns {LeanIMTMerkleProof<bigint>} A lean incremental Merkle tree inclusion proof.
|
|
59
|
+
* @throws {Error} If the leaf is not found in the leaves array.
|
|
60
|
+
*/
|
|
61
|
+
export declare function generateMerkleProof(leaves: bigint[], leaf: bigint): LeanIMTMerkleProof<bigint>;
|
|
62
|
+
export declare function bigintToHash(value: bigint): Hash;
|
|
63
|
+
export declare function bigintToHex(num: bigint | string | undefined): Hex;
|
|
64
|
+
/**
|
|
65
|
+
* Calculates the context hash for a withdrawal.
|
|
66
|
+
*/
|
|
67
|
+
export declare function calculateContext(withdrawal: Withdrawal, scope: Hash): string;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ErrorCode, SDKError } from "./base.error.js";
|
|
2
|
+
import { Hash } from "../types/commitment.js";
|
|
3
|
+
export declare class AccountError extends SDKError {
|
|
4
|
+
constructor(message: string, code?: ErrorCode, details?: Record<string, unknown>);
|
|
5
|
+
static commitmentNotFound(hash: Hash | string): AccountError;
|
|
6
|
+
static invalidPoolAccount(): AccountError;
|
|
7
|
+
static accountInitializationFailed(reason: string): AccountError;
|
|
8
|
+
static duplicatePools(scope: bigint): AccountError;
|
|
9
|
+
static invalidIndex(index: bigint): AccountError;
|
|
10
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unified error codes for the SDK.
|
|
3
|
+
*/
|
|
4
|
+
export declare enum ErrorCode {
|
|
5
|
+
UNKNOWN = "UNKNOWN",
|
|
6
|
+
INVALID_INPUT = "INVALID_INPUT",
|
|
7
|
+
OPERATION_FAILED = "OPERATION_FAILED",
|
|
8
|
+
NETWORK_ERROR = "NETWORK_ERROR",
|
|
9
|
+
PROOF_GENERATION_FAILED = "PROOF_GENERATION_FAILED",
|
|
10
|
+
PROOF_VERIFICATION_FAILED = "PROOF_VERIFICATION_FAILED",
|
|
11
|
+
INVALID_PROOF = "INVALID_PROOF",
|
|
12
|
+
INVALID_PUBLIC_SIGNALS = "INVALID_PUBLIC_SIGNALS",
|
|
13
|
+
CIRCUIT_ERROR = "CIRCUIT_ERROR",
|
|
14
|
+
CONTRACT_ERROR = "CONTRACT_ERROR",
|
|
15
|
+
CRYPTO_ERROR = "CRYPTO_ERROR",
|
|
16
|
+
MERKLE_ERROR = "MERKLE_ERROR"
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Base error class for the SDK.
|
|
20
|
+
* All other error classes should extend this.
|
|
21
|
+
*/
|
|
22
|
+
export declare class SDKError extends Error {
|
|
23
|
+
readonly code: ErrorCode;
|
|
24
|
+
readonly details?: Record<string, unknown> | undefined;
|
|
25
|
+
constructor(message: string, code?: ErrorCode, details?: Record<string, unknown> | undefined);
|
|
26
|
+
/**
|
|
27
|
+
* Creates a JSON representation of the error.
|
|
28
|
+
*/
|
|
29
|
+
toJSON(): Record<string, unknown>;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Specialized error class for proof-related operations.
|
|
33
|
+
*/
|
|
34
|
+
export declare class ProofError extends SDKError {
|
|
35
|
+
constructor(message: string, code?: ErrorCode, details?: Record<string, unknown>);
|
|
36
|
+
/**
|
|
37
|
+
* Creates an error for proof generation failures.
|
|
38
|
+
*/
|
|
39
|
+
static generationFailed(details?: Record<string, unknown>): ProofError;
|
|
40
|
+
/**
|
|
41
|
+
* Creates an error for proof verification failures.
|
|
42
|
+
*/
|
|
43
|
+
static verificationFailed(details?: Record<string, unknown>): ProofError;
|
|
44
|
+
/**
|
|
45
|
+
* Creates an error for invalid proof format.
|
|
46
|
+
*/
|
|
47
|
+
static invalidProof(details?: Record<string, unknown>): ProofError;
|
|
48
|
+
}
|
|
49
|
+
export declare class ContractError extends SDKError {
|
|
50
|
+
constructor(message: string, code?: ErrorCode, details?: Record<string, unknown>);
|
|
51
|
+
static scopeNotFound(scope: bigint): ContractError;
|
|
52
|
+
static assetNotFound(address: string): ContractError;
|
|
53
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ErrorCode, SDKError } from "./base.error.js";
|
|
2
|
+
export declare class DataError extends SDKError {
|
|
3
|
+
constructor(message: string, code?: ErrorCode, details?: Record<string, unknown>);
|
|
4
|
+
static invalidLog(type: string, reason: string): DataError;
|
|
5
|
+
static chainNotConfigured(chainId: number): DataError;
|
|
6
|
+
static networkError(chainId: number, error: Error): DataError;
|
|
7
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare enum ErrorCode {
|
|
2
|
+
INVALID_COMMITMENT = "INVALID_COMMITMENT",
|
|
3
|
+
INVALID_MERKLE_PROOF = "INVALID_MERKLE_PROOF",
|
|
4
|
+
INVALID_NULLIFIER = "INVALID_NULLIFIER",
|
|
5
|
+
INVALID_SECRET = "INVALID_SECRET",
|
|
6
|
+
INVALID_VALUE = "INVALID_VALUE",
|
|
7
|
+
INVALID_LABEL = "INVALID_LABEL",
|
|
8
|
+
MERKLE_ERROR = "MERKLE_ERROR"
|
|
9
|
+
}
|
|
10
|
+
export declare class PrivacyPoolError extends Error {
|
|
11
|
+
code: ErrorCode;
|
|
12
|
+
constructor(code: ErrorCode, message: string);
|
|
13
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type { IBlockchainProvider } from "./internal.js";
|
|
2
|
+
export { InvalidRpcUrl } from "./internal.js";
|
|
3
|
+
export { BlockchainProvider } from "./internal.js";
|
|
4
|
+
export { Circuits } from "./circuits/index.js";
|
|
5
|
+
export { ContractInteractionsService } from "./core/contracts.service.js";
|
|
6
|
+
export type { LeanIMTMerkleProof } from "@zk-kit/lean-imt";
|
|
7
|
+
export type { Address } from "viem";
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { F as FetchArtifact } from './index-CPuQ9H-0.js';
|
|
2
|
+
import 'viem/accounts';
|
|
3
|
+
import 'buffer';
|
|
4
|
+
import 'http';
|
|
5
|
+
import 'https';
|
|
6
|
+
import 'zlib';
|
|
7
|
+
import 'crypto';
|
|
8
|
+
import 'node:crypto';
|
|
9
|
+
import 'events';
|
|
10
|
+
import 'net';
|
|
11
|
+
import 'tls';
|
|
12
|
+
import 'stream';
|
|
13
|
+
import 'url';
|
|
14
|
+
import 'assert';
|
|
15
|
+
import 'viem';
|
|
16
|
+
import 'viem/chains';
|
|
17
|
+
import 'os';
|
|
18
|
+
import 'vm';
|
|
19
|
+
import 'worker_threads';
|
|
20
|
+
import 'fs';
|
|
21
|
+
import 'constants';
|
|
22
|
+
import 'readline';
|
|
23
|
+
import 'path';
|
|
24
|
+
|
|
25
|
+
async function fetchVersionedArtifact(artifactUrl) {
|
|
26
|
+
const res = await fetch(artifactUrl);
|
|
27
|
+
if (res.status !== 200) {
|
|
28
|
+
throw new FetchArtifact(artifactUrl);
|
|
29
|
+
}
|
|
30
|
+
const aBuf = await res.arrayBuffer();
|
|
31
|
+
return new Uint8Array(aBuf);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export { fetchVersionedArtifact };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { F as FetchArtifact } from './index-CPuQ9H-0.js';
|
|
2
|
+
import 'viem/accounts';
|
|
3
|
+
import 'buffer';
|
|
4
|
+
import 'http';
|
|
5
|
+
import 'https';
|
|
6
|
+
import 'zlib';
|
|
7
|
+
import 'crypto';
|
|
8
|
+
import 'node:crypto';
|
|
9
|
+
import 'events';
|
|
10
|
+
import 'net';
|
|
11
|
+
import 'tls';
|
|
12
|
+
import 'stream';
|
|
13
|
+
import 'url';
|
|
14
|
+
import 'assert';
|
|
15
|
+
import 'viem';
|
|
16
|
+
import 'viem/chains';
|
|
17
|
+
import 'os';
|
|
18
|
+
import 'vm';
|
|
19
|
+
import 'worker_threads';
|
|
20
|
+
import 'fs';
|
|
21
|
+
import 'constants';
|
|
22
|
+
import 'readline';
|
|
23
|
+
import 'path';
|
|
24
|
+
|
|
25
|
+
async function fetchVersionedArtifact(artifactUrl) {
|
|
26
|
+
try {
|
|
27
|
+
const fs = (await import('fs')).default;
|
|
28
|
+
const readPromise = new Promise((resolve, reject) => {
|
|
29
|
+
fs.readFile(artifactUrl.pathname, (err, data) => {
|
|
30
|
+
if (err) {
|
|
31
|
+
reject(err);
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
resolve(data);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
const buf = await readPromise;
|
|
39
|
+
return new Uint8Array(buf);
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
console.error(error);
|
|
43
|
+
throw new FetchArtifact(artifactUrl);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export { fetchVersionedArtifact };
|