@cloak.dev/sdk 0.1.1 → 0.1.2

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 (2) hide show
  1. package/README.md +102 -13
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # @cloak.ag/sdk
1
+ # @cloak.dev/sdk
2
2
 
3
3
  TypeScript SDK for the Cloak Protocol - Private transactions on Solana using zero-knowledge proofs.
4
4
 
@@ -14,11 +14,11 @@ TypeScript SDK for the Cloak Protocol - Private transactions on Solana using zer
14
14
  ## Installation
15
15
 
16
16
  ```bash
17
- npm install @cloak.ag/sdk @solana/web3.js
17
+ npm install @cloak.dev/sdk @solana/web3.js
18
18
  # or
19
- yarn add @cloak.ag/sdk @solana/web3.js
19
+ yarn add @cloak.dev/sdk @solana/web3.js
20
20
  # or
21
- pnpm add @cloak.ag/sdk @solana/web3.js
21
+ pnpm add @cloak.dev/sdk @solana/web3.js
22
22
  ```
23
23
 
24
24
  **Note**: For swap functionality, you'll also need `@solana/spl-token`:
@@ -28,12 +28,101 @@ npm install @solana/spl-token
28
28
 
29
29
  ## Quick Start
30
30
 
31
- ### Risk Quote Configuration (Recommended)
31
+ ### SDK Defaults (Recommended)
32
32
 
33
- - Default production flow: set `CLOAK_RELAY_URL` and let relay handle Range quoting.
34
- - Keep `RANGE_API_KEY` only in relay/service backend, not in SDK clients.
35
- - SDK auto-uses `${CLOAK_RELAY_URL}/range-quote` when `relayUrl` is provided.
36
- - SDK-side `rangeApiKey` exists only as a server-side fallback (no-relay scenarios).
33
+ - Standard integrations should use SDK defaults for program, relay, and circuits.
34
+ - Do not expose protocol-level config (`programId`, relay URL, circuits URL) as end-user input.
35
+ - `transact`, `partialWithdraw`, and `fullWithdraw` already include stale-root retry handling.
36
+ - For simple CLI sends, require only `SOLANA_RPC_URL` and `KEYPAIR_PATH`.
37
+
38
+ ### Minimal Private SOL Send (Single File, Keypair)
39
+
40
+ Use this contract for one-shot scripts and AI-generated snippets.
41
+
42
+ ```ts
43
+ import { readFileSync } from "fs";
44
+ import {
45
+ CLOAK_PROGRAM_ID,
46
+ NATIVE_SOL_MINT,
47
+ createUtxo,
48
+ createZeroUtxo,
49
+ fullWithdraw,
50
+ generateUtxoKeypair,
51
+ transact,
52
+ } from "@cloak.dev/sdk";
53
+ import { Connection, Keypair, PublicKey } from "@solana/web3.js";
54
+
55
+ async function main() {
56
+ const [recipientArg, lamportsArg] = process.argv.slice(2);
57
+ if (!recipientArg || !lamportsArg) {
58
+ throw new Error("Usage: npx tsx send-sol-private.ts <recipientPubkey> <lamports>");
59
+ }
60
+
61
+ const rpcUrl = process.env.SOLANA_RPC_URL;
62
+ const keypairPath = process.env.KEYPAIR_PATH;
63
+ if (!rpcUrl || !keypairPath) {
64
+ throw new Error("Set SOLANA_RPC_URL and KEYPAIR_PATH");
65
+ }
66
+
67
+ const connection = new Connection(rpcUrl, "confirmed");
68
+ const signer = Keypair.fromSecretKey(
69
+ Uint8Array.from(JSON.parse(readFileSync(keypairPath, "utf8"))),
70
+ );
71
+
72
+ const recipient = new PublicKey(recipientArg);
73
+ const amountLamports = BigInt(lamportsArg);
74
+
75
+ const owner = await generateUtxoKeypair();
76
+ const output = await createUtxo(amountLamports, owner, NATIVE_SOL_MINT);
77
+
78
+ const deposited = await transact(
79
+ {
80
+ inputUtxos: [await createZeroUtxo(NATIVE_SOL_MINT)],
81
+ outputUtxos: [output],
82
+ externalAmount: amountLamports,
83
+ depositor: signer.publicKey,
84
+ },
85
+ {
86
+ connection,
87
+ programId: CLOAK_PROGRAM_ID,
88
+ depositorKeypair: signer,
89
+ walletPublicKey: signer.publicKey,
90
+ enforceViewingKeyRegistration: false,
91
+ },
92
+ );
93
+
94
+ const withdrawn = await fullWithdraw(deposited.outputUtxos, recipient, {
95
+ connection,
96
+ programId: CLOAK_PROGRAM_ID,
97
+ depositorKeypair: signer,
98
+ walletPublicKey: signer.publicKey,
99
+ cachedMerkleTree: deposited.merkleTree,
100
+ enforceViewingKeyRegistration: false,
101
+ });
102
+
103
+ console.log(withdrawn.signature);
104
+ }
105
+
106
+ main().catch((e) => {
107
+ console.error(e instanceof Error ? e.message : String(e));
108
+ process.exit(1);
109
+ });
110
+ ```
111
+
112
+ Run:
113
+
114
+ ```bash
115
+ SOLANA_RPC_URL="https://api.mainnet-beta.solana.com" \
116
+ KEYPAIR_PATH="/absolute/path/to/id.json" \
117
+ npx tsx send-sol-private.ts <recipientPubkey> <lamports>
118
+ ```
119
+
120
+ Hard rules for minimal scripts:
121
+
122
+ - Use lamports from CLI (`<lamports>`) and keep transaction math in `bigint`.
123
+ - Use `KEYPAIR_PATH`; do not ask for raw private key env vars.
124
+ - Do not parse SOL decimals with float math (`parseFloat`, `AMOUNT_SOL`).
125
+ - Keep `programId` fixed to `CLOAK_PROGRAM_ID` (no end-user override).
37
126
 
38
127
  ### Maintained Examples
39
128
 
@@ -66,7 +155,7 @@ npm run test:examples
66
155
  ### Node.js (with Keypair)
67
156
 
68
157
  ```typescript
69
- import { CloakSDK } from "@cloak.ag/sdk";
158
+ import { CloakSDK } from "@cloak.dev/sdk";
70
159
  import { Connection, Keypair, PublicKey } from "@solana/web3.js";
71
160
 
72
161
  // Initialize connection and keypair
@@ -96,7 +185,7 @@ console.log("Withdrawn! TX:", withdrawResult.signature);
96
185
  ### React/Next.js (with Wallet Adapter)
97
186
 
98
187
  ```typescript
99
- import { CloakSDK } from "@cloak.ag/sdk";
188
+ import { CloakSDK } from "@cloak.dev/sdk";
100
189
  import { useWallet, useConnection } from "@solana/wallet-adapter-react";
101
190
  import { PublicKey } from "@solana/web3.js";
102
191
 
@@ -181,7 +270,7 @@ const result = await sdk.swap(connection, note, recipientPublicKey, {
181
270
  Use `getDistributableAmount()` to calculate the amount after fees:
182
271
 
183
272
  ```typescript
184
- import { getDistributableAmount } from "@cloak.ag/sdk";
273
+ import { getDistributableAmount } from "@cloak.dev/sdk";
185
274
 
186
275
  const deposited = 100_000_000; // 0.1 SOL
187
276
  const afterFees = getDistributableAmount(deposited); // ~94,700,000 lamports
@@ -245,7 +334,7 @@ sequenceDiagram
245
334
  ## Error Handling
246
335
 
247
336
  ```typescript
248
- import { CloakError } from "@cloak.ag/sdk";
337
+ import { CloakError } from "@cloak.dev/sdk";
249
338
 
250
339
  try {
251
340
  await sdk.withdraw(connection, note, recipient);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloak.dev/sdk",
3
3
  "description": "TypeScript SDK for Cloak",
4
- "version": "0.1.1",
4
+ "version": "0.1.2",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
7
7
  "module": "dist/index.js",