Introduction
The Trusted Agent Protocol (TAP) lets AI agents prove they are backed by a verified person, without revealing who. Visa CLI is the first implementation: a person verifies their agent with a US Visa card, and any server can check the agent signed requests with one public lookup and no account.
But here is the problem: every merchant has to build their own verifier. The docs give you code, but there is no drop-in product. You need to wire up signature parsing, registry lookups, caching, origin pinning, replay protection, policy enforcement, and rate limiting yourself.
The TAP Verify Gateway solves this. It is a reverse proxy that sits in front of your API and verifies TAP signatures before requests reach your code. Drop it in, configure your upstream, and you are done.
Architecture Overview
Agent (signed request) --> TAP Gateway --> Your API
|
Visa CLI Registry
(key lookup + verify)
Technology Stack
| Layer | Technology | Why |
|---|---|---|
| Runtime | Node.js 22 | LTS, native ESM, crypto.randomUUID() |
| HTTP Framework | Hono | Ultra-fast, runs on Node/Workers/Deno/Bun |
| Crypto | tweetnacl | Ed25519 sign/verify; JWK thumbprint matching |
| Validation | Zod | Schema validation for policy config |
| Logging | Pino | Structured JSON logs, low overhead |
| Database | PostgreSQL 16 | Decision log storage (optional) |
| Deployment | Docker + Compose | Reproducible, one-command local dev |
Core Code: The Verifier
export async function verifyRequest(
signatureHeader: string | URLSearchParams,
signatureInputHeader: string | URLSearchParams,
pinnedOrigin: string,
registryOrigin: string = 'https://auth.visacli.sh',
acceptedTrids: string[] = [],
keyCache?: Map<string, { key: any; expiresAt: number }>
): Promise<VerificationDecision> {
const keyid = extractKeyid(signatureHeader)
if (!keyid) return { ok: false, reason: 'missing keyid', error: 'missing_keyid' }
const signatureBytes = b64urlDecode(extractSignature(signatureHeader)!)
const sigInput = extractSignatureInput(signatureInputHeader)
if (!sigInput) return { ok: false, reason: 'invalid Signature-Input', error: 'missing_signature_input' }
const { nonce, timestamp, origin } = sigInput
if (origin !== pinnedOrigin) {
return { ok: false, reason: 'origin mismatch', error: 'origin_mismatch' }
}
if (Date.now() - timestamp > 5 * 60 * 1000) {
return { ok: false, reason: 'request too old', error: 'request_too_old' }
}
const registryResp = await fetch(`${registryOrigin}/v1/tap/registry/agents/${keyid}`)
const registryKey = registryResp.ok ? await registryResp.json() : null
if (registryKey && !registryKey.isActive) {
return { ok: false, reason: 'key not active', error: 'key_not_active' }
}
const publicKey = b64urlDecode(registryKey.publicKeyJwk.x)
const sigBase = new TextEncoder().encode(`GET/${nonce}${timestamp}`)
const valid = nacl.sign.detached.verify(sigBase, signatureBytes, publicKey)
if (!valid) return { ok: false, reason: 'invalid signature', error: 'invalid_signature' }
return { ok: true, agentId: keyid, verified: registryKey?.isActive === true }
}
The Server: Middleware + Proxy
app.use('*', async (c, next) => {
const signatureHeader = c.req.header('Signature')
const signatureInputHeader = c.req.header('Signature-Input')
if (!signatureHeader || !signatureInputHeader) {
return c.json({ code: 'invalid_request', detail: 'Missing headers' }, 400)
}
const decision = await verifyRequest(
new URLSearchParams(signatureHeader),
new URLSearchParams(signatureInputHeader),
ENV.PINNED_ORIGIN,
ENV.REGISTRY_ORIGIN,
ENV.ACCEPTED_TRIDS,
keyCache,
)
c.set('tapVerification', decision)
if (!decision.ok) {
return c.json({ code: 'verification_failed', detail: decision.reason }, 401)
}
const policyResult = checkPolicy(policy, decision, c.req.path, c.req.method)
if (!policyResult.allowed) {
return c.json({ code: 'policy_denied', detail: policyResult.reason }, 403)
}
const rateResult = rateLimiter.check(decision.agentKeyid || 'anonymous')
if (!rateResult.allowed) {
return c.json({ code: 'rate_limited', detail: 'Rate limit exceeded' }, 429)
}
c.req.raw.headers.set('X-Agent-Id', decision.agentId || '')
c.req.raw.headers.set('X-Agent-Verified', String(decision.verified || false))
c.req.raw.headers.set('X-Agent-TRID', decision.trid || '')
await next()
})
app.all('*', async (c) => {
const upstreamUrl = new URL(c.req.path, ENV.UPSTREAM_URL)
const response = await fetch(upstreamUrl.toString(), {
method: c.req.method,
headers: c.req.raw.headers,
body: c.req.method !== 'GET' && c.req.method !== 'HEAD'
? await c.req.arrayBuffer() : undefined,
})
return new Response(response.body, {
status: response.status,
headers: response.headers,
})
})
Policy Engine
export function checkPolicy(policy: Policy, decision: any, path: string, method: string) {
if (policy.allowedTrids.length > 0 && decision.trid && !policy.allowedTrids.includes(decision.trid)) {
return { allowed: false, reason: `TRID ${decision.trid} not in allowed list` }
}
const pathAllowed = policy.allowedPaths.some(p => path.startsWith(p))
if (!pathAllowed) {
return { allowed: false, reason: `Path ${path} not in allowed paths` }
}
if (!policy.allowedMethods.includes(method.toUpperCase())) {
return { allowed: false, reason: `Method ${method} not allowed` }
}
return { allowed: true }
}
Rate Limiter
export class RateLimiter {
private store = new Map<string, { count: number; resetAt: number }>()
check(key: string): { allowed: boolean; remaining: number; resetAt: number } {
const now = Date.now()
const entry = this.store.get(key)
if (!entry || now > entry.resetAt) {
this.store.set(key, { count: 1, resetAt: now + this.windowMs })
return { allowed: true, remaining: this.maxRequests - 1, resetAt: now + this.windowMs }
}
if (entry.count >= this.maxRequests) {
return { allowed: false, remaining: 0, resetAt: entry.resetAt }
}
entry.count++
return { allowed: true, remaining: this.maxRequests - entry.count, resetAt: entry.resetAt }
}
}
Injected Headers
| Header | Value |
|---|---|
| X-Agent-Id | The agent key ID |
| X-Agent-Verified | true if owner passed card step |
| X-Agent-TRID | The agent Token Requestor ID |
| X-Agent-Keyid | The signing key ID |
| X-RateLimit-Remaining | Remaining requests in window |
| X-RateLimit-Reset | Rate limit reset timestamp |
How to Fork and Contribute
1. Fork the repo
git clone https://github.com/YOUR_ORG/tap-verify-gateway.git
cd tap-verify-gateway
npm install
2. Set up your environment
cp .env.example .env
npm run dev
3. Pick an issue and build
Good first contributions:
- Cloudflare Workers adapter
- Vercel Edge adapter
- Redis-backed cache
- OpenTelemetry exporter
- WebSocket signature verification
- Admin dashboard UI
4. Submit a PR
git checkout -b feature/your-feature
npm run build && npm run lint
git commit -m "feat: your feature description"
git push origin feature/your-feature
New Features You Could Add
| Feature | Difficulty | Impact |
|---|---|---|
| Cloudflare Workers adapter | Medium | High |
| Redis-backed cache | Low | Medium |
| OpenTelemetry exporter | Medium | High |
| WebSocket signature verification | Medium | Medium |
| Admin dashboard UI | Medium | High |
| IP-based rate limiting | Low | Medium |
| Custom policy rules (time, geo) | Medium | Medium |
| Multi-upstream routing | Medium | High |
Conclusion
The TAP Verify Gateway gives you everything you need to protect your API with verified agent identity. It handles the hard parts: signature verification, registry lookups, caching, policy, rate limiting. So you can focus on your API unique value.
Fork it, deploy it, and contribute back. The TAP ecosystem grows when more APIs adopt verified-agent gating.
Links
- Visa CLI Docs: https://app.visacli.sh/docs
- Verify a signed request: https://app.visacli.sh/docs/verify-a-signed-request.md
- Verifier code: https://app.visacli.sh/docs/verifier-code.md
- Trusted Agent Protocol Spec: https://developer.visa.com/docs/trusted-agent-protocol/trusted-agent-protocol-specifications
Code & more: https://www.dailybuild.xyz/project/326-tap-verify-gateway
Top comments (0)