@metamask/utils 11.4.1 → 11.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +23 -1
- package/dist/caip-types.cjs.map +1 -1
- package/dist/caip-types.d.cts +8 -0
- package/dist/caip-types.d.cts.map +1 -1
- package/dist/caip-types.d.mts +8 -0
- package/dist/caip-types.d.mts.map +1 -1
- package/dist/caip-types.mjs.map +1 -1
- package/dist/hex.cjs +67 -28
- package/dist/hex.cjs.map +1 -1
- package/dist/hex.d.cts +40 -10
- package/dist/hex.d.cts.map +1 -1
- package/dist/hex.d.mts +40 -10
- package/dist/hex.d.mts.map +1 -1
- package/dist/hex.mjs +63 -22
- package/dist/hex.mjs.map +1 -1
- package/dist/index.cjs +3 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,26 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [11.5.0]
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- Add `KnownCaipNamespacedChainId` type as narrower subtype of `CaipChainId` ([#258](https://github.com/MetaMask/utils/pull/258))
|
|
15
|
+
|
|
16
|
+
### Changed
|
|
17
|
+
|
|
18
|
+
- Add `lodash` and `@types/lodash` as dependencies ([#253](https://github.com/MetaMask/utils/pull/253), [#257](https://github.com/MetaMask/utils/pull/257))
|
|
19
|
+
|
|
20
|
+
### Removed
|
|
21
|
+
|
|
22
|
+
- Remove `lodash.memoize` (dependency) and `@types/lodash.memoize` (devDependency) ([#253](https://github.com/MetaMask/utils/pull/253)).
|
|
23
|
+
|
|
24
|
+
## [11.4.2]
|
|
25
|
+
|
|
26
|
+
### Fixed
|
|
27
|
+
|
|
28
|
+
- Improve performance of `isValidChecksumAddress` and `isValidHexAddress` functions ([#248](https://github.com/MetaMask/utils/pull/248))
|
|
29
|
+
|
|
10
30
|
## [11.4.1]
|
|
11
31
|
|
|
12
32
|
### Fixed
|
|
@@ -421,7 +441,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
421
441
|
|
|
422
442
|
- Initial release
|
|
423
443
|
|
|
424
|
-
[Unreleased]: https://github.com/MetaMask/utils/compare/v11.
|
|
444
|
+
[Unreleased]: https://github.com/MetaMask/utils/compare/v11.5.0...HEAD
|
|
445
|
+
[11.5.0]: https://github.com/MetaMask/utils/compare/v11.4.2...v11.5.0
|
|
446
|
+
[11.4.2]: https://github.com/MetaMask/utils/compare/v11.4.1...v11.4.2
|
|
425
447
|
[11.4.1]: https://github.com/MetaMask/utils/compare/v11.4.0...v11.4.1
|
|
426
448
|
[11.4.0]: https://github.com/MetaMask/utils/compare/v11.3.0...v11.4.0
|
|
427
449
|
[11.3.0]: https://github.com/MetaMask/utils/compare/v11.2.0...v11.3.0
|
package/dist/caip-types.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"caip-types.cjs","sourceRoot":"","sources":["../src/caip-types.ts"],"names":[],"mappings":";;;AACA,uDAA2C;AAE3C,mDAA8C;AAEjC,QAAA,mBAAmB,GAC9B,mEAAmE,CAAC;AAEzD,QAAA,oBAAoB,GAAG,mBAAmB,CAAC;AAE3C,QAAA,oBAAoB,GAAG,wBAAwB,CAAC;AAEhD,QAAA,qBAAqB,GAChC,wHAAwH,CAAC;AAE9G,QAAA,0BAA0B,GAAG,0BAA0B,CAAC;AAExD,QAAA,0BAA0B,GAAG,mBAAmB,CAAC;AAEjD,QAAA,0BAA0B,GAAG,0BAA0B,CAAC;AAExD,QAAA,mBAAmB,GAAG,yBAAyB,CAAC;A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CD,sCAsCC","sourcesContent":["import type { Infer } from '@metamask/superstruct';\nimport { is } from '@metamask/superstruct';\n\nimport { definePattern } from './superstruct';\n\nexport const CAIP_CHAIN_ID_REGEX =\n /^(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-_a-zA-Z0-9]{1,32})$/u;\n\nexport const CAIP_NAMESPACE_REGEX = /^[-a-z0-9]{3,8}$/u;\n\nexport const CAIP_REFERENCE_REGEX = /^[-_a-zA-Z0-9]{1,32}$/u;\n\nexport const CAIP_ACCOUNT_ID_REGEX =\n /^(?<chainId>(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-_a-zA-Z0-9]{1,32})):(?<accountAddress>[-.%a-zA-Z0-9]{1,128})$/u;\n\nexport const CAIP_ACCOUNT_ADDRESS_REGEX = /^[-.%a-zA-Z0-9]{1,128}$/u;\n\nexport const CAIP_ASSET_NAMESPACE_REGEX = /^[-a-z0-9]{3,8}$/u;\n\nexport const CAIP_ASSET_REFERENCE_REGEX = /^[-.%a-zA-Z0-9]{1,128}$/u;\n\nexport const CAIP_TOKEN_ID_REGEX = /^[-.%a-zA-Z0-9]{1,78}$/u;\n\nexport const CAIP_ASSET_TYPE_REGEX =\n /^(?<chainId>(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-_a-zA-Z0-9]{1,32}))\\/(?<assetNamespace>[-a-z0-9]{3,8}):(?<assetReference>[-.%a-zA-Z0-9]{1,128})$/u;\n\nexport const CAIP_ASSET_ID_REGEX =\n /^(?<chainId>(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-_a-zA-Z0-9]{1,32}))\\/(?<assetNamespace>[-a-z0-9]{3,8}):(?<assetReference>[-.%a-zA-Z0-9]{1,128})\\/(?<tokenId>[-.%a-zA-Z0-9]{1,78})$/u;\n\nconst CAIP_ASSET_TYPE_OR_ID_REGEX =\n /^(?<chainId>(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-_a-zA-Z0-9]{1,32}))\\/(?<assetNamespace>[-a-z0-9]{3,8}):(?<assetReference>[-.%a-zA-Z0-9]{1,128})(\\/(?<tokenId>[-.%a-zA-Z0-9]{1,78}))?$/u;\n\n/**\n * A CAIP-2 chain ID, i.e., a human-readable namespace and reference.\n */\nexport const CaipChainIdStruct = definePattern<`${string}:${string}`>(\n 'CaipChainId',\n CAIP_CHAIN_ID_REGEX,\n);\nexport type CaipChainId = Infer<typeof CaipChainIdStruct>;\n\n/**\n * A CAIP-2 namespace, i.e., the first part of a CAIP chain ID.\n */\nexport const CaipNamespaceStruct = definePattern(\n 'CaipNamespace',\n CAIP_NAMESPACE_REGEX,\n);\nexport type CaipNamespace = Infer<typeof CaipNamespaceStruct>;\n\n/**\n * A CAIP-2 reference, i.e., the second part of a CAIP chain ID.\n */\nexport const CaipReferenceStruct = definePattern(\n 'CaipReference',\n CAIP_REFERENCE_REGEX,\n);\nexport type CaipReference = Infer<typeof CaipReferenceStruct>;\n\n/**\n * A CAIP-10 account ID, i.e., a human-readable namespace, reference, and account address.\n */\nexport const CaipAccountIdStruct =\n definePattern<`${string}:${string}:${string}`>(\n 'CaipAccountId',\n CAIP_ACCOUNT_ID_REGEX,\n );\nexport type CaipAccountId = Infer<typeof CaipAccountIdStruct>;\n\n/**\n * A CAIP-10 account address, i.e., the third part of the CAIP account ID.\n */\nexport const CaipAccountAddressStruct = definePattern(\n 'CaipAccountAddress',\n CAIP_ACCOUNT_ADDRESS_REGEX,\n);\nexport type CaipAccountAddress = Infer<typeof CaipAccountAddressStruct>;\n\n/**\n * A CAIP-19 asset namespace, i.e., a namespace domain of an asset.\n */\nexport const CaipAssetNamespaceStruct = definePattern(\n 'CaipAssetNamespace',\n CAIP_ASSET_NAMESPACE_REGEX,\n);\nexport type CaipAssetNamespace = Infer<typeof CaipAssetNamespaceStruct>;\n\n/**\n * A CAIP-19 asset reference, i.e., an identifier for an asset within a given namespace.\n */\nexport const CaipAssetReferenceStruct = definePattern(\n 'CaipAssetReference',\n CAIP_ASSET_REFERENCE_REGEX,\n);\nexport type CaipAssetReference = Infer<typeof CaipAssetReferenceStruct>;\n\n/**\n * A CAIP-19 asset token ID, i.e., a unique identifier for an addressable asset of a given type\n */\nexport const CaipTokenIdStruct = definePattern(\n 'CaipTokenId',\n CAIP_TOKEN_ID_REGEX,\n);\nexport type CaipTokenId = Infer<typeof CaipTokenIdStruct>;\n\n/**\n * A CAIP-19 asset type identifier, i.e., a human-readable type of asset identifier.\n */\nexport const CaipAssetTypeStruct =\n definePattern<`${string}:${string}/${string}:${string}`>(\n 'CaipAssetType',\n CAIP_ASSET_TYPE_REGEX,\n );\nexport type CaipAssetType = Infer<typeof CaipAssetTypeStruct>;\n\n/**\n * A CAIP-19 asset ID identifier, i.e., a human-readable type of asset ID.\n */\nexport const CaipAssetIdStruct =\n definePattern<`${string}:${string}/${string}:${string}/${string}`>(\n 'CaipAssetId',\n CAIP_ASSET_ID_REGEX,\n );\nexport type CaipAssetId = Infer<typeof CaipAssetIdStruct>;\n\n/**\n * A CAIP-19 asset type or asset ID identifier, i.e., a human-readable type of asset identifier.\n */\nexport const CaipAssetTypeOrIdStruct = definePattern<\n CaipAssetType | CaipAssetId\n>('CaipAssetTypeOrId', CAIP_ASSET_TYPE_OR_ID_REGEX);\nexport type CaipAssetTypeOrId = Infer<typeof CaipAssetTypeOrIdStruct>;\n\n/** Known CAIP namespaces. */\nexport enum KnownCaipNamespace {\n /** BIP-122 (Bitcoin) compatible chains. */\n Bip122 = 'bip122',\n /** Solana compatible chains */\n Solana = 'solana',\n /** EIP-155 compatible chains. */\n Eip155 = 'eip155',\n Wallet = 'wallet',\n}\n\n/**\n * Check if the given value is a {@link CaipChainId}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipChainId}.\n */\nexport function isCaipChainId(value: unknown): value is CaipChainId {\n return is(value, CaipChainIdStruct);\n}\n\n/**\n * Check if the given value is a {@link CaipNamespace}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipNamespace}.\n */\nexport function isCaipNamespace(value: unknown): value is CaipNamespace {\n return is(value, CaipNamespaceStruct);\n}\n\n/**\n * Check if the given value is a {@link CaipReference}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipReference}.\n */\nexport function isCaipReference(value: unknown): value is CaipReference {\n return is(value, CaipReferenceStruct);\n}\n\n/**\n * Check if the given value is a {@link CaipAccountId}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipAccountId}.\n */\nexport function isCaipAccountId(value: unknown): value is CaipAccountId {\n return is(value, CaipAccountIdStruct);\n}\n\n/**\n * Check if a value is a {@link CaipAccountAddress}.\n *\n * @param value - The value to validate.\n * @returns True if the value is a valid {@link CaipAccountAddress}.\n */\nexport function isCaipAccountAddress(\n value: unknown,\n): value is CaipAccountAddress {\n return is(value, CaipAccountAddressStruct);\n}\n\n/**\n * Check if the given value is a {@link CaipAssetNamespace}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipAssetNamespace}.\n */\nexport function isCaipAssetNamespace(\n value: unknown,\n): value is CaipAssetNamespace {\n return is(value, CaipAssetNamespaceStruct);\n}\n\n/**\n * Check if the given value is a {@link CaipAssetReference}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipAssetReference}.\n */\nexport function isCaipAssetReference(\n value: unknown,\n): value is CaipAssetReference {\n return is(value, CaipAssetReferenceStruct);\n}\n\n/**\n * Check if the given value is a {@link CaipTokenId}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipTokenId}.\n */\nexport function isCaipTokenId(value: unknown): value is CaipTokenId {\n return is(value, CaipTokenIdStruct);\n}\n\n/**\n * Check if the given value is a {@link CaipAssetType}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipAssetType}.\n */\nexport function isCaipAssetType(value: unknown): value is CaipAssetType {\n return is(value, CaipAssetTypeStruct);\n}\n\n/**\n * Check if the given value is a {@link CaipAssetId}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipAssetId}.\n */\nexport function isCaipAssetId(value: unknown): value is CaipAssetId {\n return is(value, CaipAssetIdStruct);\n}\n\n/**\n * Parse a CAIP-2 chain ID to an object containing the namespace and reference.\n * This validates the CAIP-2 chain ID before parsing it.\n *\n * @param caipChainId - The CAIP-2 chain ID to validate and parse.\n * @returns The parsed CAIP-2 chain ID.\n */\nexport function parseCaipChainId(caipChainId: CaipChainId): {\n namespace: CaipNamespace;\n reference: CaipReference;\n} {\n const match = CAIP_CHAIN_ID_REGEX.exec(caipChainId);\n if (!match?.groups) {\n throw new Error('Invalid CAIP chain ID.');\n }\n\n return {\n namespace: match.groups.namespace as CaipNamespace,\n reference: match.groups.reference as CaipReference,\n };\n}\n\n/**\n * Parse an CAIP-10 account ID to an object containing the chain ID, parsed chain ID, and account address.\n * This validates the CAIP-10 account ID before parsing it.\n *\n * @param caipAccountId - The CAIP-10 account ID to validate and parse.\n * @returns The parsed CAIP-10 account ID.\n */\nexport function parseCaipAccountId(caipAccountId: CaipAccountId): {\n address: CaipAccountAddress;\n chainId: CaipChainId;\n chain: { namespace: CaipNamespace; reference: CaipReference };\n} {\n const match = CAIP_ACCOUNT_ID_REGEX.exec(caipAccountId);\n if (!match?.groups) {\n throw new Error('Invalid CAIP account ID.');\n }\n\n return {\n address: match.groups.accountAddress as CaipAccountAddress,\n chainId: match.groups.chainId as CaipChainId,\n chain: {\n namespace: match.groups.namespace as CaipNamespace,\n reference: match.groups.reference as CaipReference,\n },\n };\n}\n\n/**\n * Parse a CAIP-19 asset type to an object containing the chain ID, parsed chain ID,\n * asset namespace, and asset reference\n *\n * This validates the CAIP-19 asset type before parsing it.\n *\n * @param caipAssetType - The CAIP-19 asset type to validate and parse.\n * @returns The parsed CAIP-19 asset type.\n */\nexport function parseCaipAssetType(caipAssetType: CaipAssetType): {\n assetNamespace: CaipAssetNamespace;\n assetReference: CaipAssetReference;\n chainId: CaipChainId;\n chain: { namespace: CaipNamespace; reference: CaipReference };\n} {\n const match = CAIP_ASSET_TYPE_REGEX.exec(caipAssetType);\n if (!match?.groups) {\n throw new Error('Invalid CAIP asset type.');\n }\n\n return {\n assetNamespace: match.groups.assetNamespace as CaipAssetNamespace,\n assetReference: match.groups.assetReference as CaipAssetReference,\n chainId: match.groups.chainId as CaipChainId,\n chain: {\n namespace: match.groups.namespace as CaipNamespace,\n reference: match.groups.reference as CaipReference,\n },\n };\n}\n\n/**\n * Parse a CAIP-19 asset ID to an object containing the chain ID, parsed chain ID,\n * asset namespace, asset reference, and token ID.\n *\n * This validates the CAIP-19 asset ID before parsing it.\n *\n * @param caipAssetId - The CAIP-19 asset ID to validate and parse.\n * @returns The parsed CAIP-19 asset ID.\n */\nexport function parseCaipAssetId(caipAssetId: CaipAssetId): {\n assetNamespace: CaipAssetNamespace;\n assetReference: CaipAssetReference;\n tokenId: CaipTokenId;\n chainId: CaipChainId;\n chain: { namespace: CaipNamespace; reference: CaipReference };\n} {\n const match = CAIP_ASSET_ID_REGEX.exec(caipAssetId);\n if (!match?.groups) {\n throw new Error('Invalid CAIP asset ID.');\n }\n\n return {\n assetNamespace: match.groups.assetNamespace as CaipAssetNamespace,\n assetReference: match.groups.assetReference as CaipAssetReference,\n tokenId: match.groups.tokenId as CaipTokenId,\n chainId: match.groups.chainId as CaipChainId,\n chain: {\n namespace: match.groups.namespace as CaipNamespace,\n reference: match.groups.reference as CaipReference,\n },\n };\n}\n\n/**\n * Chain ID as defined per the CAIP-2\n * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-2.md}.\n *\n * It defines a way to uniquely identify any blockchain in a human-readable\n * way.\n *\n * @param namespace - The standard (ecosystem) of similar blockchains.\n * @param reference - Identify of a blockchain within a given namespace.\n * @throws {@link Error}\n * This exception is thrown if the inputs does not comply with the CAIP-2\n * syntax specification\n * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-2.md#syntax}.\n * @returns A CAIP chain ID.\n */\nexport function toCaipChainId(\n namespace: CaipNamespace,\n reference: CaipReference,\n): CaipChainId {\n if (!isCaipNamespace(namespace)) {\n throw new Error(\n `Invalid \"namespace\", must match: ${CAIP_NAMESPACE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipReference(reference)) {\n throw new Error(\n `Invalid \"reference\", must match: ${CAIP_REFERENCE_REGEX.toString()}`,\n );\n }\n\n return `${namespace}:${reference}`;\n}\n\n/**\n * Account ID as defined per the CAIP-10\n * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-10.md}.\n *\n * It defines a way to uniquely identify any blockchain account in a human-readable\n * way.\n *\n * @param namespace - The standard (ecosystem) of similar blockchains.\n * @param reference - Identity of a blockchain within a given namespace.\n * @param accountAddress - The address of the blockchain account.\n * @throws {@link Error}\n * This exception is thrown if the inputs do not comply with the CAIP-10\n * syntax specification\n * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-10.md#syntax}.\n * @returns A CAIP account ID.\n */\nexport function toCaipAccountId(\n namespace: CaipNamespace,\n reference: CaipReference,\n accountAddress: CaipAccountAddress,\n): CaipAccountId {\n if (!isCaipNamespace(namespace)) {\n throw new Error(\n `Invalid \"namespace\", must match: ${CAIP_NAMESPACE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipReference(reference)) {\n throw new Error(\n `Invalid \"reference\", must match: ${CAIP_REFERENCE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipAccountAddress(accountAddress)) {\n throw new Error(\n `Invalid \"accountAddress\", must match: ${CAIP_ACCOUNT_ADDRESS_REGEX.toString()}`,\n );\n }\n\n return `${namespace}:${reference}:${accountAddress}`;\n}\n\n/**\n * Asset Type as defined per the CAIP-19\n * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-19.md}.\n *\n * It defines a way to uniquely identify any blockchain asset in a human-readable\n * way.\n *\n * @param namespace - The standard (ecosystem) of similar blockchains.\n * @param reference - Identity of a blockchain within a given namespace.\n * @param assetNamespace - The namespace domain of an asset.\n * @param assetReference - The identity of an asset within a given namespace.\n * @throws {@link Error}\n * This exception is thrown if the inputs do not comply with the CAIP-19\n * syntax specification\n * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-19.md#syntax}.\n * @returns A CAIP asset type.\n */\nexport function toCaipAssetType(\n namespace: CaipNamespace,\n reference: CaipReference,\n assetNamespace: CaipAssetNamespace,\n assetReference: CaipAssetReference,\n): CaipAssetType {\n if (!isCaipNamespace(namespace)) {\n throw new Error(\n `Invalid \"namespace\", must match: ${CAIP_NAMESPACE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipReference(reference)) {\n throw new Error(\n `Invalid \"reference\", must match: ${CAIP_REFERENCE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipAssetNamespace(assetNamespace)) {\n throw new Error(\n `Invalid \"assetNamespace\", must match: ${CAIP_ASSET_NAMESPACE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipAssetReference(assetReference)) {\n throw new Error(\n `Invalid \"assetReference\", must match: ${CAIP_ASSET_REFERENCE_REGEX.toString()}`,\n );\n }\n\n return `${namespace}:${reference}/${assetNamespace}:${assetReference}`;\n}\n\n/**\n * Asset ID as defined per the CAIP-19\n * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-19.md}.\n *\n * It defines a way to uniquely identify any blockchain asset in a human-readable\n * way.\n *\n * @param namespace - The standard (ecosystem) of similar blockchains.\n * @param reference - Identity of a blockchain within a given namespace.\n * @param assetNamespace - The namespace domain of an asset.\n * @param assetReference - The identity of an asset within a given namespace.\n * @param tokenId - The unique identifier for an addressable asset of a given type.\n * @throws {@link Error}\n * This exception is thrown if the inputs do not comply with the CAIP-19\n * syntax specification\n * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-19.md#syntax}.\n * @returns A CAIP asset ID.\n */\nexport function toCaipAssetId(\n namespace: CaipNamespace,\n reference: CaipReference,\n assetNamespace: CaipAssetNamespace,\n assetReference: CaipAssetReference,\n tokenId: CaipTokenId,\n): CaipAssetId {\n if (!isCaipNamespace(namespace)) {\n throw new Error(\n `Invalid \"namespace\", must match: ${CAIP_NAMESPACE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipReference(reference)) {\n throw new Error(\n `Invalid \"reference\", must match: ${CAIP_REFERENCE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipAssetNamespace(assetNamespace)) {\n throw new Error(\n `Invalid \"assetNamespace\", must match: ${CAIP_ASSET_NAMESPACE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipAssetReference(assetReference)) {\n throw new Error(\n `Invalid \"assetReference\", must match: ${CAIP_ASSET_REFERENCE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipTokenId(tokenId)) {\n throw new Error(\n `Invalid \"tokenId\", must match: ${CAIP_TOKEN_ID_REGEX.toString()}`,\n );\n }\n\n return `${namespace}:${reference}/${assetNamespace}:${assetReference}/${tokenId}`;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"caip-types.cjs","sourceRoot":"","sources":["../src/caip-types.ts"],"names":[],"mappings":";;;AACA,uDAA2C;AAE3C,mDAA8C;AAEjC,QAAA,mBAAmB,GAC9B,mEAAmE,CAAC;AAEzD,QAAA,oBAAoB,GAAG,mBAAmB,CAAC;AAE3C,QAAA,oBAAoB,GAAG,wBAAwB,CAAC;AAEhD,QAAA,qBAAqB,GAChC,wHAAwH,CAAC;AAE9G,QAAA,0BAA0B,GAAG,0BAA0B,CAAC;AAExD,QAAA,0BAA0B,GAAG,mBAAmB,CAAC;AAEjD,QAAA,0BAA0B,GAAG,0BAA0B,CAAC;AAExD,QAAA,mBAAmB,GAAG,yBAAyB,CAAC;AAEhD,QAAA,qBAAqB,GAChC,2JAA2J,CAAC;AAEjJ,QAAA,mBAAmB,GAC9B,6LAA6L,CAAC;AAEhM,MAAM,2BAA2B,GAC/B,gMAAgM,CAAC;AAEnM;;GAEG;AACU,QAAA,iBAAiB,GAAG,IAAA,2BAAa,EAC5C,aAAa,EACb,2BAAmB,CACpB,CAAC;AAGF;;GAEG;AACU,QAAA,mBAAmB,GAAG,IAAA,2BA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,IAAI,cAAc,IAAI,cAAc,EAAE,CAAC;AACzE,CAAC;AA/BD,0CA+BC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,SAAgB,aAAa,CAC3B,SAAwB,EACxB,SAAwB,EACxB,cAAkC,EAClC,cAAkC,EAClC,OAAoB;IAEpB,IAAI,CAAC,eAAe,CAAC,SAAS,CAAC,EAAE;QAC/B,MAAM,IAAI,KAAK,CACb,oCAAoC,4BAAoB,CAAC,QAAQ,EAAE,EAAE,CACtE,CAAC;KACH;IAED,IAAI,CAAC,eAAe,CAAC,SAAS,CAAC,EAAE;QAC/B,MAAM,IAAI,KAAK,CACb,oCAAoC,4BAAoB,CAAC,QAAQ,EAAE,EAAE,CACtE,CAAC;KACH;IAED,IAAI,CAAC,oBAAoB,CAAC,cAAc,CAAC,EAAE;QACzC,MAAM,IAAI,KAAK,CACb,yCAAyC,kCAA0B,CAAC,QAAQ,EAAE,EAAE,CACjF,CAAC;KACH;IAED,IAAI,CAAC,oBAAoB,CAAC,cAAc,CAAC,EAAE;QACzC,MAAM,IAAI,KAAK,CACb,yCAAyC,kCAA0B,CAAC,QAAQ,EAAE,EAAE,CACjF,CAAC;KACH;IAED,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,EAAE;QAC3B,MAAM,IAAI,KAAK,CACb,kCAAkC,2BAAmB,CAAC,QAAQ,EAAE,EAAE,CACnE,CAAC;KACH;IAED,OAAO,GAAG,SAAS,IAAI,SAAS,IAAI,cAAc,IAAI,cAAc,IAAI,OAAO,EAAE,CAAC;AACpF,CAAC;AAtCD,sCAsCC","sourcesContent":["import type { Infer } from '@metamask/superstruct';\nimport { is } from '@metamask/superstruct';\n\nimport { definePattern } from './superstruct';\n\nexport const CAIP_CHAIN_ID_REGEX =\n /^(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-_a-zA-Z0-9]{1,32})$/u;\n\nexport const CAIP_NAMESPACE_REGEX = /^[-a-z0-9]{3,8}$/u;\n\nexport const CAIP_REFERENCE_REGEX = /^[-_a-zA-Z0-9]{1,32}$/u;\n\nexport const CAIP_ACCOUNT_ID_REGEX =\n /^(?<chainId>(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-_a-zA-Z0-9]{1,32})):(?<accountAddress>[-.%a-zA-Z0-9]{1,128})$/u;\n\nexport const CAIP_ACCOUNT_ADDRESS_REGEX = /^[-.%a-zA-Z0-9]{1,128}$/u;\n\nexport const CAIP_ASSET_NAMESPACE_REGEX = /^[-a-z0-9]{3,8}$/u;\n\nexport const CAIP_ASSET_REFERENCE_REGEX = /^[-.%a-zA-Z0-9]{1,128}$/u;\n\nexport const CAIP_TOKEN_ID_REGEX = /^[-.%a-zA-Z0-9]{1,78}$/u;\n\nexport const CAIP_ASSET_TYPE_REGEX =\n /^(?<chainId>(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-_a-zA-Z0-9]{1,32}))\\/(?<assetNamespace>[-a-z0-9]{3,8}):(?<assetReference>[-.%a-zA-Z0-9]{1,128})$/u;\n\nexport const CAIP_ASSET_ID_REGEX =\n /^(?<chainId>(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-_a-zA-Z0-9]{1,32}))\\/(?<assetNamespace>[-a-z0-9]{3,8}):(?<assetReference>[-.%a-zA-Z0-9]{1,128})\\/(?<tokenId>[-.%a-zA-Z0-9]{1,78})$/u;\n\nconst CAIP_ASSET_TYPE_OR_ID_REGEX =\n /^(?<chainId>(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-_a-zA-Z0-9]{1,32}))\\/(?<assetNamespace>[-a-z0-9]{3,8}):(?<assetReference>[-.%a-zA-Z0-9]{1,128})(\\/(?<tokenId>[-.%a-zA-Z0-9]{1,78}))?$/u;\n\n/**\n * A CAIP-2 chain ID, i.e., a human-readable namespace and reference.\n */\nexport const CaipChainIdStruct = definePattern<`${string}:${string}`>(\n 'CaipChainId',\n CAIP_CHAIN_ID_REGEX,\n);\nexport type CaipChainId = Infer<typeof CaipChainIdStruct>;\n\n/**\n * A CAIP-2 namespace, i.e., the first part of a CAIP chain ID.\n */\nexport const CaipNamespaceStruct = definePattern(\n 'CaipNamespace',\n CAIP_NAMESPACE_REGEX,\n);\nexport type CaipNamespace = Infer<typeof CaipNamespaceStruct>;\n\n/**\n * A CAIP-2 reference, i.e., the second part of a CAIP chain ID.\n */\nexport const CaipReferenceStruct = definePattern(\n 'CaipReference',\n CAIP_REFERENCE_REGEX,\n);\nexport type CaipReference = Infer<typeof CaipReferenceStruct>;\n\n/**\n * A CAIP-10 account ID, i.e., a human-readable namespace, reference, and account address.\n */\nexport const CaipAccountIdStruct =\n definePattern<`${string}:${string}:${string}`>(\n 'CaipAccountId',\n CAIP_ACCOUNT_ID_REGEX,\n );\nexport type CaipAccountId = Infer<typeof CaipAccountIdStruct>;\n\n/**\n * A CAIP-10 account address, i.e., the third part of the CAIP account ID.\n */\nexport const CaipAccountAddressStruct = definePattern(\n 'CaipAccountAddress',\n CAIP_ACCOUNT_ADDRESS_REGEX,\n);\nexport type CaipAccountAddress = Infer<typeof CaipAccountAddressStruct>;\n\n/**\n * A CAIP-19 asset namespace, i.e., a namespace domain of an asset.\n */\nexport const CaipAssetNamespaceStruct = definePattern(\n 'CaipAssetNamespace',\n CAIP_ASSET_NAMESPACE_REGEX,\n);\nexport type CaipAssetNamespace = Infer<typeof CaipAssetNamespaceStruct>;\n\n/**\n * A CAIP-19 asset reference, i.e., an identifier for an asset within a given namespace.\n */\nexport const CaipAssetReferenceStruct = definePattern(\n 'CaipAssetReference',\n CAIP_ASSET_REFERENCE_REGEX,\n);\nexport type CaipAssetReference = Infer<typeof CaipAssetReferenceStruct>;\n\n/**\n * A CAIP-19 asset token ID, i.e., a unique identifier for an addressable asset of a given type\n */\nexport const CaipTokenIdStruct = definePattern(\n 'CaipTokenId',\n CAIP_TOKEN_ID_REGEX,\n);\nexport type CaipTokenId = Infer<typeof CaipTokenIdStruct>;\n\n/**\n * A CAIP-19 asset type identifier, i.e., a human-readable type of asset identifier.\n */\nexport const CaipAssetTypeStruct =\n definePattern<`${string}:${string}/${string}:${string}`>(\n 'CaipAssetType',\n CAIP_ASSET_TYPE_REGEX,\n );\nexport type CaipAssetType = Infer<typeof CaipAssetTypeStruct>;\n\n/**\n * A CAIP-19 asset ID identifier, i.e., a human-readable type of asset ID.\n */\nexport const CaipAssetIdStruct =\n definePattern<`${string}:${string}/${string}:${string}/${string}`>(\n 'CaipAssetId',\n CAIP_ASSET_ID_REGEX,\n );\nexport type CaipAssetId = Infer<typeof CaipAssetIdStruct>;\n\n/**\n * A CAIP-19 asset type or asset ID identifier, i.e., a human-readable type of asset identifier.\n */\nexport const CaipAssetTypeOrIdStruct = definePattern<\n CaipAssetType | CaipAssetId\n>('CaipAssetTypeOrId', CAIP_ASSET_TYPE_OR_ID_REGEX);\nexport type CaipAssetTypeOrId = Infer<typeof CaipAssetTypeOrIdStruct>;\n\n/** Known CAIP namespaces. */\nexport enum KnownCaipNamespace {\n /** BIP-122 (Bitcoin) compatible chains. */\n Bip122 = 'bip122',\n /** Solana compatible chains */\n Solana = 'solana',\n /** EIP-155 compatible chains. */\n Eip155 = 'eip155',\n Wallet = 'wallet',\n}\n\n/**\n * A CAIP-2 chain ID that is guaranteed to have a known CAIP namespace\n * (@see {@link KnownCaipNamespace}).\n *\n * This is a narrower, more type-safe alternative to {@link CaipChainId} for use cases\n * where the chain namespace must be one of the known standards.\n */\nexport type KnownCaipNamespacedChainId = `${KnownCaipNamespace}:${string}`;\n\n/**\n * Check if the given value is a {@link CaipChainId}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipChainId}.\n */\nexport function isCaipChainId(value: unknown): value is CaipChainId {\n return is(value, CaipChainIdStruct);\n}\n\n/**\n * Check if the given value is a {@link CaipNamespace}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipNamespace}.\n */\nexport function isCaipNamespace(value: unknown): value is CaipNamespace {\n return is(value, CaipNamespaceStruct);\n}\n\n/**\n * Check if the given value is a {@link CaipReference}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipReference}.\n */\nexport function isCaipReference(value: unknown): value is CaipReference {\n return is(value, CaipReferenceStruct);\n}\n\n/**\n * Check if the given value is a {@link CaipAccountId}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipAccountId}.\n */\nexport function isCaipAccountId(value: unknown): value is CaipAccountId {\n return is(value, CaipAccountIdStruct);\n}\n\n/**\n * Check if a value is a {@link CaipAccountAddress}.\n *\n * @param value - The value to validate.\n * @returns True if the value is a valid {@link CaipAccountAddress}.\n */\nexport function isCaipAccountAddress(\n value: unknown,\n): value is CaipAccountAddress {\n return is(value, CaipAccountAddressStruct);\n}\n\n/**\n * Check if the given value is a {@link CaipAssetNamespace}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipAssetNamespace}.\n */\nexport function isCaipAssetNamespace(\n value: unknown,\n): value is CaipAssetNamespace {\n return is(value, CaipAssetNamespaceStruct);\n}\n\n/**\n * Check if the given value is a {@link CaipAssetReference}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipAssetReference}.\n */\nexport function isCaipAssetReference(\n value: unknown,\n): value is CaipAssetReference {\n return is(value, CaipAssetReferenceStruct);\n}\n\n/**\n * Check if the given value is a {@link CaipTokenId}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipTokenId}.\n */\nexport function isCaipTokenId(value: unknown): value is CaipTokenId {\n return is(value, CaipTokenIdStruct);\n}\n\n/**\n * Check if the given value is a {@link CaipAssetType}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipAssetType}.\n */\nexport function isCaipAssetType(value: unknown): value is CaipAssetType {\n return is(value, CaipAssetTypeStruct);\n}\n\n/**\n * Check if the given value is a {@link CaipAssetId}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipAssetId}.\n */\nexport function isCaipAssetId(value: unknown): value is CaipAssetId {\n return is(value, CaipAssetIdStruct);\n}\n\n/**\n * Parse a CAIP-2 chain ID to an object containing the namespace and reference.\n * This validates the CAIP-2 chain ID before parsing it.\n *\n * @param caipChainId - The CAIP-2 chain ID to validate and parse.\n * @returns The parsed CAIP-2 chain ID.\n */\nexport function parseCaipChainId(caipChainId: CaipChainId): {\n namespace: CaipNamespace;\n reference: CaipReference;\n} {\n const match = CAIP_CHAIN_ID_REGEX.exec(caipChainId);\n if (!match?.groups) {\n throw new Error('Invalid CAIP chain ID.');\n }\n\n return {\n namespace: match.groups.namespace as CaipNamespace,\n reference: match.groups.reference as CaipReference,\n };\n}\n\n/**\n * Parse an CAIP-10 account ID to an object containing the chain ID, parsed chain ID, and account address.\n * This validates the CAIP-10 account ID before parsing it.\n *\n * @param caipAccountId - The CAIP-10 account ID to validate and parse.\n * @returns The parsed CAIP-10 account ID.\n */\nexport function parseCaipAccountId(caipAccountId: CaipAccountId): {\n address: CaipAccountAddress;\n chainId: CaipChainId;\n chain: { namespace: CaipNamespace; reference: CaipReference };\n} {\n const match = CAIP_ACCOUNT_ID_REGEX.exec(caipAccountId);\n if (!match?.groups) {\n throw new Error('Invalid CAIP account ID.');\n }\n\n return {\n address: match.groups.accountAddress as CaipAccountAddress,\n chainId: match.groups.chainId as CaipChainId,\n chain: {\n namespace: match.groups.namespace as CaipNamespace,\n reference: match.groups.reference as CaipReference,\n },\n };\n}\n\n/**\n * Parse a CAIP-19 asset type to an object containing the chain ID, parsed chain ID,\n * asset namespace, and asset reference\n *\n * This validates the CAIP-19 asset type before parsing it.\n *\n * @param caipAssetType - The CAIP-19 asset type to validate and parse.\n * @returns The parsed CAIP-19 asset type.\n */\nexport function parseCaipAssetType(caipAssetType: CaipAssetType): {\n assetNamespace: CaipAssetNamespace;\n assetReference: CaipAssetReference;\n chainId: CaipChainId;\n chain: { namespace: CaipNamespace; reference: CaipReference };\n} {\n const match = CAIP_ASSET_TYPE_REGEX.exec(caipAssetType);\n if (!match?.groups) {\n throw new Error('Invalid CAIP asset type.');\n }\n\n return {\n assetNamespace: match.groups.assetNamespace as CaipAssetNamespace,\n assetReference: match.groups.assetReference as CaipAssetReference,\n chainId: match.groups.chainId as CaipChainId,\n chain: {\n namespace: match.groups.namespace as CaipNamespace,\n reference: match.groups.reference as CaipReference,\n },\n };\n}\n\n/**\n * Parse a CAIP-19 asset ID to an object containing the chain ID, parsed chain ID,\n * asset namespace, asset reference, and token ID.\n *\n * This validates the CAIP-19 asset ID before parsing it.\n *\n * @param caipAssetId - The CAIP-19 asset ID to validate and parse.\n * @returns The parsed CAIP-19 asset ID.\n */\nexport function parseCaipAssetId(caipAssetId: CaipAssetId): {\n assetNamespace: CaipAssetNamespace;\n assetReference: CaipAssetReference;\n tokenId: CaipTokenId;\n chainId: CaipChainId;\n chain: { namespace: CaipNamespace; reference: CaipReference };\n} {\n const match = CAIP_ASSET_ID_REGEX.exec(caipAssetId);\n if (!match?.groups) {\n throw new Error('Invalid CAIP asset ID.');\n }\n\n return {\n assetNamespace: match.groups.assetNamespace as CaipAssetNamespace,\n assetReference: match.groups.assetReference as CaipAssetReference,\n tokenId: match.groups.tokenId as CaipTokenId,\n chainId: match.groups.chainId as CaipChainId,\n chain: {\n namespace: match.groups.namespace as CaipNamespace,\n reference: match.groups.reference as CaipReference,\n },\n };\n}\n\n/**\n * Chain ID as defined per the CAIP-2\n * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-2.md}.\n *\n * It defines a way to uniquely identify any blockchain in a human-readable\n * way.\n *\n * @param namespace - The standard (ecosystem) of similar blockchains.\n * @param reference - Identify of a blockchain within a given namespace.\n * @throws {@link Error}\n * This exception is thrown if the inputs does not comply with the CAIP-2\n * syntax specification\n * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-2.md#syntax}.\n * @returns A CAIP chain ID.\n */\nexport function toCaipChainId(\n namespace: CaipNamespace,\n reference: CaipReference,\n): CaipChainId {\n if (!isCaipNamespace(namespace)) {\n throw new Error(\n `Invalid \"namespace\", must match: ${CAIP_NAMESPACE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipReference(reference)) {\n throw new Error(\n `Invalid \"reference\", must match: ${CAIP_REFERENCE_REGEX.toString()}`,\n );\n }\n\n return `${namespace}:${reference}`;\n}\n\n/**\n * Account ID as defined per the CAIP-10\n * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-10.md}.\n *\n * It defines a way to uniquely identify any blockchain account in a human-readable\n * way.\n *\n * @param namespace - The standard (ecosystem) of similar blockchains.\n * @param reference - Identity of a blockchain within a given namespace.\n * @param accountAddress - The address of the blockchain account.\n * @throws {@link Error}\n * This exception is thrown if the inputs do not comply with the CAIP-10\n * syntax specification\n * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-10.md#syntax}.\n * @returns A CAIP account ID.\n */\nexport function toCaipAccountId(\n namespace: CaipNamespace,\n reference: CaipReference,\n accountAddress: CaipAccountAddress,\n): CaipAccountId {\n if (!isCaipNamespace(namespace)) {\n throw new Error(\n `Invalid \"namespace\", must match: ${CAIP_NAMESPACE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipReference(reference)) {\n throw new Error(\n `Invalid \"reference\", must match: ${CAIP_REFERENCE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipAccountAddress(accountAddress)) {\n throw new Error(\n `Invalid \"accountAddress\", must match: ${CAIP_ACCOUNT_ADDRESS_REGEX.toString()}`,\n );\n }\n\n return `${namespace}:${reference}:${accountAddress}`;\n}\n\n/**\n * Asset Type as defined per the CAIP-19\n * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-19.md}.\n *\n * It defines a way to uniquely identify any blockchain asset in a human-readable\n * way.\n *\n * @param namespace - The standard (ecosystem) of similar blockchains.\n * @param reference - Identity of a blockchain within a given namespace.\n * @param assetNamespace - The namespace domain of an asset.\n * @param assetReference - The identity of an asset within a given namespace.\n * @throws {@link Error}\n * This exception is thrown if the inputs do not comply with the CAIP-19\n * syntax specification\n * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-19.md#syntax}.\n * @returns A CAIP asset type.\n */\nexport function toCaipAssetType(\n namespace: CaipNamespace,\n reference: CaipReference,\n assetNamespace: CaipAssetNamespace,\n assetReference: CaipAssetReference,\n): CaipAssetType {\n if (!isCaipNamespace(namespace)) {\n throw new Error(\n `Invalid \"namespace\", must match: ${CAIP_NAMESPACE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipReference(reference)) {\n throw new Error(\n `Invalid \"reference\", must match: ${CAIP_REFERENCE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipAssetNamespace(assetNamespace)) {\n throw new Error(\n `Invalid \"assetNamespace\", must match: ${CAIP_ASSET_NAMESPACE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipAssetReference(assetReference)) {\n throw new Error(\n `Invalid \"assetReference\", must match: ${CAIP_ASSET_REFERENCE_REGEX.toString()}`,\n );\n }\n\n return `${namespace}:${reference}/${assetNamespace}:${assetReference}`;\n}\n\n/**\n * Asset ID as defined per the CAIP-19\n * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-19.md}.\n *\n * It defines a way to uniquely identify any blockchain asset in a human-readable\n * way.\n *\n * @param namespace - The standard (ecosystem) of similar blockchains.\n * @param reference - Identity of a blockchain within a given namespace.\n * @param assetNamespace - The namespace domain of an asset.\n * @param assetReference - The identity of an asset within a given namespace.\n * @param tokenId - The unique identifier for an addressable asset of a given type.\n * @throws {@link Error}\n * This exception is thrown if the inputs do not comply with the CAIP-19\n * syntax specification\n * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-19.md#syntax}.\n * @returns A CAIP asset ID.\n */\nexport function toCaipAssetId(\n namespace: CaipNamespace,\n reference: CaipReference,\n assetNamespace: CaipAssetNamespace,\n assetReference: CaipAssetReference,\n tokenId: CaipTokenId,\n): CaipAssetId {\n if (!isCaipNamespace(namespace)) {\n throw new Error(\n `Invalid \"namespace\", must match: ${CAIP_NAMESPACE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipReference(reference)) {\n throw new Error(\n `Invalid \"reference\", must match: ${CAIP_REFERENCE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipAssetNamespace(assetNamespace)) {\n throw new Error(\n `Invalid \"assetNamespace\", must match: ${CAIP_ASSET_NAMESPACE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipAssetReference(assetReference)) {\n throw new Error(\n `Invalid \"assetReference\", must match: ${CAIP_ASSET_REFERENCE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipTokenId(tokenId)) {\n throw new Error(\n `Invalid \"tokenId\", must match: ${CAIP_TOKEN_ID_REGEX.toString()}`,\n );\n }\n\n return `${namespace}:${reference}/${assetNamespace}:${assetReference}/${tokenId}`;\n}\n"]}
|
package/dist/caip-types.d.cts
CHANGED
|
@@ -74,6 +74,14 @@ export declare enum KnownCaipNamespace {
|
|
|
74
74
|
Eip155 = "eip155",
|
|
75
75
|
Wallet = "wallet"
|
|
76
76
|
}
|
|
77
|
+
/**
|
|
78
|
+
* A CAIP-2 chain ID that is guaranteed to have a known CAIP namespace
|
|
79
|
+
* (@see {@link KnownCaipNamespace}).
|
|
80
|
+
*
|
|
81
|
+
* This is a narrower, more type-safe alternative to {@link CaipChainId} for use cases
|
|
82
|
+
* where the chain namespace must be one of the known standards.
|
|
83
|
+
*/
|
|
84
|
+
export type KnownCaipNamespacedChainId = `${KnownCaipNamespace}:${string}`;
|
|
77
85
|
/**
|
|
78
86
|
* Check if the given value is a {@link CaipChainId}.
|
|
79
87
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"caip-types.d.cts","sourceRoot":"","sources":["../src/caip-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,8BAA8B;AAKnD,eAAO,MAAM,mBAAmB,QACqC,CAAC;AAEtE,eAAO,MAAM,oBAAoB,QAAsB,CAAC;AAExD,eAAO,MAAM,oBAAoB,QAA2B,CAAC;AAE7D,eAAO,MAAM,qBAAqB,QACwF,CAAC;AAE3H,e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ACjC,aAAa,CA0Bf;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,aAAa,CAC3B,SAAS,EAAE,aAAa,EACxB,SAAS,EAAE,aAAa,EACxB,cAAc,EAAE,kBAAkB,EAClC,cAAc,EAAE,kBAAkB,EAClC,OAAO,EAAE,WAAW,GACnB,WAAW,CAgCb"}
|
package/dist/caip-types.d.mts
CHANGED
|
@@ -74,6 +74,14 @@ export declare enum KnownCaipNamespace {
|
|
|
74
74
|
Eip155 = "eip155",
|
|
75
75
|
Wallet = "wallet"
|
|
76
76
|
}
|
|
77
|
+
/**
|
|
78
|
+
* A CAIP-2 chain ID that is guaranteed to have a known CAIP namespace
|
|
79
|
+
* (@see {@link KnownCaipNamespace}).
|
|
80
|
+
*
|
|
81
|
+
* This is a narrower, more type-safe alternative to {@link CaipChainId} for use cases
|
|
82
|
+
* where the chain namespace must be one of the known standards.
|
|
83
|
+
*/
|
|
84
|
+
export type KnownCaipNamespacedChainId = `${KnownCaipNamespace}:${string}`;
|
|
77
85
|
/**
|
|
78
86
|
* Check if the given value is a {@link CaipChainId}.
|
|
79
87
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"caip-types.d.mts","sourceRoot":"","sources":["../src/caip-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,8BAA8B;AAKnD,eAAO,MAAM,mBAAmB,QACqC,CAAC;AAEtE,eAAO,MAAM,oBAAoB,QAAsB,CAAC;AAExD,eAAO,MAAM,oBAAoB,QAA2B,CAAC;AAE7D,eAAO,MAAM,qBAAqB,QACwF,CAAC;AAE3H,eAAO,MAAM,0BAA0B,QAA6B,CAAC;AAErE,eAAO,MAAM,0BAA0B,QAAsB,CAAC;AAE9D,eAAO,MAAM,0BAA0B,QAA6B,CAAC;AAErE,eAAO,MAAM,mBAAmB,QAA4B,CAAC;AAE7D,eAAO,MAAM,qBAAqB,QAC2H,CAAC;AAE9J,eAAO,MAAM,mBAAmB,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AC,oBAAoB,CAAC,cAAc,CAAC,EAAE;QACzC,MAAM,IAAI,KAAK,CACb,yCAAyC,0BAA0B,CAAC,QAAQ,EAAE,EAAE,CACjF,CAAC;KACH;IAED,IAAI,CAAC,oBAAoB,CAAC,cAAc,CAAC,EAAE;QACzC,MAAM,IAAI,KAAK,CACb,yCAAyC,0BAA0B,CAAC,QAAQ,EAAE,EAAE,CACjF,CAAC;KACH;IAED,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,EAAE;QAC3B,MAAM,IAAI,KAAK,CACb,kCAAkC,mBAAmB,CAAC,QAAQ,EAAE,EAAE,CACnE,CAAC;KACH;IAED,OAAO,GAAG,SAAS,IAAI,SAAS,IAAI,cAAc,IAAI,cAAc,IAAI,OAAO,EAAE,CAAC;AACpF,CAAC","sourcesContent":["import type { Infer } from '@metamask/superstruct';\nimport { is } from '@metamask/superstruct';\n\nimport { definePattern } from './superstruct';\n\nexport const CAIP_CHAIN_ID_REGEX =\n /^(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-_a-zA-Z0-9]{1,32})$/u;\n\nexport const CAIP_NAMESPACE_REGEX = /^[-a-z0-9]{3,8}$/u;\n\nexport const CAIP_REFERENCE_REGEX = /^[-_a-zA-Z0-9]{1,32}$/u;\n\nexport const CAIP_ACCOUNT_ID_REGEX =\n /^(?<chainId>(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-_a-zA-Z0-9]{1,32})):(?<accountAddress>[-.%a-zA-Z0-9]{1,128})$/u;\n\nexport const CAIP_ACCOUNT_ADDRESS_REGEX = /^[-.%a-zA-Z0-9]{1,128}$/u;\n\nexport const CAIP_ASSET_NAMESPACE_REGEX = /^[-a-z0-9]{3,8}$/u;\n\nexport const CAIP_ASSET_REFERENCE_REGEX = /^[-.%a-zA-Z0-9]{1,128}$/u;\n\nexport const CAIP_TOKEN_ID_REGEX = /^[-.%a-zA-Z0-9]{1,78}$/u;\n\nexport const CAIP_ASSET_TYPE_REGEX =\n /^(?<chainId>(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-_a-zA-Z0-9]{1,32}))\\/(?<assetNamespace>[-a-z0-9]{3,8}):(?<assetReference>[-.%a-zA-Z0-9]{1,128})$/u;\n\nexport const CAIP_ASSET_ID_REGEX =\n /^(?<chainId>(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-_a-zA-Z0-9]{1,32}))\\/(?<assetNamespace>[-a-z0-9]{3,8}):(?<assetReference>[-.%a-zA-Z0-9]{1,128})\\/(?<tokenId>[-.%a-zA-Z0-9]{1,78})$/u;\n\nconst CAIP_ASSET_TYPE_OR_ID_REGEX =\n /^(?<chainId>(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-_a-zA-Z0-9]{1,32}))\\/(?<assetNamespace>[-a-z0-9]{3,8}):(?<assetReference>[-.%a-zA-Z0-9]{1,128})(\\/(?<tokenId>[-.%a-zA-Z0-9]{1,78}))?$/u;\n\n/**\n * A CAIP-2 chain ID, i.e., a human-readable namespace and reference.\n */\nexport const CaipChainIdStruct = definePattern<`${string}:${string}`>(\n 'CaipChainId',\n CAIP_CHAIN_ID_REGEX,\n);\nexport type CaipChainId = Infer<typeof CaipChainIdStruct>;\n\n/**\n * A CAIP-2 namespace, i.e., the first part of a CAIP chain ID.\n */\nexport const CaipNamespaceStruct = definePattern(\n 'CaipNamespace',\n CAIP_NAMESPACE_REGEX,\n);\nexport type CaipNamespace = Infer<typeof CaipNamespaceStruct>;\n\n/**\n * A CAIP-2 reference, i.e., the second part of a CAIP chain ID.\n */\nexport const CaipReferenceStruct = definePattern(\n 'CaipReference',\n CAIP_REFERENCE_REGEX,\n);\nexport type CaipReference = Infer<typeof CaipReferenceStruct>;\n\n/**\n * A CAIP-10 account ID, i.e., a human-readable namespace, reference, and account address.\n */\nexport const CaipAccountIdStruct =\n definePattern<`${string}:${string}:${string}`>(\n 'CaipAccountId',\n CAIP_ACCOUNT_ID_REGEX,\n );\nexport type CaipAccountId = Infer<typeof CaipAccountIdStruct>;\n\n/**\n * A CAIP-10 account address, i.e., the third part of the CAIP account ID.\n */\nexport const CaipAccountAddressStruct = definePattern(\n 'CaipAccountAddress',\n CAIP_ACCOUNT_ADDRESS_REGEX,\n);\nexport type CaipAccountAddress = Infer<typeof CaipAccountAddressStruct>;\n\n/**\n * A CAIP-19 asset namespace, i.e., a namespace domain of an asset.\n */\nexport const CaipAssetNamespaceStruct = definePattern(\n 'CaipAssetNamespace',\n CAIP_ASSET_NAMESPACE_REGEX,\n);\nexport type CaipAssetNamespace = Infer<typeof CaipAssetNamespaceStruct>;\n\n/**\n * A CAIP-19 asset reference, i.e., an identifier for an asset within a given namespace.\n */\nexport const CaipAssetReferenceStruct = definePattern(\n 'CaipAssetReference',\n CAIP_ASSET_REFERENCE_REGEX,\n);\nexport type CaipAssetReference = Infer<typeof CaipAssetReferenceStruct>;\n\n/**\n * A CAIP-19 asset token ID, i.e., a unique identifier for an addressable asset of a given type\n */\nexport const CaipTokenIdStruct = definePattern(\n 'CaipTokenId',\n CAIP_TOKEN_ID_REGEX,\n);\nexport type CaipTokenId = Infer<typeof CaipTokenIdStruct>;\n\n/**\n * A CAIP-19 asset type identifier, i.e., a human-readable type of asset identifier.\n */\nexport const CaipAssetTypeStruct =\n definePattern<`${string}:${string}/${string}:${string}`>(\n 'CaipAssetType',\n CAIP_ASSET_TYPE_REGEX,\n );\nexport type CaipAssetType = Infer<typeof CaipAssetTypeStruct>;\n\n/**\n * A CAIP-19 asset ID identifier, i.e., a human-readable type of asset ID.\n */\nexport const CaipAssetIdStruct =\n definePattern<`${string}:${string}/${string}:${string}/${string}`>(\n 'CaipAssetId',\n CAIP_ASSET_ID_REGEX,\n );\nexport type CaipAssetId = Infer<typeof CaipAssetIdStruct>;\n\n/**\n * A CAIP-19 asset type or asset ID identifier, i.e., a human-readable type of asset identifier.\n */\nexport const CaipAssetTypeOrIdStruct = definePattern<\n CaipAssetType | CaipAssetId\n>('CaipAssetTypeOrId', CAIP_ASSET_TYPE_OR_ID_REGEX);\nexport type CaipAssetTypeOrId = Infer<typeof CaipAssetTypeOrIdStruct>;\n\n/** Known CAIP namespaces. */\nexport enum KnownCaipNamespace {\n /** BIP-122 (Bitcoin) compatible chains. */\n Bip122 = 'bip122',\n /** Solana compatible chains */\n Solana = 'solana',\n /** EIP-155 compatible chains. */\n Eip155 = 'eip155',\n Wallet = 'wallet',\n}\n\n/**\n * Check if the given value is a {@link CaipChainId}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipChainId}.\n */\nexport function isCaipChainId(value: unknown): value is CaipChainId {\n return is(value, CaipChainIdStruct);\n}\n\n/**\n * Check if the given value is a {@link CaipNamespace}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipNamespace}.\n */\nexport function isCaipNamespace(value: unknown): value is CaipNamespace {\n return is(value, CaipNamespaceStruct);\n}\n\n/**\n * Check if the given value is a {@link CaipReference}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipReference}.\n */\nexport function isCaipReference(value: unknown): value is CaipReference {\n return is(value, CaipReferenceStruct);\n}\n\n/**\n * Check if the given value is a {@link CaipAccountId}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipAccountId}.\n */\nexport function isCaipAccountId(value: unknown): value is CaipAccountId {\n return is(value, CaipAccountIdStruct);\n}\n\n/**\n * Check if a value is a {@link CaipAccountAddress}.\n *\n * @param value - The value to validate.\n * @returns True if the value is a valid {@link CaipAccountAddress}.\n */\nexport function isCaipAccountAddress(\n value: unknown,\n): value is CaipAccountAddress {\n return is(value, CaipAccountAddressStruct);\n}\n\n/**\n * Check if the given value is a {@link CaipAssetNamespace}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipAssetNamespace}.\n */\nexport function isCaipAssetNamespace(\n value: unknown,\n): value is CaipAssetNamespace {\n return is(value, CaipAssetNamespaceStruct);\n}\n\n/**\n * Check if the given value is a {@link CaipAssetReference}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipAssetReference}.\n */\nexport function isCaipAssetReference(\n value: unknown,\n): value is CaipAssetReference {\n return is(value, CaipAssetReferenceStruct);\n}\n\n/**\n * Check if the given value is a {@link CaipTokenId}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipTokenId}.\n */\nexport function isCaipTokenId(value: unknown): value is CaipTokenId {\n return is(value, CaipTokenIdStruct);\n}\n\n/**\n * Check if the given value is a {@link CaipAssetType}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipAssetType}.\n */\nexport function isCaipAssetType(value: unknown): value is CaipAssetType {\n return is(value, CaipAssetTypeStruct);\n}\n\n/**\n * Check if the given value is a {@link CaipAssetId}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipAssetId}.\n */\nexport function isCaipAssetId(value: unknown): value is CaipAssetId {\n return is(value, CaipAssetIdStruct);\n}\n\n/**\n * Parse a CAIP-2 chain ID to an object containing the namespace and reference.\n * This validates the CAIP-2 chain ID before parsing it.\n *\n * @param caipChainId - The CAIP-2 chain ID to validate and parse.\n * @returns The parsed CAIP-2 chain ID.\n */\nexport function parseCaipChainId(caipChainId: CaipChainId): {\n namespace: CaipNamespace;\n reference: CaipReference;\n} {\n const match = CAIP_CHAIN_ID_REGEX.exec(caipChainId);\n if (!match?.groups) {\n throw new Error('Invalid CAIP chain ID.');\n }\n\n return {\n namespace: match.groups.namespace as CaipNamespace,\n reference: match.groups.reference as CaipReference,\n };\n}\n\n/**\n * Parse an CAIP-10 account ID to an object containing the chain ID, parsed chain ID, and account address.\n * This validates the CAIP-10 account ID before parsing it.\n *\n * @param caipAccountId - The CAIP-10 account ID to validate and parse.\n * @returns The parsed CAIP-10 account ID.\n */\nexport function parseCaipAccountId(caipAccountId: CaipAccountId): {\n address: CaipAccountAddress;\n chainId: CaipChainId;\n chain: { namespace: CaipNamespace; reference: CaipReference };\n} {\n const match = CAIP_ACCOUNT_ID_REGEX.exec(caipAccountId);\n if (!match?.groups) {\n throw new Error('Invalid CAIP account ID.');\n }\n\n return {\n address: match.groups.accountAddress as CaipAccountAddress,\n chainId: match.groups.chainId as CaipChainId,\n chain: {\n namespace: match.groups.namespace as CaipNamespace,\n reference: match.groups.reference as CaipReference,\n },\n };\n}\n\n/**\n * Parse a CAIP-19 asset type to an object containing the chain ID, parsed chain ID,\n * asset namespace, and asset reference\n *\n * This validates the CAIP-19 asset type before parsing it.\n *\n * @param caipAssetType - The CAIP-19 asset type to validate and parse.\n * @returns The parsed CAIP-19 asset type.\n */\nexport function parseCaipAssetType(caipAssetType: CaipAssetType): {\n assetNamespace: CaipAssetNamespace;\n assetReference: CaipAssetReference;\n chainId: CaipChainId;\n chain: { namespace: CaipNamespace; reference: CaipReference };\n} {\n const match = CAIP_ASSET_TYPE_REGEX.exec(caipAssetType);\n if (!match?.groups) {\n throw new Error('Invalid CAIP asset type.');\n }\n\n return {\n assetNamespace: match.groups.assetNamespace as CaipAssetNamespace,\n assetReference: match.groups.assetReference as CaipAssetReference,\n chainId: match.groups.chainId as CaipChainId,\n chain: {\n namespace: match.groups.namespace as CaipNamespace,\n reference: match.groups.reference as CaipReference,\n },\n };\n}\n\n/**\n * Parse a CAIP-19 asset ID to an object containing the chain ID, parsed chain ID,\n * asset namespace, asset reference, and token ID.\n *\n * This validates the CAIP-19 asset ID before parsing it.\n *\n * @param caipAssetId - The CAIP-19 asset ID to validate and parse.\n * @returns The parsed CAIP-19 asset ID.\n */\nexport function parseCaipAssetId(caipAssetId: CaipAssetId): {\n assetNamespace: CaipAssetNamespace;\n assetReference: CaipAssetReference;\n tokenId: CaipTokenId;\n chainId: CaipChainId;\n chain: { namespace: CaipNamespace; reference: CaipReference };\n} {\n const match = CAIP_ASSET_ID_REGEX.exec(caipAssetId);\n if (!match?.groups) {\n throw new Error('Invalid CAIP asset ID.');\n }\n\n return {\n assetNamespace: match.groups.assetNamespace as CaipAssetNamespace,\n assetReference: match.groups.assetReference as CaipAssetReference,\n tokenId: match.groups.tokenId as CaipTokenId,\n chainId: match.groups.chainId as CaipChainId,\n chain: {\n namespace: match.groups.namespace as CaipNamespace,\n reference: match.groups.reference as CaipReference,\n },\n };\n}\n\n/**\n * Chain ID as defined per the CAIP-2\n * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-2.md}.\n *\n * It defines a way to uniquely identify any blockchain in a human-readable\n * way.\n *\n * @param namespace - The standard (ecosystem) of similar blockchains.\n * @param reference - Identify of a blockchain within a given namespace.\n * @throws {@link Error}\n * This exception is thrown if the inputs does not comply with the CAIP-2\n * syntax specification\n * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-2.md#syntax}.\n * @returns A CAIP chain ID.\n */\nexport function toCaipChainId(\n namespace: CaipNamespace,\n reference: CaipReference,\n): CaipChainId {\n if (!isCaipNamespace(namespace)) {\n throw new Error(\n `Invalid \"namespace\", must match: ${CAIP_NAMESPACE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipReference(reference)) {\n throw new Error(\n `Invalid \"reference\", must match: ${CAIP_REFERENCE_REGEX.toString()}`,\n );\n }\n\n return `${namespace}:${reference}`;\n}\n\n/**\n * Account ID as defined per the CAIP-10\n * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-10.md}.\n *\n * It defines a way to uniquely identify any blockchain account in a human-readable\n * way.\n *\n * @param namespace - The standard (ecosystem) of similar blockchains.\n * @param reference - Identity of a blockchain within a given namespace.\n * @param accountAddress - The address of the blockchain account.\n * @throws {@link Error}\n * This exception is thrown if the inputs do not comply with the CAIP-10\n * syntax specification\n * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-10.md#syntax}.\n * @returns A CAIP account ID.\n */\nexport function toCaipAccountId(\n namespace: CaipNamespace,\n reference: CaipReference,\n accountAddress: CaipAccountAddress,\n): CaipAccountId {\n if (!isCaipNamespace(namespace)) {\n throw new Error(\n `Invalid \"namespace\", must match: ${CAIP_NAMESPACE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipReference(reference)) {\n throw new Error(\n `Invalid \"reference\", must match: ${CAIP_REFERENCE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipAccountAddress(accountAddress)) {\n throw new Error(\n `Invalid \"accountAddress\", must match: ${CAIP_ACCOUNT_ADDRESS_REGEX.toString()}`,\n );\n }\n\n return `${namespace}:${reference}:${accountAddress}`;\n}\n\n/**\n * Asset Type as defined per the CAIP-19\n * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-19.md}.\n *\n * It defines a way to uniquely identify any blockchain asset in a human-readable\n * way.\n *\n * @param namespace - The standard (ecosystem) of similar blockchains.\n * @param reference - Identity of a blockchain within a given namespace.\n * @param assetNamespace - The namespace domain of an asset.\n * @param assetReference - The identity of an asset within a given namespace.\n * @throws {@link Error}\n * This exception is thrown if the inputs do not comply with the CAIP-19\n * syntax specification\n * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-19.md#syntax}.\n * @returns A CAIP asset type.\n */\nexport function toCaipAssetType(\n namespace: CaipNamespace,\n reference: CaipReference,\n assetNamespace: CaipAssetNamespace,\n assetReference: CaipAssetReference,\n): CaipAssetType {\n if (!isCaipNamespace(namespace)) {\n throw new Error(\n `Invalid \"namespace\", must match: ${CAIP_NAMESPACE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipReference(reference)) {\n throw new Error(\n `Invalid \"reference\", must match: ${CAIP_REFERENCE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipAssetNamespace(assetNamespace)) {\n throw new Error(\n `Invalid \"assetNamespace\", must match: ${CAIP_ASSET_NAMESPACE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipAssetReference(assetReference)) {\n throw new Error(\n `Invalid \"assetReference\", must match: ${CAIP_ASSET_REFERENCE_REGEX.toString()}`,\n );\n }\n\n return `${namespace}:${reference}/${assetNamespace}:${assetReference}`;\n}\n\n/**\n * Asset ID as defined per the CAIP-19\n * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-19.md}.\n *\n * It defines a way to uniquely identify any blockchain asset in a human-readable\n * way.\n *\n * @param namespace - The standard (ecosystem) of similar blockchains.\n * @param reference - Identity of a blockchain within a given namespace.\n * @param assetNamespace - The namespace domain of an asset.\n * @param assetReference - The identity of an asset within a given namespace.\n * @param tokenId - The unique identifier for an addressable asset of a given type.\n * @throws {@link Error}\n * This exception is thrown if the inputs do not comply with the CAIP-19\n * syntax specification\n * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-19.md#syntax}.\n * @returns A CAIP asset ID.\n */\nexport function toCaipAssetId(\n namespace: CaipNamespace,\n reference: CaipReference,\n assetNamespace: CaipAssetNamespace,\n assetReference: CaipAssetReference,\n tokenId: CaipTokenId,\n): CaipAssetId {\n if (!isCaipNamespace(namespace)) {\n throw new Error(\n `Invalid \"namespace\", must match: ${CAIP_NAMESPACE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipReference(reference)) {\n throw new Error(\n `Invalid \"reference\", must match: ${CAIP_REFERENCE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipAssetNamespace(assetNamespace)) {\n throw new Error(\n `Invalid \"assetNamespace\", must match: ${CAIP_ASSET_NAMESPACE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipAssetReference(assetReference)) {\n throw new Error(\n `Invalid \"assetReference\", must match: ${CAIP_ASSET_REFERENCE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipTokenId(tokenId)) {\n throw new Error(\n `Invalid \"tokenId\", must match: ${CAIP_TOKEN_ID_REGEX.toString()}`,\n );\n }\n\n return `${namespace}:${reference}/${assetNamespace}:${assetReference}/${tokenId}`;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"caip-types.mjs","sourceRoot":"","sources":["../src/caip-types.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAE,8BAA8B;AAE3C,OAAO,EAAE,aAAa,EAAE,0BAAsB;AAE9C,MAAM,CAAC,MAAM,mBAAmB,GAC9B,mEAAmE,CAAC;AAEtE,MAAM,CAAC,MAAM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aAAa,CAAC,OAAO,CAAC,EAAE;QAC3B,MAAM,IAAI,KAAK,CACb,kCAAkC,mBAAmB,CAAC,QAAQ,EAAE,EAAE,CACnE,CAAC;KACH;IAED,OAAO,GAAG,SAAS,IAAI,SAAS,IAAI,cAAc,IAAI,cAAc,IAAI,OAAO,EAAE,CAAC;AACpF,CAAC","sourcesContent":["import type { Infer } from '@metamask/superstruct';\nimport { is } from '@metamask/superstruct';\n\nimport { definePattern } from './superstruct';\n\nexport const CAIP_CHAIN_ID_REGEX =\n /^(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-_a-zA-Z0-9]{1,32})$/u;\n\nexport const CAIP_NAMESPACE_REGEX = /^[-a-z0-9]{3,8}$/u;\n\nexport const CAIP_REFERENCE_REGEX = /^[-_a-zA-Z0-9]{1,32}$/u;\n\nexport const CAIP_ACCOUNT_ID_REGEX =\n /^(?<chainId>(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-_a-zA-Z0-9]{1,32})):(?<accountAddress>[-.%a-zA-Z0-9]{1,128})$/u;\n\nexport const CAIP_ACCOUNT_ADDRESS_REGEX = /^[-.%a-zA-Z0-9]{1,128}$/u;\n\nexport const CAIP_ASSET_NAMESPACE_REGEX = /^[-a-z0-9]{3,8}$/u;\n\nexport const CAIP_ASSET_REFERENCE_REGEX = /^[-.%a-zA-Z0-9]{1,128}$/u;\n\nexport const CAIP_TOKEN_ID_REGEX = /^[-.%a-zA-Z0-9]{1,78}$/u;\n\nexport const CAIP_ASSET_TYPE_REGEX =\n /^(?<chainId>(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-_a-zA-Z0-9]{1,32}))\\/(?<assetNamespace>[-a-z0-9]{3,8}):(?<assetReference>[-.%a-zA-Z0-9]{1,128})$/u;\n\nexport const CAIP_ASSET_ID_REGEX =\n /^(?<chainId>(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-_a-zA-Z0-9]{1,32}))\\/(?<assetNamespace>[-a-z0-9]{3,8}):(?<assetReference>[-.%a-zA-Z0-9]{1,128})\\/(?<tokenId>[-.%a-zA-Z0-9]{1,78})$/u;\n\nconst CAIP_ASSET_TYPE_OR_ID_REGEX =\n /^(?<chainId>(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-_a-zA-Z0-9]{1,32}))\\/(?<assetNamespace>[-a-z0-9]{3,8}):(?<assetReference>[-.%a-zA-Z0-9]{1,128})(\\/(?<tokenId>[-.%a-zA-Z0-9]{1,78}))?$/u;\n\n/**\n * A CAIP-2 chain ID, i.e., a human-readable namespace and reference.\n */\nexport const CaipChainIdStruct = definePattern<`${string}:${string}`>(\n 'CaipChainId',\n CAIP_CHAIN_ID_REGEX,\n);\nexport type CaipChainId = Infer<typeof CaipChainIdStruct>;\n\n/**\n * A CAIP-2 namespace, i.e., the first part of a CAIP chain ID.\n */\nexport const CaipNamespaceStruct = definePattern(\n 'CaipNamespace',\n CAIP_NAMESPACE_REGEX,\n);\nexport type CaipNamespace = Infer<typeof CaipNamespaceStruct>;\n\n/**\n * A CAIP-2 reference, i.e., the second part of a CAIP chain ID.\n */\nexport const CaipReferenceStruct = definePattern(\n 'CaipReference',\n CAIP_REFERENCE_REGEX,\n);\nexport type CaipReference = Infer<typeof CaipReferenceStruct>;\n\n/**\n * A CAIP-10 account ID, i.e., a human-readable namespace, reference, and account address.\n */\nexport const CaipAccountIdStruct =\n definePattern<`${string}:${string}:${string}`>(\n 'CaipAccountId',\n CAIP_ACCOUNT_ID_REGEX,\n );\nexport type CaipAccountId = Infer<typeof CaipAccountIdStruct>;\n\n/**\n * A CAIP-10 account address, i.e., the third part of the CAIP account ID.\n */\nexport const CaipAccountAddressStruct = definePattern(\n 'CaipAccountAddress',\n CAIP_ACCOUNT_ADDRESS_REGEX,\n);\nexport type CaipAccountAddress = Infer<typeof CaipAccountAddressStruct>;\n\n/**\n * A CAIP-19 asset namespace, i.e., a namespace domain of an asset.\n */\nexport const CaipAssetNamespaceStruct = definePattern(\n 'CaipAssetNamespace',\n CAIP_ASSET_NAMESPACE_REGEX,\n);\nexport type CaipAssetNamespace = Infer<typeof CaipAssetNamespaceStruct>;\n\n/**\n * A CAIP-19 asset reference, i.e., an identifier for an asset within a given namespace.\n */\nexport const CaipAssetReferenceStruct = definePattern(\n 'CaipAssetReference',\n CAIP_ASSET_REFERENCE_REGEX,\n);\nexport type CaipAssetReference = Infer<typeof CaipAssetReferenceStruct>;\n\n/**\n * A CAIP-19 asset token ID, i.e., a unique identifier for an addressable asset of a given type\n */\nexport const CaipTokenIdStruct = definePattern(\n 'CaipTokenId',\n CAIP_TOKEN_ID_REGEX,\n);\nexport type CaipTokenId = Infer<typeof CaipTokenIdStruct>;\n\n/**\n * A CAIP-19 asset type identifier, i.e., a human-readable type of asset identifier.\n */\nexport const CaipAssetTypeStruct =\n definePattern<`${string}:${string}/${string}:${string}`>(\n 'CaipAssetType',\n CAIP_ASSET_TYPE_REGEX,\n );\nexport type CaipAssetType = Infer<typeof CaipAssetTypeStruct>;\n\n/**\n * A CAIP-19 asset ID identifier, i.e., a human-readable type of asset ID.\n */\nexport const CaipAssetIdStruct =\n definePattern<`${string}:${string}/${string}:${string}/${string}`>(\n 'CaipAssetId',\n CAIP_ASSET_ID_REGEX,\n );\nexport type CaipAssetId = Infer<typeof CaipAssetIdStruct>;\n\n/**\n * A CAIP-19 asset type or asset ID identifier, i.e., a human-readable type of asset identifier.\n */\nexport const CaipAssetTypeOrIdStruct = definePattern<\n CaipAssetType | CaipAssetId\n>('CaipAssetTypeOrId', CAIP_ASSET_TYPE_OR_ID_REGEX);\nexport type CaipAssetTypeOrId = Infer<typeof CaipAssetTypeOrIdStruct>;\n\n/** Known CAIP namespaces. */\nexport enum KnownCaipNamespace {\n /** BIP-122 (Bitcoin) compatible chains. */\n Bip122 = 'bip122',\n /** Solana compatible chains */\n Solana = 'solana',\n /** EIP-155 compatible chains. */\n Eip155 = 'eip155',\n Wallet = 'wallet',\n}\n\n/**\n * A CAIP-2 chain ID that is guaranteed to have a known CAIP namespace\n * (@see {@link KnownCaipNamespace}).\n *\n * This is a narrower, more type-safe alternative to {@link CaipChainId} for use cases\n * where the chain namespace must be one of the known standards.\n */\nexport type KnownCaipNamespacedChainId = `${KnownCaipNamespace}:${string}`;\n\n/**\n * Check if the given value is a {@link CaipChainId}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipChainId}.\n */\nexport function isCaipChainId(value: unknown): value is CaipChainId {\n return is(value, CaipChainIdStruct);\n}\n\n/**\n * Check if the given value is a {@link CaipNamespace}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipNamespace}.\n */\nexport function isCaipNamespace(value: unknown): value is CaipNamespace {\n return is(value, CaipNamespaceStruct);\n}\n\n/**\n * Check if the given value is a {@link CaipReference}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipReference}.\n */\nexport function isCaipReference(value: unknown): value is CaipReference {\n return is(value, CaipReferenceStruct);\n}\n\n/**\n * Check if the given value is a {@link CaipAccountId}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipAccountId}.\n */\nexport function isCaipAccountId(value: unknown): value is CaipAccountId {\n return is(value, CaipAccountIdStruct);\n}\n\n/**\n * Check if a value is a {@link CaipAccountAddress}.\n *\n * @param value - The value to validate.\n * @returns True if the value is a valid {@link CaipAccountAddress}.\n */\nexport function isCaipAccountAddress(\n value: unknown,\n): value is CaipAccountAddress {\n return is(value, CaipAccountAddressStruct);\n}\n\n/**\n * Check if the given value is a {@link CaipAssetNamespace}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipAssetNamespace}.\n */\nexport function isCaipAssetNamespace(\n value: unknown,\n): value is CaipAssetNamespace {\n return is(value, CaipAssetNamespaceStruct);\n}\n\n/**\n * Check if the given value is a {@link CaipAssetReference}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipAssetReference}.\n */\nexport function isCaipAssetReference(\n value: unknown,\n): value is CaipAssetReference {\n return is(value, CaipAssetReferenceStruct);\n}\n\n/**\n * Check if the given value is a {@link CaipTokenId}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipTokenId}.\n */\nexport function isCaipTokenId(value: unknown): value is CaipTokenId {\n return is(value, CaipTokenIdStruct);\n}\n\n/**\n * Check if the given value is a {@link CaipAssetType}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipAssetType}.\n */\nexport function isCaipAssetType(value: unknown): value is CaipAssetType {\n return is(value, CaipAssetTypeStruct);\n}\n\n/**\n * Check if the given value is a {@link CaipAssetId}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipAssetId}.\n */\nexport function isCaipAssetId(value: unknown): value is CaipAssetId {\n return is(value, CaipAssetIdStruct);\n}\n\n/**\n * Parse a CAIP-2 chain ID to an object containing the namespace and reference.\n * This validates the CAIP-2 chain ID before parsing it.\n *\n * @param caipChainId - The CAIP-2 chain ID to validate and parse.\n * @returns The parsed CAIP-2 chain ID.\n */\nexport function parseCaipChainId(caipChainId: CaipChainId): {\n namespace: CaipNamespace;\n reference: CaipReference;\n} {\n const match = CAIP_CHAIN_ID_REGEX.exec(caipChainId);\n if (!match?.groups) {\n throw new Error('Invalid CAIP chain ID.');\n }\n\n return {\n namespace: match.groups.namespace as CaipNamespace,\n reference: match.groups.reference as CaipReference,\n };\n}\n\n/**\n * Parse an CAIP-10 account ID to an object containing the chain ID, parsed chain ID, and account address.\n * This validates the CAIP-10 account ID before parsing it.\n *\n * @param caipAccountId - The CAIP-10 account ID to validate and parse.\n * @returns The parsed CAIP-10 account ID.\n */\nexport function parseCaipAccountId(caipAccountId: CaipAccountId): {\n address: CaipAccountAddress;\n chainId: CaipChainId;\n chain: { namespace: CaipNamespace; reference: CaipReference };\n} {\n const match = CAIP_ACCOUNT_ID_REGEX.exec(caipAccountId);\n if (!match?.groups) {\n throw new Error('Invalid CAIP account ID.');\n }\n\n return {\n address: match.groups.accountAddress as CaipAccountAddress,\n chainId: match.groups.chainId as CaipChainId,\n chain: {\n namespace: match.groups.namespace as CaipNamespace,\n reference: match.groups.reference as CaipReference,\n },\n };\n}\n\n/**\n * Parse a CAIP-19 asset type to an object containing the chain ID, parsed chain ID,\n * asset namespace, and asset reference\n *\n * This validates the CAIP-19 asset type before parsing it.\n *\n * @param caipAssetType - The CAIP-19 asset type to validate and parse.\n * @returns The parsed CAIP-19 asset type.\n */\nexport function parseCaipAssetType(caipAssetType: CaipAssetType): {\n assetNamespace: CaipAssetNamespace;\n assetReference: CaipAssetReference;\n chainId: CaipChainId;\n chain: { namespace: CaipNamespace; reference: CaipReference };\n} {\n const match = CAIP_ASSET_TYPE_REGEX.exec(caipAssetType);\n if (!match?.groups) {\n throw new Error('Invalid CAIP asset type.');\n }\n\n return {\n assetNamespace: match.groups.assetNamespace as CaipAssetNamespace,\n assetReference: match.groups.assetReference as CaipAssetReference,\n chainId: match.groups.chainId as CaipChainId,\n chain: {\n namespace: match.groups.namespace as CaipNamespace,\n reference: match.groups.reference as CaipReference,\n },\n };\n}\n\n/**\n * Parse a CAIP-19 asset ID to an object containing the chain ID, parsed chain ID,\n * asset namespace, asset reference, and token ID.\n *\n * This validates the CAIP-19 asset ID before parsing it.\n *\n * @param caipAssetId - The CAIP-19 asset ID to validate and parse.\n * @returns The parsed CAIP-19 asset ID.\n */\nexport function parseCaipAssetId(caipAssetId: CaipAssetId): {\n assetNamespace: CaipAssetNamespace;\n assetReference: CaipAssetReference;\n tokenId: CaipTokenId;\n chainId: CaipChainId;\n chain: { namespace: CaipNamespace; reference: CaipReference };\n} {\n const match = CAIP_ASSET_ID_REGEX.exec(caipAssetId);\n if (!match?.groups) {\n throw new Error('Invalid CAIP asset ID.');\n }\n\n return {\n assetNamespace: match.groups.assetNamespace as CaipAssetNamespace,\n assetReference: match.groups.assetReference as CaipAssetReference,\n tokenId: match.groups.tokenId as CaipTokenId,\n chainId: match.groups.chainId as CaipChainId,\n chain: {\n namespace: match.groups.namespace as CaipNamespace,\n reference: match.groups.reference as CaipReference,\n },\n };\n}\n\n/**\n * Chain ID as defined per the CAIP-2\n * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-2.md}.\n *\n * It defines a way to uniquely identify any blockchain in a human-readable\n * way.\n *\n * @param namespace - The standard (ecosystem) of similar blockchains.\n * @param reference - Identify of a blockchain within a given namespace.\n * @throws {@link Error}\n * This exception is thrown if the inputs does not comply with the CAIP-2\n * syntax specification\n * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-2.md#syntax}.\n * @returns A CAIP chain ID.\n */\nexport function toCaipChainId(\n namespace: CaipNamespace,\n reference: CaipReference,\n): CaipChainId {\n if (!isCaipNamespace(namespace)) {\n throw new Error(\n `Invalid \"namespace\", must match: ${CAIP_NAMESPACE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipReference(reference)) {\n throw new Error(\n `Invalid \"reference\", must match: ${CAIP_REFERENCE_REGEX.toString()}`,\n );\n }\n\n return `${namespace}:${reference}`;\n}\n\n/**\n * Account ID as defined per the CAIP-10\n * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-10.md}.\n *\n * It defines a way to uniquely identify any blockchain account in a human-readable\n * way.\n *\n * @param namespace - The standard (ecosystem) of similar blockchains.\n * @param reference - Identity of a blockchain within a given namespace.\n * @param accountAddress - The address of the blockchain account.\n * @throws {@link Error}\n * This exception is thrown if the inputs do not comply with the CAIP-10\n * syntax specification\n * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-10.md#syntax}.\n * @returns A CAIP account ID.\n */\nexport function toCaipAccountId(\n namespace: CaipNamespace,\n reference: CaipReference,\n accountAddress: CaipAccountAddress,\n): CaipAccountId {\n if (!isCaipNamespace(namespace)) {\n throw new Error(\n `Invalid \"namespace\", must match: ${CAIP_NAMESPACE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipReference(reference)) {\n throw new Error(\n `Invalid \"reference\", must match: ${CAIP_REFERENCE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipAccountAddress(accountAddress)) {\n throw new Error(\n `Invalid \"accountAddress\", must match: ${CAIP_ACCOUNT_ADDRESS_REGEX.toString()}`,\n );\n }\n\n return `${namespace}:${reference}:${accountAddress}`;\n}\n\n/**\n * Asset Type as defined per the CAIP-19\n * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-19.md}.\n *\n * It defines a way to uniquely identify any blockchain asset in a human-readable\n * way.\n *\n * @param namespace - The standard (ecosystem) of similar blockchains.\n * @param reference - Identity of a blockchain within a given namespace.\n * @param assetNamespace - The namespace domain of an asset.\n * @param assetReference - The identity of an asset within a given namespace.\n * @throws {@link Error}\n * This exception is thrown if the inputs do not comply with the CAIP-19\n * syntax specification\n * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-19.md#syntax}.\n * @returns A CAIP asset type.\n */\nexport function toCaipAssetType(\n namespace: CaipNamespace,\n reference: CaipReference,\n assetNamespace: CaipAssetNamespace,\n assetReference: CaipAssetReference,\n): CaipAssetType {\n if (!isCaipNamespace(namespace)) {\n throw new Error(\n `Invalid \"namespace\", must match: ${CAIP_NAMESPACE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipReference(reference)) {\n throw new Error(\n `Invalid \"reference\", must match: ${CAIP_REFERENCE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipAssetNamespace(assetNamespace)) {\n throw new Error(\n `Invalid \"assetNamespace\", must match: ${CAIP_ASSET_NAMESPACE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipAssetReference(assetReference)) {\n throw new Error(\n `Invalid \"assetReference\", must match: ${CAIP_ASSET_REFERENCE_REGEX.toString()}`,\n );\n }\n\n return `${namespace}:${reference}/${assetNamespace}:${assetReference}`;\n}\n\n/**\n * Asset ID as defined per the CAIP-19\n * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-19.md}.\n *\n * It defines a way to uniquely identify any blockchain asset in a human-readable\n * way.\n *\n * @param namespace - The standard (ecosystem) of similar blockchains.\n * @param reference - Identity of a blockchain within a given namespace.\n * @param assetNamespace - The namespace domain of an asset.\n * @param assetReference - The identity of an asset within a given namespace.\n * @param tokenId - The unique identifier for an addressable asset of a given type.\n * @throws {@link Error}\n * This exception is thrown if the inputs do not comply with the CAIP-19\n * syntax specification\n * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-19.md#syntax}.\n * @returns A CAIP asset ID.\n */\nexport function toCaipAssetId(\n namespace: CaipNamespace,\n reference: CaipReference,\n assetNamespace: CaipAssetNamespace,\n assetReference: CaipAssetReference,\n tokenId: CaipTokenId,\n): CaipAssetId {\n if (!isCaipNamespace(namespace)) {\n throw new Error(\n `Invalid \"namespace\", must match: ${CAIP_NAMESPACE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipReference(reference)) {\n throw new Error(\n `Invalid \"reference\", must match: ${CAIP_REFERENCE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipAssetNamespace(assetNamespace)) {\n throw new Error(\n `Invalid \"assetNamespace\", must match: ${CAIP_ASSET_NAMESPACE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipAssetReference(assetReference)) {\n throw new Error(\n `Invalid \"assetReference\", must match: ${CAIP_ASSET_REFERENCE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipTokenId(tokenId)) {\n throw new Error(\n `Invalid \"tokenId\", must match: ${CAIP_TOKEN_ID_REGEX.toString()}`,\n );\n }\n\n return `${namespace}:${reference}/${assetNamespace}:${assetReference}/${tokenId}`;\n}\n"]}
|
package/dist/hex.cjs
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.remove0x = exports.add0x = exports.isValidChecksumAddress = exports.
|
|
3
|
+
exports.remove0x = exports.add0x = exports.isValidHexAddress = exports.isValidHexAddressUnmemoized = exports.isValidChecksumAddress = exports.isValidChecksumAddressUnmemoized = exports.getChecksumAddress = exports.getChecksumAddressUnmemoized = exports.assertIsStrictHexString = exports.assertIsHexString = exports.isHexChecksumAddress = exports.isHexAddress = exports.isStrictHexString = exports.isHexString = exports.HexChecksumAddressStruct = exports.HexAddressStruct = exports.StrictHexStruct = exports.HexStruct = void 0;
|
|
7
4
|
const superstruct_1 = require("@metamask/superstruct");
|
|
8
5
|
const sha3_1 = require("@noble/hashes/sha3");
|
|
9
|
-
const
|
|
6
|
+
const lodash_1 = require("lodash");
|
|
10
7
|
const assert_1 = require("./assert.cjs");
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
// Use native regexes instead of superstruct for maximum performance.
|
|
9
|
+
// Pre-compiled regex for maximum performance - avoids recompilation on each call
|
|
10
|
+
const HEX_REGEX = /^(?:0x)?[0-9a-f]+$/iu;
|
|
11
|
+
const STRICT_HEX_REGEX = /^0x[0-9a-f]+$/iu;
|
|
12
|
+
const HEX_ADDRESS_REGEX = /^0x[0-9a-f]{40}$/u;
|
|
13
|
+
const HEX_CHECKSUM_ADDRESS_REGEX = /^0x[0-9a-fA-F]{40}$/u;
|
|
14
|
+
exports.HexStruct = (0, superstruct_1.pattern)((0, superstruct_1.string)(), HEX_REGEX);
|
|
15
|
+
exports.StrictHexStruct = (0, superstruct_1.pattern)((0, superstruct_1.string)(), STRICT_HEX_REGEX);
|
|
16
|
+
exports.HexAddressStruct = (0, superstruct_1.pattern)((0, superstruct_1.string)(), HEX_ADDRESS_REGEX);
|
|
17
|
+
exports.HexChecksumAddressStruct = (0, superstruct_1.pattern)((0, superstruct_1.string)(), HEX_CHECKSUM_ADDRESS_REGEX);
|
|
18
|
+
const isString = (value) => typeof value === 'string';
|
|
15
19
|
/**
|
|
16
20
|
* Check if a string is a valid hex string.
|
|
17
21
|
*
|
|
@@ -19,7 +23,7 @@ exports.HexChecksumAddressStruct = (0, superstruct_1.pattern)((0, superstruct_1.
|
|
|
19
23
|
* @returns Whether the value is a valid hex string.
|
|
20
24
|
*/
|
|
21
25
|
function isHexString(value) {
|
|
22
|
-
return (
|
|
26
|
+
return isString(value) && HEX_REGEX.test(value);
|
|
23
27
|
}
|
|
24
28
|
exports.isHexString = isHexString;
|
|
25
29
|
/**
|
|
@@ -30,9 +34,29 @@ exports.isHexString = isHexString;
|
|
|
30
34
|
* @returns Whether the value is a valid hex string.
|
|
31
35
|
*/
|
|
32
36
|
function isStrictHexString(value) {
|
|
33
|
-
return (
|
|
37
|
+
return isString(value) && STRICT_HEX_REGEX.test(value);
|
|
34
38
|
}
|
|
35
39
|
exports.isStrictHexString = isStrictHexString;
|
|
40
|
+
/**
|
|
41
|
+
* Check if a string is a valid hex address.
|
|
42
|
+
*
|
|
43
|
+
* @param value - The value to check.
|
|
44
|
+
* @returns Whether the value is a valid hex address.
|
|
45
|
+
*/
|
|
46
|
+
function isHexAddress(value) {
|
|
47
|
+
return isString(value) && HEX_ADDRESS_REGEX.test(value);
|
|
48
|
+
}
|
|
49
|
+
exports.isHexAddress = isHexAddress;
|
|
50
|
+
/**
|
|
51
|
+
* Check if a string is a valid hex checksum address.
|
|
52
|
+
*
|
|
53
|
+
* @param value - The value to check.
|
|
54
|
+
* @returns Whether the value is a valid hex checksum address.
|
|
55
|
+
*/
|
|
56
|
+
function isHexChecksumAddress(value) {
|
|
57
|
+
return isString(value) && HEX_CHECKSUM_ADDRESS_REGEX.test(value);
|
|
58
|
+
}
|
|
59
|
+
exports.isHexChecksumAddress = isHexChecksumAddress;
|
|
36
60
|
/**
|
|
37
61
|
* Assert that a value is a valid hex string.
|
|
38
62
|
*
|
|
@@ -54,18 +78,6 @@ function assertIsStrictHexString(value) {
|
|
|
54
78
|
(0, assert_1.assert)(isStrictHexString(value), 'Value must be a hexadecimal string, starting with "0x".');
|
|
55
79
|
}
|
|
56
80
|
exports.assertIsStrictHexString = assertIsStrictHexString;
|
|
57
|
-
/**
|
|
58
|
-
* Validate that the passed prefixed hex string is an all-lowercase
|
|
59
|
-
* hex address, or a valid mixed-case checksum address.
|
|
60
|
-
*
|
|
61
|
-
* @param possibleAddress - Input parameter to check against.
|
|
62
|
-
* @returns Whether or not the input is a valid hex address.
|
|
63
|
-
*/
|
|
64
|
-
function isValidHexAddress(possibleAddress) {
|
|
65
|
-
return ((0, superstruct_1.is)(possibleAddress, exports.HexAddressStruct) ||
|
|
66
|
-
isValidChecksumAddress(possibleAddress));
|
|
67
|
-
}
|
|
68
|
-
exports.isValidHexAddress = isValidHexAddress;
|
|
69
81
|
/**
|
|
70
82
|
* Encode a passed hex string as an ERC-55 mixed-case checksum address.
|
|
71
83
|
* This is the unmemoized version, primarily used for testing.
|
|
@@ -75,7 +87,7 @@ exports.isValidHexAddress = isValidHexAddress;
|
|
|
75
87
|
* @see https://eips.ethereum.org/EIPS/eip-55
|
|
76
88
|
*/
|
|
77
89
|
function getChecksumAddressUnmemoized(hexAddress) {
|
|
78
|
-
(0, assert_1.assert)((
|
|
90
|
+
(0, assert_1.assert)(isHexChecksumAddress(hexAddress), 'Invalid hex address.');
|
|
79
91
|
const address = remove0x(hexAddress).toLowerCase();
|
|
80
92
|
const hashBytes = (0, sha3_1.keccak_256)(address);
|
|
81
93
|
const { length } = address;
|
|
@@ -100,7 +112,7 @@ exports.getChecksumAddressUnmemoized = getChecksumAddressUnmemoized;
|
|
|
100
112
|
* @returns The address encoded according to ERC-55.
|
|
101
113
|
* @see https://eips.ethereum.org/EIPS/eip-55
|
|
102
114
|
*/
|
|
103
|
-
exports.getChecksumAddress = (0,
|
|
115
|
+
exports.getChecksumAddress = (0, lodash_1.memoize)(getChecksumAddressUnmemoized);
|
|
104
116
|
/**
|
|
105
117
|
* Validate that the passed hex string is a valid ERC-55 mixed-case
|
|
106
118
|
* checksum address.
|
|
@@ -108,13 +120,40 @@ exports.getChecksumAddress = (0, lodash_memoize_1.default)(getChecksumAddressUnm
|
|
|
108
120
|
* @param possibleChecksum - The hex address to check.
|
|
109
121
|
* @returns True if the address is a checksum address.
|
|
110
122
|
*/
|
|
111
|
-
function
|
|
112
|
-
if (!(
|
|
123
|
+
function isValidChecksumAddressUnmemoized(possibleChecksum) {
|
|
124
|
+
if (!isHexChecksumAddress(possibleChecksum)) {
|
|
113
125
|
return false;
|
|
114
126
|
}
|
|
115
127
|
return (0, exports.getChecksumAddress)(possibleChecksum) === possibleChecksum;
|
|
116
128
|
}
|
|
117
|
-
exports.
|
|
129
|
+
exports.isValidChecksumAddressUnmemoized = isValidChecksumAddressUnmemoized;
|
|
130
|
+
/**
|
|
131
|
+
* Validate that the passed hex string is a valid ERC-55 mixed-case
|
|
132
|
+
* checksum address.
|
|
133
|
+
*
|
|
134
|
+
* @param possibleChecksum - The hex address to check.
|
|
135
|
+
* @returns True if the address is a checksum address.
|
|
136
|
+
*/
|
|
137
|
+
exports.isValidChecksumAddress = (0, lodash_1.memoize)(isValidChecksumAddressUnmemoized);
|
|
138
|
+
/**
|
|
139
|
+
* Validate that the passed prefixed hex string is an all-lowercase
|
|
140
|
+
* hex address, or a valid mixed-case checksum address.
|
|
141
|
+
*
|
|
142
|
+
* @param possibleAddress - Input parameter to check against.
|
|
143
|
+
* @returns Whether or not the input is a valid hex address.
|
|
144
|
+
*/
|
|
145
|
+
function isValidHexAddressUnmemoized(possibleAddress) {
|
|
146
|
+
return (isHexAddress(possibleAddress) || (0, exports.isValidChecksumAddress)(possibleAddress));
|
|
147
|
+
}
|
|
148
|
+
exports.isValidHexAddressUnmemoized = isValidHexAddressUnmemoized;
|
|
149
|
+
/**
|
|
150
|
+
* Validate that the passed prefixed hex string is an all-lowercase
|
|
151
|
+
* hex address, or a valid mixed-case checksum address.
|
|
152
|
+
*
|
|
153
|
+
* @param possibleAddress - Input parameter to check against.
|
|
154
|
+
* @returns Whether or not the input is a valid hex address.
|
|
155
|
+
*/
|
|
156
|
+
exports.isValidHexAddress = (0, lodash_1.memoize)(isValidHexAddressUnmemoized);
|
|
118
157
|
/**
|
|
119
158
|
* Add the `0x`-prefix to a hexadecimal string. If the string already has the
|
|
120
159
|
* prefix, it is returned as-is.
|
package/dist/hex.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hex.cjs","sourceRoot":"","sources":["../src/hex.ts"],"names":[],"mappings":";;;;;;AACA,uDAA4D;AAC5D,6CAA6D;AAC7D,oEAAqC;AAErC,yCAAkC;AAIrB,QAAA,SAAS,GAAG,IAAA,qBAAO,EAAC,IAAA,oBAAM,GAAE,EAAE,sBAAsB,CAAC,CAAC;AACtD,QAAA,eAAe,GAAG,IAAA,qBAAO,EAAC,IAAA,oBAAM,GAAE,EAAE,iBAAiB,CAGjE,CAAC;AACW,QAAA,gBAAgB,GAAG,IAAA,qBAAO,EACrC,IAAA,oBAAM,GAAE,EACR,mBAAmB,CACC,CAAC;AACV,QAAA,wBAAwB,GAAG,IAAA,qBAAO,EAC7C,IAAA,oBAAM,GAAE,EACR,sBAAsB,CACF,CAAC;AAEvB;;;;;GAKG;AACH,SAAgB,WAAW,CAAC,KAAc;IACxC,OAAO,IAAA,gBAAE,EAAC,KAAK,EAAE,iBAAS,CAAC,CAAC;AAC9B,CAAC;AAFD,kCAEC;AAED;;;;;;GAMG;AACH,SAAgB,iBAAiB,CAAC,KAAc;IAC9C,OAAO,IAAA,gBAAE,EAAC,KAAK,EAAE,uBAAe,CAAC,CAAC;AACpC,CAAC;AAFD,8CAEC;AAED;;;;;GAKG;AACH,SAAgB,iBAAiB,CAAC,KAAc;IAC9C,IAAA,eAAM,EAAC,WAAW,CAAC,KAAK,CAAC,EAAE,qCAAqC,CAAC,CAAC;AACpE,CAAC;AAFD,8CAEC;AAED;;;;;;GAMG;AACH,SAAgB,uBAAuB,CAAC,KAAc;IACpD,IAAA,eAAM,EACJ,iBAAiB,CAAC,KAAK,CAAC,EACxB,yDAAyD,CAC1D,CAAC;AACJ,CAAC;AALD,0DAKC;AAED;;;;;;GAMG;AACH,SAAgB,iBAAiB,CAAC,eAAoB;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;;GAOG;AACU,QAAA,kBAAkB,GAAG,IAAA,wBAAO,EAAC,4BAA4B,CAAC,CAAC;AAExE;;;;;;GAMG;AACH,SAAgB,sBAAsB,CAAC,gBAAqB;IAC1D,IAAI,CAAC,IAAA,gBAAE,EAAC,gBAAgB,EAAE,gCAAwB,CAAC,EAAE;QACnD,OAAO,KAAK,CAAC;KACd;IAED,OAAO,IAAA,0BAAkB,EAAC,gBAAgB,CAAC,KAAK,gBAAgB,CAAC;AACnE,CAAC;AAND,wDAMC;AAED;;;;;;GAMG;AACH,SAAgB,KAAK,CAAC,WAAmB;IACvC,IAAI,WAAW,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE;QAChC,OAAO,WAAkB,CAAC;KAC3B;IAED,IAAI,WAAW,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE;QAChC,OAAO,KAAK,WAAW,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC;KACxC;IAED,OAAO,KAAK,WAAW,EAAE,CAAC;AAC5B,CAAC;AAVD,sBAUC;AAED;;;;;;GAMG;AACH,SAAgB,QAAQ,CAAC,WAAmB;IAC1C,IAAI,WAAW,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,WAAW,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE;QAChE,OAAO,WAAW,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;KACjC;IAED,OAAO,WAAW,CAAC;AACrB,CAAC;AAND,4BAMC","sourcesContent":["import type { Struct } from '@metamask/superstruct';\nimport { is, pattern, string } from '@metamask/superstruct';\nimport { keccak_256 as keccak256 } from '@noble/hashes/sha3';\nimport memoize from 'lodash.memoize';\n\nimport { assert } from './assert';\n\nexport type Hex = `0x${string}`;\n\nexport const HexStruct = pattern(string(), /^(?:0x)?[0-9a-f]+$/iu);\nexport const StrictHexStruct = pattern(string(), /^0x[0-9a-f]+$/iu) as Struct<\n Hex,\n null\n>;\nexport const HexAddressStruct = pattern(\n string(),\n /^0x[0-9a-f]{40}$/u,\n) as Struct<Hex, null>;\nexport const HexChecksumAddressStruct = pattern(\n string(),\n /^0x[0-9a-fA-F]{40}$/u,\n) as Struct<Hex, null>;\n\n/**\n * Check if a string is a valid hex string.\n *\n * @param value - The value to check.\n * @returns Whether the value is a valid hex string.\n */\nexport function isHexString(value: unknown): value is string {\n return is(value, HexStruct);\n}\n\n/**\n * Strictly check if a string is a valid hex string. A valid hex string must\n * start with the \"0x\"-prefix.\n *\n * @param value - The value to check.\n * @returns Whether the value is a valid hex string.\n */\nexport function isStrictHexString(value: unknown): value is Hex {\n return is(value, StrictHexStruct);\n}\n\n/**\n * Assert that a value is a valid hex string.\n *\n * @param value - The value to check.\n * @throws If the value is not a valid hex string.\n */\nexport function assertIsHexString(value: unknown): asserts value is string {\n assert(isHexString(value), 'Value must be a hexadecimal string.');\n}\n\n/**\n * Assert that a value is a valid hex string. A valid hex string must start with\n * the \"0x\"-prefix.\n *\n * @param value - The value to check.\n * @throws If the value is not a valid hex string.\n */\nexport function assertIsStrictHexString(value: unknown): asserts value is Hex {\n assert(\n isStrictHexString(value),\n 'Value must be a hexadecimal string, starting with \"0x\".',\n );\n}\n\n/**\n * Validate that the passed prefixed hex string is an all-lowercase\n * hex address, or a valid mixed-case checksum address.\n *\n * @param possibleAddress - Input parameter to check against.\n * @returns Whether or not the input is a valid hex address.\n */\nexport function isValidHexAddress(possibleAddress: Hex) {\n return (\n is(possibleAddress, HexAddressStruct) ||\n isValidChecksumAddress(possibleAddress)\n );\n}\n\n/**\n * Encode a passed hex string as an ERC-55 mixed-case checksum address.\n * This is the unmemoized version, primarily used for testing.\n *\n * @param hexAddress - The hex address to encode.\n * @returns The address encoded according to ERC-55.\n * @see https://eips.ethereum.org/EIPS/eip-55\n */\nexport function getChecksumAddressUnmemoized(hexAddress: Hex): Hex {\n assert(is(hexAddress, HexChecksumAddressStruct), 'Invalid hex address.');\n const address = remove0x(hexAddress).toLowerCase();\n\n const hashBytes = keccak256(address);\n const { length } = address;\n const result = new Array(length); // Pre-allocate array\n\n for (let i = 0; i < length; i++) {\n /* eslint-disable no-bitwise */\n const byteIndex = i >> 1; // Faster than Math.floor(i / 2)\n const nibbleIndex = i & 1; // Faster than i % 2\n const byte = hashBytes[byteIndex] as number;\n const nibble = nibbleIndex === 0 ? byte >> 4 : byte & 0x0f;\n /* eslint-enable no-bitwise */\n\n result[i] = nibble >= 8 ? (address[i] as string).toUpperCase() : address[i];\n }\n\n return `0x${result.join('')}`;\n}\n\n/**\n * Encode a passed hex string as an ERC-55 mixed-case checksum address.\n * This function is memoized for performance.\n *\n * @param hexAddress - The hex address to encode.\n * @returns The address encoded according to ERC-55.\n * @see https://eips.ethereum.org/EIPS/eip-55\n */\nexport const getChecksumAddress = memoize(getChecksumAddressUnmemoized);\n\n/**\n * Validate that the passed hex string is a valid ERC-55 mixed-case\n * checksum address.\n *\n * @param possibleChecksum - The hex address to check.\n * @returns True if the address is a checksum address.\n */\nexport function isValidChecksumAddress(possibleChecksum: Hex) {\n if (!is(possibleChecksum, HexChecksumAddressStruct)) {\n return false;\n }\n\n return getChecksumAddress(possibleChecksum) === possibleChecksum;\n}\n\n/**\n * Add the `0x`-prefix to a hexadecimal string. If the string already has the\n * prefix, it is returned as-is.\n *\n * @param hexadecimal - The hexadecimal string to add the prefix to.\n * @returns The prefixed hexadecimal string.\n */\nexport function add0x(hexadecimal: string): Hex {\n if (hexadecimal.startsWith('0x')) {\n return hexadecimal as Hex;\n }\n\n if (hexadecimal.startsWith('0X')) {\n return `0x${hexadecimal.substring(2)}`;\n }\n\n return `0x${hexadecimal}`;\n}\n\n/**\n * Remove the `0x`-prefix from a hexadecimal string. If the string doesn't have\n * the prefix, it is returned as-is.\n *\n * @param hexadecimal - The hexadecimal string to remove the prefix from.\n * @returns The un-prefixed hexadecimal string.\n */\nexport function remove0x(hexadecimal: string): string {\n if (hexadecimal.startsWith('0x') || hexadecimal.startsWith('0X')) {\n return hexadecimal.substring(2);\n }\n\n return hexadecimal;\n}\n"]}
|
|
1
|
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AAO,KAAK,WAAW,EAAE,CAAC;AAC5B,CAAC;AAVD,sBAUC;AAED;;;;;;GAMG;AACH,SAAgB,QAAQ,CAAC,WAAmB;IAC1C,IAAI,WAAW,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,WAAW,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE;QAChE,OAAO,WAAW,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;KACjC;IAED,OAAO,WAAW,CAAC;AACrB,CAAC;AAND,4BAMC","sourcesContent":["import { pattern, type Struct, string } from '@metamask/superstruct';\nimport { keccak_256 as keccak256 } from '@noble/hashes/sha3';\nimport { memoize } from 'lodash';\n\nimport { assert } from './assert';\n\nexport type Hex = `0x${string}`;\n\n// Use native regexes instead of superstruct for maximum performance.\n// Pre-compiled regex for maximum performance - avoids recompilation on each call\nconst HEX_REGEX = /^(?:0x)?[0-9a-f]+$/iu;\nconst STRICT_HEX_REGEX = /^0x[0-9a-f]+$/iu;\nconst HEX_ADDRESS_REGEX = /^0x[0-9a-f]{40}$/u;\nconst HEX_CHECKSUM_ADDRESS_REGEX = /^0x[0-9a-fA-F]{40}$/u;\n\nexport const HexStruct = pattern(string(), HEX_REGEX);\nexport const StrictHexStruct = pattern(string(), STRICT_HEX_REGEX) as Struct<\n Hex,\n null\n>;\nexport const HexAddressStruct = pattern(string(), HEX_ADDRESS_REGEX) as Struct<\n Hex,\n null\n>;\nexport const HexChecksumAddressStruct = pattern(\n string(),\n HEX_CHECKSUM_ADDRESS_REGEX,\n) as Struct<Hex, null>;\n\nconst isString = (value: unknown): value is string => typeof value === 'string';\n\n/**\n * Check if a string is a valid hex string.\n *\n * @param value - The value to check.\n * @returns Whether the value is a valid hex string.\n */\nexport function isHexString(value: unknown): value is string {\n return isString(value) && HEX_REGEX.test(value);\n}\n\n/**\n * Strictly check if a string is a valid hex string. A valid hex string must\n * start with the \"0x\"-prefix.\n *\n * @param value - The value to check.\n * @returns Whether the value is a valid hex string.\n */\nexport function isStrictHexString(value: unknown): value is Hex {\n return isString(value) && STRICT_HEX_REGEX.test(value);\n}\n\n/**\n * Check if a string is a valid hex address.\n *\n * @param value - The value to check.\n * @returns Whether the value is a valid hex address.\n */\nexport function isHexAddress(value: unknown): value is Hex {\n return isString(value) && HEX_ADDRESS_REGEX.test(value);\n}\n\n/**\n * Check if a string is a valid hex checksum address.\n *\n * @param value - The value to check.\n * @returns Whether the value is a valid hex checksum address.\n */\nexport function isHexChecksumAddress(value: unknown): value is Hex {\n return isString(value) && HEX_CHECKSUM_ADDRESS_REGEX.test(value);\n}\n\n/**\n * Assert that a value is a valid hex string.\n *\n * @param value - The value to check.\n * @throws If the value is not a valid hex string.\n */\nexport function assertIsHexString(value: unknown): asserts value is string {\n assert(isHexString(value), 'Value must be a hexadecimal string.');\n}\n\n/**\n * Assert that a value is a valid hex string. A valid hex string must start with\n * the \"0x\"-prefix.\n *\n * @param value - The value to check.\n * @throws If the value is not a valid hex string.\n */\nexport function assertIsStrictHexString(value: unknown): asserts value is Hex {\n assert(\n isStrictHexString(value),\n 'Value must be a hexadecimal string, starting with \"0x\".',\n );\n}\n\n/**\n * Encode a passed hex string as an ERC-55 mixed-case checksum address.\n * This is the unmemoized version, primarily used for testing.\n *\n * @param hexAddress - The hex address to encode.\n * @returns The address encoded according to ERC-55.\n * @see https://eips.ethereum.org/EIPS/eip-55\n */\nexport function getChecksumAddressUnmemoized(hexAddress: Hex): Hex {\n assert(isHexChecksumAddress(hexAddress), 'Invalid hex address.');\n const address = remove0x(hexAddress).toLowerCase();\n\n const hashBytes = keccak256(address);\n const { length } = address;\n const result = new Array(length); // Pre-allocate array\n\n for (let i = 0; i < length; i++) {\n /* eslint-disable no-bitwise */\n const byteIndex = i >> 1; // Faster than Math.floor(i / 2)\n const nibbleIndex = i & 1; // Faster than i % 2\n const byte = hashBytes[byteIndex] as number;\n const nibble = nibbleIndex === 0 ? byte >> 4 : byte & 0x0f;\n /* eslint-enable no-bitwise */\n\n result[i] = nibble >= 8 ? (address[i] as string).toUpperCase() : address[i];\n }\n\n return `0x${result.join('')}`;\n}\n\n/**\n * Encode a passed hex string as an ERC-55 mixed-case checksum address.\n * This function is memoized for performance.\n *\n * @param hexAddress - The hex address to encode.\n * @returns The address encoded according to ERC-55.\n * @see https://eips.ethereum.org/EIPS/eip-55\n */\nexport const getChecksumAddress = memoize(getChecksumAddressUnmemoized);\n\n/**\n * Validate that the passed hex string is a valid ERC-55 mixed-case\n * checksum address.\n *\n * @param possibleChecksum - The hex address to check.\n * @returns True if the address is a checksum address.\n */\nexport function isValidChecksumAddressUnmemoized(possibleChecksum: Hex) {\n if (!isHexChecksumAddress(possibleChecksum)) {\n return false;\n }\n\n return getChecksumAddress(possibleChecksum) === possibleChecksum;\n}\n\n/**\n * Validate that the passed hex string is a valid ERC-55 mixed-case\n * checksum address.\n *\n * @param possibleChecksum - The hex address to check.\n * @returns True if the address is a checksum address.\n */\nexport const isValidChecksumAddress = memoize(isValidChecksumAddressUnmemoized);\n\n/**\n * Validate that the passed prefixed hex string is an all-lowercase\n * hex address, or a valid mixed-case checksum address.\n *\n * @param possibleAddress - Input parameter to check against.\n * @returns Whether or not the input is a valid hex address.\n */\nexport function isValidHexAddressUnmemoized(possibleAddress: Hex) {\n return (\n isHexAddress(possibleAddress) || isValidChecksumAddress(possibleAddress)\n );\n}\n\n/**\n * Validate that the passed prefixed hex string is an all-lowercase\n * hex address, or a valid mixed-case checksum address.\n *\n * @param possibleAddress - Input parameter to check against.\n * @returns Whether or not the input is a valid hex address.\n */\nexport const isValidHexAddress = memoize(isValidHexAddressUnmemoized);\n\n/**\n * Add the `0x`-prefix to a hexadecimal string. If the string already has the\n * prefix, it is returned as-is.\n *\n * @param hexadecimal - The hexadecimal string to add the prefix to.\n * @returns The prefixed hexadecimal string.\n */\nexport function add0x(hexadecimal: string): Hex {\n if (hexadecimal.startsWith('0x')) {\n return hexadecimal as Hex;\n }\n\n if (hexadecimal.startsWith('0X')) {\n return `0x${hexadecimal.substring(2)}`;\n }\n\n return `0x${hexadecimal}`;\n}\n\n/**\n * Remove the `0x`-prefix from a hexadecimal string. If the string doesn't have\n * the prefix, it is returned as-is.\n *\n * @param hexadecimal - The hexadecimal string to remove the prefix from.\n * @returns The un-prefixed hexadecimal string.\n */\nexport function remove0x(hexadecimal: string): string {\n if (hexadecimal.startsWith('0x') || hexadecimal.startsWith('0X')) {\n return hexadecimal.substring(2);\n }\n\n return hexadecimal;\n}\n"]}
|
package/dist/hex.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="lodash" />
|
|
2
|
-
import type
|
|
2
|
+
import { type Struct } from "@metamask/superstruct";
|
|
3
3
|
export type Hex = `0x${string}`;
|
|
4
4
|
export declare const HexStruct: Struct<string, null>;
|
|
5
5
|
export declare const StrictHexStruct: Struct<`0x${string}`, null>;
|
|
@@ -20,6 +20,20 @@ export declare function isHexString(value: unknown): value is string;
|
|
|
20
20
|
* @returns Whether the value is a valid hex string.
|
|
21
21
|
*/
|
|
22
22
|
export declare function isStrictHexString(value: unknown): value is Hex;
|
|
23
|
+
/**
|
|
24
|
+
* Check if a string is a valid hex address.
|
|
25
|
+
*
|
|
26
|
+
* @param value - The value to check.
|
|
27
|
+
* @returns Whether the value is a valid hex address.
|
|
28
|
+
*/
|
|
29
|
+
export declare function isHexAddress(value: unknown): value is Hex;
|
|
30
|
+
/**
|
|
31
|
+
* Check if a string is a valid hex checksum address.
|
|
32
|
+
*
|
|
33
|
+
* @param value - The value to check.
|
|
34
|
+
* @returns Whether the value is a valid hex checksum address.
|
|
35
|
+
*/
|
|
36
|
+
export declare function isHexChecksumAddress(value: unknown): value is Hex;
|
|
23
37
|
/**
|
|
24
38
|
* Assert that a value is a valid hex string.
|
|
25
39
|
*
|
|
@@ -35,14 +49,6 @@ export declare function assertIsHexString(value: unknown): asserts value is stri
|
|
|
35
49
|
* @throws If the value is not a valid hex string.
|
|
36
50
|
*/
|
|
37
51
|
export declare function assertIsStrictHexString(value: unknown): asserts value is Hex;
|
|
38
|
-
/**
|
|
39
|
-
* Validate that the passed prefixed hex string is an all-lowercase
|
|
40
|
-
* hex address, or a valid mixed-case checksum address.
|
|
41
|
-
*
|
|
42
|
-
* @param possibleAddress - Input parameter to check against.
|
|
43
|
-
* @returns Whether or not the input is a valid hex address.
|
|
44
|
-
*/
|
|
45
|
-
export declare function isValidHexAddress(possibleAddress: Hex): boolean;
|
|
46
52
|
/**
|
|
47
53
|
* Encode a passed hex string as an ERC-55 mixed-case checksum address.
|
|
48
54
|
* This is the unmemoized version, primarily used for testing.
|
|
@@ -68,7 +74,31 @@ export declare const getChecksumAddress: typeof getChecksumAddressUnmemoized & i
|
|
|
68
74
|
* @param possibleChecksum - The hex address to check.
|
|
69
75
|
* @returns True if the address is a checksum address.
|
|
70
76
|
*/
|
|
71
|
-
export declare function
|
|
77
|
+
export declare function isValidChecksumAddressUnmemoized(possibleChecksum: Hex): boolean;
|
|
78
|
+
/**
|
|
79
|
+
* Validate that the passed hex string is a valid ERC-55 mixed-case
|
|
80
|
+
* checksum address.
|
|
81
|
+
*
|
|
82
|
+
* @param possibleChecksum - The hex address to check.
|
|
83
|
+
* @returns True if the address is a checksum address.
|
|
84
|
+
*/
|
|
85
|
+
export declare const isValidChecksumAddress: typeof isValidChecksumAddressUnmemoized & import("lodash").MemoizedFunction;
|
|
86
|
+
/**
|
|
87
|
+
* Validate that the passed prefixed hex string is an all-lowercase
|
|
88
|
+
* hex address, or a valid mixed-case checksum address.
|
|
89
|
+
*
|
|
90
|
+
* @param possibleAddress - Input parameter to check against.
|
|
91
|
+
* @returns Whether or not the input is a valid hex address.
|
|
92
|
+
*/
|
|
93
|
+
export declare function isValidHexAddressUnmemoized(possibleAddress: Hex): boolean;
|
|
94
|
+
/**
|
|
95
|
+
* Validate that the passed prefixed hex string is an all-lowercase
|
|
96
|
+
* hex address, or a valid mixed-case checksum address.
|
|
97
|
+
*
|
|
98
|
+
* @param possibleAddress - Input parameter to check against.
|
|
99
|
+
* @returns Whether or not the input is a valid hex address.
|
|
100
|
+
*/
|
|
101
|
+
export declare const isValidHexAddress: typeof isValidHexAddressUnmemoized & import("lodash").MemoizedFunction;
|
|
72
102
|
/**
|
|
73
103
|
* Add the `0x`-prefix to a hexadecimal string. If the string already has the
|
|
74
104
|
* prefix, it is returned as-is.
|
package/dist/hex.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hex.d.cts","sourceRoot":"","sources":["../src/hex.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"hex.d.cts","sourceRoot":"","sources":["../src/hex.ts"],"names":[],"mappings":";AAAA,OAAO,EAAW,KAAK,MAAM,EAAU,8BAA8B;AAMrE,MAAM,MAAM,GAAG,GAAG,KAAK,MAAM,EAAE,CAAC;AAShC,eAAO,MAAM,SAAS,sBAA+B,CAAC;AACtD,eAAO,MAAM,eAAe,6BAG3B,CAAC;AACF,eAAO,MAAM,gBAAgB,6BAG5B,CAAC;AACF,eAAO,MAAM,wBAAwB,6BAGf,CAAC;AAIvB;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAE3D;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,GAAG,CAE9D;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,GAAG,CAEzD;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,GAAG,CAEjE;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,KAAK,IAAI,MAAM,CAEzE;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,KAAK,IAAI,GAAG,CAK5E;AAED;;;;;;;GAOG;AACH,wBAAgB,4BAA4B,CAAC,UAAU,EAAE,GAAG,GAAG,GAAG,CAoBjE;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,kBAAkB,yEAAwC,CAAC;AAExE;;;;;;GAMG;AACH,wBAAgB,gCAAgC,CAAC,gBAAgB,EAAE,GAAG,WAMrE;AAED;;;;;;GAMG;AACH,eAAO,MAAM,sBAAsB,6EAA4C,CAAC;AAEhF;;;;;;GAMG;AACH,wBAAgB,2BAA2B,CAAC,eAAe,EAAE,GAAG,WAI/D;AAED;;;;;;GAMG;AACH,eAAO,MAAM,iBAAiB,wEAAuC,CAAC;AAEtE;;;;;;GAMG;AACH,wBAAgB,KAAK,CAAC,WAAW,EAAE,MAAM,GAAG,GAAG,CAU9C;AAED;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAMpD"}
|
package/dist/hex.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="lodash" />
|
|
2
|
-
import type
|
|
2
|
+
import { type Struct } from "@metamask/superstruct";
|
|
3
3
|
export type Hex = `0x${string}`;
|
|
4
4
|
export declare const HexStruct: Struct<string, null>;
|
|
5
5
|
export declare const StrictHexStruct: Struct<`0x${string}`, null>;
|
|
@@ -20,6 +20,20 @@ export declare function isHexString(value: unknown): value is string;
|
|
|
20
20
|
* @returns Whether the value is a valid hex string.
|
|
21
21
|
*/
|
|
22
22
|
export declare function isStrictHexString(value: unknown): value is Hex;
|
|
23
|
+
/**
|
|
24
|
+
* Check if a string is a valid hex address.
|
|
25
|
+
*
|
|
26
|
+
* @param value - The value to check.
|
|
27
|
+
* @returns Whether the value is a valid hex address.
|
|
28
|
+
*/
|
|
29
|
+
export declare function isHexAddress(value: unknown): value is Hex;
|
|
30
|
+
/**
|
|
31
|
+
* Check if a string is a valid hex checksum address.
|
|
32
|
+
*
|
|
33
|
+
* @param value - The value to check.
|
|
34
|
+
* @returns Whether the value is a valid hex checksum address.
|
|
35
|
+
*/
|
|
36
|
+
export declare function isHexChecksumAddress(value: unknown): value is Hex;
|
|
23
37
|
/**
|
|
24
38
|
* Assert that a value is a valid hex string.
|
|
25
39
|
*
|
|
@@ -35,14 +49,6 @@ export declare function assertIsHexString(value: unknown): asserts value is stri
|
|
|
35
49
|
* @throws If the value is not a valid hex string.
|
|
36
50
|
*/
|
|
37
51
|
export declare function assertIsStrictHexString(value: unknown): asserts value is Hex;
|
|
38
|
-
/**
|
|
39
|
-
* Validate that the passed prefixed hex string is an all-lowercase
|
|
40
|
-
* hex address, or a valid mixed-case checksum address.
|
|
41
|
-
*
|
|
42
|
-
* @param possibleAddress - Input parameter to check against.
|
|
43
|
-
* @returns Whether or not the input is a valid hex address.
|
|
44
|
-
*/
|
|
45
|
-
export declare function isValidHexAddress(possibleAddress: Hex): boolean;
|
|
46
52
|
/**
|
|
47
53
|
* Encode a passed hex string as an ERC-55 mixed-case checksum address.
|
|
48
54
|
* This is the unmemoized version, primarily used for testing.
|
|
@@ -68,7 +74,31 @@ export declare const getChecksumAddress: typeof getChecksumAddressUnmemoized & i
|
|
|
68
74
|
* @param possibleChecksum - The hex address to check.
|
|
69
75
|
* @returns True if the address is a checksum address.
|
|
70
76
|
*/
|
|
71
|
-
export declare function
|
|
77
|
+
export declare function isValidChecksumAddressUnmemoized(possibleChecksum: Hex): boolean;
|
|
78
|
+
/**
|
|
79
|
+
* Validate that the passed hex string is a valid ERC-55 mixed-case
|
|
80
|
+
* checksum address.
|
|
81
|
+
*
|
|
82
|
+
* @param possibleChecksum - The hex address to check.
|
|
83
|
+
* @returns True if the address is a checksum address.
|
|
84
|
+
*/
|
|
85
|
+
export declare const isValidChecksumAddress: typeof isValidChecksumAddressUnmemoized & import("lodash").MemoizedFunction;
|
|
86
|
+
/**
|
|
87
|
+
* Validate that the passed prefixed hex string is an all-lowercase
|
|
88
|
+
* hex address, or a valid mixed-case checksum address.
|
|
89
|
+
*
|
|
90
|
+
* @param possibleAddress - Input parameter to check against.
|
|
91
|
+
* @returns Whether or not the input is a valid hex address.
|
|
92
|
+
*/
|
|
93
|
+
export declare function isValidHexAddressUnmemoized(possibleAddress: Hex): boolean;
|
|
94
|
+
/**
|
|
95
|
+
* Validate that the passed prefixed hex string is an all-lowercase
|
|
96
|
+
* hex address, or a valid mixed-case checksum address.
|
|
97
|
+
*
|
|
98
|
+
* @param possibleAddress - Input parameter to check against.
|
|
99
|
+
* @returns Whether or not the input is a valid hex address.
|
|
100
|
+
*/
|
|
101
|
+
export declare const isValidHexAddress: typeof isValidHexAddressUnmemoized & import("lodash").MemoizedFunction;
|
|
72
102
|
/**
|
|
73
103
|
* Add the `0x`-prefix to a hexadecimal string. If the string already has the
|
|
74
104
|
* prefix, it is returned as-is.
|
package/dist/hex.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hex.d.mts","sourceRoot":"","sources":["../src/hex.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"hex.d.mts","sourceRoot":"","sources":["../src/hex.ts"],"names":[],"mappings":";AAAA,OAAO,EAAW,KAAK,MAAM,EAAU,8BAA8B;AAMrE,MAAM,MAAM,GAAG,GAAG,KAAK,MAAM,EAAE,CAAC;AAShC,eAAO,MAAM,SAAS,sBAA+B,CAAC;AACtD,eAAO,MAAM,eAAe,6BAG3B,CAAC;AACF,eAAO,MAAM,gBAAgB,6BAG5B,CAAC;AACF,eAAO,MAAM,wBAAwB,6BAGf,CAAC;AAIvB;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAE3D;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,GAAG,CAE9D;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,GAAG,CAEzD;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,GAAG,CAEjE;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,KAAK,IAAI,MAAM,CAEzE;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,KAAK,IAAI,GAAG,CAK5E;AAED;;;;;;;GAOG;AACH,wBAAgB,4BAA4B,CAAC,UAAU,EAAE,GAAG,GAAG,GAAG,CAoBjE;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,kBAAkB,yEAAwC,CAAC;AAExE;;;;;;GAMG;AACH,wBAAgB,gCAAgC,CAAC,gBAAgB,EAAE,GAAG,WAMrE;AAED;;;;;;GAMG;AACH,eAAO,MAAM,sBAAsB,6EAA4C,CAAC;AAEhF;;;;;;GAMG;AACH,wBAAgB,2BAA2B,CAAC,eAAe,EAAE,GAAG,WAI/D;AAED;;;;;;GAMG;AACH,eAAO,MAAM,iBAAiB,wEAAuC,CAAC;AAEtE;;;;;;GAMG;AACH,wBAAgB,KAAK,CAAC,WAAW,EAAE,MAAM,GAAG,GAAG,CAU9C;AAED;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAMpD"}
|
package/dist/hex.mjs
CHANGED
|
@@ -1,11 +1,19 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { pattern, string } from "@metamask/superstruct";
|
|
2
2
|
import { keccak_256 as keccak256 } from "@noble/hashes/sha3";
|
|
3
|
-
import
|
|
3
|
+
import $lodash from "lodash";
|
|
4
|
+
const { memoize } = $lodash;
|
|
4
5
|
import { assert } from "./assert.mjs";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
// Use native regexes instead of superstruct for maximum performance.
|
|
7
|
+
// Pre-compiled regex for maximum performance - avoids recompilation on each call
|
|
8
|
+
const HEX_REGEX = /^(?:0x)?[0-9a-f]+$/iu;
|
|
9
|
+
const STRICT_HEX_REGEX = /^0x[0-9a-f]+$/iu;
|
|
10
|
+
const HEX_ADDRESS_REGEX = /^0x[0-9a-f]{40}$/u;
|
|
11
|
+
const HEX_CHECKSUM_ADDRESS_REGEX = /^0x[0-9a-fA-F]{40}$/u;
|
|
12
|
+
export const HexStruct = pattern(string(), HEX_REGEX);
|
|
13
|
+
export const StrictHexStruct = pattern(string(), STRICT_HEX_REGEX);
|
|
14
|
+
export const HexAddressStruct = pattern(string(), HEX_ADDRESS_REGEX);
|
|
15
|
+
export const HexChecksumAddressStruct = pattern(string(), HEX_CHECKSUM_ADDRESS_REGEX);
|
|
16
|
+
const isString = (value) => typeof value === 'string';
|
|
9
17
|
/**
|
|
10
18
|
* Check if a string is a valid hex string.
|
|
11
19
|
*
|
|
@@ -13,7 +21,7 @@ export const HexChecksumAddressStruct = pattern(string(), /^0x[0-9a-fA-F]{40}$/u
|
|
|
13
21
|
* @returns Whether the value is a valid hex string.
|
|
14
22
|
*/
|
|
15
23
|
export function isHexString(value) {
|
|
16
|
-
return
|
|
24
|
+
return isString(value) && HEX_REGEX.test(value);
|
|
17
25
|
}
|
|
18
26
|
/**
|
|
19
27
|
* Strictly check if a string is a valid hex string. A valid hex string must
|
|
@@ -23,7 +31,25 @@ export function isHexString(value) {
|
|
|
23
31
|
* @returns Whether the value is a valid hex string.
|
|
24
32
|
*/
|
|
25
33
|
export function isStrictHexString(value) {
|
|
26
|
-
return
|
|
34
|
+
return isString(value) && STRICT_HEX_REGEX.test(value);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Check if a string is a valid hex address.
|
|
38
|
+
*
|
|
39
|
+
* @param value - The value to check.
|
|
40
|
+
* @returns Whether the value is a valid hex address.
|
|
41
|
+
*/
|
|
42
|
+
export function isHexAddress(value) {
|
|
43
|
+
return isString(value) && HEX_ADDRESS_REGEX.test(value);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Check if a string is a valid hex checksum address.
|
|
47
|
+
*
|
|
48
|
+
* @param value - The value to check.
|
|
49
|
+
* @returns Whether the value is a valid hex checksum address.
|
|
50
|
+
*/
|
|
51
|
+
export function isHexChecksumAddress(value) {
|
|
52
|
+
return isString(value) && HEX_CHECKSUM_ADDRESS_REGEX.test(value);
|
|
27
53
|
}
|
|
28
54
|
/**
|
|
29
55
|
* Assert that a value is a valid hex string.
|
|
@@ -44,17 +70,6 @@ export function assertIsHexString(value) {
|
|
|
44
70
|
export function assertIsStrictHexString(value) {
|
|
45
71
|
assert(isStrictHexString(value), 'Value must be a hexadecimal string, starting with "0x".');
|
|
46
72
|
}
|
|
47
|
-
/**
|
|
48
|
-
* Validate that the passed prefixed hex string is an all-lowercase
|
|
49
|
-
* hex address, or a valid mixed-case checksum address.
|
|
50
|
-
*
|
|
51
|
-
* @param possibleAddress - Input parameter to check against.
|
|
52
|
-
* @returns Whether or not the input is a valid hex address.
|
|
53
|
-
*/
|
|
54
|
-
export function isValidHexAddress(possibleAddress) {
|
|
55
|
-
return (is(possibleAddress, HexAddressStruct) ||
|
|
56
|
-
isValidChecksumAddress(possibleAddress));
|
|
57
|
-
}
|
|
58
73
|
/**
|
|
59
74
|
* Encode a passed hex string as an ERC-55 mixed-case checksum address.
|
|
60
75
|
* This is the unmemoized version, primarily used for testing.
|
|
@@ -64,7 +79,7 @@ export function isValidHexAddress(possibleAddress) {
|
|
|
64
79
|
* @see https://eips.ethereum.org/EIPS/eip-55
|
|
65
80
|
*/
|
|
66
81
|
export function getChecksumAddressUnmemoized(hexAddress) {
|
|
67
|
-
assert(
|
|
82
|
+
assert(isHexChecksumAddress(hexAddress), 'Invalid hex address.');
|
|
68
83
|
const address = remove0x(hexAddress).toLowerCase();
|
|
69
84
|
const hashBytes = keccak256(address);
|
|
70
85
|
const { length } = address;
|
|
@@ -96,12 +111,38 @@ export const getChecksumAddress = memoize(getChecksumAddressUnmemoized);
|
|
|
96
111
|
* @param possibleChecksum - The hex address to check.
|
|
97
112
|
* @returns True if the address is a checksum address.
|
|
98
113
|
*/
|
|
99
|
-
export function
|
|
100
|
-
if (!
|
|
114
|
+
export function isValidChecksumAddressUnmemoized(possibleChecksum) {
|
|
115
|
+
if (!isHexChecksumAddress(possibleChecksum)) {
|
|
101
116
|
return false;
|
|
102
117
|
}
|
|
103
118
|
return getChecksumAddress(possibleChecksum) === possibleChecksum;
|
|
104
119
|
}
|
|
120
|
+
/**
|
|
121
|
+
* Validate that the passed hex string is a valid ERC-55 mixed-case
|
|
122
|
+
* checksum address.
|
|
123
|
+
*
|
|
124
|
+
* @param possibleChecksum - The hex address to check.
|
|
125
|
+
* @returns True if the address is a checksum address.
|
|
126
|
+
*/
|
|
127
|
+
export const isValidChecksumAddress = memoize(isValidChecksumAddressUnmemoized);
|
|
128
|
+
/**
|
|
129
|
+
* Validate that the passed prefixed hex string is an all-lowercase
|
|
130
|
+
* hex address, or a valid mixed-case checksum address.
|
|
131
|
+
*
|
|
132
|
+
* @param possibleAddress - Input parameter to check against.
|
|
133
|
+
* @returns Whether or not the input is a valid hex address.
|
|
134
|
+
*/
|
|
135
|
+
export function isValidHexAddressUnmemoized(possibleAddress) {
|
|
136
|
+
return (isHexAddress(possibleAddress) || isValidChecksumAddress(possibleAddress));
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Validate that the passed prefixed hex string is an all-lowercase
|
|
140
|
+
* hex address, or a valid mixed-case checksum address.
|
|
141
|
+
*
|
|
142
|
+
* @param possibleAddress - Input parameter to check against.
|
|
143
|
+
* @returns Whether or not the input is a valid hex address.
|
|
144
|
+
*/
|
|
145
|
+
export const isValidHexAddress = memoize(isValidHexAddressUnmemoized);
|
|
105
146
|
/**
|
|
106
147
|
* Add the `0x`-prefix to a hexadecimal string. If the string already has the
|
|
107
148
|
* prefix, it is returned as-is.
|
package/dist/hex.mjs.map
CHANGED
|
@@ -1 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,MAAM,UAAU,sBAAsB,CAAC,gBAAqB;IAC1D,IAAI,CAAC,EAAE,CAAC,gBAAgB,EAAE,wBAAwB,CAAC,EAAE;QACnD,OAAO,KAAK,CAAC;KACd;IAED,OAAO,kBAAkB,CAAC,gBAAgB,CAAC,KAAK,gBAAgB,CAAC;AACnE,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,KAAK,CAAC,WAAmB;IACvC,IAAI,WAAW,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE;QAChC,OAAO,WAAkB,CAAC;KAC3B;IAED,IAAI,WAAW,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE;QAChC,OAAO,KAAK,WAAW,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC;KACxC;IAED,OAAO,KAAK,WAAW,EAAE,CAAC;AAC5B,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,QAAQ,CAAC,WAAmB;IAC1C,IAAI,WAAW,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,WAAW,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE;QAChE,OAAO,WAAW,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;KACjC;IAED,OAAO,WAAW,CAAC;AACrB,CAAC","sourcesContent":["import type { Struct } from '@metamask/superstruct';\nimport { is, pattern, string } from '@metamask/superstruct';\nimport { keccak_256 as keccak256 } from '@noble/hashes/sha3';\nimport memoize from 'lodash.memoize';\n\nimport { assert } from './assert';\n\nexport type Hex = `0x${string}`;\n\nexport const HexStruct = pattern(string(), /^(?:0x)?[0-9a-f]+$/iu);\nexport const StrictHexStruct = pattern(string(), /^0x[0-9a-f]+$/iu) as Struct<\n Hex,\n null\n>;\nexport const HexAddressStruct = pattern(\n string(),\n /^0x[0-9a-f]{40}$/u,\n) as Struct<Hex, null>;\nexport const HexChecksumAddressStruct = pattern(\n string(),\n /^0x[0-9a-fA-F]{40}$/u,\n) as Struct<Hex, null>;\n\n/**\n * Check if a string is a valid hex string.\n *\n * @param value - The value to check.\n * @returns Whether the value is a valid hex string.\n */\nexport function isHexString(value: unknown): value is string {\n return is(value, HexStruct);\n}\n\n/**\n * Strictly check if a string is a valid hex string. A valid hex string must\n * start with the \"0x\"-prefix.\n *\n * @param value - The value to check.\n * @returns Whether the value is a valid hex string.\n */\nexport function isStrictHexString(value: unknown): value is Hex {\n return is(value, StrictHexStruct);\n}\n\n/**\n * Assert that a value is a valid hex string.\n *\n * @param value - The value to check.\n * @throws If the value is not a valid hex string.\n */\nexport function assertIsHexString(value: unknown): asserts value is string {\n assert(isHexString(value), 'Value must be a hexadecimal string.');\n}\n\n/**\n * Assert that a value is a valid hex string. A valid hex string must start with\n * the \"0x\"-prefix.\n *\n * @param value - The value to check.\n * @throws If the value is not a valid hex string.\n */\nexport function assertIsStrictHexString(value: unknown): asserts value is Hex {\n assert(\n isStrictHexString(value),\n 'Value must be a hexadecimal string, starting with \"0x\".',\n );\n}\n\n/**\n * Validate that the passed prefixed hex string is an all-lowercase\n * hex address, or a valid mixed-case checksum address.\n *\n * @param possibleAddress - Input parameter to check against.\n * @returns Whether or not the input is a valid hex address.\n */\nexport function isValidHexAddress(possibleAddress: Hex) {\n return (\n is(possibleAddress, HexAddressStruct) ||\n isValidChecksumAddress(possibleAddress)\n );\n}\n\n/**\n * Encode a passed hex string as an ERC-55 mixed-case checksum address.\n * This is the unmemoized version, primarily used for testing.\n *\n * @param hexAddress - The hex address to encode.\n * @returns The address encoded according to ERC-55.\n * @see https://eips.ethereum.org/EIPS/eip-55\n */\nexport function getChecksumAddressUnmemoized(hexAddress: Hex): Hex {\n assert(is(hexAddress, HexChecksumAddressStruct), 'Invalid hex address.');\n const address = remove0x(hexAddress).toLowerCase();\n\n const hashBytes = keccak256(address);\n const { length } = address;\n const result = new Array(length); // Pre-allocate array\n\n for (let i = 0; i < length; i++) {\n /* eslint-disable no-bitwise */\n const byteIndex = i >> 1; // Faster than Math.floor(i / 2)\n const nibbleIndex = i & 1; // Faster than i % 2\n const byte = hashBytes[byteIndex] as number;\n const nibble = nibbleIndex === 0 ? byte >> 4 : byte & 0x0f;\n /* eslint-enable no-bitwise */\n\n result[i] = nibble >= 8 ? (address[i] as string).toUpperCase() : address[i];\n }\n\n return `0x${result.join('')}`;\n}\n\n/**\n * Encode a passed hex string as an ERC-55 mixed-case checksum address.\n * This function is memoized for performance.\n *\n * @param hexAddress - The hex address to encode.\n * @returns The address encoded according to ERC-55.\n * @see https://eips.ethereum.org/EIPS/eip-55\n */\nexport const getChecksumAddress = memoize(getChecksumAddressUnmemoized);\n\n/**\n * Validate that the passed hex string is a valid ERC-55 mixed-case\n * checksum address.\n *\n * @param possibleChecksum - The hex address to check.\n * @returns True if the address is a checksum address.\n */\nexport function isValidChecksumAddress(possibleChecksum: Hex) {\n if (!is(possibleChecksum, HexChecksumAddressStruct)) {\n return false;\n }\n\n return getChecksumAddress(possibleChecksum) === possibleChecksum;\n}\n\n/**\n * Add the `0x`-prefix to a hexadecimal string. If the string already has the\n * prefix, it is returned as-is.\n *\n * @param hexadecimal - The hexadecimal string to add the prefix to.\n * @returns The prefixed hexadecimal string.\n */\nexport function add0x(hexadecimal: string): Hex {\n if (hexadecimal.startsWith('0x')) {\n return hexadecimal as Hex;\n }\n\n if (hexadecimal.startsWith('0X')) {\n return `0x${hexadecimal.substring(2)}`;\n }\n\n return `0x${hexadecimal}`;\n}\n\n/**\n * Remove the `0x`-prefix from a hexadecimal string. If the string doesn't have\n * the prefix, it is returned as-is.\n *\n * @param hexadecimal - The hexadecimal string to remove the prefix from.\n * @returns The un-prefixed hexadecimal string.\n */\nexport function remove0x(hexadecimal: string): string {\n if (hexadecimal.startsWith('0x') || hexadecimal.startsWith('0X')) {\n return hexadecimal.substring(2);\n }\n\n return hexadecimal;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"hex.mjs","sourceRoot":"","sources":["../src/hex.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAe,MAAM,EAAE,8BAA8B;AACrE,OAAO,EAAE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AAW,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE;QAChE,OAAO,WAAW,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;KACjC;IAED,OAAO,WAAW,CAAC;AACrB,CAAC","sourcesContent":["import { pattern, type Struct, string } from '@metamask/superstruct';\nimport { keccak_256 as keccak256 } from '@noble/hashes/sha3';\nimport { memoize } from 'lodash';\n\nimport { assert } from './assert';\n\nexport type Hex = `0x${string}`;\n\n// Use native regexes instead of superstruct for maximum performance.\n// Pre-compiled regex for maximum performance - avoids recompilation on each call\nconst HEX_REGEX = /^(?:0x)?[0-9a-f]+$/iu;\nconst STRICT_HEX_REGEX = /^0x[0-9a-f]+$/iu;\nconst HEX_ADDRESS_REGEX = /^0x[0-9a-f]{40}$/u;\nconst HEX_CHECKSUM_ADDRESS_REGEX = /^0x[0-9a-fA-F]{40}$/u;\n\nexport const HexStruct = pattern(string(), HEX_REGEX);\nexport const StrictHexStruct = pattern(string(), STRICT_HEX_REGEX) as Struct<\n Hex,\n null\n>;\nexport const HexAddressStruct = pattern(string(), HEX_ADDRESS_REGEX) as Struct<\n Hex,\n null\n>;\nexport const HexChecksumAddressStruct = pattern(\n string(),\n HEX_CHECKSUM_ADDRESS_REGEX,\n) as Struct<Hex, null>;\n\nconst isString = (value: unknown): value is string => typeof value === 'string';\n\n/**\n * Check if a string is a valid hex string.\n *\n * @param value - The value to check.\n * @returns Whether the value is a valid hex string.\n */\nexport function isHexString(value: unknown): value is string {\n return isString(value) && HEX_REGEX.test(value);\n}\n\n/**\n * Strictly check if a string is a valid hex string. A valid hex string must\n * start with the \"0x\"-prefix.\n *\n * @param value - The value to check.\n * @returns Whether the value is a valid hex string.\n */\nexport function isStrictHexString(value: unknown): value is Hex {\n return isString(value) && STRICT_HEX_REGEX.test(value);\n}\n\n/**\n * Check if a string is a valid hex address.\n *\n * @param value - The value to check.\n * @returns Whether the value is a valid hex address.\n */\nexport function isHexAddress(value: unknown): value is Hex {\n return isString(value) && HEX_ADDRESS_REGEX.test(value);\n}\n\n/**\n * Check if a string is a valid hex checksum address.\n *\n * @param value - The value to check.\n * @returns Whether the value is a valid hex checksum address.\n */\nexport function isHexChecksumAddress(value: unknown): value is Hex {\n return isString(value) && HEX_CHECKSUM_ADDRESS_REGEX.test(value);\n}\n\n/**\n * Assert that a value is a valid hex string.\n *\n * @param value - The value to check.\n * @throws If the value is not a valid hex string.\n */\nexport function assertIsHexString(value: unknown): asserts value is string {\n assert(isHexString(value), 'Value must be a hexadecimal string.');\n}\n\n/**\n * Assert that a value is a valid hex string. A valid hex string must start with\n * the \"0x\"-prefix.\n *\n * @param value - The value to check.\n * @throws If the value is not a valid hex string.\n */\nexport function assertIsStrictHexString(value: unknown): asserts value is Hex {\n assert(\n isStrictHexString(value),\n 'Value must be a hexadecimal string, starting with \"0x\".',\n );\n}\n\n/**\n * Encode a passed hex string as an ERC-55 mixed-case checksum address.\n * This is the unmemoized version, primarily used for testing.\n *\n * @param hexAddress - The hex address to encode.\n * @returns The address encoded according to ERC-55.\n * @see https://eips.ethereum.org/EIPS/eip-55\n */\nexport function getChecksumAddressUnmemoized(hexAddress: Hex): Hex {\n assert(isHexChecksumAddress(hexAddress), 'Invalid hex address.');\n const address = remove0x(hexAddress).toLowerCase();\n\n const hashBytes = keccak256(address);\n const { length } = address;\n const result = new Array(length); // Pre-allocate array\n\n for (let i = 0; i < length; i++) {\n /* eslint-disable no-bitwise */\n const byteIndex = i >> 1; // Faster than Math.floor(i / 2)\n const nibbleIndex = i & 1; // Faster than i % 2\n const byte = hashBytes[byteIndex] as number;\n const nibble = nibbleIndex === 0 ? byte >> 4 : byte & 0x0f;\n /* eslint-enable no-bitwise */\n\n result[i] = nibble >= 8 ? (address[i] as string).toUpperCase() : address[i];\n }\n\n return `0x${result.join('')}`;\n}\n\n/**\n * Encode a passed hex string as an ERC-55 mixed-case checksum address.\n * This function is memoized for performance.\n *\n * @param hexAddress - The hex address to encode.\n * @returns The address encoded according to ERC-55.\n * @see https://eips.ethereum.org/EIPS/eip-55\n */\nexport const getChecksumAddress = memoize(getChecksumAddressUnmemoized);\n\n/**\n * Validate that the passed hex string is a valid ERC-55 mixed-case\n * checksum address.\n *\n * @param possibleChecksum - The hex address to check.\n * @returns True if the address is a checksum address.\n */\nexport function isValidChecksumAddressUnmemoized(possibleChecksum: Hex) {\n if (!isHexChecksumAddress(possibleChecksum)) {\n return false;\n }\n\n return getChecksumAddress(possibleChecksum) === possibleChecksum;\n}\n\n/**\n * Validate that the passed hex string is a valid ERC-55 mixed-case\n * checksum address.\n *\n * @param possibleChecksum - The hex address to check.\n * @returns True if the address is a checksum address.\n */\nexport const isValidChecksumAddress = memoize(isValidChecksumAddressUnmemoized);\n\n/**\n * Validate that the passed prefixed hex string is an all-lowercase\n * hex address, or a valid mixed-case checksum address.\n *\n * @param possibleAddress - Input parameter to check against.\n * @returns Whether or not the input is a valid hex address.\n */\nexport function isValidHexAddressUnmemoized(possibleAddress: Hex) {\n return (\n isHexAddress(possibleAddress) || isValidChecksumAddress(possibleAddress)\n );\n}\n\n/**\n * Validate that the passed prefixed hex string is an all-lowercase\n * hex address, or a valid mixed-case checksum address.\n *\n * @param possibleAddress - Input parameter to check against.\n * @returns Whether or not the input is a valid hex address.\n */\nexport const isValidHexAddress = memoize(isValidHexAddressUnmemoized);\n\n/**\n * Add the `0x`-prefix to a hexadecimal string. If the string already has the\n * prefix, it is returned as-is.\n *\n * @param hexadecimal - The hexadecimal string to add the prefix to.\n * @returns The prefixed hexadecimal string.\n */\nexport function add0x(hexadecimal: string): Hex {\n if (hexadecimal.startsWith('0x')) {\n return hexadecimal as Hex;\n }\n\n if (hexadecimal.startsWith('0X')) {\n return `0x${hexadecimal.substring(2)}`;\n }\n\n return `0x${hexadecimal}`;\n}\n\n/**\n * Remove the `0x`-prefix from a hexadecimal string. If the string doesn't have\n * the prefix, it is returned as-is.\n *\n * @param hexadecimal - The hexadecimal string to remove the prefix from.\n * @returns The un-prefixed hexadecimal string.\n */\nexport function remove0x(hexadecimal: string): string {\n if (hexadecimal.startsWith('0x') || hexadecimal.startsWith('0X')) {\n return hexadecimal.substring(2);\n }\n\n return hexadecimal;\n}\n"]}
|
package/dist/index.cjs
CHANGED
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.remove0x = exports.add0x = exports.isValidChecksumAddress = exports.getChecksumAddress = exports.isValidHexAddress = exports.assertIsStrictHexString = exports.assertIsHexString = exports.isStrictHexString = exports.isHexString = exports.HexChecksumAddressStruct = exports.HexAddressStruct = exports.StrictHexStruct = exports.HexStruct = void 0;
|
|
17
|
+
exports.remove0x = exports.add0x = exports.isValidChecksumAddress = exports.getChecksumAddress = exports.isValidHexAddress = exports.assertIsStrictHexString = exports.assertIsHexString = exports.isHexChecksumAddress = exports.isHexAddress = exports.isStrictHexString = exports.isHexString = exports.HexChecksumAddressStruct = exports.HexAddressStruct = exports.StrictHexStruct = exports.HexStruct = void 0;
|
|
18
18
|
__exportStar(require("./assert.cjs"), exports);
|
|
19
19
|
__exportStar(require("./base64.cjs"), exports);
|
|
20
20
|
__exportStar(require("./bytes.cjs"), exports);
|
|
@@ -31,6 +31,8 @@ Object.defineProperty(exports, "HexAddressStruct", { enumerable: true, get: func
|
|
|
31
31
|
Object.defineProperty(exports, "HexChecksumAddressStruct", { enumerable: true, get: function () { return hex_1.HexChecksumAddressStruct; } });
|
|
32
32
|
Object.defineProperty(exports, "isHexString", { enumerable: true, get: function () { return hex_1.isHexString; } });
|
|
33
33
|
Object.defineProperty(exports, "isStrictHexString", { enumerable: true, get: function () { return hex_1.isStrictHexString; } });
|
|
34
|
+
Object.defineProperty(exports, "isHexAddress", { enumerable: true, get: function () { return hex_1.isHexAddress; } });
|
|
35
|
+
Object.defineProperty(exports, "isHexChecksumAddress", { enumerable: true, get: function () { return hex_1.isHexChecksumAddress; } });
|
|
34
36
|
Object.defineProperty(exports, "assertIsHexString", { enumerable: true, get: function () { return hex_1.assertIsHexString; } });
|
|
35
37
|
Object.defineProperty(exports, "assertIsStrictHexString", { enumerable: true, get: function () { return hex_1.assertIsStrictHexString; } });
|
|
36
38
|
Object.defineProperty(exports, "isValidHexAddress", { enumerable: true, get: function () { return hex_1.isValidHexAddress; } });
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,+CAAyB;AACzB,+CAAyB;AACzB,8CAAwB;AACxB,mDAA6B;AAC7B,iDAA2B;AAC3B,iDAA2B;AAC3B,oDAA8B;AAC9B,yDAAmC;AACnC,+CAAyB;AAEzB,
|
|
1
|
+
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,+CAAyB;AACzB,+CAAyB;AACzB,8CAAwB;AACxB,mDAA6B;AAC7B,iDAA2B;AAC3B,iDAA2B;AAC3B,oDAA8B;AAC9B,yDAAmC;AACnC,+CAAyB;AAEzB,iCAgBe;AAfb,gGAAA,SAAS,OAAA;AACT,sGAAA,eAAe,OAAA;AACf,uGAAA,gBAAgB,OAAA;AAChB,+GAAA,wBAAwB,OAAA;AACxB,kGAAA,WAAW,OAAA;AACX,wGAAA,iBAAiB,OAAA;AACjB,mGAAA,YAAY,OAAA;AACZ,2GAAA,oBAAoB,OAAA;AACpB,wGAAA,iBAAiB,OAAA;AACjB,8GAAA,uBAAuB,OAAA;AACvB,wGAAA,iBAAiB,OAAA;AACjB,yGAAA,kBAAkB,OAAA;AAClB,6GAAA,sBAAsB,OAAA;AACtB,4FAAA,KAAK,OAAA;AACL,+FAAA,QAAQ,OAAA;AAEV,6CAAuB;AACvB,gDAA0B;AAC1B,gDAA0B;AAC1B,6CAAuB;AACvB,+CAAyB;AACzB,+CAAyB;AACzB,gDAA0B;AAC1B,oDAA8B;AAC9B,6CAAuB;AACvB,0DAAoC;AACpC,iDAA2B","sourcesContent":["export * from './assert';\nexport * from './base64';\nexport * from './bytes';\nexport * from './caip-types';\nexport * from './checksum';\nexport * from './coercers';\nexport * from './collections';\nexport * from './encryption-types';\nexport * from './errors';\nexport type { Hex } from './hex';\nexport {\n HexStruct,\n StrictHexStruct,\n HexAddressStruct,\n HexChecksumAddressStruct,\n isHexString,\n isStrictHexString,\n isHexAddress,\n isHexChecksumAddress,\n assertIsHexString,\n assertIsStrictHexString,\n isValidHexAddress,\n getChecksumAddress,\n isValidChecksumAddress,\n add0x,\n remove0x,\n} from './hex';\nexport * from './json';\nexport * from './keyring';\nexport * from './logging';\nexport * from './misc';\nexport * from './number';\nexport * from './opaque';\nexport * from './promise';\nexport * from './superstruct';\nexport * from './time';\nexport * from './transaction-types';\nexport * from './versions';\n"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -8,7 +8,7 @@ export * from "./collections.cjs";
|
|
|
8
8
|
export * from "./encryption-types.cjs";
|
|
9
9
|
export * from "./errors.cjs";
|
|
10
10
|
export type { Hex } from "./hex.cjs";
|
|
11
|
-
export { HexStruct, StrictHexStruct, HexAddressStruct, HexChecksumAddressStruct, isHexString, isStrictHexString, assertIsHexString, assertIsStrictHexString, isValidHexAddress, getChecksumAddress, isValidChecksumAddress, add0x, remove0x, } from "./hex.cjs";
|
|
11
|
+
export { HexStruct, StrictHexStruct, HexAddressStruct, HexChecksumAddressStruct, isHexString, isStrictHexString, isHexAddress, isHexChecksumAddress, assertIsHexString, assertIsStrictHexString, isValidHexAddress, getChecksumAddress, isValidChecksumAddress, add0x, remove0x, } from "./hex.cjs";
|
|
12
12
|
export * from "./json.cjs";
|
|
13
13
|
export * from "./keyring.cjs";
|
|
14
14
|
export * from "./logging.cjs";
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,6BAAyB;AACzB,6BAAyB;AACzB,4BAAwB;AACxB,iCAA6B;AAC7B,+BAA2B;AAC3B,+BAA2B;AAC3B,kCAA8B;AAC9B,uCAAmC;AACnC,6BAAyB;AACzB,YAAY,EAAE,GAAG,EAAE,kBAAc;AACjC,OAAO,EACL,SAAS,EACT,eAAe,EACf,gBAAgB,EAChB,wBAAwB,EACxB,WAAW,EACX,iBAAiB,EACjB,iBAAiB,EACjB,uBAAuB,EACvB,iBAAiB,EACjB,kBAAkB,EAClB,sBAAsB,EACtB,KAAK,EACL,QAAQ,GACT,kBAAc;AACf,2BAAuB;AACvB,8BAA0B;AAC1B,8BAA0B;AAC1B,2BAAuB;AACvB,6BAAyB;AACzB,6BAAyB;AACzB,8BAA0B;AAC1B,kCAA8B;AAC9B,2BAAuB;AACvB,wCAAoC;AACpC,+BAA2B"}
|
|
1
|
+
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,6BAAyB;AACzB,6BAAyB;AACzB,4BAAwB;AACxB,iCAA6B;AAC7B,+BAA2B;AAC3B,+BAA2B;AAC3B,kCAA8B;AAC9B,uCAAmC;AACnC,6BAAyB;AACzB,YAAY,EAAE,GAAG,EAAE,kBAAc;AACjC,OAAO,EACL,SAAS,EACT,eAAe,EACf,gBAAgB,EAChB,wBAAwB,EACxB,WAAW,EACX,iBAAiB,EACjB,YAAY,EACZ,oBAAoB,EACpB,iBAAiB,EACjB,uBAAuB,EACvB,iBAAiB,EACjB,kBAAkB,EAClB,sBAAsB,EACtB,KAAK,EACL,QAAQ,GACT,kBAAc;AACf,2BAAuB;AACvB,8BAA0B;AAC1B,8BAA0B;AAC1B,2BAAuB;AACvB,6BAAyB;AACzB,6BAAyB;AACzB,8BAA0B;AAC1B,kCAA8B;AAC9B,2BAAuB;AACvB,wCAAoC;AACpC,+BAA2B"}
|
package/dist/index.d.mts
CHANGED
|
@@ -8,7 +8,7 @@ export * from "./collections.mjs";
|
|
|
8
8
|
export * from "./encryption-types.mjs";
|
|
9
9
|
export * from "./errors.mjs";
|
|
10
10
|
export type { Hex } from "./hex.mjs";
|
|
11
|
-
export { HexStruct, StrictHexStruct, HexAddressStruct, HexChecksumAddressStruct, isHexString, isStrictHexString, assertIsHexString, assertIsStrictHexString, isValidHexAddress, getChecksumAddress, isValidChecksumAddress, add0x, remove0x, } from "./hex.mjs";
|
|
11
|
+
export { HexStruct, StrictHexStruct, HexAddressStruct, HexChecksumAddressStruct, isHexString, isStrictHexString, isHexAddress, isHexChecksumAddress, assertIsHexString, assertIsStrictHexString, isValidHexAddress, getChecksumAddress, isValidChecksumAddress, add0x, remove0x, } from "./hex.mjs";
|
|
12
12
|
export * from "./json.mjs";
|
|
13
13
|
export * from "./keyring.mjs";
|
|
14
14
|
export * from "./logging.mjs";
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,6BAAyB;AACzB,6BAAyB;AACzB,4BAAwB;AACxB,iCAA6B;AAC7B,+BAA2B;AAC3B,+BAA2B;AAC3B,kCAA8B;AAC9B,uCAAmC;AACnC,6BAAyB;AACzB,YAAY,EAAE,GAAG,EAAE,kBAAc;AACjC,OAAO,EACL,SAAS,EACT,eAAe,EACf,gBAAgB,EAChB,wBAAwB,EACxB,WAAW,EACX,iBAAiB,EACjB,iBAAiB,EACjB,uBAAuB,EACvB,iBAAiB,EACjB,kBAAkB,EAClB,sBAAsB,EACtB,KAAK,EACL,QAAQ,GACT,kBAAc;AACf,2BAAuB;AACvB,8BAA0B;AAC1B,8BAA0B;AAC1B,2BAAuB;AACvB,6BAAyB;AACzB,6BAAyB;AACzB,8BAA0B;AAC1B,kCAA8B;AAC9B,2BAAuB;AACvB,wCAAoC;AACpC,+BAA2B"}
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,6BAAyB;AACzB,6BAAyB;AACzB,4BAAwB;AACxB,iCAA6B;AAC7B,+BAA2B;AAC3B,+BAA2B;AAC3B,kCAA8B;AAC9B,uCAAmC;AACnC,6BAAyB;AACzB,YAAY,EAAE,GAAG,EAAE,kBAAc;AACjC,OAAO,EACL,SAAS,EACT,eAAe,EACf,gBAAgB,EAChB,wBAAwB,EACxB,WAAW,EACX,iBAAiB,EACjB,YAAY,EACZ,oBAAoB,EACpB,iBAAiB,EACjB,uBAAuB,EACvB,iBAAiB,EACjB,kBAAkB,EAClB,sBAAsB,EACtB,KAAK,EACL,QAAQ,GACT,kBAAc;AACf,2BAAuB;AACvB,8BAA0B;AAC1B,8BAA0B;AAC1B,2BAAuB;AACvB,6BAAyB;AACzB,6BAAyB;AACzB,8BAA0B;AAC1B,kCAA8B;AAC9B,2BAAuB;AACvB,wCAAoC;AACpC,+BAA2B"}
|
package/dist/index.mjs
CHANGED
|
@@ -7,7 +7,7 @@ export * from "./coercers.mjs";
|
|
|
7
7
|
export * from "./collections.mjs";
|
|
8
8
|
export * from "./encryption-types.mjs";
|
|
9
9
|
export * from "./errors.mjs";
|
|
10
|
-
export { HexStruct, StrictHexStruct, HexAddressStruct, HexChecksumAddressStruct, isHexString, isStrictHexString, assertIsHexString, assertIsStrictHexString, isValidHexAddress, getChecksumAddress, isValidChecksumAddress, add0x, remove0x } from "./hex.mjs";
|
|
10
|
+
export { HexStruct, StrictHexStruct, HexAddressStruct, HexChecksumAddressStruct, isHexString, isStrictHexString, isHexAddress, isHexChecksumAddress, assertIsHexString, assertIsStrictHexString, isValidHexAddress, getChecksumAddress, isValidChecksumAddress, add0x, remove0x } from "./hex.mjs";
|
|
11
11
|
export * from "./json.mjs";
|
|
12
12
|
export * from "./keyring.mjs";
|
|
13
13
|
export * from "./logging.mjs";
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,6BAAyB;AACzB,6BAAyB;AACzB,4BAAwB;AACxB,iCAA6B;AAC7B,+BAA2B;AAC3B,+BAA2B;AAC3B,kCAA8B;AAC9B,uCAAmC;AACnC,6BAAyB;AAEzB,OAAO,EACL,SAAS,EACT,eAAe,EACf,gBAAgB,EAChB,wBAAwB,EACxB,WAAW,EACX,iBAAiB,EACjB,iBAAiB,EACjB,uBAAuB,EACvB,iBAAiB,EACjB,kBAAkB,EAClB,sBAAsB,EACtB,KAAK,EACL,QAAQ,EACT,kBAAc;AACf,2BAAuB;AACvB,8BAA0B;AAC1B,8BAA0B;AAC1B,2BAAuB;AACvB,6BAAyB;AACzB,6BAAyB;AACzB,8BAA0B;AAC1B,kCAA8B;AAC9B,2BAAuB;AACvB,wCAAoC;AACpC,+BAA2B","sourcesContent":["export * from './assert';\nexport * from './base64';\nexport * from './bytes';\nexport * from './caip-types';\nexport * from './checksum';\nexport * from './coercers';\nexport * from './collections';\nexport * from './encryption-types';\nexport * from './errors';\nexport type { Hex } from './hex';\nexport {\n HexStruct,\n StrictHexStruct,\n HexAddressStruct,\n HexChecksumAddressStruct,\n isHexString,\n isStrictHexString,\n assertIsHexString,\n assertIsStrictHexString,\n isValidHexAddress,\n getChecksumAddress,\n isValidChecksumAddress,\n add0x,\n remove0x,\n} from './hex';\nexport * from './json';\nexport * from './keyring';\nexport * from './logging';\nexport * from './misc';\nexport * from './number';\nexport * from './opaque';\nexport * from './promise';\nexport * from './superstruct';\nexport * from './time';\nexport * from './transaction-types';\nexport * from './versions';\n"]}
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,6BAAyB;AACzB,6BAAyB;AACzB,4BAAwB;AACxB,iCAA6B;AAC7B,+BAA2B;AAC3B,+BAA2B;AAC3B,kCAA8B;AAC9B,uCAAmC;AACnC,6BAAyB;AAEzB,OAAO,EACL,SAAS,EACT,eAAe,EACf,gBAAgB,EAChB,wBAAwB,EACxB,WAAW,EACX,iBAAiB,EACjB,YAAY,EACZ,oBAAoB,EACpB,iBAAiB,EACjB,uBAAuB,EACvB,iBAAiB,EACjB,kBAAkB,EAClB,sBAAsB,EACtB,KAAK,EACL,QAAQ,EACT,kBAAc;AACf,2BAAuB;AACvB,8BAA0B;AAC1B,8BAA0B;AAC1B,2BAAuB;AACvB,6BAAyB;AACzB,6BAAyB;AACzB,8BAA0B;AAC1B,kCAA8B;AAC9B,2BAAuB;AACvB,wCAAoC;AACpC,+BAA2B","sourcesContent":["export * from './assert';\nexport * from './base64';\nexport * from './bytes';\nexport * from './caip-types';\nexport * from './checksum';\nexport * from './coercers';\nexport * from './collections';\nexport * from './encryption-types';\nexport * from './errors';\nexport type { Hex } from './hex';\nexport {\n HexStruct,\n StrictHexStruct,\n HexAddressStruct,\n HexChecksumAddressStruct,\n isHexString,\n isStrictHexString,\n isHexAddress,\n isHexChecksumAddress,\n assertIsHexString,\n assertIsStrictHexString,\n isValidHexAddress,\n getChecksumAddress,\n isValidChecksumAddress,\n add0x,\n remove0x,\n} from './hex';\nexport * from './json';\nexport * from './keyring';\nexport * from './logging';\nexport * from './misc';\nexport * from './number';\nexport * from './opaque';\nexport * from './promise';\nexport * from './superstruct';\nexport * from './time';\nexport * from './transaction-types';\nexport * from './versions';\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask/utils",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.5.0",
|
|
4
4
|
"description": "Various JavaScript/TypeScript utilities of wide relevance to the MetaMask codebase",
|
|
5
5
|
"homepage": "https://github.com/MetaMask/utils#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -66,8 +66,9 @@
|
|
|
66
66
|
"@noble/hashes": "^1.3.1",
|
|
67
67
|
"@scure/base": "^1.1.3",
|
|
68
68
|
"@types/debug": "^4.1.7",
|
|
69
|
+
"@types/lodash": "^4.17.20",
|
|
69
70
|
"debug": "^4.3.4",
|
|
70
|
-
"lodash
|
|
71
|
+
"lodash": "^4.17.21",
|
|
71
72
|
"pony-cause": "^2.1.10",
|
|
72
73
|
"semver": "^7.5.4",
|
|
73
74
|
"uuid": "^9.0.1"
|
|
@@ -84,7 +85,6 @@
|
|
|
84
85
|
"@ts-bridge/shims": "^0.1.1",
|
|
85
86
|
"@types/jest": "^28.1.7",
|
|
86
87
|
"@types/jest-when": "^3.5.3",
|
|
87
|
-
"@types/lodash.memoize": "^4.1.9",
|
|
88
88
|
"@types/node": "~18.18.14",
|
|
89
89
|
"@types/uuid": "^9.0.8",
|
|
90
90
|
"@typescript-eslint/eslint-plugin": "^5.43.0",
|