vapi-network 0.2.3 → 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,155 +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
32
- vapi export-key # print the private key for this wallet, on stdout only
20
+ vapi receipts # one line per paid call: quote, settlement, latency
33
21
  ```
34
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
+
35
28
  `vapi search` tags each listing with its group — `[vapi]`, `[added]`,
36
- `[partner]`, or `[external]` — and prints the network fee already inside the
37
- 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;
38
31
  partner and external listings carry none. `vapi inspect` and `--json` return the
39
32
  same `group` and `fee` fields.
40
33
 
41
- No install? Prefix any command with `npx vapi-network`, for example `npx vapi-network init`.
42
- (`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.
43
80
 
44
- ### Use it from an agent (MCP)
81
+ Three things vAPI cannot do:
45
82
 
46
- Add this to Claude Desktop, Claude Code, or Cursor. The passphrase unlocks the local keystore; it never leaves the machine.
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
+ ```
123
+
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:
47
236
 
48
237
  ```json
49
238
  {
50
239
  "mcpServers": {
51
240
  "vapi": {
52
241
  "command": "npx",
53
- "args": ["-y", "vapi-network", "mcp"],
54
- "env": { "VAPI_KEYSTORE_PASSWORD": "your-passphrase" }
242
+ "args": ["-y", "vapi-network", "mcp"]
55
243
  }
56
244
  }
57
245
  }
58
246
  ```
59
247
 
60
- Tools: `call.search`, `call.inspect`, `call.pay`, `wallet.address`, `wallet.balance`,
61
- `wallet.accounts`, `wallet.fund`, `receipts.list`, `receipts.stats`, `support.report`. Spend caps
62
- 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:
63
249
 
64
- ## Sign-in with X
250
+ ```bash
251
+ vapi unlock # the passphrase goes into the macOS Keychain or libsecret
252
+ ```
65
253
 
66
- x402 v2 services can require Sign-In-With-X (SIWX) before returning a price. When `call.pay` or
67
- `vapi pay` receives that challenge, vAPI checks that both the challenge domain and URI match the
68
- final resource origin, signs the canonical EIP-4361 message locally with EVM `personal_sign`, and
69
- retries once with `SIGN-IN-WITH-X`. The proof is never sent to a redirect or a different host.
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.
70
258
 
71
- If the retry returns a normal 402 quote, the usual spend-policy and payment flow continues. If the
72
- resource is free after sign-in, the result has `outcome: "signed_in"` and the local receipt records
73
- `amountAtomic: "0"`.
259
+ Give an agent its own capped wallet by creating it yourself and pinning the
260
+ agent to it:
74
261
 
75
- ## Fund the wallet
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
+ ```
267
+
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
+ ```
282
+
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
76
335
 
77
336
  ```bash
78
- vapi fund # ask the registry for a hosted onramp session
79
- vapi fund --amount 25 # prefill a US dollar amount
80
- vapi fund --json # stable machine-readable shape
337
+ npm i @vapi-network/core @vapi-network/sources
81
338
  ```
82
339
 
83
- `vapi fund` POSTs `{ address, network: "base", asset: "USDC", fiatAmount }` to
84
- `<registry>/api/wallet/onramp-session` through the same guarded network client as
85
- every other command, prints the returned URL, and opens it in your default
86
- browser when you are on a terminal. The onramp is **Coinbase's**: Coinbase takes
87
- the card or Apple Pay payment and sends USDC straight to your local address.
88
- **vAPI never holds your funds**, never proxies the payment, and never sees your
89
- card details or your private key.
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
+ );
379
+ ```
90
380
 
91
- When the registry replies `503 onramp_unavailable` — or cannot be reached at all
92
- — the command stays useful instead of failing: it prints your address and
381
+ Manage wallets:
93
382
 
94
- ```text
95
- Send USDC on Base (eip155:8453) to this address; add a little ETH for gas if you plan to sweep.
383
+ ```ts
384
+ import { WalletStore, getVapiPaths, usdToAtomic } from "@vapi-network/core";
385
+
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
+ });
96
394
  ```
97
395
 
98
- Either way it finishes by printing the current balance. MCP clients can use the
99
- `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.
100
400
 
101
- ## 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`).
102
404
 
103
- `vapi accounts` lists one deposit account for every configured network, including its CAIP-2 ID,
104
- network name, address, atomic and formatted USDC balance, gas-token balance, and deposit guidance.
105
- Use `--json` for the stable `{ "accounts": [...] }` shape. `vapi init` prints the same account list
106
- after creating the encrypted keystore and configuration. MCP clients can use `wallet.accounts`.
405
+ ## Configuration
107
406
 
108
- Base uses the wallet's EVM address and tells you to send USDC on Base. For Arc testnet, add the
109
- faucet URL or instructions to that network's `config.json` entry:
407
+ Local state lives in `~/.vapi/`:
110
408
 
111
- ```json
112
- {
113
- "depositUrl": "https://your-arc-faucet.example",
114
- "depositInstructions": "Use the configured Arc testnet faucet, then send USDC to this address."
115
- }
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
116
421
  ```
117
422
 
118
- Account lookup dispatches by CAIP namespace: the EVM and Solana adapters use their corresponding
119
- 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 |
120
430
 
121
- ## Exporting the key
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.
122
435
 
123
- The wallet is yours, so the key can leave on demand:
436
+ ## Funding
124
437
 
125
438
  ```bash
126
- vapi export-key # EVM key (eip155:8453) as 0x-prefixed hex
127
- vapi export-key --network solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdpKuc147dw2N9d
128
- vapi export-key --json # { "network", "address", "privateKey" }
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 }
129
442
  ```
130
443
 
131
- The command asks for the keystore passphrase, prints a one-line warning on
132
- stderr, and writes the key alone on stdout so it can be piped into a password
133
- manager. Anyone holding that key can spend the wallet: never paste it into a
134
- website or a chat. Nothing else in vAPI ever logs it.
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
- ## Reporting a bug
451
+ The command itself makes **no network call**: it works offline, and it always
452
+ also prints
137
453
 
138
- ```bash
139
- vapi report "the provider returned 402 twice"
140
- vapi report "the provider returned 402 twice" --include-addresses
141
- vapi report "the provider returned 402 twice" --send
454
+ ```text
455
+ Send USDC on Base (eip155:8453) to this address; add a little ETH for gas if you plan to sweep.
142
456
  ```
143
457
 
144
- The command first writes `$VAPI_HOME/reports/<timestamp>.json`, then prints that path and a prefilled
145
- GitHub issue URL. Reports contain the message, client version, OS/Node information, and only the
146
- newest five receipt IDs. Wallet and payee addresses are included only with `--include-addresses`;
147
- amounts are never included. No report is uploaded unless `--send` is explicit. With `--send`, vAPI
148
- uses the guarded network client to POST the same JSON to the configured registry and prints the HTTP
149
- response code, including non-success responses such as 404. MCP clients can use `support.report`
150
- with the corresponding `includeAddresses` and `send` booleans.
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.
151
463
 
152
- ## Networks
464
+ ## Networks and accounts
153
465
 
154
466
  | Network | x402 identifier | USDC | Gas / RPC notes |
155
467
  | -------------- | ----------------------------------------------------- | ---------------------------------------------- | ------------------------------------------------------ |
@@ -159,150 +471,123 @@ with the corresponding `includeAddresses` and `send` booleans.
159
471
 
160
472
  The x402 reference packages shorten the Solana CAIP-2 reference to
161
473
  `solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp`; vAPI accepts that identifier as an
162
- alias while persisting the full genesis hash above. Arc mainnet is not enabled:
163
- **not yet — placeholder only.** Arc and the x402 packages do not publish a
164
- mainnet RPC plus canonical USDC, so the client deliberately carries only a
165
- non-routable code placeholder instead of guessing a production configuration.
166
-
167
- Create both local accounts during initialization:
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.
168
478
 
169
- ```bash
170
- vapi init --networks base,solana
171
- ```
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:
172
484
 
173
- Or add an Ed25519 account to an existing encrypted keystore:
174
-
175
- ```bash
176
- 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
+ }
177
490
  ```
178
491
 
179
- Fund the printed Solana address with SPL USDC. Exact x402 payments use the
180
- facilitator advertised in the challenge as fee payer, so they do not consume the
181
- local SOL balance. `vapi sweep <solana-address> --network
182
- solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdpKuc147dw2N9d` is a separate transaction
183
- and requires a small amount of SOL locally for fees and, when necessary,
184
- 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
185
498
  rate-limited and has no availability guarantee; set `SOLANA_RPC_URL` to a
186
- trusted dedicated endpoint for regular use.
499
+ dedicated endpoint for regular use.
187
500
 
188
501
  ## Discovery sources
189
502
 
190
- Discovery is a plugin interface. The client can merge listings from multiple
191
- 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
192
505
  provenance:
193
506
 
194
- - **vAPI Registry** is enabled by the default distribution, using
195
- `https://api.vapinetwork.ai/api/call/discovery` for discovery and
196
- `https://api.vapinetwork.ai/api/call/services` for service details. If the
197
- primary returns HTTP 404 or cannot be resolved, the client logs one notice
198
- and tries the fallbacks in `registryFallbacks`, using the same canonical
199
- paths; the default distribution no longer ships a distinct fallback host,
200
- because the `console.vapinetwork.ai` and `console-staging.vapinetwork.ai`
201
- hosts are retired. A `config.json` that still names them is repaired in
202
- memory on load and rewritten on disk by `vapi init`. The registry's historical `/api/marketplace/discovery`
203
- and `/api/network/services` paths still answer for one release and reply with
204
- `Deprecation: true` plus a `Link` header naming the successor; a base URL
205
- supplied on either of them is normalized to the canonical pair.
206
- - **Coinbase Bazaar** reads the public x402 v2
207
- `/discovery/resources` catalog exposed by a facilitator.
208
- - **Local file** reads a JSON array of listings for private or development
209
- catalogs.
210
- - **x402scan** is a deliberate stub for now. The source research documents its
211
- discovery convention, but not a stable public read API that this client can
212
- safely target.
213
-
214
- Use `@vapi-network/sources` to compose only the catalogs you trust. Network
215
- access is guarded against local and private destinations before a request is
216
- made.
217
-
218
- Set `VAPI_REGISTRY_URL` to replace the registry base; the client derives
219
- `/api/call/discovery` and `/api/call/services` beneath it. The existing
220
- `VAPI_MARKETPLACE_DISCOVERY_URL` and `VAPI_DISCOVERY_URL` variables can still
221
- override either full endpoint separately. Registry fallbacks are stored in
222
- `config.json` under `registryFallbacks`.
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.
223
525
 
224
- ## Packages
225
-
226
- | Package | Purpose |
227
- | ----------------------- | ------------------------------------------------------------------------ |
228
- | `@vapi-network/core` | x402 protocol, wallet, spend policy, discovery merge, and receipts |
229
- | `@vapi-network/sources` | vAPI Registry, Coinbase Bazaar, local-file, and x402scan source adapters |
230
- | `@vapi-network/mcp` | stdio MCP server with namespaced payment tools |
231
- | `@vapi-network/cli` | `init`, discovery, payment, wallet, receipt, and MCP commands |
232
- | `vapi-network` | zero-dependency distribution with the `vapi` binary and defaults |
233
-
234
- Every npm tarball is bundled and has zero runtime dependencies. The scoped
235
- packages are useful for embedding; most users should start with
236
- `vapi-network`.
237
-
238
- ## SDK
526
+ ## Sign-in with X
239
527
 
240
- The core and source packages can be used without the CLI or MCP layer. See the
241
- runnable [SDK example](./examples/pay-with-sdk.ts) for discovery, policy
242
- 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.
243
533
 
244
- 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"`.
245
537
 
246
- ## Local state and migration
538
+ ## Metrics and bug reports
247
539
 
248
- 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.
249
548
 
250
- ```text
251
- config.json
252
- keystore.json
253
- receipts.jsonl
254
- spend-ledger.json
255
- reports/
549
+ ```sh
550
+ vapi stats --range 7d
551
+ vapi receipts export --format csv --range 30d
256
552
  ```
257
553
 
258
- Set `VAPI_HOME` to use a different directory. On first use of the default home,
259
- the client copies an existing `~/.vapi/agent-cash/` configuration into
260
- `~/.vapi/` when it can do so without overwriting files, prints a migration
261
- notice, and leaves the old directory untouched.
262
-
263
- ## Metrics
264
-
265
- vAPI measures call and discovery health locally. Call receipts can include the
266
- listing name and provider host, policy decision, retry count, client version,
267
- outcome, total latency, and discovery, quote, signing, request, and settlement
268
- phase timings. Policy declines are recorded with the quoted amount but without
269
- a payer or transaction, so blocked spend remains visible without creating a
270
- payment authorization. Search events record the query, sources tried,
271
- per-source latency and result count, merged result count, and timestamp.
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.
272
559
 
273
- Call receipts are appended to `$VAPI_HOME/receipts.jsonl`; search events are
274
- appended to `$VAPI_HOME/searches.jsonl`. Nothing in either ledger is uploaded,
275
- and vAPI sends no telemetry off the machine by default. The vAPI website can
276
- show public on-chain usage for a wallet address directly from the chain; that
277
- view does not require uploading these local files.
560
+ ## Packages
278
561
 
279
- Use `vapi stats --range 24h|7d|30d` for a human-readable summary or add `--json`
280
- for the stable `{ range, generatedAt, totals, outcomes, latency, topServices,
281
- search }` shape. `receipts.stats` exposes the same shape through MCP. Export raw
282
- 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` |
283
569
 
284
- ```sh
285
- vapi receipts export --format json --range 30d
286
- vapi receipts export --format csv --range 30d
287
- ```
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`.
288
572
 
289
573
  ## Roadmap
290
574
 
291
575
  - A local gateway daemon (`vapi serve`) with per-key budgets
292
576
  - OpenTelemetry traces and metrics, with exporters enabled only by the user
293
- - `task.*` tools for posting, funding, delivering, and reviewing work
577
+ - `task.*` tools for posting, funding, delivering and reviewing work
294
578
  - `compute.*` tools for discovering models and paying for inference
295
579
 
296
- Until the gateway lands, `vapi serve` and the provider-side `vapi publish`
297
- command exit with a preview message. Payments remain direct from the local
298
- 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.
299
583
 
300
584
  ## Development
301
585
 
302
- 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:
303
587
 
304
588
  ```sh
305
589
  pnpm install
590
+ pnpm format:check
306
591
  pnpm lint
307
592
  pnpm typecheck
308
593
  pnpm test
@@ -310,32 +595,13 @@ pnpm build
310
595
  pnpm pack:check
311
596
  ```
312
597
 
313
- See [CONTRIBUTING.md](./CONTRIBUTING.md) for the development workflow,
314
- [CHANGELOG.md](./CHANGELOG.md) for what shipped in each release, and
315
- [SECURITY.md](./SECURITY.md) for private vulnerability reports.
316
-
317
- CLI commands exit `0` on success, `1` on an operational failure, and `2` for
318
- invalid usage or an announced preview-only command. `--json` sends both success
319
- values and errors to stdout as one JSON value; `mcp --json` is accepted as a
320
- no-op because the stdio transport is already JSON-RPC.
321
-
322
- ## Publishing
323
-
324
- 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
325
599
  package manifest before lifecycle hooks run, so the release is made from the
326
600
  generated `publish/` directories, never from the workspace package roots.
327
601
 
328
- First update every package to the same version and verify the exact tarballs:
329
-
330
602
  ```sh
331
603
  pnpm install --frozen-lockfile
332
604
  pnpm pack:check
333
- ```
334
-
335
- After reviewing the output, a maintainer with npm access runs these commands
336
- manually:
337
-
338
- ```sh
339
605
  npm login
340
606
  pnpm --dir packages/core publish:npm
341
607
  pnpm --dir packages/sources publish:npm
@@ -344,11 +610,15 @@ pnpm --dir packages/cli publish:npm
344
610
  pnpm --dir packages/vapi-network publish:npm
345
611
  ```
346
612
 
347
- Each package's `publish:npm` script publishes its staged `./publish` directory
348
- to the `latest` npm tag. Every package also has a `publish:npm:next` script that
349
- publishes the same tarball to `next` instead, for preview builds. The manual
350
- release workflow verifies and prints these commands; it never receives npm
351
- 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.
352
622
 
353
623
  ## License
354
624