Skip to content

How it works

PQ-402 extends x402, the HTTP payment protocol built on status 402 Payment Required. It keeps the x402 v2 headers and replaces two things: the payment is signed with ML-DSA-87 instead of ECDSA, and the bodies travel sealed with ML-KEM-1024.

One paid, sealed callThe client probes and receives a 402 price; reads the server's sealing key from the chain; sends a sealed request with an ML-DSA-87 payment. The server checks the payer's key on chain, runs the handler, seals the answer to the payer, settles on chain, and returns the sealed answer with a signed receipt, which the client checks against the server's key on chain before opening it.Client (payer)Server (gateway)QoreChain testnet6. open, run, seal1. request without body (probe)2. 402 Payment Required: price, payee3. read the server's ML-KEM-1024 key4. sealed request + ML-DSA-87 payment5. check payer's key; read its ML-KEM key7. settle (relayer pays gas)8. sealed answer + signed receipt9. check receipt against server's key
One paid, sealed call. Dashed arrows are responses.
  1. Probe. The client sends the request without its body, with PQ402-Probe: 1. It does not send the body in plain text before it knows the server seals.
  2. Price. A paid route answers 402 with what it costs, who gets paid, which schemes it accepts, and the gateway account that seals and signs.
  3. Key. The client reads the gateway’s ML-KEM-1024 key from the chain’s KEM key registry. It never takes a key from the 402.
  4. Pay. The client seals the body to that key and signs a payment with its ML-DSA-87 key. The payment commits to the price, the payee, a time window, a nonce and a hash of the method, path and sealed body.
  5. Verify. The server checks the signature against the key pqcKeyStatus reports for the payer, refuses replays, and reads the payer’s ML-KEM-1024 key so it can seal the answer.
  6. Serve. The server opens the body, runs your handler, and seals the answer to the payer’s key.
  7. Settle. The server’s relayer submits the payment on chain and pays the gas. The contract that moves the money, the escrow or the agent-budget vault, checks the ML-DSA-87 signature again with the pqcVerify precompile.
  8. Answer. The sealed answer comes back with a receipt signed by the gateway’s ML-DSA-87 key. The receipt binds the payment, the request and the exact bytes of the answer.
  9. Check and open. The client checks the receipt against the gateway’s key on chain, then opens the answer with its ML-KEM-1024 key.
Scheme Paid from Settled by
pq-erc20 a deposit of fUSD in PQ402Escrow PQ402Escrow.settle
pq-perennial an agent budget: a vault position whose owner set funds aside for the agent the vault’s spend

A server offers one or both, at the same price. See pay from an escrow and pay from an agent budget.

The server. Its relayer submits every settlement from its own account and EVM window, so the client holds no QOR for paying and sends no transaction per call. The relayer can only submit what payers signed, to the payees they named.