Skip to content

fix(caip): add input validation to createCaip10AccountId#67

Open
ak68a wants to merge 2 commits intoagentcommercekit:mainfrom
ak68a:fix/caip10-validation
Open

fix(caip): add input validation to createCaip10AccountId#67
ak68a wants to merge 2 commits intoagentcommercekit:mainfrom
ak68a:fix/caip10-validation

Conversation

@ak68a
Copy link
Copy Markdown

@ak68a ak68a commented Mar 25, 2026

Summary

  • Validate chainId against caip2ChainIdRegex and address against caip10AccountAddressRegex before creating the account ID
  • Add test cases for invalid inputs

createCaip10AccountId previously performed no validation, allowing malformed chain IDs and addresses to propagate silently. The regex patterns were already defined in the module but not being used. This brings the function in line with caip10Parts(), which already validates its input.

Test plan

  • Existing CAIP tests pass
  • New tests verify rejection of invalid chain IDs and addresses

AI Disclosure: This PR was developed with assistance from Claude Code (Claude Opus).

Summary by CodeRabbit

  • Bug Fixes
    • Improved validation when creating CAIP-10 account IDs so invalid chain identifiers and empty/invalid account addresses are rejected with clearer error responses.
  • Tests
    • Added test coverage for the new validation and expected failure cases to ensure reliable behavior.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 25, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5ac4496b-2e88-4c24-9519-545e608979d9

📥 Commits

Reviewing files that changed from the base of the PR and between d370f60 and 15f4b52.

📒 Files selected for processing (1)
  • packages/caip/src/caips/caip-10.ts
✅ Files skipped from review due to trivial changes (1)
  • packages/caip/src/caips/caip-10.ts

Walkthrough

Added runtime input validation to createCaip10AccountId and corresponding Vitest cases asserting errors for invalid CAIP-2 chain IDs and empty CAIP-10 account addresses.

Changes

Cohort / File(s) Summary
CAIP-10 implementation
packages/caip/src/caips/caip-10.ts
Adds runtime validation: checks chainId against caip2ChainIdRegex and address against caip10AccountAddressRegex; throws descriptive Error on validation failure; returns ${chainId}:${address} on success.
CAIP-10 tests
packages/caip/src/caips/caip-10.test.ts
Adds two Vitest cases asserting that invalid chainId throws "Invalid CAIP-2 chain ID" and that an empty address throws "Invalid CAIP-10 account address".

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: adding input validation to createCaip10AccountId function.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 and usage tips.

@venables
Copy link
Copy Markdown
Contributor

venables commented Apr 1, 2026

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 1, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/caip/src/caips/caip-10.ts`:
- Around line 41-46: Add explicit string type guards before using
caip2ChainIdRegex.test(chainId) and caip10AccountAddressRegex.test(address):
check typeof chainId === "string" and typeof address === "string" and throw the
existing Error messages if those checks fail, then perform the regex tests as
currently written; update the validation logic around the caip2ChainIdRegex and
caip10AccountAddressRegex usages so non-string inputs are rejected early and
clearly (refer to the variables chainId, address and the regex constants
caip2ChainIdRegex, caip10AccountAddressRegex).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: efc6a196-ca87-46a2-a4ff-64f44f7a18df

📥 Commits

Reviewing files that changed from the base of the PR and between f0e8c6c and d370f60.

📒 Files selected for processing (2)
  • packages/caip/src/caips/caip-10.test.ts
  • packages/caip/src/caips/caip-10.ts

Co-Authored-By: Claude Opus 4.6 (1M context) <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.

2 participants