@metamask/utils 11.5.0 → 11.6.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 CHANGED
@@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [11.6.0]
11
+
12
+ ### Added
13
+
14
+ - Migrate units conversion utils from `@metamask/ethjs-unit` ([#255](https://github.com/MetaMask/utils/pull/255))
15
+
16
+ ### Changed
17
+
18
+ - Make `KnownCaipNamespacedChainId` type generic over `Namespace` type parameter ([#262](https://github.com/MetaMask/utils/pull/262))
19
+
10
20
  ## [11.5.0]
11
21
 
12
22
  ### Added
@@ -441,7 +451,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
441
451
 
442
452
  - Initial release
443
453
 
444
- [Unreleased]: https://github.com/MetaMask/utils/compare/v11.5.0...HEAD
454
+ [Unreleased]: https://github.com/MetaMask/utils/compare/v11.6.0...HEAD
455
+ [11.6.0]: https://github.com/MetaMask/utils/compare/v11.5.0...v11.6.0
445
456
  [11.5.0]: https://github.com/MetaMask/utils/compare/v11.4.2...v11.5.0
446
457
  [11.4.2]: https://github.com/MetaMask/utils/compare/v11.4.1...v11.4.2
447
458
  [11.4.1]: https://github.com/MetaMask/utils/compare/v11.4.0...v11.4.1
@@ -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,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AO,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"]}
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,CA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C;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 *\n * @template Namespace - The namespace of the CAIP-2 chain ID. Must be a known namespace specified in {@link KnownCaipNamespace}.\n */\nexport type KnownCaipNamespacedChainId<\n Namespace extends `${KnownCaipNamespace}` = `${KnownCaipNamespace}`,\n> = `${Namespace}:${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"]}
@@ -80,8 +80,10 @@ export declare enum KnownCaipNamespace {
80
80
  *
81
81
  * This is a narrower, more type-safe alternative to {@link CaipChainId} for use cases
82
82
  * where the chain namespace must be one of the known standards.
83
+ *
84
+ * @template Namespace - The namespace of the CAIP-2 chain ID. Must be a known namespace specified in {@link KnownCaipNamespace}.
83
85
  */
84
- export type KnownCaipNamespacedChainId = `${KnownCaipNamespace}:${string}`;
86
+ export type KnownCaipNamespacedChainId<Namespace extends `${KnownCaipNamespace}` = `${KnownCaipNamespace}`> = `${Namespace}:${string}`;
85
87
  /**
86
88
  * Check if the given value is a {@link CaipChainId}.
87
89
  *
@@ -1 +1 @@
1
- {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AC;CAC/D,CAgBA;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,aAAa,CAC3B,SAAS,EAAE,aAAa,EACxB,SAAS,EAAE,aAAa,GACvB,WAAW,CAcb;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,eAAe,CAC7B,SAAS,EAAE,aAAa,EACxB,SAAS,EAAE,aAAa,EACxB,cAAc,EAAE,kBAAkB,GACjC,aAAa,CAoBf;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,eAAe,CAC7B,SAAS,EAAE,aAAa,EACxB,SAAS,EAAE,aAAa,EACxB,cAAc,EAAE,kBAAkB,EAClC,cAAc,EAAE,kBAAkB,GACjC,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"}
@@ -80,8 +80,10 @@ export declare enum KnownCaipNamespace {
80
80
  *
81
81
  * This is a narrower, more type-safe alternative to {@link CaipChainId} for use cases
82
82
  * where the chain namespace must be one of the known standards.
83
+ *
84
+ * @template Namespace - The namespace of the CAIP-2 chain ID. Must be a known namespace specified in {@link KnownCaipNamespace}.
83
85
  */
84
- export type KnownCaipNamespacedChainId = `${KnownCaipNamespace}:${string}`;
86
+ export type KnownCaipNamespacedChainId<Namespace extends `${KnownCaipNamespace}` = `${KnownCaipNamespace}`> = `${Namespace}:${string}`;
85
87
  /**
86
88
  * Check if the given value is a {@link CaipChainId}.
87
89
  *
@@ -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,QA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AAC;AACzE,CAAC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,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,oBAAoB,CAAC,QAAQ,EAAE,EAAE,CACtE,CAAC;KACH;IAED,IAAI,CAAC,eAAe,CAAC,SAAS,CAAC,EAAE;QAC/B,MAAM,IAAI,KAAK,CACb,oCAAoC,oBAAoB,CAAC,QAAQ,EAAE,EAAE,CACtE,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,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 * 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"]}
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,oBAAoB,GAAG,mBAAmB,CAAC;AAExD,MAAM,CAAC,MAAM,oBAAoB,GAAG,wBAAwB,CAAC;AAE7D,MAAM,CAAC,MAAM,qBAAqB,GAChC,wHAAwH,CAAC;AAE3H,MAAM,CAAC,MAAM,0BAA0B,GAAG,0BAA0B,CAAC;AAErE,MAAM,CAAC,MAAM,0BAA0B,GAAG,mBAAmB,CAAC;AAE9D,MAAM,CAAC,MAAM,0BAA0B,GAAG,0BAA0B,CAAC;AAErE,MAAM,CAAC,MAAM,mBAAmB,GAAG,yBAAyB,CAAC;AAE7D,MAAM,CAAC,MAAM,qBAAqB,GAChC,2JAA2J,CAAC;AAE9J,MAAM,CAAC,MAAM,mBAAmB,GAC9B,6LAA6L,CAAC;AAEhM,MAAM,2BAA2B,GAC/B,gMAAgM,CAAC;AAEnM;;GAEG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,aAAa,CAC5C,aAAa,EACb,mBAAmB,CACpB,CAAC;AAGF;;GAEG;AACH,MAAM,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B,EACxB,cAAkC,EAClC,cAAkC,EAClC,OAAoB;IAEpB,IAAI,CAAC,eAAe,CAAC,SAAS,CAAC,EAAE;QAC/B,MAAM,IAAI,KAAK,CACb,oCAAoC,oBAAoB,CAAC,QAAQ,EAAE,EAAE,CACtE,CAAC;KACH;IAED,IAAI,CAAC,eAAe,CAAC,SAAS,CAAC,EAAE;QAC/B,MAAM,IAAI,KAAK,CACb,oCAAoC,oBAAoB,CAAC,QAAQ,EAAE,EAAE,CACtE,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,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 * 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 *\n * @template Namespace - The namespace of the CAIP-2 chain ID. Must be a known namespace specified in {@link KnownCaipNamespace}.\n */\nexport type KnownCaipNamespacedChainId<\n Namespace extends `${KnownCaipNamespace}` = `${KnownCaipNamespace}`,\n> = `${Namespace}:${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/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.isHexChecksumAddress = exports.isHexAddress = exports.isStrictHexString = exports.isHexString = exports.HexChecksumAddressStruct = exports.HexAddressStruct = exports.StrictHexStruct = exports.HexStruct = void 0;
17
+ exports.unitMap = exports.getValueOfUnit = exports.numberToString = exports.fromWei = exports.toWei = 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);
@@ -51,4 +51,10 @@ __exportStar(require("./superstruct.cjs"), exports);
51
51
  __exportStar(require("./time.cjs"), exports);
52
52
  __exportStar(require("./transaction-types.cjs"), exports);
53
53
  __exportStar(require("./versions.cjs"), exports);
54
+ var unitsConversion_1 = require("./unitsConversion.cjs");
55
+ Object.defineProperty(exports, "toWei", { enumerable: true, get: function () { return unitsConversion_1.toWei; } });
56
+ Object.defineProperty(exports, "fromWei", { enumerable: true, get: function () { return unitsConversion_1.fromWei; } });
57
+ Object.defineProperty(exports, "numberToString", { enumerable: true, get: function () { return unitsConversion_1.numberToString; } });
58
+ Object.defineProperty(exports, "getValueOfUnit", { enumerable: true, get: function () { return unitsConversion_1.getValueOfUnit; } });
59
+ Object.defineProperty(exports, "unitMap", { enumerable: true, get: function () { return unitsConversion_1.unitMap; } });
54
60
  //# sourceMappingURL=index.cjs.map
@@ -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,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"]}
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;AAC3B,yDAM2B;AALzB,wGAAA,KAAK,OAAA;AACL,0GAAA,OAAO,OAAA;AACP,iHAAA,cAAc,OAAA;AACd,iHAAA,cAAc,OAAA;AACd,0GAAA,OAAO,OAAA","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';\nexport {\n toWei,\n fromWei,\n numberToString,\n getValueOfUnit,\n unitMap,\n} from './unitsConversion';\n"]}
package/dist/index.d.cts CHANGED
@@ -20,4 +20,5 @@ export * from "./superstruct.cjs";
20
20
  export * from "./time.cjs";
21
21
  export * from "./transaction-types.cjs";
22
22
  export * from "./versions.cjs";
23
+ export { toWei, fromWei, numberToString, getValueOfUnit, unitMap, } from "./unitsConversion.cjs";
23
24
  //# sourceMappingURL=index.d.cts.map
@@ -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,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"}
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;AAC3B,OAAO,EACL,KAAK,EACL,OAAO,EACP,cAAc,EACd,cAAc,EACd,OAAO,GACR,8BAA0B"}
package/dist/index.d.mts CHANGED
@@ -20,4 +20,5 @@ export * from "./superstruct.mjs";
20
20
  export * from "./time.mjs";
21
21
  export * from "./transaction-types.mjs";
22
22
  export * from "./versions.mjs";
23
+ export { toWei, fromWei, numberToString, getValueOfUnit, unitMap, } from "./unitsConversion.mjs";
23
24
  //# sourceMappingURL=index.d.mts.map
@@ -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,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"}
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;AAC3B,OAAO,EACL,KAAK,EACL,OAAO,EACP,cAAc,EACd,cAAc,EACd,OAAO,GACR,8BAA0B"}
package/dist/index.mjs CHANGED
@@ -19,4 +19,5 @@ export * from "./superstruct.mjs";
19
19
  export * from "./time.mjs";
20
20
  export * from "./transaction-types.mjs";
21
21
  export * from "./versions.mjs";
22
+ export { toWei, fromWei, numberToString, getValueOfUnit, unitMap } from "./unitsConversion.mjs";
22
23
  //# sourceMappingURL=index.mjs.map
@@ -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,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"]}
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;AAC3B,OAAO,EACL,KAAK,EACL,OAAO,EACP,cAAc,EACd,cAAc,EACd,OAAO,EACR,8BAA0B","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';\nexport {\n toWei,\n fromWei,\n numberToString,\n getValueOfUnit,\n unitMap,\n} from './unitsConversion';\n"]}
@@ -0,0 +1,217 @@
1
+ "use strict";
2
+ /* eslint-disable operator-assignment */
3
+ /*
4
+ Primary Attribution
5
+ Richard Moore <ricmoo@me.com>
6
+ https://github.com/ethers-io
7
+
8
+ Note, Richard is a god of ether gods. Follow and respect him, and use Ethers.io!
9
+ */
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.toWei = exports.fromWei = exports.numberToString = exports.getValueOfUnit = exports.unitMap = exports.numericToBigInt = void 0;
12
+ const zero = BigInt(0);
13
+ const negative1 = BigInt(-1);
14
+ /**
15
+ * Converts a string, number, or bigint to a bigint.
16
+ *
17
+ * @param arg - The value to convert to bigint.
18
+ * @returns The bigint representation of the input.
19
+ * @throws Error if the input type cannot be converted to bigint.
20
+ */
21
+ function numericToBigInt(arg) {
22
+ if (typeof arg === 'string') {
23
+ return BigInt(arg);
24
+ }
25
+ if (typeof arg === 'number') {
26
+ return BigInt(arg);
27
+ }
28
+ if (typeof arg === 'bigint') {
29
+ return arg;
30
+ }
31
+ throw new Error(`Cannot convert ${typeof arg} to BigInt`);
32
+ }
33
+ exports.numericToBigInt = numericToBigInt;
34
+ // complete ethereum unit map
35
+ exports.unitMap = {
36
+ noether: '0',
37
+ wei: '1',
38
+ kwei: '1000',
39
+ Kwei: '1000',
40
+ babbage: '1000',
41
+ femtoether: '1000',
42
+ mwei: '1000000',
43
+ Mwei: '1000000',
44
+ lovelace: '1000000',
45
+ picoether: '1000000',
46
+ gwei: '1000000000',
47
+ Gwei: '1000000000',
48
+ shannon: '1000000000',
49
+ nanoether: '1000000000',
50
+ nano: '1000000000',
51
+ szabo: '1000000000000',
52
+ microether: '1000000000000',
53
+ micro: '1000000000000',
54
+ finney: '1000000000000000',
55
+ milliether: '1000000000000000',
56
+ milli: '1000000000000000',
57
+ ether: '1000000000000000000',
58
+ kether: '1000000000000000000000',
59
+ grand: '1000000000000000000000',
60
+ mether: '1000000000000000000000000',
61
+ gether: '1000000000000000000000000000',
62
+ tether: '1000000000000000000000000000000',
63
+ };
64
+ // Pre-computed unit values as BigInt for performance
65
+ const unitMapBigInt = Object.fromEntries(Object.entries(exports.unitMap).map(([key, value]) => [key, BigInt(value)]));
66
+ const unitLengths = Object.fromEntries(Object.entries(exports.unitMap).map(([key, value]) => [key, value.length - 1 || 1]));
67
+ const NUMBER_REGEX = /^-?[0-9.]+$/u;
68
+ const FRACTION_REGEX = /^([0-9]*[1-9]|0)(0*)/u;
69
+ const COMMIFY_REGEX = /\B(?=(\d{3})+(?!\d))/gu;
70
+ /**
71
+ * Returns value of unit in Wei.
72
+ *
73
+ * @param unitInput - The unit to convert to, default ether.
74
+ * @returns Value of the unit (in Wei).
75
+ * @throws Error if the unit is not correct.
76
+ */
77
+ function getValueOfUnit(unitInput = 'ether') {
78
+ const unit = unitInput.toLowerCase();
79
+ const unitValue = unitMapBigInt[unit];
80
+ if (unitValue === undefined) {
81
+ throw new Error(`The unit provided ${unitInput} doesn't exist, please use the one of the following units ${JSON.stringify(exports.unitMap, null, 2)}`);
82
+ }
83
+ return unitValue;
84
+ }
85
+ exports.getValueOfUnit = getValueOfUnit;
86
+ /**
87
+ * Converts a number to a string.
88
+ *
89
+ * @param arg - The number to convert to a string.
90
+ * @returns The string representation of the number.
91
+ * @throws Error if the number is invalid.
92
+ */
93
+ function numberToString(arg) {
94
+ if (typeof arg === 'string') {
95
+ if (!NUMBER_REGEX.test(arg)) {
96
+ throw new Error(`while converting number to string, invalid number value '${arg}', should be a number matching (^-?[0-9.]+).`);
97
+ }
98
+ return arg;
99
+ }
100
+ if (typeof arg === 'number') {
101
+ return String(arg);
102
+ }
103
+ if (typeof arg === 'bigint') {
104
+ return arg.toString();
105
+ }
106
+ throw new Error(`while converting number to string, invalid number value '${String(arg)}' type ${typeof arg}.`);
107
+ }
108
+ exports.numberToString = numberToString;
109
+ /**
110
+ * Converts a number from Wei to a string.
111
+ *
112
+ * @param weiInput - The number to convert from Wei.
113
+ * @param unit - The unit to convert to, default ether.
114
+ * @param optionsInput - The options to use for the conversion.
115
+ * @param optionsInput.pad - Whether to pad the fractional part with zeros.
116
+ * @param optionsInput.commify - Whether to add commas to separate thousands.
117
+ * @returns The string representation of the number.
118
+ * @throws Error if the number is invalid.
119
+ */
120
+ function fromWei(weiInput, unit, optionsInput) {
121
+ let wei = numericToBigInt(weiInput);
122
+ const negative = wei < zero;
123
+ const unitLower = unit.toLowerCase();
124
+ const base = unitMapBigInt[unitLower];
125
+ const baseLength = unitLengths[unitLower];
126
+ const options = optionsInput ?? {};
127
+ if (base === undefined) {
128
+ throw new Error(`The unit provided ${unit} doesn't exist, please use the one of the following units ${JSON.stringify(exports.unitMap, null, 2)}`);
129
+ }
130
+ // Handle special case of noether (base = 0)
131
+ if (base === zero) {
132
+ return negative ? '-0' : '0';
133
+ }
134
+ if (negative) {
135
+ wei = wei * negative1;
136
+ }
137
+ let fraction = (wei % base).toString();
138
+ fraction = fraction.padStart(baseLength, '0');
139
+ if (!options.pad) {
140
+ const fractionMatch = fraction.match(FRACTION_REGEX);
141
+ // istanbul ignore next: defensive fallback that's never reachable but necessary to satisfy TS
142
+ fraction = fractionMatch?.[1] ?? '0';
143
+ }
144
+ let whole = (wei / base).toString();
145
+ if (options.commify) {
146
+ whole = whole.replace(COMMIFY_REGEX, ',');
147
+ }
148
+ let value = `${whole}${fraction === '0' ? '' : `.${fraction}`}`;
149
+ if (negative) {
150
+ value = `-${value}`;
151
+ }
152
+ return value;
153
+ }
154
+ exports.fromWei = fromWei;
155
+ /**
156
+ * Converts a number to Wei.
157
+ *
158
+ * @param etherInput - The number to convert to Wei.
159
+ * @param unit - The unit to convert to, default ether.
160
+ * @returns The number in Wei.
161
+ * @throws Error if the number is invalid.
162
+ */
163
+ function toWei(etherInput, unit) {
164
+ const unitLower = unit.toLowerCase();
165
+ const base = unitMapBigInt[unitLower];
166
+ const baseLength = unitLengths[unitLower];
167
+ if (base === undefined) {
168
+ throw new Error(`The unit provided ${unit} doesn't exist, please use the one of the following units ${JSON.stringify(exports.unitMap, null, 2)}`);
169
+ }
170
+ // Handle special case of noether (base = 0)
171
+ if (base === zero) {
172
+ return zero;
173
+ }
174
+ // Fast path for bigint inputs when unit is wei (no conversion needed)
175
+ if (typeof etherInput === 'bigint' && unitLower === 'wei') {
176
+ return etherInput;
177
+ }
178
+ // Fast path for bigint inputs with whole units (no fractional part)
179
+ if (typeof etherInput === 'bigint') {
180
+ return etherInput * base;
181
+ }
182
+ let ether = numberToString(etherInput);
183
+ // Is it negative?
184
+ const negative = ether.startsWith('-');
185
+ if (negative) {
186
+ ether = ether.substring(1);
187
+ }
188
+ if (ether === '.') {
189
+ throw new Error(`While converting number ${etherInput} to wei, invalid value`);
190
+ }
191
+ // Split it into a whole and fractional part
192
+ const comps = ether.split('.');
193
+ if (comps.length > 2) {
194
+ throw new Error(`While converting number ${etherInput} to wei, too many decimal points`);
195
+ }
196
+ let whole = comps[0];
197
+ let fraction = comps[1];
198
+ if (!whole) {
199
+ whole = '0';
200
+ }
201
+ if (!fraction) {
202
+ fraction = '0';
203
+ }
204
+ if (fraction.length > baseLength) {
205
+ throw new Error(`While converting number ${etherInput} to wei, too many decimal places`);
206
+ }
207
+ fraction = fraction.padEnd(baseLength, '0');
208
+ const wholeBigInt = BigInt(whole);
209
+ const fractionBigInt = BigInt(fraction);
210
+ let wei = wholeBigInt * base + fractionBigInt;
211
+ if (negative) {
212
+ wei = wei * negative1;
213
+ }
214
+ return wei;
215
+ }
216
+ exports.toWei = toWei;
217
+ //# sourceMappingURL=unitsConversion.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unitsConversion.cjs","sourceRoot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AAM,CAAC,QAAQ,CAAC,CAAC;IACxC,IAAI,GAAG,GAAG,WAAW,GAAG,IAAI,GAAG,cAAc,CAAC;IAE9C,IAAI,QAAQ,EAAE;QACZ,GAAG,GAAG,GAAG,GAAG,SAAS,CAAC;KACvB;IAED,OAAO,GAAG,CAAC;AACb,CAAC;AAjFD,sBAiFC","sourcesContent":["/* eslint-disable operator-assignment */\n/*\nPrimary Attribution\nRichard Moore <ricmoo@me.com>\nhttps://github.com/ethers-io\n\nNote, Richard is a god of ether gods. Follow and respect him, and use Ethers.io!\n*/\n\nconst zero = BigInt(0);\nconst negative1 = BigInt(-1);\n\n/**\n * Converts a string, number, or bigint to a bigint.\n *\n * @param arg - The value to convert to bigint.\n * @returns The bigint representation of the input.\n * @throws Error if the input type cannot be converted to bigint.\n */\nexport function numericToBigInt(arg: string | number | bigint): bigint {\n if (typeof arg === 'string') {\n return BigInt(arg);\n }\n if (typeof arg === 'number') {\n return BigInt(arg);\n }\n if (typeof arg === 'bigint') {\n return arg;\n }\n\n throw new Error(`Cannot convert ${typeof arg} to BigInt`);\n}\n\n// complete ethereum unit map\nexport const unitMap = {\n noether: '0',\n wei: '1',\n kwei: '1000',\n Kwei: '1000',\n babbage: '1000',\n femtoether: '1000',\n mwei: '1000000',\n Mwei: '1000000',\n lovelace: '1000000',\n picoether: '1000000',\n gwei: '1000000000',\n Gwei: '1000000000',\n shannon: '1000000000',\n nanoether: '1000000000',\n nano: '1000000000',\n szabo: '1000000000000',\n microether: '1000000000000',\n micro: '1000000000000',\n finney: '1000000000000000',\n milliether: '1000000000000000',\n milli: '1000000000000000',\n ether: '1000000000000000000',\n kether: '1000000000000000000000',\n grand: '1000000000000000000000',\n mether: '1000000000000000000000000',\n gether: '1000000000000000000000000000',\n tether: '1000000000000000000000000000000',\n} as const;\n\n// Pre-computed unit values as BigInt for performance\nconst unitMapBigInt = Object.fromEntries(\n Object.entries(unitMap).map(([key, value]) => [key, BigInt(value)]),\n) as Record<EthereumUnit, bigint>;\n\nconst unitLengths = Object.fromEntries(\n Object.entries(unitMap).map(([key, value]) => [key, value.length - 1 || 1]),\n) as Record<EthereumUnit, number>;\n\nconst NUMBER_REGEX = /^-?[0-9.]+$/u;\nconst FRACTION_REGEX = /^([0-9]*[1-9]|0)(0*)/u;\nconst COMMIFY_REGEX = /\\B(?=(\\d{3})+(?!\\d))/gu;\n\ntype EthereumUnit = keyof typeof unitMap;\n\n/**\n * Returns value of unit in Wei.\n *\n * @param unitInput - The unit to convert to, default ether.\n * @returns Value of the unit (in Wei).\n * @throws Error if the unit is not correct.\n */\nexport function getValueOfUnit(unitInput: EthereumUnit = 'ether'): bigint {\n const unit = unitInput.toLowerCase() as EthereumUnit;\n const unitValue = unitMapBigInt[unit];\n\n if (unitValue === undefined) {\n throw new Error(\n `The unit provided ${unitInput} doesn't exist, please use the one of the following units ${JSON.stringify(\n unitMap,\n null,\n 2,\n )}`,\n );\n }\n\n return unitValue;\n}\n\n/**\n * Converts a number to a string.\n *\n * @param arg - The number to convert to a string.\n * @returns The string representation of the number.\n * @throws Error if the number is invalid.\n */\nexport function numberToString(arg: string | number | bigint) {\n if (typeof arg === 'string') {\n if (!NUMBER_REGEX.test(arg)) {\n throw new Error(\n `while converting number to string, invalid number value '${arg}', should be a number matching (^-?[0-9.]+).`,\n );\n }\n return arg;\n }\n if (typeof arg === 'number') {\n return String(arg);\n }\n if (typeof arg === 'bigint') {\n return arg.toString();\n }\n throw new Error(\n `while converting number to string, invalid number value '${String(\n arg,\n )}' type ${typeof arg}.`,\n );\n}\n\n/**\n * Converts a number from Wei to a string.\n *\n * @param weiInput - The number to convert from Wei.\n * @param unit - The unit to convert to, default ether.\n * @param optionsInput - The options to use for the conversion.\n * @param optionsInput.pad - Whether to pad the fractional part with zeros.\n * @param optionsInput.commify - Whether to add commas to separate thousands.\n * @returns The string representation of the number.\n * @throws Error if the number is invalid.\n */\nexport function fromWei(\n weiInput: string | number | bigint,\n unit: EthereumUnit,\n optionsInput?: { pad?: boolean; commify?: boolean },\n) {\n let wei = numericToBigInt(weiInput);\n const negative = wei < zero;\n const unitLower = unit.toLowerCase() as EthereumUnit;\n const base = unitMapBigInt[unitLower];\n const baseLength = unitLengths[unitLower];\n const options = optionsInput ?? {};\n\n if (base === undefined) {\n throw new Error(\n `The unit provided ${unit} doesn't exist, please use the one of the following units ${JSON.stringify(\n unitMap,\n null,\n 2,\n )}`,\n );\n }\n\n // Handle special case of noether (base = 0)\n if (base === zero) {\n return negative ? '-0' : '0';\n }\n\n if (negative) {\n wei = wei * negative1;\n }\n\n let fraction = (wei % base).toString();\n\n fraction = fraction.padStart(baseLength, '0');\n\n if (!options.pad) {\n const fractionMatch = fraction.match(FRACTION_REGEX);\n // istanbul ignore next: defensive fallback that's never reachable but necessary to satisfy TS\n fraction = fractionMatch?.[1] ?? '0';\n }\n\n let whole = (wei / base).toString();\n\n if (options.commify) {\n whole = whole.replace(COMMIFY_REGEX, ',');\n }\n\n let value = `${whole}${fraction === '0' ? '' : `.${fraction}`}`;\n\n if (negative) {\n value = `-${value}`;\n }\n\n return value;\n}\n\n/**\n * Converts a number to Wei.\n *\n * @param etherInput - The number to convert to Wei.\n * @param unit - The unit to convert to, default ether.\n * @returns The number in Wei.\n * @throws Error if the number is invalid.\n */\nexport function toWei(\n etherInput: string | number | bigint,\n unit: EthereumUnit,\n): bigint {\n const unitLower = unit.toLowerCase() as EthereumUnit;\n const base = unitMapBigInt[unitLower];\n const baseLength = unitLengths[unitLower];\n\n if (base === undefined) {\n throw new Error(\n `The unit provided ${unit} doesn't exist, please use the one of the following units ${JSON.stringify(\n unitMap,\n null,\n 2,\n )}`,\n );\n }\n\n // Handle special case of noether (base = 0)\n if (base === zero) {\n return zero;\n }\n\n // Fast path for bigint inputs when unit is wei (no conversion needed)\n if (typeof etherInput === 'bigint' && unitLower === 'wei') {\n return etherInput;\n }\n\n // Fast path for bigint inputs with whole units (no fractional part)\n if (typeof etherInput === 'bigint') {\n return etherInput * base;\n }\n\n let ether = numberToString(etherInput);\n\n // Is it negative?\n const negative = ether.startsWith('-');\n if (negative) {\n ether = ether.substring(1);\n }\n\n if (ether === '.') {\n throw new Error(\n `While converting number ${etherInput} to wei, invalid value`,\n );\n }\n\n // Split it into a whole and fractional part\n const comps = ether.split('.');\n if (comps.length > 2) {\n throw new Error(\n `While converting number ${etherInput} to wei, too many decimal points`,\n );\n }\n\n let whole = comps[0];\n let fraction = comps[1];\n\n if (!whole) {\n whole = '0';\n }\n if (!fraction) {\n fraction = '0';\n }\n if (fraction.length > baseLength) {\n throw new Error(\n `While converting number ${etherInput} to wei, too many decimal places`,\n );\n }\n\n fraction = fraction.padEnd(baseLength, '0');\n\n const wholeBigInt = BigInt(whole);\n const fractionBigInt = BigInt(fraction);\n let wei = wholeBigInt * base + fractionBigInt;\n\n if (negative) {\n wei = wei * negative1;\n }\n\n return wei;\n}\n"]}
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Converts a string, number, or bigint to a bigint.
3
+ *
4
+ * @param arg - The value to convert to bigint.
5
+ * @returns The bigint representation of the input.
6
+ * @throws Error if the input type cannot be converted to bigint.
7
+ */
8
+ export declare function numericToBigInt(arg: string | number | bigint): bigint;
9
+ export declare const unitMap: {
10
+ readonly noether: "0";
11
+ readonly wei: "1";
12
+ readonly kwei: "1000";
13
+ readonly Kwei: "1000";
14
+ readonly babbage: "1000";
15
+ readonly femtoether: "1000";
16
+ readonly mwei: "1000000";
17
+ readonly Mwei: "1000000";
18
+ readonly lovelace: "1000000";
19
+ readonly picoether: "1000000";
20
+ readonly gwei: "1000000000";
21
+ readonly Gwei: "1000000000";
22
+ readonly shannon: "1000000000";
23
+ readonly nanoether: "1000000000";
24
+ readonly nano: "1000000000";
25
+ readonly szabo: "1000000000000";
26
+ readonly microether: "1000000000000";
27
+ readonly micro: "1000000000000";
28
+ readonly finney: "1000000000000000";
29
+ readonly milliether: "1000000000000000";
30
+ readonly milli: "1000000000000000";
31
+ readonly ether: "1000000000000000000";
32
+ readonly kether: "1000000000000000000000";
33
+ readonly grand: "1000000000000000000000";
34
+ readonly mether: "1000000000000000000000000";
35
+ readonly gether: "1000000000000000000000000000";
36
+ readonly tether: "1000000000000000000000000000000";
37
+ };
38
+ type EthereumUnit = keyof typeof unitMap;
39
+ /**
40
+ * Returns value of unit in Wei.
41
+ *
42
+ * @param unitInput - The unit to convert to, default ether.
43
+ * @returns Value of the unit (in Wei).
44
+ * @throws Error if the unit is not correct.
45
+ */
46
+ export declare function getValueOfUnit(unitInput?: EthereumUnit): bigint;
47
+ /**
48
+ * Converts a number to a string.
49
+ *
50
+ * @param arg - The number to convert to a string.
51
+ * @returns The string representation of the number.
52
+ * @throws Error if the number is invalid.
53
+ */
54
+ export declare function numberToString(arg: string | number | bigint): string;
55
+ /**
56
+ * Converts a number from Wei to a string.
57
+ *
58
+ * @param weiInput - The number to convert from Wei.
59
+ * @param unit - The unit to convert to, default ether.
60
+ * @param optionsInput - The options to use for the conversion.
61
+ * @param optionsInput.pad - Whether to pad the fractional part with zeros.
62
+ * @param optionsInput.commify - Whether to add commas to separate thousands.
63
+ * @returns The string representation of the number.
64
+ * @throws Error if the number is invalid.
65
+ */
66
+ export declare function fromWei(weiInput: string | number | bigint, unit: EthereumUnit, optionsInput?: {
67
+ pad?: boolean;
68
+ commify?: boolean;
69
+ }): string;
70
+ /**
71
+ * Converts a number to Wei.
72
+ *
73
+ * @param etherInput - The number to convert to Wei.
74
+ * @param unit - The unit to convert to, default ether.
75
+ * @returns The number in Wei.
76
+ * @throws Error if the number is invalid.
77
+ */
78
+ export declare function toWei(etherInput: string | number | bigint, unit: EthereumUnit): bigint;
79
+ export {};
80
+ //# sourceMappingURL=unitsConversion.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unitsConversion.d.cts","sourceRoot":"","sources":["../src/unitsConversion.ts"],"names":[],"mappings":"AAYA;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAYrE;AAGD,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4BV,CAAC;AAeX,KAAK,YAAY,GAAG,MAAM,OAAO,OAAO,CAAC;AAEzC;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,SAAS,GAAE,YAAsB,GAAG,MAAM,CAexE;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,UAoB3D;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,OAAO,CACrB,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,EAClC,IAAI,EAAE,YAAY,EAClB,YAAY,CAAC,EAAE;IAAE,GAAG,CAAC,EAAE,OAAO,CAAC;IAAC,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,UAmDpD;AAED;;;;;;;GAOG;AACH,wBAAgB,KAAK,CACnB,UAAU,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,EACpC,IAAI,EAAE,YAAY,GACjB,MAAM,CA8ER"}
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Converts a string, number, or bigint to a bigint.
3
+ *
4
+ * @param arg - The value to convert to bigint.
5
+ * @returns The bigint representation of the input.
6
+ * @throws Error if the input type cannot be converted to bigint.
7
+ */
8
+ export declare function numericToBigInt(arg: string | number | bigint): bigint;
9
+ export declare const unitMap: {
10
+ readonly noether: "0";
11
+ readonly wei: "1";
12
+ readonly kwei: "1000";
13
+ readonly Kwei: "1000";
14
+ readonly babbage: "1000";
15
+ readonly femtoether: "1000";
16
+ readonly mwei: "1000000";
17
+ readonly Mwei: "1000000";
18
+ readonly lovelace: "1000000";
19
+ readonly picoether: "1000000";
20
+ readonly gwei: "1000000000";
21
+ readonly Gwei: "1000000000";
22
+ readonly shannon: "1000000000";
23
+ readonly nanoether: "1000000000";
24
+ readonly nano: "1000000000";
25
+ readonly szabo: "1000000000000";
26
+ readonly microether: "1000000000000";
27
+ readonly micro: "1000000000000";
28
+ readonly finney: "1000000000000000";
29
+ readonly milliether: "1000000000000000";
30
+ readonly milli: "1000000000000000";
31
+ readonly ether: "1000000000000000000";
32
+ readonly kether: "1000000000000000000000";
33
+ readonly grand: "1000000000000000000000";
34
+ readonly mether: "1000000000000000000000000";
35
+ readonly gether: "1000000000000000000000000000";
36
+ readonly tether: "1000000000000000000000000000000";
37
+ };
38
+ type EthereumUnit = keyof typeof unitMap;
39
+ /**
40
+ * Returns value of unit in Wei.
41
+ *
42
+ * @param unitInput - The unit to convert to, default ether.
43
+ * @returns Value of the unit (in Wei).
44
+ * @throws Error if the unit is not correct.
45
+ */
46
+ export declare function getValueOfUnit(unitInput?: EthereumUnit): bigint;
47
+ /**
48
+ * Converts a number to a string.
49
+ *
50
+ * @param arg - The number to convert to a string.
51
+ * @returns The string representation of the number.
52
+ * @throws Error if the number is invalid.
53
+ */
54
+ export declare function numberToString(arg: string | number | bigint): string;
55
+ /**
56
+ * Converts a number from Wei to a string.
57
+ *
58
+ * @param weiInput - The number to convert from Wei.
59
+ * @param unit - The unit to convert to, default ether.
60
+ * @param optionsInput - The options to use for the conversion.
61
+ * @param optionsInput.pad - Whether to pad the fractional part with zeros.
62
+ * @param optionsInput.commify - Whether to add commas to separate thousands.
63
+ * @returns The string representation of the number.
64
+ * @throws Error if the number is invalid.
65
+ */
66
+ export declare function fromWei(weiInput: string | number | bigint, unit: EthereumUnit, optionsInput?: {
67
+ pad?: boolean;
68
+ commify?: boolean;
69
+ }): string;
70
+ /**
71
+ * Converts a number to Wei.
72
+ *
73
+ * @param etherInput - The number to convert to Wei.
74
+ * @param unit - The unit to convert to, default ether.
75
+ * @returns The number in Wei.
76
+ * @throws Error if the number is invalid.
77
+ */
78
+ export declare function toWei(etherInput: string | number | bigint, unit: EthereumUnit): bigint;
79
+ export {};
80
+ //# sourceMappingURL=unitsConversion.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unitsConversion.d.mts","sourceRoot":"","sources":["../src/unitsConversion.ts"],"names":[],"mappings":"AAYA;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAYrE;AAGD,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4BV,CAAC;AAeX,KAAK,YAAY,GAAG,MAAM,OAAO,OAAO,CAAC;AAEzC;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,SAAS,GAAE,YAAsB,GAAG,MAAM,CAexE;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,UAoB3D;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,OAAO,CACrB,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,EAClC,IAAI,EAAE,YAAY,EAClB,YAAY,CAAC,EAAE;IAAE,GAAG,CAAC,EAAE,OAAO,CAAC;IAAC,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,UAmDpD;AAED;;;;;;;GAOG;AACH,wBAAgB,KAAK,CACnB,UAAU,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,EACpC,IAAI,EAAE,YAAY,GACjB,MAAM,CA8ER"}
@@ -0,0 +1,209 @@
1
+ /* eslint-disable operator-assignment */
2
+ /*
3
+ Primary Attribution
4
+ Richard Moore <ricmoo@me.com>
5
+ https://github.com/ethers-io
6
+
7
+ Note, Richard is a god of ether gods. Follow and respect him, and use Ethers.io!
8
+ */
9
+ const zero = BigInt(0);
10
+ const negative1 = BigInt(-1);
11
+ /**
12
+ * Converts a string, number, or bigint to a bigint.
13
+ *
14
+ * @param arg - The value to convert to bigint.
15
+ * @returns The bigint representation of the input.
16
+ * @throws Error if the input type cannot be converted to bigint.
17
+ */
18
+ export function numericToBigInt(arg) {
19
+ if (typeof arg === 'string') {
20
+ return BigInt(arg);
21
+ }
22
+ if (typeof arg === 'number') {
23
+ return BigInt(arg);
24
+ }
25
+ if (typeof arg === 'bigint') {
26
+ return arg;
27
+ }
28
+ throw new Error(`Cannot convert ${typeof arg} to BigInt`);
29
+ }
30
+ // complete ethereum unit map
31
+ export const unitMap = {
32
+ noether: '0',
33
+ wei: '1',
34
+ kwei: '1000',
35
+ Kwei: '1000',
36
+ babbage: '1000',
37
+ femtoether: '1000',
38
+ mwei: '1000000',
39
+ Mwei: '1000000',
40
+ lovelace: '1000000',
41
+ picoether: '1000000',
42
+ gwei: '1000000000',
43
+ Gwei: '1000000000',
44
+ shannon: '1000000000',
45
+ nanoether: '1000000000',
46
+ nano: '1000000000',
47
+ szabo: '1000000000000',
48
+ microether: '1000000000000',
49
+ micro: '1000000000000',
50
+ finney: '1000000000000000',
51
+ milliether: '1000000000000000',
52
+ milli: '1000000000000000',
53
+ ether: '1000000000000000000',
54
+ kether: '1000000000000000000000',
55
+ grand: '1000000000000000000000',
56
+ mether: '1000000000000000000000000',
57
+ gether: '1000000000000000000000000000',
58
+ tether: '1000000000000000000000000000000',
59
+ };
60
+ // Pre-computed unit values as BigInt for performance
61
+ const unitMapBigInt = Object.fromEntries(Object.entries(unitMap).map(([key, value]) => [key, BigInt(value)]));
62
+ const unitLengths = Object.fromEntries(Object.entries(unitMap).map(([key, value]) => [key, value.length - 1 || 1]));
63
+ const NUMBER_REGEX = /^-?[0-9.]+$/u;
64
+ const FRACTION_REGEX = /^([0-9]*[1-9]|0)(0*)/u;
65
+ const COMMIFY_REGEX = /\B(?=(\d{3})+(?!\d))/gu;
66
+ /**
67
+ * Returns value of unit in Wei.
68
+ *
69
+ * @param unitInput - The unit to convert to, default ether.
70
+ * @returns Value of the unit (in Wei).
71
+ * @throws Error if the unit is not correct.
72
+ */
73
+ export function getValueOfUnit(unitInput = 'ether') {
74
+ const unit = unitInput.toLowerCase();
75
+ const unitValue = unitMapBigInt[unit];
76
+ if (unitValue === undefined) {
77
+ throw new Error(`The unit provided ${unitInput} doesn't exist, please use the one of the following units ${JSON.stringify(unitMap, null, 2)}`);
78
+ }
79
+ return unitValue;
80
+ }
81
+ /**
82
+ * Converts a number to a string.
83
+ *
84
+ * @param arg - The number to convert to a string.
85
+ * @returns The string representation of the number.
86
+ * @throws Error if the number is invalid.
87
+ */
88
+ export function numberToString(arg) {
89
+ if (typeof arg === 'string') {
90
+ if (!NUMBER_REGEX.test(arg)) {
91
+ throw new Error(`while converting number to string, invalid number value '${arg}', should be a number matching (^-?[0-9.]+).`);
92
+ }
93
+ return arg;
94
+ }
95
+ if (typeof arg === 'number') {
96
+ return String(arg);
97
+ }
98
+ if (typeof arg === 'bigint') {
99
+ return arg.toString();
100
+ }
101
+ throw new Error(`while converting number to string, invalid number value '${String(arg)}' type ${typeof arg}.`);
102
+ }
103
+ /**
104
+ * Converts a number from Wei to a string.
105
+ *
106
+ * @param weiInput - The number to convert from Wei.
107
+ * @param unit - The unit to convert to, default ether.
108
+ * @param optionsInput - The options to use for the conversion.
109
+ * @param optionsInput.pad - Whether to pad the fractional part with zeros.
110
+ * @param optionsInput.commify - Whether to add commas to separate thousands.
111
+ * @returns The string representation of the number.
112
+ * @throws Error if the number is invalid.
113
+ */
114
+ export function fromWei(weiInput, unit, optionsInput) {
115
+ let wei = numericToBigInt(weiInput);
116
+ const negative = wei < zero;
117
+ const unitLower = unit.toLowerCase();
118
+ const base = unitMapBigInt[unitLower];
119
+ const baseLength = unitLengths[unitLower];
120
+ const options = optionsInput ?? {};
121
+ if (base === undefined) {
122
+ throw new Error(`The unit provided ${unit} doesn't exist, please use the one of the following units ${JSON.stringify(unitMap, null, 2)}`);
123
+ }
124
+ // Handle special case of noether (base = 0)
125
+ if (base === zero) {
126
+ return negative ? '-0' : '0';
127
+ }
128
+ if (negative) {
129
+ wei = wei * negative1;
130
+ }
131
+ let fraction = (wei % base).toString();
132
+ fraction = fraction.padStart(baseLength, '0');
133
+ if (!options.pad) {
134
+ const fractionMatch = fraction.match(FRACTION_REGEX);
135
+ // istanbul ignore next: defensive fallback that's never reachable but necessary to satisfy TS
136
+ fraction = fractionMatch?.[1] ?? '0';
137
+ }
138
+ let whole = (wei / base).toString();
139
+ if (options.commify) {
140
+ whole = whole.replace(COMMIFY_REGEX, ',');
141
+ }
142
+ let value = `${whole}${fraction === '0' ? '' : `.${fraction}`}`;
143
+ if (negative) {
144
+ value = `-${value}`;
145
+ }
146
+ return value;
147
+ }
148
+ /**
149
+ * Converts a number to Wei.
150
+ *
151
+ * @param etherInput - The number to convert to Wei.
152
+ * @param unit - The unit to convert to, default ether.
153
+ * @returns The number in Wei.
154
+ * @throws Error if the number is invalid.
155
+ */
156
+ export function toWei(etherInput, unit) {
157
+ const unitLower = unit.toLowerCase();
158
+ const base = unitMapBigInt[unitLower];
159
+ const baseLength = unitLengths[unitLower];
160
+ if (base === undefined) {
161
+ throw new Error(`The unit provided ${unit} doesn't exist, please use the one of the following units ${JSON.stringify(unitMap, null, 2)}`);
162
+ }
163
+ // Handle special case of noether (base = 0)
164
+ if (base === zero) {
165
+ return zero;
166
+ }
167
+ // Fast path for bigint inputs when unit is wei (no conversion needed)
168
+ if (typeof etherInput === 'bigint' && unitLower === 'wei') {
169
+ return etherInput;
170
+ }
171
+ // Fast path for bigint inputs with whole units (no fractional part)
172
+ if (typeof etherInput === 'bigint') {
173
+ return etherInput * base;
174
+ }
175
+ let ether = numberToString(etherInput);
176
+ // Is it negative?
177
+ const negative = ether.startsWith('-');
178
+ if (negative) {
179
+ ether = ether.substring(1);
180
+ }
181
+ if (ether === '.') {
182
+ throw new Error(`While converting number ${etherInput} to wei, invalid value`);
183
+ }
184
+ // Split it into a whole and fractional part
185
+ const comps = ether.split('.');
186
+ if (comps.length > 2) {
187
+ throw new Error(`While converting number ${etherInput} to wei, too many decimal points`);
188
+ }
189
+ let whole = comps[0];
190
+ let fraction = comps[1];
191
+ if (!whole) {
192
+ whole = '0';
193
+ }
194
+ if (!fraction) {
195
+ fraction = '0';
196
+ }
197
+ if (fraction.length > baseLength) {
198
+ throw new Error(`While converting number ${etherInput} to wei, too many decimal places`);
199
+ }
200
+ fraction = fraction.padEnd(baseLength, '0');
201
+ const wholeBigInt = BigInt(whole);
202
+ const fractionBigInt = BigInt(fraction);
203
+ let wei = wholeBigInt * base + fractionBigInt;
204
+ if (negative) {
205
+ wei = wei * negative1;
206
+ }
207
+ return wei;
208
+ }
209
+ //# sourceMappingURL=unitsConversion.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unitsConversion.mjs","sourceRoot":"","sources":["../src/unitsConversion.ts"],"names":[],"mappings":"AAAA,wCAAwC;AACxC;;;;;;EAME;AAEF,MAAM,IAAI,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;AACvB,MAAM,SAAS,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;AAE7B;;;;;;GAMG;AACH,MAAM,UAAU,eAAe,CAAC,GAA6B;IAC3D,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE;QAC3B,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC;KACpB;IACD,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE;QAC3B,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC;KACpB;IACD,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE;QAC3B,OAAO,GAAG,CAAC;KACZ;IAED,MAAM,IAAI,KAAK,CAAC,kBAAkB,OAAO,GAAG,YAAY,CAAC,CAAC;AAC5D,CAAC;AAED,6BAA6B;AAC7B,MAAM,CAAC,MAAM,OAAO,GAAG;IACrB,OAAO,EAAE,GAAG;IACZ,GAAG,EAAE,GAAG;IACR,IAAI,EAAE,MAAM;IACZ,IAAI,EAAE,MAAM;IACZ,OAAO,EAAE,MAAM;IACf,UAAU,EAAE,MAAM;IAClB,IAAI,EAAE,SAAS;IACf,IAAI,EAAE,SAAS;IACf,QAAQ,EAAE,SAAS;IACnB,SAAS,EAAE,SAAS;IACpB,IAAI,EAAE,YAAY;IAClB,IAAI,EAAE,YAAY;IAClB,OAAO,EAAE,YAAY;IACrB,SAAS,EAAE,YAAY;I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MAAM,GAAG,UAAU,EAAE;QAChC,MAAM,IAAI,KAAK,CACb,2BAA2B,UAAU,kCAAkC,CACxE,CAAC;KACH;IAED,QAAQ,GAAG,QAAQ,CAAC,MAAM,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC;IAE5C,MAAM,WAAW,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IAClC,MAAM,cAAc,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;IACxC,IAAI,GAAG,GAAG,WAAW,GAAG,IAAI,GAAG,cAAc,CAAC;IAE9C,IAAI,QAAQ,EAAE;QACZ,GAAG,GAAG,GAAG,GAAG,SAAS,CAAC;KACvB;IAED,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["/* eslint-disable operator-assignment */\n/*\nPrimary Attribution\nRichard Moore <ricmoo@me.com>\nhttps://github.com/ethers-io\n\nNote, Richard is a god of ether gods. Follow and respect him, and use Ethers.io!\n*/\n\nconst zero = BigInt(0);\nconst negative1 = BigInt(-1);\n\n/**\n * Converts a string, number, or bigint to a bigint.\n *\n * @param arg - The value to convert to bigint.\n * @returns The bigint representation of the input.\n * @throws Error if the input type cannot be converted to bigint.\n */\nexport function numericToBigInt(arg: string | number | bigint): bigint {\n if (typeof arg === 'string') {\n return BigInt(arg);\n }\n if (typeof arg === 'number') {\n return BigInt(arg);\n }\n if (typeof arg === 'bigint') {\n return arg;\n }\n\n throw new Error(`Cannot convert ${typeof arg} to BigInt`);\n}\n\n// complete ethereum unit map\nexport const unitMap = {\n noether: '0',\n wei: '1',\n kwei: '1000',\n Kwei: '1000',\n babbage: '1000',\n femtoether: '1000',\n mwei: '1000000',\n Mwei: '1000000',\n lovelace: '1000000',\n picoether: '1000000',\n gwei: '1000000000',\n Gwei: '1000000000',\n shannon: '1000000000',\n nanoether: '1000000000',\n nano: '1000000000',\n szabo: '1000000000000',\n microether: '1000000000000',\n micro: '1000000000000',\n finney: '1000000000000000',\n milliether: '1000000000000000',\n milli: '1000000000000000',\n ether: '1000000000000000000',\n kether: '1000000000000000000000',\n grand: '1000000000000000000000',\n mether: '1000000000000000000000000',\n gether: '1000000000000000000000000000',\n tether: '1000000000000000000000000000000',\n} as const;\n\n// Pre-computed unit values as BigInt for performance\nconst unitMapBigInt = Object.fromEntries(\n Object.entries(unitMap).map(([key, value]) => [key, BigInt(value)]),\n) as Record<EthereumUnit, bigint>;\n\nconst unitLengths = Object.fromEntries(\n Object.entries(unitMap).map(([key, value]) => [key, value.length - 1 || 1]),\n) as Record<EthereumUnit, number>;\n\nconst NUMBER_REGEX = /^-?[0-9.]+$/u;\nconst FRACTION_REGEX = /^([0-9]*[1-9]|0)(0*)/u;\nconst COMMIFY_REGEX = /\\B(?=(\\d{3})+(?!\\d))/gu;\n\ntype EthereumUnit = keyof typeof unitMap;\n\n/**\n * Returns value of unit in Wei.\n *\n * @param unitInput - The unit to convert to, default ether.\n * @returns Value of the unit (in Wei).\n * @throws Error if the unit is not correct.\n */\nexport function getValueOfUnit(unitInput: EthereumUnit = 'ether'): bigint {\n const unit = unitInput.toLowerCase() as EthereumUnit;\n const unitValue = unitMapBigInt[unit];\n\n if (unitValue === undefined) {\n throw new Error(\n `The unit provided ${unitInput} doesn't exist, please use the one of the following units ${JSON.stringify(\n unitMap,\n null,\n 2,\n )}`,\n );\n }\n\n return unitValue;\n}\n\n/**\n * Converts a number to a string.\n *\n * @param arg - The number to convert to a string.\n * @returns The string representation of the number.\n * @throws Error if the number is invalid.\n */\nexport function numberToString(arg: string | number | bigint) {\n if (typeof arg === 'string') {\n if (!NUMBER_REGEX.test(arg)) {\n throw new Error(\n `while converting number to string, invalid number value '${arg}', should be a number matching (^-?[0-9.]+).`,\n );\n }\n return arg;\n }\n if (typeof arg === 'number') {\n return String(arg);\n }\n if (typeof arg === 'bigint') {\n return arg.toString();\n }\n throw new Error(\n `while converting number to string, invalid number value '${String(\n arg,\n )}' type ${typeof arg}.`,\n );\n}\n\n/**\n * Converts a number from Wei to a string.\n *\n * @param weiInput - The number to convert from Wei.\n * @param unit - The unit to convert to, default ether.\n * @param optionsInput - The options to use for the conversion.\n * @param optionsInput.pad - Whether to pad the fractional part with zeros.\n * @param optionsInput.commify - Whether to add commas to separate thousands.\n * @returns The string representation of the number.\n * @throws Error if the number is invalid.\n */\nexport function fromWei(\n weiInput: string | number | bigint,\n unit: EthereumUnit,\n optionsInput?: { pad?: boolean; commify?: boolean },\n) {\n let wei = numericToBigInt(weiInput);\n const negative = wei < zero;\n const unitLower = unit.toLowerCase() as EthereumUnit;\n const base = unitMapBigInt[unitLower];\n const baseLength = unitLengths[unitLower];\n const options = optionsInput ?? {};\n\n if (base === undefined) {\n throw new Error(\n `The unit provided ${unit} doesn't exist, please use the one of the following units ${JSON.stringify(\n unitMap,\n null,\n 2,\n )}`,\n );\n }\n\n // Handle special case of noether (base = 0)\n if (base === zero) {\n return negative ? '-0' : '0';\n }\n\n if (negative) {\n wei = wei * negative1;\n }\n\n let fraction = (wei % base).toString();\n\n fraction = fraction.padStart(baseLength, '0');\n\n if (!options.pad) {\n const fractionMatch = fraction.match(FRACTION_REGEX);\n // istanbul ignore next: defensive fallback that's never reachable but necessary to satisfy TS\n fraction = fractionMatch?.[1] ?? '0';\n }\n\n let whole = (wei / base).toString();\n\n if (options.commify) {\n whole = whole.replace(COMMIFY_REGEX, ',');\n }\n\n let value = `${whole}${fraction === '0' ? '' : `.${fraction}`}`;\n\n if (negative) {\n value = `-${value}`;\n }\n\n return value;\n}\n\n/**\n * Converts a number to Wei.\n *\n * @param etherInput - The number to convert to Wei.\n * @param unit - The unit to convert to, default ether.\n * @returns The number in Wei.\n * @throws Error if the number is invalid.\n */\nexport function toWei(\n etherInput: string | number | bigint,\n unit: EthereumUnit,\n): bigint {\n const unitLower = unit.toLowerCase() as EthereumUnit;\n const base = unitMapBigInt[unitLower];\n const baseLength = unitLengths[unitLower];\n\n if (base === undefined) {\n throw new Error(\n `The unit provided ${unit} doesn't exist, please use the one of the following units ${JSON.stringify(\n unitMap,\n null,\n 2,\n )}`,\n );\n }\n\n // Handle special case of noether (base = 0)\n if (base === zero) {\n return zero;\n }\n\n // Fast path for bigint inputs when unit is wei (no conversion needed)\n if (typeof etherInput === 'bigint' && unitLower === 'wei') {\n return etherInput;\n }\n\n // Fast path for bigint inputs with whole units (no fractional part)\n if (typeof etherInput === 'bigint') {\n return etherInput * base;\n }\n\n let ether = numberToString(etherInput);\n\n // Is it negative?\n const negative = ether.startsWith('-');\n if (negative) {\n ether = ether.substring(1);\n }\n\n if (ether === '.') {\n throw new Error(\n `While converting number ${etherInput} to wei, invalid value`,\n );\n }\n\n // Split it into a whole and fractional part\n const comps = ether.split('.');\n if (comps.length > 2) {\n throw new Error(\n `While converting number ${etherInput} to wei, too many decimal points`,\n );\n }\n\n let whole = comps[0];\n let fraction = comps[1];\n\n if (!whole) {\n whole = '0';\n }\n if (!fraction) {\n fraction = '0';\n }\n if (fraction.length > baseLength) {\n throw new Error(\n `While converting number ${etherInput} to wei, too many decimal places`,\n );\n }\n\n fraction = fraction.padEnd(baseLength, '0');\n\n const wholeBigInt = BigInt(whole);\n const fractionBigInt = BigInt(fraction);\n let wei = wholeBigInt * base + fractionBigInt;\n\n if (negative) {\n wei = wei * negative1;\n }\n\n return wei;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask/utils",
3
- "version": "11.5.0",
3
+ "version": "11.6.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": {
@@ -108,7 +108,8 @@
108
108
  "ts-node": "^10.7.0",
109
109
  "tsd": "^0.29.0",
110
110
  "typedoc": "^0.23.15",
111
- "typescript": "~5.0.4"
111
+ "typescript": "~5.0.4",
112
+ "web3": "^4.16.0"
112
113
  },
113
114
  "packageManager": "yarn@3.8.5",
114
115
  "engines": {