跳到正文
DEV Community· Harish Kotra (he/him)·· 5 小時前AI 評分45

建立 TAP Marketplace 入門套件

Building a TAP Marketplace Starter Kit

AI 導讀

TAP Marketplace Starter Kit 是 Trusted Agent Protocol(TAP)的參考實作,提供完整任務流程:發布、搜尋、認領、提交、接受及付款。

正文

Introduction

The Trusted Agent Protocol (TAP) is an open standard that 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 what happens after verification? How do you actually build a marketplace where verified agents do real work and get paid?

That is what the TAP Marketplace Starter Kit answers. It is a reference implementation of the full task lifecycle: post, discover, claim, submit, accept, payout. Using TAP signatures, escrow, and OUSD/402 payments.

Architecture Overview

┌─────────────────────────────────────────────────────────────────┐
│                    TAP Marketplace Starter Kit                   │
├─────────────────────────────────────────────────────────────────┤
│                                                                 │
│  ┌──────────────┐    ┌──────────────┐    ┌──────────────┐      │
│  │   Agent      │    │  Marketplace │    │  Visa CLI    │      │
│  │   (MCP)      │    │   Server     │    │  Registry    │      │
│  └──────┬───────┘    └──────┬───────┘    └──────┬───────┘      │
│         │                   │                   │              │
│         │  1. POST /tasks   │                   │              │
│         │ ─────────────────►│                   │              │
│         │                   │  2. verify sig    │              │
│         │                   │ ─────────────────►│              │
│         │                   │                   │              │
│         │  3. 201 created   │                   │              │
│         │ ◄─────────────────│                   │              │
│         │                   │                   │              │
│         │  4. GET /tasks    │                   │              │
│         │ ─────────────────►│                   │              │
│         │                   │                   │              │
│         │  5. POST /claim   │                   │              │
│         │ ─────────────────►│                   │              │
│         │                   │  6. verify sig    │              │
│         │                   │ ─────────────────►│              │
│         │                   │                   │              │
│         │  7. POST /submit  │                   │              │
│         │ ─────────────────►│                   │              │
│         │                   │                   │              │
│         │  8. POST /accept  │                   │              │
│         │ ─────────────────►│                   │              │
│         │                   │  9. payout check  │              │
│         │                   │ ─────────────────►│ Visa Agent   │
│         │                   │                   │ Directory    │
│         │                   │                   │              │
│         │  10. OUSD payout  │                   │              │
│         │ ◄─────────────────│                   │              │
│                                                                 │
└─────────────────────────────────────────────────────────────────┘

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
ORM Drizzle ORM Type-safe, zero runtime deps, auto-migrations
Database PostgreSQL 16 ACID, JSONB for flexible content, great for audit logs
Crypto tweetnacl Ed25519 sign/verify; JWK thumbprint matching
Validation Zod Schema validation for request bodies
Logging Pino Structured JSON logs, low overhead
Deployment Docker + Compose Reproducible, one-command local dev

Database Schema

CREATE TABLE tasks (
  id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
  owner_id UUID NOT NULL REFERENCES agents(id),
  reward_oistr TEXT NOT NULL,
  stake_oistr TEXT,
  title TEXT NOT NULL,
  description TEXT,
  capability TEXT,
  deadline TIMESTAMPTZ,
  free_submissions INTEGER NOT NULL DEFAULT 0,
  status TEXT NOT NULL DEFAULT 'open',
  claimed_at TIMESTAMPTZ,
  submitted_at TIMESTAMPTZ,
  accepted_at TIMESTAMPTZ,
  created_at TIMESTAMPTZ DEFAULT now(),
  updated_at TIMESTAMPTZ DEFAULT now()
);

Core Code: The Verifier

The heart of the marketplace is the TAP verifier. Every request must carry a Signature + Signature-Input header pair.

export async function verifyRequest(
  signatureHeader: string | URLSearchParams,
  signatureInputHeader: string | URLSearchParams,
  pinnedOrigin: string,
  registryOrigin: string = 'https://auth.visacli.sh',
  acceptedTrids: string[] = []
): 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: Routes

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,
  )

  c.set('tapVerification', decision)
  if (!decision.ok) {
    return c.json({ code: 'verification_failed', detail: decision.reason }, 401)
  }
  await next()
})

app.post('/tasks', async (c) => {
  const body = await c.req.json()
  const task = await dbAny.insert(schemaAny.tasks).values({
    ownerId: body.ownerId,
    rewardOistr: body.rewardOistr,
    title: body.title,
  }).returning()
  return c.json({ id: task[0].id, task: task[0] }, 201)
})

How to Fork and Contribute

1. Fork the repo

git clone https://github.com/YOUR_ORG/tap-marketplace-starter-kit.git
cd tap-marketplace-starter-kit
npm install

2. Set up your environment

cp .env.example .env
docker compose up -d
npm run db:generate && npm run db:migrate
npm run dev

3. Pick an issue and build

Good first contributions:

  • Add requiresVerified column for verified-only tasks
  • Rate limiting with per-agent 429 and Retry-After header
  • MCP adapter wiring attest_http_request to POST /tasks
  • Real Tempo integration for OUSD payments
  • Approval inbox web UI for owners
  • Vitest + test containers for integration testing
  • OpenAPI spec generation from Hono routes

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
Multi-agent tasks Medium High
Reputation scoring Medium High
Task templates Low Medium
Webhook notifications Low Medium
Dashboard UI Medium High
OpenAPI + SDK generation Low Medium
Real-time updates Medium Medium
Multi-currency support High High

Conclusion

The TAP Marketplace Starter Kit gives you everything you need to build a marketplace where verified AI agents do real work and get paid. It handles the hard parts: signature verification, escrow, payout checks, audit logging. So you can focus on your marketplace unique value.

Fork it, build on it, and contribute back. The TAP ecosystem grows when more marketplaces adopt verified-agent gating.

Links

Code & more: https://www.dailybuild.xyz/project/324-tap-marketplace-starter-kit

來源:DEV Community · dev.to