Skip to content

Conversation

@MajorLift
Copy link
Contributor

@MajorLift MajorLift commented Aug 25, 2025

This commit adds a type for CAIP chain IDs that are namespaced by a known CAIP namespace.

This type enables the usage of safer literal string types for namespaced CAIP chain IDs, and is intended as a narrower alternative to CaipChainId.

Any and all suggestions about type name, jsdoc comments etc. are welcome.

Copy link
Contributor

@mcmire mcmire left a comment

Choose a reason for hiding this comment

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

Makes sense to me.

Would be curious to know what @ccharly, @jiexi, and @erwolff think, since they worked on these types in the past.

@erwolff
Copy link
Contributor

erwolff commented Aug 25, 2025

Makes sense to me.

Would be curious to know what @ccharly, @jiexi, and @erwolff think, since they worked on these types in the past.

I'll defer to @ccharly for final say here, but I think this is a useful addition. That being said, I think the reasoning (and the jsdoc comment) may need to be adjusted. 'eip155:${string}' is indeed assignable to '${string}:${string}', as it is a valid subtype. This proposed change is simply adding a narrower subtype, to ensure the namespace of the chain id is known to this library. I'd propose updating the jsdoc to something along the lines of:

/**
 * A CAIP-2 chain ID that is guaranteed to have a known CAIP namespace
 * (see {@link KnownCaipNamespace}).
 *
 * This is a narrower, more type-safe alternative to {@link CaipChainId} for use cases
 * where the chain namespace must be one of the known standards.
 */

Co-authored-by: Eric Wolff <erwolff@gmail.com>
@MajorLift
Copy link
Contributor Author

MajorLift commented Aug 25, 2025

`eip155:${string}` is indeed assignable to `${string}:${string}`

@erwolff Thanks for the correction. I should have verified that first. Looks like I was misunderstanding the error message I was seeing.

Fixed jsdoc as suggested: 23c99b9

@MajorLift MajorLift merged commit 4eab923 into main Aug 26, 2025
22 checks passed
@MajorLift MajorLift deleted the jongsun/feat/250825-add-type-KnownCaipNamespacedChainId branch August 26, 2025 11:04
@ccharly
Copy link
Contributor

ccharly commented Aug 28, 2025

Sorry, completely miss the notification here. But that sounds like a good addition to me yes! Thanks 💪

MajorLift added a commit that referenced this pull request Aug 28, 2025
…eter (#262)

This commit refactors `KnownCaipNamespacedChainId` (introduced in
[#258](#258)) into a generic type
by adding a `Namespace` type parameter. This allows the type to be
narrowed down to chain IDs with a specific namespace.

This is not a breaking change, as `Namespace` defaults to a type union
of known CAIP namespaces. The type's previous behavior is preserved when
its generic type parameter is omitted.
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.

6 participants