@veil-cash/sdk 0.5.0 → 0.6.1
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 +75 -37
- package/SDK.md +55 -1
- package/dist/cli/index.cjs +806 -22
- package/dist/index.cjs +554 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +486 -1
- package/dist/index.d.ts +486 -1
- package/dist/index.js +537 -23
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/skills/veil/SKILL.md +74 -2
- package/skills/veil/reference.md +71 -2
- package/src/abi.ts +172 -0
- package/src/addresses.ts +14 -0
- package/src/cli/commands/subaccount.ts +355 -0
- package/src/cli/errors.ts +4 -0
- package/src/cli/index.ts +5 -1
- package/src/cli/wallet.ts +2 -2
- package/src/index.ts +35 -0
- package/src/relay.ts +45 -24
- package/src/subaccount.ts +481 -0
- package/src/types.ts +134 -0
package/README.md
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
# @veil-cash/sdk
|
|
2
2
|
|
|
3
|
-
[
|
|
4
|
-
[
|
|
5
|
-
[
|
|
3
|
+
[npm version](https://www.npmjs.com/package/@veil-cash/sdk)
|
|
4
|
+
[npm downloads](https://www.npmjs.com/package/@veil-cash/sdk)
|
|
5
|
+
[license](https://github.com/veildotcash/veildotcash-sdk/blob/main/LICENSE)
|
|
6
6
|
|
|
7
7
|
SDK and CLI for interacting with [Veil Cash](https://veil.cash) privacy pools on Base.
|
|
8
8
|
|
|
9
9
|
Generate keypairs, register, deposit, withdraw, transfer, and merge ETH and USDC privately.
|
|
10
10
|
|
|
11
|
+
`0.6.0` adds SDK-first subaccount support for deterministic slot derivation, forwarder status, relay-backed deploy/sweep, and direct recovery.
|
|
12
|
+
|
|
11
13
|
## Installation
|
|
12
14
|
|
|
13
15
|
```bash
|
|
@@ -19,13 +21,14 @@ pnpm add @veil-cash/sdk
|
|
|
19
21
|
```
|
|
20
22
|
|
|
21
23
|
For global CLI access:
|
|
24
|
+
|
|
22
25
|
```bash
|
|
23
26
|
npm install -g @veil-cash/sdk
|
|
24
27
|
```
|
|
25
28
|
|
|
26
29
|
## Agent Skill
|
|
27
30
|
|
|
28
|
-
This repo includes a Veil agent skill at [
|
|
31
|
+
This repo includes a Veil agent skill at [skills/veil/SKILL.md](./skills/veil/SKILL.md).
|
|
29
32
|
|
|
30
33
|
Quick mapping:
|
|
31
34
|
|
|
@@ -33,16 +36,18 @@ Quick mapping:
|
|
|
33
36
|
- CLI binary: `veil`
|
|
34
37
|
- agent skill file: `skills/veil/SKILL.md`
|
|
35
38
|
|
|
36
|
-
If you are pointing an agent at this repo, send it to [
|
|
39
|
+
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
40
|
|
|
38
41
|
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
42
|
|
|
40
43
|
## Supported Assets
|
|
41
44
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
|
45
|
-
|
|
|
45
|
+
|
|
46
|
+
| Asset | Decimals | Token Contract |
|
|
47
|
+
| ----- | -------- | -------------------------------------------- |
|
|
48
|
+
| ETH | 18 | Native ETH (via WETH) |
|
|
49
|
+
| USDC | 6 | `0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913` |
|
|
50
|
+
|
|
46
51
|
|
|
47
52
|
## CLI Quick Start
|
|
48
53
|
|
|
@@ -76,9 +81,17 @@ veil withdraw ETH 0.05 0xRecipientAddress
|
|
|
76
81
|
veil transfer ETH 0.02 0xRecipientAddress
|
|
77
82
|
veil merge ETH 0.1
|
|
78
83
|
|
|
79
|
-
# 8.
|
|
84
|
+
# 8. Work with subaccounts
|
|
85
|
+
veil subaccount derive --slot 0
|
|
86
|
+
veil subaccount status --slot 0
|
|
87
|
+
veil subaccount deploy --slot 0
|
|
88
|
+
veil subaccount sweep --slot 0 --asset eth
|
|
89
|
+
veil subaccount recover --slot 0 --asset usdc --to 0xRecipientAddress --amount 25
|
|
90
|
+
|
|
91
|
+
# 9. Use JSON or unsigned modes when you need automation
|
|
80
92
|
veil status --json
|
|
81
93
|
veil deposit ETH 0.1 --unsigned
|
|
94
|
+
veil subaccount status --slot 0 --json
|
|
82
95
|
```
|
|
83
96
|
|
|
84
97
|
## CLI Tasks
|
|
@@ -188,25 +201,47 @@ veil merge USDC 100
|
|
|
188
201
|
veil merge ETH 0.1 --json
|
|
189
202
|
```
|
|
190
203
|
|
|
204
|
+
### Subaccounts
|
|
205
|
+
|
|
206
|
+
Subaccounts are deterministic child slots derived from your main `VEIL_KEY`:
|
|
207
|
+
|
|
208
|
+
`root key -> slot -> child key -> child deposit key -> forwarder`
|
|
209
|
+
|
|
210
|
+
Base mainnet only. Deploy and sweep are relay-backed. Status reports the forwarder wallet and queue state only, not private pool attribution after queued funds are accepted. Recovery is for assets still sitting on the forwarder after refund or rejection, and is submitted directly on-chain by your CLI gas payer.
|
|
211
|
+
|
|
212
|
+
```bash
|
|
213
|
+
veil subaccount derive --slot 0
|
|
214
|
+
veil subaccount status --slot 0
|
|
215
|
+
veil subaccount address --slot 0
|
|
216
|
+
veil subaccount deploy --slot 0
|
|
217
|
+
veil subaccount sweep --slot 0 --asset eth
|
|
218
|
+
veil subaccount recover --slot 0 --asset usdc --to 0xRecipientAddress --amount 25
|
|
219
|
+
veil subaccount status --slot 0 --json
|
|
220
|
+
```
|
|
221
|
+
|
|
191
222
|
## Environment Variables
|
|
192
223
|
|
|
193
224
|
The CLI uses two config files:
|
|
194
225
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
|
198
|
-
| `.env` |
|
|
226
|
+
|
|
227
|
+
| File | Purpose |
|
|
228
|
+
| ----------- | ---------------------------------------------------------------------------- |
|
|
229
|
+
| `.env.veil` | Veil keypair (VEIL_KEY, DEPOSIT_KEY) - created by `veil init` |
|
|
230
|
+
| `.env` | Wallet config (WALLET_KEY or SIGNER_ADDRESS, RPC_URL) - your existing config |
|
|
231
|
+
|
|
199
232
|
|
|
200
233
|
### Variables
|
|
201
234
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
|
205
|
-
| `
|
|
206
|
-
| `
|
|
207
|
-
| `
|
|
208
|
-
| `
|
|
209
|
-
| `
|
|
235
|
+
|
|
236
|
+
| Variable | Description |
|
|
237
|
+
| ---------------- | ---------------------------------------------------------------------------------------------- |
|
|
238
|
+
| `VEIL_KEY` | Your Veil private key (for ZK proofs, withdrawals, transfers) |
|
|
239
|
+
| `DEPOSIT_KEY` | Your Veil deposit key (public, for register/deposit) |
|
|
240
|
+
| `WALLET_KEY` | Ethereum wallet private key (for signing transactions) |
|
|
241
|
+
| `SIGNER_ADDRESS` | Ethereum address for unsigned/query flows when signing is handled externally |
|
|
242
|
+
| `RPC_URL` | Base RPC URL (optional, defaults to public RPC) |
|
|
243
|
+
| `RELAY_URL` | Override relay base URL for relayed CLI operations, subaccount deploy/sweep, and status checks |
|
|
244
|
+
|
|
210
245
|
|
|
211
246
|
`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`.
|
|
212
247
|
|
|
@@ -224,21 +259,24 @@ Commands print human-readable success output by default. Errors are standardized
|
|
|
224
259
|
|
|
225
260
|
### Error Codes
|
|
226
261
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
|
230
|
-
| `
|
|
231
|
-
| `
|
|
232
|
-
| `
|
|
233
|
-
| `
|
|
234
|
-
| `
|
|
235
|
-
| `
|
|
236
|
-
| `
|
|
237
|
-
| `
|
|
238
|
-
| `
|
|
239
|
-
| `
|
|
240
|
-
| `
|
|
241
|
-
| `
|
|
262
|
+
|
|
263
|
+
| Code | Description |
|
|
264
|
+
| ---------------------- | --------------------------------- |
|
|
265
|
+
| `VEIL_KEY_MISSING` | VEIL_KEY not provided |
|
|
266
|
+
| `WALLET_KEY_MISSING` | WALLET_KEY not provided |
|
|
267
|
+
| `DEPOSIT_KEY_MISSING` | DEPOSIT_KEY not provided |
|
|
268
|
+
| `CONFIG_CONFLICT` | Conflicting CLI env vars provided |
|
|
269
|
+
| `INVALID_ADDRESS` | Invalid Ethereum address format |
|
|
270
|
+
| `INVALID_SLOT` | Invalid subaccount slot format |
|
|
271
|
+
| `INVALID_AMOUNT` | Invalid or below minimum amount |
|
|
272
|
+
| `INSUFFICIENT_BALANCE` | Not enough ETH balance |
|
|
273
|
+
| `USER_NOT_REGISTERED` | Recipient not registered in Veil |
|
|
274
|
+
| `NO_UTXOS` | No unspent UTXOs available |
|
|
275
|
+
| `RELAY_ERROR` | Error from relayer service |
|
|
276
|
+
| `RPC_ERROR` | RPC/network error |
|
|
277
|
+
| `CONTRACT_ERROR` | Smart contract reverted |
|
|
278
|
+
| `UNKNOWN_ERROR` | Unexpected error |
|
|
279
|
+
|
|
242
280
|
|
|
243
281
|
## SDK Docs
|
|
244
282
|
|
package/SDK.md
CHANGED
|
@@ -10,7 +10,7 @@ If you are looking for the CLI first-run flow, go back to the main [README](./RE
|
|
|
10
10
|
import {
|
|
11
11
|
Keypair, buildRegisterTx, buildDepositETHTx,
|
|
12
12
|
buildDepositUSDCTx, buildApproveUSDCTx,
|
|
13
|
-
withdraw, transfer,
|
|
13
|
+
withdraw, transfer, getSubaccountStatus,
|
|
14
14
|
} from '@veil-cash/sdk';
|
|
15
15
|
import { createWalletClient, http } from 'viem';
|
|
16
16
|
import { base } from 'viem/chains';
|
|
@@ -65,6 +65,13 @@ const transferResult = await transfer({
|
|
|
65
65
|
pool: 'eth', // 'eth' | 'usdc' (default: 'eth')
|
|
66
66
|
});
|
|
67
67
|
|
|
68
|
+
// 7. Inspect a deterministic subaccount slot
|
|
69
|
+
const subaccount = await getSubaccountStatus({
|
|
70
|
+
rootPrivateKey: keypair.privkey as `0x${string}`,
|
|
71
|
+
slot: 0,
|
|
72
|
+
});
|
|
73
|
+
console.log(subaccount.slot.forwarderAddress);
|
|
74
|
+
|
|
68
75
|
```
|
|
69
76
|
|
|
70
77
|
## SDK API Reference
|
|
@@ -190,6 +197,53 @@ const privateBalance = await getPrivateBalance({
|
|
|
190
197
|
});
|
|
191
198
|
```
|
|
192
199
|
|
|
200
|
+
### Subaccounts
|
|
201
|
+
|
|
202
|
+
Subaccounts are deterministic child slots derived from your main Veil key:
|
|
203
|
+
|
|
204
|
+
`root key -> slot -> child key -> child deposit key -> forwarder`
|
|
205
|
+
|
|
206
|
+
Base mainnet only. Status shows the forwarder wallet and queue state only. Deploy and sweep are relay-backed. Recovery signs a forwarder withdraw request with the child key and returns a direct transaction for your gas payer to submit.
|
|
207
|
+
|
|
208
|
+
```typescript
|
|
209
|
+
import {
|
|
210
|
+
deriveSubaccountSlot,
|
|
211
|
+
getSubaccountStatus,
|
|
212
|
+
deploySubaccountForwarder,
|
|
213
|
+
sweepSubaccountForwarder,
|
|
214
|
+
buildSubaccountRecoveryTx,
|
|
215
|
+
} from '@veil-cash/sdk';
|
|
216
|
+
|
|
217
|
+
const slot = await deriveSubaccountSlot({
|
|
218
|
+
rootPrivateKey: veilKey,
|
|
219
|
+
slot: 0,
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
const status = await getSubaccountStatus({
|
|
223
|
+
rootPrivateKey: veilKey,
|
|
224
|
+
slot: 0,
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
await deploySubaccountForwarder({
|
|
228
|
+
rootPrivateKey: veilKey,
|
|
229
|
+
slot: 0,
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
await sweepSubaccountForwarder({
|
|
233
|
+
forwarderAddress: slot.forwarderAddress,
|
|
234
|
+
asset: 'eth',
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
const recovery = await buildSubaccountRecoveryTx({
|
|
238
|
+
rootPrivateKey: veilKey,
|
|
239
|
+
slot: 0,
|
|
240
|
+
asset: 'usdc',
|
|
241
|
+
to: '0xRecipientAddress',
|
|
242
|
+
amount: '25',
|
|
243
|
+
});
|
|
244
|
+
// Send recovery.transaction with your wallet client
|
|
245
|
+
```
|
|
246
|
+
|
|
193
247
|
### Addresses
|
|
194
248
|
|
|
195
249
|
```typescript
|