zkenclave-sdk 0.1.0

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.
@@ -0,0 +1,209 @@
1
+ import { ethers } from 'ethers';
2
+
3
+ interface DepositNote {
4
+ commitment: Uint8Array;
5
+ secret: Uint8Array;
6
+ nullifierSeed: Uint8Array;
7
+ amount: bigint;
8
+ leafIndex: number;
9
+ timestamp: number;
10
+ }
11
+ interface WithdrawalRequest {
12
+ commitment: Uint8Array;
13
+ nullifier: Uint8Array;
14
+ recipient: string;
15
+ amount: bigint;
16
+ leafIndex: number;
17
+ merkleRoot?: Uint8Array;
18
+ merklePath: Uint8Array[];
19
+ pathIndices: boolean[];
20
+ }
21
+ interface WithdrawalResult {
22
+ success: boolean;
23
+ txHash?: string;
24
+ zkProof: Uint8Array;
25
+ nullifierHash: Uint8Array;
26
+ merkleRoot: Uint8Array;
27
+ timestamp: number;
28
+ error?: string;
29
+ }
30
+ interface DepositResult {
31
+ success: boolean;
32
+ txHash: string;
33
+ commitment: Uint8Array;
34
+ leafIndex: number;
35
+ note: DepositNote;
36
+ }
37
+ interface ComplianceProof {
38
+ id: string;
39
+ depositCommitment?: Uint8Array;
40
+ associationRoot: Uint8Array;
41
+ zkProof?: Uint8Array;
42
+ proof: Uint8Array;
43
+ valid: boolean;
44
+ timestamp: number;
45
+ }
46
+ interface MerkleProof {
47
+ path: Uint8Array[];
48
+ indices: boolean[];
49
+ root: Uint8Array;
50
+ }
51
+ interface TEEAttestation {
52
+ dataHash: Uint8Array;
53
+ timestamp: number;
54
+ enclaveId: Uint8Array;
55
+ signature: Uint8Array;
56
+ }
57
+ interface VaultConfig {
58
+ vaultAddress: string;
59
+ zkVerifierAddress: string;
60
+ aspRegistryAddress: string;
61
+ chainId: number;
62
+ rpcUrl: string;
63
+ }
64
+ interface ASPProvider {
65
+ address: string;
66
+ name: string;
67
+ currentRoot: Uint8Array;
68
+ reputationScore: number;
69
+ active: boolean;
70
+ }
71
+ interface VaultStats {
72
+ totalDeposits: bigint;
73
+ totalWithdrawals: bigint;
74
+ nextLeafIndex: number;
75
+ latestRoot: Uint8Array;
76
+ }
77
+ type ProofStatus = "pending" | "verified" | "rejected" | "expired";
78
+ interface BatchWithdrawal {
79
+ requests: WithdrawalRequest[];
80
+ aggregatedProof?: Uint8Array;
81
+ status: ProofStatus;
82
+ }
83
+
84
+ declare class PrivacyVaultSDK {
85
+ private provider;
86
+ private signer;
87
+ private vault;
88
+ private _aspRegistry;
89
+ private zkClient;
90
+ private config;
91
+ private _merkleTree;
92
+ constructor(config: VaultConfig, signer?: ethers.Signer);
93
+ connect(signer: ethers.Signer): Promise<void>;
94
+ deposit(amount: bigint): Promise<DepositResult>;
95
+ withdraw(note: DepositNote, recipient: string): Promise<WithdrawalResult>;
96
+ getLatestRoot(): Promise<Uint8Array>;
97
+ getNextLeafIndex(): Promise<number>;
98
+ isNullifierUsed(nullifier: Uint8Array): Promise<boolean>;
99
+ isKnownRoot(root: Uint8Array): Promise<boolean>;
100
+ getVaultStats(): Promise<VaultStats>;
101
+ getConfig(): VaultConfig;
102
+ }
103
+
104
+ declare function generateRandomBytes(length: number): Uint8Array;
105
+ declare function bytesToHex(bytes: Uint8Array): string;
106
+ declare function hexToBytes(hex: string): Uint8Array;
107
+ declare function bigIntToBytes32(value: bigint): Uint8Array;
108
+ declare function bytes32ToBigInt(bytes: Uint8Array): bigint;
109
+ declare function poseidonHash(inputs: bigint[]): bigint;
110
+ declare function computeCommitment(secret: bigint, nullifierSeed: bigint, amount: bigint): bigint;
111
+ declare function computeNullifier(nullifierSeed: bigint, leafIndex: number): bigint;
112
+ declare function generateDepositNote(amount: bigint): DepositNote;
113
+ declare function serializeNote(note: DepositNote): string;
114
+ declare function deserializeNote(serialized: string): DepositNote;
115
+ declare function encryptNote(note: DepositNote, password: string): string;
116
+ declare function decryptNote(encrypted: string, password: string): DepositNote;
117
+ declare class MerkleTree {
118
+ private leaves;
119
+ private layers;
120
+ private readonly depth;
121
+ private readonly zeroValues;
122
+ constructor(depth?: number);
123
+ private computeZeroValues;
124
+ insert(leaf: bigint): number;
125
+ private rebuild;
126
+ getRoot(): bigint;
127
+ generateProof(index: number): MerkleProof;
128
+ verifyProof(leaf: bigint, proof: MerkleProof): boolean;
129
+ }
130
+
131
+ declare const MERKLE_TREE_DEPTH = 20;
132
+ declare const FIELD_SIZE: bigint;
133
+ declare const DEFAULT_GAS_LIMIT = 500000n;
134
+ declare const DEFAULT_BATCH_SIZE = 10;
135
+ declare const PROOF_EXPIRY_MS = 300000;
136
+ declare const CONTRACT_ADDRESSES: {
137
+ readonly ethereum: {
138
+ readonly mainnet: {
139
+ readonly vault: "0x0000000000000000000000000000000000000000";
140
+ readonly zkVerifier: "0x0000000000000000000000000000000000000000";
141
+ readonly aspRegistry: "0x0000000000000000000000000000000000000000";
142
+ };
143
+ readonly celoSepolia: {
144
+ readonly vault: "0x68F19280d3030eaE36B8Da42621B66e92a8AEA32";
145
+ readonly zkVerifier: "0x68491614a84C0410E9Fc0CB59Fc60A4F9188687c";
146
+ readonly aspRegistry: "0xB041Cff58FB866c7f4326e0767c97B93434aBa9E";
147
+ };
148
+ readonly horizenSepolia: {
149
+ readonly vault: "0x68F19280d3030eaE36B8Da42621B66e92a8AEA32";
150
+ readonly zkVerifier: "0x68491614a84C0410E9Fc0CB59Fc60A4F9188687c";
151
+ readonly aspRegistry: "0xB041Cff58FB866c7f4326e0767c97B93434aBa9E";
152
+ };
153
+ };
154
+ readonly phala: {
155
+ readonly mainnet: {
156
+ readonly phatContract: "";
157
+ };
158
+ readonly testnet: {
159
+ readonly phatContract: "";
160
+ };
161
+ };
162
+ };
163
+ declare const CHAIN_CONFIG: {
164
+ readonly 1: {
165
+ readonly name: "Ethereum Mainnet";
166
+ readonly rpcUrl: "https://eth.llamarpc.com";
167
+ readonly explorer: "https://etherscan.io";
168
+ };
169
+ readonly 11142220: {
170
+ readonly name: "Celo Sepolia";
171
+ readonly rpcUrl: "https://forno.celo-sepolia.celo-testnet.org";
172
+ readonly explorer: "https://sepolia.celoscan.io";
173
+ };
174
+ readonly 2035: {
175
+ readonly name: "Phala L2";
176
+ readonly rpcUrl: "https://rpc.phala.network";
177
+ readonly explorer: "https://explorer.phala.network";
178
+ };
179
+ readonly 845320009: {
180
+ readonly name: "Horizen Sepolia Testnet";
181
+ readonly rpcUrl: "https://horizen-rpc-testnet.appchain.base.org";
182
+ readonly explorer: "https://explorer-horizen-testnet.appchain.base.org";
183
+ };
184
+ };
185
+ declare const POSEIDON_CONSTANTS: {
186
+ readonly T: 3;
187
+ readonly ROUNDS_F: 8;
188
+ readonly ROUNDS_P: 57;
189
+ };
190
+ declare const PRIVACY_VAULT_ABI: readonly ["function deposit(bytes32 commitment) external payable", "function withdraw(bytes32 nullifierHash, bytes32 root, address recipient, uint256 amount, bytes calldata zkProof, bytes calldata teeAttestation) external", "function withdrawWithCompliance(bytes32 nullifierHash, bytes32 root, address recipient, uint256 amount, bytes calldata zkProof, bytes calldata associationProof, address aspProvider) external", "function isKnownRoot(bytes32 root) external view returns (bool)", "function getLatestRoot() external view returns (bytes32)", "function getNextLeafIndex() external view returns (uint256)", "function isNullifierUsed(bytes32 nullifier) external view returns (bool)", "function getUserDeposits(address user) external view returns (bytes32[])", "event Deposit(bytes32 indexed commitment, uint256 leafIndex, uint256 amount, uint256 timestamp)", "event Withdrawal(bytes32 indexed nullifierHash, address indexed recipient, uint256 amount, bytes32 merkleRoot)"];
191
+ declare const ZK_VERIFIER_ABI: readonly ["function verifyProof(bytes calldata proof, bytes32[] calldata publicInputs) external returns (bool)", "function verifyProofView(bytes calldata proof, bytes32[] calldata publicInputs) external view returns (bool)", "function isProofVerified(bytes32 proofHash) external view returns (bool)"];
192
+ declare const ASP_REGISTRY_ABI: readonly ["function isRegistered(address provider) external view returns (bool)", "function getProviderRoot(address provider) external view returns (bytes32)", "function getActiveProviders() external view returns (address[])", "function getHighReputationProviders(uint256 minScore) external view returns (address[])"];
193
+ declare const ZERO_BYTES32: Uint8Array<ArrayBuffer>;
194
+ declare function getZeroNode(level: number): Uint8Array;
195
+
196
+ interface ZKProofClientConfig {
197
+ circuitPath?: string;
198
+ }
199
+ declare class ZKProofClient {
200
+ private config;
201
+ constructor(config?: ZKProofClientConfig);
202
+ generateWithdrawalProof(request: WithdrawalRequest): Promise<WithdrawalResult>;
203
+ generateComplianceProof(commitment: Uint8Array, associationRoot: Uint8Array): Promise<ComplianceProof>;
204
+ private computeNullifierHash;
205
+ private generateMockProof;
206
+ private hexToBytes;
207
+ }
208
+
209
+ export { type ASPProvider, ASP_REGISTRY_ABI, type BatchWithdrawal, CHAIN_CONFIG, CONTRACT_ADDRESSES, type ComplianceProof, DEFAULT_BATCH_SIZE, DEFAULT_GAS_LIMIT, type DepositNote, type DepositResult, FIELD_SIZE, MERKLE_TREE_DEPTH, type MerkleProof, MerkleTree, POSEIDON_CONSTANTS, PRIVACY_VAULT_ABI, PROOF_EXPIRY_MS, PrivacyVaultSDK, type ProofStatus, type TEEAttestation, type VaultConfig, type VaultStats, type WithdrawalRequest, type WithdrawalResult, ZERO_BYTES32, ZKProofClient, ZK_VERIFIER_ABI, bigIntToBytes32, bytes32ToBigInt, bytesToHex, computeCommitment, computeNullifier, decryptNote, deserializeNote, encryptNote, generateDepositNote, generateRandomBytes, getZeroNode, hexToBytes, poseidonHash, serializeNote };
@@ -0,0 +1,209 @@
1
+ import { ethers } from 'ethers';
2
+
3
+ interface DepositNote {
4
+ commitment: Uint8Array;
5
+ secret: Uint8Array;
6
+ nullifierSeed: Uint8Array;
7
+ amount: bigint;
8
+ leafIndex: number;
9
+ timestamp: number;
10
+ }
11
+ interface WithdrawalRequest {
12
+ commitment: Uint8Array;
13
+ nullifier: Uint8Array;
14
+ recipient: string;
15
+ amount: bigint;
16
+ leafIndex: number;
17
+ merkleRoot?: Uint8Array;
18
+ merklePath: Uint8Array[];
19
+ pathIndices: boolean[];
20
+ }
21
+ interface WithdrawalResult {
22
+ success: boolean;
23
+ txHash?: string;
24
+ zkProof: Uint8Array;
25
+ nullifierHash: Uint8Array;
26
+ merkleRoot: Uint8Array;
27
+ timestamp: number;
28
+ error?: string;
29
+ }
30
+ interface DepositResult {
31
+ success: boolean;
32
+ txHash: string;
33
+ commitment: Uint8Array;
34
+ leafIndex: number;
35
+ note: DepositNote;
36
+ }
37
+ interface ComplianceProof {
38
+ id: string;
39
+ depositCommitment?: Uint8Array;
40
+ associationRoot: Uint8Array;
41
+ zkProof?: Uint8Array;
42
+ proof: Uint8Array;
43
+ valid: boolean;
44
+ timestamp: number;
45
+ }
46
+ interface MerkleProof {
47
+ path: Uint8Array[];
48
+ indices: boolean[];
49
+ root: Uint8Array;
50
+ }
51
+ interface TEEAttestation {
52
+ dataHash: Uint8Array;
53
+ timestamp: number;
54
+ enclaveId: Uint8Array;
55
+ signature: Uint8Array;
56
+ }
57
+ interface VaultConfig {
58
+ vaultAddress: string;
59
+ zkVerifierAddress: string;
60
+ aspRegistryAddress: string;
61
+ chainId: number;
62
+ rpcUrl: string;
63
+ }
64
+ interface ASPProvider {
65
+ address: string;
66
+ name: string;
67
+ currentRoot: Uint8Array;
68
+ reputationScore: number;
69
+ active: boolean;
70
+ }
71
+ interface VaultStats {
72
+ totalDeposits: bigint;
73
+ totalWithdrawals: bigint;
74
+ nextLeafIndex: number;
75
+ latestRoot: Uint8Array;
76
+ }
77
+ type ProofStatus = "pending" | "verified" | "rejected" | "expired";
78
+ interface BatchWithdrawal {
79
+ requests: WithdrawalRequest[];
80
+ aggregatedProof?: Uint8Array;
81
+ status: ProofStatus;
82
+ }
83
+
84
+ declare class PrivacyVaultSDK {
85
+ private provider;
86
+ private signer;
87
+ private vault;
88
+ private _aspRegistry;
89
+ private zkClient;
90
+ private config;
91
+ private _merkleTree;
92
+ constructor(config: VaultConfig, signer?: ethers.Signer);
93
+ connect(signer: ethers.Signer): Promise<void>;
94
+ deposit(amount: bigint): Promise<DepositResult>;
95
+ withdraw(note: DepositNote, recipient: string): Promise<WithdrawalResult>;
96
+ getLatestRoot(): Promise<Uint8Array>;
97
+ getNextLeafIndex(): Promise<number>;
98
+ isNullifierUsed(nullifier: Uint8Array): Promise<boolean>;
99
+ isKnownRoot(root: Uint8Array): Promise<boolean>;
100
+ getVaultStats(): Promise<VaultStats>;
101
+ getConfig(): VaultConfig;
102
+ }
103
+
104
+ declare function generateRandomBytes(length: number): Uint8Array;
105
+ declare function bytesToHex(bytes: Uint8Array): string;
106
+ declare function hexToBytes(hex: string): Uint8Array;
107
+ declare function bigIntToBytes32(value: bigint): Uint8Array;
108
+ declare function bytes32ToBigInt(bytes: Uint8Array): bigint;
109
+ declare function poseidonHash(inputs: bigint[]): bigint;
110
+ declare function computeCommitment(secret: bigint, nullifierSeed: bigint, amount: bigint): bigint;
111
+ declare function computeNullifier(nullifierSeed: bigint, leafIndex: number): bigint;
112
+ declare function generateDepositNote(amount: bigint): DepositNote;
113
+ declare function serializeNote(note: DepositNote): string;
114
+ declare function deserializeNote(serialized: string): DepositNote;
115
+ declare function encryptNote(note: DepositNote, password: string): string;
116
+ declare function decryptNote(encrypted: string, password: string): DepositNote;
117
+ declare class MerkleTree {
118
+ private leaves;
119
+ private layers;
120
+ private readonly depth;
121
+ private readonly zeroValues;
122
+ constructor(depth?: number);
123
+ private computeZeroValues;
124
+ insert(leaf: bigint): number;
125
+ private rebuild;
126
+ getRoot(): bigint;
127
+ generateProof(index: number): MerkleProof;
128
+ verifyProof(leaf: bigint, proof: MerkleProof): boolean;
129
+ }
130
+
131
+ declare const MERKLE_TREE_DEPTH = 20;
132
+ declare const FIELD_SIZE: bigint;
133
+ declare const DEFAULT_GAS_LIMIT = 500000n;
134
+ declare const DEFAULT_BATCH_SIZE = 10;
135
+ declare const PROOF_EXPIRY_MS = 300000;
136
+ declare const CONTRACT_ADDRESSES: {
137
+ readonly ethereum: {
138
+ readonly mainnet: {
139
+ readonly vault: "0x0000000000000000000000000000000000000000";
140
+ readonly zkVerifier: "0x0000000000000000000000000000000000000000";
141
+ readonly aspRegistry: "0x0000000000000000000000000000000000000000";
142
+ };
143
+ readonly celoSepolia: {
144
+ readonly vault: "0x68F19280d3030eaE36B8Da42621B66e92a8AEA32";
145
+ readonly zkVerifier: "0x68491614a84C0410E9Fc0CB59Fc60A4F9188687c";
146
+ readonly aspRegistry: "0xB041Cff58FB866c7f4326e0767c97B93434aBa9E";
147
+ };
148
+ readonly horizenSepolia: {
149
+ readonly vault: "0x68F19280d3030eaE36B8Da42621B66e92a8AEA32";
150
+ readonly zkVerifier: "0x68491614a84C0410E9Fc0CB59Fc60A4F9188687c";
151
+ readonly aspRegistry: "0xB041Cff58FB866c7f4326e0767c97B93434aBa9E";
152
+ };
153
+ };
154
+ readonly phala: {
155
+ readonly mainnet: {
156
+ readonly phatContract: "";
157
+ };
158
+ readonly testnet: {
159
+ readonly phatContract: "";
160
+ };
161
+ };
162
+ };
163
+ declare const CHAIN_CONFIG: {
164
+ readonly 1: {
165
+ readonly name: "Ethereum Mainnet";
166
+ readonly rpcUrl: "https://eth.llamarpc.com";
167
+ readonly explorer: "https://etherscan.io";
168
+ };
169
+ readonly 11142220: {
170
+ readonly name: "Celo Sepolia";
171
+ readonly rpcUrl: "https://forno.celo-sepolia.celo-testnet.org";
172
+ readonly explorer: "https://sepolia.celoscan.io";
173
+ };
174
+ readonly 2035: {
175
+ readonly name: "Phala L2";
176
+ readonly rpcUrl: "https://rpc.phala.network";
177
+ readonly explorer: "https://explorer.phala.network";
178
+ };
179
+ readonly 845320009: {
180
+ readonly name: "Horizen Sepolia Testnet";
181
+ readonly rpcUrl: "https://horizen-rpc-testnet.appchain.base.org";
182
+ readonly explorer: "https://explorer-horizen-testnet.appchain.base.org";
183
+ };
184
+ };
185
+ declare const POSEIDON_CONSTANTS: {
186
+ readonly T: 3;
187
+ readonly ROUNDS_F: 8;
188
+ readonly ROUNDS_P: 57;
189
+ };
190
+ declare const PRIVACY_VAULT_ABI: readonly ["function deposit(bytes32 commitment) external payable", "function withdraw(bytes32 nullifierHash, bytes32 root, address recipient, uint256 amount, bytes calldata zkProof, bytes calldata teeAttestation) external", "function withdrawWithCompliance(bytes32 nullifierHash, bytes32 root, address recipient, uint256 amount, bytes calldata zkProof, bytes calldata associationProof, address aspProvider) external", "function isKnownRoot(bytes32 root) external view returns (bool)", "function getLatestRoot() external view returns (bytes32)", "function getNextLeafIndex() external view returns (uint256)", "function isNullifierUsed(bytes32 nullifier) external view returns (bool)", "function getUserDeposits(address user) external view returns (bytes32[])", "event Deposit(bytes32 indexed commitment, uint256 leafIndex, uint256 amount, uint256 timestamp)", "event Withdrawal(bytes32 indexed nullifierHash, address indexed recipient, uint256 amount, bytes32 merkleRoot)"];
191
+ declare const ZK_VERIFIER_ABI: readonly ["function verifyProof(bytes calldata proof, bytes32[] calldata publicInputs) external returns (bool)", "function verifyProofView(bytes calldata proof, bytes32[] calldata publicInputs) external view returns (bool)", "function isProofVerified(bytes32 proofHash) external view returns (bool)"];
192
+ declare const ASP_REGISTRY_ABI: readonly ["function isRegistered(address provider) external view returns (bool)", "function getProviderRoot(address provider) external view returns (bytes32)", "function getActiveProviders() external view returns (address[])", "function getHighReputationProviders(uint256 minScore) external view returns (address[])"];
193
+ declare const ZERO_BYTES32: Uint8Array<ArrayBuffer>;
194
+ declare function getZeroNode(level: number): Uint8Array;
195
+
196
+ interface ZKProofClientConfig {
197
+ circuitPath?: string;
198
+ }
199
+ declare class ZKProofClient {
200
+ private config;
201
+ constructor(config?: ZKProofClientConfig);
202
+ generateWithdrawalProof(request: WithdrawalRequest): Promise<WithdrawalResult>;
203
+ generateComplianceProof(commitment: Uint8Array, associationRoot: Uint8Array): Promise<ComplianceProof>;
204
+ private computeNullifierHash;
205
+ private generateMockProof;
206
+ private hexToBytes;
207
+ }
208
+
209
+ export { type ASPProvider, ASP_REGISTRY_ABI, type BatchWithdrawal, CHAIN_CONFIG, CONTRACT_ADDRESSES, type ComplianceProof, DEFAULT_BATCH_SIZE, DEFAULT_GAS_LIMIT, type DepositNote, type DepositResult, FIELD_SIZE, MERKLE_TREE_DEPTH, type MerkleProof, MerkleTree, POSEIDON_CONSTANTS, PRIVACY_VAULT_ABI, PROOF_EXPIRY_MS, PrivacyVaultSDK, type ProofStatus, type TEEAttestation, type VaultConfig, type VaultStats, type WithdrawalRequest, type WithdrawalResult, ZERO_BYTES32, ZKProofClient, ZK_VERIFIER_ABI, bigIntToBytes32, bytes32ToBigInt, bytesToHex, computeCommitment, computeNullifier, decryptNote, deserializeNote, encryptNote, generateDepositNote, generateRandomBytes, getZeroNode, hexToBytes, poseidonHash, serializeNote };