@cloak.ag/sdk 1.0.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.
package/README.md ADDED
@@ -0,0 +1,180 @@
1
+ # @cloak.ag/sdk
2
+
3
+ TypeScript SDK for the Cloak Protocol - Private transactions on Solana using zero-knowledge proofs.
4
+
5
+ ## Features
6
+
7
+ - 🔒 **Private Transfers**: Send SOL privately using zero-knowledge proofs
8
+ - 👥 **Multi-Recipient**: Support for 1-5 recipients in a single transaction
9
+ - 💱 **Token Swaps**: Swap SOL for SPL tokens privately
10
+ - 🔐 **Type-Safe**: Full TypeScript support with comprehensive types
11
+ - 🌐 **Cross-Platform**: Works in browser and Node.js
12
+ - ⚡ **Simple API**: Easy-to-use high-level client
13
+
14
+ ## Installation
15
+
16
+ ```bash
17
+ npm install @cloak.ag/sdk @solana/web3.js
18
+ # or
19
+ yarn add @cloak.ag/sdk @solana/web3.js
20
+ # or
21
+ pnpm add @cloak.ag/sdk @solana/web3.js
22
+ ```
23
+
24
+ **Note**: For swap functionality, you'll also need `@solana/spl-token`:
25
+ ```bash
26
+ npm install @solana/spl-token
27
+ ```
28
+
29
+ ## Quick Start
30
+
31
+ ```typescript
32
+ import { CloakSDK, generateNote } from "@cloak.ag/sdk";
33
+ import { Connection, Keypair, PublicKey } from "@solana/web3.js";
34
+
35
+ // Initialize connection and keypair
36
+ const connection = new Connection("https://api.devnet.solana.com");
37
+ const keypair = Keypair.fromSecretKey(/* your secret key */);
38
+
39
+ // Initialize SDK
40
+ const sdk = new CloakSDK({
41
+ keypairBytes: keypair.secretKey,
42
+ network: "devnet",
43
+ });
44
+
45
+ // Deposit SOL into the privacy pool
46
+ const depositResult = await sdk.deposit(connection, 100_000_000); // 0.1 SOL
47
+ console.log("Deposited! Leaf index:", depositResult.leafIndex);
48
+
49
+ // Withdraw to a recipient
50
+ const withdrawResult = await sdk.withdraw(
51
+ connection,
52
+ depositResult.note,
53
+ new PublicKey("RECIPIENT_ADDRESS"),
54
+ { withdrawAll: true }
55
+ );
56
+ console.log("Withdrawn! TX:", withdrawResult.signature);
57
+ ```
58
+
59
+ ## API Configuration
60
+
61
+ The SDK connects to `https://api.cloak.ag` by default. You can override this:
62
+
63
+ ```typescript
64
+ const sdk = new CloakSDK({
65
+ keypairBytes: keypair.secretKey,
66
+ network: "devnet",
67
+ indexerUrl: "http://localhost:3001", // Custom indexer
68
+ relayUrl: "http://localhost:3002", // Custom relay
69
+ });
70
+ ```
71
+
72
+ Or use environment variables:
73
+ - `CLOAK_INDEXER_URL` - Override indexer URL
74
+ - `CLOAK_RELAY_URL` - Override relay URL
75
+
76
+ ## Core Methods
77
+
78
+ ### Deposit
79
+
80
+ Deposit SOL into the privacy pool:
81
+
82
+ ```typescript
83
+ const result = await sdk.deposit(connection, 100_000_000); // 0.1 SOL
84
+ // Save the note securely - you need it to withdraw!
85
+ console.log(result.note);
86
+ ```
87
+
88
+ ### Withdraw
89
+
90
+ Withdraw to a single recipient:
91
+
92
+ ```typescript
93
+ const result = await sdk.withdraw(
94
+ connection,
95
+ note,
96
+ recipientPublicKey,
97
+ { withdrawAll: true }
98
+ );
99
+ ```
100
+
101
+ ### Send to Multiple Recipients
102
+
103
+ Send to up to 5 recipients:
104
+
105
+ ```typescript
106
+ const result = await sdk.send(connection, note, [
107
+ { recipient: addr1, amount: 50_000_000 },
108
+ { recipient: addr2, amount: 47_000_000 },
109
+ ]);
110
+ ```
111
+
112
+ ### Swap
113
+
114
+ Swap SOL for SPL tokens:
115
+
116
+ ```typescript
117
+ const result = await sdk.swap(connection, note, recipientPublicKey, {
118
+ outputMint: "TOKEN_MINT_ADDRESS",
119
+ minOutputAmount: 1000000,
120
+ });
121
+ ```
122
+
123
+ ## Fee Structure
124
+
125
+ - **Fixed Fee**: 0.003 SOL (3,000,000 lamports)
126
+ - **Variable Fee**: 0.5% of deposit amount
127
+
128
+ Use `getDistributableAmount()` to calculate the amount after fees:
129
+
130
+ ```typescript
131
+ import { getDistributableAmount } from "@cloak.ag/sdk";
132
+
133
+ const deposited = 100_000_000; // 0.1 SOL
134
+ const afterFees = getDistributableAmount(deposited); // ~97,000,000 lamports
135
+ ```
136
+
137
+ ## Notes
138
+
139
+ A **Cloak Note** is a cryptographic commitment representing a private amount of SOL:
140
+
141
+ ```typescript
142
+ interface CloakNote {
143
+ version: string;
144
+ amount: number; // Amount in lamports
145
+ commitment: string; // Commitment hash
146
+ sk_spend: string; // Spending key (keep secret!)
147
+ r: string; // Randomness
148
+ timestamp: number;
149
+ network: Network;
150
+ leafIndex?: number; // Set after deposit
151
+ depositSignature?: string;
152
+ }
153
+ ```
154
+
155
+ **⚠️ Important**: Save your notes securely! Without the note, you cannot withdraw your funds.
156
+
157
+ ## Error Handling
158
+
159
+ ```typescript
160
+ import { CloakError } from "@cloak.ag/sdk";
161
+
162
+ try {
163
+ await sdk.withdraw(connection, note, recipient);
164
+ } catch (error) {
165
+ if (error instanceof CloakError) {
166
+ console.log("Category:", error.category); // 'wallet', 'network', 'prover', etc.
167
+ console.log("Retryable:", error.retryable);
168
+ }
169
+ }
170
+ ```
171
+
172
+ ## Links
173
+
174
+ - Website: [https://cloak.ag](https://cloak.ag)
175
+ - Documentation: [https://docs.cloak.ag](https://docs.cloak.ag)
176
+ - GitHub: [https://github.com/cloak-labs/sdk](https://github.com/cloak-labs/sdk)
177
+
178
+ ## License
179
+
180
+ Apache-2.0