@veil-cash/sdk 0.2.0 → 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 +218 -41
- package/dist/cli/index.cjs +507 -130
- 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 +76 -33
- 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/transfer.ts +23 -10
- package/src/cli/commands/withdraw.ts +13 -5
- package/src/cli/index.ts +1 -1
- 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, transfer, and merge ETH privately.
|
|
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
|
|
@@ -38,14 +46,20 @@ veil register
|
|
|
38
46
|
# 4. Check your setup
|
|
39
47
|
veil status
|
|
40
48
|
|
|
41
|
-
# 5. Deposit ETH
|
|
49
|
+
# 5. Deposit (ETH, USDC, or cbBTC)
|
|
42
50
|
veil deposit ETH 0.1
|
|
51
|
+
veil deposit USDC 100
|
|
52
|
+
veil deposit CBBTC 0.001
|
|
43
53
|
|
|
44
54
|
# 6. Check your balance
|
|
45
|
-
veil balance
|
|
55
|
+
veil balance # ETH pool (default)
|
|
56
|
+
veil balance --pool usdc # USDC pool
|
|
57
|
+
veil balance --pool cbbtc # cbBTC pool
|
|
46
58
|
|
|
47
59
|
# 7. Withdraw to any address
|
|
48
60
|
veil withdraw ETH 0.05 0xRecipientAddress
|
|
61
|
+
veil withdraw USDC 50 0xRecipientAddress
|
|
62
|
+
veil withdraw CBBTC 0.0005 0xRecipientAddress
|
|
49
63
|
|
|
50
64
|
# 8. Transfer privately to another registered user
|
|
51
65
|
veil transfer ETH 0.02 0xRecipientAddress
|
|
@@ -58,14 +72,19 @@ veil merge ETH 0.1
|
|
|
58
72
|
|
|
59
73
|
### `veil init`
|
|
60
74
|
|
|
61
|
-
Generate a
|
|
75
|
+
Generate or derive a Veil keypair.
|
|
62
76
|
|
|
63
77
|
```bash
|
|
64
|
-
veil init
|
|
65
|
-
veil init --force
|
|
66
|
-
veil init --json
|
|
67
|
-
veil init --
|
|
68
|
-
|
|
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...
|
|
69
88
|
```
|
|
70
89
|
|
|
71
90
|
### `veil keypair`
|
|
@@ -109,20 +128,28 @@ Output:
|
|
|
109
128
|
|
|
110
129
|
### `veil register`
|
|
111
130
|
|
|
112
|
-
Register your deposit key on-chain
|
|
131
|
+
Register or update your deposit key on-chain.
|
|
113
132
|
|
|
114
133
|
```bash
|
|
115
|
-
veil register #
|
|
134
|
+
veil register # Register (first time)
|
|
116
135
|
veil register --json # JSON output
|
|
117
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
|
|
118
141
|
```
|
|
119
142
|
|
|
120
|
-
|
|
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.
|
|
144
|
+
|
|
145
|
+
### `veil deposit <asset> <amount>`
|
|
121
146
|
|
|
122
|
-
Deposit ETH into the privacy pool.
|
|
147
|
+
Deposit ETH, USDC, or cbBTC into the privacy pool. For USDC and cbBTC, the CLI automatically handles ERC20 approval before depositing.
|
|
123
148
|
|
|
124
149
|
```bash
|
|
125
|
-
veil deposit ETH 0.1 #
|
|
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
|
|
126
153
|
veil deposit ETH 0.1 --unsigned # Unsigned payload for agents
|
|
127
154
|
veil deposit ETH 0.1 --quiet # Suppress progress output
|
|
128
155
|
```
|
|
@@ -132,6 +159,7 @@ Output:
|
|
|
132
159
|
{
|
|
133
160
|
"success": true,
|
|
134
161
|
"hash": "0x...",
|
|
162
|
+
"asset": "ETH",
|
|
135
163
|
"amount": "0.1",
|
|
136
164
|
"blockNumber": "12345678",
|
|
137
165
|
"gasUsed": "150000"
|
|
@@ -143,7 +171,9 @@ Output:
|
|
|
143
171
|
Show both queue and private balances.
|
|
144
172
|
|
|
145
173
|
```bash
|
|
146
|
-
veil balance #
|
|
174
|
+
veil balance # ETH pool (default)
|
|
175
|
+
veil balance --pool usdc # USDC pool
|
|
176
|
+
veil balance --pool cbbtc # cbBTC pool
|
|
147
177
|
veil balance --quiet # Suppress progress output
|
|
148
178
|
```
|
|
149
179
|
|
|
@@ -151,6 +181,8 @@ Output:
|
|
|
151
181
|
```json
|
|
152
182
|
{
|
|
153
183
|
"address": "0x...",
|
|
184
|
+
"pool": "ETH",
|
|
185
|
+
"symbol": "ETH",
|
|
154
186
|
"depositKey": "0x...",
|
|
155
187
|
"totalBalance": "0.15",
|
|
156
188
|
"totalBalanceWei": "150000000000000000",
|
|
@@ -174,12 +206,14 @@ Output:
|
|
|
174
206
|
}
|
|
175
207
|
```
|
|
176
208
|
|
|
177
|
-
### `veil withdraw
|
|
209
|
+
### `veil withdraw <asset> <amount> <recipient>`
|
|
178
210
|
|
|
179
211
|
Withdraw from the privacy pool to any public address.
|
|
180
212
|
|
|
181
213
|
```bash
|
|
182
214
|
veil withdraw ETH 0.05 0xRecipientAddress
|
|
215
|
+
veil withdraw USDC 50 0xRecipientAddress
|
|
216
|
+
veil withdraw CBBTC 0.0005 0xRecipientAddress
|
|
183
217
|
veil withdraw ETH 0.05 0xRecipientAddress --quiet
|
|
184
218
|
```
|
|
185
219
|
|
|
@@ -189,18 +223,20 @@ Output:
|
|
|
189
223
|
"success": true,
|
|
190
224
|
"transactionHash": "0x...",
|
|
191
225
|
"blockNumber": 12345678,
|
|
226
|
+
"asset": "ETH",
|
|
192
227
|
"amount": "0.05",
|
|
193
|
-
"recipient": "0x..."
|
|
194
|
-
"type": "withdraw"
|
|
228
|
+
"recipient": "0x..."
|
|
195
229
|
}
|
|
196
230
|
```
|
|
197
231
|
|
|
198
|
-
### `veil transfer
|
|
232
|
+
### `veil transfer <asset> <amount> <recipient>`
|
|
199
233
|
|
|
200
234
|
Transfer privately to another registered Veil user.
|
|
201
235
|
|
|
202
236
|
```bash
|
|
203
237
|
veil transfer ETH 0.02 0xRecipientAddress
|
|
238
|
+
veil transfer USDC 25 0xRecipientAddress
|
|
239
|
+
veil transfer CBBTC 0.0002 0xRecipientAddress
|
|
204
240
|
veil transfer ETH 0.02 0xRecipientAddress --quiet
|
|
205
241
|
```
|
|
206
242
|
|
|
@@ -210,18 +246,21 @@ Output:
|
|
|
210
246
|
"success": true,
|
|
211
247
|
"transactionHash": "0x...",
|
|
212
248
|
"blockNumber": 12345678,
|
|
249
|
+
"asset": "ETH",
|
|
213
250
|
"amount": "0.02",
|
|
214
251
|
"recipient": "0x...",
|
|
215
252
|
"type": "transfer"
|
|
216
253
|
}
|
|
217
254
|
```
|
|
218
255
|
|
|
219
|
-
### `veil merge
|
|
256
|
+
### `veil merge <asset> <amount>`
|
|
220
257
|
|
|
221
258
|
Consolidate multiple small UTXOs into one (self-transfer).
|
|
222
259
|
|
|
223
260
|
```bash
|
|
224
|
-
veil merge ETH 0.1 # Merge UTXOs totaling 0.1 ETH
|
|
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
|
|
225
264
|
veil merge ETH 0.1 --quiet
|
|
226
265
|
```
|
|
227
266
|
|
|
@@ -231,6 +270,7 @@ Output:
|
|
|
231
270
|
"success": true,
|
|
232
271
|
"transactionHash": "0x...",
|
|
233
272
|
"blockNumber": 12345678,
|
|
273
|
+
"asset": "ETH",
|
|
234
274
|
"amount": "0.1",
|
|
235
275
|
"type": "merge"
|
|
236
276
|
}
|
|
@@ -286,7 +326,12 @@ All CLI commands output JSON with standardized error codes:
|
|
|
286
326
|
## SDK Quick Start
|
|
287
327
|
|
|
288
328
|
```typescript
|
|
289
|
-
import {
|
|
329
|
+
import {
|
|
330
|
+
Keypair, buildRegisterTx, buildDepositETHTx,
|
|
331
|
+
buildDepositUSDCTx, buildApproveUSDCTx,
|
|
332
|
+
buildDepositCBBTCTx, buildApproveCBBTCTx,
|
|
333
|
+
withdraw, transfer,
|
|
334
|
+
} from '@veil-cash/sdk';
|
|
290
335
|
import { createWalletClient, http } from 'viem';
|
|
291
336
|
import { base } from 'viem/chains';
|
|
292
337
|
import { privateKeyToAccount } from 'viem/accounts';
|
|
@@ -311,18 +356,34 @@ await client.sendTransaction(registerTx);
|
|
|
311
356
|
// 4. Deposit ETH
|
|
312
357
|
const depositTx = buildDepositETHTx({
|
|
313
358
|
depositKey: keypair.depositKey(),
|
|
314
|
-
amount: '0.1',
|
|
359
|
+
amount: '0.1',
|
|
315
360
|
});
|
|
316
|
-
await client.sendTransaction({
|
|
317
|
-
|
|
318
|
-
|
|
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',
|
|
319
369
|
});
|
|
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',
|
|
378
|
+
});
|
|
379
|
+
await client.sendTransaction(cbbtcTx);
|
|
320
380
|
|
|
321
381
|
// 5. Withdraw (sent via relayer, no wallet signing needed)
|
|
322
382
|
const withdrawResult = await withdraw({
|
|
323
383
|
amount: '0.05',
|
|
324
384
|
recipient: '0xRecipientAddress',
|
|
325
385
|
keypair,
|
|
386
|
+
pool: 'eth', // 'eth' | 'usdc' | 'cbbtc' (default: 'eth')
|
|
326
387
|
});
|
|
327
388
|
|
|
328
389
|
// 6. Transfer privately
|
|
@@ -330,6 +391,7 @@ const transferResult = await transfer({
|
|
|
330
391
|
amount: '0.02',
|
|
331
392
|
recipientAddress: '0xRecipientAddress',
|
|
332
393
|
senderKeypair: keypair,
|
|
394
|
+
pool: 'eth', // 'eth' | 'usdc' | 'cbbtc' (default: 'eth')
|
|
333
395
|
});
|
|
334
396
|
```
|
|
335
397
|
|
|
@@ -338,14 +400,27 @@ const transferResult = await transfer({
|
|
|
338
400
|
### Keypair
|
|
339
401
|
|
|
340
402
|
```typescript
|
|
341
|
-
import { Keypair } from '@veil-cash/sdk';
|
|
403
|
+
import { Keypair, VEIL_SIGNED_MESSAGE } from '@veil-cash/sdk';
|
|
404
|
+
import type { MessageSigner } from '@veil-cash/sdk';
|
|
342
405
|
|
|
343
|
-
// Generate
|
|
406
|
+
// Generate random keypair
|
|
344
407
|
const keypair = new Keypair();
|
|
345
408
|
|
|
346
409
|
// Restore from saved Veil private key
|
|
347
410
|
const restored = new Keypair(savedVeilKey);
|
|
348
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
|
+
|
|
349
424
|
// Get deposit key (for registration)
|
|
350
425
|
keypair.depositKey(); // '0x...' (130 hex chars)
|
|
351
426
|
|
|
@@ -356,72 +431,131 @@ keypair.privkey; // '0x...'
|
|
|
356
431
|
### Transaction Builders
|
|
357
432
|
|
|
358
433
|
```typescript
|
|
359
|
-
import {
|
|
434
|
+
import {
|
|
435
|
+
buildRegisterTx, buildChangeDepositKeyTx, buildDepositETHTx, buildDepositTx,
|
|
436
|
+
buildDepositUSDCTx, buildApproveUSDCTx,
|
|
437
|
+
buildDepositCBBTCTx, buildApproveCBBTCTx,
|
|
438
|
+
} from '@veil-cash/sdk';
|
|
360
439
|
|
|
361
|
-
// Register deposit key (
|
|
440
|
+
// Register deposit key (first time)
|
|
362
441
|
const registerTx = buildRegisterTx(depositKey, ownerAddress);
|
|
363
442
|
// → { to: '0x...', data: '0x...' }
|
|
364
443
|
|
|
444
|
+
// Change deposit key (must already be registered)
|
|
445
|
+
const changeTx = buildChangeDepositKeyTx(newDepositKey, ownerAddress);
|
|
446
|
+
// → { to: '0x...', data: '0x...' }
|
|
447
|
+
|
|
365
448
|
// Deposit ETH
|
|
366
449
|
const depositTx = buildDepositETHTx({
|
|
367
450
|
depositKey: keypair.depositKey(),
|
|
368
451
|
amount: '0.1',
|
|
369
452
|
});
|
|
370
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
|
+
});
|
|
371
475
|
```
|
|
372
476
|
|
|
373
477
|
### Withdraw & Transfer
|
|
374
478
|
|
|
479
|
+
All withdraw, transfer, and merge functions accept an optional `pool` parameter (`'eth'` | `'usdc'` | `'cbbtc'`), defaulting to `'eth'`.
|
|
480
|
+
|
|
375
481
|
```typescript
|
|
376
482
|
import { withdraw, transfer, mergeUtxos } from '@veil-cash/sdk';
|
|
377
483
|
|
|
378
|
-
// Withdraw to public address
|
|
484
|
+
// Withdraw ETH to public address
|
|
379
485
|
const withdrawResult = await withdraw({
|
|
380
486
|
amount: '0.05',
|
|
381
487
|
recipient: '0xRecipientAddress',
|
|
382
488
|
keypair,
|
|
489
|
+
pool: 'eth', // default
|
|
383
490
|
onProgress: (stage, detail) => console.log(stage, detail),
|
|
384
491
|
});
|
|
385
492
|
|
|
386
|
-
//
|
|
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
|
|
387
502
|
const transferResult = await transfer({
|
|
388
|
-
amount: '0.
|
|
503
|
+
amount: '0.0002',
|
|
389
504
|
recipientAddress: '0xRecipientAddress',
|
|
390
505
|
senderKeypair: keypair,
|
|
506
|
+
pool: 'cbbtc',
|
|
391
507
|
});
|
|
392
508
|
|
|
393
509
|
// Merge UTXOs (consolidate small balances)
|
|
394
510
|
const mergeResult = await mergeUtxos({
|
|
395
511
|
amount: '0.1',
|
|
396
512
|
keypair,
|
|
513
|
+
pool: 'eth',
|
|
397
514
|
});
|
|
398
515
|
```
|
|
399
516
|
|
|
400
517
|
### Balance Queries
|
|
401
518
|
|
|
519
|
+
Balance functions accept an optional `pool` parameter (`'eth'` | `'usdc'` | `'cbbtc'`), defaulting to `'eth'`.
|
|
520
|
+
|
|
402
521
|
```typescript
|
|
403
522
|
import { getQueueBalance, getPrivateBalance } from '@veil-cash/sdk';
|
|
404
523
|
|
|
405
|
-
// Check queue balance (pending deposits)
|
|
524
|
+
// Check ETH queue balance (pending deposits)
|
|
406
525
|
const queueBalance = await getQueueBalance({
|
|
407
526
|
address: '0x...',
|
|
527
|
+
pool: 'eth', // default
|
|
408
528
|
});
|
|
409
529
|
|
|
410
|
-
// Check private balance (requires keypair)
|
|
530
|
+
// Check USDC private balance (requires keypair)
|
|
411
531
|
const privateBalance = await getPrivateBalance({
|
|
412
532
|
keypair,
|
|
533
|
+
pool: 'usdc',
|
|
534
|
+
});
|
|
535
|
+
|
|
536
|
+
// Check cbBTC private balance
|
|
537
|
+
const btcBalance = await getPrivateBalance({
|
|
538
|
+
keypair,
|
|
539
|
+
pool: 'cbbtc',
|
|
413
540
|
});
|
|
414
541
|
```
|
|
415
542
|
|
|
416
543
|
### Addresses
|
|
417
544
|
|
|
418
545
|
```typescript
|
|
419
|
-
import { getAddresses } from '@veil-cash/sdk';
|
|
546
|
+
import { getAddresses, getPoolAddress, getQueueAddress } from '@veil-cash/sdk';
|
|
420
547
|
|
|
421
548
|
const addresses = getAddresses();
|
|
422
549
|
console.log(addresses.entry); // Entry contract
|
|
423
550
|
console.log(addresses.ethPool); // ETH pool
|
|
424
|
-
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
|
|
425
559
|
```
|
|
426
560
|
|
|
427
561
|
## For AI Agents
|
|
@@ -439,14 +573,49 @@ veil init --json
|
|
|
439
573
|
# Get unsigned transaction payloads for agent signing
|
|
440
574
|
veil register --unsigned --address 0x...
|
|
441
575
|
veil deposit ETH 0.1 --unsigned
|
|
576
|
+
veil deposit USDC 100 --unsigned # Outputs approve + deposit payloads
|
|
577
|
+
veil deposit CBBTC 0.001 --unsigned
|
|
442
578
|
|
|
443
579
|
# Suppress progress output for clean JSON
|
|
444
580
|
veil balance --quiet
|
|
581
|
+
veil balance --pool usdc --quiet
|
|
445
582
|
veil withdraw ETH 0.05 0xRecipient --quiet
|
|
446
583
|
```
|
|
447
584
|
|
|
448
585
|
### Bankr Integration
|
|
449
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
|
+
|
|
450
619
|
Use `--unsigned` to get Bankr-compatible transaction payloads:
|
|
451
620
|
|
|
452
621
|
```bash
|
|
@@ -459,7 +628,7 @@ The `--unsigned` flag outputs the [Bankr arbitrary transaction format](https://g
|
|
|
459
628
|
### Programmatic SDK Usage
|
|
460
629
|
|
|
461
630
|
```typescript
|
|
462
|
-
import { Keypair, buildDepositETHTx, withdraw } from '@veil-cash/sdk';
|
|
631
|
+
import { Keypair, buildDepositETHTx, buildDepositTx, withdraw } from '@veil-cash/sdk';
|
|
463
632
|
|
|
464
633
|
// For deposits: build transaction, let agent sign via Bankr
|
|
465
634
|
const keypair = new Keypair(veilKey);
|
|
@@ -469,11 +638,19 @@ const tx = buildDepositETHTx({
|
|
|
469
638
|
});
|
|
470
639
|
// → { to, data, value } - pass to Bankr for signing
|
|
471
640
|
|
|
641
|
+
// Generic builder works for any asset
|
|
642
|
+
const usdcTx = buildDepositTx({
|
|
643
|
+
depositKey: keypair.depositKey(),
|
|
644
|
+
amount: '100',
|
|
645
|
+
token: 'USDC',
|
|
646
|
+
});
|
|
647
|
+
|
|
472
648
|
// For withdrawals: SDK handles ZK proofs, submits to relayer
|
|
473
649
|
const result = await withdraw({
|
|
474
650
|
amount: '0.05',
|
|
475
651
|
recipient: '0xRecipient',
|
|
476
652
|
keypair,
|
|
653
|
+
pool: 'eth', // 'eth' | 'usdc' | 'cbbtc'
|
|
477
654
|
});
|
|
478
655
|
// → { success, transactionHash, blockNumber }
|
|
479
656
|
```
|
|
@@ -483,14 +660,14 @@ const result = await withdraw({
|
|
|
483
660
|
1. **Generate Keypair**: Run `veil init` to create and save your Veil keypair
|
|
484
661
|
2. **Register**: Run `veil register` to link your deposit key on-chain (one-time)
|
|
485
662
|
3. **Check Status**: Run `veil status` to verify your setup
|
|
486
|
-
4. **Deposit**: Run `veil deposit
|
|
663
|
+
4. **Deposit**: Run `veil deposit <asset> <amount>` (e.g., `veil deposit ETH 0.1`, `veil deposit USDC 100`, `veil deposit CBBTC 0.001`)
|
|
487
664
|
5. **Wait**: The Veil deposit engine processes your deposit
|
|
488
665
|
6. **Done**: Your deposit is accepted into the privacy pool
|
|
489
666
|
|
|
490
667
|
## Withdrawal Flow
|
|
491
668
|
|
|
492
|
-
1. **Check Balance**: Run `veil balance
|
|
493
|
-
2. **Withdraw**: Run `veil withdraw
|
|
669
|
+
1. **Check Balance**: Run `veil balance --pool <pool>` to see your private balance
|
|
670
|
+
2. **Withdraw**: Run `veil withdraw <asset> <amount> <recipient>`
|
|
494
671
|
3. **Done**: The SDK builds ZK proofs and submits via the relayer
|
|
495
672
|
|
|
496
673
|
## License
|