@minia2a/x402-check 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 (2) hide show
  1. package/cli.js +22 -7
  2. package/package.json +25 -6
package/cli.js CHANGED
@@ -60,12 +60,21 @@ async function fetchOne(url, headers, timeoutMs) {
60
60
  } finally { clearTimeout(t); }
61
61
  }
62
62
 
63
+ // USD conversion is honest only for a 6-decimal stablecoin we can name. An
64
+ // arbitrary eip155 token may have 18 decimals, so converting it by network alone
65
+ // would inflate the price by 1e12 — report unmeasured instead.
66
+ const SIX_DEC_USD = {
67
+ 'eip155:8453|0x833589fcd6edb6e08f4c7c32d4f71b54bda02913': true, // USDC on Base
68
+ 'eip155:84532|0x036cbd53842c5426634e7929541ec2318f3dcf7e': true, // USDC on Base Sepolia
69
+ 'eip155:1|0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48': true, // USDC on Ethereum
70
+ 'eip155:137|0x3c499c542cef5e3811e1192ce70d8cc03d5c3359': true, // USDC on Polygon
71
+ 'eip155:42161|0xaf88d065e77c8cc2239327c5edb3a432268e5831': true, // USDC on Arbitrum
72
+ };
63
73
  function offerAmountToUsd(amount, network, asset) {
64
- // USDC has 6 decimals on Base/EVM chains; we only convert when we recognize
65
- // the shape. Unknown decimals -> null (the check says "unmeasured", not 0).
66
74
  if (!/^\d+$/.test(String(amount))) return null;
67
- if (network && network.startsWith('eip155:')) return Number(amount) / 1e6;
68
- return null;
75
+ const key = `${String(network || '').toLowerCase()}|${String(asset || '').toLowerCase()}`;
76
+ if (!SIX_DEC_USD[key]) return null;
77
+ return Number(amount) / 1e6;
69
78
  }
70
79
 
71
80
  function checkChallenge(doc, headerInfo, bodyDoc) {
@@ -131,8 +140,11 @@ function checkDiscovery(doc) {
131
140
  else {
132
141
  if (!input.method) add('WARN', 'no-method', 'info.input.method is missing');
133
142
  const params = input.queryParams || input.body;
134
- if (!params || (typeof params === 'object' && Object.keys(params).length === 0)) {
135
- add('WARN', 'empty-input-example', 'info.input carries no example params: the advertised call is not runnable as written');
143
+ const required = Array.isArray(input.schema && input.schema.required) ? input.schema.required : [];
144
+ if ((!params || (typeof params === 'object' && Object.keys(params).length === 0)) && required.length === 0) {
145
+ // A service that takes no input legitimately has no example params. From
146
+ // outside we cannot tell that apart from an omitted example, so say so.
147
+ add('INFO', 'no-example-params', 'info.input carries no example params (fine if the service takes no input)');
136
148
  }
137
149
  if (input.schema && Array.isArray(input.schema.required) && params && typeof params === 'object') {
138
150
  const missing = input.schema.required.filter(k => !(k in params));
@@ -152,7 +164,10 @@ function checkClientCap(doc, maxPrice) {
152
164
  const findings = [];
153
165
  const offers = (doc && doc.accepts) || [];
154
166
  const prices = offers.map(o => offerAmountToUsd(o.amount, o.network, o.asset)).filter(v => v !== null);
155
- if (!prices.length) return findings;
167
+ if (!prices.length) {
168
+ if (offers.length) findings.push({ level: 'INFO', code: 'price-unmeasured', msg: 'no offer names a 6-decimal USD stablecoin I can convert; the price was not measured (not "0")' });
169
+ return findings;
170
+ }
156
171
  const cheapest = Math.min(...prices);
157
172
  if (cheapest > maxPrice) {
158
173
  findings.push({ level: 'FAIL', code: 'over-max-price', msg: `cheapest offer is $${cheapest} > --max-price $${maxPrice}` });
package/package.json CHANGED
@@ -1,13 +1,32 @@
1
1
  {
2
2
  "name": "@minia2a/x402-check",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Inspect a live x402 endpoint before you pay it: challenge shape, door parity, EIP-712 domain, discovery examples, and the $1 client-cap trap.",
5
- "bin": { "x402-check": "cli.js" },
6
- "files": ["cli.js", "README.md", "LICENSE"],
7
- "engines": { "node": ">=18" },
8
- "keywords": ["x402", "http-402", "usdc", "payments", "agents", "cli", "audit"],
5
+ "bin": {
6
+ "x402-check": "cli.js"
7
+ },
8
+ "files": [
9
+ "cli.js",
10
+ "README.md",
11
+ "LICENSE"
12
+ ],
13
+ "engines": {
14
+ "node": ">=18"
15
+ },
16
+ "keywords": [
17
+ "x402",
18
+ "http-402",
19
+ "usdc",
20
+ "payments",
21
+ "agents",
22
+ "cli",
23
+ "audit"
24
+ ],
9
25
  "license": "MIT",
10
26
  "author": "minia2a <hello@minia2a.uk> (https://minia2a.uk)",
11
27
  "homepage": "https://minia2a.uk",
12
- "repository": { "type": "git", "url": "https://github.com/minia2auk/x402-check.git" }
28
+ "repository": {
29
+ "type": "git",
30
+ "url": "https://github.com/minia2auk/x402-check.git"
31
+ }
13
32
  }