verify-before-pay
v0.1.2
Published
Verify an x402 counterparty's settlement-grounded reputation before your agent pays it. Drop-in for any x402 client's paymentRequirementsSelector. By Crest / AgentRank.
Downloads
431
Maintainers
Readme
verify-before-pay
Before your AI agent releases funds over x402, check the counterparty against AgentRank's
settlement-grounded verdict. Drop it into any x402 client's paymentRequirementsSelector so
verification runs after the payee is known but before the payment is signed.
The payer-side complement to require-rank (which
is the provider side: a service gating its caller).
Why settlement-grounded
A counterfeit agent can fake fluency, a badge, even an on-chain-looking reference. It cannot fake having actually been paid. The verdict here is recomputed from real settled USDC, weighted by payer standing. In a sealed, preregistered experiment, a fake-verifiable counterfeit beat an honest agent 99% of the time without verification; performing the check flipped it, and it held 94% even against an actively lying counterparty. Surface heuristics collapse under mimicry; only verification recovers the truth.
Install & use
import { wrapFetchWithPayment } from "x402-fetch";
import { verifyingSelector } from "verify-before-pay";
// default-on: every payment verifies its counterparty first
const fetchWithPay = wrapFetchWithPayment(
fetch, wallet, maxValue,
verifyingSelector({ minScore: 1, onFail: "warn" }) // surface by default; flip to "block" to refuse
);Or check directly:
import { verifyCounterparty } from "verify-before-pay";
const v = await verifyCounterparty("0xPAYEE..."); // { verified, score, usd, payers, verdict }Policy (all optional)
| option | default | meaning |
|---|---|---|
| minScore | 0 | require at least this AgentRank score (0–1000) to pass |
| requireVerified | false | require settlement-verified, not just scored |
| onFail | "warn" | "warn" (surface + proceed) · "block" (throw) · "allow" (silent) |
| failClosed | false | on a lookup error, refuse instead of failing open |
| onCheck(results) | — | callback with every verdict, for logging/telemetry |
| apiBase | https://api.agentrank.info | verdict source |
Defaults are non-breaking: it always checks and surfaces, never blocks, so installing it can't
break a flow. Turn on minScore / requireVerified / onFail:"block" to make it a hard gate.
On a verification outage it fails open by default (a verifier outage must not halt your agent).
MIT · by Crest Deployment Systems · https://agentrank.info
Example: classify before paying
See example.mjs — a drop-in payIfTrusted() that classifies the payTo (service / buyer / rail / treasury / dust) and refuses anything that is not a real service, using the free /full counterparty endpoint.
node example.mjs blockrun.ai # service -> would pay
node example.mjs 0x1111... # dust -> would refuse