x402-proxy 0.1.0 → 0.1.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.
Files changed (3) hide show
  1. package/LICENSE +4 -4
  2. package/README.md +88 -0
  3. package/package.json +5 -4
package/LICENSE CHANGED
@@ -48,9 +48,9 @@
48
48
  "Contribution" shall mean any work of authorship, including
49
49
  the original version of the Work and any modifications or additions
50
50
  to that Work or Derivative Works thereof, that is intentionally
51
- submitted to the Licensor for inclusion in the Work by the copyright
52
- owner or by an individual or Legal Entity authorized to submit on behalf
53
- of the copyright owner. For the purposes of this definition, "submitted"
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
54
  means any form of electronic, verbal, or written communication sent
55
55
  to the Licensor or its representatives, including but not limited to
56
56
  communication on electronic mailing lists, source code control systems,
@@ -186,7 +186,7 @@
186
186
  same "printed page" as the copyright notice for easier
187
187
  identification within third-party archives.
188
188
 
189
- Copyright 2025 Cascade Protocol
189
+ Copyright [yyyy] [name of copyright owner]
190
190
 
191
191
  Licensed under the Apache License, Version 2.0 (the "License");
192
192
  you may not use this file except in compliance with the License.
package/README.md ADDED
@@ -0,0 +1,88 @@
1
+ # x402-proxy
2
+
3
+ Generic [x402](https://www.x402.org/) payment proxy library for Solana and EVM USDC. Wraps `fetch` with automatic x402 payment handling, tracks transaction history, and provides wallet loading utilities.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install x402-proxy
9
+ ```
10
+
11
+ Peer dependencies: `@solana/kit`, `ethers`, `viem`
12
+
13
+ ## Usage
14
+
15
+ ```ts
16
+ import {
17
+ x402Client,
18
+ ExactSvmScheme,
19
+ ExactEvmScheme,
20
+ createX402ProxyHandler,
21
+ extractTxSignature,
22
+ loadSvmWallet,
23
+ loadEvmWallet,
24
+ } from "x402-proxy";
25
+
26
+ // 1. Configure the x402 client with payment schemes
27
+ const svmWallet = await loadSvmWallet("/path/to/keypair.json");
28
+ const client = x402Client([ExactSvmScheme(svmWallet)]);
29
+
30
+ // 2. Create the proxy handler
31
+ const { x402Fetch, shiftPayment } = createX402ProxyHandler({ client });
32
+
33
+ // 3. Make requests - payments are handled automatically
34
+ const response = await x402Fetch("https://api.example.com/paid-endpoint");
35
+ const payment = shiftPayment(); // { network, payTo, amount, asset }
36
+ const txSig = extractTxSignature(response);
37
+ ```
38
+
39
+ ### Transaction history
40
+
41
+ ```ts
42
+ import { appendHistory, readHistory, calcSpend, formatTxLine } from "x402-proxy";
43
+
44
+ // Append a transaction record
45
+ appendHistory("/path/to/history.jsonl", {
46
+ t: Date.now(),
47
+ ok: true,
48
+ kind: "x402_inference",
49
+ net: "solana:mainnet",
50
+ from: "J5UH...",
51
+ tx: "5abc...",
52
+ amount: 0.05,
53
+ token: "USDC",
54
+ model: "claude-sonnet-4-20250514",
55
+ });
56
+
57
+ // Read and aggregate
58
+ const records = readHistory("/path/to/history.jsonl");
59
+ const { today, total, count } = calcSpend(records);
60
+ ```
61
+
62
+ ## API
63
+
64
+ ### Payment proxy
65
+
66
+ - `createX402ProxyHandler(opts)` - wraps fetch with automatic x402 payment. Returns `{ x402Fetch, shiftPayment }`
67
+ - `extractTxSignature(response)` - extracts on-chain TX signature from payment response headers
68
+
69
+ ### Wallet loading
70
+
71
+ - `loadSvmWallet(path)` - load Solana keypair from solana-keygen JSON file
72
+ - `loadEvmWallet(path)` - load EVM wallet from hex private key file
73
+
74
+ ### Transaction history
75
+
76
+ - `appendHistory(path, record)` - append a `TxRecord` to a JSONL file (auto-truncates at 1000 lines)
77
+ - `readHistory(path)` - read all records from a JSONL history file
78
+ - `calcSpend(records)` - aggregate USDC spend (today/total/count)
79
+ - `explorerUrl(net, tx)` - generate block explorer URL (Solscan, Basescan, Etherscan)
80
+ - `formatTxLine(record)` - format a record as a markdown line with explorer link
81
+
82
+ ### Re-exports
83
+
84
+ - `x402Client`, `ExactSvmScheme`, `ExactEvmScheme`, `toClientEvmSigner` - from `@x402/fetch`, `@x402/svm`, `@x402/evm`
85
+
86
+ ## License
87
+
88
+ Apache-2.0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "x402-proxy",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Generic x402 payment proxy library for Solana USDC",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -16,6 +16,7 @@
16
16
  },
17
17
  "peerDependencies": {
18
18
  "@solana/kit": "^6.0.0",
19
+ "ethers": "^6.0.0",
19
20
  "viem": "^2.0.0"
20
21
  },
21
22
  "devDependencies": {
@@ -37,12 +38,12 @@
37
38
  },
38
39
  "repository": {
39
40
  "type": "git",
40
- "url": "git+https://github.com/cascade-protocol/agentbox.git",
41
+ "url": "git+https://github.com/cascade-protocol/x402-proxy.git",
41
42
  "directory": "packages/x402-proxy"
42
43
  },
43
- "homepage": "https://github.com/cascade-protocol/agentbox/tree/main/packages/x402-proxy#readme",
44
+ "homepage": "https://github.com/cascade-protocol/x402-proxy#readme",
44
45
  "bugs": {
45
- "url": "https://github.com/cascade-protocol/agentbox/issues"
46
+ "url": "https://github.com/cascade-protocol/x402-proxy/issues"
46
47
  },
47
48
  "scripts": {
48
49
  "build": "rm -rf dist && tsdown --publint",