Overview
@billionsnetwork/x402-human-proof-client is the client SDK for agents calling services that require per-request payments and human-backed verification powered by the x402 human proof protocol.
It enables clients to:
- Sign CAIP-122 (SIWE) challenges embedded in
402responses so the server can verify the agent is operated by a real human. - Check held attestations against the Billions Network registry before attempting a payment, so attestation-gated (discounted) pricing tiers are selected only when the client qualifies.
- Fall back gracefully when attestations are missing (
MissingAttestationsError) or when a per-human usage cap is hit (isMaxUseExceededError+disqualify()).
How It Works

- The selector runs synchronously at payment creation time; attestation state is cached and refreshed via
refresh(). - The extension re-checks attestations live just before signing — the selector cache and the live check serve different purposes: tier selection vs. proof construction.
- If the server returns
max_use_exceeded, calldisqualify()on the selector and retry — it will skip discounted tiers permanently for that instance.
Installation
Requires Node.js
>= 20.11.0 and an x402-compatible HTTP client. The agent wallet must hold a Billions Network PoU attestation to access discounted pricing tiers.Quick Start
Core Concepts
The Human-Proof Challenge
When the server is configured with@billionsnetwork/x402-human-proof-server, its 402 responses include an extensions["human-proof"] object:
createHumanProofExtension handles signing and proof construction automatically when registered with the x402 client.
CAIP-122 / SIWE Signing
CAIP-122 defines chain-agnostic message signing. For EVM chains the SDK uses Sign-In with Ethereum (SIWE /eip191). signHumanProofChallengeEVM handles message formatting and signing; createHumanProofExtension calls it automatically — use it directly only if you need lower-level control.
Configuration Reference
createHumanProofExtension(signer, options?)
Register this extension on your x402 client to handle challenge signing automatically. On each payment attempt it extracts the human-proof challenge from the 402 body, verifies the wallet holds all required attestations, and injects the signed proof into the payment payload.
HumanProofExtensionOptions:
If no challenge is present in the
402 body the payload is returned unchanged. Otherwise it checks each required attestation schema (throwing MissingAttestationsError if any are missing), signs the SIWE message with the first eip191/eip1271 chain, and returns the payload with extensions["human-proof"] set.
Compatibility: the
EVMSigner interface is intentionally minimal. It is compatible with viem WalletClient, viem LocalAccount (privateKeyToAccount), and ethers v6 Signer.createAttestationAwareSelector(did, schemas?, options?)
Creates a selector + refresh + disqualify triple for use with new x402Client(selector). The selector picks the most favorable accepts entry based on cached attestation state.
Returns:
buildDIDFromAddress(ethAddress)
Derives the Billions Network DID from an EVM wallet address.
Returns:
string — the full DID string using the did:iden3:billions:main: method.
checkAttestation(did, schemaId, options?)
Queries the Billions Network attestations API to check whether a DID holds at least one attestation matching a given schema ID.
Returns:
Promise<boolean> — true if at least one matching attestation record exists.
Low-Level Helpers
signHumanProofChallengeEVM(challenge, signer, chainId)
Lower-level function that signs a CAIP-122 challenge for an EVM chain and returns the JSON proof string. createHumanProofExtension calls this internally.
Returns:
Promise<string> — a JSON-encoded string containing all CAIP-122 fields plus address, signature, chainId, and type.
Throws: Error if chainId is not found in challenge.supportedChains with type eip191.
extractHumanProofChallenge(paymentRequired)
Extracts the human-proof extension object from a 402 response body. Returns null if no challenge is present — safe to call on any paymentRequired response.
Returns:
HumanProofChallenge | null
Error Handling
MissingAttestationsError
Thrown by createHumanProofExtension when the wallet doesn’t hold one or more required attestations.
Expect this when one or more schemas in
challenge.info.requiredAttestations are not held by the DID — either the user hasn’t completed Billions Network registration yet, or the DID was derived from a different wallet than the one that holds the attestation.
isMaxUseExceededError
Returns true when an HTTP error response has status 402 and the payment-required header contains error: "max_use_exceeded".
boolean. Compatible with axios, fetch, node-fetch, and similar.