x402 response encryption: the buyer's key rides in the nonce
An open x402 proposal seals each paid response to a key the buyer hides inside the EIP-3009 nonce. We reproduced its test vectors with a third, independent implementation. We also ran a stock x402 buyer against it and measured it on a real LLM completion. The binding holds. But the nonce it relies on is already taken in three other x402 payment schemes, and the format stops at single JSON responses.
The proposal is issue #4223, opened on 2026-11-11 by code0xff. Its design document is dated 2026-11-07 and marked "design draft". The code lives in code0xff/x402-response-encryption (Apache-2.0, last push 2026-11-13 at commit 16cb494). It includes a spec, JSON Schemas, TypeScript packages for a client, an Express seller and a gateway origin, and a Python verifier that shares no code with the generator. The issue has one comment, the author's own update. No maintainer has answered yet.
We read it with one question: what would it take for a paid LLM answer to reach an agent without every hop in between being able to read it?
The problem: TLS ends at every hop
A paid x402 response rarely travels one TLS connection from seller to buyer. CDNs, reverse proxies, API gateways, marketplaces and agent platforms terminate TLS, and each one can log, cache or keep the body. The proposal lists them in its threat model and makes a fair point. Most of these systems are honest. The exposure comes from what they store, not from what they intend.
The obvious fix is weak. If a client sends its own public key in a header and the seller encrypts to it, an active intermediary can swap that header for its own key. It reads the response, re-encrypts it to the client's key, and neither side notices. The proposal's related-work section compares itself with Tessera's opt-in encrypted responses. There the client key travels in an X-Tessera-Encrypt-Pubkey header that nothing ties to the payment. That comparison is the proposal's own reading of Tessera's public docs. We did not test Tessera.
The design choice in #4223 is to anchor both keys to the one thing an intermediary cannot rewrite: the buyer's payment signature.
How the binding works
The client generates a fresh secp256k1 key pair (e, E) for each request. It does not put E in a header. It folds E into the EIP-3009 nonce it is about to sign:
// proposal 3.1 — the nonce the wallet signs is a commitment
c = keccak256("x402-response-encryption/v1/nonce" ‖ E ‖ keyId ‖ requestHash ‖ r)
authorization.nonce = c
// requestHash binds method, the issued resource.url and the body
requestHash = SHA-256("x402-response-encryption/v1/request"
‖ len(method) ‖ method ‖ len(url) ‖ url ‖ SHA-256(body))
E and the 32 random bytes r travel unsigned in the payload's extension field. The seller recomputes c from the request it actually received and compares it with the signed nonce. If an intermediary swapped E, or changed the method, URL or body, the values differ and the seller refuses before settlement.
The seller side uses a separate encryption key M, held online, never the payTo key. payTo signs an EIP-712 attestation over M once, offline. The 402 carries the key and the attestation, and the client checks that the attesting address is the payTo it is about to pay. The response is then encrypted with ECDH between e and M, HKDF-SHA256 salted with the authorization's EIP-712 digest, and AES-256-GCM. The AAD covers the version, key ID, original status code and content type. The result is a JSON envelope sent with status 200 and content type application/x402-encrypted+json.
Wallets only sign ordinary typed data. Nobody needs ECDH from a wallet, and the payTo key can stay cold.
This works because of how EIP-3009 defines the nonce. The standard describes nonces as "randomly generated 32-byte data unique to the authorizer's address". The token contract only checks that a nonce has not been used. A keccak output that includes 32 random bytes looks like any other random nonce.
Three implementations, one answer
We ran the repository at 16cb494. The TypeScript suites passed: 77 tests in the core package and 57 in the Express package, across EIP-3009 and Permit2, for both a seller running x402 itself and an origin behind a payment gateway. The Python verifier reproduced the EIP-3009 vector (14 intermediate values plus 7 extra checks), 37 of 37 tampering cases, 35 of 35 URL canonicalization cases, 47 of 47 schema checks, and the Permit2 (13 values, 7 of 7 cases) and Solana (14 values, 9 of 9 cases) profile vectors.
Their two implementations share a test vector, so we wrote a third. It uses only Node 22.22.2's built-in crypto (ECDH, HKDF, AES-GCM, SHA-256) and viem 2.57.8 for keccak and EIP-712. It takes the vector's inputs and nothing from the repository's code. All 17 checks matched: both public keys, requestHash, keyId, the nonce, the authorization digest, the recovered payer, the shared secret from both sides, the HKDF info, the AES key, the AAD and the decrypted body. Two tamper checks also behaved: swapping E changes the nonce, and flipping the status in the AAD from 200 to 201 makes GCM reject the ciphertext.
We also checked the demo settlement on Base Sepolia. Transaction 0x8c2191ab…bdbef3 succeeded in block 57,421,521 with 85,728 gas. It emitted AuthorizationUsed with nonce 0xc99eaf7d… and moved 10,000 base units (0.01 USDC). Nothing on-chain marks that nonce as a commitment. That is the point: the token contract and the facilitator do not need to know. The Permit2 demo, 0x4a422231…ec174b, settled through x402ExactPermit2Proxy at 0x4020…0001 with 98,499 gas.
What a stock buyer sees
A protected route is useful only if the buyers that cannot decrypt fail safely. So we pointed the stock @x402/fetch 2.29.0 client, with the stock ExactEvmScheme from @x402/evm 2.29.0, at the reference seller. That is the version the reference packages pin.
The result: one signature, zero settlements, zero handler runs, and a 402 back to the caller. Fail-closed works. The interesting part is the error. The stock client follows x402 v2's extension convention and echoes the advertised info into its payload: version, required, suite, keyId, publicKey, attestation. It echoed "required": true and then ignored it. The seller found the extension present but without an ephemeral key, so it answered response_encryption_invalid_ephemeral_key.
That reason sounds like a cryptographic fault. The real condition is that the client does not support the extension. The proposal reserves response_encryption_extension_missing for a payload with no extension info, but stock clients will rarely send that, because they echo. It is the gap behind #4252: a 402 whose reason a client cannot branch on.
Two other details matter for agent wallets. First, "rejected before settlement" means the seller did not settle. It does not void the signature. The buyer's authorization stays a valid EIP-3009 transfer until validBefore, and anyone holding it can submit it, with funds going to payTo. We saw the same property in our x402 recovery audit. Second, a stock client cannot produce the binding at all. In @x402/evm 2.29.0 and on main at 911709c (2026-11-17), createEIP3009Payload calls const nonce = createNonce() and takes no nonce parameter. The reference client therefore builds and signs the authorization itself and uses only x402's header encoders. Whatever a buyer attached to x402Client, such as registerPolicy filters, spend controls or onBeforePaymentCreation hooks, is not on that path.
The nonce is already spoken for
The proposal defines profiles for exact only: EIP-3009, Permit2 and Solana. It argues that putting a computed value in the nonce is safe, and notes that x402's auth-capture client already puts a hash there. That is true. It also means the nonce is no longer free. In @x402/evm 2.29.0, the version the reference packages depend on, two other schemes already derive the EIP-3009 nonce from a commitment, and an open PR adds a third:
auth-capture. In @x402/evm 2.29.0 the facilitator recomputes the nonce as computePayerAgnosticPaymentInfoHash(chainId, paymentInfo, escrow) and rejects any mismatch with invalid_auth_capture_evm_nonce_mismatch, for both the EIP-3009 and Permit2 paths. The free input is paymentInfo.salt. With salt binding on, that salt is itself keccak256(typehash, receiverAuthorizer, policy, saltNonce), checked as invalid_auth_capture_evm_salt_binding_mismatch. We covered the escrow model in our auth-capture audit.
batch-settlement. The deposit nonce is keccak256(abi.encode(channelId, salt)). Per-request payments are vouchers, and the voucher type has two fields, channelId and maxClaimableAmount. No client-chosen field covers an individual request, so there is no place for a per-request binding without changing the voucher.
upto via EIP-3009. Open PR #3867 (head 8473172) adds x402UptoERC3009Proxy. The contract recomputes keccak256(abi.encode(NONCE_TYPEHASH, chainid, token, payTo, settler, salt)) on-chain and reverts with InvalidNonce on mismatch. We tested that proxy on a Base fork in our upto EIP-3009 audit.
There is a pattern here, and it points to a fix. Each of these derived nonces keeps one client-chosen 32-byte input: a salt or a salt nonce. The response-encryption commitment can live there instead of in the nonce. For auth-capture with salt binding, c would sit two hashes below the signed nonce. That works in principle, because the seller can recompute the whole chain from the payload. But each combination needs its own profile, and none exists yet.
The rule we would add to x402 is short. Any scheme that derives its nonce from a commitment must expose exactly one client-chosen 32-byte input and name it in its spec. Extensions that need a signed slot then bind to that input. Without the rule, every new nonce-commitment proposal has to rediscover the others.
Two quieter checks came back clean. Permit2 nonces in the TypeScript client are already 32 random bytes (createPermit2Nonce), so using c there does not change which bitmap words Permit2 touches. On Solana, the proposal itself notes the conflict. c must be the only memo, so a covered resource cannot also set extra.memo.
What a sealed completion costs
To size it on our own traffic, we generated a real non-streamed chat completion: 688 output tokens from a local 12B model through an OpenAI-compatible endpoint. The JSON body was 3,508 bytes. Gzip brings it to 1,682 bytes.
Sealed with the proposal's envelope format, the same body is 4,875 bytes: the 16-byte tag, base64url's one-third expansion and the JSON fields. Ciphertext does not compress. Gzipping the envelope only gets it to 3,725 bytes, because that just undoes part of the base64. On a path that compresses, the sealed answer costs about 2.2 to 2.9 times the bytes of the plain one. The proposal defines no content encoding inside the envelope. A seller that wants compression would have to compress before encrypting, and compression combined with encryption has a long record of length side channels.
Length leaks anyway. The ciphertext is the plaintext length plus 16 bytes, and the envelope does not pad. An intermediary that cannot read a completion still learns its exact size.
Headers grow too, but not by much. Using the vector's values, the extension adds 525 bytes of JSON (700 base64) to PAYMENT-REQUIRED and 698 bytes (932 base64) to PAYMENT-SIGNATURE, since the payload echoes the 402 info and adds E and r. Our stock-buyer probe's full PAYMENT-SIGNATURE was 1,720 base64 characters with the echo included. That is well inside common 8 and 16 KiB header limits.
CPU cost is small but not zero. On our test host, in Node 22's OpenSSL, the median costs were 1,286 µs for the secp256k1 ECDH, 36 µs for the keccak commitment, 27 µs for HKDF and 21 µs to seal the 3,508-byte body. On the retry path, where the seller verifies the buyer's signature locally, viem's recoverTypedDataAddress took 4,503 µs. Those numbers depend on the host and library. They are not the bottleneck for inference.
Streaming is the hard part
The proposal says it plainly: "Single JSON response. Streaming is future work." For an LLM gateway, that leaves out every streamed completion.
We streamed the same prompt. The server-sent events stream had 690 data: events and 172,707 bytes, about 250 bytes per event. It gzips to 3,782 bytes because the chunks are nearly identical. Sealing each event as its own record, which is the naive streaming design, comes to 248,876 bytes. The tags alone are 11,040 bytes. Sealing the whole stream as one envelope removes the streaming.
Size is the smaller problem. Per-event encryption keeps the shape of the stream visible, and that shape has been attacked. Weiss and co-authors showed at USENIX Security 2024 that token lengths visible in encrypted streaming responses are enough to accurately reconstruct 27% of an assistant's answers and infer the topic of 53%. Microsoft's Whisper Leak, published 2025-11-07, classified conversation topics from packet sizes and timing alone. The paper demonstrates it across 28 popular LLMs, often above 98% AUPRC. It evaluated random padding, token batching and packet injection. Each reduced the attack's effectiveness, and none provided complete protection.
The building blocks for a streaming profile exist. RFC 8188 (aes128gcm content coding) splits a body into fixed-size records. Each record carries a padding delimiter, and the last one is marked with a different delimiter value so truncation is detectable. A streaming profile for #4223 would need the same three properties (records, padding and a final marker), plus a padding policy chosen with the side-channel results in mind. Per-event sealing without those properties would encrypt the text and still leak its shape.
The retry store is the real product
Section 8.1 of the proposal handles lost responses. It is the most complete retry design we have read in an x402 draft. After settlement, the seller stores the envelope for at least 24 hours, keyed by the signed commitment, together with the authorization digest and the payer. A retry with the identical payload gets the stored envelope byte for byte. There is no new signature, no facilitator call and no second execution. Processing is serialized per commitment with a lock, so a concurrent duplicate waits instead of running the handler twice.
The key is the important part. Our recovery audit found that keying replays on a response hash let an unpaid operation collect a settled operation's answer, and that the payment-identifier extension it tested had no store at all. Here the key is a signed commitment to the exact request, so a replay against a different method, URL or body fails the nonce check. The reference tests include the awkward cases: another Permit2 owner signing the identical message, a connection that closes mid-handler, and a retry after validBefore.
This connects to two open threads. #4293 notes that a stock x402 hook can only answer an in-flight payment with a fresh 402, which invites a second signature. #4198 asks for an idempotency key for identical concurrent offers. Response encryption has to solve both for its own envelopes, and its answer is "wait for the lock and return the stored envelope". That pattern deserves to exist outside the extension.
What stays in the clear
The proposal is honest about its limits, and they matter more for inference than for most APIs.
The request is not encrypted. For an LLM call, the request body is the prompt, which is often as sensitive as the answer. The proposal sketches a follow-up for request encryption and says it would need a payTo known out of band. The path, query, headers, sizes and timing stay visible, and so does PAYMENT-RESPONSE.
The seller sees plaintext by design. In a gateway, that includes the gateway and every upstream model provider. Response encryption protects the path after the seller, not the seller. Confidentiality against the operator is a different tool, which we covered in our audit of attested inference.
An active intermediary can still replace payTo, the key and the attestation together, and get the client to pay it. The proposal says so in section 4.3 and points out that plain x402 already allows this. The defense is a payTo pinned in advance, or the optional did:web profile.
Gateway deployments need the payment payload at the origin, because the origin checks the binding. The proposal notes that Cloudflare's Monetization Gateway verifies payments itself and forwards a signed JWT instead. Cloudflare's documentation describes forwarding a signed JWT in a PAYMENT-CONTEXT header after verifying the client's authorization. That fits the gateway's own model, but it is not the signed nonce this extension needs.
What it means for LLM4Agents
LLM4Agents is a seller in this model. Agents pay us per call over x402, with EIP-3009 on the exact scheme on Base, and we return completions. Response encryption would let an agent that routes through a tool gateway, an agent platform or a corporate proxy receive our answer sealed to a key only it holds. It would also keep our responses out of the logs of anything sitting in front of us.
It does not change what we see. We read the prompt and the completion because we meter tokens and forward to providers, and the providers see both too. The extension narrows who else can read the answer. It does not hide the answer from the parties that produce it.
The fit is partial today. The format covers non-streamed JSON only, and streamed completions are outside it. Usage numbers inside an OpenAI-compatible body would be sealed along with the text, which is correct but means any intermediary that reports cost from the body loses that view. The 24-hour envelope store and per-commitment lock are real infrastructure for a high-volume API. Enabling it on a default route would turn every stock x402 buyer into a 402 with a confusing reason, as our probe showed.
It also changes an assumption that payment code tends to make quietly: that the nonce is random noise. With auth-capture, batch-settlement and the upto proxy, the nonce already carries meaning in x402. Response encryption adds another meaning. Code that inspects, logs or deduplicates nonces should treat them as opaque, unique 32-byte values and nothing more.
Staying on the frontier
First, contribute the composition data to #4223 while the design is still open. The three derived-nonce schemes, their free salt inputs and the voucher with no per-request field are concrete facts the thread does not yet have. Propose the general rule: a scheme that derives its nonce names one client-chosen 32-byte input, and extensions bind there.
Second, push for a nonce hook in the x402 client. Today any extension that needs the signed slot must fork payload construction and lose x402Client policies and hooks. A small, explicit "nonce provider" in ExactEvmScheme would let extensions compose with spend controls instead of bypassing them.
Third, ask for an unambiguous reason for buyers that do not support the extension. A stock client that echoes the info should receive a code that means "extension required, client unsupported", not an invalid-key error. The same principle sits behind #4252.
Fourth, prototype it behind an opt-in flag on non-streamed chat completions only, with the published vector as a CI fixture. The vector is deterministic, and our independent verifier already reproduces it. Measure the envelope store and the lock on real traffic before any default.
Fifth, write down what a streaming profile must have before anyone ships one: RFC 8188-style records, a final-record marker against truncation, and a padding policy informed by the token-length and Whisper Leak results. Offer the SSE measurements above as a starting point.
Sixth, publish a pinnable payTo for our endpoints, in a well-known location or a did:web document. Section 4.3 turns payTo pinning from good practice into the line that separates a confidential response from a redirected payment.
Pay per call. Keep the answer yours.
LLM4Agents is an OpenAI-compatible gateway where autonomous agents pay per request in stablecoins over x402, and we track the extensions that decide who else can read the response.
Register an agent