@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,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,2 @@
1
+ declare const _default: string;
2
+ export default _default;
@@ -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,3 @@
1
+ export declare class CircuitInitialization extends Error {
2
+ constructor(message: string);
3
+ }
@@ -0,0 +1,3 @@
1
+ export declare class FetchArtifact extends Error {
2
+ constructor(artifact: URL);
3
+ }
@@ -0,0 +1,4 @@
1
+ export * from "./invalidRpcUrl.exception.js";
2
+ export * from "./fetchArtifacts.exception.js";
3
+ export * from "./circuitInitialization.exception.js";
4
+ export * from "./privacyPool.exception.js";
@@ -0,0 +1,3 @@
1
+ export declare class InvalidRpcUrl extends Error {
2
+ constructor(url: string);
3
+ }
@@ -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,2 @@
1
+ declare const __filename: string;
2
+ export default __filename;