Documentation Index
Fetch the complete documentation index at: https://docs.prudra.dev/llms.txt
Use this file to discover all available pages before exploring further.
How challenges are built
WhenpayMiddleware determines a request has no valid payment, it calls the Prudra API to generate a dual challenge. Both the x402 and MPP challenges are built atomically in a single buildDualChallenge() call. Neither header is written until both are ready.
The challenge generation call
payMiddleware calls POST /challenges with:
ip field is used for rate limiting (20 challenges per IP per 60 seconds).
The x402 challenge
ThePAYMENT-REQUIRED header value is a base64-encoded JSON array of payment options:
payTo address is the server’s registered wallet address. The asset is the USDC contract address on Base. maxAmountRequired is the price converted to token base units (6 decimals for USDC).
The MPP challenge
TheWWW-Authenticate header uses the standard HTTP Payment scheme:
id field is the HMAC-SHA256 challenge ID:
crypto.timingSafeEqual(). No database lookup. No stored challenge state.
The request field is a base64url-encoded JSON object:
Atomicity
Both challenges reference the same wallet address and the same price. They’re built in sequence within the same function, not in separate HTTP calls. This eliminates:- Clock skew — both challenges have the same expiry base time
- Race conditions — a 402 response never has one challenge without the other
- Early flush bugs — headers are accumulated before
res.writeHead()is called
Rate limiting
The challenge endpoint is rate-limited to 20 requests per IP per 60 seconds using a Redis sliding window. Requests that exceed this limit return:Secrets never leave the server
TheMPP_CHALLENGE_SECRET used to compute the HMAC is a server-side environment variable. It’s never sent to agents, never included in response headers, and never logged. The HMAC design means the secret is never needed on the client side — only Prudra’s server needs it to generate and verify challenges.
Related
- Choose between x402 and MPP — when to use each protocol
- Dual-protocol overview — the full dual-protocol design
- Prevent challenge harvesting — rate limiting and no-challenge-on-error
- Replay attack protection — how txHash uniqueness prevents replay

