Skip to main content

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.
Already running an x402 server? Adding human-proof takes a single function call — jump straight to Step 2 in the Setup section.
New to x402? It’s an open payment protocol that lets any API accept per-request payments from AI agents and humans, with no subscriptions or API keys. The Setup guide below covers both.
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: x402 Human Proof request lifecycle
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.
If the selected accepts entry has no requiredAttestations in its extra field, the human-proof hook is a no-op and the payment proceeds normally.

Installation

Requires Node.js >= 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 the 402 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 accepts entry — the second pricing tier, gated behind an ownership attestation.
  • declareHumanProofExtension — tells the challenge generator what to embed in each 402 response for this route.
Any payer can use the $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 as server.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.006 price means the server found an ownership attestation for the agent’s DID, and your server logs Human <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 as humanId. 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:
This DID is used to query the Attestations API and look up the human behind the agent. DIDs are computed deterministically, and the SDK handles the conversion internally.

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.
Internally calls:
  • server.registerExtension(createHumanProofExtension(extensionOptions)) — adds the CAIP-122 challenge generator to 402 responses.
  • server.onBeforeVerify(createVerifyHumanProofHook({...})) — verifies the signed proof before payment settlement.
If storage is provided:
  • onAfterVerify — rolls back usage on facilitator failure.
  • onVerifyFailure — rolls back on hook error.
  • onSettleFailure — rolls back if on-chain settlement fails.
Options:

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.
Options:

Tiered Pricing

Human-proof is configured per route — each endpoint in your paymentMiddleware 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

Any client can access the route. Verified humans pay less; everyone else pays full price. This is the most common setup.
Only clients whose DID holds an ownership attestation can use the route. Clients without it are rejected with 402.
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.
How tier selection works: the server does not choose — the client selects a tier by constructing their payment payload for a specific accepts entry. The server enforces it:
  • If the client chose Tier 1 (no requiredAttestations in extra), 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 with 402.

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:
Route setup:
What happens when the limit is reached:
  1. storage.incrementIfBelow(humanId, maxUse, scope) returns null.
  2. The hook returns { abort: true, reason: "max_use_exceeded" }.
  3. The server sends 402 with error: "max_use_exceeded" in the payment-required header.
  4. On the client, isMaxUseExceededError(err) returns true and disqualify() 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.
Shared quota across routes: two routes can share a single usage pool by using the same scope key. A human’s uses are counted across both routes combined.
With 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 an onEvent 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 below maxUse. Return the new count, or null if the limit is already reached.
  • decrementIfAboveZero — Decrement the counter only if it is above zero. Return the new count, or null if no decrement was performed. Called by the rollback hooks when a payment fails after the counter was already incremented.
incrementIfBelow must be a single atomic operation. Without atomicity, two concurrent requests from the same human can both pass the limit check and both increment the counter, effectively doubling the allowed usage. A non-atomic check-then-increment is a race condition that will silently bypass maxUse under load.

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, implement HumanUsageStorage backed by a persistent, shared store. The key constraint is atomicity on incrementIfBelow.
  • Redis — Use a Lua script that performs the GET and conditional INCR as a single atomic operation. The key format is typically human_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 count pattern. A single statement with a WHERE clause 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 a count column.
  • 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 using configureHumanProofServer 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.
The default page links to the identity skill at clawhub.ai and skills.sh.

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(...).
Options: 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.
If 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.
Queries the Attestations API for the DID, takes the most recent ownership attestation, then resolves its 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

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.
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.
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.
A route has extra.maxUse set but no storage was passed to the hook. Pass a storage implementation to configureHumanProofServer or createVerifyHumanProofHook.
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.
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 the reason field when the hook aborts, and in the error field of the x402 payment-required header returned to the client.