@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.
- package/README.md +73 -0
- package/dist/esm/ccip-nJye9Itm.js +166 -0
- package/dist/esm/ccip-nJye9Itm.js.map +1 -0
- package/dist/esm/index-DAWUECi8.js +84043 -0
- package/dist/esm/index-DAWUECi8.js.map +1 -0
- package/dist/esm/index.mjs +4 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/index.d.mts +666 -0
- package/dist/node/ccip-lPhPeJab.js +183 -0
- package/dist/node/ccip-lPhPeJab.js.map +1 -0
- package/dist/node/index-BiU5Ef8Z.js +90625 -0
- package/dist/node/index-BiU5Ef8Z.js.map +1 -0
- package/dist/node/index.mjs +21 -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 +794 -0
- package/dist/types/abi/IPrivacyPool.d.ts +51 -0
- package/dist/types/ccip-BZzz1Y5w.js +182 -0
- package/dist/types/circuits/circuits.impl.d.ts +108 -0
- package/dist/types/circuits/circuits.interface.d.ts +127 -0
- package/dist/types/circuits/index.d.ts +2 -0
- package/dist/types/constants.d.ts +2 -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 +106 -0
- package/dist/types/core/sdk.d.ts +44 -0
- package/dist/types/core/withdrawal.service.d.ts +32 -0
- package/dist/types/crypto.d.ts +45 -0
- package/dist/types/dirname.helper.d.ts +2 -0
- package/dist/types/errors/base.error.d.ts +52 -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/filename.helper.d.ts +2 -0
- package/dist/types/index-D-_1h8-n.js +90638 -0
- package/dist/types/index.d.ts +10 -0
- package/dist/types/index.js +20 -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 +28 -0
- package/dist/types/interfaces/index.d.ts +1 -0
- package/dist/types/internal.d.ts +6 -0
- package/dist/types/providers/blockchainProvider.d.ts +8 -0
- package/dist/types/providers/index.d.ts +1 -0
- package/dist/types/types/commitment.d.ts +48 -0
- package/dist/types/types/index.d.ts +2 -0
- package/dist/types/types/withdrawal.d.ts +30 -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 +1077 -0
- package/src/core/bruteForce.service.ts +120 -0
- package/src/core/commitment.service.ts +84 -0
- package/src/core/contracts.service.ts +442 -0
- package/src/core/data.service.ts +272 -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 +26 -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,44 @@
|
|
|
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
|
+
/**
|
|
7
|
+
* Main SDK class providing access to all privacy pool functionality.
|
|
8
|
+
* Uses Poseidon hash for all commitment operations.
|
|
9
|
+
*/
|
|
10
|
+
export declare class PrivacyPoolSDK {
|
|
11
|
+
private readonly commitmentService;
|
|
12
|
+
private readonly withdrawalService;
|
|
13
|
+
constructor(circuits: CircuitsInterface);
|
|
14
|
+
createContractInstance(rpcUrl: string, chain: Chain, entrypointAddress: Address, privateKey: Hex): ContractInteractionsService;
|
|
15
|
+
/**
|
|
16
|
+
* Generates a commitment proof.
|
|
17
|
+
*
|
|
18
|
+
* @param value - Value to commit
|
|
19
|
+
* @param label - Label for the commitment
|
|
20
|
+
* @param nullifier - Nullifier for the commitment
|
|
21
|
+
* @param secret - Secret for the commitment
|
|
22
|
+
*/
|
|
23
|
+
proveCommitment(value: bigint, label: bigint, nullifier: bigint, secret: bigint): Promise<CommitmentProof>;
|
|
24
|
+
/**
|
|
25
|
+
* Verifies a commitment proof.
|
|
26
|
+
*
|
|
27
|
+
* @param proof - The proof to verify
|
|
28
|
+
*/
|
|
29
|
+
verifyCommitment(proof: CommitmentProof): Promise<boolean>;
|
|
30
|
+
/**
|
|
31
|
+
* Generates a withdrawal proof.
|
|
32
|
+
*
|
|
33
|
+
* @param commitment - Commitment to withdraw
|
|
34
|
+
* @param input - Input parameters for the withdrawal
|
|
35
|
+
* @param withdrawal - Withdrawal details
|
|
36
|
+
*/
|
|
37
|
+
proveWithdrawal(commitment: Commitment, input: WithdrawalProofInput): Promise<WithdrawalProof>;
|
|
38
|
+
/**
|
|
39
|
+
* Verifies a withdrawal proof.
|
|
40
|
+
*
|
|
41
|
+
* @param withdrawalProof - The withdrawal payload to verify
|
|
42
|
+
*/
|
|
43
|
+
verifyWithdrawal(withdrawalProof: WithdrawalProof): Promise<boolean>;
|
|
44
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { CircuitsInterface } from "../interfaces/circuits.interface.js";
|
|
2
|
+
import { Commitment } from "../types/commitment.js";
|
|
3
|
+
import { WithdrawalProof, WithdrawalProofInput } from "../types/withdrawal.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, 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,45 @@
|
|
|
1
|
+
import { LeanIMTMerkleProof } from "@zk-kit/lean-imt";
|
|
2
|
+
import { Commitment, Hash, Secret, Withdrawal } from "./types/index.js";
|
|
3
|
+
import { Hex } from "viem";
|
|
4
|
+
/**
|
|
5
|
+
* Generates random nullifier and secret.
|
|
6
|
+
*
|
|
7
|
+
* @returns {{ nullifier: Secret, secret: Secret }} Randomly generated secrets.
|
|
8
|
+
*/
|
|
9
|
+
export declare function generateSecrets(): {
|
|
10
|
+
nullifier: Secret;
|
|
11
|
+
secret: Secret;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Computes a Poseidon hash for the given nullifier and secret.
|
|
15
|
+
*
|
|
16
|
+
* @param {Secret} nullifier - The nullifier to hash.
|
|
17
|
+
* @param {Secret} secret - The secret to hash.
|
|
18
|
+
* @returns {Hash} The Poseidon hash.
|
|
19
|
+
*/
|
|
20
|
+
export declare function hashPrecommitment(nullifier: Secret, secret: Secret): Hash;
|
|
21
|
+
/**
|
|
22
|
+
* Generates a commitment using the given parameters.
|
|
23
|
+
*
|
|
24
|
+
* @param {bigint} value - The value associated with the commitment.
|
|
25
|
+
* @param {bigint} label - The label used for the commitment.
|
|
26
|
+
* @param {Secret} nullifier - The nullifier used in the precommitment.
|
|
27
|
+
* @param {Secret} secret - The secret used in the precommitment.
|
|
28
|
+
* @returns {Commitment} The generated commitment object.
|
|
29
|
+
*/
|
|
30
|
+
export declare function getCommitment(value: bigint, label: bigint, nullifier: Secret, secret: Secret): Commitment;
|
|
31
|
+
/**
|
|
32
|
+
* Generates a Merkle inclusion proof for a given leaf in a set of leaves.
|
|
33
|
+
*
|
|
34
|
+
* @param {bigint[]} leaves - Array of leaves for the Lean Incremental Merkle tree.
|
|
35
|
+
* @param {bigint} leaf - The specific leaf to generate the inclusion proof for.
|
|
36
|
+
* @returns {LeanIMTMerkleProof<bigint>} A lean incremental Merkle tree inclusion proof.
|
|
37
|
+
* @throws {Error} If the leaf is not found in the leaves array.
|
|
38
|
+
*/
|
|
39
|
+
export declare function generateMerkleProof(leaves: bigint[], leaf: bigint): LeanIMTMerkleProof<bigint>;
|
|
40
|
+
export declare function bigintToHash(value: bigint): Hash;
|
|
41
|
+
export declare function bigintToHex(num: bigint | string | undefined): Hex;
|
|
42
|
+
/**
|
|
43
|
+
* Calculates the context hash for a withdrawal.
|
|
44
|
+
*/
|
|
45
|
+
export declare function calculateContext(withdrawal: Withdrawal, scope: Hash): string;
|
|
@@ -0,0 +1,52 @@
|
|
|
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
|
+
}
|
|
@@ -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";
|