@0xbow/privacy-pools-core-sdk 0.0.0-3dpf8pk

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 (117) hide show
  1. package/README.md +73 -0
  2. package/dist/esm/fetchArtifacts.esm-DTr__iP-.js +18 -0
  3. package/dist/esm/fetchArtifacts.esm-DTr__iP-.js.map +1 -0
  4. package/dist/esm/fetchArtifacts.node-BLw8nwbt.js +31 -0
  5. package/dist/esm/fetchArtifacts.node-BLw8nwbt.js.map +1 -0
  6. package/dist/esm/index-Derz3sX9.js +73457 -0
  7. package/dist/esm/index-Derz3sX9.js.map +1 -0
  8. package/dist/esm/index.mjs +7 -0
  9. package/dist/esm/index.mjs.map +1 -0
  10. package/dist/index.d.mts +1326 -0
  11. package/dist/node/fetchArtifacts.esm-ZwE-hqnx.js +35 -0
  12. package/dist/node/fetchArtifacts.esm-ZwE-hqnx.js.map +1 -0
  13. package/dist/node/fetchArtifacts.node-CY8wLnXd.js +48 -0
  14. package/dist/node/fetchArtifacts.node-CY8wLnXd.js.map +1 -0
  15. package/dist/node/index-B804ILXn.js +80507 -0
  16. package/dist/node/index-B804ILXn.js.map +1 -0
  17. package/dist/node/index.mjs +24 -0
  18. package/dist/node/index.mjs.map +1 -0
  19. package/dist/types/abi/ERC20.d.ts +38 -0
  20. package/dist/types/abi/IEntrypoint.d.ts +823 -0
  21. package/dist/types/abi/IPrivacyPool.d.ts +51 -0
  22. package/dist/types/circuits/circuits.impl.d.ts +120 -0
  23. package/dist/types/circuits/circuits.interface.d.ts +129 -0
  24. package/dist/types/circuits/fetchArtifacts.d.ts +1 -0
  25. package/dist/types/circuits/fetchArtifacts.esm.d.ts +1 -0
  26. package/dist/types/circuits/fetchArtifacts.node.d.ts +1 -0
  27. package/dist/types/circuits/index.d.ts +2 -0
  28. package/dist/types/constants.d.ts +2 -0
  29. package/dist/types/core/account.service.d.ts +355 -0
  30. package/dist/types/core/bruteForce.service.d.ts +61 -0
  31. package/dist/types/core/commitment.service.d.ts +30 -0
  32. package/dist/types/core/contracts.service.d.ts +114 -0
  33. package/dist/types/core/data.service.d.ts +72 -0
  34. package/dist/types/core/sdk.d.ts +45 -0
  35. package/dist/types/core/withdrawal.service.d.ts +32 -0
  36. package/dist/types/crypto.d.ts +67 -0
  37. package/dist/types/dirname.helper.d.ts +2 -0
  38. package/dist/types/errors/account.error.d.ts +10 -0
  39. package/dist/types/errors/base.error.d.ts +53 -0
  40. package/dist/types/errors/data.error.d.ts +7 -0
  41. package/dist/types/errors/events.error.d.ts +9 -0
  42. package/dist/types/exceptions/circuitInitialization.exception.d.ts +3 -0
  43. package/dist/types/exceptions/fetchArtifacts.exception.d.ts +3 -0
  44. package/dist/types/exceptions/index.d.ts +4 -0
  45. package/dist/types/exceptions/invalidRpcUrl.exception.d.ts +3 -0
  46. package/dist/types/exceptions/privacyPool.exception.d.ts +13 -0
  47. package/dist/types/external.d.ts +7 -0
  48. package/dist/types/fetchArtifacts.esm-m-j0Hu4b.js +34 -0
  49. package/dist/types/fetchArtifacts.node-CGJMDWIh.js +47 -0
  50. package/dist/types/filename.helper.d.ts +2 -0
  51. package/dist/types/index-B6kM6ceO.js +80520 -0
  52. package/dist/types/index.d.ts +14 -0
  53. package/dist/types/index.js +23 -0
  54. package/dist/types/interfaces/blockchainProvider.interface.d.ts +12 -0
  55. package/dist/types/interfaces/circuits.interface.d.ts +30 -0
  56. package/dist/types/interfaces/contracts.interface.d.ts +35 -0
  57. package/dist/types/interfaces/index.d.ts +1 -0
  58. package/dist/types/internal.d.ts +6 -0
  59. package/dist/types/keys.d.ts +18 -0
  60. package/dist/types/providers/blockchainProvider.d.ts +8 -0
  61. package/dist/types/providers/index.d.ts +1 -0
  62. package/dist/types/types/account.d.ts +31 -0
  63. package/dist/types/types/commitment.d.ts +48 -0
  64. package/dist/types/types/events.d.ts +72 -0
  65. package/dist/types/types/index.d.ts +4 -0
  66. package/dist/types/types/keys.d.ts +5 -0
  67. package/dist/types/types/rateLimit.d.ts +51 -0
  68. package/dist/types/types/withdrawal.d.ts +30 -0
  69. package/dist/types/utils/logger.d.ts +22 -0
  70. package/package.json +84 -0
  71. package/src/abi/ERC20.ts +222 -0
  72. package/src/abi/IEntrypoint.ts +1059 -0
  73. package/src/abi/IPrivacyPool.ts +576 -0
  74. package/src/circuits/circuits.impl.ts +232 -0
  75. package/src/circuits/circuits.interface.ts +166 -0
  76. package/src/circuits/fetchArtifacts.esm.ts +12 -0
  77. package/src/circuits/fetchArtifacts.node.ts +23 -0
  78. package/src/circuits/fetchArtifacts.ts +7 -0
  79. package/src/circuits/index.ts +2 -0
  80. package/src/constants.ts +3 -0
  81. package/src/core/account.service.ts +1343 -0
  82. package/src/core/bruteForce.service.ts +120 -0
  83. package/src/core/commitment.service.ts +84 -0
  84. package/src/core/contracts.service.ts +442 -0
  85. package/src/core/data.service.ts +608 -0
  86. package/src/core/sdk.ts +92 -0
  87. package/src/core/withdrawal.service.ts +126 -0
  88. package/src/crypto.ts +226 -0
  89. package/src/dirname.helper.ts +4 -0
  90. package/src/errors/account.error.ts +49 -0
  91. package/src/errors/base.error.ts +125 -0
  92. package/src/errors/data.error.ts +34 -0
  93. package/src/errors/events.error.ts +38 -0
  94. package/src/exceptions/circuitInitialization.exception.ts +6 -0
  95. package/src/exceptions/fetchArtifacts.exception.ts +7 -0
  96. package/src/exceptions/index.ts +4 -0
  97. package/src/exceptions/invalidRpcUrl.exception.ts +6 -0
  98. package/src/exceptions/privacyPool.exception.ts +19 -0
  99. package/src/external.ts +13 -0
  100. package/src/filename.helper.ts +4 -0
  101. package/src/index.ts +25 -0
  102. package/src/interfaces/blockchainProvider.interface.ts +13 -0
  103. package/src/interfaces/circuits.interface.ts +34 -0
  104. package/src/interfaces/contracts.interface.ts +66 -0
  105. package/src/interfaces/index.ts +1 -0
  106. package/src/internal.ts +6 -0
  107. package/src/keys.ts +42 -0
  108. package/src/providers/blockchainProvider.ts +26 -0
  109. package/src/providers/index.ts +1 -0
  110. package/src/types/account.ts +35 -0
  111. package/src/types/commitment.ts +50 -0
  112. package/src/types/events.ts +82 -0
  113. package/src/types/index.ts +4 -0
  114. package/src/types/keys.ts +6 -0
  115. package/src/types/rateLimit.ts +66 -0
  116. package/src/types/withdrawal.ts +33 -0
  117. package/src/utils/logger.ts +56 -0
package/src/index.ts ADDED
@@ -0,0 +1,25 @@
1
+ export * from "./types/index.js";
2
+ export * from "./crypto.js";
3
+ export * from "./external.js";
4
+ export { PrivacyPoolSDK } from "./core/sdk.js";
5
+
6
+ // Additional Types (not included in types/index.js)
7
+ export * from "./types/account.js";
8
+ export * from "./types/events.js";
9
+
10
+ // Errors
11
+ export * from "./errors/base.error.js";
12
+ export * from "./errors/account.error.js";
13
+
14
+ // Interfaces
15
+ export * from "./interfaces/circuits.interface.js";
16
+
17
+ // Services (exported for advanced usage)
18
+ export { CommitmentService } from "./core/commitment.service.js";
19
+ export { WithdrawalService } from "./core/withdrawal.service.js";
20
+ export { AccountService } from "./core/account.service.js";
21
+ export { DataService } from "./core/data.service.js";
22
+
23
+ // Logging utilities (exported so consumers can control log level)
24
+ export { Logger, LogLevel } from "./utils/logger.js";
25
+
@@ -0,0 +1,13 @@
1
+ import { Address } from "../internal.js";
2
+
3
+ /**
4
+ * Represents an interface for a blockchain provider.
5
+ */
6
+ export interface IBlockchainProvider {
7
+ /**
8
+ * Retrieves the balance of the specified address.
9
+ * @param {Address} address The address for which to retrieve the balance.
10
+ * @returns {Promise<bigint>} A Promise that resolves to the balance of the address.
11
+ */
12
+ getBalance(address: Address): Promise<bigint>;
13
+ }
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Available circuit types in the system.
3
+ */
4
+ export enum CircuitName {
5
+ Commitment = "commitment",
6
+ Withdraw = "withdraw",
7
+ }
8
+
9
+ /**
10
+ * Type for circuit input signals.
11
+ */
12
+ export type CircuitSignals = {
13
+ [key: string]: bigint | bigint[] | string;
14
+ };
15
+
16
+ /**
17
+ * Interface for accessing circuit-related resources.
18
+ */
19
+ export interface CircuitsInterface {
20
+ /**
21
+ * Gets the WASM binary for a circuit.
22
+ */
23
+ getWasm(name: CircuitName): Promise<Uint8Array>;
24
+
25
+ /**
26
+ * Gets the proving key for a circuit.
27
+ */
28
+ getProvingKey(name: CircuitName): Promise<Uint8Array>;
29
+
30
+ /**
31
+ * Gets the verification key for a circuit.
32
+ */
33
+ getVerificationKey(name: CircuitName): Promise<Uint8Array>;
34
+ }
@@ -0,0 +1,66 @@
1
+ import { Address } from "viem";
2
+ import { Withdrawal, WithdrawalProof } from "../types/withdrawal.js";
3
+ import { CommitmentProof, Hash } from "../types/commitment.js";
4
+
5
+ export interface SolidityGroth16Proof {
6
+ pA: [bigint, bigint];
7
+ pB: [[bigint, bigint], [bigint, bigint]];
8
+ pC: [bigint, bigint];
9
+ pubSignals: bigint[];
10
+ }
11
+
12
+ export interface AssetConfig {
13
+ pool: Address,
14
+ minimumDepositAmount: bigint,
15
+ vettingFeeBPS: bigint,
16
+ maxRelayFeeBPS: bigint
17
+ }
18
+
19
+ export interface TransactionResponse {
20
+ hash: string;
21
+ wait: () => Promise<void>;
22
+ }
23
+
24
+ export interface ContractInteractions {
25
+ depositERC20(
26
+ asset: Address,
27
+ amount: bigint,
28
+ precommitment: bigint,
29
+ ): Promise<TransactionResponse>;
30
+
31
+ depositETH(
32
+ amount: bigint,
33
+ precommitment: bigint,
34
+ ): Promise<TransactionResponse>;
35
+
36
+ withdraw(
37
+ withdrawal: Withdrawal,
38
+ withdrawalProof: WithdrawalProof,
39
+ scope: Hash,
40
+ ): Promise<TransactionResponse>;
41
+
42
+ relay(
43
+ withdrawal: Withdrawal,
44
+ withdrawalProof: WithdrawalProof,
45
+ scope: Hash,
46
+ ): Promise<TransactionResponse>;
47
+
48
+ ragequit(
49
+ commitmentProof: CommitmentProof,
50
+ privacyPoolAddress: Address,
51
+ ): Promise<TransactionResponse>;
52
+
53
+ getScope(privacyPoolAddress: Address): Promise<bigint>;
54
+ getStateRoot(privacyPoolAddress: Address): Promise<bigint>;
55
+ getStateSize(privacyPoolAddress: Address): Promise<bigint>;
56
+ getAssetConfig(assetAddress: Address): Promise<AssetConfig>;
57
+ getScopeData(
58
+ scope: bigint,
59
+ ): Promise<{ poolAddress: Address | null; assetAddress: Address | null }>;
60
+
61
+ approveERC20(
62
+ spenderAddress: Address,
63
+ tokenAddress: Address,
64
+ amount: bigint,
65
+ ): Promise<TransactionResponse>;
66
+ }
@@ -0,0 +1 @@
1
+ export * from "./blockchainProvider.interface.js";
@@ -0,0 +1,6 @@
1
+ export type { Address } from "viem";
2
+ export * from "./exceptions/index.js";
3
+ export * from "./interfaces/index.js";
4
+ export * from "./providers/index.js";
5
+ export * from "./circuits/index.js";
6
+ export * from "./constants.js";
package/src/keys.ts ADDED
@@ -0,0 +1,42 @@
1
+ import { poseidon } from "maci-crypto/build/ts/hashing.js";
2
+ import { Hash, Secret } from "./types/index.js";
3
+ import { Hex } from "viem";
4
+ import { generatePrivateKey } from "viem/accounts";
5
+
6
+ export function genMasterKeys(seed?: Hex): [Secret, Secret] {
7
+ const preimage = seed ? poseidon([BigInt(seed)]) : BigInt(generatePrivateKey());
8
+
9
+ const masterKey1 = poseidon([preimage, BigInt(1)]) as Secret;
10
+ const masterKey2 = poseidon([preimage, BigInt(2)]) as Secret;
11
+
12
+ return [masterKey1, masterKey2];
13
+ }
14
+
15
+ /**
16
+ * Computes a Poseidon hash for the given nullifier and secret.
17
+ *
18
+ * @param {Secret} nullifier - The nullifier to hash.
19
+ * @param {Secret} secret - The secret to hash.
20
+ * @returns {Hash} The Poseidon hash.
21
+ */
22
+ export function getDepositSecrets(
23
+ masterKey: [Secret, Secret],
24
+ scope: Hash,
25
+ index: bigint,
26
+ ): { nullifier: Secret; secret: Secret } {
27
+ const depositNullifier = poseidon([masterKey[0], scope, index]) as Secret;
28
+ const depositSecret = poseidon([masterKey[1], scope, index]) as Secret;
29
+
30
+ return { nullifier: depositNullifier, secret: depositSecret };
31
+ }
32
+
33
+ export function getWithdrawalSecrets(
34
+ masterKey: [Secret, Secret],
35
+ label: Hash,
36
+ index: bigint,
37
+ ): { nullifier: Secret; secret: Secret } {
38
+ const withdrawalNullifier = poseidon([masterKey[0], label, index]) as Secret;
39
+ const withdrawalSecret = poseidon([masterKey[1], label, index]) as Secret;
40
+
41
+ return { nullifier: withdrawalNullifier, secret: withdrawalSecret };
42
+ }
@@ -0,0 +1,26 @@
1
+ import type { Address, Chain, HttpTransport } from "viem";
2
+ import { createPublicClient, http } from "viem";
3
+ import { mainnet } from "viem/chains";
4
+
5
+ import { IBlockchainProvider, InvalidRpcUrl } from "../internal.js";
6
+
7
+ export class BlockchainProvider implements IBlockchainProvider {
8
+ private client: ReturnType<typeof createPublicClient<HttpTransport, Chain>>;
9
+
10
+ constructor(rpcUrl: string) {
11
+ // dummy check for the rpcUrl
12
+ if (!rpcUrl || !rpcUrl.startsWith("http")) {
13
+ throw new InvalidRpcUrl(rpcUrl);
14
+ }
15
+
16
+ this.client = createPublicClient({
17
+ chain: mainnet,
18
+ transport: http(rpcUrl),
19
+ });
20
+ }
21
+
22
+ /** @inheritdoc */
23
+ async getBalance(address: Address): Promise<bigint> {
24
+ return this.client.getBalance({ address });
25
+ }
26
+ }
@@ -0,0 +1 @@
1
+ export * from "./blockchainProvider.js";
@@ -0,0 +1,35 @@
1
+ import { Hash, Secret } from "./commitment.js";
2
+ import { Hex } from "viem";
3
+ import { RagequitEvent } from "./events.js";
4
+
5
+ export interface PoolAccount {
6
+ label: Hash;
7
+ deposit: AccountCommitment;
8
+ children: AccountCommitment[];
9
+ ragequit?: RagequitEvent
10
+ }
11
+
12
+ export interface AccountCommitment {
13
+ hash: Hash;
14
+ value: bigint;
15
+ label: Hash;
16
+ nullifier: Secret;
17
+ secret: Secret;
18
+ blockNumber: bigint;
19
+ timestamp?: bigint;
20
+ txHash: Hex;
21
+ }
22
+
23
+ export interface PrivacyPoolAccount {
24
+ masterKeys: [masterNullifier: Secret, masterSecret: Secret];
25
+ poolAccounts: Map<Hash, PoolAccount[]>;
26
+ creationTimestamp?: bigint;
27
+ lastUpdateTimestamp?: bigint;
28
+ }
29
+
30
+ export interface PoolInfo {
31
+ chainId: number;
32
+ address: Hex;
33
+ scope: Hash;
34
+ deploymentBlock: bigint;
35
+ }
@@ -0,0 +1,50 @@
1
+ import { Groth16Proof, PublicSignals } from "snarkjs";
2
+
3
+ /**
4
+ * Represents a hash value in the system.
5
+ * This is a branded type to ensure type safety.
6
+ */
7
+ export type Hash = bigint & { readonly __brand: unique symbol };
8
+
9
+ /**
10
+ * Represents a secret value in the system.
11
+ * This is a branded type to ensure type safety.
12
+ */
13
+ export type Secret = bigint & { readonly __brand: unique symbol };
14
+
15
+ /**
16
+ * Represents a precommitment structure containing the hash, nullifier, and secret.
17
+ * All hashes are computed using Poseidon.
18
+ */
19
+ export interface Precommitment {
20
+ readonly hash: Hash;
21
+ readonly nullifier: Secret;
22
+ readonly secret: Secret;
23
+ }
24
+
25
+ /**
26
+ * Represents the preimage of a commitment containing the value, label, and precommitment.
27
+ */
28
+ export interface CommitmentPreimage {
29
+ readonly value: bigint;
30
+ readonly label: bigint;
31
+ readonly precommitment: Precommitment;
32
+ }
33
+
34
+ /**
35
+ * Represents a complete commitment structure.
36
+ * All hashes are computed using Poseidon.
37
+ */
38
+ export interface Commitment {
39
+ readonly hash: Hash;
40
+ readonly nullifierHash: Hash;
41
+ readonly preimage: CommitmentPreimage;
42
+ }
43
+
44
+ /**
45
+ * Represents the result of a commitment proof operation.
46
+ */
47
+ export interface CommitmentProof {
48
+ readonly proof: Groth16Proof;
49
+ readonly publicSignals: PublicSignals;
50
+ }
@@ -0,0 +1,82 @@
1
+ import { Address, Hex } from "viem";
2
+ import { Hash } from "./commitment.js";
3
+
4
+ /**
5
+ * Represents a deposit event from a privacy pool
6
+ */
7
+ export interface DepositEvent {
8
+ depositor: string;
9
+ commitment: Hash;
10
+ label: Hash;
11
+ value: bigint;
12
+ precommitment: Hash;
13
+ blockNumber: bigint;
14
+ transactionHash: Hex;
15
+ }
16
+
17
+ /**
18
+ * Represents a withdrawal event from a privacy pool
19
+ */
20
+ export interface WithdrawalEvent {
21
+ withdrawn: bigint;
22
+ spentNullifier: Hash;
23
+ newCommitment: Hash;
24
+ blockNumber: bigint;
25
+ transactionHash: Hex;
26
+ }
27
+
28
+ /**
29
+ * Represents a ragequit event from a privacy pool
30
+ */
31
+ export interface RagequitEvent {
32
+ ragequitter: string;
33
+ commitment: Hash;
34
+ label: Hash;
35
+ value: bigint;
36
+ blockNumber: bigint;
37
+ transactionHash: Hex;
38
+ }
39
+
40
+ /**
41
+ * Configuration for a chain's data provider
42
+ */
43
+ export interface ChainConfig {
44
+ chainId: number;
45
+ privacyPoolAddress: Address;
46
+ startBlock: bigint;
47
+ rpcUrl: string;
48
+ }
49
+
50
+ /**
51
+ * Event filter options
52
+ */
53
+ export interface EventFilterOptions {
54
+ fromBlock?: bigint;
55
+ toBlock?: bigint;
56
+ depositor?: string;
57
+ limit?: number;
58
+ skip?: number;
59
+ }
60
+
61
+ /**
62
+ * Collection of pool events
63
+ */
64
+ export interface PoolEvents {
65
+ deposits: DepositEvent[];
66
+ withdrawals: WithdrawalEvent[];
67
+ }
68
+
69
+ export interface PoolEventsSuccess {
70
+ depositEvents: Map<Hash, DepositEvent>;
71
+ withdrawalEvents: Map<Hash, WithdrawalEvent>;
72
+ ragequitEvents: Map<Hash, RagequitEvent>;
73
+ }
74
+
75
+ export interface PoolEventsError {
76
+ reason: string;
77
+ scope: Hash;
78
+ }
79
+
80
+ export type PoolEventsResult = Map<Hash, PoolEventsSuccess | PoolEventsError>;
81
+
82
+ export type ProcessedDepositEventsResult = Map<Hash, DepositEvent>;
@@ -0,0 +1,4 @@
1
+ export * from "./commitment.js";
2
+ export * from "./withdrawal.js";
3
+ export * from "./keys.js";
4
+ export * from "./rateLimit.js";
@@ -0,0 +1,6 @@
1
+ import { Secret } from "./commitment.js";
2
+
3
+ export interface MasterKeys {
4
+ masterNullifier: Secret;
5
+ masterSecret: Secret;
6
+ }
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Configuration options for rate-limited log fetching
3
+ */
4
+ export interface LogFetchConfig {
5
+ /**
6
+ * Maximum number of blocks to fetch in a single RPC call.
7
+ * Default: 10000 (typical limit for most RPC providers)
8
+ */
9
+ blockChunkSize: number;
10
+
11
+ /**
12
+ * Maximum number of concurrent log fetch operations.
13
+ * Default: 3
14
+ */
15
+ concurrency: number;
16
+
17
+ /**
18
+ * Delay in milliseconds between chunk requests (for additional throttling).
19
+ * Default: 0 (no delay)
20
+ */
21
+ chunkDelayMs: number;
22
+
23
+ /**
24
+ * Whether to retry failed chunk fetches.
25
+ * Default: true
26
+ */
27
+ retryOnFailure: boolean;
28
+
29
+ /**
30
+ * Maximum number of retries for a failed chunk.
31
+ * Default: 3
32
+ */
33
+ maxRetries: number;
34
+
35
+ /**
36
+ * Base delay for exponential backoff on retries (ms).
37
+ * Default: 1000
38
+ */
39
+ retryBaseDelayMs: number;
40
+ }
41
+
42
+ /**
43
+ * Default log fetch configuration
44
+ */
45
+ export const DEFAULT_LOG_FETCH_CONFIG: LogFetchConfig = {
46
+ blockChunkSize: 10000,
47
+ concurrency: 3,
48
+ chunkDelayMs: 0,
49
+ retryOnFailure: true,
50
+ maxRetries: 3,
51
+ retryBaseDelayMs: 1000,
52
+ };
53
+
54
+ /**
55
+ * Per-chain log fetch configuration map
56
+ * Maps chainId to its specific LogFetchConfig
57
+ */
58
+ export type ChainLogFetchConfig = Map<number, Partial<LogFetchConfig>>;
59
+
60
+ /**
61
+ * Block range for chunked fetching
62
+ */
63
+ export interface BlockRange {
64
+ fromBlock: bigint;
65
+ toBlock: bigint;
66
+ }
@@ -0,0 +1,33 @@
1
+ import { Address, Hex } from "viem";
2
+ import { Groth16Proof, PublicSignals } from "snarkjs";
3
+ import { LeanIMTMerkleProof } from "@zk-kit/lean-imt";
4
+ import { Hash, Secret } from "./commitment.js";
5
+
6
+ /**
7
+ * Represents a withdrawal request in the system.
8
+ */
9
+ export interface Withdrawal {
10
+ readonly processooor: Address;
11
+ readonly data: Hex;
12
+ }
13
+
14
+ export interface WithdrawalProof {
15
+ readonly proof: Groth16Proof;
16
+ readonly publicSignals: PublicSignals;
17
+ }
18
+
19
+ /**
20
+ * Input parameters required for withdrawal proof generation.
21
+ */
22
+ export interface WithdrawalProofInput {
23
+ readonly context: bigint;
24
+ readonly withdrawalAmount: bigint;
25
+ readonly stateMerkleProof: LeanIMTMerkleProof<bigint>;
26
+ readonly aspMerkleProof: LeanIMTMerkleProof<bigint>;
27
+ readonly stateRoot: Hash;
28
+ readonly stateTreeDepth: bigint;
29
+ readonly aspRoot: Hash;
30
+ readonly aspTreeDepth: bigint;
31
+ readonly newSecret: Secret;
32
+ readonly newNullifier: Secret;
33
+ }
@@ -0,0 +1,56 @@
1
+ export enum LogLevel {
2
+ DEBUG = 0,
3
+ INFO = 1,
4
+ WARN = 2,
5
+ ERROR = 3,
6
+ }
7
+
8
+ export interface LoggerOptions {
9
+ level?: LogLevel;
10
+ prefix?: string;
11
+ enabled?: boolean;
12
+ }
13
+
14
+ export class Logger {
15
+ private level: LogLevel;
16
+ private prefix: string;
17
+ private enabled: boolean;
18
+
19
+ constructor(options: LoggerOptions = {}) {
20
+ this.level = options.level ?? LogLevel.INFO;
21
+ this.prefix = options.prefix ?? "";
22
+ this.enabled = options.enabled ?? true;
23
+ }
24
+
25
+ private formatMessage(level: string, message: string): string {
26
+ return `${new Date().toISOString()} [${this.prefix}::${level}] ${message}`;
27
+ }
28
+
29
+ debug(message: string, ...args: unknown[]): void {
30
+ if (this.enabled && this.level <= LogLevel.DEBUG) {
31
+ console.debug(this.formatMessage("DEBUG", message), ...args);
32
+ }
33
+ }
34
+
35
+ info(message: string, ...args: unknown[]): void {
36
+ if (this.enabled && this.level <= LogLevel.INFO) {
37
+ console.log(this.formatMessage("INFO", message), ...args);
38
+ }
39
+ }
40
+
41
+ warn(message: string, ...args: unknown[]): void {
42
+ if (this.enabled && this.level <= LogLevel.WARN) {
43
+ console.warn(this.formatMessage("WARN", message), ...args);
44
+ }
45
+ }
46
+
47
+ error(message: string, error?: Error, ...args: unknown[]): void {
48
+ if (this.enabled && this.level <= LogLevel.ERROR) {
49
+ console.error(
50
+ this.formatMessage("ERROR", message),
51
+ error?.stack ?? "",
52
+ ...args,
53
+ );
54
+ }
55
+ }
56
+ }