@metamask-previews/utils 11.12.1-preview-9962b7e

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.
Files changed (112) hide show
  1. package/CHANGELOG.md +584 -0
  2. package/LICENSE +15 -0
  3. package/README.md +106 -0
  4. package/dist/assert.d.ts +61 -0
  5. package/dist/assert.d.ts.map +1 -0
  6. package/dist/assert.js +115 -0
  7. package/dist/assert.js.map +1 -0
  8. package/dist/base64.d.ts +25 -0
  9. package/dist/base64.d.ts.map +1 -0
  10. package/dist/base64.js +30 -0
  11. package/dist/base64.js.map +1 -0
  12. package/dist/bytes.d.ts +198 -0
  13. package/dist/bytes.d.ts.map +1 -0
  14. package/dist/bytes.js +406 -0
  15. package/dist/bytes.js.map +1 -0
  16. package/dist/caip-types.d.ts +294 -0
  17. package/dist/caip-types.d.ts.map +1 -0
  18. package/dist/caip-types.js +369 -0
  19. package/dist/caip-types.js.map +1 -0
  20. package/dist/checksum.d.ts +2 -0
  21. package/dist/checksum.d.ts.map +1 -0
  22. package/dist/checksum.js +4 -0
  23. package/dist/checksum.js.map +1 -0
  24. package/dist/coercers.d.ts +97 -0
  25. package/dist/coercers.d.ts.map +1 -0
  26. package/dist/coercers.js +159 -0
  27. package/dist/coercers.js.map +1 -0
  28. package/dist/collections.d.ts +39 -0
  29. package/dist/collections.d.ts.map +1 -0
  30. package/dist/collections.js +105 -0
  31. package/dist/collections.js.map +1 -0
  32. package/dist/encryption-types.d.ts +7 -0
  33. package/dist/encryption-types.d.ts.map +1 -0
  34. package/dist/encryption-types.js +2 -0
  35. package/dist/encryption-types.js.map +1 -0
  36. package/dist/errors.d.ts +68 -0
  37. package/dist/errors.d.ts.map +1 -0
  38. package/dist/errors.js +121 -0
  39. package/dist/errors.js.map +1 -0
  40. package/dist/fs.d.ts +133 -0
  41. package/dist/fs.d.ts.map +1 -0
  42. package/dist/fs.js +210 -0
  43. package/dist/fs.js.map +1 -0
  44. package/dist/hashing.d.ts +28 -0
  45. package/dist/hashing.d.ts.map +1 -0
  46. package/dist/hashing.js +59 -0
  47. package/dist/hashing.js.map +1 -0
  48. package/dist/hex.d.ts +117 -0
  49. package/dist/hex.d.ts.map +1 -0
  50. package/dist/hex.js +174 -0
  51. package/dist/hex.js.map +1 -0
  52. package/dist/index.d.ts +26 -0
  53. package/dist/index.d.ts.map +1 -0
  54. package/dist/index.js +21 -0
  55. package/dist/index.js.map +1 -0
  56. package/dist/json.d.ts +398 -0
  57. package/dist/json.d.ts.map +1 -0
  58. package/dist/json.js +402 -0
  59. package/dist/json.js.map +1 -0
  60. package/dist/keyring.d.ts +243 -0
  61. package/dist/keyring.d.ts.map +1 -0
  62. package/dist/keyring.js +2 -0
  63. package/dist/keyring.js.map +1 -0
  64. package/dist/logging.d.ts +30 -0
  65. package/dist/logging.d.ts.map +1 -0
  66. package/dist/logging.js +35 -0
  67. package/dist/logging.js.map +1 -0
  68. package/dist/misc.d.ts +127 -0
  69. package/dist/misc.d.ts.map +1 -0
  70. package/dist/misc.js +142 -0
  71. package/dist/misc.js.map +1 -0
  72. package/dist/mnemonic.d.ts +14 -0
  73. package/dist/mnemonic.d.ts.map +1 -0
  74. package/dist/mnemonic.js +25 -0
  75. package/dist/mnemonic.js.map +1 -0
  76. package/dist/node.d.ts +3 -0
  77. package/dist/node.d.ts.map +1 -0
  78. package/dist/node.js +3 -0
  79. package/dist/node.js.map +1 -0
  80. package/dist/number.d.ts +74 -0
  81. package/dist/number.d.ts.map +1 -0
  82. package/dist/number.js +95 -0
  83. package/dist/number.js.map +1 -0
  84. package/dist/opaque.d.ts +6 -0
  85. package/dist/opaque.d.ts.map +1 -0
  86. package/dist/opaque.js +2 -0
  87. package/dist/opaque.js.map +1 -0
  88. package/dist/promise.d.ts +45 -0
  89. package/dist/promise.d.ts.map +1 -0
  90. package/dist/promise.js +40 -0
  91. package/dist/promise.js.map +1 -0
  92. package/dist/superstruct.d.ts +20 -0
  93. package/dist/superstruct.d.ts.map +1 -0
  94. package/dist/superstruct.js +24 -0
  95. package/dist/superstruct.js.map +1 -0
  96. package/dist/time.d.ts +49 -0
  97. package/dist/time.d.ts.map +1 -0
  98. package/dist/time.js +62 -0
  99. package/dist/time.js.map +1 -0
  100. package/dist/transaction-types.d.ts +117 -0
  101. package/dist/transaction-types.d.ts.map +1 -0
  102. package/dist/transaction-types.js +2 -0
  103. package/dist/transaction-types.js.map +1 -0
  104. package/dist/unitsConversion.d.ts +80 -0
  105. package/dist/unitsConversion.d.ts.map +1 -0
  106. package/dist/unitsConversion.js +209 -0
  107. package/dist/unitsConversion.js.map +1 -0
  108. package/dist/versions.d.ts +101 -0
  109. package/dist/versions.d.ts.map +1 -0
  110. package/dist/versions.js +85 -0
  111. package/dist/versions.js.map +1 -0
  112. package/package.json +122 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"caip-types.js","sourceRoot":"","sources":["../src/caip-types.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD,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,MA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AQ,EAAE,EAAE,CACjF,CAAC;IACJ,CAAC;IAED,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,EAAE,CAAC;QAC5B,MAAM,IAAI,KAAK,CACb,kCAAkC,mBAAmB,CAAC,QAAQ,EAAE,EAAE,CACnE,CAAC;IACJ,CAAC;IAED,OAAO,GAAG,SAAS,IAAI,SAAS,IAAI,cAAc,IAAI,cAAc,IAAI,OAAO,EAAE,CAAC;AACpF,CAAC","sourcesContent":["import type { Infer } from '@metamask/superstruct';\n\nimport { definePattern } from './superstruct.js';\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 /** Stellar compatible chains */\n Stellar = 'stellar',\n /** Tron compatible chains */\n Tron = 'tron',\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 typeof value === 'string' && CAIP_CHAIN_ID_REGEX.test(value);\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 typeof value === 'string' && CAIP_NAMESPACE_REGEX.test(value);\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 typeof value === 'string' && CAIP_REFERENCE_REGEX.test(value);\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 typeof value === 'string' && CAIP_ACCOUNT_ID_REGEX.test(value);\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 typeof value === 'string' && CAIP_ACCOUNT_ADDRESS_REGEX.test(value);\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 typeof value === 'string' && CAIP_ASSET_NAMESPACE_REGEX.test(value);\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 typeof value === 'string' && CAIP_ASSET_REFERENCE_REGEX.test(value);\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 typeof value === 'string' && CAIP_TOKEN_ID_REGEX.test(value);\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 typeof value === 'string' && CAIP_ASSET_TYPE_REGEX.test(value);\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 typeof value === 'string' && CAIP_ASSET_ID_REGEX.test(value);\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"]}
@@ -0,0 +1,2 @@
1
+ export declare const ChecksumStruct: import("@metamask/superstruct").Struct<string, null>;
2
+ //# sourceMappingURL=checksum.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"checksum.d.ts","sourceRoot":"","sources":["../src/checksum.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,cAAc,sDAI1B,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { size, string } from '@metamask/superstruct';
2
+ import { base64 } from './base64.js';
3
+ export const ChecksumStruct = size(base64(string(), { paddingRequired: true }), 44, 44);
4
+ //# sourceMappingURL=checksum.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"checksum.js","sourceRoot":"","sources":["../src/checksum.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAErD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,MAAM,CAAC,MAAM,cAAc,GAAG,IAAI,CAChC,MAAM,CAAC,MAAM,EAAE,EAAE,EAAE,eAAe,EAAE,IAAI,EAAE,CAAC,EAC3C,EAAE,EACF,EAAE,CACH,CAAC","sourcesContent":["import { size, string } from '@metamask/superstruct';\n\nimport { base64 } from './base64.js';\n\nexport const ChecksumStruct = size(\n base64(string(), { paddingRequired: true }),\n 44,\n 44,\n);\n"]}
@@ -0,0 +1,97 @@
1
+ import type { Infer } from '@metamask/superstruct';
2
+ import type { Hex } from './hex.js';
3
+ declare const NumberLikeStruct: import("@metamask/superstruct").Struct<string | number | bigint, null>;
4
+ declare const BytesLikeStruct: import("@metamask/superstruct").Struct<Uint8Array<ArrayBuffer> | `0x${string}`, null>;
5
+ export type NumberLike = Infer<typeof NumberLikeStruct>;
6
+ export type BytesLike = Infer<typeof BytesLikeStruct>;
7
+ /**
8
+ * Create a number from a number-like value.
9
+ *
10
+ * - If the value is a number, it is returned as-is.
11
+ * - If the value is a `bigint`, it is converted to a number.
12
+ * - If the value is a string, it is interpreted as a decimal number.
13
+ * - If the value is a hex string (i.e., it starts with "0x"), it is
14
+ * interpreted as a hexadecimal number.
15
+ *
16
+ * This validates that the value is a number-like value, and that the resulting
17
+ * number is not `NaN` or `Infinity`.
18
+ *
19
+ * @example
20
+ * ```typescript
21
+ * const value = createNumber('0x010203');
22
+ * console.log(value); // 66051
23
+ *
24
+ * const otherValue = createNumber(123n);
25
+ * console.log(otherValue); // 123
26
+ * ```
27
+ * @param value - The value to create the number from.
28
+ * @returns The created number.
29
+ * @throws If the value is not a number-like value, or if the resulting number
30
+ * is `NaN` or `Infinity`.
31
+ */
32
+ export declare function createNumber(value: NumberLike): number;
33
+ /**
34
+ * Create a `bigint` from a number-like value.
35
+ *
36
+ * - If the value is a number, it is converted to a `bigint`.
37
+ * - If the value is a `bigint`, it is returned as-is.
38
+ * - If the value is a string, it is interpreted as a decimal number and
39
+ * converted to a `bigint`.
40
+ * - If the value is a hex string (i.e., it starts with "0x"), it is
41
+ * interpreted as a hexadecimal number and converted to a `bigint`.
42
+ *
43
+ * @example
44
+ * ```typescript
45
+ * const value = createBigInt('0x010203');
46
+ * console.log(value); // 16909060n
47
+ *
48
+ * const otherValue = createBigInt(123);
49
+ * console.log(otherValue); // 123n
50
+ * ```
51
+ * @param value - The value to create the bigint from.
52
+ * @returns The created bigint.
53
+ * @throws If the value is not a number-like value.
54
+ */
55
+ export declare function createBigInt(value: NumberLike): bigint;
56
+ /**
57
+ * Create a byte array from a bytes-like value.
58
+ *
59
+ * - If the value is a byte array, it is returned as-is.
60
+ * - If the value is a hex string (i.e., it starts with "0x"), it is interpreted
61
+ * as a hexadecimal number and converted to a byte array.
62
+ *
63
+ * @example
64
+ * ```typescript
65
+ * const value = createBytes('0x010203');
66
+ * console.log(value); // Uint8Array [ 1, 2, 3 ]
67
+ *
68
+ * const otherValue = createBytes('0x010203');
69
+ * console.log(otherValue); // Uint8Array [ 1, 2, 3 ]
70
+ * ```
71
+ * @param value - The value to create the byte array from.
72
+ * @returns The created byte array.
73
+ * @throws If the value is not a bytes-like value.
74
+ */
75
+ export declare function createBytes(value: BytesLike): Uint8Array;
76
+ /**
77
+ * Create a hexadecimal string from a bytes-like value.
78
+ *
79
+ * - If the value is a hex string (i.e., it starts with "0x"), it is returned
80
+ * as-is.
81
+ * - If the value is a `Uint8Array`, it is converted to a hex string.
82
+ *
83
+ * @example
84
+ * ```typescript
85
+ * const value = createHex(new Uint8Array([1, 2, 3]));
86
+ * console.log(value); // '0x010203'
87
+ *
88
+ * const otherValue = createHex('0x010203');
89
+ * console.log(otherValue); // '0x010203'
90
+ * ```
91
+ * @param value - The value to create the hex string from.
92
+ * @returns The created hex string.
93
+ * @throws If the value is not a bytes-like value.
94
+ */
95
+ export declare function createHex(value: BytesLike): Hex;
96
+ export {};
97
+ //# sourceMappingURL=coercers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"coercers.d.ts","sourceRoot":"","sources":["../src/coercers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAcnD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAGpC,QAAA,MAAM,gBAAgB,wEAAyD,CAAC;AAKhF,QAAA,MAAM,eAAe,uFAAiD,CAAC;AASvE,MAAM,MAAM,UAAU,GAAG,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC;AACxD,MAAM,MAAM,SAAS,GAAG,KAAK,CAAC,OAAO,eAAe,CAAC,CAAC;AAEtD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAkBtD;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAgBtD;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,SAAS,GAAG,UAAU,CAkBxD;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,SAAS,GAAG,GAAG,CAqB/C"}
@@ -0,0 +1,159 @@
1
+ import { bigint, coerce, create, instance, number, string, StructError, union, } from '@metamask/superstruct';
2
+ import { assert } from './assert.js';
3
+ import { bytesToHex, hexToBytes } from './bytes.js';
4
+ import { StrictHexStruct } from './hex.js';
5
+ const NumberLikeStruct = union([number(), bigint(), string(), StrictHexStruct]);
6
+ const NumberCoercer = coerce(number(), NumberLikeStruct, Number);
7
+ const BigIntCoercer = coerce(bigint(), NumberLikeStruct, BigInt);
8
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars -- Only referenced via `Infer<typeof ...>` below, but the value is required for that.
9
+ const BytesLikeStruct = union([StrictHexStruct, instance(Uint8Array)]);
10
+ const BytesCoercer = coerce(instance(Uint8Array), union([StrictHexStruct]), hexToBytes);
11
+ const HexCoercer = coerce(StrictHexStruct, instance(Uint8Array), bytesToHex);
12
+ /**
13
+ * Create a number from a number-like value.
14
+ *
15
+ * - If the value is a number, it is returned as-is.
16
+ * - If the value is a `bigint`, it is converted to a number.
17
+ * - If the value is a string, it is interpreted as a decimal number.
18
+ * - If the value is a hex string (i.e., it starts with "0x"), it is
19
+ * interpreted as a hexadecimal number.
20
+ *
21
+ * This validates that the value is a number-like value, and that the resulting
22
+ * number is not `NaN` or `Infinity`.
23
+ *
24
+ * @example
25
+ * ```typescript
26
+ * const value = createNumber('0x010203');
27
+ * console.log(value); // 66051
28
+ *
29
+ * const otherValue = createNumber(123n);
30
+ * console.log(otherValue); // 123
31
+ * ```
32
+ * @param value - The value to create the number from.
33
+ * @returns The created number.
34
+ * @throws If the value is not a number-like value, or if the resulting number
35
+ * is `NaN` or `Infinity`.
36
+ */
37
+ export function createNumber(value) {
38
+ try {
39
+ const result = create(value, NumberCoercer);
40
+ assert(Number.isFinite(result), `Expected a number-like value, got "${value}".`);
41
+ return result;
42
+ }
43
+ catch (error) {
44
+ if (error instanceof StructError) {
45
+ throw new Error(`Expected a number-like value, got "${value}".`);
46
+ }
47
+ /* istanbul ignore next */
48
+ throw error;
49
+ }
50
+ }
51
+ /**
52
+ * Create a `bigint` from a number-like value.
53
+ *
54
+ * - If the value is a number, it is converted to a `bigint`.
55
+ * - If the value is a `bigint`, it is returned as-is.
56
+ * - If the value is a string, it is interpreted as a decimal number and
57
+ * converted to a `bigint`.
58
+ * - If the value is a hex string (i.e., it starts with "0x"), it is
59
+ * interpreted as a hexadecimal number and converted to a `bigint`.
60
+ *
61
+ * @example
62
+ * ```typescript
63
+ * const value = createBigInt('0x010203');
64
+ * console.log(value); // 16909060n
65
+ *
66
+ * const otherValue = createBigInt(123);
67
+ * console.log(otherValue); // 123n
68
+ * ```
69
+ * @param value - The value to create the bigint from.
70
+ * @returns The created bigint.
71
+ * @throws If the value is not a number-like value.
72
+ */
73
+ export function createBigInt(value) {
74
+ try {
75
+ // The `BigInt` constructor throws if the value is not a number-like value.
76
+ // There is no need to validate the value manually.
77
+ return create(value, BigIntCoercer);
78
+ }
79
+ catch (error) {
80
+ /* istanbul ignore else -- Coercion failures always surface as StructError; the rethrow below is a safety net. */
81
+ if (error instanceof StructError) {
82
+ throw new Error(`Expected a number-like value, got "${String(error.value)}".`);
83
+ }
84
+ /* istanbul ignore next */
85
+ throw error;
86
+ }
87
+ }
88
+ /**
89
+ * Create a byte array from a bytes-like value.
90
+ *
91
+ * - If the value is a byte array, it is returned as-is.
92
+ * - If the value is a hex string (i.e., it starts with "0x"), it is interpreted
93
+ * as a hexadecimal number and converted to a byte array.
94
+ *
95
+ * @example
96
+ * ```typescript
97
+ * const value = createBytes('0x010203');
98
+ * console.log(value); // Uint8Array [ 1, 2, 3 ]
99
+ *
100
+ * const otherValue = createBytes('0x010203');
101
+ * console.log(otherValue); // Uint8Array [ 1, 2, 3 ]
102
+ * ```
103
+ * @param value - The value to create the byte array from.
104
+ * @returns The created byte array.
105
+ * @throws If the value is not a bytes-like value.
106
+ */
107
+ export function createBytes(value) {
108
+ if (typeof value === 'string' && value.toLowerCase() === '0x') {
109
+ return new Uint8Array();
110
+ }
111
+ try {
112
+ return create(value, BytesCoercer);
113
+ }
114
+ catch (error) {
115
+ /* istanbul ignore else -- Coercion failures always surface as StructError; the rethrow below is a safety net. */
116
+ if (error instanceof StructError) {
117
+ throw new Error(`Expected a bytes-like value, got "${String(error.value)}".`);
118
+ }
119
+ /* istanbul ignore next */
120
+ throw error;
121
+ }
122
+ }
123
+ /**
124
+ * Create a hexadecimal string from a bytes-like value.
125
+ *
126
+ * - If the value is a hex string (i.e., it starts with "0x"), it is returned
127
+ * as-is.
128
+ * - If the value is a `Uint8Array`, it is converted to a hex string.
129
+ *
130
+ * @example
131
+ * ```typescript
132
+ * const value = createHex(new Uint8Array([1, 2, 3]));
133
+ * console.log(value); // '0x010203'
134
+ *
135
+ * const otherValue = createHex('0x010203');
136
+ * console.log(otherValue); // '0x010203'
137
+ * ```
138
+ * @param value - The value to create the hex string from.
139
+ * @returns The created hex string.
140
+ * @throws If the value is not a bytes-like value.
141
+ */
142
+ export function createHex(value) {
143
+ if ((value instanceof Uint8Array && value.length === 0) ||
144
+ (typeof value === 'string' && value.toLowerCase() === '0x')) {
145
+ return '0x';
146
+ }
147
+ try {
148
+ return create(value, HexCoercer);
149
+ }
150
+ catch (error) {
151
+ /* istanbul ignore else -- Coercion failures always surface as StructError; the rethrow below is a safety net. */
152
+ if (error instanceof StructError) {
153
+ throw new Error(`Expected a bytes-like value, got "${String(error.value)}".`);
154
+ }
155
+ /* istanbul ignore next */
156
+ throw error;
157
+ }
158
+ }
159
+ //# sourceMappingURL=coercers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"coercers.js","sourceRoot":"","sources":["../src/coercers.ts"],"names":[],"mappings":"AACA,OAAO,EACL,MAAM,EACN,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YAAY,UAAU,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,CAAC;QACnD,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,WAAW,EAAE,KAAK,IAAI,CAAC,EAC3D,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAI,CAAC;QACH,OAAO,MAAM,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;IACnC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,iHAAiH;QACjH,IAAI,KAAK,YAAY,WAAW,EAAE,CAAC;YACjC,MAAM,IAAI,KAAK,CACb,qCAAqC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAC7D,CAAC;QACJ,CAAC;QAED,0BAA0B;QAC1B,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC","sourcesContent":["import type { Infer } from '@metamask/superstruct';\nimport {\n bigint,\n coerce,\n create,\n instance,\n number,\n string,\n StructError,\n union,\n} from '@metamask/superstruct';\n\nimport { assert } from './assert.js';\nimport { bytesToHex, hexToBytes } from './bytes.js';\nimport type { Hex } from './hex.js';\nimport { StrictHexStruct } from './hex.js';\n\nconst NumberLikeStruct = union([number(), bigint(), string(), StrictHexStruct]);\nconst NumberCoercer = coerce(number(), NumberLikeStruct, Number);\nconst BigIntCoercer = coerce(bigint(), NumberLikeStruct, BigInt);\n\n// eslint-disable-next-line @typescript-eslint/no-unused-vars -- Only referenced via `Infer<typeof ...>` below, but the value is required for that.\nconst BytesLikeStruct = union([StrictHexStruct, instance(Uint8Array)]);\nconst BytesCoercer = coerce(\n instance(Uint8Array),\n union([StrictHexStruct]),\n hexToBytes,\n);\n\nconst HexCoercer = coerce(StrictHexStruct, instance(Uint8Array), bytesToHex);\n\nexport type NumberLike = Infer<typeof NumberLikeStruct>;\nexport type BytesLike = Infer<typeof BytesLikeStruct>;\n\n/**\n * Create a number from a number-like value.\n *\n * - If the value is a number, it is returned as-is.\n * - If the value is a `bigint`, it is converted to a number.\n * - If the value is a string, it is interpreted as a decimal number.\n * - If the value is a hex string (i.e., it starts with \"0x\"), it is\n * interpreted as a hexadecimal number.\n *\n * This validates that the value is a number-like value, and that the resulting\n * number is not `NaN` or `Infinity`.\n *\n * @example\n * ```typescript\n * const value = createNumber('0x010203');\n * console.log(value); // 66051\n *\n * const otherValue = createNumber(123n);\n * console.log(otherValue); // 123\n * ```\n * @param value - The value to create the number from.\n * @returns The created number.\n * @throws If the value is not a number-like value, or if the resulting number\n * is `NaN` or `Infinity`.\n */\nexport function createNumber(value: NumberLike): number {\n try {\n const result = create(value, NumberCoercer);\n\n assert(\n Number.isFinite(result),\n `Expected a number-like value, got \"${value}\".`,\n );\n\n return result;\n } catch (error) {\n if (error instanceof StructError) {\n throw new Error(`Expected a number-like value, got \"${value}\".`);\n }\n\n /* istanbul ignore next */\n throw error;\n }\n}\n\n/**\n * Create a `bigint` from a number-like value.\n *\n * - If the value is a number, it is converted to a `bigint`.\n * - If the value is a `bigint`, it is returned as-is.\n * - If the value is a string, it is interpreted as a decimal number and\n * converted to a `bigint`.\n * - If the value is a hex string (i.e., it starts with \"0x\"), it is\n * interpreted as a hexadecimal number and converted to a `bigint`.\n *\n * @example\n * ```typescript\n * const value = createBigInt('0x010203');\n * console.log(value); // 16909060n\n *\n * const otherValue = createBigInt(123);\n * console.log(otherValue); // 123n\n * ```\n * @param value - The value to create the bigint from.\n * @returns The created bigint.\n * @throws If the value is not a number-like value.\n */\nexport function createBigInt(value: NumberLike): bigint {\n try {\n // The `BigInt` constructor throws if the value is not a number-like value.\n // There is no need to validate the value manually.\n return create(value, BigIntCoercer);\n } catch (error) {\n /* istanbul ignore else -- Coercion failures always surface as StructError; the rethrow below is a safety net. */\n if (error instanceof StructError) {\n throw new Error(\n `Expected a number-like value, got \"${String(error.value)}\".`,\n );\n }\n\n /* istanbul ignore next */\n throw error;\n }\n}\n\n/**\n * Create a byte array from a bytes-like value.\n *\n * - If the value is a byte array, it is returned as-is.\n * - If the value is a hex string (i.e., it starts with \"0x\"), it is interpreted\n * as a hexadecimal number and converted to a byte array.\n *\n * @example\n * ```typescript\n * const value = createBytes('0x010203');\n * console.log(value); // Uint8Array [ 1, 2, 3 ]\n *\n * const otherValue = createBytes('0x010203');\n * console.log(otherValue); // Uint8Array [ 1, 2, 3 ]\n * ```\n * @param value - The value to create the byte array from.\n * @returns The created byte array.\n * @throws If the value is not a bytes-like value.\n */\nexport function createBytes(value: BytesLike): Uint8Array {\n if (typeof value === 'string' && value.toLowerCase() === '0x') {\n return new Uint8Array();\n }\n\n try {\n return create(value, BytesCoercer);\n } catch (error) {\n /* istanbul ignore else -- Coercion failures always surface as StructError; the rethrow below is a safety net. */\n if (error instanceof StructError) {\n throw new Error(\n `Expected a bytes-like value, got \"${String(error.value)}\".`,\n );\n }\n\n /* istanbul ignore next */\n throw error;\n }\n}\n\n/**\n * Create a hexadecimal string from a bytes-like value.\n *\n * - If the value is a hex string (i.e., it starts with \"0x\"), it is returned\n * as-is.\n * - If the value is a `Uint8Array`, it is converted to a hex string.\n *\n * @example\n * ```typescript\n * const value = createHex(new Uint8Array([1, 2, 3]));\n * console.log(value); // '0x010203'\n *\n * const otherValue = createHex('0x010203');\n * console.log(otherValue); // '0x010203'\n * ```\n * @param value - The value to create the hex string from.\n * @returns The created hex string.\n * @throws If the value is not a bytes-like value.\n */\nexport function createHex(value: BytesLike): Hex {\n if (\n (value instanceof Uint8Array && value.length === 0) ||\n (typeof value === 'string' && value.toLowerCase() === '0x')\n ) {\n return '0x';\n }\n\n try {\n return create(value, HexCoercer);\n } catch (error) {\n /* istanbul ignore else -- Coercion failures always surface as StructError; the rethrow below is a safety net. */\n if (error instanceof StructError) {\n throw new Error(\n `Expected a bytes-like value, got \"${String(error.value)}\".`,\n );\n }\n\n /* istanbul ignore next */\n throw error;\n }\n}\n"]}
@@ -0,0 +1,39 @@
1
+ /**
2
+ * A {@link ReadonlyMap} that cannot be modified after instantiation.
3
+ * The implementation uses an inner map hidden via a private field, and the
4
+ * immutability guarantee relies on it being impossible to get a reference
5
+ * to this map.
6
+ */
7
+ declare class FrozenMap<Key, Value> implements ReadonlyMap<Key, Value> {
8
+ #private;
9
+ get size(): number;
10
+ [Symbol.iterator](): MapIterator<[Key, Value]>;
11
+ constructor(entries?: readonly (readonly [Key, Value])[] | null);
12
+ entries(): MapIterator<[Key, Value]>;
13
+ forEach(callbackfn: (value: Value, key: Key, map: this) => void, thisArg?: any): void;
14
+ get(key: Key): Value | undefined;
15
+ has(key: Key): boolean;
16
+ keys(): MapIterator<Key>;
17
+ values(): MapIterator<Value>;
18
+ toString(): string;
19
+ }
20
+ /**
21
+ * A {@link ReadonlySet} that cannot be modified after instantiation.
22
+ * The implementation uses an inner set hidden via a private field, and the
23
+ * immutability guarantee relies on it being impossible to get a reference
24
+ * to this set.
25
+ */
26
+ declare class FrozenSet<Value> implements ReadonlySet<Value> {
27
+ #private;
28
+ get size(): number;
29
+ [Symbol.iterator](): SetIterator<Value>;
30
+ constructor(values?: readonly Value[] | null);
31
+ entries(): SetIterator<[Value, Value]>;
32
+ forEach(callbackfn: (value: Value, value2: Value, set: this) => void, thisArg?: any): void;
33
+ has(value: Value): boolean;
34
+ keys(): SetIterator<Value>;
35
+ values(): SetIterator<Value>;
36
+ toString(): string;
37
+ }
38
+ export { FrozenMap, FrozenSet };
39
+ //# sourceMappingURL=collections.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"collections.d.ts","sourceRoot":"","sources":["../src/collections.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,cAAM,SAAS,CAAC,GAAG,EAAE,KAAK,CAAE,YAAW,WAAW,CAAC,GAAG,EAAE,KAAK,CAAC;;IAG5D,IAAW,IAAI,WAEd;IAEM,CAAC,MAAM,CAAC,QAAQ,CAAC,8BAEvB;IAED,YAAY,OAAO,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,EAAE,GAAG,IAAI,EAG9D;IAEM,OAAO,8BAEb;IAEM,OAAO,CACZ,UAAU,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,KAAK,IAAI,EACvD,OAAO,CAAC,EAAE,GAAG,GACZ,IAAI,CAMN;IAEM,GAAG,CAAC,GAAG,EAAE,GAAG,qBAElB;IAEM,GAAG,CAAC,GAAG,EAAE,GAAG,WAElB;IAEM,IAAI,qBAEV;IAEM,MAAM,uBAEZ;IAEM,QAAQ,IAAI,MAAM,CAQxB;CACF;AAED;;;;;GAKG;AACH,cAAM,SAAS,CAAC,KAAK,CAAE,YAAW,WAAW,CAAC,KAAK,CAAC;;IAGlD,IAAW,IAAI,WAEd;IAEM,CAAC,MAAM,CAAC,QAAQ,CAAC,uBAEvB;IAED,YAAY,MAAM,CAAC,EAAE,SAAS,KAAK,EAAE,GAAG,IAAI,EAG3C;IAEM,OAAO,gCAEb;IAEM,OAAO,CACZ,UAAU,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,KAAK,IAAI,EAC5D,OAAO,CAAC,EAAE,GAAG,GACZ,IAAI,CAMN;IAEM,GAAG,CAAC,KAAK,EAAE,KAAK,WAEtB;IAEM,IAAI,uBAEV;IAEM,MAAM,uBAEZ;IAEM,QAAQ,IAAI,MAAM,CAMxB;CACF;AAQD,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC"}
@@ -0,0 +1,105 @@
1
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
2
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
3
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
4
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
+ };
6
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
7
+ if (kind === "m") throw new TypeError("Private method is not writable");
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
9
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
10
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
11
+ };
12
+ var _FrozenMap_map, _FrozenSet_set;
13
+ /**
14
+ * A {@link ReadonlyMap} that cannot be modified after instantiation.
15
+ * The implementation uses an inner map hidden via a private field, and the
16
+ * immutability guarantee relies on it being impossible to get a reference
17
+ * to this map.
18
+ */
19
+ class FrozenMap {
20
+ get size() {
21
+ return __classPrivateFieldGet(this, _FrozenMap_map, "f").size;
22
+ }
23
+ [(_FrozenMap_map = new WeakMap(), Symbol.iterator)]() {
24
+ return __classPrivateFieldGet(this, _FrozenMap_map, "f")[Symbol.iterator]();
25
+ }
26
+ constructor(entries) {
27
+ _FrozenMap_map.set(this, void 0);
28
+ __classPrivateFieldSet(this, _FrozenMap_map, new Map(entries), "f");
29
+ Object.freeze(this);
30
+ }
31
+ entries() {
32
+ return __classPrivateFieldGet(this, _FrozenMap_map, "f").entries();
33
+ }
34
+ forEach(callbackfn, thisArg) {
35
+ // We have to wrap the specified callback in order to prevent it from
36
+ // receiving a reference to the inner map.
37
+ return __classPrivateFieldGet(this, _FrozenMap_map, "f").forEach((value, key, _map) => callbackfn.call(thisArg, value, key, this));
38
+ }
39
+ get(key) {
40
+ return __classPrivateFieldGet(this, _FrozenMap_map, "f").get(key);
41
+ }
42
+ has(key) {
43
+ return __classPrivateFieldGet(this, _FrozenMap_map, "f").has(key);
44
+ }
45
+ keys() {
46
+ return __classPrivateFieldGet(this, _FrozenMap_map, "f").keys();
47
+ }
48
+ values() {
49
+ return __classPrivateFieldGet(this, _FrozenMap_map, "f").values();
50
+ }
51
+ toString() {
52
+ return `FrozenMap(${this.size}) {${this.size > 0
53
+ ? ` ${[...this.entries()]
54
+ .map(([key, value]) => `${String(key)} => ${String(value)}`)
55
+ .join(', ')} `
56
+ : ''}}`;
57
+ }
58
+ }
59
+ /**
60
+ * A {@link ReadonlySet} that cannot be modified after instantiation.
61
+ * The implementation uses an inner set hidden via a private field, and the
62
+ * immutability guarantee relies on it being impossible to get a reference
63
+ * to this set.
64
+ */
65
+ class FrozenSet {
66
+ get size() {
67
+ return __classPrivateFieldGet(this, _FrozenSet_set, "f").size;
68
+ }
69
+ [(_FrozenSet_set = new WeakMap(), Symbol.iterator)]() {
70
+ return __classPrivateFieldGet(this, _FrozenSet_set, "f")[Symbol.iterator]();
71
+ }
72
+ constructor(values) {
73
+ _FrozenSet_set.set(this, void 0);
74
+ __classPrivateFieldSet(this, _FrozenSet_set, new Set(values), "f");
75
+ Object.freeze(this);
76
+ }
77
+ entries() {
78
+ return __classPrivateFieldGet(this, _FrozenSet_set, "f").entries();
79
+ }
80
+ forEach(callbackfn, thisArg) {
81
+ // We have to wrap the specified callback in order to prevent it from
82
+ // receiving a reference to the inner set.
83
+ return __classPrivateFieldGet(this, _FrozenSet_set, "f").forEach((value, value2, _set) => callbackfn.call(thisArg, value, value2, this));
84
+ }
85
+ has(value) {
86
+ return __classPrivateFieldGet(this, _FrozenSet_set, "f").has(value);
87
+ }
88
+ keys() {
89
+ return __classPrivateFieldGet(this, _FrozenSet_set, "f").keys();
90
+ }
91
+ values() {
92
+ return __classPrivateFieldGet(this, _FrozenSet_set, "f").values();
93
+ }
94
+ toString() {
95
+ return `FrozenSet(${this.size}) {${this.size > 0
96
+ ? ` ${[...this.values()].map((member) => String(member)).join(', ')} `
97
+ : ''}}`;
98
+ }
99
+ }
100
+ Object.freeze(FrozenMap);
101
+ Object.freeze(FrozenMap.prototype);
102
+ Object.freeze(FrozenSet);
103
+ Object.freeze(FrozenSet.prototype);
104
+ export { FrozenMap, FrozenSet };
105
+ //# sourceMappingURL=collections.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"collections.js","sourceRoot":"","sources":["../src/collections.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,EAAE,CAAC;IAC1B,CAAC;IAEM,MAAM;QACX,OAAO,uBAAA,IAAI,sBAAK,CAAC,MAAM,EAAE,CAAC;IAC5B,CAAC;IAEM,QAAQ;QACb,OAAO,aAAa,IAAI,CAAC,IAAI,MAC3B,IAAI,CAAC,IAAI,GAAG,CAAC;YACX,CAAC,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG;YACtE,CAAC,CAAC,EACN,GAAG,CAAC;IACN,CAAC;CACF;AAED,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;AACzB,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;AAEnC,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;AACzB,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;AAEnC,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC","sourcesContent":["/**\n * A {@link ReadonlyMap} that cannot be modified after instantiation.\n * The implementation uses an inner map hidden via a private field, and the\n * immutability guarantee relies on it being impossible to get a reference\n * to this map.\n */\nclass FrozenMap<Key, Value> implements ReadonlyMap<Key, Value> {\n readonly #map: Map<Key, Value>;\n\n public get size() {\n return this.#map.size;\n }\n\n public [Symbol.iterator]() {\n return this.#map[Symbol.iterator]();\n }\n\n constructor(entries?: readonly (readonly [Key, Value])[] | null) {\n this.#map = new Map<Key, Value>(entries);\n Object.freeze(this);\n }\n\n public entries() {\n return this.#map.entries();\n }\n\n public forEach(\n callbackfn: (value: Value, key: Key, map: this) => void,\n thisArg?: any,\n ): void {\n // We have to wrap the specified callback in order to prevent it from\n // receiving a reference to the inner map.\n return this.#map.forEach((value: Value, key: Key, _map: unknown) =>\n callbackfn.call(thisArg, value, key, this),\n );\n }\n\n public get(key: Key) {\n return this.#map.get(key);\n }\n\n public has(key: Key) {\n return this.#map.has(key);\n }\n\n public keys() {\n return this.#map.keys();\n }\n\n public values() {\n return this.#map.values();\n }\n\n public toString(): string {\n return `FrozenMap(${this.size}) {${\n this.size > 0\n ? ` ${[...this.entries()]\n .map(([key, value]) => `${String(key)} => ${String(value)}`)\n .join(', ')} `\n : ''\n }}`;\n }\n}\n\n/**\n * A {@link ReadonlySet} that cannot be modified after instantiation.\n * The implementation uses an inner set hidden via a private field, and the\n * immutability guarantee relies on it being impossible to get a reference\n * to this set.\n */\nclass FrozenSet<Value> implements ReadonlySet<Value> {\n readonly #set: Set<Value>;\n\n public get size() {\n return this.#set.size;\n }\n\n public [Symbol.iterator]() {\n return this.#set[Symbol.iterator]();\n }\n\n constructor(values?: readonly Value[] | null) {\n this.#set = new Set<Value>(values);\n Object.freeze(this);\n }\n\n public entries() {\n return this.#set.entries();\n }\n\n public forEach(\n callbackfn: (value: Value, value2: Value, set: this) => void,\n thisArg?: any,\n ): void {\n // We have to wrap the specified callback in order to prevent it from\n // receiving a reference to the inner set.\n return this.#set.forEach((value: Value, value2: Value, _set: unknown) =>\n callbackfn.call(thisArg, value, value2, this),\n );\n }\n\n public has(value: Value) {\n return this.#set.has(value);\n }\n\n public keys() {\n return this.#set.keys();\n }\n\n public values() {\n return this.#set.values();\n }\n\n public toString(): string {\n return `FrozenSet(${this.size}) {${\n this.size > 0\n ? ` ${[...this.values()].map((member) => String(member)).join(', ')} `\n : ''\n }}`;\n }\n}\n\nObject.freeze(FrozenMap);\nObject.freeze(FrozenMap.prototype);\n\nObject.freeze(FrozenSet);\nObject.freeze(FrozenSet.prototype);\n\nexport { FrozenMap, FrozenSet };\n"]}
@@ -0,0 +1,7 @@
1
+ export type Eip1024EncryptedData = {
2
+ version: string;
3
+ nonce: string;
4
+ ephemPublicKey: string;
5
+ ciphertext: string;
6
+ };
7
+ //# sourceMappingURL=encryption-types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encryption-types.d.ts","sourceRoot":"","sources":["../src/encryption-types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,oBAAoB,GAAG;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,cAAc,EAAE,MAAM,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=encryption-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encryption-types.js","sourceRoot":"","sources":["../src/encryption-types.ts"],"names":[],"mappings":"","sourcesContent":["export type Eip1024EncryptedData = {\n version: string;\n nonce: string;\n ephemPublicKey: string;\n ciphertext: string;\n};\n"]}
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Type guard for determining whether the given value is an error object with a
3
+ * `code` property such as the type of error that Node throws for filesystem
4
+ * operations, etc.
5
+ *
6
+ * @param error - The object to check.
7
+ * @returns A boolean.
8
+ */
9
+ export declare function isErrorWithCode(error: unknown): error is {
10
+ code: string;
11
+ };
12
+ /**
13
+ * Type guard for determining whether the given value is an error object with a
14
+ * `message` property, such as an instance of Error.
15
+ *
16
+ * @param error - The object to check.
17
+ * @returns A boolean.
18
+ */
19
+ export declare function isErrorWithMessage(error: unknown): error is {
20
+ message: string;
21
+ };
22
+ /**
23
+ * Type guard for determining whether the given value is an error object with a
24
+ * `stack` property, such as an instance of Error.
25
+ *
26
+ * @param error - The object to check.
27
+ * @returns A boolean.
28
+ */
29
+ export declare function isErrorWithStack(error: unknown): error is {
30
+ stack: string;
31
+ };
32
+ /**
33
+ * Attempts to obtain the message from a possible error object, defaulting to an
34
+ * empty string if it is impossible to do so.
35
+ *
36
+ * @param error - The possible error to get the message from.
37
+ * @returns The message if `error` is an object with a `message` property;
38
+ * the string version of `error` if it is not `undefined` or `null`; otherwise
39
+ * an empty string.
40
+ */
41
+ export declare function getErrorMessage(error: unknown): string;
42
+ /**
43
+ * Builds a new error object, linking it to the original error via the `cause`
44
+ * property if it is an Error.
45
+ *
46
+ * This function is useful to reframe error messages in general, but is
47
+ * _critical_ when interacting with any of Node's filesystem functions as
48
+ * provided via `fs.promises`, because these do not produce stack traces in the
49
+ * case of an I/O error (see <https://github.com/nodejs/node/issues/30944>).
50
+ *
51
+ * @param originalError - The error to be wrapped (something throwable).
52
+ * @param message - The desired message of the new error.
53
+ * @returns A new error object.
54
+ */
55
+ export declare function wrapError<Throwable>(originalError: Throwable, message: string): Error & {
56
+ code?: string;
57
+ };
58
+ /**
59
+ * Ensures we have a proper Error object.
60
+ * If the input is already an Error, returns it unchanged.
61
+ * Otherwise, converts to an Error with an appropriate message and preserves
62
+ * the original value as the cause.
63
+ *
64
+ * @param error - The caught error (could be Error, string, or unknown).
65
+ * @returns A proper Error instance.
66
+ */
67
+ export declare function ensureError(error: unknown): Error;
68
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAmBA;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAEzE;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,OAAO,GACb,KAAK,IAAI;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,CAE9B;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,CAE3E;AAED;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAWtD;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,SAAS,CAAC,SAAS,EACjC,aAAa,EAAE,SAAS,EACxB,OAAO,EAAE,MAAM,GACd,KAAK,GAAG;IAAE,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,CA4B3B;AAED;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,CAQjD"}