Architecture Overview
Grantex x402 adds an authorization layer to the x402 HTTP Payment Required protocol. Five components work together to ensure that every agent payment is authorized, scoped, and auditable.Components
GDT Issuer
The GDT Issuer creates signed W3C Verifiable Credentials that encode the delegation from a principal to an agent. Each GDT specifies:- Agent DID — The identity of the delegated agent
- Scope — What resources/actions the agent can access
- Spend Limit — Maximum amount per time period
- Expiry — When the delegation ends
- Delegation Chain — Parent DIDs for sub-delegation
GDT Verifier
The verifier is embedded in thex402Middleware and the verifyGDT() function. It performs six checks:
- JWT Signature — Ed25519 (EdDSA) verification using the issuer’s public key (resolved from the DID)
- Token Expiry — Rejects tokens past their
expclaim - Revocation Status — Checks the revocation registry
- Scope Match — Ensures the requested resource is covered by granted scopes
- Spend Limit — Ensures the request amount doesn’t exceed the authorized limit
- VC Structure — Validates the W3C VC 2.0 credential format
x402 Adapter
The adapter wraps the nativefetch() function to handle the x402 payment flow automatically:
- Sends the initial request with the
X-Grantex-GDTheader - On
402 Payment Required, extracts payment details - Executes payment via the configured handler (Base L2 USDC transfer)
- Retries the request with both
X-Payment-ProofandX-Grantex-GDTheaders
Revocation Registry
An in-memory registry of revoked token IDs. Tokens are identified by theirjti (JWT ID) claim. Revocation is instant — a revoked token is rejected on the next verification.
The RevocationRegistry interface supports pluggable backends:
Audit Log
An append-only log that records every GDT lifecycle event:- Issuance — When a GDT is created
- Verification — When a GDT is successfully verified
- Rejection — When verification fails (scope mismatch, spend exceeded, revoked)
- Payment — When an x402 payment is processed
- Revocation — When a token is revoked
Security Model
Threat: Compromised Agent
A compromised agent cannot spend beyond the GDT’s scope and limit. If detected, the principal revokes the GDT immediately. The audit log shows exactly what the agent accessed.Threat: Token Replay
Each GDT has a uniquejti claim. The revocation registry prevents reuse after revocation. The spend limit provides a natural cap even without revocation.
Threat: Scope Escalation
The verifier performs strict scope matching. Aweather:read token cannot be used for finance:write. Wildcard scopes (weather:*) are supported but must be explicitly granted.
Threat: Token Tampering
Ed25519 signatures are verified against the issuer’s public key (derived from the DID). Any modification to the JWT payload invalidates the signature.HTTP Headers
| Header | Direction | Purpose |
|---|---|---|
X-Grantex-GDT | Request | Carries the GDT JWT |
X-Payment-Required | Response (402) | Indicates payment is needed |
X-Payment-Amount | Response (402) | Payment amount |
X-Payment-Currency | Response (402) | Payment currency (USDC/USDT) |
X-Payment-Recipient | Response (402) | Recipient wallet address |
X-Payment-Chain | Response (402) | Blockchain (e.g., “base”) |
X-Payment-Proof | Request (retry) | Payment transaction proof |
DID Resolution
GDTs usedid:key identifiers for both principals and agents. The public key is embedded directly in the DID, enabling offline verification without network calls.
z— multibase prefix for base58btc6Mk— start of Ed25519 multicodec-encoded keys- Supports offline resolution — no DID resolver network required