@veil-cash/sdk 0.4.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 +104 -467
- package/SDK.md +311 -0
- package/dist/cli/index.cjs +1438 -917
- package/dist/index.cjs +7 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +7 -4
- package/dist/index.js.map +1 -1
- package/package.json +5 -4
- package/skills/veil/SKILL.md +526 -0
- package/skills/veil/reference.md +231 -0
- package/src/addresses.ts +6 -2
- package/src/balance.ts +4 -4
- package/src/cli/commands/balance.ts +126 -38
- package/src/cli/commands/deposit.ts +136 -63
- package/src/cli/commands/init.ts +95 -72
- package/src/cli/commands/keypair.ts +34 -16
- package/src/cli/commands/private-balance.ts +37 -35
- package/src/cli/commands/queue-balance.ts +48 -36
- package/src/cli/commands/register.ts +67 -53
- package/src/cli/commands/status.ts +196 -70
- package/src/cli/commands/transfer.ts +62 -53
- package/src/cli/commands/withdraw.ts +32 -30
- package/src/cli/config.ts +85 -5
- package/src/cli/errors.ts +4 -0
- package/src/cli/index.ts +23 -5
- package/src/cli/output.ts +87 -0
- package/src/cli/wallet.ts +75 -16
- package/src/index.ts +6 -1
- package/src/prover.ts +3 -0
package/README.md
CHANGED
|
@@ -23,6 +23,20 @@ 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 |
|
|
@@ -32,239 +46,146 @@ npm install -g @veil-cash/sdk
|
|
|
32
46
|
|
|
33
47
|
## CLI Quick Start
|
|
34
48
|
|
|
35
|
-
|
|
36
|
-
# 1. Generate and save your Veil keypair
|
|
37
|
-
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.
|
|
38
50
|
|
|
39
|
-
|
|
51
|
+
```bash
|
|
52
|
+
# 1. Set your Ethereum wallet key
|
|
40
53
|
export WALLET_KEY=0x...
|
|
41
54
|
|
|
55
|
+
# 2. Derive and save your Veil keypair
|
|
56
|
+
veil init
|
|
57
|
+
|
|
42
58
|
# 3. Register your deposit key (one-time)
|
|
43
59
|
veil register
|
|
44
60
|
|
|
45
61
|
# 4. Check your setup
|
|
46
62
|
veil status
|
|
47
63
|
|
|
48
|
-
# 5. Deposit (
|
|
64
|
+
# 5. Deposit into the pool (amount is what arrives in your balance; fee added automatically)
|
|
49
65
|
veil deposit ETH 0.1
|
|
50
66
|
veil deposit USDC 100
|
|
51
67
|
|
|
52
|
-
# 6.
|
|
53
|
-
veil balance
|
|
54
|
-
veil balance --pool
|
|
68
|
+
# 6. Inspect balances
|
|
69
|
+
veil balance
|
|
70
|
+
veil balance --pool eth
|
|
71
|
+
veil balance queue --pool usdc
|
|
72
|
+
veil balance private
|
|
55
73
|
|
|
56
|
-
# 7.
|
|
74
|
+
# 7. Use privacy actions
|
|
57
75
|
veil withdraw ETH 0.05 0xRecipientAddress
|
|
58
|
-
veil withdraw USDC 50 0xRecipientAddress
|
|
59
|
-
|
|
60
|
-
# 8. Transfer privately to another registered user
|
|
61
76
|
veil transfer ETH 0.02 0xRecipientAddress
|
|
62
|
-
|
|
63
|
-
# 9. Merge small UTXOs (consolidate balances)
|
|
64
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
|
|
65
82
|
```
|
|
66
83
|
|
|
67
|
-
## CLI
|
|
84
|
+
## CLI Tasks
|
|
68
85
|
|
|
69
|
-
###
|
|
86
|
+
### Setup
|
|
70
87
|
|
|
71
|
-
|
|
88
|
+
Derive a Veil keypair from your wallet (default) or generate a random one:
|
|
72
89
|
|
|
73
90
|
```bash
|
|
74
|
-
veil init
|
|
75
|
-
veil init --
|
|
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.)
|
|
91
|
+
veil init
|
|
92
|
+
veil init --generate
|
|
83
93
|
veil init --signature 0x...
|
|
94
|
+
veil init --force
|
|
95
|
+
veil init --no-save
|
|
96
|
+
veil init --json
|
|
84
97
|
```
|
|
85
98
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
Show current Veil keypair as JSON (from VEIL_KEY env).
|
|
99
|
+
Show the current keypair from `VEIL_KEY`:
|
|
89
100
|
|
|
90
101
|
```bash
|
|
91
102
|
veil keypair
|
|
92
|
-
|
|
103
|
+
veil keypair --json
|
|
93
104
|
```
|
|
94
105
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
Check configuration and service status.
|
|
106
|
+
Check local configuration, registration, and relay health:
|
|
98
107
|
|
|
99
108
|
```bash
|
|
100
109
|
veil status
|
|
110
|
+
veil status --json
|
|
101
111
|
```
|
|
102
112
|
|
|
103
|
-
|
|
104
|
-
```json
|
|
105
|
-
{
|
|
106
|
-
"walletKey": { "found": true, "address": "0x..." },
|
|
107
|
-
"veilKey": { "found": true },
|
|
108
|
-
"depositKey": { "found": true, "key": "0x1234...abcd" },
|
|
109
|
-
"rpcUrl": { "found": false, "url": "https://mainnet.base.org" },
|
|
110
|
-
"registration": {
|
|
111
|
-
"checked": true,
|
|
112
|
-
"registered": true,
|
|
113
|
-
"matches": true,
|
|
114
|
-
"onChainKey": "0x..."
|
|
115
|
-
},
|
|
116
|
-
"relay": {
|
|
117
|
-
"checked": true,
|
|
118
|
-
"healthy": true,
|
|
119
|
-
"status": "ok",
|
|
120
|
-
"network": "mainnet"
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
```
|
|
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.
|
|
124
114
|
|
|
125
|
-
###
|
|
115
|
+
### Registration and Deposits
|
|
126
116
|
|
|
127
|
-
Register or update your deposit key on-chain
|
|
117
|
+
Register or update your deposit key on-chain:
|
|
128
118
|
|
|
129
119
|
```bash
|
|
130
|
-
veil register
|
|
131
|
-
veil register --
|
|
132
|
-
veil register --
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
veil register --force # Change to local deposit key
|
|
136
|
-
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
|
|
137
125
|
```
|
|
138
126
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
### `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.
|
|
142
128
|
|
|
143
|
-
Deposit ETH or USDC into the
|
|
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:
|
|
144
130
|
|
|
145
131
|
```bash
|
|
146
|
-
veil deposit ETH 0.1
|
|
147
|
-
veil deposit USDC 100
|
|
148
|
-
veil deposit ETH 0.1 --
|
|
149
|
-
veil deposit ETH 0.1 --
|
|
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
|
|
150
136
|
```
|
|
151
137
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
"success": true,
|
|
156
|
-
"hash": "0x...",
|
|
157
|
-
"asset": "ETH",
|
|
158
|
-
"amount": "0.1",
|
|
159
|
-
"blockNumber": "12345678",
|
|
160
|
-
"gasUsed": "150000"
|
|
161
|
-
}
|
|
162
|
-
```
|
|
138
|
+
### Balances
|
|
139
|
+
|
|
140
|
+
Show combined balances across queue and private pools:
|
|
163
141
|
|
|
164
|
-
|
|
142
|
+
```bash
|
|
143
|
+
veil balance
|
|
144
|
+
veil balance --pool eth
|
|
145
|
+
veil balance --pool usdc
|
|
146
|
+
veil balance --json
|
|
147
|
+
```
|
|
165
148
|
|
|
166
|
-
|
|
149
|
+
Inspect queue balances directly:
|
|
167
150
|
|
|
168
151
|
```bash
|
|
169
|
-
veil balance
|
|
170
|
-
veil balance --pool usdc
|
|
171
|
-
veil balance --
|
|
152
|
+
veil balance queue
|
|
153
|
+
veil balance queue --pool usdc
|
|
154
|
+
veil balance queue --address 0x... --json
|
|
172
155
|
```
|
|
173
156
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
"depositKey": "0x...",
|
|
181
|
-
"totalBalance": "0.15",
|
|
182
|
-
"totalBalanceWei": "150000000000000000",
|
|
183
|
-
"private": {
|
|
184
|
-
"balance": "0.10",
|
|
185
|
-
"balanceWei": "100000000000000000",
|
|
186
|
-
"utxoCount": 2,
|
|
187
|
-
"utxos": [
|
|
188
|
-
{ "index": 5, "amount": "0.05" },
|
|
189
|
-
{ "index": 8, "amount": "0.05" }
|
|
190
|
-
]
|
|
191
|
-
},
|
|
192
|
-
"queue": {
|
|
193
|
-
"balance": "0.05",
|
|
194
|
-
"balanceWei": "50000000000000000",
|
|
195
|
-
"count": 1,
|
|
196
|
-
"deposits": [
|
|
197
|
-
{ "nonce": 42, "amount": "0.05", "status": "pending" }
|
|
198
|
-
]
|
|
199
|
-
}
|
|
200
|
-
}
|
|
157
|
+
Inspect private balances directly:
|
|
158
|
+
|
|
159
|
+
```bash
|
|
160
|
+
veil balance private
|
|
161
|
+
veil balance private --pool usdc
|
|
162
|
+
veil balance private --json
|
|
201
163
|
```
|
|
202
164
|
|
|
203
|
-
###
|
|
165
|
+
### Private Actions
|
|
204
166
|
|
|
205
|
-
Withdraw from the
|
|
167
|
+
Withdraw from the private pool to a public address:
|
|
206
168
|
|
|
207
169
|
```bash
|
|
208
170
|
veil withdraw ETH 0.05 0xRecipientAddress
|
|
209
171
|
veil withdraw USDC 50 0xRecipientAddress
|
|
210
|
-
veil withdraw ETH 0.05 0xRecipientAddress --
|
|
172
|
+
veil withdraw ETH 0.05 0xRecipientAddress --json
|
|
211
173
|
```
|
|
212
174
|
|
|
213
|
-
|
|
214
|
-
```json
|
|
215
|
-
{
|
|
216
|
-
"success": true,
|
|
217
|
-
"transactionHash": "0x...",
|
|
218
|
-
"blockNumber": 12345678,
|
|
219
|
-
"asset": "ETH",
|
|
220
|
-
"amount": "0.05",
|
|
221
|
-
"recipient": "0x..."
|
|
222
|
-
}
|
|
223
|
-
```
|
|
224
|
-
|
|
225
|
-
### `veil transfer <asset> <amount> <recipient>`
|
|
226
|
-
|
|
227
|
-
Transfer privately to another registered Veil user.
|
|
175
|
+
Transfer privately to another registered Veil user:
|
|
228
176
|
|
|
229
177
|
```bash
|
|
230
178
|
veil transfer ETH 0.02 0xRecipientAddress
|
|
231
179
|
veil transfer USDC 25 0xRecipientAddress
|
|
232
|
-
veil transfer ETH 0.02 0xRecipientAddress --
|
|
233
|
-
```
|
|
234
|
-
|
|
235
|
-
Output:
|
|
236
|
-
```json
|
|
237
|
-
{
|
|
238
|
-
"success": true,
|
|
239
|
-
"transactionHash": "0x...",
|
|
240
|
-
"blockNumber": 12345678,
|
|
241
|
-
"asset": "ETH",
|
|
242
|
-
"amount": "0.02",
|
|
243
|
-
"recipient": "0x...",
|
|
244
|
-
"type": "transfer"
|
|
245
|
-
}
|
|
180
|
+
veil transfer ETH 0.02 0xRecipientAddress --json
|
|
246
181
|
```
|
|
247
182
|
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
Consolidate multiple small UTXOs into one (self-transfer).
|
|
183
|
+
Merge small UTXOs into one:
|
|
251
184
|
|
|
252
185
|
```bash
|
|
253
|
-
veil merge ETH 0.1
|
|
254
|
-
veil merge USDC 100
|
|
255
|
-
veil merge ETH 0.1 --
|
|
256
|
-
```
|
|
257
|
-
|
|
258
|
-
Output:
|
|
259
|
-
```json
|
|
260
|
-
{
|
|
261
|
-
"success": true,
|
|
262
|
-
"transactionHash": "0x...",
|
|
263
|
-
"blockNumber": 12345678,
|
|
264
|
-
"asset": "ETH",
|
|
265
|
-
"amount": "0.1",
|
|
266
|
-
"type": "merge"
|
|
267
|
-
}
|
|
186
|
+
veil merge ETH 0.1
|
|
187
|
+
veil merge USDC 100
|
|
188
|
+
veil merge ETH 0.1 --json
|
|
268
189
|
```
|
|
269
190
|
|
|
270
191
|
## Environment Variables
|
|
@@ -274,7 +195,7 @@ The CLI uses two config files:
|
|
|
274
195
|
| File | Purpose |
|
|
275
196
|
|------|---------|
|
|
276
197
|
| `.env.veil` | Veil keypair (VEIL_KEY, DEPOSIT_KEY) - created by `veil init` |
|
|
277
|
-
| `.env` | Wallet config (WALLET_KEY, RPC_URL) - your existing config |
|
|
198
|
+
| `.env` | Wallet config (WALLET_KEY or SIGNER_ADDRESS, RPC_URL) - your existing config |
|
|
278
199
|
|
|
279
200
|
### Variables
|
|
280
201
|
|
|
@@ -283,17 +204,21 @@ The CLI uses two config files:
|
|
|
283
204
|
| `VEIL_KEY` | Your Veil private key (for ZK proofs, withdrawals, transfers) |
|
|
284
205
|
| `DEPOSIT_KEY` | Your Veil deposit key (public, for register/deposit) |
|
|
285
206
|
| `WALLET_KEY` | Ethereum wallet private key (for signing transactions) |
|
|
207
|
+
| `SIGNER_ADDRESS` | Ethereum address for unsigned/query flows when signing is handled externally |
|
|
286
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`.
|
|
287
212
|
|
|
288
213
|
## Error Handling
|
|
289
214
|
|
|
290
|
-
|
|
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:
|
|
291
216
|
|
|
292
217
|
```json
|
|
293
218
|
{
|
|
294
219
|
"success": false,
|
|
295
220
|
"errorCode": "VEIL_KEY_MISSING",
|
|
296
|
-
"error": "VEIL_KEY required.
|
|
221
|
+
"error": "VEIL_KEY required. Set VEIL_KEY env"
|
|
297
222
|
}
|
|
298
223
|
```
|
|
299
224
|
|
|
@@ -304,6 +229,7 @@ All CLI commands output JSON with standardized error codes:
|
|
|
304
229
|
| `VEIL_KEY_MISSING` | VEIL_KEY not provided |
|
|
305
230
|
| `WALLET_KEY_MISSING` | WALLET_KEY not provided |
|
|
306
231
|
| `DEPOSIT_KEY_MISSING` | DEPOSIT_KEY not provided |
|
|
232
|
+
| `CONFIG_CONFLICT` | Conflicting CLI env vars provided |
|
|
307
233
|
| `INVALID_ADDRESS` | Invalid Ethereum address format |
|
|
308
234
|
| `INVALID_AMOUNT` | Invalid or below minimum amount |
|
|
309
235
|
| `INSUFFICIENT_BALANCE` | Not enough ETH balance |
|
|
@@ -314,311 +240,22 @@ All CLI commands output JSON with standardized error codes:
|
|
|
314
240
|
| `CONTRACT_ERROR` | Smart contract reverted |
|
|
315
241
|
| `UNKNOWN_ERROR` | Unexpected error |
|
|
316
242
|
|
|
317
|
-
## SDK
|
|
318
|
-
|
|
319
|
-
```typescript
|
|
320
|
-
import {
|
|
321
|
-
Keypair, buildRegisterTx, buildDepositETHTx,
|
|
322
|
-
buildDepositUSDCTx, buildApproveUSDCTx,
|
|
323
|
-
withdraw, transfer,
|
|
324
|
-
} from '@veil-cash/sdk';
|
|
325
|
-
import { createWalletClient, http } from 'viem';
|
|
326
|
-
import { base } from 'viem/chains';
|
|
327
|
-
import { privateKeyToAccount } from 'viem/accounts';
|
|
328
|
-
|
|
329
|
-
// 1. Generate a Veil keypair (do this once, save securely!)
|
|
330
|
-
const keypair = new Keypair();
|
|
331
|
-
console.log('Veil Private Key:', keypair.privkey); // SAVE THIS!
|
|
332
|
-
console.log('Deposit Key:', keypair.depositKey()); // Register this on-chain
|
|
333
|
-
|
|
334
|
-
// 2. Setup your Ethereum wallet
|
|
335
|
-
const account = privateKeyToAccount('0x...');
|
|
336
|
-
const client = createWalletClient({
|
|
337
|
-
account,
|
|
338
|
-
chain: base,
|
|
339
|
-
transport: http(),
|
|
340
|
-
});
|
|
341
|
-
|
|
342
|
-
// 3. Register your deposit key (one-time)
|
|
343
|
-
const registerTx = buildRegisterTx(keypair.depositKey(), account.address);
|
|
344
|
-
await client.sendTransaction(registerTx);
|
|
345
|
-
|
|
346
|
-
// 4. Deposit ETH
|
|
347
|
-
const depositTx = buildDepositETHTx({
|
|
348
|
-
depositKey: keypair.depositKey(),
|
|
349
|
-
amount: '0.1',
|
|
350
|
-
});
|
|
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',
|
|
359
|
-
});
|
|
360
|
-
await client.sendTransaction(usdcTx);
|
|
361
|
-
|
|
362
|
-
// 5. Withdraw (sent via relayer, no wallet signing needed)
|
|
363
|
-
const withdrawResult = await withdraw({
|
|
364
|
-
amount: '0.05',
|
|
365
|
-
recipient: '0xRecipientAddress',
|
|
366
|
-
keypair,
|
|
367
|
-
pool: 'eth', // 'eth' | 'usdc' (default: 'eth')
|
|
368
|
-
});
|
|
369
|
-
|
|
370
|
-
// 6. Transfer privately
|
|
371
|
-
const transferResult = await transfer({
|
|
372
|
-
amount: '0.02',
|
|
373
|
-
recipientAddress: '0xRecipientAddress',
|
|
374
|
-
senderKeypair: keypair,
|
|
375
|
-
pool: 'eth', // 'eth' | 'usdc' (default: 'eth')
|
|
376
|
-
});
|
|
377
|
-
```
|
|
378
|
-
|
|
379
|
-
## SDK API Reference
|
|
380
|
-
|
|
381
|
-
### Keypair
|
|
382
|
-
|
|
383
|
-
```typescript
|
|
384
|
-
import { Keypair, VEIL_SIGNED_MESSAGE } from '@veil-cash/sdk';
|
|
385
|
-
import type { MessageSigner } from '@veil-cash/sdk';
|
|
386
|
-
|
|
387
|
-
// Generate random keypair
|
|
388
|
-
const keypair = new Keypair();
|
|
389
|
-
|
|
390
|
-
// Restore from saved Veil private key
|
|
391
|
-
const restored = new Keypair(savedVeilKey);
|
|
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
|
-
|
|
405
|
-
// Get deposit key (for registration)
|
|
406
|
-
keypair.depositKey(); // '0x...' (130 hex chars)
|
|
407
|
-
|
|
408
|
-
// Veil private key (store securely!)
|
|
409
|
-
keypair.privkey; // '0x...'
|
|
410
|
-
```
|
|
411
|
-
|
|
412
|
-
### Transaction Builders
|
|
413
|
-
|
|
414
|
-
```typescript
|
|
415
|
-
import {
|
|
416
|
-
buildRegisterTx, buildChangeDepositKeyTx, buildDepositETHTx, buildDepositTx,
|
|
417
|
-
buildDepositUSDCTx, buildApproveUSDCTx,
|
|
418
|
-
} from '@veil-cash/sdk';
|
|
419
|
-
|
|
420
|
-
// Register deposit key (first time)
|
|
421
|
-
const registerTx = buildRegisterTx(depositKey, ownerAddress);
|
|
422
|
-
// → { to: '0x...', data: '0x...' }
|
|
423
|
-
|
|
424
|
-
// Change deposit key (must already be registered)
|
|
425
|
-
const changeTx = buildChangeDepositKeyTx(newDepositKey, ownerAddress);
|
|
426
|
-
// → { to: '0x...', data: '0x...' }
|
|
427
|
-
|
|
428
|
-
// Deposit ETH
|
|
429
|
-
const depositTx = buildDepositETHTx({
|
|
430
|
-
depositKey: keypair.depositKey(),
|
|
431
|
-
amount: '0.1',
|
|
432
|
-
});
|
|
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
|
-
});
|
|
448
|
-
```
|
|
449
|
-
|
|
450
|
-
### Withdraw & Transfer
|
|
451
|
-
|
|
452
|
-
All withdraw, transfer, and merge functions accept an optional `pool` parameter (`'eth'` | `'usdc'`), defaulting to `'eth'`.
|
|
453
|
-
|
|
454
|
-
```typescript
|
|
455
|
-
import { withdraw, transfer, mergeUtxos } from '@veil-cash/sdk';
|
|
456
|
-
|
|
457
|
-
// Withdraw ETH to public address
|
|
458
|
-
const withdrawResult = await withdraw({
|
|
459
|
-
amount: '0.05',
|
|
460
|
-
recipient: '0xRecipientAddress',
|
|
461
|
-
keypair,
|
|
462
|
-
pool: 'eth', // default
|
|
463
|
-
onProgress: (stage, detail) => console.log(stage, detail),
|
|
464
|
-
});
|
|
465
|
-
|
|
466
|
-
// Withdraw USDC
|
|
467
|
-
const withdrawUsdc = await withdraw({
|
|
468
|
-
amount: '50',
|
|
469
|
-
recipient: '0xRecipientAddress',
|
|
470
|
-
keypair,
|
|
471
|
-
pool: 'usdc',
|
|
472
|
-
});
|
|
473
|
-
|
|
474
|
-
// Merge UTXOs (consolidate small balances)
|
|
475
|
-
const mergeResult = await mergeUtxos({
|
|
476
|
-
amount: '0.1',
|
|
477
|
-
keypair,
|
|
478
|
-
pool: 'eth',
|
|
479
|
-
});
|
|
480
|
-
```
|
|
481
|
-
|
|
482
|
-
### Balance Queries
|
|
483
|
-
|
|
484
|
-
Balance functions accept an optional `pool` parameter (`'eth'` | `'usdc'`), defaulting to `'eth'`.
|
|
485
|
-
|
|
486
|
-
```typescript
|
|
487
|
-
import { getQueueBalance, getPrivateBalance } from '@veil-cash/sdk';
|
|
488
|
-
|
|
489
|
-
// Check ETH queue balance (pending deposits)
|
|
490
|
-
const queueBalance = await getQueueBalance({
|
|
491
|
-
address: '0x...',
|
|
492
|
-
pool: 'eth', // default
|
|
493
|
-
});
|
|
494
|
-
|
|
495
|
-
// Check USDC private balance (requires keypair)
|
|
496
|
-
const privateBalance = await getPrivateBalance({
|
|
497
|
-
keypair,
|
|
498
|
-
pool: 'usdc',
|
|
499
|
-
});
|
|
500
|
-
|
|
501
|
-
```
|
|
502
|
-
|
|
503
|
-
### Addresses
|
|
504
|
-
|
|
505
|
-
```typescript
|
|
506
|
-
import { getAddresses, getPoolAddress, getQueueAddress } from '@veil-cash/sdk';
|
|
507
|
-
|
|
508
|
-
const addresses = getAddresses();
|
|
509
|
-
console.log(addresses.entry); // Entry contract
|
|
510
|
-
console.log(addresses.ethPool); // ETH pool
|
|
511
|
-
console.log(addresses.usdcPool); // USDC pool
|
|
243
|
+
## SDK Docs
|
|
512
244
|
|
|
513
|
-
|
|
514
|
-
console.log(getPoolAddress('eth')); // ETH pool address
|
|
515
|
-
console.log(getPoolAddress('usdc')); // USDC pool address
|
|
516
|
-
```
|
|
517
|
-
|
|
518
|
-
## For AI Agents
|
|
519
|
-
|
|
520
|
-
This SDK is designed to work with AI agent frameworks like [Bankr](https://bankr.bot).
|
|
521
|
-
|
|
522
|
-
### Non-Interactive CLI
|
|
523
|
-
|
|
524
|
-
All commands output JSON and support non-interactive usage:
|
|
525
|
-
|
|
526
|
-
```bash
|
|
527
|
-
# Generate keypair as JSON (no prompts, no file save)
|
|
528
|
-
veil init --json
|
|
529
|
-
|
|
530
|
-
# Get unsigned transaction payloads for agent signing
|
|
531
|
-
veil register --unsigned --address 0x...
|
|
532
|
-
veil deposit ETH 0.1 --unsigned
|
|
533
|
-
veil deposit USDC 100 --unsigned # Outputs approve + deposit payloads
|
|
534
|
-
|
|
535
|
-
# Suppress progress output for clean JSON
|
|
536
|
-
veil balance --quiet
|
|
537
|
-
veil balance --pool usdc --quiet
|
|
538
|
-
veil withdraw ETH 0.05 0xRecipient --quiet
|
|
539
|
-
```
|
|
540
|
-
|
|
541
|
-
### Bankr Integration
|
|
542
|
-
|
|
543
|
-
#### 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:
|
|
544
246
|
|
|
545
|
-
|
|
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
|
-
|
|
575
|
-
Use `--unsigned` to get Bankr-compatible transaction payloads:
|
|
576
|
-
|
|
577
|
-
```bash
|
|
578
|
-
veil deposit ETH 0.1 --unsigned
|
|
579
|
-
# {"to":"0x...","data":"0x...","value":"100000000000000000","chainId":8453}
|
|
580
|
-
```
|
|
581
|
-
|
|
582
|
-
The `--unsigned` flag outputs the [Bankr arbitrary transaction format](https://github.com/BankrBot/moltbot-skills/blob/main/bankr/references/arbitrary-transaction.md).
|
|
583
|
-
|
|
584
|
-
### Programmatic SDK Usage
|
|
585
|
-
|
|
586
|
-
```typescript
|
|
587
|
-
import { Keypair, buildDepositETHTx, buildDepositTx, withdraw } from '@veil-cash/sdk';
|
|
588
|
-
|
|
589
|
-
// For deposits: build transaction, let agent sign via Bankr
|
|
590
|
-
const keypair = new Keypair(veilKey);
|
|
591
|
-
const tx = buildDepositETHTx({
|
|
592
|
-
depositKey: keypair.depositKey(),
|
|
593
|
-
amount: '0.1',
|
|
594
|
-
});
|
|
595
|
-
// → { to, data, value } - pass to Bankr for signing
|
|
596
|
-
|
|
597
|
-
// Generic builder works for any asset
|
|
598
|
-
const usdcTx = buildDepositTx({
|
|
599
|
-
depositKey: keypair.depositKey(),
|
|
600
|
-
amount: '100',
|
|
601
|
-
token: 'USDC',
|
|
602
|
-
});
|
|
603
|
-
|
|
604
|
-
// For withdrawals: SDK handles ZK proofs, submits to relayer
|
|
605
|
-
const result = await withdraw({
|
|
606
|
-
amount: '0.05',
|
|
607
|
-
recipient: '0xRecipient',
|
|
608
|
-
keypair,
|
|
609
|
-
pool: 'eth', // 'eth' | 'usdc'
|
|
610
|
-
});
|
|
611
|
-
// → { success, transactionHash, blockNumber }
|
|
612
|
-
```
|
|
247
|
+
- [SDK Quick Start and API Reference](./SDK.md)
|
|
248
|
+
- [AI agent and signer integration notes](./SDK.md#for-ai-agents)
|
|
613
249
|
|
|
614
250
|
## Deposit Flow
|
|
615
251
|
|
|
616
|
-
1. **
|
|
617
|
-
2. **
|
|
618
|
-
3. **
|
|
619
|
-
4. **
|
|
620
|
-
5. **
|
|
621
|
-
6. **
|
|
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
|
|
622
259
|
|
|
623
260
|
## Withdrawal Flow
|
|
624
261
|
|