@minia2a/x402-check 0.1.0 → 0.1.1

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 +17 -5
  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) {
@@ -152,7 +161,10 @@ function checkClientCap(doc, maxPrice) {
152
161
  const findings = [];
153
162
  const offers = (doc && doc.accepts) || [];
154
163
  const prices = offers.map(o => offerAmountToUsd(o.amount, o.network, o.asset)).filter(v => v !== null);
155
- if (!prices.length) return findings;
164
+ if (!prices.length) {
165
+ 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")' });
166
+ return findings;
167
+ }
156
168
  const cheapest = Math.min(...prices);
157
169
  if (cheapest > maxPrice) {
158
170
  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.1",
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
  }