Documentation Index
Fetch the complete documentation index at: https://sigil-10dddbf2.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
@sigil-xyz/x402 implements a request authentication flow on top of HTTP 402 Payment Required. It lets any server verify that an incoming request comes from a credentialed, in-budget agent — without a separate auth service.
How it works
Agent builds signed headers
The agent calls
buildSigilHeaders with its keypair, the principal public key, the request method, path, and spend amount. This produces four HTTP headers containing the agent’s public key, the principal’s public key, a timestamp, and an ed25519 signature.Signature verification
The middleware reconstructs the signed message
{timestamp}:{METHOD}:{path}:{spendAmount} and verifies the ed25519 signature against the agent’s public key.Timestamp check
Rejects the request if the timestamp is older than
maxRequestAgeMs (default 60 seconds). Prevents replay attacks.On-chain Sigil check
Calls
client.verifySigil(agentPubkey, { requiredCapability, maxSpendAmount }). Returns 402 if the Sigil is missing, revoked, expired, or lacking the required capability.Record spend
If
spendAmount > 0, calls client.recordSpend(agentPubkey, amount) on-chain. This debits the agent’s daily limit and rejects the request if the limit would be exceeded.Required headers
Agents must attach these four headers to every request:| Header | Value |
|---|---|
x-sigil-agent | Base58 agent public key |
x-sigil-principal | Base58 principal public key that issued the agent’s Sigil |
x-sigil-timestamp | Unix timestamp in milliseconds |
x-sigil-signature | Base58 ed25519 signature |
Signature payload
1714300000000:POST:/api/generate:50000
The message is UTF-8 encoded and signed with the agent’s ed25519 secret key using nacl.sign.detached.
402 response body
When authorization fails, the middleware returns HTTP402 with:
SigilMiddlewareConfig
All adapters (Express and Next.js) share the same config interface:spendAmount to zero (or omitting it) runs verification only — the Sigil is checked but no spend is recorded.