@veil-cash/sdk 0.1.1 → 0.3.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 +285 -60
- package/dist/cli/index.cjs +589 -122
- package/dist/index.cjs +214 -30
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +172 -4
- package/dist/index.d.ts +172 -4
- package/dist/index.js +210 -32
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/abi.ts +30 -0
- package/src/addresses.ts +40 -1
- package/src/balance.ts +22 -15
- package/src/cli/commands/balance.ts +114 -54
- package/src/cli/commands/deposit.ts +79 -30
- package/src/cli/commands/init.ts +45 -8
- package/src/cli/commands/private-balance.ts +6 -1
- package/src/cli/commands/queue-balance.ts +5 -1
- package/src/cli/commands/register.ts +47 -12
- package/src/cli/commands/status.ts +129 -0
- package/src/cli/commands/transfer.ts +29 -4
- package/src/cli/commands/withdraw.ts +16 -2
- package/src/cli/index.ts +14 -11
- package/src/deposit.ts +106 -1
- package/src/index.ts +8 -2
- package/src/keypair.ts +79 -0
- package/src/relay.ts +2 -2
- package/src/transfer.ts +14 -11
- package/src/types.ts +9 -2
- package/src/withdraw.ts +7 -6
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
SDK and CLI for interacting with [Veil Cash](https://veil.cash) privacy pools on Base.
|
|
8
8
|
|
|
9
|
-
Generate keypairs, register, deposit, withdraw, and
|
|
9
|
+
Generate keypairs, register, deposit, withdraw, transfer, and merge ETH, USDC, and cbBTC privately.
|
|
10
10
|
|
|
11
11
|
## Installation
|
|
12
12
|
|
|
@@ -23,6 +23,14 @@ For global CLI access:
|
|
|
23
23
|
npm install -g @veil-cash/sdk
|
|
24
24
|
```
|
|
25
25
|
|
|
26
|
+
## Supported Assets
|
|
27
|
+
|
|
28
|
+
| Asset | Decimals | Token Contract |
|
|
29
|
+
|-------|----------|---------------|
|
|
30
|
+
| ETH | 18 | Native ETH (via WETH) |
|
|
31
|
+
| USDC | 6 | `0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913` |
|
|
32
|
+
| cbBTC | 8 | `0xcbB7C0000aB88B473b1f5aFd9ef808440eed33Bf` |
|
|
33
|
+
|
|
26
34
|
## CLI Quick Start
|
|
27
35
|
|
|
28
36
|
```bash
|
|
@@ -35,60 +43,115 @@ export WALLET_KEY=0x...
|
|
|
35
43
|
# 3. Register your deposit key (one-time)
|
|
36
44
|
veil register
|
|
37
45
|
|
|
38
|
-
# 4.
|
|
39
|
-
veil
|
|
46
|
+
# 4. Check your setup
|
|
47
|
+
veil status
|
|
48
|
+
|
|
49
|
+
# 5. Deposit (ETH, USDC, or cbBTC)
|
|
50
|
+
veil deposit ETH 0.1
|
|
51
|
+
veil deposit USDC 100
|
|
52
|
+
veil deposit CBBTC 0.001
|
|
40
53
|
|
|
41
|
-
#
|
|
42
|
-
veil balance
|
|
54
|
+
# 6. Check your balance
|
|
55
|
+
veil balance # ETH pool (default)
|
|
56
|
+
veil balance --pool usdc # USDC pool
|
|
57
|
+
veil balance --pool cbbtc # cbBTC pool
|
|
43
58
|
|
|
44
|
-
#
|
|
45
|
-
veil withdraw 0.05 0xRecipientAddress
|
|
59
|
+
# 7. Withdraw to any address
|
|
60
|
+
veil withdraw ETH 0.05 0xRecipientAddress
|
|
61
|
+
veil withdraw USDC 50 0xRecipientAddress
|
|
62
|
+
veil withdraw CBBTC 0.0005 0xRecipientAddress
|
|
46
63
|
|
|
47
|
-
#
|
|
48
|
-
veil transfer 0.02 0xRecipientAddress
|
|
64
|
+
# 8. Transfer privately to another registered user
|
|
65
|
+
veil transfer ETH 0.02 0xRecipientAddress
|
|
66
|
+
|
|
67
|
+
# 9. Merge small UTXOs (consolidate balances)
|
|
68
|
+
veil merge ETH 0.1
|
|
49
69
|
```
|
|
50
70
|
|
|
51
71
|
## CLI Commands
|
|
52
72
|
|
|
53
73
|
### `veil init`
|
|
54
74
|
|
|
55
|
-
Generate a
|
|
75
|
+
Generate or derive a Veil keypair.
|
|
56
76
|
|
|
57
77
|
```bash
|
|
58
|
-
veil init
|
|
59
|
-
veil init --force
|
|
60
|
-
veil init --json
|
|
61
|
-
veil init --
|
|
62
|
-
|
|
78
|
+
veil init # Random keypair, saves to .env.veil
|
|
79
|
+
veil init --force # Overwrite existing without prompting
|
|
80
|
+
veil init --json # Output as JSON (no prompts, no file save)
|
|
81
|
+
veil init --no-save # Print keypair without saving
|
|
82
|
+
|
|
83
|
+
# Derive from wallet (same keypair as frontend login)
|
|
84
|
+
veil init --sign-message --wallet-key 0x...
|
|
85
|
+
|
|
86
|
+
# Derive from a pre-computed EIP-191 signature (from Bankr, MPC, etc.)
|
|
87
|
+
veil init --signature 0x...
|
|
63
88
|
```
|
|
64
89
|
|
|
65
90
|
### `veil keypair`
|
|
66
91
|
|
|
67
|
-
|
|
92
|
+
Show current Veil keypair as JSON (from VEIL_KEY env).
|
|
68
93
|
|
|
69
94
|
```bash
|
|
70
95
|
veil keypair
|
|
71
96
|
# {"veilPrivateKey":"0x...","depositKey":"0x..."}
|
|
72
97
|
```
|
|
73
98
|
|
|
99
|
+
### `veil status`
|
|
100
|
+
|
|
101
|
+
Check configuration and service status.
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
veil status
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Output:
|
|
108
|
+
```json
|
|
109
|
+
{
|
|
110
|
+
"walletKey": { "found": true, "address": "0x..." },
|
|
111
|
+
"veilKey": { "found": true },
|
|
112
|
+
"depositKey": { "found": true, "key": "0x1234...abcd" },
|
|
113
|
+
"rpcUrl": { "found": false, "url": "https://mainnet.base.org" },
|
|
114
|
+
"registration": {
|
|
115
|
+
"checked": true,
|
|
116
|
+
"registered": true,
|
|
117
|
+
"matches": true,
|
|
118
|
+
"onChainKey": "0x..."
|
|
119
|
+
},
|
|
120
|
+
"relay": {
|
|
121
|
+
"checked": true,
|
|
122
|
+
"healthy": true,
|
|
123
|
+
"status": "ok",
|
|
124
|
+
"network": "mainnet"
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
```
|
|
128
|
+
|
|
74
129
|
### `veil register`
|
|
75
130
|
|
|
76
|
-
Register your deposit key on-chain
|
|
131
|
+
Register or update your deposit key on-chain.
|
|
77
132
|
|
|
78
133
|
```bash
|
|
79
|
-
veil register #
|
|
134
|
+
veil register # Register (first time)
|
|
80
135
|
veil register --json # JSON output
|
|
81
136
|
veil register --unsigned --address 0x... # Unsigned payload for agents
|
|
137
|
+
|
|
138
|
+
# Change deposit key (if already registered with a different key)
|
|
139
|
+
veil register --force # Change to local deposit key
|
|
140
|
+
veil register --force --unsigned # Unsigned change payload for agents
|
|
82
141
|
```
|
|
83
142
|
|
|
84
|
-
|
|
143
|
+
If already registered with the same key, the command exits successfully. If registered with a different key (e.g. after `veil init --sign-message`), use `--force` to update it on-chain.
|
|
85
144
|
|
|
86
|
-
|
|
145
|
+
### `veil deposit <asset> <amount>`
|
|
146
|
+
|
|
147
|
+
Deposit ETH, USDC, or cbBTC into the privacy pool. For USDC and cbBTC, the CLI automatically handles ERC20 approval before depositing.
|
|
87
148
|
|
|
88
149
|
```bash
|
|
89
|
-
veil deposit 0.1 #
|
|
90
|
-
veil deposit
|
|
91
|
-
veil deposit 0.
|
|
150
|
+
veil deposit ETH 0.1 # Deposit ETH
|
|
151
|
+
veil deposit USDC 100 # Approve + deposit USDC
|
|
152
|
+
veil deposit CBBTC 0.001 # Approve + deposit cbBTC
|
|
153
|
+
veil deposit ETH 0.1 --unsigned # Unsigned payload for agents
|
|
154
|
+
veil deposit ETH 0.1 --quiet # Suppress progress output
|
|
92
155
|
```
|
|
93
156
|
|
|
94
157
|
Output:
|
|
@@ -96,6 +159,7 @@ Output:
|
|
|
96
159
|
{
|
|
97
160
|
"success": true,
|
|
98
161
|
"hash": "0x...",
|
|
162
|
+
"asset": "ETH",
|
|
99
163
|
"amount": "0.1",
|
|
100
164
|
"blockNumber": "12345678",
|
|
101
165
|
"gasUsed": "150000"
|
|
@@ -107,7 +171,9 @@ Output:
|
|
|
107
171
|
Show both queue and private balances.
|
|
108
172
|
|
|
109
173
|
```bash
|
|
110
|
-
veil balance #
|
|
174
|
+
veil balance # ETH pool (default)
|
|
175
|
+
veil balance --pool usdc # USDC pool
|
|
176
|
+
veil balance --pool cbbtc # cbBTC pool
|
|
111
177
|
veil balance --quiet # Suppress progress output
|
|
112
178
|
```
|
|
113
179
|
|
|
@@ -115,6 +181,8 @@ Output:
|
|
|
115
181
|
```json
|
|
116
182
|
{
|
|
117
183
|
"address": "0x...",
|
|
184
|
+
"pool": "ETH",
|
|
185
|
+
"symbol": "ETH",
|
|
118
186
|
"depositKey": "0x...",
|
|
119
187
|
"totalBalance": "0.15",
|
|
120
188
|
"totalBalanceWei": "150000000000000000",
|
|
@@ -138,13 +206,15 @@ Output:
|
|
|
138
206
|
}
|
|
139
207
|
```
|
|
140
208
|
|
|
141
|
-
### `veil withdraw <amount> <recipient>`
|
|
209
|
+
### `veil withdraw <asset> <amount> <recipient>`
|
|
142
210
|
|
|
143
211
|
Withdraw from the privacy pool to any public address.
|
|
144
212
|
|
|
145
213
|
```bash
|
|
146
|
-
veil withdraw 0.05 0xRecipientAddress
|
|
147
|
-
veil withdraw
|
|
214
|
+
veil withdraw ETH 0.05 0xRecipientAddress
|
|
215
|
+
veil withdraw USDC 50 0xRecipientAddress
|
|
216
|
+
veil withdraw CBBTC 0.0005 0xRecipientAddress
|
|
217
|
+
veil withdraw ETH 0.05 0xRecipientAddress --quiet
|
|
148
218
|
```
|
|
149
219
|
|
|
150
220
|
Output:
|
|
@@ -153,19 +223,21 @@ Output:
|
|
|
153
223
|
"success": true,
|
|
154
224
|
"transactionHash": "0x...",
|
|
155
225
|
"blockNumber": 12345678,
|
|
226
|
+
"asset": "ETH",
|
|
156
227
|
"amount": "0.05",
|
|
157
|
-
"recipient": "0x..."
|
|
158
|
-
"type": "withdraw"
|
|
228
|
+
"recipient": "0x..."
|
|
159
229
|
}
|
|
160
230
|
```
|
|
161
231
|
|
|
162
|
-
### `veil transfer <amount> <recipient>`
|
|
232
|
+
### `veil transfer <asset> <amount> <recipient>`
|
|
163
233
|
|
|
164
234
|
Transfer privately to another registered Veil user.
|
|
165
235
|
|
|
166
236
|
```bash
|
|
167
|
-
veil transfer 0.02 0xRecipientAddress
|
|
168
|
-
veil transfer
|
|
237
|
+
veil transfer ETH 0.02 0xRecipientAddress
|
|
238
|
+
veil transfer USDC 25 0xRecipientAddress
|
|
239
|
+
veil transfer CBBTC 0.0002 0xRecipientAddress
|
|
240
|
+
veil transfer ETH 0.02 0xRecipientAddress --quiet
|
|
169
241
|
```
|
|
170
242
|
|
|
171
243
|
Output:
|
|
@@ -174,19 +246,34 @@ Output:
|
|
|
174
246
|
"success": true,
|
|
175
247
|
"transactionHash": "0x...",
|
|
176
248
|
"blockNumber": 12345678,
|
|
249
|
+
"asset": "ETH",
|
|
177
250
|
"amount": "0.02",
|
|
178
251
|
"recipient": "0x...",
|
|
179
252
|
"type": "transfer"
|
|
180
253
|
}
|
|
181
254
|
```
|
|
182
255
|
|
|
183
|
-
### `veil merge <amount>`
|
|
256
|
+
### `veil merge <asset> <amount>`
|
|
184
257
|
|
|
185
258
|
Consolidate multiple small UTXOs into one (self-transfer).
|
|
186
259
|
|
|
187
260
|
```bash
|
|
188
|
-
veil merge 0.1 # Merge UTXOs totaling 0.1 ETH
|
|
189
|
-
veil merge
|
|
261
|
+
veil merge ETH 0.1 # Merge ETH UTXOs totaling 0.1 ETH
|
|
262
|
+
veil merge USDC 100 # Merge USDC UTXOs
|
|
263
|
+
veil merge CBBTC 0.001 # Merge cbBTC UTXOs
|
|
264
|
+
veil merge ETH 0.1 --quiet
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
Output:
|
|
268
|
+
```json
|
|
269
|
+
{
|
|
270
|
+
"success": true,
|
|
271
|
+
"transactionHash": "0x...",
|
|
272
|
+
"blockNumber": 12345678,
|
|
273
|
+
"asset": "ETH",
|
|
274
|
+
"amount": "0.1",
|
|
275
|
+
"type": "merge"
|
|
276
|
+
}
|
|
190
277
|
```
|
|
191
278
|
|
|
192
279
|
## Environment Variables
|
|
@@ -239,7 +326,12 @@ All CLI commands output JSON with standardized error codes:
|
|
|
239
326
|
## SDK Quick Start
|
|
240
327
|
|
|
241
328
|
```typescript
|
|
242
|
-
import {
|
|
329
|
+
import {
|
|
330
|
+
Keypair, buildRegisterTx, buildDepositETHTx,
|
|
331
|
+
buildDepositUSDCTx, buildApproveUSDCTx,
|
|
332
|
+
buildDepositCBBTCTx, buildApproveCBBTCTx,
|
|
333
|
+
withdraw, transfer,
|
|
334
|
+
} from '@veil-cash/sdk';
|
|
243
335
|
import { createWalletClient, http } from 'viem';
|
|
244
336
|
import { base } from 'viem/chains';
|
|
245
337
|
import { privateKeyToAccount } from 'viem/accounts';
|
|
@@ -264,18 +356,34 @@ await client.sendTransaction(registerTx);
|
|
|
264
356
|
// 4. Deposit ETH
|
|
265
357
|
const depositTx = buildDepositETHTx({
|
|
266
358
|
depositKey: keypair.depositKey(),
|
|
267
|
-
amount: '0.1',
|
|
359
|
+
amount: '0.1',
|
|
360
|
+
});
|
|
361
|
+
await client.sendTransaction({ ...depositTx, value: depositTx.value });
|
|
362
|
+
|
|
363
|
+
// 4b. Deposit USDC (approve first)
|
|
364
|
+
const approveTx = buildApproveUSDCTx({ amount: '100' });
|
|
365
|
+
await client.sendTransaction(approveTx);
|
|
366
|
+
const usdcTx = buildDepositUSDCTx({
|
|
367
|
+
depositKey: keypair.depositKey(),
|
|
368
|
+
amount: '100',
|
|
268
369
|
});
|
|
269
|
-
await client.sendTransaction(
|
|
270
|
-
|
|
271
|
-
|
|
370
|
+
await client.sendTransaction(usdcTx);
|
|
371
|
+
|
|
372
|
+
// 4c. Deposit cbBTC (approve first)
|
|
373
|
+
const approveCbbtcTx = buildApproveCBBTCTx({ amount: '0.001' });
|
|
374
|
+
await client.sendTransaction(approveCbbtcTx);
|
|
375
|
+
const cbbtcTx = buildDepositCBBTCTx({
|
|
376
|
+
depositKey: keypair.depositKey(),
|
|
377
|
+
amount: '0.001',
|
|
272
378
|
});
|
|
379
|
+
await client.sendTransaction(cbbtcTx);
|
|
273
380
|
|
|
274
381
|
// 5. Withdraw (sent via relayer, no wallet signing needed)
|
|
275
382
|
const withdrawResult = await withdraw({
|
|
276
383
|
amount: '0.05',
|
|
277
384
|
recipient: '0xRecipientAddress',
|
|
278
385
|
keypair,
|
|
386
|
+
pool: 'eth', // 'eth' | 'usdc' | 'cbbtc' (default: 'eth')
|
|
279
387
|
});
|
|
280
388
|
|
|
281
389
|
// 6. Transfer privately
|
|
@@ -283,6 +391,7 @@ const transferResult = await transfer({
|
|
|
283
391
|
amount: '0.02',
|
|
284
392
|
recipientAddress: '0xRecipientAddress',
|
|
285
393
|
senderKeypair: keypair,
|
|
394
|
+
pool: 'eth', // 'eth' | 'usdc' | 'cbbtc' (default: 'eth')
|
|
286
395
|
});
|
|
287
396
|
```
|
|
288
397
|
|
|
@@ -291,14 +400,27 @@ const transferResult = await transfer({
|
|
|
291
400
|
### Keypair
|
|
292
401
|
|
|
293
402
|
```typescript
|
|
294
|
-
import { Keypair } from '@veil-cash/sdk';
|
|
403
|
+
import { Keypair, VEIL_SIGNED_MESSAGE } from '@veil-cash/sdk';
|
|
404
|
+
import type { MessageSigner } from '@veil-cash/sdk';
|
|
295
405
|
|
|
296
|
-
// Generate
|
|
406
|
+
// Generate random keypair
|
|
297
407
|
const keypair = new Keypair();
|
|
298
408
|
|
|
299
409
|
// Restore from saved Veil private key
|
|
300
410
|
const restored = new Keypair(savedVeilKey);
|
|
301
411
|
|
|
412
|
+
// Derive from wallet key (same keypair as frontend login)
|
|
413
|
+
const derived = await Keypair.fromWalletKey('0xYOUR_WALLET_KEY');
|
|
414
|
+
|
|
415
|
+
// Derive from a raw EIP-191 signature
|
|
416
|
+
const fromSig = Keypair.fromSignature('0xSIGNATURE...');
|
|
417
|
+
|
|
418
|
+
// Derive from any external signer (Bankr, MPC, custodial, etc.)
|
|
419
|
+
const fromSigner = await Keypair.fromSigner(async (message) => {
|
|
420
|
+
// Sign `message` using any personal_sign provider and return the signature
|
|
421
|
+
return await mySigningService.personalSign(message);
|
|
422
|
+
});
|
|
423
|
+
|
|
302
424
|
// Get deposit key (for registration)
|
|
303
425
|
keypair.depositKey(); // '0x...' (130 hex chars)
|
|
304
426
|
|
|
@@ -309,72 +431,131 @@ keypair.privkey; // '0x...'
|
|
|
309
431
|
### Transaction Builders
|
|
310
432
|
|
|
311
433
|
```typescript
|
|
312
|
-
import {
|
|
434
|
+
import {
|
|
435
|
+
buildRegisterTx, buildChangeDepositKeyTx, buildDepositETHTx, buildDepositTx,
|
|
436
|
+
buildDepositUSDCTx, buildApproveUSDCTx,
|
|
437
|
+
buildDepositCBBTCTx, buildApproveCBBTCTx,
|
|
438
|
+
} from '@veil-cash/sdk';
|
|
313
439
|
|
|
314
|
-
// Register deposit key (
|
|
440
|
+
// Register deposit key (first time)
|
|
315
441
|
const registerTx = buildRegisterTx(depositKey, ownerAddress);
|
|
316
442
|
// → { to: '0x...', data: '0x...' }
|
|
317
443
|
|
|
444
|
+
// Change deposit key (must already be registered)
|
|
445
|
+
const changeTx = buildChangeDepositKeyTx(newDepositKey, ownerAddress);
|
|
446
|
+
// → { to: '0x...', data: '0x...' }
|
|
447
|
+
|
|
318
448
|
// Deposit ETH
|
|
319
449
|
const depositTx = buildDepositETHTx({
|
|
320
450
|
depositKey: keypair.depositKey(),
|
|
321
451
|
amount: '0.1',
|
|
322
452
|
});
|
|
323
453
|
// → { to: '0x...', data: '0x...', value: 100000000000000000n }
|
|
454
|
+
|
|
455
|
+
// Deposit USDC (approve + deposit)
|
|
456
|
+
const approveUsdcTx = buildApproveUSDCTx({ amount: '100' });
|
|
457
|
+
const depositUsdcTx = buildDepositUSDCTx({
|
|
458
|
+
depositKey: keypair.depositKey(),
|
|
459
|
+
amount: '100',
|
|
460
|
+
});
|
|
461
|
+
|
|
462
|
+
// Deposit cbBTC (approve + deposit)
|
|
463
|
+
const approveCbbtcTx = buildApproveCBBTCTx({ amount: '0.001' });
|
|
464
|
+
const depositCbbtcTx = buildDepositCBBTCTx({
|
|
465
|
+
depositKey: keypair.depositKey(),
|
|
466
|
+
amount: '0.001',
|
|
467
|
+
});
|
|
468
|
+
|
|
469
|
+
// Generic builder (routes by token)
|
|
470
|
+
const tx = buildDepositTx({
|
|
471
|
+
depositKey: keypair.depositKey(),
|
|
472
|
+
amount: '0.1',
|
|
473
|
+
token: 'ETH', // 'ETH' | 'USDC' | 'CBBTC'
|
|
474
|
+
});
|
|
324
475
|
```
|
|
325
476
|
|
|
326
477
|
### Withdraw & Transfer
|
|
327
478
|
|
|
479
|
+
All withdraw, transfer, and merge functions accept an optional `pool` parameter (`'eth'` | `'usdc'` | `'cbbtc'`), defaulting to `'eth'`.
|
|
480
|
+
|
|
328
481
|
```typescript
|
|
329
482
|
import { withdraw, transfer, mergeUtxos } from '@veil-cash/sdk';
|
|
330
483
|
|
|
331
|
-
// Withdraw to public address
|
|
484
|
+
// Withdraw ETH to public address
|
|
332
485
|
const withdrawResult = await withdraw({
|
|
333
486
|
amount: '0.05',
|
|
334
487
|
recipient: '0xRecipientAddress',
|
|
335
488
|
keypair,
|
|
489
|
+
pool: 'eth', // default
|
|
336
490
|
onProgress: (stage, detail) => console.log(stage, detail),
|
|
337
491
|
});
|
|
338
492
|
|
|
339
|
-
//
|
|
493
|
+
// Withdraw USDC
|
|
494
|
+
const withdrawUsdc = await withdraw({
|
|
495
|
+
amount: '50',
|
|
496
|
+
recipient: '0xRecipientAddress',
|
|
497
|
+
keypair,
|
|
498
|
+
pool: 'usdc',
|
|
499
|
+
});
|
|
500
|
+
|
|
501
|
+
// Transfer cbBTC to another registered user
|
|
340
502
|
const transferResult = await transfer({
|
|
341
|
-
amount: '0.
|
|
503
|
+
amount: '0.0002',
|
|
342
504
|
recipientAddress: '0xRecipientAddress',
|
|
343
505
|
senderKeypair: keypair,
|
|
506
|
+
pool: 'cbbtc',
|
|
344
507
|
});
|
|
345
508
|
|
|
346
509
|
// Merge UTXOs (consolidate small balances)
|
|
347
510
|
const mergeResult = await mergeUtxos({
|
|
348
511
|
amount: '0.1',
|
|
349
512
|
keypair,
|
|
513
|
+
pool: 'eth',
|
|
350
514
|
});
|
|
351
515
|
```
|
|
352
516
|
|
|
353
517
|
### Balance Queries
|
|
354
518
|
|
|
519
|
+
Balance functions accept an optional `pool` parameter (`'eth'` | `'usdc'` | `'cbbtc'`), defaulting to `'eth'`.
|
|
520
|
+
|
|
355
521
|
```typescript
|
|
356
522
|
import { getQueueBalance, getPrivateBalance } from '@veil-cash/sdk';
|
|
357
523
|
|
|
358
|
-
// Check queue balance (pending deposits)
|
|
524
|
+
// Check ETH queue balance (pending deposits)
|
|
359
525
|
const queueBalance = await getQueueBalance({
|
|
360
526
|
address: '0x...',
|
|
527
|
+
pool: 'eth', // default
|
|
361
528
|
});
|
|
362
529
|
|
|
363
|
-
// Check private balance (requires keypair)
|
|
530
|
+
// Check USDC private balance (requires keypair)
|
|
364
531
|
const privateBalance = await getPrivateBalance({
|
|
365
532
|
keypair,
|
|
533
|
+
pool: 'usdc',
|
|
534
|
+
});
|
|
535
|
+
|
|
536
|
+
// Check cbBTC private balance
|
|
537
|
+
const btcBalance = await getPrivateBalance({
|
|
538
|
+
keypair,
|
|
539
|
+
pool: 'cbbtc',
|
|
366
540
|
});
|
|
367
541
|
```
|
|
368
542
|
|
|
369
543
|
### Addresses
|
|
370
544
|
|
|
371
545
|
```typescript
|
|
372
|
-
import { getAddresses } from '@veil-cash/sdk';
|
|
546
|
+
import { getAddresses, getPoolAddress, getQueueAddress } from '@veil-cash/sdk';
|
|
373
547
|
|
|
374
548
|
const addresses = getAddresses();
|
|
375
549
|
console.log(addresses.entry); // Entry contract
|
|
376
550
|
console.log(addresses.ethPool); // ETH pool
|
|
377
|
-
console.log(addresses.
|
|
551
|
+
console.log(addresses.usdcPool); // USDC pool
|
|
552
|
+
console.log(addresses.cbbtcPool); // cbBTC pool
|
|
553
|
+
|
|
554
|
+
// Helper functions to resolve by pool name
|
|
555
|
+
console.log(getPoolAddress('eth')); // ETH pool address
|
|
556
|
+
console.log(getPoolAddress('usdc')); // USDC pool address
|
|
557
|
+
console.log(getPoolAddress('cbbtc')); // cbBTC pool address
|
|
558
|
+
console.log(getQueueAddress('cbbtc')); // cbBTC queue address
|
|
378
559
|
```
|
|
379
560
|
|
|
380
561
|
## For AI Agents
|
|
@@ -391,19 +572,54 @@ veil init --json
|
|
|
391
572
|
|
|
392
573
|
# Get unsigned transaction payloads for agent signing
|
|
393
574
|
veil register --unsigned --address 0x...
|
|
394
|
-
veil deposit 0.1 --unsigned
|
|
575
|
+
veil deposit ETH 0.1 --unsigned
|
|
576
|
+
veil deposit USDC 100 --unsigned # Outputs approve + deposit payloads
|
|
577
|
+
veil deposit CBBTC 0.001 --unsigned
|
|
395
578
|
|
|
396
579
|
# Suppress progress output for clean JSON
|
|
397
580
|
veil balance --quiet
|
|
398
|
-
veil
|
|
581
|
+
veil balance --pool usdc --quiet
|
|
582
|
+
veil withdraw ETH 0.05 0xRecipient --quiet
|
|
399
583
|
```
|
|
400
584
|
|
|
401
585
|
### Bankr Integration
|
|
402
586
|
|
|
587
|
+
#### Keypair Derivation via Bankr Sign API
|
|
588
|
+
|
|
589
|
+
Use `Keypair.fromSigner()` with Bankr's `POST /agent/sign` endpoint to derive the same keypair as the frontend:
|
|
590
|
+
|
|
591
|
+
```typescript
|
|
592
|
+
import { Keypair } from '@veil-cash/sdk';
|
|
593
|
+
|
|
594
|
+
const keypair = await Keypair.fromSigner(async (message) => {
|
|
595
|
+
const res = await fetch('https://api.bankr.bot/agent/sign', {
|
|
596
|
+
method: 'POST',
|
|
597
|
+
headers: { 'X-API-Key': BANKR_API_KEY, 'Content-Type': 'application/json' },
|
|
598
|
+
body: JSON.stringify({ signatureType: 'personal_sign', message }),
|
|
599
|
+
});
|
|
600
|
+
return (await res.json()).signature;
|
|
601
|
+
});
|
|
602
|
+
```
|
|
603
|
+
|
|
604
|
+
Or via CLI (two-step):
|
|
605
|
+
```bash
|
|
606
|
+
# 1. Get signature from Bankr sign API
|
|
607
|
+
SIG=$(curl -s -X POST "https://api.bankr.bot/agent/sign" \
|
|
608
|
+
-H "X-API-Key: $BANKR_API_KEY" \
|
|
609
|
+
-H "Content-Type: application/json" \
|
|
610
|
+
-d "{\"signatureType\":\"personal_sign\",\"message\":\"$(node -e "const{VEIL_SIGNED_MESSAGE}=require('@veil-cash/sdk');console.log(VEIL_SIGNED_MESSAGE)")\"}" \
|
|
611
|
+
| jq -r '.signature')
|
|
612
|
+
|
|
613
|
+
# 2. Derive keypair from signature
|
|
614
|
+
veil init --signature $SIG
|
|
615
|
+
```
|
|
616
|
+
|
|
617
|
+
#### Unsigned Transaction Payloads
|
|
618
|
+
|
|
403
619
|
Use `--unsigned` to get Bankr-compatible transaction payloads:
|
|
404
620
|
|
|
405
621
|
```bash
|
|
406
|
-
veil deposit 0.1 --unsigned
|
|
622
|
+
veil deposit ETH 0.1 --unsigned
|
|
407
623
|
# {"to":"0x...","data":"0x...","value":"100000000000000000","chainId":8453}
|
|
408
624
|
```
|
|
409
625
|
|
|
@@ -412,7 +628,7 @@ The `--unsigned` flag outputs the [Bankr arbitrary transaction format](https://g
|
|
|
412
628
|
### Programmatic SDK Usage
|
|
413
629
|
|
|
414
630
|
```typescript
|
|
415
|
-
import { Keypair, buildDepositETHTx, withdraw } from '@veil-cash/sdk';
|
|
631
|
+
import { Keypair, buildDepositETHTx, buildDepositTx, withdraw } from '@veil-cash/sdk';
|
|
416
632
|
|
|
417
633
|
// For deposits: build transaction, let agent sign via Bankr
|
|
418
634
|
const keypair = new Keypair(veilKey);
|
|
@@ -422,11 +638,19 @@ const tx = buildDepositETHTx({
|
|
|
422
638
|
});
|
|
423
639
|
// → { to, data, value } - pass to Bankr for signing
|
|
424
640
|
|
|
641
|
+
// Generic builder works for any asset
|
|
642
|
+
const usdcTx = buildDepositTx({
|
|
643
|
+
depositKey: keypair.depositKey(),
|
|
644
|
+
amount: '100',
|
|
645
|
+
token: 'USDC',
|
|
646
|
+
});
|
|
647
|
+
|
|
425
648
|
// For withdrawals: SDK handles ZK proofs, submits to relayer
|
|
426
649
|
const result = await withdraw({
|
|
427
650
|
amount: '0.05',
|
|
428
651
|
recipient: '0xRecipient',
|
|
429
652
|
keypair,
|
|
653
|
+
pool: 'eth', // 'eth' | 'usdc' | 'cbbtc'
|
|
430
654
|
});
|
|
431
655
|
// → { success, transactionHash, blockNumber }
|
|
432
656
|
```
|
|
@@ -435,14 +659,15 @@ const result = await withdraw({
|
|
|
435
659
|
|
|
436
660
|
1. **Generate Keypair**: Run `veil init` to create and save your Veil keypair
|
|
437
661
|
2. **Register**: Run `veil register` to link your deposit key on-chain (one-time)
|
|
438
|
-
3. **
|
|
439
|
-
4. **
|
|
440
|
-
5. **
|
|
662
|
+
3. **Check Status**: Run `veil status` to verify your setup
|
|
663
|
+
4. **Deposit**: Run `veil deposit <asset> <amount>` (e.g., `veil deposit ETH 0.1`, `veil deposit USDC 100`, `veil deposit CBBTC 0.001`)
|
|
664
|
+
5. **Wait**: The Veil deposit engine processes your deposit
|
|
665
|
+
6. **Done**: Your deposit is accepted into the privacy pool
|
|
441
666
|
|
|
442
667
|
## Withdrawal Flow
|
|
443
668
|
|
|
444
|
-
1. **Check Balance**: Run `veil balance
|
|
445
|
-
2. **Withdraw**: Run `veil withdraw <amount> <recipient>`
|
|
669
|
+
1. **Check Balance**: Run `veil balance --pool <pool>` to see your private balance
|
|
670
|
+
2. **Withdraw**: Run `veil withdraw <asset> <amount> <recipient>`
|
|
446
671
|
3. **Done**: The SDK builds ZK proofs and submits via the relayer
|
|
447
672
|
|
|
448
673
|
## License
|