Skip to content

fix(caip): allow hyphen in CAIP-2 namespace per spec - #176

Open
midasbal wants to merge 1 commit into
agentcommercekit:mainfrom
midasbal:fix/caip2-namespace-hyphen
Open

fix(caip): allow hyphen in CAIP-2 namespace per spec#176
midasbal wants to merge 1 commit into
agentcommercekit:mainfrom
midasbal:fix/caip2-namespace-hyphen

Conversation

@midasbal

@midasbal midasbal commented Aug 24, 2026

Copy link
Copy Markdown

caip2NamespacePattern (packages/caip/src/caips/caip-2.ts) was "[a-z0-9]{3,8}", but the CAIP-2 spec defines the namespace grammar as [-a-z0-9]{3,8}, hyphen included. The sibling caip19AssetNamespacePattern in caip-19.ts already uses the hyphenated form, and this file's own doc comment repeated the same wrong pattern, so the fix also corrects the comment for internal consistency. Added regression tests for a hyphenated namespace being accepted and an invalid character still being rejected, and a changeset for @agentcommercekit/caip (patch). One existing did:pkh resolver test's "invalid URI" fixture depended on the old regex rejecting a hyphenated namespace as its only source of invalidity; it's updated to use an uppercase namespace instead, which stays invalid for its own, unrelated, still-enforced reason.

AI assistance disclosure: This contribution was AI-assisted using Claude Code. AI was used to identify the spec discrepancy, implement the pattern/doc-comment fix, write the regression tests, and update the affected did:pkh test fixture. I reviewed the full diff and test output, understand the change and why the did:pkh test needed updating, and take responsibility for what's submitted here.

Summary by CodeRabbit

  • Bug Fixes

    • CAIP-2 chain identifiers now correctly accept hyphens in namespaces, in accordance with the specification.
    • Invalid underscore characters and uppercase namespace values continue to be rejected.
  • Tests

    • Expanded validation coverage for hyphenated namespaces and invalid namespace formats.
  • Release

    • Prepared a patch release for the CAIP package.

caip2NamespacePattern was "[a-z0-9]{3,8}", but the CAIP-2 spec defines
namespace as "[-a-z0-9]{3,8}" (hyphen allowed). The sibling
caip19AssetNamespacePattern already used the hyphenated form, and this
file's own doc comment repeated the wrong pattern.

Also updates a did:pkh resolver test whose "invalid URI" fixture relied
on the old, hyphen-rejecting namespace regex as its only source of
invalidity; it now uses an uppercase namespace, which is invalid for an
unrelated, still-enforced reason.
@coderabbitai

coderabbitai Bot commented Aug 24, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 158757fe-909a-4cac-ac68-890e472c3621

📥 Commits

Reviewing files that changed from the base of the PR and between 0b8fdaa and 9125d43.

📒 Files selected for processing (5)
  • .changeset/curly-hyphens-parse.md
  • packages/caip/src/caips/caip-2.test.ts
  • packages/caip/src/caips/caip-2.ts
  • packages/caip/src/schemas/schemas.test.ts
  • packages/did/src/did-resolvers/pkh-did-resolver.test.ts

Included review availability: Your plan provides up to 2 included reviews per hour; 1 remains after this review.


Walkthrough

The CAIP-2 namespace pattern now permits hyphens within 3–8-character namespaces. Tests cover valid hyphenated namespaces and invalid underscores. A related did:pkh test now checks uppercase namespace rejection, and a patch changeset documents the update.

Changes

CAIP-2 Namespace Support

Layer / File(s) Summary
Update CAIP-2 namespace patterns
packages/caip/src/caips/caip-2.ts
The CAIP-2 namespace pattern now permits hyphens and updates the derived chain ID and regex patterns.
Validate namespace handling
packages/caip/src/caips/caip-2.test.ts, packages/caip/src/schemas/schemas.test.ts, packages/did/src/did-resolvers/pkh-did-resolver.test.ts, .changeset/curly-hyphens-parse.md
Tests accept eip-155:1, reject underscores, preserve uppercase namespace rejection, and document the patch release.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 9125d

This patch permits spec-compliant hyphenated CAIP-2 namespaces while continuing to reject invalid characters, with focused test updates. No actionable merge-blocking risk remains after normal checks and review.

Suggested reviewers: venables

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: allowing hyphens in CAIP-2 namespaces according to the specification.
Docstring Coverage ✅ Passed Docstring check was indeterminate for this PR — some files could not be analyzed in time. Not blocking.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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