x402-proxy 0.4.1 → 0.4.2

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/CHANGELOG.md ADDED
@@ -0,0 +1,141 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ## [0.4.2] - 2026-03-16
11
+
12
+ ### Fixed
13
+ - Twitter endpoint URLs updated from `/user/` to `/users/` to match spec change
14
+
15
+ ### Added
16
+ - CHANGELOG.md included in npm package metadata
17
+ - `skills/` directory with SKILL.md and library reference included in npm package
18
+
19
+ ## [0.4.1] - 2026-03-13
20
+
21
+ ### Changed
22
+ - Extracted `createNetworkFilter`, `createNetworkPreference`, `networkToCaipPrefix` as exported functions for testability
23
+ - Publish workflow auto-creates GitHub releases from CHANGELOG.md (no more manual `gh release create`)
24
+ - Release docs updated in CLAUDE.md with `act` dry-run instructions for CI workflows
25
+
26
+ ### Added
27
+ - Tests for network filter, network preference selector, Solana address derivation, and wallet resolution (14 new tests)
28
+
29
+ ## [0.4.0] - 2026-03-13
30
+
31
+ ### Added
32
+ - `--network` flag for `fetch` and `mcp` commands - hard filter that requires a specific network (base, solana, or CAIP-2 ID), fails with clear error if unavailable
33
+ - Human-readable network names in payment output ("Base", "Solana" instead of "eip155:8453")
34
+ - `displayNetwork()` exported from library for mapping CAIP-2 IDs to display names
35
+
36
+ ### Fixed
37
+ - Wildcard scheme registration (`eip155:*`, `solana:*`) via SDK helpers - payment signing now works for any EVM chain a server requests, not just Base
38
+ - Solana address derivation for `--solana-key` flag and `X402_PROXY_WALLET_SOLANA_KEY` env var - balance detection, wallet display, and history recording were broken without it
39
+ - MCP command now auto-detects preferred network based on USDC balance (same fix previously applied to `fetch`)
40
+ - MCP payment history records now include `amount`, `to`, and correct `network` (removed fragile type cast)
41
+ - Removed debug prefix stripping from payment amounts in handler
42
+ - USDC balance display now shows 4 decimal places (was 2)
43
+
44
+ ## [0.3.2] - 2026-03-13
45
+
46
+ ### Added
47
+ - Auto-setup: running `npx x402-proxy <url>` without a wallet launches the setup wizard, then continues with the request
48
+ - 402 error handling parses the endpoint's `PAYMENT-REQUIRED` header to show actual accepted networks and costs
49
+ - CI pipeline (GitHub Actions: check, build, test on push/PR)
50
+ - Automated npm publishing with OIDC provenance on tag push
51
+ - Tests for wallet derivation and transaction history (25 tests)
52
+ - Funding hint in `wallet` when USDC balance is zero
53
+
54
+ ### Changed
55
+ - Version injected at build time from package.json (no more stale hardcoded strings)
56
+ - `wallet fund` command removed (addresses and hint shown in `wallet` directly)
57
+ - All command references use `$ npx x402-proxy` format
58
+
59
+ ## [0.3.1] - 2026-03-12
60
+
61
+ ### Added
62
+ - `wallet export-key mnemonic` - export BIP-39 mnemonic to stdout (pipe-safe, with confirmation prompt)
63
+
64
+ ## [0.3.0] - 2026-03-12
65
+
66
+ ### Added
67
+ - Live wallet balances in `status` and `wallet` commands (USDC + ETH/SOL via RPC)
68
+ - Recent transactions shown in `status` (last 5) and `wallet` (last 10)
69
+ - Network preference (`defaultNetwork` config) - prefers configured chain when endpoint accepts multiple
70
+ - Spend limits (`spendLimitDaily`, `spendLimitPerTx` config) enforced via x402Client policy
71
+ - `--verbose` flag on `wallet` command to show transaction IDs
72
+ - Confirmation prompt on `wallet export-key` when stdout is a terminal
73
+ - Help text with usage examples for `fetch --help` and `mcp --help`
74
+ - Full command reference, "try:" suggestion, and repo link in no-args output
75
+ - Network indicator on transaction lines (base/sol)
76
+ - Setup outro with "try your first request" using real endpoint
77
+
78
+ ### Changed
79
+ - "EVM" label replaced with "Base" throughout (wallet, status, setup)
80
+ - Config directory displayed as `~/.config/...` instead of absolute path
81
+ - Error messages prefixed with `✗`, success with `✓` for accessibility
82
+ - No-args output redesigned: identity header, wallet summary, commands, try suggestion
83
+ - Example URLs use path-based format (`/user/cascade_fyi`) to avoid zsh glob issues
84
+ - `@solana/kit`, `ethers`, `viem` moved from peerDependencies to dependencies (fixes npx ERESOLVE warnings)
85
+ - Wallet subcommand hints shown at bottom of `wallet` output
86
+
87
+ ### Fixed
88
+ - RPC balance failures show "(network error)" instead of silent omission
89
+
90
+ ## [0.2.1] - 2026-03-12
91
+
92
+ ### Changed
93
+ - Package description and keywords aligned with "curl for x402 paid APIs" positioning
94
+ - README rewritten: real endpoint in Quick Start, MCP Proxy elevated above HTTP Requests
95
+ - Stricli commands use explicit generic types (fixes TS 5.9 type inference)
96
+ - `displayStatus()` extracted as callable function from status command
97
+ - `PaymentRequirements.amount` used instead of removed `maxAmountRequired`
98
+
99
+ ### Fixed
100
+ - All `tsc --noEmit` type errors resolved (previously passing only at build time)
101
+ - Biome schema version bumped to match CLI 2.4.6
102
+
103
+ ## [0.2.0] - 2026-03-12
104
+
105
+ ### Added
106
+ - CLI binary accessible via `npx x402-proxy`
107
+ - `fetch` command (default) - curl-like HTTP client with automatic x402 payment
108
+ - `mcp` command (alpha) - MCP stdio proxy with auto-payment for AI agents
109
+ - `setup` command - interactive onboarding wizard with @clack/prompts
110
+ - `status` command - config, wallet, and spend summary
111
+ - `wallet` subcommand with `info`, `history`, `fund`, `export-key`
112
+ - BIP-39 mnemonic wallet derivation (Solana SLIP-10 + EVM BIP-32 from single seed)
113
+ - XDG-compliant config storage (`~/.config/x402-proxy/`)
114
+ - Wallet resolution cascade: flags > env vars > mnemonic env > wallet.json
115
+ - JSONL payment history with auto-truncation
116
+ - Env var overrides with `X402_PROXY_WALLET_*` prefix
117
+
118
+ ### Changed
119
+ - Package now ships both CLI binary and library
120
+ - Dual tsdown build entries (bin/cli with shebang + index with dts)
121
+
122
+ ## [0.1.0] - 2026-03-10
123
+
124
+ ### Added
125
+ - Initial release (library only)
126
+ - `createX402ProxyHandler` - wraps fetch with automatic x402 payment
127
+ - `extractTxSignature` - extracts TX signature from payment response headers
128
+ - `loadSvmWallet` / `loadEvmWallet` - wallet loading utilities
129
+ - `appendHistory` / `readHistory` / `calcSpend` - JSONL transaction history
130
+ - Re-exports from `@x402/fetch`, `@x402/svm`, `@x402/evm`
131
+
132
+ [Unreleased]: https://github.com/cascade-protocol/x402-proxy/compare/v0.4.2...HEAD
133
+ [0.4.2]: https://github.com/cascade-protocol/x402-proxy/compare/v0.4.1...v0.4.2
134
+ [0.4.1]: https://github.com/cascade-protocol/x402-proxy/compare/v0.4.0...v0.4.1
135
+ [0.4.0]: https://github.com/cascade-protocol/x402-proxy/compare/v0.3.2...v0.4.0
136
+ [0.3.2]: https://github.com/cascade-protocol/x402-proxy/compare/v0.3.1...v0.3.2
137
+ [0.3.1]: https://github.com/cascade-protocol/x402-proxy/compare/v0.3.0...v0.3.1
138
+ [0.3.0]: https://github.com/cascade-protocol/x402-proxy/compare/v0.2.1...v0.3.0
139
+ [0.2.1]: https://github.com/cascade-protocol/x402-proxy/compare/v0.2.0...v0.2.1
140
+ [0.2.0]: https://github.com/cascade-protocol/x402-proxy/compare/v0.1.0...v0.2.0
141
+ [0.1.0]: https://github.com/cascade-protocol/x402-proxy/releases/tag/v0.1.0
package/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  ## Quick Start
6
6
 
7
7
  ```bash
8
- npx x402-proxy https://twitter.surf.cascade.fyi/user/cascade_fyi
8
+ npx x402-proxy https://twitter.surf.cascade.fyi/users/cascade_fyi
9
9
  ```
10
10
 
11
11
  That's it. The endpoint returns 402, x402-proxy pays and streams the response.
@@ -38,7 +38,7 @@ Works like curl. Response body streams to stdout, payment info goes to stderr.
38
38
 
39
39
  ```bash
40
40
  # GET request
41
- $ npx x402-proxy https://twitter.surf.cascade.fyi/user/cascade_fyi
41
+ $ npx x402-proxy https://twitter.surf.cascade.fyi/users/cascade_fyi
42
42
 
43
43
  # POST with body and headers
44
44
  $ npx x402-proxy --method POST \
package/dist/bin/cli.js CHANGED
@@ -404,7 +404,7 @@ Add to your MCP client config (Claude, Cursor, etc.):
404
404
  const { x402MCPClient } = await import("@x402/mcp");
405
405
  const x402Mcp = new x402MCPClient(new Client({
406
406
  name: "x402-proxy",
407
- version: "0.4.1"
407
+ version: "0.4.2"
408
408
  }), x402PaymentClient, {
409
409
  autoPayment: true,
410
410
  onPaymentRequested: (ctx) => {
@@ -451,7 +451,7 @@ Add to your MCP client config (Claude, Cursor, etc.):
451
451
  dim(` ${tools.length} tools available`);
452
452
  const localServer = new McpServer({
453
453
  name: "x402-proxy",
454
- version: "0.4.1"
454
+ version: "0.4.2"
455
455
  });
456
456
  for (const tool of tools) localServer.tool(tool.name, tool.description ?? "", tool.inputSchema?.properties ? Object.fromEntries(Object.entries(tool.inputSchema.properties).map(([k, v]) => [k, v])) : {}, async (args) => {
457
457
  const result = await x402Mcp.callTool(tool.name, args);
@@ -608,7 +608,7 @@ const routes = buildRouteMap({
608
608
  });
609
609
  const app = buildApplication(routes, {
610
610
  name: "x402-proxy",
611
- versionInfo: { currentVersion: "0.4.1" },
611
+ versionInfo: { currentVersion: "0.4.2" },
612
612
  scanner: { caseStyle: "allow-kebab-for-camel" }
613
613
  });
614
614
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "x402-proxy",
3
- "version": "0.4.1",
3
+ "version": "0.4.2",
4
4
  "description": "curl for x402 paid APIs. Auto-pays any endpoint on Base and Solana.",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -47,6 +47,8 @@
47
47
  "files": [
48
48
  "dist/**",
49
49
  "README.md",
50
+ "CHANGELOG.md",
51
+ "skills/**",
50
52
  "LICENSE"
51
53
  ],
52
54
  "keywords": [
@@ -0,0 +1,144 @@
1
+ ---
2
+ name: x402-proxy
3
+ description: Use x402-proxy CLI for consuming and debugging x402 paid APIs. Use this skill when testing x402 endpoints, configuring MCP payment proxies for AI agents, managing x402 wallets, or scripting paid HTTP requests. Triggers on x402-proxy, npx x402-proxy, x402 endpoint testing, paid API debugging, MCP payment proxy, x402 wallet management, or any mention of auto-paying HTTP 402 responses.
4
+ ---
5
+
6
+ # x402-proxy
7
+
8
+ `curl` for x402 paid APIs. Auto-pays HTTP 402 responses with USDC on Base and Solana.
9
+
10
+ ## Quick start
11
+
12
+ ```bash
13
+ npx x402-proxy https://twitter.surf.cascade.fyi/users/cascade_fyi
14
+ ```
15
+
16
+ First run auto-creates a wallet. No setup needed.
17
+
18
+ ## HTTP requests
19
+
20
+ ```bash
21
+ # GET - body to stdout, payment info to stderr
22
+ npx x402-proxy https://api.example.com/resource
23
+
24
+ # POST with body and headers
25
+ npx x402-proxy --method POST \
26
+ --header "Content-Type: application/json" \
27
+ --body '{"query":"example"}' \
28
+ https://api.example.com/search
29
+
30
+ # Force a specific chain
31
+ npx x402-proxy --network solana https://api.example.com/data
32
+
33
+ # Pipe-safe - only response body on stdout
34
+ npx x402-proxy https://api.example.com/data | jq '.results'
35
+
36
+ # Save response to file
37
+ npx x402-proxy https://api.example.com/data > response.json
38
+ ```
39
+
40
+ ## Commands
41
+
42
+ ```
43
+ x402-proxy <url> # paid HTTP request (default)
44
+ x402-proxy mcp <url> # MCP stdio proxy for AI agents
45
+ x402-proxy setup # wallet onboarding wizard
46
+ x402-proxy setup --force # re-run setup (overwrite existing wallet)
47
+ x402-proxy status # config + wallet + daily spend summary
48
+ x402-proxy wallet # show addresses and USDC balances
49
+ x402-proxy wallet history # payment log
50
+ x402-proxy wallet history --limit 5 # last 5 payments
51
+ x402-proxy wallet history --json # machine-readable output
52
+ x402-proxy wallet export-key evm # bare EVM private key to stdout
53
+ x402-proxy wallet export-key solana # bare Solana private key to stdout
54
+ x402-proxy wallet export-key mnemonic # bare mnemonic to stdout
55
+ ```
56
+
57
+ ## Fetch flags
58
+
59
+ ```
60
+ --method, -X <METHOD> HTTP method (default: GET)
61
+ --header, -H <KEY:VALUE> Add request header (repeatable)
62
+ --body, -d <DATA> Request body (string or @file)
63
+ --network <base|solana> Force payment on this chain
64
+ ```
65
+
66
+ ## MCP proxy for AI agents
67
+
68
+ Drop into Claude, Cursor, or any MCP client config:
69
+
70
+ ```json
71
+ {
72
+ "mcpServers": {
73
+ "paid-service": {
74
+ "command": "npx",
75
+ "args": ["x402-proxy", "mcp", "https://mcp.example.com/sse"],
76
+ "env": {
77
+ "X402_PROXY_WALLET_MNEMONIC": "your 24 words here"
78
+ }
79
+ }
80
+ }
81
+ }
82
+ ```
83
+
84
+ The proxy intercepts 402 responses, pays automatically, forwards the result. Supports StreamableHTTP and SSE.
85
+
86
+ ## Wallet & env vars
87
+
88
+ One BIP-39 mnemonic derives both Solana and EVM keypairs. Auto-detects which chain based on USDC balance.
89
+
90
+ ```
91
+ X402_PROXY_WALLET_MNEMONIC # BIP-39 mnemonic (derives both chains)
92
+ X402_PROXY_WALLET_EVM_KEY # EVM private key (hex, 0x optional)
93
+ X402_PROXY_WALLET_SOLANA_KEY # Solana private key (base58 or JSON array)
94
+ ```
95
+
96
+ Resolution: flags > env vars > mnemonic env > `~/.config/x402-proxy/wallet.json`
97
+
98
+ Pipe-safe export for scripting:
99
+
100
+ ```bash
101
+ MY_KEY=$(npx x402-proxy wallet export-key evm)
102
+ MY_MNEMONIC=$(npx x402-proxy wallet export-key mnemonic)
103
+ ```
104
+
105
+ ## Config
106
+
107
+ Lives at `~/.config/x402-proxy/` (or `$XDG_CONFIG_HOME/x402-proxy/`):
108
+
109
+ ```yaml
110
+ # config.yaml
111
+ defaultNetwork: base # or "solana"
112
+ spendLimitDaily: 10 # USDC daily cap
113
+ spendLimitPerTx: 1 # USDC per-request cap
114
+ ```
115
+
116
+ Also supports JSONC and JSON config files. Wallet stored in `wallet.json` (mode 0600), payments logged to `history.jsonl`.
117
+
118
+ ## Testing & debugging x402 services
119
+
120
+ ```bash
121
+ # Smoke test an endpoint
122
+ npx x402-proxy https://your-service.com/paid-route
123
+
124
+ # Test both chains
125
+ npx x402-proxy --network base https://your-service.com/route
126
+ npx x402-proxy --network solana https://your-service.com/route
127
+
128
+ # Batch test
129
+ for route in /users/test /tweets/search /v1/crawl; do
130
+ echo "--- $route ---"
131
+ npx x402-proxy "https://your-service.com$route" 2>/dev/null | head -c 200
132
+ echo
133
+ done
134
+
135
+ # Check what you spent
136
+ npx x402-proxy wallet history --limit 5
137
+ npx x402-proxy status
138
+ ```
139
+
140
+ stdout = response body, stderr = payment info. Pipes, redirects, and `jq` all work cleanly.
141
+
142
+ ## Library API
143
+
144
+ For programmatic use in Node.js apps, read `references/library.md`.
@@ -0,0 +1,85 @@
1
+ # x402-proxy Library API
2
+
3
+ ```bash
4
+ npm install x402-proxy
5
+ ```
6
+
7
+ ## Exports
8
+
9
+ ```typescript
10
+ // Core
11
+ import { createX402ProxyHandler, extractTxSignature } from "x402-proxy";
12
+ import { x402Client } from "x402-proxy";
13
+
14
+ // Chain schemes
15
+ import { ExactEvmScheme, toClientEvmSigner } from "x402-proxy";
16
+ import { ExactSvmScheme } from "x402-proxy";
17
+
18
+ // Wallet loaders
19
+ import { loadEvmWallet, loadSvmWallet } from "x402-proxy";
20
+
21
+ // History
22
+ import { appendHistory, readHistory, calcSpend, explorerUrl, formatTxLine } from "x402-proxy";
23
+ ```
24
+
25
+ ## EVM (Base) setup
26
+
27
+ ```typescript
28
+ import { createX402ProxyHandler, x402Client, ExactEvmScheme, toClientEvmSigner } from "x402-proxy";
29
+ import { createWalletClient, http } from "viem";
30
+ import { privateKeyToAccount } from "viem/accounts";
31
+ import { base } from "viem/chains";
32
+
33
+ const account = privateKeyToAccount(process.env.EVM_KEY as `0x${string}`);
34
+ const wallet = createWalletClient({ account, chain: base, transport: http() });
35
+
36
+ const client = x402Client(fetch)
37
+ .register(new ExactEvmScheme(toClientEvmSigner(wallet)));
38
+
39
+ const { x402Fetch, shiftPayment } = createX402ProxyHandler({ x402Client: client });
40
+
41
+ const res = await x402Fetch("https://api.example.com/data");
42
+ const body = await res.json();
43
+ const payment = shiftPayment(); // { network, payTo, amount, asset }
44
+ ```
45
+
46
+ ## Solana setup
47
+
48
+ ```typescript
49
+ import { createX402ProxyHandler, x402Client, ExactSvmScheme, loadSvmWallet } from "x402-proxy";
50
+
51
+ const signer = loadSvmWallet(process.env.MNEMONIC!);
52
+ const client = x402Client(fetch).register(new ExactSvmScheme(signer));
53
+ const { x402Fetch } = createX402ProxyHandler({ x402Client: client });
54
+ ```
55
+
56
+ ## Payment history
57
+
58
+ ```typescript
59
+ import { appendHistory, readHistory, calcSpend } from "x402-proxy";
60
+
61
+ // Read and summarize
62
+ const records = await readHistory("./history.jsonl");
63
+ const { dailyUsd, totalUsd, txCount } = calcSpend(records);
64
+
65
+ // Append a record
66
+ await appendHistory("./history.jsonl", {
67
+ ts: Date.now(),
68
+ status: 200,
69
+ network: "eip155:8453",
70
+ payTo: "0x...",
71
+ amount: "0.001",
72
+ asset: "USDC",
73
+ txId: "0xabc...",
74
+ host: "api.example.com",
75
+ });
76
+ ```
77
+
78
+ ## Types
79
+
80
+ ```typescript
81
+ type PaymentInfo = { network: string; payTo: string; amount: string; asset: string };
82
+ type X402ProxyOptions = { x402Client: ReturnType<typeof x402Client> };
83
+ type X402ProxyHandler = { x402Fetch: typeof fetch; shiftPayment: () => PaymentInfo | undefined };
84
+ type TxRecord = { ts: number; status: number; network: string; payTo: string; amount: string; asset: string; txId?: string; host: string };
85
+ ```