Skip to content

Commit 4afd599

Browse files
authored
Document canonicalization in CAIP2 and CAIP10 libraries (#5319)
1 parent 0df841d commit 4afd599

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

contracts/utils/CAIP10.sol

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ import {CAIP2} from "./CAIP2.sol";
1313
* account_id: chain_id + ":" + account_address
1414
* chain_id: [-a-z0-9]{3,8}:[-_a-zA-Z0-9]{1,32} (See {CAIP2})
1515
* account_address: [-.%a-zA-Z0-9]{1,128}
16+
*
17+
* WARNING: According to [CAIP-10's canonicalization section](https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-10.md#canonicalization),
18+
* the implementation remains at the developer's discretion. Please note that case variations may introduce ambiguity.
19+
* For example, when building hashes to identify accounts or data associated to them, multiple representations of the
20+
* same account would derive to different hashes. For EVM chains, we recommend using checksummed addresses for the
21+
* "account_address" part. They can be generated onchain using {Strings-toChecksumHexString}.
1622
*/
1723
library CAIP10 {
1824
using Strings for address;

contracts/utils/CAIP2.sol

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ import {Strings} from "./Strings.sol";
1212
* chain_id: namespace + ":" + reference
1313
* namespace: [-a-z0-9]{3,8}
1414
* reference: [-_a-zA-Z0-9]{1,32}
15+
*
16+
* WARNING: In some cases, multiple CAIP-2 identifiers may all be valid representation of a single chain.
17+
* For EVM chains, it is recommended to use `eip155:xxx` as the canonical representation (where `xxx` is
18+
* the EIP-155 chain id). Consider the possible ambiguity when processing CAIP-2 identifiers or when using them
19+
* in the context of hashes.
1520
*/
1621
library CAIP2 {
1722
using Strings for uint256;

0 commit comments

Comments
 (0)