@veil-cash/sdk 0.3.0 → 0.5.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, USDC, and cbBTC privately.
9
+ Generate keypairs, register, deposit, withdraw, transfer, and merge ETH and USDC privately.
10
10
 
11
11
  ## Installation
12
12
 
@@ -23,257 +23,169 @@ For global CLI access:
23
23
  npm install -g @veil-cash/sdk
24
24
  ```
25
25
 
26
+ ## Agent Skill
27
+
28
+ This repo includes a Veil agent skill at [`skills/veil/SKILL.md`](./skills/veil/SKILL.md).
29
+
30
+ Quick mapping:
31
+
32
+ - npm package: `@veil-cash/sdk`
33
+ - CLI binary: `veil`
34
+ - agent skill file: `skills/veil/SKILL.md`
35
+
36
+ If you are pointing an agent at this repo, send it to [`skills/veil/SKILL.md`](./skills/veil/SKILL.md) for the canonical CLI workflow.
37
+
38
+ If you install the npm package, the published package also includes the `skills/` directory so the same skill can be discovered from the installed package contents.
39
+
26
40
  ## Supported Assets
27
41
 
28
42
  | Asset | Decimals | Token Contract |
29
43
  |-------|----------|---------------|
30
44
  | ETH | 18 | Native ETH (via WETH) |
31
45
  | USDC | 6 | `0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913` |
32
- | cbBTC | 8 | `0xcbB7C0000aB88B473b1f5aFd9ef808440eed33Bf` |
33
46
 
34
47
  ## CLI Quick Start
35
48
 
36
- ```bash
37
- # 1. Generate and save your Veil keypair
38
- veil init
49
+ The CLI is human-readable by default. Add `--json` when you want stable machine-readable output. `--unsigned` commands always emit transaction payload JSON for automation and agents.
39
50
 
40
- # 2. Set your Ethereum wallet key (for signing transactions)
51
+ ```bash
52
+ # 1. Set your Ethereum wallet key
41
53
  export WALLET_KEY=0x...
42
54
 
55
+ # 2. Derive and save your Veil keypair
56
+ veil init
57
+
43
58
  # 3. Register your deposit key (one-time)
44
59
  veil register
45
60
 
46
61
  # 4. Check your setup
47
62
  veil status
48
63
 
49
- # 5. Deposit (ETH, USDC, or cbBTC)
64
+ # 5. Deposit into the pool (amount is what arrives in your balance; fee added automatically)
50
65
  veil deposit ETH 0.1
51
66
  veil deposit USDC 100
52
- veil deposit CBBTC 0.001
53
67
 
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
68
+ # 6. Inspect balances
69
+ veil balance
70
+ veil balance --pool eth
71
+ veil balance queue --pool usdc
72
+ veil balance private
58
73
 
59
- # 7. Withdraw to any address
74
+ # 7. Use privacy actions
60
75
  veil withdraw ETH 0.05 0xRecipientAddress
61
- veil withdraw USDC 50 0xRecipientAddress
62
- veil withdraw CBBTC 0.0005 0xRecipientAddress
63
-
64
- # 8. Transfer privately to another registered user
65
76
  veil transfer ETH 0.02 0xRecipientAddress
66
-
67
- # 9. Merge small UTXOs (consolidate balances)
68
77
  veil merge ETH 0.1
78
+
79
+ # 8. Use JSON or unsigned modes when you need automation
80
+ veil status --json
81
+ veil deposit ETH 0.1 --unsigned
69
82
  ```
70
83
 
71
- ## CLI Commands
84
+ ## CLI Tasks
72
85
 
73
- ### `veil init`
86
+ ### Setup
74
87
 
75
- Generate or derive a Veil keypair.
88
+ Derive a Veil keypair from your wallet (default) or generate a random one:
76
89
 
77
90
  ```bash
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.)
91
+ veil init
92
+ veil init --generate
87
93
  veil init --signature 0x...
94
+ veil init --force
95
+ veil init --no-save
96
+ veil init --json
88
97
  ```
89
98
 
90
- ### `veil keypair`
91
-
92
- Show current Veil keypair as JSON (from VEIL_KEY env).
99
+ Show the current keypair from `VEIL_KEY`:
93
100
 
94
101
  ```bash
95
102
  veil keypair
96
- # {"veilPrivateKey":"0x...","depositKey":"0x..."}
103
+ veil keypair --json
97
104
  ```
98
105
 
99
- ### `veil status`
100
-
101
- Check configuration and service status.
106
+ Check local configuration, registration, and relay health:
102
107
 
103
108
  ```bash
104
109
  veil status
110
+ veil status --json
105
111
  ```
106
112
 
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
- ```
113
+ `veil status` shows a **Signing** row that reflects the active mode: `local (WALLET_KEY)`, `external (SIGNER_ADDRESS)`, or `not configured`. It also shows the resolved address, public ETH balance when available, and registration state. For unsigned or agent flows, set `SIGNER_ADDRESS` to let `veil status` and balance commands resolve address and registration without a private key.
128
114
 
129
- ### `veil register`
115
+ ### Registration and Deposits
130
116
 
131
- Register or update your deposit key on-chain.
117
+ Register or update your deposit key on-chain:
132
118
 
133
119
  ```bash
134
- veil register # Register (first time)
135
- veil register --json # JSON output
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
120
+ veil register
121
+ veil register --force
122
+ veil register --json
123
+ veil register --unsigned --address 0x...
124
+ SIGNER_ADDRESS=0x... veil register --unsigned
141
125
  ```
142
126
 
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>`
127
+ In `--unsigned` mode, `--address` is optional when `SIGNER_ADDRESS` is set. `veil register --force` checks on-chain state first and emits a `changeDepositKey` payload only if the address is already registered; otherwise it emits a normal `register` payload.
146
128
 
147
- Deposit ETH, USDC, or cbBTC into the privacy pool. For USDC and cbBTC, the CLI automatically handles ERC20 approval before depositing.
129
+ Deposit ETH or USDC into Veil. The amount you specify is the **net** amount that arrives in your Veil balance. The 0.3% protocol fee is calculated on-chain and added automatically:
148
130
 
149
131
  ```bash
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
132
+ veil deposit ETH 0.1 # 0.1 ETH lands in pool, ~0.1003 ETH sent
133
+ veil deposit USDC 100 # 100 USDC lands in pool, ~100.30 USDC sent
134
+ veil deposit ETH 0.1 --json
135
+ veil deposit ETH 0.1 --unsigned
155
136
  ```
156
137
 
157
- Output:
158
- ```json
159
- {
160
- "success": true,
161
- "hash": "0x...",
162
- "asset": "ETH",
163
- "amount": "0.1",
164
- "blockNumber": "12345678",
165
- "gasUsed": "150000"
166
- }
167
- ```
138
+ ### Balances
139
+
140
+ Show combined balances across queue and private pools:
168
141
 
169
- ### `veil balance`
142
+ ```bash
143
+ veil balance
144
+ veil balance --pool eth
145
+ veil balance --pool usdc
146
+ veil balance --json
147
+ ```
170
148
 
171
- Show both queue and private balances.
149
+ Inspect queue balances directly:
172
150
 
173
151
  ```bash
174
- veil balance # ETH pool (default)
175
- veil balance --pool usdc # USDC pool
176
- veil balance --pool cbbtc # cbBTC pool
177
- veil balance --quiet # Suppress progress output
152
+ veil balance queue
153
+ veil balance queue --pool usdc
154
+ veil balance queue --address 0x... --json
178
155
  ```
179
156
 
180
- Output:
181
- ```json
182
- {
183
- "address": "0x...",
184
- "pool": "ETH",
185
- "symbol": "ETH",
186
- "depositKey": "0x...",
187
- "totalBalance": "0.15",
188
- "totalBalanceWei": "150000000000000000",
189
- "private": {
190
- "balance": "0.10",
191
- "balanceWei": "100000000000000000",
192
- "utxoCount": 2,
193
- "utxos": [
194
- { "index": 5, "amount": "0.05" },
195
- { "index": 8, "amount": "0.05" }
196
- ]
197
- },
198
- "queue": {
199
- "balance": "0.05",
200
- "balanceWei": "50000000000000000",
201
- "count": 1,
202
- "deposits": [
203
- { "nonce": 42, "amount": "0.05", "status": "pending" }
204
- ]
205
- }
206
- }
157
+ Inspect private balances directly:
158
+
159
+ ```bash
160
+ veil balance private
161
+ veil balance private --pool usdc
162
+ veil balance private --json
207
163
  ```
208
164
 
209
- ### `veil withdraw <asset> <amount> <recipient>`
165
+ ### Private Actions
210
166
 
211
- Withdraw from the privacy pool to any public address.
167
+ Withdraw from the private pool to a public address:
212
168
 
213
169
  ```bash
214
170
  veil withdraw ETH 0.05 0xRecipientAddress
215
171
  veil withdraw USDC 50 0xRecipientAddress
216
- veil withdraw CBBTC 0.0005 0xRecipientAddress
217
- veil withdraw ETH 0.05 0xRecipientAddress --quiet
172
+ veil withdraw ETH 0.05 0xRecipientAddress --json
218
173
  ```
219
174
 
220
- Output:
221
- ```json
222
- {
223
- "success": true,
224
- "transactionHash": "0x...",
225
- "blockNumber": 12345678,
226
- "asset": "ETH",
227
- "amount": "0.05",
228
- "recipient": "0x..."
229
- }
230
- ```
231
-
232
- ### `veil transfer <asset> <amount> <recipient>`
233
-
234
- Transfer privately to another registered Veil user.
175
+ Transfer privately to another registered Veil user:
235
176
 
236
177
  ```bash
237
178
  veil transfer ETH 0.02 0xRecipientAddress
238
179
  veil transfer USDC 25 0xRecipientAddress
239
- veil transfer CBBTC 0.0002 0xRecipientAddress
240
- veil transfer ETH 0.02 0xRecipientAddress --quiet
241
- ```
242
-
243
- Output:
244
- ```json
245
- {
246
- "success": true,
247
- "transactionHash": "0x...",
248
- "blockNumber": 12345678,
249
- "asset": "ETH",
250
- "amount": "0.02",
251
- "recipient": "0x...",
252
- "type": "transfer"
253
- }
180
+ veil transfer ETH 0.02 0xRecipientAddress --json
254
181
  ```
255
182
 
256
- ### `veil merge <asset> <amount>`
257
-
258
- Consolidate multiple small UTXOs into one (self-transfer).
183
+ Merge small UTXOs into one:
259
184
 
260
185
  ```bash
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
- }
186
+ veil merge ETH 0.1
187
+ veil merge USDC 100
188
+ veil merge ETH 0.1 --json
277
189
  ```
278
190
 
279
191
  ## Environment Variables
@@ -283,7 +195,7 @@ The CLI uses two config files:
283
195
  | File | Purpose |
284
196
  |------|---------|
285
197
  | `.env.veil` | Veil keypair (VEIL_KEY, DEPOSIT_KEY) - created by `veil init` |
286
- | `.env` | Wallet config (WALLET_KEY, RPC_URL) - your existing config |
198
+ | `.env` | Wallet config (WALLET_KEY or SIGNER_ADDRESS, RPC_URL) - your existing config |
287
199
 
288
200
  ### Variables
289
201
 
@@ -292,17 +204,21 @@ The CLI uses two config files:
292
204
  | `VEIL_KEY` | Your Veil private key (for ZK proofs, withdrawals, transfers) |
293
205
  | `DEPOSIT_KEY` | Your Veil deposit key (public, for register/deposit) |
294
206
  | `WALLET_KEY` | Ethereum wallet private key (for signing transactions) |
207
+ | `SIGNER_ADDRESS` | Ethereum address for unsigned/query flows when signing is handled externally |
295
208
  | `RPC_URL` | Base RPC URL (optional, defaults to public RPC) |
209
+ | `RELAY_URL` | Override relay base URL for relayed CLI operations and status checks |
210
+
211
+ `WALLET_KEY` and `SIGNER_ADDRESS` are mutually exclusive. Use `WALLET_KEY` for commands that sign transactions, and `SIGNER_ADDRESS` for address-only agent flows like `status`, `balance`, and `register --unsigned`.
296
212
 
297
213
  ## Error Handling
298
214
 
299
- All CLI commands output JSON with standardized error codes:
215
+ Commands print human-readable success output by default. Errors are standardized JSON with machine-readable error codes so scripts can detect failure cases reliably:
300
216
 
301
217
  ```json
302
218
  {
303
219
  "success": false,
304
220
  "errorCode": "VEIL_KEY_MISSING",
305
- "error": "VEIL_KEY required. Use --veil-key or set VEIL_KEY env"
221
+ "error": "VEIL_KEY required. Set VEIL_KEY env"
306
222
  }
307
223
  ```
308
224
 
@@ -313,6 +229,7 @@ All CLI commands output JSON with standardized error codes:
313
229
  | `VEIL_KEY_MISSING` | VEIL_KEY not provided |
314
230
  | `WALLET_KEY_MISSING` | WALLET_KEY not provided |
315
231
  | `DEPOSIT_KEY_MISSING` | DEPOSIT_KEY not provided |
232
+ | `CONFIG_CONFLICT` | Conflicting CLI env vars provided |
316
233
  | `INVALID_ADDRESS` | Invalid Ethereum address format |
317
234
  | `INVALID_AMOUNT` | Invalid or below minimum amount |
318
235
  | `INSUFFICIENT_BALANCE` | Not enough ETH balance |
@@ -323,346 +240,22 @@ All CLI commands output JSON with standardized error codes:
323
240
  | `CONTRACT_ERROR` | Smart contract reverted |
324
241
  | `UNKNOWN_ERROR` | Unexpected error |
325
242
 
326
- ## SDK Quick Start
327
-
328
- ```typescript
329
- import {
330
- Keypair, buildRegisterTx, buildDepositETHTx,
331
- buildDepositUSDCTx, buildApproveUSDCTx,
332
- buildDepositCBBTCTx, buildApproveCBBTCTx,
333
- withdraw, transfer,
334
- } from '@veil-cash/sdk';
335
- import { createWalletClient, http } from 'viem';
336
- import { base } from 'viem/chains';
337
- import { privateKeyToAccount } from 'viem/accounts';
338
-
339
- // 1. Generate a Veil keypair (do this once, save securely!)
340
- const keypair = new Keypair();
341
- console.log('Veil Private Key:', keypair.privkey); // SAVE THIS!
342
- console.log('Deposit Key:', keypair.depositKey()); // Register this on-chain
343
-
344
- // 2. Setup your Ethereum wallet
345
- const account = privateKeyToAccount('0x...');
346
- const client = createWalletClient({
347
- account,
348
- chain: base,
349
- transport: http(),
350
- });
351
-
352
- // 3. Register your deposit key (one-time)
353
- const registerTx = buildRegisterTx(keypair.depositKey(), account.address);
354
- await client.sendTransaction(registerTx);
355
-
356
- // 4. Deposit ETH
357
- const depositTx = buildDepositETHTx({
358
- depositKey: keypair.depositKey(),
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',
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);
380
-
381
- // 5. Withdraw (sent via relayer, no wallet signing needed)
382
- const withdrawResult = await withdraw({
383
- amount: '0.05',
384
- recipient: '0xRecipientAddress',
385
- keypair,
386
- pool: 'eth', // 'eth' | 'usdc' | 'cbbtc' (default: 'eth')
387
- });
388
-
389
- // 6. Transfer privately
390
- const transferResult = await transfer({
391
- amount: '0.02',
392
- recipientAddress: '0xRecipientAddress',
393
- senderKeypair: keypair,
394
- pool: 'eth', // 'eth' | 'usdc' | 'cbbtc' (default: 'eth')
395
- });
396
- ```
397
-
398
- ## SDK API Reference
399
-
400
- ### Keypair
401
-
402
- ```typescript
403
- import { Keypair, VEIL_SIGNED_MESSAGE } from '@veil-cash/sdk';
404
- import type { MessageSigner } from '@veil-cash/sdk';
405
-
406
- // Generate random keypair
407
- const keypair = new Keypair();
408
-
409
- // Restore from saved Veil private key
410
- const restored = new Keypair(savedVeilKey);
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
-
424
- // Get deposit key (for registration)
425
- keypair.depositKey(); // '0x...' (130 hex chars)
426
-
427
- // Veil private key (store securely!)
428
- keypair.privkey; // '0x...'
429
- ```
430
-
431
- ### Transaction Builders
432
-
433
- ```typescript
434
- import {
435
- buildRegisterTx, buildChangeDepositKeyTx, buildDepositETHTx, buildDepositTx,
436
- buildDepositUSDCTx, buildApproveUSDCTx,
437
- buildDepositCBBTCTx, buildApproveCBBTCTx,
438
- } from '@veil-cash/sdk';
439
-
440
- // Register deposit key (first time)
441
- const registerTx = buildRegisterTx(depositKey, ownerAddress);
442
- // → { to: '0x...', data: '0x...' }
443
-
444
- // Change deposit key (must already be registered)
445
- const changeTx = buildChangeDepositKeyTx(newDepositKey, ownerAddress);
446
- // → { to: '0x...', data: '0x...' }
447
-
448
- // Deposit ETH
449
- const depositTx = buildDepositETHTx({
450
- depositKey: keypair.depositKey(),
451
- amount: '0.1',
452
- });
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
- });
475
- ```
476
-
477
- ### Withdraw & Transfer
478
-
479
- All withdraw, transfer, and merge functions accept an optional `pool` parameter (`'eth'` | `'usdc'` | `'cbbtc'`), defaulting to `'eth'`.
480
-
481
- ```typescript
482
- import { withdraw, transfer, mergeUtxos } from '@veil-cash/sdk';
483
-
484
- // Withdraw ETH to public address
485
- const withdrawResult = await withdraw({
486
- amount: '0.05',
487
- recipient: '0xRecipientAddress',
488
- keypair,
489
- pool: 'eth', // default
490
- onProgress: (stage, detail) => console.log(stage, detail),
491
- });
492
-
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
502
- const transferResult = await transfer({
503
- amount: '0.0002',
504
- recipientAddress: '0xRecipientAddress',
505
- senderKeypair: keypair,
506
- pool: 'cbbtc',
507
- });
508
-
509
- // Merge UTXOs (consolidate small balances)
510
- const mergeResult = await mergeUtxos({
511
- amount: '0.1',
512
- keypair,
513
- pool: 'eth',
514
- });
515
- ```
516
-
517
- ### Balance Queries
518
-
519
- Balance functions accept an optional `pool` parameter (`'eth'` | `'usdc'` | `'cbbtc'`), defaulting to `'eth'`.
520
-
521
- ```typescript
522
- import { getQueueBalance, getPrivateBalance } from '@veil-cash/sdk';
523
-
524
- // Check ETH queue balance (pending deposits)
525
- const queueBalance = await getQueueBalance({
526
- address: '0x...',
527
- pool: 'eth', // default
528
- });
529
-
530
- // Check USDC private balance (requires keypair)
531
- const privateBalance = await getPrivateBalance({
532
- keypair,
533
- pool: 'usdc',
534
- });
535
-
536
- // Check cbBTC private balance
537
- const btcBalance = await getPrivateBalance({
538
- keypair,
539
- pool: 'cbbtc',
540
- });
541
- ```
542
-
543
- ### Addresses
544
-
545
- ```typescript
546
- import { getAddresses, getPoolAddress, getQueueAddress } from '@veil-cash/sdk';
547
-
548
- const addresses = getAddresses();
549
- console.log(addresses.entry); // Entry contract
550
- console.log(addresses.ethPool); // ETH pool
551
- console.log(addresses.usdcPool); // USDC pool
552
- console.log(addresses.cbbtcPool); // cbBTC pool
243
+ ## SDK Docs
553
244
 
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
559
- ```
560
-
561
- ## For AI Agents
562
-
563
- This SDK is designed to work with AI agent frameworks like [Bankr](https://bankr.bot).
564
-
565
- ### Non-Interactive CLI
566
-
567
- All commands output JSON and support non-interactive usage:
568
-
569
- ```bash
570
- # Generate keypair as JSON (no prompts, no file save)
571
- veil init --json
572
-
573
- # Get unsigned transaction payloads for agent signing
574
- veil register --unsigned --address 0x...
575
- veil deposit ETH 0.1 --unsigned
576
- veil deposit USDC 100 --unsigned # Outputs approve + deposit payloads
577
- veil deposit CBBTC 0.001 --unsigned
578
-
579
- # Suppress progress output for clean JSON
580
- veil balance --quiet
581
- veil balance --pool usdc --quiet
582
- veil withdraw ETH 0.05 0xRecipient --quiet
583
- ```
584
-
585
- ### Bankr Integration
586
-
587
- #### Keypair Derivation via Bankr Sign API
245
+ The CLI is the main entrypoint for most users. If you are integrating Veil programmatically, use the dedicated SDK guide:
588
246
 
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
-
619
- Use `--unsigned` to get Bankr-compatible transaction payloads:
620
-
621
- ```bash
622
- veil deposit ETH 0.1 --unsigned
623
- # {"to":"0x...","data":"0x...","value":"100000000000000000","chainId":8453}
624
- ```
625
-
626
- The `--unsigned` flag outputs the [Bankr arbitrary transaction format](https://github.com/BankrBot/moltbot-skills/blob/main/bankr/references/arbitrary-transaction.md).
627
-
628
- ### Programmatic SDK Usage
629
-
630
- ```typescript
631
- import { Keypair, buildDepositETHTx, buildDepositTx, withdraw } from '@veil-cash/sdk';
632
-
633
- // For deposits: build transaction, let agent sign via Bankr
634
- const keypair = new Keypair(veilKey);
635
- const tx = buildDepositETHTx({
636
- depositKey: keypair.depositKey(),
637
- amount: '0.1',
638
- });
639
- // → { to, data, value } - pass to Bankr for signing
640
-
641
- // Generic builder works for any asset
642
- const usdcTx = buildDepositTx({
643
- depositKey: keypair.depositKey(),
644
- amount: '100',
645
- token: 'USDC',
646
- });
647
-
648
- // For withdrawals: SDK handles ZK proofs, submits to relayer
649
- const result = await withdraw({
650
- amount: '0.05',
651
- recipient: '0xRecipient',
652
- keypair,
653
- pool: 'eth', // 'eth' | 'usdc' | 'cbbtc'
654
- });
655
- // → { success, transactionHash, blockNumber }
656
- ```
247
+ - [SDK Quick Start and API Reference](./SDK.md)
248
+ - [AI agent and signer integration notes](./SDK.md#for-ai-agents)
657
249
 
658
250
  ## Deposit Flow
659
251
 
660
- 1. **Generate Keypair**: Run `veil init` to create and save your Veil keypair
661
- 2. **Register**: Run `veil register` to link your deposit key on-chain (one-time)
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
252
+ 1. **Set Wallet Key**: `export WALLET_KEY=0x...` in your `.env` or shell
253
+ 2. **Derive Keypair**: Run `veil init` to derive and save your Veil keypair
254
+ 3. **Register**: Run `veil register` to link your deposit key on-chain (one-time)
255
+ 4. **Check Status**: Run `veil status` to verify your setup
256
+ 5. **Deposit**: Run `veil deposit <asset> <amount>` — the amount is what lands in your balance (e.g., `veil deposit ETH 0.1` deposits 0.1 ETH; the 0.3% fee is added automatically)
257
+ 6. **Wait**: The Veil deposit engine processes your deposit
258
+ 7. **Done**: Your deposit is accepted into the privacy pool
666
259
 
667
260
  ## Withdrawal Flow
668
261