Overview
@billionsnetwork/x402-human-proof-server adds human verification to any x402-enabled API — letting service providers check that paying agents are paired with a verified human, offer them better pricing, and set per-human limits against spam and sybil abuse.
It enables API providers to:
- Verify that a paying agent is paired with a unique, verified human, using Billions Network Proof-of-Uniqueness (PoU) attestations. This tells you who stands behind the agent. It does not stop that human’s agent from misbehaving.
- Offer discounted pricing to agents backed by verified humans while keeping a standard price open to all payers.
- Enforce per-identity usage caps (
maxUse) so a single verified human, across all the agents paired to them, cannot use a discounted price tier an unlimited number of times. - Gate additional capabilities behind arbitrary attestation schemas beyond the basic ownership proof.
Not using x402?
verifyHumanProofRequest from this package works without it, in any app and with no payment. See Verify an Agent in Your App.How It Works
The full request lifecycle with human-proof enabled:
Key insight: Human-proof verification is layered on top of — not in place of — normal x402 payment verification. The facilitator still verifies the on-chain payment. The human-proof hook runs before that, as an additional gate on the selected payment option.
accepts entry has no requiredAttestations in its extra field, the human-proof hook is a no-op and the payment proceeds normally.
Installation
>= 20.11.0. This reference matches version 0.1.9. For a full project setup, including x402 itself, see Protect an x402 Endpoint.
Setup
Human proof sits on top of x402: it adds identity verification to an API that already accepts x402 payments. If you’re new to x402, work through Step 1 first. If your server already accepts x402 payments, jump straight to Step 2.Step 1: Make your server x402-compatible
x402 is an open payment protocol built on the402 Payment Required HTTP status code. When a client hits a protected route without payment, the server returns a 402 with the accepted payment terms. The client pays and retries; the server settles on-chain and returns 200.
Setting up x402 takes three things: a facilitator (handles on-chain settlement), a resource server (coordinates x402 logic), and a payment middleware (gates your routes).
For the full x402 documentation, see docs.x402.org.
Step 2: Add human-proof verification
With x402 in place, register the verification hook once, then add two things to each protected route:configureHumanProofServer— registers the challenge generator and verification hook on the x402 server object.- A discounted
acceptsentry — the second pricing tier, gated behind an ownership attestation. declareHumanProofExtension— tells the challenge generator what to embed in each402response for this route.
$0.01 tier. An agent can use the $0.006 tier only if it signs a human proof and its DID holds an ownership attestation.
paywallInstructions() provides the default HTML page shown to browser users hitting a paid URL — it points them to the skill installation.To add per-human usage caps or a custom paywall page, see Usage Limits and Paywall HTML further down.
Complete Example
Here is the full server in one file, combining both steps, with the three human-proof additions marked. Save it asserver.ts in the project from Protect an x402 Endpoint. It reads FACILITATOR_URL and EVM_ADDRESS from .env, described in Environment Variables.
Testing Your Integration
With your server running, as built in Setup, test it with an agent:- With the Verified Agent Identity skill. The skill handles the human-proof flow without code. Pair the agent with yourself, then ask it to fetch
http://localhost:4021/weather. A response at the$0.006price means the server found an ownership attestation for the agent’s DID, and your server logsHuman <humanId> verified. - With a custom client. Run the Client SDK Quick Start against the same server.
Core Concepts
For how human proof fits into the x402 payment flow, see x402 Human Proof.Proof of Uniqueness and ownership attestations
A person proves they are a unique human with a Proof of Uniqueness credential. When they pair an agent, an ownership attestation is recorded on-chain, linking their human DID to the agent DID. For each gated request, the server SDK derives the agent DID from the signature, looks up its ownership attestation, then resolves the human’s nullifier through the nullifier API. The nullifier is a privacy-preserving identifier for the person, and the SDK uses it ashumanId.
One human can pair several agents. They all resolve to the same humanId, so maxUse quotas apply per human, not per agent.
CAIP-122 Signed Messages
CAIP-122 defines chain-agnostic sign-in messages. The SDK supports its Ethereum form, Sign-In with Ethereum (eip191). The signed payload includes:
domain, uri, version, nonce, issuedAt, expirationTime (optional), statement (optional), resources, chainId, type, address, signature, and requiredAttestations.
With x402, the signed payload travels in the payment payload, under extensions["human-proof"]. Used on its own, it travels in the HUMAN-PROOF HTTP header.
Supported Signatures
Decentralized Identifiers (DID)
A DID is derived from the agent’s EVM address using the Billions method:Configuration Reference
Environment Variables
configureHumanProofServer(server, options?)
The recommended one-call setup. Registers the extension, wires all lifecycle hooks, and optionally adds rollback hooks when storage is provided.
server.registerExtension(createHumanProofExtension(extensionOptions))— adds the CAIP-122 challenge generator to402responses.server.onBeforeVerify(createVerifyHumanProofHook({...}))— verifies the signed proof before payment settlement.
storage is provided:
onAfterVerify— rolls back usage on facilitator failure.onVerifyFailure— rolls back on hook error.onSettleFailure— rolls back if on-chain settlement fails.
declareHumanProofExtension(options?)
Attaches human-proof rules to a specific route’s extensions block. This is a declaration only — it tells the challenge generator what to include in the CAIP-122 message for that route.
Tiered Pricing
Human-proof is configured per route — each endpoint in yourpaymentMiddleware config can have its own pricing model independently. configureHumanProofServer registers the hook globally, but the hook only activates on routes where requiredAttestations is present.
Configuration Patterns
Pattern 1 — Attestation optional (discount for verified humans)
Pattern 1 — Attestation optional (discount for verified humans)
Any client can access the route. Verified humans pay less; everyone else pays full price. This is the most common setup.
Pattern 2 — Attestation required (verified humans only)
Pattern 2 — Attestation required (verified humans only)
Only clients whose DID holds an ownership attestation can use the route. Clients without it are rejected with
402.Pattern 3 — No human-proof (plain x402)
Pattern 3 — No human-proof (plain x402)
Human-proof is bypassed entirely for this route. The hook never runs regardless of
configureHumanProofServer being called.extra Fields on accepts Entries
The accepts array on a route can contain multiple payment options. The human-proof system layers on top to gate access to specific tiers.
accepts entry. The server enforces it:
- If the client chose Tier 1 (no
requiredAttestationsinextra), the hook is skipped entirely. - If the client chose Tier 2 (has
requiredAttestations), the hook verifies the proof and checks attestations. If verification fails, the payment is rejected with402.
Usage Limits (maxUse)
maxUse lets you offer a discounted price up to N times per human and scope, then fall back to standard pricing automatically. Every agent paired to the same human shares one counter. Scope defaults to the route’s resource URL unless you set extra.scope.
Server setup:
storage.incrementIfBelow(humanId, maxUse, scope)returnsnull.- The hook returns
{ abort: true, reason: "max_use_exceeded" }. - The server sends
402witherror: "max_use_exceeded"in the payment-required header. - On the client,
isMaxUseExceededError(err)returnstrueanddisqualify()forces the selector to skip discounted options on the next retry. Both helpers are part of the client SDK — see the Client SDK for details.
scope key. A human’s uses are counted across both routes combined.
maxUse: 2 and scope: "forecast_pool", a human who calls /weather once and /forecast once has consumed both uses — the next request to either route returns max_use_exceeded.
Event System
Register anonEvent callback to observe verification lifecycle events:
Storage: HumanUsageStorage
HumanUsageStorage is required when any route uses extra.maxUse. It tracks how many times each human has used a given priced tier within a scope.
incrementIfBelow— Increment the counter for(humanId, scope)only if it is strictly belowmaxUse. Return the new count, ornullif the limit is already reached.decrementIfAboveZero— Decrement the counter only if it is above zero. Return the new count, ornullif no decrement was performed. Called by the rollback hooks when a payment fails after the counter was already incremented.
InMemoryHumanUsageStorage (development)
An in-memory implementation is available for local development (
InMemoryHumanUsageStorage from the examples directory), but it must not be used in production — state is lost on restart and is not shared across server instances.Production Storage
For production, implementHumanUsageStorage backed by a persistent, shared store. The key constraint is atomicity on incrementIfBelow.
- Redis — Use a Lua script that performs the
GETand conditionalINCRas a single atomic operation. The key format is typicallyhuman_usage:{humanId}:{scope}. Set a TTL (e.g. 30 days) so counters self-expire. Lua scripts in Redis execute atomically on a single shard, making them the right tool here. - SQL (PostgreSQL / MySQL) — Use an
INSERT ... ON CONFLICT DO UPDATE SET count = count + 1 WHERE count < maxUse RETURNING countpattern. A single statement with aWHEREclause is atomic within a transaction and prevents the race condition without needing an explicit lock. Create a table with(human_id, scope)as the primary key and acountcolumn. - Distributed systems — If you run multiple server instances behind a load balancer, the storage backend must be shared (not per-process). A single Redis instance or a common database satisfies this; a per-process in-memory map does not.
Rollback Hooks
When usingconfigureHumanProofServer with a storage, three rollback hooks are automatically registered to keep usage counts consistent with successfully settled payments:
This ensures a human’s usage quota is only consumed by successfully completed payments. A failed transaction does not burn quota.
To register rollback hooks manually (when not using
configureHumanProofServer):
Paywall HTML
When an unpaid request arrives, the server can return a custom HTML page.paywallInstructions() provides a default page that directs agents to install the identity skill, which enables agents to understand how to sign human-proof challenges, select the right payment tier, and complete the full x402 flow.
Low-Level Helpers
createHumanProofExtension
Lower-level function that creates the ResourceServerExtension object. configureHumanProofServer calls this internally. Use it directly if you need to register the extension manually with server.registerExtension(...).
What it generates inside each
402 response:
The
nonce is generated fresh with randomBytes(16) on every 402 response, so each challenge is unique. The verifier does not check that a nonce was issued by your server or that it hasn’t been used before, and expirationTime is only enforced when the signed payload contains one. If you need replay protection, set expirationSeconds and track issued nonces yourself.createVerifyHumanProofHook
Creates the onBeforeVerify hook function. configureHumanProofServer calls this internally. Use it directly for fine-grained lifecycle control.
requiredAttestations is absent or empty on the selected accepts entry, the hook returns immediately and payment proceeds normally. Otherwise it validates CAIP-122 fields, verifies the EVM signature, resolves the DID against the Billions Network registry, checks any additional attestation schemas, and enforces maxUse if configured.
createPoUVerifier
Creates the default Proof-of-Uniqueness verifier that queries the Billions Network explorer API.
fromId through the nullifier API to return { humanId: nullifier, verifiedAt, attestationId, humanDid, humanAddress, agentDid, agentAddress }. The API leaves revoked attestations out. Expiry is not checked. The defaults point at production; see Environments for the testnet URLs.
Troubleshooting
invalid_signature even though the client signed correctly
invalid_signature even though the client signed correctly
The most common cause is a URI mismatch. The CAIP-122 message embeds the resource URI at signing time, and the server validates that it matches the actual request URL. Check that the
uri in the proof exactly matches http(s)://your-host/your-path — trailing slashes, port numbers, and query strings all matter.not_registered for a DID that should be registered
not_registered for a DID that should be registered
The server calls
lookupHuman, which requires both an attestation record and a valid nullifier via the nullifier API. An attestation existing on the explorer is not enough — fromId must be present on the attestation record and the nullifier API must return a result for it. Verify both by checking the Billions Network explorer directly for your DID.message_expired immediately after signing
message_expired immediately after signing
This usually means significant clock skew between the client and server. The
expirationTime is computed from the server’s clock at 402 generation time. If the client’s clock is far behind the server’s, the message may expire before the client retries. Check NTP sync on both sides.misconfigured_max_use_storage error
misconfigured_max_use_storage error
A route has
extra.maxUse set but no storage was passed to the hook. Pass a storage implementation to configureHumanProofServer or createVerifyHumanProofHook.max_use_exceeded on the first request
max_use_exceeded on the first request
The counter is per
(humanId, scope). If the same human, through any of their agents, previously used the discounted tier (even in a previous server session, if using persistent storage), their counter is already at the limit. Either increase maxUse, change the scope key, or flush the counter in your storage backend.Human-proof check fires even though I didn't set requiredAttestations
Human-proof check fires even though I didn't set requiredAttestations
The hook only runs when
context.requirements?.extra?.requiredAttestations is non-empty. If the hook is running unexpectedly, the client is selecting an accepts entry that has requiredAttestations in its extra. Check which payment option the client is choosing.Error Reference
These values appear in thereason field when the hook aborts, and in the error field of the x402 payment-required header returned to the client.