Skip to content

fix(scan): accept all valid CAIP-2 chain namespaces in ChainIdSchema#688

Closed
craigbidenbot[bot] wants to merge 1 commit intomainfrom
craig/fix-caip2-chainid-schema
Closed

fix(scan): accept all valid CAIP-2 chain namespaces in ChainIdSchema#688
craigbidenbot[bot] wants to merge 1 commit intomainfrom
craig/fix-caip2-chainid-schema

Conversation

@craigbidenbot
Copy link
Copy Markdown
Contributor

@craigbidenbot craigbidenbot Bot commented Mar 5, 2026

Summary

Fixes #687. The ChainIdSchema regex was hardcoded to only accept eip155: and solana: namespaces, rejecting valid CAIP-2 identifiers like tron:0x2b6653dc and aptos:1. This caused multi-chain x402 servers to have all endpoints rejected.

Changes

  • Updated regex in apps/scan/src/lib/x402/v2/schema.ts from /^(eip155:\d+|solana:.+)$/ to /^[a-z][a-z0-9-]{2,}:[a-zA-Z0-9._-]+$/ which follows the CAIP-2 grammar

Test Plan

  • Existing eip155/solana networks still pass validation
  • Tron (tron:0x2b6653dc) and Aptos (aptos:1) now accepted
  • Invalid strings (empty, no colon, short namespace) still rejected

@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented Mar 5, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
x402scan Ready Ready Preview, Comment Mar 5, 2026 10:09am

// NOTE(shafu): this was changed in V2, it does not support network names like base
const ChainIdSchema = z3.custom<Network>(
val => typeof val === 'string' && /^(eip155:\d+|solana:.+)$/.test(val),
val => typeof val === 'string' && /^[a-z][a-z0-9-]{2,}:[a-zA-Z0-9._-]+$/.test(val),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
val => typeof val === 'string' && /^[a-z][a-z0-9-]{2,}:[a-zA-Z0-9._-]+$/.test(val),
val => typeof val === 'string' && /^[-a-z0-9]{3,8}:[-_a-zA-Z0-9]{1,32}$/.test(val),

CAIP-2 regex pattern allows periods in references, exceeds 8-character namespace limit, and has no 32-character reference length limit, violating the official specification

Fix on Vercel

@craigbidenbot
Copy link
Copy Markdown
Contributor Author

craigbidenbot Bot commented Mar 14, 2026

Closing — V2 schema already uses a flexible CAIP-2 regex that accepts all namespaces. V1 is legacy and maintained for backward compat only. Not worth the conflict resolution.

@craigbidenbot craigbidenbot Bot closed this Mar 14, 2026
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.

ChainIdSchema rejects valid CAIP-2 namespaces (tron, aptos)

1 participant