vapi-network 0.2.2 → 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 CHANGED
@@ -1,139 +1,467 @@
1
1
  # vAPI Network
2
2
 
3
3
  **One wallet, every x402 API.** vAPI Network is an open-source, non-custodial
4
- TypeScript toolkit for discovering and paying x402 services from a CLI, MCP
5
- client, or your own code. Call works today. Tasks and Compute are next.
4
+ TypeScript toolkit for discovering and paying x402 services from a terminal, an
5
+ MCP client, or your own code. Your key is generated on your machine, encrypted
6
+ under your passphrase, and never leaves it. vAPI applies spend policy before
7
+ signing, sends the payment straight to the service, and writes a local receipt.
6
8
 
7
- Your key stays encrypted on your machine. vAPI Network applies spend policy
8
- before signing, sends payment directly to the service, and writes receipts to a
9
- local append-only ledger. It does not hold funds, proxy payments, or send
10
- telemetry off the machine by default.
9
+ Call works today. Tasks and Compute are next.
11
10
 
12
- ## 60-second quickstart
13
-
14
- Install once, then every command is `vapi …`:
11
+ ## Quickstart
15
12
 
16
13
  ```bash
17
14
  npm i -g vapi-network
18
- vapi init # encrypted wallet + config under ~/.vapi (or $VAPI_HOME), prints the address
19
- ```
20
-
21
- Fund that address with `vapi fund` (card or Apple Pay via Coinbase Onramp) or by
22
- sending USDC on Base to it. Then:
23
-
24
- ```bash
25
- vapi fund # hosted onramp link, or direct-transfer instructions
26
- vapi search "weather" # every catalog, merged, with provenance
27
- vapi inspect <listing-ref> # request contract and the live 402 quote, before paying
15
+ vapi init # creates ~/.vapi, the wallet main, and prints its address
16
+ vapi backup # write the 12 words down; vAPI cannot recover them
17
+ vapi fund # opens the hosted funding page for your address
18
+ vapi search "weather" # every catalogue, merged, with provenance
28
19
  vapi pay <listing-ref> --max 0.02
29
- vapi balance
30
- vapi accounts # balances plus network-specific deposit guidance
31
- vapi receipts # one line per paid call: quote, settlement, latency
20
+ vapi receipts # one line per paid call: quote, settlement, latency
32
21
  ```
33
22
 
23
+ That is the same order `vapi init` prints as its next steps, and the same order
24
+ `vapi` alone lists. Two more are worth knowing early: `vapi inspect <ref>` shows
25
+ a listing's request contract and live 402 quote for free, before you pay, and
26
+ `vapi balance` shows what the wallet holds.
27
+
34
28
  `vapi search` tags each listing with its group — `[vapi]`, `[added]`,
35
- `[partner]`, or `[external]` — and prints the network fee already inside the
36
- price: vAPI and added APIs carry a 5% network fee inside the quoted price, while
29
+ `[partner]` or `[external]` — and prints the network fee that is already inside
30
+ the price. vAPI and added APIs carry a 5% network fee inside the quoted price;
37
31
  partner and external listings carry none. `vapi inspect` and `--json` return the
38
32
  same `group` and `fee` fields.
39
33
 
40
- No install? Prefix any command with `npx vapi-network`, for example `npx vapi-network init`.
41
- (`npx vapi` cannot work: the bare `vapi` name on npm belongs to an unrelated package.)
34
+ No install? Prefix any command with `npx vapi-network`, for example
35
+ `npx vapi-network init`. (`npx vapi` cannot work: the bare `vapi` name on npm
36
+ belongs to an unrelated package.)
37
+
38
+ ## Wallets
39
+
40
+ One machine can hold several wallets: your own, and a capped one per agent. Each
41
+ keystore lives in `$VAPI_HOME/wallets/<name>.json`; `$VAPI_HOME/wallets.json`
42
+ records which one is the default, what each may spend, and its label. Names are
43
+ 1 to 32 characters of lowercase letters, digits and dashes.
44
+
45
+ ```bash
46
+ vapi wallet list # address, default marker, caps, unlocked, label
47
+ vapi wallet create agent --label "claude code" # a wallet of its own for the agent
48
+ vapi wallet caps agent --per-call 0.05 --per-day 1
49
+ vapi wallet use agent # make it the default for later commands
50
+ vapi pay <listing-ref> --wallet agent --max 0.02
51
+ vapi receipts --wallet agent # or --all-wallets for every one
52
+ ```
53
+
54
+ Every command that touches a wallet takes `--wallet <name>`: `balance`,
55
+ `accounts`, `fund`, `pay`, `sweep`, `receipts`, `stats`, `export-key`, `backup`,
56
+ `import`, `passphrase`, `unlock`, `lock` and `mcp`. Without it, `VAPI_WALLET`
57
+ decides; without that, the default set by `vapi wallet use` does. Each of them
58
+ names the wallet it used — `Wallet: main (0x…)` on the first line, or a `wallet`
59
+ field in `--json` — so neither you nor an agent can be wrong about which key
60
+ just moved.
61
+
62
+ Spend caps belong to the wallet, not to the machine, and today's total is
63
+ counted per wallet: an agent cannot spend your daily allowance. Removing a
64
+ wallet is a move, not a delete — the encrypted keystore goes to
65
+ `wallets/.trash/`, where `vapi wallet restore` can bring it back.
66
+
67
+ **Coming from 0.2.x?** Nothing to do. The first command you run opens the wallet
68
+ store, moves `keystore.json` to `wallets/main.json` with its contents untouched,
69
+ turns `config.json`'s spend caps into the caps of `main`, and leaves
70
+ `keystore.json` behind as a mode 0600 symlink for one release so existing
71
+ scripts keep working. A home with no keystore migrates nothing.
72
+
73
+ ## Your wallet is yours
74
+
75
+ `vapi init` generates a 12-word BIP-39 recovery phrase on your machine, derives
76
+ the Base account (`m/44'/60'/0'/0/0`) and, with `--networks base,solana`, the
77
+ Solana account (`m/44'/501'/0'/0'`) from it, and writes the phrase encrypted
78
+ under your passphrase to `$VAPI_HOME/wallets/main.json` (mode 0600). The phrase
79
+ is shown once, on a terminal, and never in `--json` or piped output.
42
80
 
43
- ### Use it from an agent (MCP)
81
+ Three things vAPI cannot do:
82
+
83
+ - **See it.** No key, phrase or passphrase ever leaves the machine.
84
+ - **Recover it.** There is no copy anywhere to restore from.
85
+ - **Freeze it.** Payments go straight from your wallet to the service.
86
+
87
+ ### Back it up
88
+
89
+ ```bash
90
+ vapi backup # the 12 words, numbered, on a terminal
91
+ vapi backup --json # { "wallet": "main", "recoveryPhrase": "..." }
92
+ ```
93
+
94
+ Write the words on paper and keep them somewhere only you reach. Anyone holding
95
+ them can spend the wallet, so never type them into a website or a chat.
96
+
97
+ Wallets created before 0.2.5 have no recovery phrase. `vapi backup` says so and
98
+ points at `vapi export-key`, which prints the private key itself; back that key
99
+ up, or `vapi import --key` it into a new wallet. Restoring a phrase-based wallet
100
+ in MetaMask, Rabby, Coinbase Wallet or Phantom gives the same addresses.
101
+
102
+ ### Import and move a wallet
103
+
104
+ ```bash
105
+ vapi import --phrase # type the words at the prompt
106
+ vapi import --phrase --networks base,solana # restore both accounts
107
+ vapi import --key # a 0x private key instead of words
108
+ vapi import --phrase --wallet backup-2026 # into a named wallet of its own
109
+ ```
110
+
111
+ `vapi import` reads the secret from a prompt, never from the command line where
112
+ a shell history would keep it, and asks for a new passphrase. It writes a new
113
+ named wallet rather than replacing one: `--wallet <name>` chooses the name, and
114
+ `main` is assumed only on a machine with no wallet yet. `--replace` moves the
115
+ named wallet to `wallets/.trash/` first, and still refuses a wallet that holds
116
+ USDC on Base unless you add `--force`.
117
+
118
+ ### Change the passphrase
119
+
120
+ ```bash
121
+ vapi passphrase # current passphrase, then the new one twice
122
+ ```
44
123
 
45
- Add this to Claude Desktop, Claude Code, or Cursor. The passphrase unlocks the local keystore; it never leaves the machine.
124
+ The wallet, its addresses and its recovery phrase are unchanged. Any copy of the
125
+ old passphrase stored by `vapi unlock` is removed at the same time, so nothing
126
+ is left behind that no longer opens the wallet.
127
+
128
+ ### Agents and secrets
129
+
130
+ An agent can drive vAPI all day without ever seeing a secret. It can search,
131
+ inspect, pay from the wallet you gave it, read balances and receipts, and pick a
132
+ wallet by name with `wallet.use` — which changes only that session, never your
133
+ default on disk. It cannot see a recovery phrase, a private key or a passphrase,
134
+ and the MCP server has no tool that creates, removes, renames, backs up or
135
+ exports a wallet.
136
+
137
+ `vapi backup` and `vapi export-key` print a secret, so they run only when a
138
+ person is demonstrably there: stdin and stdout are both a real terminal, no
139
+ agent or CI marker is set, and you type the wallet's own name to confirm.
140
+ Otherwise they print nothing and say:
141
+
142
+ ```text
143
+ Run this yourself in a terminal; an agent must never see these words.
144
+ ```
145
+
146
+ The markers vAPI refuses on are `VAPI_NO_SECRETS`, `CLAUDECODE`, `CLAUDE_CODE`,
147
+ `CURSOR_AGENT`, `CODEX_SANDBOX`, `OPENAI_CODEX`, `AGENT` and `CI`. Set
148
+ `VAPI_NO_SECRETS=1` in a machine's agent configuration to switch secret printing
149
+ off outright. `vapi init` and `vapi wallet create` still create the wallet under
150
+ those conditions; they simply say `Recovery phrase: run vapi backup yourself in
151
+ a terminal to see it.`
152
+
153
+ In the SDK the same line is drawn by the module layout: the functions that
154
+ return a phrase or a key live in the separate `@vapi-network/core/secrets` entry
155
+ point, which the MCP package is forbidden by lint to import.
156
+
157
+ ### Where the passphrase lives
158
+
159
+ An unlock looks in three places, in this order:
160
+
161
+ 1. `VAPI_KEYSTORE_PASSWORD`, kept for CI and for Windows.
162
+ 2. The OS secret store: the macOS Keychain, or libsecret on Linux, under the
163
+ service `vapi-network` and the wallet's name.
164
+ 3. A prompt, when a person is there to answer it.
165
+
166
+ ```bash
167
+ vapi unlock --wallet agent # store it, once, in your own terminal
168
+ vapi wallet list # the UNLOCKED column says which agents can pay
169
+ vapi lock --all # take every stored passphrase back out
170
+ ```
171
+
172
+ `vapi unlock` runs only on a real terminal with no agent marker set, and only
173
+ after it has verified that the passphrase really opens that wallet. The
174
+ passphrase is handed to the OS binary over its standard input, never as a
175
+ command-line argument, so it never appears in `ps`. A run that finds no
176
+ passphrase anywhere and has no terminal says so and names both other routes; an
177
+ agent is never prompted. Windows has no store yet and keeps
178
+ `VAPI_KEYSTORE_PASSWORD`.
179
+
180
+ ### The audit log
181
+
182
+ Every secret export, every wallet change — create, import, remove, restore,
183
+ rename, default, caps, passphrase, unlock, lock — and every MCP session wallet
184
+ switch appends one JSON line to `$VAPI_HOME/audit.log` (mode 0600): the time,
185
+ the event, the wallet, whether a terminal was attached, and which marker was
186
+ set. The line never contains the secret itself, so the log answers "did anything
187
+ export my phrase while the agent was running" without you having to trust the
188
+ agent's own account of it.
189
+
190
+ ## CLI reference
191
+
192
+ Every command accepts `--json`, which writes one JSON value — success or error —
193
+ to stdout. Exit codes are `0` for success, `1` for an operational failure, and
194
+ `2` for invalid usage or an announced preview-only command.
195
+
196
+ | Command | Options | What it does |
197
+ | -------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------- |
198
+ | `vapi init` | `--networks <base,solana>` | Creates `~/.vapi`, the wallet `main` and the config. Says so if one exists. |
199
+ | `vapi wallet list` | — | Name, address, default marker, caps in USD, unlocked, label |
200
+ | `vapi wallet create <name>` | `--networks <base,solana>`, `--label <text>` | A new wallet, with its own phrase, caps and passphrase |
201
+ | `vapi wallet use <name>` | — | Makes it the default for every later command |
202
+ | `vapi wallet rename <old> <new>` | — | Renames the keystore, the registry entry and that wallet's receipts |
203
+ | `vapi wallet remove <name>` | `--force` | Moves the keystore to `wallets/.trash/`; asks you to type the name |
204
+ | `vapi wallet restore <name>` | — | Brings a removed wallet back, same passphrase |
205
+ | `vapi wallet caps <name>` | `--per-call <usd>`, `--per-day <usd>` | Sets that wallet's spend caps, in US dollars |
206
+ | `vapi fund` | `--amount <usd>`, `--wallet <name>` | Prints and opens the hosted funding page. Makes no network call. |
207
+ | `vapi accounts` | `--enable solana`, `--wallet <name>` | One deposit account per configured network, with balances and guidance |
208
+ | `vapi search [query]` | `--kind <kind>` (repeatable), `--network <caip2>`, `--limit <n>`, `--cursor <cursor>` | Merged discovery across every configured source |
209
+ | `vapi inspect <id>` | `--endpoint <name>` | A listing's request contract and live 402 quote, for free |
210
+ | `vapi pay <id-or-url>` | `--method`, `--endpoint`, `--body <json>`, `--content-type`, `--network <caip2>`, `--expected-pay-to`, `--max <usd>`, `--wallet <name>` | Calls the API and pays it from the local wallet |
211
+ | `vapi balance` | `--wallet <name>` | The wallet's address and USDC balances |
212
+ | `vapi receipts` | `--limit <n>`, `--wallet <name>`, `--all-wallets` | The local append-only call ledger, newest last |
213
+ | `vapi receipts export` | `--format <json\|csv>`, `--range <24h\|7d\|30d>`, `--wallet <name>`, `--all-wallets` | Raw receipts for a spreadsheet or dashboard |
214
+ | `vapi stats` | `--range <24h\|7d\|30d>`, `--wallet <name>`, `--all-wallets` | Spend, outcomes, latency percentiles and top services |
215
+ | `vapi sweep <address>` | `--network <caip2>`, `--wallet <name>` | Moves the USDC balance out to an address you own |
216
+ | `vapi export-key` | `--network <caip2>`, `--wallet <name>` | Prints the private key. Terminal only, never for an agent. |
217
+ | `vapi backup` | `--wallet <name>` | Prints the 12 words. Terminal only, never for an agent. |
218
+ | `vapi import` | `--phrase` or `--key`, `--wallet <name>`, `--networks <base,solana>`, `--replace`, `--force` | Restores a wallet from a prompt, never from argv |
219
+ | `vapi passphrase` | `--wallet <name>` | Re-encrypts the keystore under a new passphrase |
220
+ | `vapi unlock` | `--wallet <name>` | Puts that wallet's passphrase in the OS secret store |
221
+ | `vapi lock` | `--wallet <name>`, `--all` | Takes a stored passphrase back out |
222
+ | `vapi report "<what>"` | `--include-addresses`, `--send` | Writes a privacy-preserving local bug report |
223
+ | `vapi mcp` | `--wallet <name>` | Serves the MCP tools over stdio |
224
+ | `vapi serve` | — | Preview only; exits `2` with a message |
225
+ | `vapi publish` | — | Preview only; exits `2` with a message |
226
+ | `vapi version` | — | The client version, also as `--version` or `-v` |
227
+ | `vapi help` | — | The same help bare `vapi` shows, also as `--help` or `-h` |
228
+
229
+ `vapi pay` also accepts `--max-price-usd` as a long-standing alias for `--max`;
230
+ the two cannot be combined. `mcp --json` is accepted as a no-op, because the
231
+ stdio transport is already JSON-RPC.
232
+
233
+ ## MCP
234
+
235
+ Add this to Claude Code, Claude Desktop or Cursor:
46
236
 
47
237
  ```json
48
238
  {
49
239
  "mcpServers": {
50
240
  "vapi": {
51
241
  "command": "npx",
52
- "args": ["-y", "vapi-network", "mcp"],
53
- "env": { "VAPI_KEYSTORE_PASSWORD": "your-passphrase" }
242
+ "args": ["-y", "vapi-network", "mcp"]
54
243
  }
55
244
  }
56
245
  }
57
246
  ```
58
247
 
59
- Tools: `call.search`, `call.inspect`, `call.pay`, `wallet.address`, `wallet.balance`,
60
- `wallet.accounts`, `wallet.fund`, `receipts.list`, `receipts.stats`, `support.report`. Spend caps
61
- default to $0.10 per call and $1.00 per day; the wallet checks both before it signs a payment.
248
+ Then hand the passphrase to your operating system once, in your own terminal:
62
249
 
63
- ## Sign-in with X
250
+ ```bash
251
+ vapi unlock # the passphrase goes into the macOS Keychain or libsecret
252
+ ```
253
+
254
+ The passphrase never leaves the machine and never has to appear in an editor's
255
+ configuration file. `vapi lock` takes it back out. On Windows, until there is a
256
+ Credential Manager path, keep using
257
+ `"env": { "VAPI_KEYSTORE_PASSWORD": "your-passphrase" }` instead.
258
+
259
+ Give an agent its own capped wallet by creating it yourself and pinning the
260
+ agent to it:
64
261
 
65
- x402 v2 services can require Sign-In-With-X (SIWX) before returning a price. When `call.pay` or
66
- `vapi pay` receives that challenge, vAPI checks that both the challenge domain and URI match the
67
- final resource origin, signs the canonical EIP-4361 message locally with EVM `personal_sign`, and
68
- retries once with `SIGN-IN-WITH-X`. The proof is never sent to a redirect or a different host.
262
+ ```bash
263
+ vapi wallet create agent-claude --label "claude code"
264
+ vapi wallet caps agent-claude --per-day 5
265
+ vapi unlock --wallet agent-claude
266
+ ```
69
267
 
70
- If the retry returns a normal 402 quote, the usual spend-policy and payment flow continues. If the
71
- resource is free after sign-in, the result has `outcome: "signed_in"` and the local receipt records
72
- `amountAtomic: "0"`.
268
+ ```json
269
+ {
270
+ "mcpServers": {
271
+ "vapi": {
272
+ "command": "npx",
273
+ "args": ["-y", "vapi-network", "mcp", "--wallet", "agent-claude"],
274
+ "env": {
275
+ "VAPI_WALLET": "agent-claude",
276
+ "VAPI_NO_SECRETS": "1"
277
+ }
278
+ }
279
+ }
280
+ }
281
+ ```
73
282
 
74
- ## Fund the wallet
283
+ The agent pays from `agent-claude` and no more than $5 a day, whatever it asks
284
+ for; your own wallet is not reachable from that session, because only
285
+ `agent-claude` was unlocked. `vapi wallet list` shows which wallets are unlocked
286
+ that way.
287
+
288
+ ### Tools
289
+
290
+ | Tool | Input | Result |
291
+ | ----------------- | --------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------- |
292
+ | `call.search` | `query`, `kinds[]`, `network`, `limit`, `cursor` | One discovery page: `items`, `nextCursor`, `unavailableKinds`, `rankingVersion` |
293
+ | `call.inspect` | `id`, `endpoint` | A listing's request contract and live quote, for free, before paying |
294
+ | `call.pay` | `wallet`, `id` or `url`, `method`, `endpoint`, `body`, `contentType`, `network`, `expectedPayTo`, `maxPriceUsd` | `wallet`, `status`, `body`, `payment`, and `expectedRequest` when a 402 named one |
295
+ | `wallet.address` | `wallet` | `wallet`, `address` |
296
+ | `wallet.balance` | `wallet` | `wallet`, `address`, `balances[]` per configured network |
297
+ | `wallet.accounts` | `wallet` | `wallet`, `accounts[]` with USDC, gas balance and deposit guidance |
298
+ | `wallet.list` | — | `wallet`, `default`, and every wallet with caps in atomic USDC and dollars, balances, and `balanceError` when an RPC is unreachable |
299
+ | `wallet.use` | `name` | `wallet`, `active`, `previous`, `scope: "session"` |
300
+ | `wallet.fund` | `wallet`, `amountUsd` | `wallet`, `address`, `network`, `url`, `instructions` |
301
+ | `receipts.list` | `wallet`, `allWallets`, `limit` | `wallet`, `receipts[]` |
302
+ | `receipts.stats` | `wallet`, `allWallets`, `range` | `wallet`, `range`, `generatedAt`, `totals`, `outcomes`, `latency`, `topServices`, `search` |
303
+ | `support.report` | `message`, `includeAddresses`, `send` | `path`, `issueUrl`, the report itself, and `responseCode` when sent |
304
+
305
+ `wallet` is optional on every tool that takes it: without it the session's
306
+ active wallet is used, then `VAPI_WALLET`, then the machine default. Every
307
+ result names the wallet it used. `call.pay` applies that wallet's own spend caps
308
+ before it signs and tags the receipt with its name. `wallet.use` moves the
309
+ session onto another wallet **for this process only** — it never rewrites
310
+ `wallets.json`, so your own terminal keeps the default you chose — and appends a
311
+ `wallet.use.session` line to the audit log. Reads need no passphrase at all.
312
+
313
+ Spend caps default to $0.10 per call and $1.00 per day.
314
+
315
+ #### Deprecated tool aliases
316
+
317
+ These four pre-namespace names still work and still behave identically, but each
318
+ result carries one `DEPRECATED:` line naming its replacement. They will be
319
+ removed in a later release.
320
+
321
+ | Alias | Use instead |
322
+ | --------- | ---------------- |
323
+ | `search` | `call.search` |
324
+ | `inspect` | `call.inspect` |
325
+ | `call` | `call.pay` |
326
+ | `wallet` | `wallet.balance` |
327
+
328
+ #### What the MCP server cannot do
329
+
330
+ Create, rename, remove, restore, back up, import or export a wallet, or return a
331
+ recovery phrase, a private key or a passphrase. Those stay in the CLI, in front
332
+ of a person.
333
+
334
+ ## SDK
75
335
 
76
336
  ```bash
77
- vapi fund # ask the registry for a hosted onramp session
78
- vapi fund --amount 25 # prefill a US dollar amount
79
- vapi fund --json # stable machine-readable shape
337
+ npm i @vapi-network/core @vapi-network/sources
338
+ ```
339
+
340
+ `@vapi-network/core` is the main entry point: the x402 protocol, the wallet
341
+ store, spend policy, the network guard, discovery merge and the receipt ledger.
342
+ `@vapi-network/core/secrets` is a second, deliberately separate entry point for
343
+ the four functions that return a recovery phrase or a private key —
344
+ `exportRecoveryPhrase`, `exportKeystoreKeys`, `createKeystoreWithPhrase` and
345
+ `decryptPrivateKey`. They are not re-exported from the main index, and the MCP
346
+ package is forbidden by lint to import them, so a surface an agent drives cannot
347
+ reach a secret by accident.
348
+
349
+ Search and pay:
350
+
351
+ ```ts
352
+ import {
353
+ LocalWallet,
354
+ SpendPolicy,
355
+ WalletStore,
356
+ getVapiPaths,
357
+ loadConfig,
358
+ resolvePassphrase,
359
+ spendCapsForWallet,
360
+ } from "@vapi-network/core";
361
+ import { vapiRegistrySource } from "@vapi-network/sources";
362
+
363
+ const paths = getVapiPaths();
364
+ const config = await loadConfig(paths.config);
365
+ const [listing] = await vapiRegistrySource(config.marketplaceDiscoveryUrl, {
366
+ discoveryUrl: config.discoveryUrl,
367
+ }).search("weather");
368
+
369
+ const store = await WalletStore.open(paths.directory);
370
+ const { name } = store.resolve();
371
+ const account = await store.unlock(name, (await resolvePassphrase(name)).passphrase);
372
+ const wallet = new LocalWallet(
373
+ account,
374
+ new SpendPolicy(await spendCapsForWallet(store, name), {
375
+ ledgerPath: paths.ledger,
376
+ wallet: name,
377
+ }),
378
+ );
80
379
  ```
81
380
 
82
- `vapi fund` POSTs `{ address, network: "base", asset: "USDC", fiatAmount }` to
83
- `<registry>/api/wallet/onramp-session` through the same guarded network client as
84
- every other command, prints the returned URL, and opens it in your default
85
- browser when you are on a terminal. The onramp is **Coinbase's**: Coinbase takes
86
- the card or Apple Pay payment and sends USDC straight to your local address.
87
- **vAPI never holds your funds**, never proxies the payment, and never sees your
88
- card details or your private key.
381
+ Manage wallets:
89
382
 
90
- When the registry replies `503 onramp_unavailable` — or cannot be reached at all
91
- — the command stays useful instead of failing: it prints your address and
383
+ ```ts
384
+ import { WalletStore, getVapiPaths, usdToAtomic } from "@vapi-network/core";
92
385
 
93
- ```text
94
- Send USDC on Base (eip155:8453) to this address; add a little ETH for gas if you plan to sweep.
386
+ const store = await WalletStore.open(getVapiPaths().directory);
387
+ for (const wallet of await store.list()) {
388
+ console.log(wallet.name, wallet.address, wallet.isDefault, wallet.spendCaps);
389
+ }
390
+ await store.setSpendCaps("agent", {
391
+ perCallAtomic: String(usdToAtomic(0.05)),
392
+ perDayAtomic: String(usdToAtomic(1)),
393
+ });
95
394
  ```
96
395
 
97
- Either way it finishes by printing the current balance. MCP clients can use the
98
- `wallet.fund` tool, which returns the same `{ url }` or the same fallback text.
396
+ `WalletStore` is the one entry point for the layout: `open`, `list`, `resolve`,
397
+ `create`, `importKey`, `unlock`, `setDefault`, `rename`, `setLabel`,
398
+ `setSpendCaps`, `remove`, `restore` and `listTrash`. It never rewrites key
399
+ material; it moves, names and caps keystores.
99
400
 
100
- ## Accounts and deposits
401
+ Two runnable examples live in [`examples/`](./examples):
402
+ [`pay-with-sdk.ts`](./examples/pay-with-sdk.ts) (`pnpm example:pay -- weather`)
403
+ and [`wallets.ts`](./examples/wallets.ts) (`pnpm example:wallets -- agent-demo`).
101
404
 
102
- `vapi accounts` lists one deposit account for every configured network, including its CAIP-2 ID,
103
- network name, address, atomic and formatted USDC balance, gas-token balance, and deposit guidance.
104
- Use `--json` for the stable `{ "accounts": [...] }` shape. `vapi init` prints the same account list
105
- after creating the encrypted keystore and configuration. MCP clients can use `wallet.accounts`.
405
+ ## Configuration
106
406
 
107
- Base uses the wallet's EVM address and tells you to send USDC on Base. For Arc testnet, add the
108
- faucet URL or instructions to that network's `config.json` entry:
407
+ Local state lives in `~/.vapi/`:
109
408
 
110
- ```json
111
- {
112
- "depositUrl": "https://your-arc-faucet.example",
113
- "depositInstructions": "Use the configured Arc testnet faucet, then send USDC to this address."
114
- }
409
+ ```text
410
+ config.json registry URLs, networks and RPC endpoints
411
+ wallets.json which wallet is the default, plus per-wallet caps and labels
412
+ wallets/
413
+ main.json one encrypted keystore per wallet, mode 0600
414
+ .trash/ removed wallets, kept encrypted, never deleted for you
415
+ keystore.json a 0600 symlink to wallets/main.json, for one release
416
+ audit.log one JSON line per secret export or wallet change
417
+ receipts.jsonl the append-only call ledger
418
+ searches.jsonl one line per discovery query
419
+ spend-ledger.json today's total, per wallet
420
+ reports/ what vapi report writes
115
421
  ```
116
422
 
117
- Account lookup dispatches by CAIP namespace: the EVM and Solana adapters use their corresponding
118
- local address and guarded RPC balance calls without coupling one wallet family to the other.
423
+ | Variable | What it does |
424
+ | ------------------------ | --------------------------------------------------------------------------- |
425
+ | `VAPI_HOME` | Use a different directory instead of `~/.vapi` |
426
+ | `VAPI_WALLET` | The wallet to use when no `--wallet` is given |
427
+ | `VAPI_REGISTRY_URL` | Replace the registry base; the canonical discovery paths derive from it |
428
+ | `VAPI_KEYSTORE_PASSWORD` | The passphrase, for CI and for Windows. Checked before the OS secret store. |
429
+ | `VAPI_NO_SECRETS` | Set to `1` to stop `vapi backup` and `vapi export-key` printing anything |
119
430
 
120
- ## Reporting a bug
431
+ `ARC_TESTNET_RPC_URL` and `SOLANA_RPC_URL` point those two networks at an
432
+ endpoint you trust. On first use of the default home, the client copies an
433
+ existing `~/.vapi/agent-cash/` configuration into `~/.vapi/` when it can do so
434
+ without overwriting files, prints a notice, and leaves the old directory alone.
435
+
436
+ ## Funding
121
437
 
122
438
  ```bash
123
- vapi report "the provider returned 402 twice"
124
- vapi report "the provider returned 402 twice" --include-addresses
125
- vapi report "the provider returned 402 twice" --send
439
+ vapi fund # open the funding page for your address
440
+ vapi fund --amount 25 # prefill a US dollar amount
441
+ vapi fund --json # { address, network, url }
126
442
  ```
127
443
 
128
- The command first writes `$VAPI_HOME/reports/<timestamp>.json`, then prints that path and a prefilled
129
- GitHub issue URL. Reports contain the message, client version, OS/Node information, and only the
130
- newest five receipt IDs. Wallet and payee addresses are included only with `--include-addresses`;
131
- amounts are never included. No report is uploaded unless `--send` is explicit. With `--send`, vAPI
132
- uses the guarded network client to POST the same JSON to the configured registry and prints the HTTP
133
- response code, including non-success responses such as 404. MCP clients can use `support.report`
134
- with the corresponding `includeAddresses` and `send` booleans.
444
+ `vapi fund` prints `<registry>/fund/<your-address>` and opens it in your default
445
+ browser when you are on a terminal. The page offers three routes: a card via
446
+ Coinbase (needs a Coinbase account; US guest checkout), a transfer from
447
+ MetaMask, Coinbase Wallet or WalletConnect, or a bridge from another chain. It
448
+ is public, takes no sign-in, and mints the card session when you click — so the
449
+ link keeps working while you log in, and nothing expires in your scrollback.
135
450
 
136
- ## Networks
451
+ The command itself makes **no network call**: it works offline, and it always
452
+ also prints
453
+
454
+ ```text
455
+ Send USDC on Base (eip155:8453) to this address; add a little ETH for gas if you plan to sweep.
456
+ ```
457
+
458
+ Whichever route you pick, the USDC lands on your local address on Base. **vAPI
459
+ never holds your funds**, never proxies the payment, and never sees your card
460
+ details or your private key. MCP clients use `wallet.fund`, which returns the
461
+ same `{ address, network, url }` plus a line telling the agent to hand the link
462
+ to its human.
463
+
464
+ ## Networks and accounts
137
465
 
138
466
  | Network | x402 identifier | USDC | Gas / RPC notes |
139
467
  | -------------- | ----------------------------------------------------- | ---------------------------------------------- | ------------------------------------------------------ |
@@ -143,147 +471,123 @@ with the corresponding `includeAddresses` and `send` booleans.
143
471
 
144
472
  The x402 reference packages shorten the Solana CAIP-2 reference to
145
473
  `solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp`; vAPI accepts that identifier as an
146
- alias while persisting the full genesis hash above. Arc mainnet is not enabled:
147
- **not yet — placeholder only.** Arc and the x402 packages do not publish a
148
- mainnet RPC plus canonical USDC, so the client deliberately carries only a
149
- non-routable code placeholder instead of guessing a production configuration.
474
+ alias while persisting the full genesis hash above. Arc mainnet is **not yet — a
475
+ placeholder only**: Arc and the x402 packages publish no mainnet RPC plus
476
+ canonical USDC, so the client carries a non-routable placeholder rather than
477
+ guessing a production configuration.
150
478
 
151
- Create both local accounts during initialization:
479
+ `vapi accounts` lists one deposit account per configured network: its CAIP-2 ID,
480
+ network name, address, atomic and formatted USDC balance, gas-token balance, and
481
+ deposit guidance. Account lookup dispatches by CAIP namespace, so the EVM and
482
+ Solana adapters stay independent of one another. For Arc testnet, add the faucet
483
+ to that network's `config.json` entry:
152
484
 
153
- ```bash
154
- vapi init --networks base,solana
155
- ```
156
-
157
- Or add an Ed25519 account to an existing encrypted keystore:
158
-
159
- ```bash
160
- vapi accounts --enable solana
485
+ ```json
486
+ {
487
+ "depositUrl": "https://your-arc-faucet.example",
488
+ "depositInstructions": "Use the configured Arc testnet faucet, then send USDC to this address."
489
+ }
161
490
  ```
162
491
 
163
- Fund the printed Solana address with SPL USDC. Exact x402 payments use the
164
- facilitator advertised in the challenge as fee payer, so they do not consume the
165
- local SOL balance. `vapi sweep <solana-address> --network
166
- solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdpKuc147dw2N9d` is a separate transaction
167
- and requires a small amount of SOL locally for fees and, when necessary,
168
- creation of the destination token account. The default public Solana RPC is
492
+ Create both local accounts at initialization with `vapi init --networks
493
+ base,solana`, or add an Ed25519 account to an existing keystore with `vapi
494
+ accounts --enable solana`. Fund the printed Solana address with SPL USDC. Exact
495
+ x402 payments use the facilitator advertised in the challenge as fee payer, so
496
+ they do not consume the local SOL balance; `vapi sweep` is a separate
497
+ transaction and does need a little SOL. The default public Solana RPC is
169
498
  rate-limited and has no availability guarantee; set `SOLANA_RPC_URL` to a
170
- trusted dedicated endpoint for regular use.
499
+ dedicated endpoint for regular use.
171
500
 
172
501
  ## Discovery sources
173
502
 
174
- Discovery is a plugin interface. The client can merge listings from multiple
175
- sources, de-duplicate them by resource URL, and retain each listing's
503
+ Discovery is a plugin interface. The client merges listings from several
504
+ sources, de-duplicates them by normalized resource URL, and keeps each listing's
176
505
  provenance:
177
506
 
178
- - **vAPI Registry** is enabled by the default distribution, using
179
- `https://api.vapinetwork.ai/api/call/discovery` for discovery and
180
- `https://api.vapinetwork.ai/api/call/services` for service details. If the
181
- primary returns HTTP 404 or cannot be resolved, the client logs one notice
182
- and tries the configured fallback at `https://console.vapinetwork.ai`, using
183
- the same canonical paths. The registry's historical `/api/marketplace/discovery`
184
- and `/api/network/services` paths still answer for one release and reply with
185
- `Deprecation: true` plus a `Link` header naming the successor; a base URL
186
- supplied on either of them is normalized to the canonical pair.
187
- - **Coinbase Bazaar** reads the public x402 v2
188
- `/discovery/resources` catalog exposed by a facilitator.
189
- - **Local file** reads a JSON array of listings for private or development
190
- catalogs.
191
- - **x402scan** is a deliberate stub for now. The source research documents its
192
- discovery convention, but not a stable public read API that this client can
193
- safely target.
194
-
195
- Use `@vapi-network/sources` to compose only the catalogs you trust. Network
196
- access is guarded against local and private destinations before a request is
197
- made.
198
-
199
- Set `VAPI_REGISTRY_URL` to replace the registry base; the client derives
200
- `/api/call/discovery` and `/api/call/services` beneath it. The existing
201
- `VAPI_MARKETPLACE_DISCOVERY_URL` and `VAPI_DISCOVERY_URL` variables can still
202
- override either full endpoint separately. Registry fallbacks are stored in
203
- `config.json` under `registryFallbacks`.
204
-
205
- ## Packages
206
-
207
- | Package | Purpose |
208
- | ----------------------- | ------------------------------------------------------------------------ |
209
- | `@vapi-network/core` | x402 protocol, wallet, spend policy, discovery merge, and receipts |
210
- | `@vapi-network/sources` | vAPI Registry, Coinbase Bazaar, local-file, and x402scan source adapters |
211
- | `@vapi-network/mcp` | stdio MCP server with namespaced payment tools |
212
- | `@vapi-network/cli` | `init`, discovery, payment, wallet, receipt, and MCP commands |
213
- | `vapi-network` | zero-dependency distribution with the `vapi` binary and defaults |
507
+ - **vAPI Registry**, enabled by the default distribution, using
508
+ `https://api.vapinetwork.ai/api/call/discovery` and
509
+ `https://api.vapinetwork.ai/api/call/services`. If the primary returns HTTP
510
+ 404 or cannot be resolved, the client logs one notice and tries the hosts in
511
+ `registryFallbacks` on the same canonical paths. The historical
512
+ `/api/marketplace/discovery` and `/api/network/services` paths are deprecated;
513
+ a base URL supplied on either is normalized to the canonical pair.
514
+ - **Coinbase Bazaar**, the public x402 v2 `/discovery/resources` catalogue
515
+ exposed by a facilitator.
516
+ - **Local file**, a JSON array of listings for private or development
517
+ catalogues.
518
+ - **x402scan**, a deliberate stub until x402scan documents a stable public read
519
+ API this client can safely target.
520
+
521
+ Use `@vapi-network/sources` to compose only the catalogues you trust. Every
522
+ outbound request is guarded against local and private destinations before it is
523
+ made, and redirects and resolved IP addresses are re-validated as new
524
+ destinations.
214
525
 
215
- Every npm tarball is bundled and has zero runtime dependencies. The scoped
216
- packages are useful for embedding; most users should start with
217
- `vapi-network`.
218
-
219
- ## SDK
526
+ ## Sign-in with X
220
527
 
221
- The core and source packages can be used without the CLI or MCP layer. See the
222
- runnable [SDK example](./examples/pay-with-sdk.ts) for discovery, policy
223
- validation, local signing, and direct x402 payment construction.
528
+ x402 v2 services can require Sign-In-With-X (SIWX) before returning a price.
529
+ When `vapi pay` or `call.pay` receives that challenge, vAPI checks that both the
530
+ challenge domain and URI match the final resource origin, signs the canonical
531
+ EIP-4361 message locally with EVM `personal_sign`, and retries once with
532
+ `SIGN-IN-WITH-X`. The proof is never sent to a redirect or a different host.
224
533
 
225
- Run it after initialization with `pnpm example:pay -- weather`.
534
+ If the retry returns a normal 402 quote, the usual spend-policy and payment flow
535
+ continues. If the resource is free after sign-in, the result has
536
+ `outcome: "signed_in"` and the local receipt records `amountAtomic: "0"`.
226
537
 
227
- ## Local state and migration
538
+ ## Metrics and bug reports
228
539
 
229
- By default, local state lives in `~/.vapi/`:
540
+ vAPI measures call and discovery health locally and uploads nothing. Receipts
541
+ can include the listing name and provider host, policy decision, retry count,
542
+ client version, outcome, total latency, and discovery, quote, signing, request
543
+ and settlement phase timings. Policy declines are recorded with the quoted
544
+ amount but without a payer or transaction, so blocked spend stays visible
545
+ without creating a payment authorization. Search events record the query,
546
+ sources tried, per-source latency and result count, merged result count and
547
+ timestamp.
230
548
 
231
- ```text
232
- config.json
233
- keystore.json
234
- receipts.jsonl
235
- spend-ledger.json
236
- reports/
549
+ ```sh
550
+ vapi stats --range 7d
551
+ vapi receipts export --format csv --range 30d
237
552
  ```
238
553
 
239
- Set `VAPI_HOME` to use a different directory. On first use of the default home,
240
- the client copies an existing `~/.vapi/agent-cash/` configuration into
241
- `~/.vapi/` when it can do so without overwriting files, prints a migration
242
- notice, and leaves the old directory untouched.
243
-
244
- ## Metrics
554
+ `vapi report "<what happened>"` writes `$VAPI_HOME/reports/<timestamp>.json` and
555
+ prints that path plus a prefilled GitHub issue URL. Reports contain the message,
556
+ client version, OS and Node information, and only the newest five receipt IDs.
557
+ Wallet and payee addresses are included only with `--include-addresses`; amounts
558
+ never are. Nothing is uploaded unless `--send` is explicit.
245
559
 
246
- vAPI measures call and discovery health locally. Call receipts can include the
247
- listing name and provider host, policy decision, retry count, client version,
248
- outcome, total latency, and discovery, quote, signing, request, and settlement
249
- phase timings. Policy declines are recorded with the quoted amount but without
250
- a payer or transaction, so blocked spend remains visible without creating a
251
- payment authorization. Search events record the query, sources tried,
252
- per-source latency and result count, merged result count, and timestamp.
253
-
254
- Call receipts are appended to `$VAPI_HOME/receipts.jsonl`; search events are
255
- appended to `$VAPI_HOME/searches.jsonl`. Nothing in either ledger is uploaded,
256
- and vAPI sends no telemetry off the machine by default. The vAPI website can
257
- show public on-chain usage for a wallet address directly from the chain; that
258
- view does not require uploading these local files.
560
+ ## Packages
259
561
 
260
- Use `vapi stats --range 24h|7d|30d` for a human-readable summary or add `--json`
261
- for the stable `{ range, generatedAt, totals, outcomes, latency, topServices,
262
- search }` shape. `receipts.stats` exposes the same shape through MCP. Export raw
263
- receipts for spreadsheets and dashboards with:
562
+ | Package | Purpose |
563
+ | ----------------------- | ----------------------------------------------------------------------- |
564
+ | `vapi-network` | zero-dependency distribution with the `vapi` binary and defaults |
565
+ | `@vapi-network/core` | x402 protocol, wallet store, spend policy, discovery merge and receipts |
566
+ | `@vapi-network/sources` | vAPI Registry, Coinbase Bazaar, local-file and x402scan source adapters |
567
+ | `@vapi-network/mcp` | stdio MCP server with namespaced payment tools |
568
+ | `@vapi-network/cli` | command parsing and the command implementations behind `vapi` |
264
569
 
265
- ```sh
266
- vapi receipts export --format json --range 30d
267
- vapi receipts export --format csv --range 30d
268
- ```
570
+ Every npm tarball is bundled and has zero runtime dependencies. The scoped
571
+ packages are useful for embedding; most users should start with `vapi-network`.
269
572
 
270
573
  ## Roadmap
271
574
 
272
575
  - A local gateway daemon (`vapi serve`) with per-key budgets
273
576
  - OpenTelemetry traces and metrics, with exporters enabled only by the user
274
- - `task.*` tools for posting, funding, delivering, and reviewing work
577
+ - `task.*` tools for posting, funding, delivering and reviewing work
275
578
  - `compute.*` tools for discovering models and paying for inference
276
579
 
277
- Until the gateway lands, `vapi serve` and the provider-side `vapi publish`
278
- command exit with a preview message. Payments remain direct from the local
279
- wallet to each service.
580
+ Until the gateway lands, `vapi serve` and the provider-side `vapi publish` exit
581
+ with a preview message. Payments stay direct from the local wallet to each
582
+ service.
280
583
 
281
584
  ## Development
282
585
 
283
- This is a pnpm workspace for Node.js 22 and pnpm 10.
586
+ A pnpm workspace for Node.js 22 and pnpm 10. The gate, in order:
284
587
 
285
588
  ```sh
286
589
  pnpm install
590
+ pnpm format:check
287
591
  pnpm lint
288
592
  pnpm typecheck
289
593
  pnpm test
@@ -291,32 +595,13 @@ pnpm build
291
595
  pnpm pack:check
292
596
  ```
293
597
 
294
- See [CONTRIBUTING.md](./CONTRIBUTING.md) for the development workflow,
295
- [CHANGELOG.md](./CHANGELOG.md) for what shipped in each release, and
296
- [SECURITY.md](./SECURITY.md) for private vulnerability reports.
297
-
298
- CLI commands exit `0` on success, `1` on an operational failure, and `2` for
299
- invalid usage or an announced preview-only command. `--json` sends both success
300
- values and errors to stdout as one JSON value; `mcp --json` is accepted as a
301
- no-op because the stdio transport is already JSON-RPC.
302
-
303
- ## Publishing
304
-
305
- All five packages share one version and are published together. npm reads a
598
+ All five packages share one version and are released together. npm reads a
306
599
  package manifest before lifecycle hooks run, so the release is made from the
307
600
  generated `publish/` directories, never from the workspace package roots.
308
601
 
309
- First update every package to the same version and verify the exact tarballs:
310
-
311
602
  ```sh
312
603
  pnpm install --frozen-lockfile
313
604
  pnpm pack:check
314
- ```
315
-
316
- After reviewing the output, a maintainer with npm access runs these commands
317
- manually:
318
-
319
- ```sh
320
605
  npm login
321
606
  pnpm --dir packages/core publish:npm
322
607
  pnpm --dir packages/sources publish:npm
@@ -325,11 +610,15 @@ pnpm --dir packages/cli publish:npm
325
610
  pnpm --dir packages/vapi-network publish:npm
326
611
  ```
327
612
 
328
- Each package's `publish:npm` script publishes its staged `./publish` directory
329
- to the `latest` npm tag. Every package also has a `publish:npm:next` script that
330
- publishes the same tarball to `next` instead, for preview builds. The manual
331
- release workflow verifies and prints these commands; it never receives npm
332
- credentials or publishes automatically.
613
+ `publish:npm` publishes a package's staged `./publish` directory to the `latest`
614
+ npm tag; `publish:npm:next` publishes the same tarball to `next`. The manual
615
+ release workflow verifies artifacts and prints these commands; it never receives
616
+ npm credentials and never publishes.
617
+
618
+ See [AGENTS.md](./AGENTS.md) for layout and invariants,
619
+ [CONTRIBUTING.md](./CONTRIBUTING.md) for the workflow,
620
+ [CHANGELOG.md](./CHANGELOG.md) for what shipped in each release, and
621
+ [SECURITY.md](./SECURITY.md) for private vulnerability reports.
333
622
 
334
623
  ## License
335
624