zkenclave-sdk 0.1.0 → 0.1.5
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 +91 -0
- package/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +9 -3
- package/dist/index.mjs +9 -3
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# zkenclave-sdk
|
|
2
|
+
|
|
3
|
+
Privacy-preserving vault SDK for Zero-Knowledge withdrawals on EVM chains.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install zkenclave-sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { PrivacyVaultSDK, ZKProofClient } from "zkenclave-sdk";
|
|
15
|
+
|
|
16
|
+
const sdk = new PrivacyVaultSDK(
|
|
17
|
+
{
|
|
18
|
+
vaultAddress: "0x68F19280d3030eaE36B8Da42621B66e92a8AEA32",
|
|
19
|
+
zkVerifierAddress: "0x68491614a84C0410E9Fc0CB59Fc60A4F9188687c",
|
|
20
|
+
aspRegistryAddress: "0xB041Cff58FB866c7f4326e0767c97B93434aBa9E",
|
|
21
|
+
chainId: 845320009,
|
|
22
|
+
rpcUrl: "https://horizen-rpc-testnet.appchain.base.org",
|
|
23
|
+
},
|
|
24
|
+
signer
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
// Deposit
|
|
28
|
+
const { note, txHash, leafIndex } = await sdk.deposit(parseEther("0.1"));
|
|
29
|
+
|
|
30
|
+
// Withdraw
|
|
31
|
+
const result = await sdk.withdraw(note, recipientAddress);
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Features
|
|
35
|
+
|
|
36
|
+
- **Privacy-preserving deposits** - Commitment-nullifier scheme
|
|
37
|
+
- **ZK proof generation** - Client-side via `ZKProofClient`
|
|
38
|
+
- **Multi-chain support** - Configurable RPC/chain
|
|
39
|
+
- **TypeScript** - Full type definitions
|
|
40
|
+
|
|
41
|
+
## API
|
|
42
|
+
|
|
43
|
+
### `PrivacyVaultSDK`
|
|
44
|
+
|
|
45
|
+
| Method | Description |
|
|
46
|
+
| ---------------------------- | ------------------------- |
|
|
47
|
+
| `deposit(amount)` | Deposit ETH, returns note |
|
|
48
|
+
| `withdraw(note, recipient)` | Withdraw using note |
|
|
49
|
+
| `getLatestRoot()` | Get current Merkle root |
|
|
50
|
+
| `getNextLeafIndex()` | Get next deposit index |
|
|
51
|
+
| `isNullifierUsed(nullifier)` | Check if nullifier spent |
|
|
52
|
+
|
|
53
|
+
### `ZKProofClient`
|
|
54
|
+
|
|
55
|
+
| Method | Description |
|
|
56
|
+
| ------------------------------------------- | ------------------------- |
|
|
57
|
+
| `generateWithdrawalProof(request)` | Generate ZK proof |
|
|
58
|
+
| `generateComplianceProof(commitment, root)` | Generate compliance proof |
|
|
59
|
+
|
|
60
|
+
## Types
|
|
61
|
+
|
|
62
|
+
```typescript
|
|
63
|
+
interface VaultConfig {
|
|
64
|
+
vaultAddress: string;
|
|
65
|
+
zkVerifierAddress: string;
|
|
66
|
+
aspRegistryAddress: string;
|
|
67
|
+
chainId: number;
|
|
68
|
+
rpcUrl: string;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
interface DepositNote {
|
|
72
|
+
commitment: Uint8Array;
|
|
73
|
+
secret: Uint8Array;
|
|
74
|
+
nullifierSeed: Uint8Array;
|
|
75
|
+
amount: bigint;
|
|
76
|
+
leafIndex: number;
|
|
77
|
+
timestamp: number;
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Deployed Contracts (Horizen Sepolia)
|
|
82
|
+
|
|
83
|
+
| Contract | Address |
|
|
84
|
+
| ------------ | -------------------------------------------- |
|
|
85
|
+
| PrivacyVault | `0x68F19280d3030eaE36B8Da42621B66e92a8AEA32` |
|
|
86
|
+
| ZKVerifier | `0x68491614a84C0410E9Fc0CB59Fc60A4F9188687c` |
|
|
87
|
+
| ASPRegistry | `0xB041Cff58FB866c7f4326e0767c97B93434aBa9E` |
|
|
88
|
+
|
|
89
|
+
## License
|
|
90
|
+
|
|
91
|
+
MIT
|
package/dist/index.d.mts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -482,6 +482,7 @@ var PrivacyVaultSDK = class {
|
|
|
482
482
|
provider;
|
|
483
483
|
signer = null;
|
|
484
484
|
vault;
|
|
485
|
+
readVault;
|
|
485
486
|
_aspRegistry;
|
|
486
487
|
zkClient;
|
|
487
488
|
config;
|
|
@@ -497,6 +498,11 @@ var PrivacyVaultSDK = class {
|
|
|
497
498
|
PRIVACY_VAULT_ABI,
|
|
498
499
|
this.signer ?? this.provider
|
|
499
500
|
);
|
|
501
|
+
this.readVault = new import_ethers3.ethers.Contract(
|
|
502
|
+
config.vaultAddress,
|
|
503
|
+
PRIVACY_VAULT_ABI,
|
|
504
|
+
this.provider
|
|
505
|
+
);
|
|
500
506
|
this._aspRegistry = new import_ethers3.ethers.Contract(
|
|
501
507
|
config.aspRegistryAddress,
|
|
502
508
|
ASP_REGISTRY_ABI,
|
|
@@ -589,15 +595,15 @@ var PrivacyVaultSDK = class {
|
|
|
589
595
|
};
|
|
590
596
|
}
|
|
591
597
|
async getLatestRoot() {
|
|
592
|
-
const root = await this.
|
|
598
|
+
const root = await this.readVault.getLatestRoot();
|
|
593
599
|
return hexToBytes(root);
|
|
594
600
|
}
|
|
595
601
|
async getNextLeafIndex() {
|
|
596
|
-
const index = await this.
|
|
602
|
+
const index = await this.readVault.getNextLeafIndex();
|
|
597
603
|
return Number(index);
|
|
598
604
|
}
|
|
599
605
|
async isNullifierUsed(nullifier) {
|
|
600
|
-
return await this.
|
|
606
|
+
return await this.readVault.isNullifierUsed(bytesToHex(nullifier));
|
|
601
607
|
}
|
|
602
608
|
async isKnownRoot(root) {
|
|
603
609
|
return await this.vault.isKnownRoot(bytesToHex(root));
|
package/dist/index.mjs
CHANGED
|
@@ -428,6 +428,7 @@ var PrivacyVaultSDK = class {
|
|
|
428
428
|
provider;
|
|
429
429
|
signer = null;
|
|
430
430
|
vault;
|
|
431
|
+
readVault;
|
|
431
432
|
_aspRegistry;
|
|
432
433
|
zkClient;
|
|
433
434
|
config;
|
|
@@ -443,6 +444,11 @@ var PrivacyVaultSDK = class {
|
|
|
443
444
|
PRIVACY_VAULT_ABI,
|
|
444
445
|
this.signer ?? this.provider
|
|
445
446
|
);
|
|
447
|
+
this.readVault = new ethers.Contract(
|
|
448
|
+
config.vaultAddress,
|
|
449
|
+
PRIVACY_VAULT_ABI,
|
|
450
|
+
this.provider
|
|
451
|
+
);
|
|
446
452
|
this._aspRegistry = new ethers.Contract(
|
|
447
453
|
config.aspRegistryAddress,
|
|
448
454
|
ASP_REGISTRY_ABI,
|
|
@@ -535,15 +541,15 @@ var PrivacyVaultSDK = class {
|
|
|
535
541
|
};
|
|
536
542
|
}
|
|
537
543
|
async getLatestRoot() {
|
|
538
|
-
const root = await this.
|
|
544
|
+
const root = await this.readVault.getLatestRoot();
|
|
539
545
|
return hexToBytes(root);
|
|
540
546
|
}
|
|
541
547
|
async getNextLeafIndex() {
|
|
542
|
-
const index = await this.
|
|
548
|
+
const index = await this.readVault.getNextLeafIndex();
|
|
543
549
|
return Number(index);
|
|
544
550
|
}
|
|
545
551
|
async isNullifierUsed(nullifier) {
|
|
546
|
-
return await this.
|
|
552
|
+
return await this.readVault.isNullifierUsed(bytesToHex(nullifier));
|
|
547
553
|
}
|
|
548
554
|
async isKnownRoot(root) {
|
|
549
555
|
return await this.vault.isKnownRoot(bytesToHex(root));
|