Skip to content

feat: add /.well-known/x402.json discovery and x402 payment middleware#3

Open
cedarxyz wants to merge 1 commit into
pbtc21:masterfrom
cedarxyz:feat/x402-discovery-and-middleware
Open

feat: add /.well-known/x402.json discovery and x402 payment middleware#3
cedarxyz wants to merge 1 commit into
pbtc21:masterfrom
cedarxyz:feat/x402-discovery-and-middleware

Conversation

@cedarxyz
Copy link
Copy Markdown

Summary

  • Add consolidated GET /.well-known/x402.json endpoint listing all 3 paid endpoints (/execute, /nft/create, /nft/execute) in a single discovery document
  • Add x402 middleware that gates POST /execute and POST /nft/create behind payment verification via the Stacks x402 facilitator
  • Middleware returns 402 with x402-compliant payment details when X-Payment header is missing, and verifies the signed tx via facilitator.x402stacks.xyz when present

Changes

  • src/index.ts: Add FACILITATOR_URL constant, X402_ROUTES config, x402Middleware function, /.well-known/x402.json route, updated Hono app type with Variables

Test plan

  • GET /.well-known/x402.json → returns consolidated discovery doc with 3 endpoints
  • POST /execute without X-Payment header → returns 402 with payment requirements
  • POST /execute with invalid X-Payment header → returns 402 "Invalid Payment"
  • POST /execute with valid verified payment → passes through to handler
  • POST /nft/create without X-Payment header → returns 402
  • GET /execute (discovery) → still works unchanged
  • POST /quote, POST /aibtc/airdrop → not affected by middleware

🤖 Generated with Claude Code

- Add consolidated /.well-known/x402.json listing all 3 paid endpoints
  (/execute, /nft/create, /nft/execute) in one discovery document
- Add x402 middleware gating POST /execute and POST /nft/create behind
  payment verification via the Stacks x402 facilitator
- Middleware returns 402 with payment details when X-Payment header is
  missing, verifies signed tx via facilitator when present

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant