x402-trust-guard 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 (3) hide show
  1. package/README.md +6 -1
  2. package/package.json +1 -1
  3. package/verdict.js +16 -4
package/README.md CHANGED
@@ -18,9 +18,11 @@ Before your client signs a payment, the guard asks the [x402 Trust Board](https:
18
18
  about the endpoint and the address it wants paid, and **stops the payment** when the answer is `avoid`:
19
19
 
20
20
  - the endpoint switched to a different wallet, or asks to be paid at a burn address
21
- - it charges 10× or more what its listing says
22
21
  - the address isn't in the payout proof the seller published (a hijacked server can change where money goes; it can't change the seller's DNS)
23
22
 
23
+ Price problems (asking well above the listing), flaky uptime, low grades and thin history come back as `caution`,
24
+ which you can choose to block too (`onCaution: "block"`).
25
+
24
26
  The board checks every listing in Coinbase's x402 Bazaar, Circle's Agent Marketplace and the MPP directory several times a day,
25
27
  without paying, and counts real payments on Base and Solana.
26
28
 
@@ -45,6 +47,9 @@ withTrustGuard(client, {
45
47
 
46
48
  `checkFree(url, payTo?)` checks one URL yourself, for free, and returns the full result.
47
49
 
50
+ What each verdict is based on, and what a pre-payment check can't promise (it never pays, so it can't test delivery):
51
+ [method and limits](https://benmcalillycreative.github.io/x402-trust-board/method.html).
52
+
48
53
  ## Also available
49
54
 
50
55
  - **HTTP:** `GET https://x402-trust-check.ben-mcalilly.workers.dev/v1/check?url=…&payTo=…` ($0.01, x402)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "x402-trust-guard",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Check an x402 seller before your agent pays it: blocks switched or burn wallets, big overcharges and payout addresses the seller never proved. One line on top of @x402/fetch.",
5
5
  "type": "module",
6
6
  "main": "index.js",
package/verdict.js CHANGED
@@ -1,6 +1,7 @@
1
1
  // The verdict logic, kept free of Workers APIs so it can be tested with plain Node.
2
2
 
3
3
  export const RED = "red";
4
+ export const STALE_HOURS = 24; // the board refreshes every 6 hours; a day without one means something is wrong
4
5
 
5
6
  /** Parse and normalise the URL an agent is about to pay. Returns null if it isn't one. */
6
7
  export function parseTarget(raw) {
@@ -49,12 +50,13 @@ export function payToCheck(seller, endpoint, payTo) {
49
50
 
50
51
  /**
51
52
  * Build the answer. verdict is one of:
52
- * ok graded B or better, no warnings, nothing contradicts the payout address
53
- * caution warnings, a low grade, or not enough history to say
54
- * avoid a red flag (e.g. wallet switched, burn address) or an address the seller's own proof contradicts
53
+ * ok graded B or better, no warnings, nothing contradicts the payout address, data under a day old
54
+ * caution warnings (including big price gaps), a low grade, little history, or stale data
55
+ * avoid money would go somewhere it shouldn't: a switched or burn wallet, a non-public address, or an
56
+ * address the seller's own payout proof contradicts
55
57
  * unknown the board has never seen this seller
56
58
  */
57
- export function verdict(target, seller, payTo, board) {
59
+ export function verdict(target, seller, payTo, board, now = Date.now()) {
58
60
  const base = { url: target.url, host: target.host, board };
59
61
  if (!seller) {
60
62
  return {
@@ -98,6 +100,15 @@ export function verdict(target, seller, payTo, board) {
98
100
  reasons.push("Graded C: answers, but less reliably than most.");
99
101
  }
100
102
  }
103
+ const asOf = Date.parse(seller.generated_at || "");
104
+ const ageHours = Number.isFinite(asOf) ? Math.max(0, Math.round((now - asOf) / 36e5)) : null;
105
+ if (ageHours === null || ageHours > STALE_HOURS) {
106
+ // Old data can't vouch for anything: never answer "ok" on it.
107
+ if (v === "ok") v = "caution";
108
+ reasons.push(ageHours === null
109
+ ? "The board's data on this seller has no date, so it may be out of date."
110
+ : `The board's data on this seller is ${ageHours} hours old (it normally refreshes every 6 hours).`);
111
+ }
101
112
  if (v === "ok") reasons.push("Answers reliably and its payment terms match its listing.");
102
113
  if (seller.payout?.verified) reasons.push("The seller has published a signed proof of its payout address.");
103
114
  return {
@@ -129,5 +140,6 @@ export function verdict(target, seller, payTo, board) {
129
140
  },
130
141
  pay_to: pay,
131
142
  data_as_of: seller.generated_at,
143
+ data_age_hours: ageHours,
132
144
  };
133
145
  }