@minia2a/x402-check 0.1.3 → 0.1.4

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/README.md +3 -2
  2. package/cli.js +33 -1
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -13,8 +13,9 @@ endpoint actually serves, and reports the defects that cost money or clients:
13
13
  - `x402Version: 2` with `resource` as a string instead of an object
14
14
  - a discoverable listing whose advertised `input.example` is empty, or violates
15
15
  its own `input.schema.required`
16
- - `output.example` advertised with no `answerBasis` (nothing says it is the
17
- response to `input.example`)
16
+ - `output.example` that echoes none of the input example's values and carries no
17
+ `answerBasis` — nothing ties the response to the request. Services with no
18
+ input example are not flagged (there is no pair to check)
18
19
  - a price above the reference client's **$1 per-call default spend cap** that the
19
20
  402 does not disclose — that client will refuse the payment
20
21
  - the same cached offer on two reads with no nonce/expiry (a document, not a quote)
package/cli.js CHANGED
@@ -77,6 +77,30 @@ function offerAmountToUsd(amount, network, asset) {
77
77
  return Number(amount) / 1e6;
78
78
  }
79
79
 
80
+ // Scalar values a listing documents as its input example. `queryParams` and
81
+ // `body` are what sellers actually publish; `example` is the formal slot. Only
82
+ // strings of length >= 2 count as pairing evidence: single characters and bare
83
+ // numbers collide with unrelated fields and would hide a real mismatch.
84
+ function exampleValues(input) {
85
+ const src = [input && input.example, input && input.queryParams, input && input.body].filter(v => v && typeof v === 'object');
86
+ const out = [];
87
+ const walk = (node) => {
88
+ if (node === null || node === undefined) return;
89
+ if (Array.isArray(node)) return node.forEach(walk);
90
+ if (typeof node === 'object') return Object.values(node).forEach(walk);
91
+ if (typeof node === 'string' && node.length >= 2) out.push(node.toLowerCase());
92
+ };
93
+ src.forEach(walk);
94
+ return out;
95
+ }
96
+
97
+ function echoes(values, node) {
98
+ if (node === null || node === undefined || typeof node !== 'object') {
99
+ return typeof node === 'string' && values.includes(node.toLowerCase());
100
+ }
101
+ return Object.values(node).some(v => echoes(values, v));
102
+ }
103
+
80
104
  function checkChallenge(doc, headerInfo, bodyDoc) {
81
105
  const findings = [];
82
106
  const add = (level, code, msg) => findings.push({ level, code, msg });
@@ -154,7 +178,15 @@ function checkDiscovery(doc) {
154
178
  if (output) {
155
179
  if (output.example === undefined && !output.schema) add('WARN', 'no-output-example', 'info.output has neither example nor schema');
156
180
  if (output.example !== undefined && !output.answerBasis) {
157
- add('INFO', 'unpaired-examples', 'output.example is advertised without answerBasis: nothing states it is the response to input.example');
181
+ // 0.1.4: only fire when there IS an input example the output could be a
182
+ // response to. 0.1.3 fired on every output example without answerBasis,
183
+ // including services with no input example at all and services whose
184
+ // output example visibly echoes the input values (minia2a's own 402s echo
185
+ // `query`/`text`), which reported 36 of 40 sampled endpoints as unpaired.
186
+ const inputExample = exampleValues(input);
187
+ if (inputExample.length && !echoes(inputExample, output.example)) {
188
+ add('INFO', 'unpaired-examples', 'output.example echoes none of the input example\'s values and there is no answerBasis: nothing ties the two together');
189
+ }
158
190
  }
159
191
  }
160
192
  return findings;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@minia2a/x402-check",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
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
5
  "bin": {
6
6
  "x402-check": "cli.js"