The buyer gate
Compare the served bytes with the hash before anything is signed.
For AI agents: this page as Markdown, and llms.txt, the index of every page.
The buyer gate is the buyer-side check that compares the served bytes with H before anything is signed. Where the payment carries H, it is the one step that makes paying mean agreeing: the buyer signs only a payment bound to a record it has fetched, hashed and kept. Where the buyer's signature does not carry H, the pairing's record says so.
The steps
- Read. The pairing's
read(doc)gives H, the link, and the options this pairing can pay. A document without a well-formed hash andhttpslink is refused before anything is fetched. - Fetch. Fetch the link and keep the bytes exactly as received. Bound the fetch: this package's shared vectors
fix a limit of 1 MiB on the body, a 10-second deadline, and no redirects. Ask for the bytes as they are
(
Accept-Encoding: identity) and decline an answer in any other content coding, such asgziporbr: the hash is over the bytes served, never over bytes a decoder produced. - Compare.
hashEquals(await hash(bytes), h). On any difference, stop: nothing is signed. - Build and sign. The pairing's
build(choice, h)returns what the signer signs, with H in its place. Pass the H you compared, never a value read again from the document. - Finish.
complete(signature)gives the payment. Before sending it, check thatbound(payment)equals the H you compared. Where the pairing'sdata.coverageisnone, no public act the payer signs carries H, whateverboundreturns, and the agreement payment is the proof. - Keep the bytes. The buyer's copy of the ATR is its record of what it agreed to.
One changed byte
The comparison is over bytes, not meaning. Re-serialising the same JSON, or changing one byte, gives another hash:
import { , } from "@integraledger/lcp";
const = new ();
const = .('{"atrVersion":"1","id":"0f8fad5b-d9cb-469f-a165-70867728950e","terms":"10000 units"}');
const = await ();
const = .(.(.(new ().()), null, 1));
const = .();
[. - 3] = 0x31;
.((await (), ));
.((await (), ));
.((await (), ));true
false
falseThe gate as a package
This package gives the gate's pieces: read, hash, hashEquals, build and bound. The
buyer packages assemble them into one gate with a bounded fetch
and named declines, for TypeScript, Python and MCP clients. They follow the rows of
vectors/buyer.json, which this package ships.
The function names in this table (transact, agree, confirm, within, finish) are the buyer packages' gate
functions, not this package's; the ids in parentheses are the names of the rows in vectors/buyer.json that fix each
case.
| Row outcome | When |
|---|---|
hash-mismatch | The served bytes do not hash to H: one changed byte, the same JSON written another way, or an agreement resource advertising another ATR's hash. |
signed-not-bound | What the signer returned does not carry the H the buyer compared. |
offer-unreadable | The pairing's read refused the document, or its build refused the option with the buyer's inputs; the row carries the refusal code, and nothing is signed. |
link-not-https | The link or the agreement URL that read gave is not an https link, and it is not fetched. Each pairing's own read refuses a link or agreement URL of another scheme, which declines offer-unreadable with the refusal's code. An agreement URL refused at the agreement step, by transact or by agree called with it alone, carries this package's code for the value as its detail: x402/link-not-https for a URL of another scheme, x402/legal-context-malformed for any other value (BA5). |
atr-unfetchable | The fetch redirected, returned an error status, failed, did not answer in time, or answered in a content coding other than identity. |
atr-too-large | The body is larger than 1 MiB. The fetch is cancelled. |
signer-failed | The signer rejected. |
no-payable-option | No option is payable by the buyer's accounts. The same decline, with the detail <namespace>/input-malformed, answers inputs the caller gave confirm, agree or within that are not an object, and a refund's own Solana value that is malformed (B20, BA16, BW3, BW4). Nothing is fetched or signed. |
pairing-not-supported | The pairing id is not one the gate implements, or finish is handed a chosen payment of another pairing than its binding's (B19), before anything is rebuilt. |
agreement-pending | An agreement payment for this ATR is settling, and the full payment is not signed: the gate made the agreement payment and its receipt did not arrive in time (BA3), or the agreement URL answered the unpaid request 202 (BA14), and nothing is signed. After that unpaid 202, call again later without approval: once the agreement payment is recorded, the agreement URL answers its receipt. Never sign a second agreement payment. |
agreement-failed | The agreement's receipt names another ATR's hash, an agreement answer is in a content coding other than identity, PAYMENT-REQUIRED is not strict base64, padded, in the standard alphabet and with its pad bits zero (BA13, BA18, BA19), or the JSON text of PAYMENT-REQUIRED or of the receipt is led by a byte-order mark (BA17, BA18); the full payment is not signed. |
agreement-not-offered | The chosen pairing's payment is not a public proof of H (its data.coverage is none) and the offer names no agreement URL. The link is fetched and compared first; nothing is signed. |
The agreement URL
Where the pairing's data.coverage is none, the seller advertises an agreement URL (legalContextAgreementUrl)
beside the link; the buyer gate declines such an offer without one. The buyer first pays that URL. That payment is
itself a public proof of H: it carries H or, on a pairing whose single-use value is H itself or H's low bits (the
EIP-3009 and Permit2 nonce among them), the agreement's own value,
agreementValue(h), so the agreement and the full payment never share a single-use value. The pairing's
build(choice, h, "agreement") writes it, and bound(presented, { act: "agreement", h }) checks it. The buyer pays
the full payment only after the agreement's 200 receipt names the same H. Where the chosen pairing's payment is
itself a public proof of H (data.coverage is full), the buyer does not pay the agreement URL.
The agreement payment is a payment like any other, so the buyer's agent approves it before anything is signed:
- Fetch the agreement URL's
402and check that it advertises the same H. A202to this unpaid request means an agreement payment for this ATR is settling: the gate declinesagreement-pendingand signs nothing (BA14). - Choose its option with the main payment's rule: the options in order, the first the signer can pay whose pairing's payment is itself a public proof of H.
- Hand the agent that option's amount, token (
asset), payee (payTo) and network, and sign only once it approves. - Pay and wait for the
200receipt. The exchange is bounded by the chosen option'smaxTimeoutSecondsplus 180 seconds;maxTimeoutSecondsis a JSON number with an integral value, so60.0is60. After a202the gate sends the same payment again afterRetry-After's delay-seconds (RFC 9110 section 10.2.3) of 1 to 9 digits, at least 1 second, and after 2 seconds when the header is absent or in any other form, an HTTP-date included (BA15).
The buyer vector rows BA1 to BA19 fix this exchange: its order, the approval and the bounds.
What the gate checks, and what it does not
The gate compares the served bytes with H before anything is signed. It never parses the ATR.
- The bytes it compared are the record. Evaluate, and show a person, those bytes, never a second fetch of the
link:
LCP §12.7requires that "the document presented for human review is byte-identical to the document whose hash is signed". - The ATR's text is the seller's statement. The gate acts on nothing a party slot says. An agent that reads the
slots takes their text as the seller's statement, not as instructions to it:
LCP §12.7says free-text prose in the terms body should not "drive policy decisions directly". - The binding slot is the seller's statement too. The gate compares the bytes with H; it does not compare the options and request the binding slot records with the challenge it received.
- The link is the seller's choice.
isHttpsLinkaccepts loopback, private and link-local hosts, such as127.0.0.1,10.0.0.1,169.254.169.254,localhostand[::1]. A buyer that fetches from inside a private network refuses such destinations itself.
Next
Last updated on