@veil-cash/sdk 0.2.0 → 0.4.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 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 and USDC privately.
10
10
 
11
11
  ## Installation
12
12
 
@@ -23,6 +23,13 @@ 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
+
26
33
  ## CLI Quick Start
27
34
 
28
35
  ```bash
@@ -38,14 +45,17 @@ veil register
38
45
  # 4. Check your setup
39
46
  veil status
40
47
 
41
- # 5. Deposit ETH
48
+ # 5. Deposit (ETH or USDC)
42
49
  veil deposit ETH 0.1
50
+ veil deposit USDC 100
43
51
 
44
52
  # 6. Check your balance
45
- veil balance
53
+ veil balance # ETH pool (default)
54
+ veil balance --pool usdc # USDC pool
46
55
 
47
56
  # 7. Withdraw to any address
48
57
  veil withdraw ETH 0.05 0xRecipientAddress
58
+ veil withdraw USDC 50 0xRecipientAddress
49
59
 
50
60
  # 8. Transfer privately to another registered user
51
61
  veil transfer ETH 0.02 0xRecipientAddress
@@ -58,14 +68,19 @@ veil merge ETH 0.1
58
68
 
59
69
  ### `veil init`
60
70
 
61
- Generate a new Veil keypair.
71
+ Generate or derive a Veil keypair.
62
72
 
63
73
  ```bash
64
- veil init # Interactive, saves to .env.veil
65
- veil init --force # Overwrite existing without prompting
66
- veil init --json # Output as JSON (no prompts, no file save)
67
- veil init --out path # Save to custom path
68
- veil init --no-save # Print keypair without saving
74
+ veil init # Random keypair, saves to .env.veil
75
+ veil init --force # Overwrite existing without prompting
76
+ veil init --json # Output as JSON (no prompts, no file save)
77
+ veil init --no-save # Print keypair without saving
78
+
79
+ # Derive from wallet (same keypair as frontend login)
80
+ veil init --sign-message --wallet-key 0x...
81
+
82
+ # Derive from a pre-computed EIP-191 signature (from Bankr, MPC, etc.)
83
+ veil init --signature 0x...
69
84
  ```
70
85
 
71
86
  ### `veil keypair`
@@ -109,20 +124,27 @@ Output:
109
124
 
110
125
  ### `veil register`
111
126
 
112
- Register your deposit key on-chain (one-time per address).
127
+ Register or update your deposit key on-chain.
113
128
 
114
129
  ```bash
115
- veil register # Signs & sends
130
+ veil register # Register (first time)
116
131
  veil register --json # JSON output
117
132
  veil register --unsigned --address 0x... # Unsigned payload for agents
133
+
134
+ # Change deposit key (if already registered with a different key)
135
+ veil register --force # Change to local deposit key
136
+ veil register --force --unsigned # Unsigned change payload for agents
118
137
  ```
119
138
 
120
- ### `veil deposit ETH <amount>`
139
+ 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.
140
+
141
+ ### `veil deposit <asset> <amount>`
121
142
 
122
- Deposit ETH into the privacy pool.
143
+ Deposit ETH or USDC into the privacy pool. For USDC, the CLI automatically handles ERC20 approval before depositing.
123
144
 
124
145
  ```bash
125
- veil deposit ETH 0.1 # Signs & sends (JSON output)
146
+ veil deposit ETH 0.1 # Deposit ETH
147
+ veil deposit USDC 100 # Approve + deposit USDC
126
148
  veil deposit ETH 0.1 --unsigned # Unsigned payload for agents
127
149
  veil deposit ETH 0.1 --quiet # Suppress progress output
128
150
  ```
@@ -132,6 +154,7 @@ Output:
132
154
  {
133
155
  "success": true,
134
156
  "hash": "0x...",
157
+ "asset": "ETH",
135
158
  "amount": "0.1",
136
159
  "blockNumber": "12345678",
137
160
  "gasUsed": "150000"
@@ -143,7 +166,8 @@ Output:
143
166
  Show both queue and private balances.
144
167
 
145
168
  ```bash
146
- veil balance # Show all balances
169
+ veil balance # ETH pool (default)
170
+ veil balance --pool usdc # USDC pool
147
171
  veil balance --quiet # Suppress progress output
148
172
  ```
149
173
 
@@ -151,6 +175,8 @@ Output:
151
175
  ```json
152
176
  {
153
177
  "address": "0x...",
178
+ "pool": "ETH",
179
+ "symbol": "ETH",
154
180
  "depositKey": "0x...",
155
181
  "totalBalance": "0.15",
156
182
  "totalBalanceWei": "150000000000000000",
@@ -174,12 +200,13 @@ Output:
174
200
  }
175
201
  ```
176
202
 
177
- ### `veil withdraw ETH <amount> <recipient>`
203
+ ### `veil withdraw <asset> <amount> <recipient>`
178
204
 
179
205
  Withdraw from the privacy pool to any public address.
180
206
 
181
207
  ```bash
182
208
  veil withdraw ETH 0.05 0xRecipientAddress
209
+ veil withdraw USDC 50 0xRecipientAddress
183
210
  veil withdraw ETH 0.05 0xRecipientAddress --quiet
184
211
  ```
185
212
 
@@ -189,18 +216,19 @@ Output:
189
216
  "success": true,
190
217
  "transactionHash": "0x...",
191
218
  "blockNumber": 12345678,
219
+ "asset": "ETH",
192
220
  "amount": "0.05",
193
- "recipient": "0x...",
194
- "type": "withdraw"
221
+ "recipient": "0x..."
195
222
  }
196
223
  ```
197
224
 
198
- ### `veil transfer ETH <amount> <recipient>`
225
+ ### `veil transfer <asset> <amount> <recipient>`
199
226
 
200
227
  Transfer privately to another registered Veil user.
201
228
 
202
229
  ```bash
203
230
  veil transfer ETH 0.02 0xRecipientAddress
231
+ veil transfer USDC 25 0xRecipientAddress
204
232
  veil transfer ETH 0.02 0xRecipientAddress --quiet
205
233
  ```
206
234
 
@@ -210,18 +238,20 @@ Output:
210
238
  "success": true,
211
239
  "transactionHash": "0x...",
212
240
  "blockNumber": 12345678,
241
+ "asset": "ETH",
213
242
  "amount": "0.02",
214
243
  "recipient": "0x...",
215
244
  "type": "transfer"
216
245
  }
217
246
  ```
218
247
 
219
- ### `veil merge ETH <amount>`
248
+ ### `veil merge <asset> <amount>`
220
249
 
221
250
  Consolidate multiple small UTXOs into one (self-transfer).
222
251
 
223
252
  ```bash
224
- veil merge ETH 0.1 # Merge UTXOs totaling 0.1 ETH
253
+ veil merge ETH 0.1 # Merge ETH UTXOs totaling 0.1 ETH
254
+ veil merge USDC 100 # Merge USDC UTXOs
225
255
  veil merge ETH 0.1 --quiet
226
256
  ```
227
257
 
@@ -231,6 +261,7 @@ Output:
231
261
  "success": true,
232
262
  "transactionHash": "0x...",
233
263
  "blockNumber": 12345678,
264
+ "asset": "ETH",
234
265
  "amount": "0.1",
235
266
  "type": "merge"
236
267
  }
@@ -286,7 +317,11 @@ All CLI commands output JSON with standardized error codes:
286
317
  ## SDK Quick Start
287
318
 
288
319
  ```typescript
289
- import { Keypair, buildRegisterTx, buildDepositETHTx, withdraw, transfer } from '@veil-cash/sdk';
320
+ import {
321
+ Keypair, buildRegisterTx, buildDepositETHTx,
322
+ buildDepositUSDCTx, buildApproveUSDCTx,
323
+ withdraw, transfer,
324
+ } from '@veil-cash/sdk';
290
325
  import { createWalletClient, http } from 'viem';
291
326
  import { base } from 'viem/chains';
292
327
  import { privateKeyToAccount } from 'viem/accounts';
@@ -311,18 +346,25 @@ await client.sendTransaction(registerTx);
311
346
  // 4. Deposit ETH
312
347
  const depositTx = buildDepositETHTx({
313
348
  depositKey: keypair.depositKey(),
314
- amount: '0.1', // 0.1 ETH
349
+ amount: '0.1',
315
350
  });
316
- await client.sendTransaction({
317
- ...depositTx,
318
- value: depositTx.value,
351
+ await client.sendTransaction({ ...depositTx, value: depositTx.value });
352
+
353
+ // 4b. Deposit USDC (approve first)
354
+ const approveTx = buildApproveUSDCTx({ amount: '100' });
355
+ await client.sendTransaction(approveTx);
356
+ const usdcTx = buildDepositUSDCTx({
357
+ depositKey: keypair.depositKey(),
358
+ amount: '100',
319
359
  });
360
+ await client.sendTransaction(usdcTx);
320
361
 
321
362
  // 5. Withdraw (sent via relayer, no wallet signing needed)
322
363
  const withdrawResult = await withdraw({
323
364
  amount: '0.05',
324
365
  recipient: '0xRecipientAddress',
325
366
  keypair,
367
+ pool: 'eth', // 'eth' | 'usdc' (default: 'eth')
326
368
  });
327
369
 
328
370
  // 6. Transfer privately
@@ -330,6 +372,7 @@ const transferResult = await transfer({
330
372
  amount: '0.02',
331
373
  recipientAddress: '0xRecipientAddress',
332
374
  senderKeypair: keypair,
375
+ pool: 'eth', // 'eth' | 'usdc' (default: 'eth')
333
376
  });
334
377
  ```
335
378
 
@@ -338,14 +381,27 @@ const transferResult = await transfer({
338
381
  ### Keypair
339
382
 
340
383
  ```typescript
341
- import { Keypair } from '@veil-cash/sdk';
384
+ import { Keypair, VEIL_SIGNED_MESSAGE } from '@veil-cash/sdk';
385
+ import type { MessageSigner } from '@veil-cash/sdk';
342
386
 
343
- // Generate new keypair
387
+ // Generate random keypair
344
388
  const keypair = new Keypair();
345
389
 
346
390
  // Restore from saved Veil private key
347
391
  const restored = new Keypair(savedVeilKey);
348
392
 
393
+ // Derive from wallet key (same keypair as frontend login)
394
+ const derived = await Keypair.fromWalletKey('0xYOUR_WALLET_KEY');
395
+
396
+ // Derive from a raw EIP-191 signature
397
+ const fromSig = Keypair.fromSignature('0xSIGNATURE...');
398
+
399
+ // Derive from any external signer (Bankr, MPC, custodial, etc.)
400
+ const fromSigner = await Keypair.fromSigner(async (message) => {
401
+ // Sign `message` using any personal_sign provider and return the signature
402
+ return await mySigningService.personalSign(message);
403
+ });
404
+
349
405
  // Get deposit key (for registration)
350
406
  keypair.depositKey(); // '0x...' (130 hex chars)
351
407
 
@@ -356,72 +412,107 @@ keypair.privkey; // '0x...'
356
412
  ### Transaction Builders
357
413
 
358
414
  ```typescript
359
- import { buildRegisterTx, buildDepositETHTx } from '@veil-cash/sdk';
415
+ import {
416
+ buildRegisterTx, buildChangeDepositKeyTx, buildDepositETHTx, buildDepositTx,
417
+ buildDepositUSDCTx, buildApproveUSDCTx,
418
+ } from '@veil-cash/sdk';
360
419
 
361
- // Register deposit key (one-time)
420
+ // Register deposit key (first time)
362
421
  const registerTx = buildRegisterTx(depositKey, ownerAddress);
363
422
  // → { to: '0x...', data: '0x...' }
364
423
 
424
+ // Change deposit key (must already be registered)
425
+ const changeTx = buildChangeDepositKeyTx(newDepositKey, ownerAddress);
426
+ // → { to: '0x...', data: '0x...' }
427
+
365
428
  // Deposit ETH
366
429
  const depositTx = buildDepositETHTx({
367
430
  depositKey: keypair.depositKey(),
368
431
  amount: '0.1',
369
432
  });
370
433
  // → { to: '0x...', data: '0x...', value: 100000000000000000n }
434
+
435
+ // Deposit USDC (approve + deposit)
436
+ const approveUsdcTx = buildApproveUSDCTx({ amount: '100' });
437
+ const depositUsdcTx = buildDepositUSDCTx({
438
+ depositKey: keypair.depositKey(),
439
+ amount: '100',
440
+ });
441
+
442
+ // Generic builder (routes by token)
443
+ const tx = buildDepositTx({
444
+ depositKey: keypair.depositKey(),
445
+ amount: '0.1',
446
+ token: 'ETH', // 'ETH' | 'USDC'
447
+ });
371
448
  ```
372
449
 
373
450
  ### Withdraw & Transfer
374
451
 
452
+ All withdraw, transfer, and merge functions accept an optional `pool` parameter (`'eth'` | `'usdc'`), defaulting to `'eth'`.
453
+
375
454
  ```typescript
376
455
  import { withdraw, transfer, mergeUtxos } from '@veil-cash/sdk';
377
456
 
378
- // Withdraw to public address
457
+ // Withdraw ETH to public address
379
458
  const withdrawResult = await withdraw({
380
459
  amount: '0.05',
381
460
  recipient: '0xRecipientAddress',
382
461
  keypair,
462
+ pool: 'eth', // default
383
463
  onProgress: (stage, detail) => console.log(stage, detail),
384
464
  });
385
465
 
386
- // Transfer to another registered user
387
- const transferResult = await transfer({
388
- amount: '0.02',
389
- recipientAddress: '0xRecipientAddress',
390
- senderKeypair: keypair,
466
+ // Withdraw USDC
467
+ const withdrawUsdc = await withdraw({
468
+ amount: '50',
469
+ recipient: '0xRecipientAddress',
470
+ keypair,
471
+ pool: 'usdc',
391
472
  });
392
473
 
393
474
  // Merge UTXOs (consolidate small balances)
394
475
  const mergeResult = await mergeUtxos({
395
476
  amount: '0.1',
396
477
  keypair,
478
+ pool: 'eth',
397
479
  });
398
480
  ```
399
481
 
400
482
  ### Balance Queries
401
483
 
484
+ Balance functions accept an optional `pool` parameter (`'eth'` | `'usdc'`), defaulting to `'eth'`.
485
+
402
486
  ```typescript
403
487
  import { getQueueBalance, getPrivateBalance } from '@veil-cash/sdk';
404
488
 
405
- // Check queue balance (pending deposits)
489
+ // Check ETH queue balance (pending deposits)
406
490
  const queueBalance = await getQueueBalance({
407
491
  address: '0x...',
492
+ pool: 'eth', // default
408
493
  });
409
494
 
410
- // Check private balance (requires keypair)
495
+ // Check USDC private balance (requires keypair)
411
496
  const privateBalance = await getPrivateBalance({
412
497
  keypair,
498
+ pool: 'usdc',
413
499
  });
500
+
414
501
  ```
415
502
 
416
503
  ### Addresses
417
504
 
418
505
  ```typescript
419
- import { getAddresses } from '@veil-cash/sdk';
506
+ import { getAddresses, getPoolAddress, getQueueAddress } from '@veil-cash/sdk';
420
507
 
421
508
  const addresses = getAddresses();
422
509
  console.log(addresses.entry); // Entry contract
423
510
  console.log(addresses.ethPool); // ETH pool
424
- console.log(addresses.ethQueue); // ETH queue
511
+ console.log(addresses.usdcPool); // USDC pool
512
+
513
+ // Helper functions to resolve by pool name
514
+ console.log(getPoolAddress('eth')); // ETH pool address
515
+ console.log(getPoolAddress('usdc')); // USDC pool address
425
516
  ```
426
517
 
427
518
  ## For AI Agents
@@ -439,14 +530,48 @@ veil init --json
439
530
  # Get unsigned transaction payloads for agent signing
440
531
  veil register --unsigned --address 0x...
441
532
  veil deposit ETH 0.1 --unsigned
533
+ veil deposit USDC 100 --unsigned # Outputs approve + deposit payloads
442
534
 
443
535
  # Suppress progress output for clean JSON
444
536
  veil balance --quiet
537
+ veil balance --pool usdc --quiet
445
538
  veil withdraw ETH 0.05 0xRecipient --quiet
446
539
  ```
447
540
 
448
541
  ### Bankr Integration
449
542
 
543
+ #### Keypair Derivation via Bankr Sign API
544
+
545
+ Use `Keypair.fromSigner()` with Bankr's `POST /agent/sign` endpoint to derive the same keypair as the frontend:
546
+
547
+ ```typescript
548
+ import { Keypair } from '@veil-cash/sdk';
549
+
550
+ const keypair = await Keypair.fromSigner(async (message) => {
551
+ const res = await fetch('https://api.bankr.bot/agent/sign', {
552
+ method: 'POST',
553
+ headers: { 'X-API-Key': BANKR_API_KEY, 'Content-Type': 'application/json' },
554
+ body: JSON.stringify({ signatureType: 'personal_sign', message }),
555
+ });
556
+ return (await res.json()).signature;
557
+ });
558
+ ```
559
+
560
+ Or via CLI (two-step):
561
+ ```bash
562
+ # 1. Get signature from Bankr sign API
563
+ SIG=$(curl -s -X POST "https://api.bankr.bot/agent/sign" \
564
+ -H "X-API-Key: $BANKR_API_KEY" \
565
+ -H "Content-Type: application/json" \
566
+ -d "{\"signatureType\":\"personal_sign\",\"message\":\"$(node -e "const{VEIL_SIGNED_MESSAGE}=require('@veil-cash/sdk');console.log(VEIL_SIGNED_MESSAGE)")\"}" \
567
+ | jq -r '.signature')
568
+
569
+ # 2. Derive keypair from signature
570
+ veil init --signature $SIG
571
+ ```
572
+
573
+ #### Unsigned Transaction Payloads
574
+
450
575
  Use `--unsigned` to get Bankr-compatible transaction payloads:
451
576
 
452
577
  ```bash
@@ -459,7 +584,7 @@ The `--unsigned` flag outputs the [Bankr arbitrary transaction format](https://g
459
584
  ### Programmatic SDK Usage
460
585
 
461
586
  ```typescript
462
- import { Keypair, buildDepositETHTx, withdraw } from '@veil-cash/sdk';
587
+ import { Keypair, buildDepositETHTx, buildDepositTx, withdraw } from '@veil-cash/sdk';
463
588
 
464
589
  // For deposits: build transaction, let agent sign via Bankr
465
590
  const keypair = new Keypair(veilKey);
@@ -469,11 +594,19 @@ const tx = buildDepositETHTx({
469
594
  });
470
595
  // → { to, data, value } - pass to Bankr for signing
471
596
 
597
+ // Generic builder works for any asset
598
+ const usdcTx = buildDepositTx({
599
+ depositKey: keypair.depositKey(),
600
+ amount: '100',
601
+ token: 'USDC',
602
+ });
603
+
472
604
  // For withdrawals: SDK handles ZK proofs, submits to relayer
473
605
  const result = await withdraw({
474
606
  amount: '0.05',
475
607
  recipient: '0xRecipient',
476
608
  keypair,
609
+ pool: 'eth', // 'eth' | 'usdc'
477
610
  });
478
611
  // → { success, transactionHash, blockNumber }
479
612
  ```
@@ -483,14 +616,14 @@ const result = await withdraw({
483
616
  1. **Generate Keypair**: Run `veil init` to create and save your Veil keypair
484
617
  2. **Register**: Run `veil register` to link your deposit key on-chain (one-time)
485
618
  3. **Check Status**: Run `veil status` to verify your setup
486
- 4. **Deposit**: Run `veil deposit ETH <amount>` to send ETH
619
+ 4. **Deposit**: Run `veil deposit <asset> <amount>` (e.g., `veil deposit ETH 0.1`, `veil deposit USDC 100`)
487
620
  5. **Wait**: The Veil deposit engine processes your deposit
488
621
  6. **Done**: Your deposit is accepted into the privacy pool
489
622
 
490
623
  ## Withdrawal Flow
491
624
 
492
- 1. **Check Balance**: Run `veil balance` to see your private balance
493
- 2. **Withdraw**: Run `veil withdraw ETH <amount> <recipient>`
625
+ 1. **Check Balance**: Run `veil balance --pool <pool>` to see your private balance
626
+ 2. **Withdraw**: Run `veil withdraw <asset> <amount> <recipient>`
494
627
  3. **Done**: The SDK builds ZK proofs and submits via the relayer
495
628
 
496
629
  ## License