@xylabs/hex 5.0.19 → 5.0.21

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.
@@ -1 +1 @@
1
- {"version":3,"file":"ethAddress.d.ts","sourceRoot":"","sources":["../../src/ethAddress.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAA;AAE3C,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAExB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE/C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAM/C,eAAO,MAAM,eAAe,QAA4C,CAAA;AAExE,eAAO,MAAM,qBAAqB,aAAoC,CAAA;AAEtE,4CAA4C;AAC5C,eAAO,MAAM,wBAAwB,aAAwB,CAAA;AAE7D,eAAO,MAAM,uBAAuB,4DAAoE,CAAA;AAExG,8CAA8C;AAC9C,eAAO,MAAM,0BAA0B,4DAA0B,CAAA;AAGjE,MAAM,MAAM,UAAU,GAAG,KAAK,CAAC,MAAM,EAAE;IAAE,QAAQ,CAAC,aAAa,EAAE,IAAI,CAAA;CAAE,CAAC,CAAA;AAExE,eAAO,MAAM,gBAAgB,EAAmD,UAAU,CAAA;AAE1F,eAAO,MAAM,YAAY,GAAI,OAAO,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,eAAe,EAAE,SAAQ,SAAc,KAAG,UAKxG,CAAA;AAED,eAAO,MAAM,YAAY,GAAI,OAAO,OAAO,EAAE,SAAQ,SAAc,KAAG,KAAK,IAAI,UAG9E,CAAA;AAED,eAAO,MAAM,aAAa,aAIvB,CAAA;AAEH,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,UAAU,GAAG,SAAS,CAAA;AACpE,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,YAAY,GAAG,UAAU,CAAA"}
1
+ {"version":3,"file":"ethAddress.d.ts","sourceRoot":"","sources":["../../src/ethAddress.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAA;AAE3C,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAExB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE/C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAM/C,eAAO,MAAM,eAAe,QAA4C,CAAA;AAExE,eAAO,MAAM,qBAAqB,aAAoC,CAAA;AAEtE,4CAA4C;AAC5C,eAAO,MAAM,wBAAwB,aAAwB,CAAA;AAE7D,eAAO,MAAM,uBAAuB,4DAAoE,CAAA;AAExG,8CAA8C;AAC9C,eAAO,MAAM,0BAA0B,4DAA0B,CAAA;AAGjE,MAAM,MAAM,UAAU,GAAG,KAAK,CAAC,MAAM,EAAE;IAAE,QAAQ,CAAC,aAAa,EAAE,IAAI,CAAA;CAAE,CAAC,CAAA;AAExE,eAAO,MAAM,gBAAgB,EAAmD,UAAU,CAAA;AAE1F,eAAO,MAAM,YAAY,GAAI,OAAO,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,eAAe,EAAE,SAAQ,SAAc,KAAG,UAKxG,CAAA;AAED,eAAO,MAAM,YAAY,GAAI,OAAO,OAAO,EAAE,SAAQ,SAAc,KAAG,KAAK,IAAI,UAI9E,CAAA;AAED,eAAO,MAAM,aAAa,aAIvB,CAAA;AAEH,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,UAAU,GAAG,SAAS,CAAA;AACpE,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,YAAY,GAAG,UAAU,CAAA"}
@@ -242,7 +242,8 @@ var toEthAddress = (value, config = {}) => {
242
242
  };
243
243
  var isEthAddress = (value, config = {}) => {
244
244
  const { bitLength = 160, prefix = true } = config;
245
- return isHex(value, { bitLength, prefix });
245
+ const loweredValue = typeof value === "string" ? value.toLowerCase() : value;
246
+ return isHex(loweredValue, { bitLength, prefix });
246
247
  };
247
248
  var EthAddressZod = z6.string().regex(EthAddressRegEx, { message: "Invalid address format" }).refine(
248
249
  isEthAddress
@@ -252,7 +253,7 @@ function asEthAddress(value, assert) {
252
253
  let stringValue = void 0;
253
254
  switch (typeof value) {
254
255
  case "string": {
255
- stringValue = hexFromHexString(value, { prefix: true });
256
+ stringValue = hexFromHexString(value, { prefix: true, byteSize: 4 });
256
257
  break;
257
258
  }
258
259
  default: {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/address/address.ts","../../src/HexRegEx.ts","../../src/address/addressDeprecated.ts","../../src/assert.ts","../../src/hex/from/fromHexString.ts","../../src/hex/nibble.ts","../../src/hex/is.ts","../../src/hex/from/fromArrayBuffer.ts","../../src/hex/from/fromBigInt.ts","../../src/hex/from/fromNumber.ts","../../src/hex/from/from.ts","../../src/hex/as.ts","../../src/hex/hex.ts","../../src/hex/isHexZero.ts","../../src/hex/legacy.ts","../../src/hex/to.ts","../../src/address/AddressTransformZod.ts","../../src/address/AddressValidationZod.ts","../../src/address/to.ts","../../src/address/as.ts","../../src/address/is.ts","../../src/ethAddress.ts","../../src/hash/as.ts","../../src/hash/is.ts","../../src/hash/hash.ts","../../src/hash/zod.ts","../../src/hexToBigInt.ts"],"sourcesContent":["import type { Brand } from '@xylabs/typeof'\n// eslint-disable-next-line no-restricted-syntax\nimport * as z from 'zod'\n\nimport type { Hex } from '../hex/index.ts'\nimport { HexRegExMinMax } from '../HexRegEx.ts'\n\nexport const ZERO_ADDRESS = '0000000000000000000000000000000000000000' as Address\nexport const ADDRESS_LENGTH = 40 as const\n\nexport const AddressRegEx = HexRegExMinMax(ADDRESS_LENGTH / 2, ADDRESS_LENGTH / 2)\n\nexport const AddressZod = z.string()\n .regex(AddressRegEx, { message: 'Invalid hex format' }) as unknown as z.ZodType<Brand<Hex, { readonly __address: true }>>\n\nexport type Address = z.infer<typeof AddressZod>\n","export const HexRegExMinMax = (minBytes = 0, maxBytes: number = (Number.MAX_SAFE_INTEGER / 2)) => {\n return new RegExp(`^[a-f0-9]{${minBytes * 2},${maxBytes * 2}}$`)\n}\n\nexport const HexRegExMinMaxMixedCaseWithPrefix = (minBytes = 0, maxBytes: number = (Number.MAX_SAFE_INTEGER / 2)) => {\n return new RegExp(`^0x[a-fA-F0-9]{${minBytes * 2},${maxBytes * 2}}$`)\n}\n\nexport const HexRegEx = /^[0-9a-f]+$/\nexport const HexRegExWithPrefix = /^0x[0-9a-f]+$/\n","// eslint-disable-next-line no-restricted-syntax\nimport * as z from 'zod'\n\nimport { AddressRegEx } from './address.ts'\nimport { toAddress } from './to.ts'\n\n/** @deprecated use AddressZod */\nexport const AddressToStringZod = z.string().regex(AddressRegEx)\n\n/** @deprecated use AddressZod */\n// eslint-disable-next-line sonarjs/deprecation\nexport const AddressToStringSchema = AddressToStringZod\n\n/** @deprecated use AddressZod */\nexport const AddressFromStringZod = z.string().toLowerCase().regex(AddressRegEx).transform(v => toAddress(v))\n\n/** @deprecated use AddressZod */\n// eslint-disable-next-line sonarjs/deprecation\nexport const AddressFromStringSchema = AddressFromStringZod\n","import { isString, isUndefined } from '@xylabs/typeof'\n\ntype AssertCallback = (value: unknown, message: string) => string | boolean\n\nexport type AssertConfig = string | AssertCallback | boolean\n\nexport const assertError = (value: unknown, assert: AssertConfig | undefined, defaultMessage: string) => {\n if (!isUndefined(assert)) {\n const assertString\n = typeof assert === 'string'\n ? assert\n : typeof assert === 'boolean'\n ? defaultMessage\n : assert(value, defaultMessage)\n if (isString(assertString) || assertString === true) {\n throw new Error(assertString === true ? defaultMessage : assertString)\n }\n }\n // eslint-disable-next-line unicorn/no-useless-undefined\n return undefined\n}\n","import { isNumber } from '@xylabs/typeof'\n\nimport type { Hex, HexConfig } from '../hex.ts'\nimport { isHex } from '../is.ts'\nimport { bitsToNibbles } from '../nibble.ts'\n\nexport const hexFromHexString = (value: string, config: HexConfig = {}): Hex => {\n const {\n prefix = false, byteSize = 8, bitLength,\n } = config\n const nibbleBoundary = bitsToNibbles(byteSize)\n const unEvened = (value.startsWith('0x') ? value.slice(2) : value).toLowerCase()\n if (isHex(unEvened)) {\n const evenCharacters = unEvened.padStart(unEvened.length + (unEvened.length % nibbleBoundary), '0')\n const padded = isNumber(bitLength) ? evenCharacters.padStart(bitLength / 4, '0') : evenCharacters\n return (prefix ? `0x${padded}` : padded).toLowerCase() as Hex\n } else {\n throw new Error('Received string is not a value hex')\n }\n}\n","// determine the number of nibbles for a given number of bits\nexport const bitsToNibbles = (value: number): number => {\n const nibbles = value >> 2\n if (value !== nibbles << 2) throw new Error('Bits for nibbles must multiple of 4')\n return nibbles\n}\n\n// determine the number of nibbles for a given number of bits\nexport const nibblesToBits = (value: number): number => {\n return value << 2\n}\n","import { HexRegEx, HexRegExWithPrefix } from '../HexRegEx.ts'\nimport type { Hex, HexConfig } from './hex.ts'\nimport { bitsToNibbles } from './nibble.ts'\n\nexport const isHex = (value: unknown, config?: HexConfig): value is Hex => {\n // Is it a string?\n if (typeof value !== 'string') return false\n\n const valueCharLength = config?.prefix ? value.length - 2 : value.length\n\n // If a bitLength specified, does it conform?\n if (config?.bitLength !== undefined && valueCharLength !== bitsToNibbles(config?.bitLength)) return false\n\n // Does it only has hex values?\n return config?.prefix ? HexRegExWithPrefix.test(value) : HexRegEx.test(value)\n}\n","import type { Hex, HexConfig } from '../hex.ts'\nimport { hexFromHexString } from './fromHexString.ts'\n\n/** Convert an ArrayBuffer to a hex string */\nexport const hexFromArrayBuffer = (\n /** The buffer to be converted */\n buffer: ArrayBufferLike,\n /** Configuration of output format and validation */\n config?: HexConfig,\n): Hex => {\n const unPadded = [...new Uint8Array(buffer)].map(x => x.toString(16).padStart(2, '0')).join('')\n return hexFromHexString(unPadded, config)\n}\n","import type { Hex, HexConfig } from '../hex.ts'\nimport { hexFromHexString } from './fromHexString.ts'\n\n/** Convert a bigint to a hex string */\nexport const hexFromBigInt = (\n /** The bigint to be converted */\n value: bigint,\n /** Configuration of output format and validation */\n config: HexConfig = {},\n): Hex => {\n const unPadded = value.toString(16)\n return hexFromHexString(unPadded, config)\n}\n","import type { Hex, HexConfig } from '../hex.ts'\nimport { hexFromBigInt } from './fromBigInt.ts'\n\nexport const hexFromNumber = (value: number, config?: HexConfig): Hex => {\n return hexFromBigInt(BigInt(value), config)\n}\n","import type { Hex, HexConfig } from '../hex.ts'\nimport { hexFromArrayBuffer } from './fromArrayBuffer.ts'\nimport { hexFromBigInt } from './fromBigInt.ts'\nimport { hexFromHexString } from './fromHexString.ts'\nimport { hexFromNumber } from './fromNumber.ts'\n\n/** Takes unknown value and tries our best to convert it to a hex string */\nexport const hexFrom = (\n /** Supported types are string, number, bigint, and ArrayBuffer */\n value: string | number | bigint | ArrayBufferLike,\n /** Configuration of output format and validation */\n config?: HexConfig,\n): Hex => {\n switch (typeof value) {\n case 'string': {\n return hexFromHexString(value, config)\n }\n case 'bigint': {\n return hexFromBigInt(value, config)\n }\n case 'number': {\n return hexFromNumber(value, config)\n }\n case 'object': {\n return hexFromArrayBuffer(value, config)\n }\n default: {\n throw new Error(`Invalid type: ${typeof value}`)\n }\n }\n}\n","import type { AssertConfig } from '../assert.ts'\nimport { assertError } from '../assert.ts'\nimport { hexFromHexString } from './from/index.ts'\nimport type { Hex } from './hex.ts'\nimport { isHex } from './is.ts'\n\nexport function asHex(value: unknown): Hex | undefined\nexport function asHex(value: unknown, assert: AssertConfig): Hex\nexport function asHex(value: unknown, assert?: AssertConfig): Hex | undefined {\n let stringValue: string | undefined = undefined\n\n switch (typeof value) {\n case 'string': {\n stringValue = hexFromHexString(value)\n break\n }\n default: {\n return assertError(value, assert, `Unsupported type [${typeof value}]`)\n }\n }\n\n return isHex(stringValue) ? stringValue : assertError(value, assert, `Value is not Hex [${value}]`)\n}\n","import type { Brand } from '@xylabs/typeof'\n// eslint-disable-next-line no-restricted-syntax\nimport * as z from 'zod'\n\nimport { HexRegEx } from '../HexRegEx.ts'\n\nexport const HexZod = z.string()\n .regex(HexRegEx, { message: 'Invalid hex format' }) as unknown as z.ZodType<Brand<Lowercase<string>, { readonly __hex: true }>>\n\nexport type Hex = z.infer<typeof HexZod>\n\n/** Configuration of validation and output format */\nexport interface HexConfig {\n bitLength?: number\n byteSize?: number\n prefix?: boolean\n}\n","import { isString } from '@xylabs/typeof'\n\nimport { hexFromHexString } from './from/index.ts'\n\nexport const isHexZero = (value?: string) => {\n return isString(value) ? BigInt(hexFromHexString(value, { prefix: true })) === 0n : undefined\n}\n","export const toHexLegacy = (buffer: ArrayBuffer) => {\n return [...new Uint8Array(buffer)].map(x => x.toString(16).padStart(2, '0')).join('')\n}\n","import { hexFrom } from './from/index.ts'\nimport type { HexConfig } from './hex.ts'\n\n/** takes any value and tries our best to convert it to a hex string */\nexport const toHex = (\n /** Supported types are string, number, bigint, and ArrayBuffer */\n value: string | number | bigint | ArrayBufferLike,\n /** Configuration of output format and validation */\n config: HexConfig = {},\n) => {\n const { prefix = false } = config\n return hexFrom(value, { prefix, ...config })\n}\n","// eslint-disable-next-line no-restricted-syntax\nimport * as z from 'zod'\n\nimport { type Address, ADDRESS_LENGTH } from './address.ts'\nimport { AddressValidationZod } from './AddressValidationZod.ts'\n\nexport const AddressTransformZod = z.union([z.string(), z.bigint(), z.number()])\n .transform((value) => {\n switch (typeof value) {\n case 'bigint': {\n return value.toString(16).padStart(ADDRESS_LENGTH, '0')\n }\n case 'string': {\n if (value.startsWith('0x')) {\n return value.slice(2)\n }\n return value\n }\n case 'number': {\n return BigInt(value).toString(16).padStart(ADDRESS_LENGTH, '0')\n }\n }\n })\n .refine(x => AddressValidationZod.safeParse(x).data)\n .transform(x => x as Address)\n\nexport type AddressTransformZodType = z.infer<typeof AddressTransformZod>\n","// eslint-disable-next-line no-restricted-syntax\nimport * as z from 'zod'\n\nimport { HexZod } from '../hex/index.ts'\nimport type { Address } from './address.ts'\nimport { ADDRESS_LENGTH } from './address.ts'\n\nexport const AddressValidationZod = z.string()\n .refine(x => HexZod.safeParse(x))\n .refine(x => x.length === ADDRESS_LENGTH, { error: e => new Error(`Address must have 40 characters [${e.input}]`) })\n .transform(v => v as Address)\n\nexport type AddressValidationZodType = z.infer<typeof AddressValidationZod>\n","import type { HexConfig } from '../hex/index.ts'\nimport { hexFrom } from '../hex/index.ts'\nimport type { Address } from './address.ts'\nimport { AddressTransformZod } from './AddressTransformZod.ts'\n\nexport const toAddress = (value: string | number | bigint | ArrayBufferLike, config: HexConfig = {}): Address => {\n const { bitLength = 160, prefix = false } = config\n return hexFrom(value, {\n bitLength, prefix, ...config,\n }) as unknown as Address\n}\n\n/** @alpha */\nexport function toAddressV2(value: unknown, assert: boolean = false): Address | undefined {\n return assert\n ? AddressTransformZod.parse(value)\n : AddressTransformZod.safeParse(value).data\n}\n","import { isObject } from '@xylabs/typeof'\n\nimport type { AssertConfig } from '../assert.ts'\nimport { assertError } from '../assert.ts'\nimport { hexFromHexString } from '../hex/index.ts'\nimport type { Address } from './address.ts'\nimport { AddressValidationZod } from './AddressValidationZod.ts'\nimport { isAddress } from './is.ts'\n\nexport function asAddress(value: unknown): Address | undefined\nexport function asAddress(value: unknown, assert: AssertConfig): Address\nexport function asAddress(value: unknown, assert?: AssertConfig): Address | undefined {\n try {\n let stringValue: string | undefined = undefined\n\n switch (typeof value) {\n case 'string': {\n stringValue = hexFromHexString(value, { prefix: false })\n break\n }\n default: {\n return isObject(assert) ? assertError(value, assert, `Unsupported type [${typeof value}]`) : undefined\n }\n }\n return isAddress(stringValue) ? stringValue : assertError(value, assert, `Value is not an Address [${value}]`)\n } catch (ex) {\n const error = ex as Error\n return assertError(undefined, assert, error.message)\n }\n}\n\n/** @alpha */\nexport function asAddressV2(value: unknown, assert: boolean = false): Address | undefined {\n return assert\n ? AddressValidationZod.parse(value)\n : AddressValidationZod.safeParse(value).data\n}\n","import type { HexConfig } from '../hex/index.ts'\nimport { isHex } from '../hex/index.ts'\nimport type { Address } from './address.ts'\nimport { AddressValidationZod } from './AddressValidationZod.ts'\n\nexport const isAddress = (value: unknown, config: HexConfig = {}): value is Address => {\n const { bitLength = 160, prefix = false } = config\n return isHex(value, { bitLength, prefix })\n}\n\n/** @alpha */\nexport function isAddressV2(value: unknown): value is Address {\n return AddressValidationZod.safeParse(value).success\n}\n","import type { Brand } from '@xylabs/typeof'\n// eslint-disable-next-line no-restricted-syntax\nimport * as z from 'zod'\n\nimport type { AssertConfig } from './assert.ts'\nimport { assertError } from './assert.ts'\nimport type { HexConfig } from './hex/index.ts'\nimport {\n hexFrom, hexFromHexString, isHex,\n} from './hex/index.ts'\nimport { HexRegExMinMaxMixedCaseWithPrefix } from './HexRegEx.ts'\n\nexport const EthAddressRegEx = HexRegExMinMaxMixedCaseWithPrefix(20, 20)\n\nexport const EthAddressToStringZod = z.string().regex(EthAddressRegEx)\n\n/** @deprecated use EthAddressToStringZod */\nexport const EthAddressToStringSchema = EthAddressToStringZod\n\nexport const EthAddressFromStringZod = z.string().regex(EthAddressRegEx).transform(v => toEthAddress(v))\n\n/** @deprecated use EthAddressFromStringZod */\nexport const EthAddressFromStringSchema = EthAddressFromStringZod\n\n// using true instead of unique symbol to avoid conflicts with other versions of library\nexport type EthAddress = Brand<string, { readonly __eth_address: true }>\n\nexport const ETH_ZERO_ADDRESS = '0x0000000000000000000000000000000000000000' as EthAddress\n\nexport const toEthAddress = (value: string | number | bigint | ArrayBufferLike, config: HexConfig = {}): EthAddress => {\n const { bitLength = 160, prefix = false } = config\n return `0x${hexFrom(value, {\n bitLength, prefix, ...config,\n })}` as EthAddress\n}\n\nexport const isEthAddress = (value: unknown, config: HexConfig = {}): value is EthAddress => {\n const { bitLength = 160, prefix = true } = config\n return isHex(value, { bitLength, prefix })\n}\n\nexport const EthAddressZod = z.string()\n .regex(EthAddressRegEx, { message: 'Invalid address format' })\n .refine(\n isEthAddress,\n )\n\nexport function asEthAddress(value: unknown): EthAddress | undefined\nexport function asEthAddress(value: unknown, assert: AssertConfig): EthAddress\nexport function asEthAddress(value: unknown, assert?: AssertConfig): EthAddress | undefined {\n try {\n let stringValue: string | undefined = undefined\n\n switch (typeof value) {\n case 'string': {\n stringValue = hexFromHexString(value, { prefix: true })\n break\n }\n default: {\n if (value !== undefined) {\n return assertError(value, assert, `Unsupported type [${typeof value}]`)\n }\n }\n }\n return isEthAddress(stringValue) ? stringValue : assertError(value, assert, `Value is not an EthAddress [${value}]`)\n } catch (ex) {\n const error = ex as Error\n return assertError(undefined, assert, error.message)\n }\n}\n","import { isUndefined } from '@xylabs/typeof'\n\nimport type { AssertConfig } from '../assert.ts'\nimport { assertError } from '../assert.ts'\nimport { hexFromHexString } from '../hex/index.ts'\nimport { type Hash } from './hash.ts'\nimport { isHash } from './is.ts'\n\nexport function asHash(value: unknown): Hash | undefined\nexport function asHash(value: unknown, assert: AssertConfig): Hash\nexport function asHash(value: unknown, assert?: AssertConfig): Hash | undefined {\n let stringValue: string | undefined = undefined\n\n switch (typeof value) {\n case 'string': {\n stringValue = hexFromHexString(value)\n break\n }\n default: {\n return isUndefined(assert) ? undefined : assertError(value, assert, `Unsupported type [${typeof value}]`)\n }\n }\n return isHash(stringValue) ? stringValue : assertError(value, assert, `Value is not a Hash [${value}]`)\n}\n","import { isHex } from '../hex/index.ts'\nimport type { Hash, HashBitLength } from './hash.ts'\n\nexport const isHash = (value: unknown, bitLength: HashBitLength = 256): value is Hash => {\n return isHex(value, { bitLength })\n}\n","import type { Brand } from '@xylabs/typeof'\n// eslint-disable-next-line no-restricted-syntax\nimport * as z from 'zod'\n\nimport type { Hex } from '../hex/index.ts'\nimport { HexRegExMinMax } from '../HexRegEx.ts'\n\nexport const HASH_LENGTH = 32 as const\n\nexport const HashRegEx = HexRegExMinMax(HASH_LENGTH, HASH_LENGTH)\n\nexport const ZERO_HASH = '0000000000000000000000000000000000000000000000000000000000000000' as Hash\n\nexport type HashBitLength = 32 | 64 | 128 | 256 | 512 | 1024 | 2048 | 4096\nexport const HashBitLength: HashBitLength[] = [32, 64, 128, 256, 512, 1024, 2048, 4096]\n\nexport const isHashBitLength = (value: unknown): value is HashBitLength => {\n return typeof value === 'number' && HashBitLength.includes(value as HashBitLength)\n}\n\nexport const HashZod = z.string()\n .regex(HashRegEx, { message: 'Invalid hex format' }) as unknown as z.ZodType<Brand<Hex, { readonly __hash: true }>>\n\nexport type Hash = z.infer<typeof HashZod>\n","// eslint-disable-next-line no-restricted-syntax\nimport * as z from 'zod'\n\nimport { asHash } from './as.ts'\nimport type { Hash } from './hash.ts'\nimport { HashZod } from './hash.ts'\n\nexport const HashToJsonZod = HashZod.transform<string>(v => v)\nexport const JsonToHashZod = z.string().transform<Hash>(v => asHash(v, true))\n","import { type Hex, hexFromHexString } from './hex/index.ts'\n\nexport function hexToBigInt(hex: Hex): bigint {\n return BigInt(hexFromHexString(hex, { prefix: true }))\n}\n"],"mappings":";AAEA,YAAY,OAAO;;;ACFZ,IAAM,iBAAiB,CAAC,WAAW,GAAG,WAAoB,OAAO,mBAAmB,MAAO;AAChG,SAAO,IAAI,OAAO,aAAa,WAAW,CAAC,IAAI,WAAW,CAAC,IAAI;AACjE;AAEO,IAAM,oCAAoC,CAAC,WAAW,GAAG,WAAoB,OAAO,mBAAmB,MAAO;AACnH,SAAO,IAAI,OAAO,kBAAkB,WAAW,CAAC,IAAI,WAAW,CAAC,IAAI;AACtE;AAEO,IAAM,WAAW;AACjB,IAAM,qBAAqB;;;ADF3B,IAAM,eAAe;AACrB,IAAM,iBAAiB;AAEvB,IAAM,eAAe,eAAe,iBAAiB,GAAG,iBAAiB,CAAC;AAE1E,IAAM,aAAe,SAAO,EAChC,MAAM,cAAc,EAAE,SAAS,qBAAqB,CAAC;;;AEZxD,YAAYA,QAAO;;;ACDnB,SAAS,UAAU,mBAAmB;AAM/B,IAAM,cAAc,CAAC,OAAgB,QAAkC,mBAA2B;AACvG,MAAI,CAAC,YAAY,MAAM,GAAG;AACxB,UAAM,eACF,OAAO,WAAW,WAChB,SACA,OAAO,WAAW,YAChB,iBACA,OAAO,OAAO,cAAc;AACpC,QAAI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","z"]}
1
+ {"version":3,"sources":["../../src/address/address.ts","../../src/HexRegEx.ts","../../src/address/addressDeprecated.ts","../../src/assert.ts","../../src/hex/from/fromHexString.ts","../../src/hex/nibble.ts","../../src/hex/is.ts","../../src/hex/from/fromArrayBuffer.ts","../../src/hex/from/fromBigInt.ts","../../src/hex/from/fromNumber.ts","../../src/hex/from/from.ts","../../src/hex/as.ts","../../src/hex/hex.ts","../../src/hex/isHexZero.ts","../../src/hex/legacy.ts","../../src/hex/to.ts","../../src/address/AddressTransformZod.ts","../../src/address/AddressValidationZod.ts","../../src/address/to.ts","../../src/address/as.ts","../../src/address/is.ts","../../src/ethAddress.ts","../../src/hash/as.ts","../../src/hash/is.ts","../../src/hash/hash.ts","../../src/hash/zod.ts","../../src/hexToBigInt.ts"],"sourcesContent":["import type { Brand } from '@xylabs/typeof'\n// eslint-disable-next-line no-restricted-syntax\nimport * as z from 'zod'\n\nimport type { Hex } from '../hex/index.ts'\nimport { HexRegExMinMax } from '../HexRegEx.ts'\n\nexport const ZERO_ADDRESS = '0000000000000000000000000000000000000000' as Address\nexport const ADDRESS_LENGTH = 40 as const\n\nexport const AddressRegEx = HexRegExMinMax(ADDRESS_LENGTH / 2, ADDRESS_LENGTH / 2)\n\nexport const AddressZod = z.string()\n .regex(AddressRegEx, { message: 'Invalid hex format' }) as unknown as z.ZodType<Brand<Hex, { readonly __address: true }>>\n\nexport type Address = z.infer<typeof AddressZod>\n","export const HexRegExMinMax = (minBytes = 0, maxBytes: number = (Number.MAX_SAFE_INTEGER / 2)) => {\n return new RegExp(`^[a-f0-9]{${minBytes * 2},${maxBytes * 2}}$`)\n}\n\nexport const HexRegExMinMaxMixedCaseWithPrefix = (minBytes = 0, maxBytes: number = (Number.MAX_SAFE_INTEGER / 2)) => {\n return new RegExp(`^0x[a-fA-F0-9]{${minBytes * 2},${maxBytes * 2}}$`)\n}\n\nexport const HexRegEx = /^[0-9a-f]+$/\nexport const HexRegExWithPrefix = /^0x[0-9a-f]+$/\n","// eslint-disable-next-line no-restricted-syntax\nimport * as z from 'zod'\n\nimport { AddressRegEx } from './address.ts'\nimport { toAddress } from './to.ts'\n\n/** @deprecated use AddressZod */\nexport const AddressToStringZod = z.string().regex(AddressRegEx)\n\n/** @deprecated use AddressZod */\n// eslint-disable-next-line sonarjs/deprecation\nexport const AddressToStringSchema = AddressToStringZod\n\n/** @deprecated use AddressZod */\nexport const AddressFromStringZod = z.string().toLowerCase().regex(AddressRegEx).transform(v => toAddress(v))\n\n/** @deprecated use AddressZod */\n// eslint-disable-next-line sonarjs/deprecation\nexport const AddressFromStringSchema = AddressFromStringZod\n","import { isString, isUndefined } from '@xylabs/typeof'\n\ntype AssertCallback = (value: unknown, message: string) => string | boolean\n\nexport type AssertConfig = string | AssertCallback | boolean\n\nexport const assertError = (value: unknown, assert: AssertConfig | undefined, defaultMessage: string) => {\n if (!isUndefined(assert)) {\n const assertString\n = typeof assert === 'string'\n ? assert\n : typeof assert === 'boolean'\n ? defaultMessage\n : assert(value, defaultMessage)\n if (isString(assertString) || assertString === true) {\n throw new Error(assertString === true ? defaultMessage : assertString)\n }\n }\n // eslint-disable-next-line unicorn/no-useless-undefined\n return undefined\n}\n","import { isNumber } from '@xylabs/typeof'\n\nimport type { Hex, HexConfig } from '../hex.ts'\nimport { isHex } from '../is.ts'\nimport { bitsToNibbles } from '../nibble.ts'\n\nexport const hexFromHexString = (value: string, config: HexConfig = {}): Hex => {\n const {\n prefix = false, byteSize = 8, bitLength,\n } = config\n const nibbleBoundary = bitsToNibbles(byteSize)\n const unEvened = (value.startsWith('0x') ? value.slice(2) : value).toLowerCase()\n if (isHex(unEvened)) {\n const evenCharacters = unEvened.padStart(unEvened.length + (unEvened.length % nibbleBoundary), '0')\n const padded = isNumber(bitLength) ? evenCharacters.padStart(bitLength / 4, '0') : evenCharacters\n return (prefix ? `0x${padded}` : padded).toLowerCase() as Hex\n } else {\n throw new Error('Received string is not a value hex')\n }\n}\n","// determine the number of nibbles for a given number of bits\nexport const bitsToNibbles = (value: number): number => {\n const nibbles = value >> 2\n if (value !== nibbles << 2) throw new Error('Bits for nibbles must multiple of 4')\n return nibbles\n}\n\n// determine the number of nibbles for a given number of bits\nexport const nibblesToBits = (value: number): number => {\n return value << 2\n}\n","import { HexRegEx, HexRegExWithPrefix } from '../HexRegEx.ts'\nimport type { Hex, HexConfig } from './hex.ts'\nimport { bitsToNibbles } from './nibble.ts'\n\nexport const isHex = (value: unknown, config?: HexConfig): value is Hex => {\n // Is it a string?\n if (typeof value !== 'string') return false\n\n const valueCharLength = config?.prefix ? value.length - 2 : value.length\n\n // If a bitLength specified, does it conform?\n if (config?.bitLength !== undefined && valueCharLength !== bitsToNibbles(config?.bitLength)) return false\n\n // Does it only has hex values?\n return config?.prefix ? HexRegExWithPrefix.test(value) : HexRegEx.test(value)\n}\n","import type { Hex, HexConfig } from '../hex.ts'\nimport { hexFromHexString } from './fromHexString.ts'\n\n/** Convert an ArrayBuffer to a hex string */\nexport const hexFromArrayBuffer = (\n /** The buffer to be converted */\n buffer: ArrayBufferLike,\n /** Configuration of output format and validation */\n config?: HexConfig,\n): Hex => {\n const unPadded = [...new Uint8Array(buffer)].map(x => x.toString(16).padStart(2, '0')).join('')\n return hexFromHexString(unPadded, config)\n}\n","import type { Hex, HexConfig } from '../hex.ts'\nimport { hexFromHexString } from './fromHexString.ts'\n\n/** Convert a bigint to a hex string */\nexport const hexFromBigInt = (\n /** The bigint to be converted */\n value: bigint,\n /** Configuration of output format and validation */\n config: HexConfig = {},\n): Hex => {\n const unPadded = value.toString(16)\n return hexFromHexString(unPadded, config)\n}\n","import type { Hex, HexConfig } from '../hex.ts'\nimport { hexFromBigInt } from './fromBigInt.ts'\n\nexport const hexFromNumber = (value: number, config?: HexConfig): Hex => {\n return hexFromBigInt(BigInt(value), config)\n}\n","import type { Hex, HexConfig } from '../hex.ts'\nimport { hexFromArrayBuffer } from './fromArrayBuffer.ts'\nimport { hexFromBigInt } from './fromBigInt.ts'\nimport { hexFromHexString } from './fromHexString.ts'\nimport { hexFromNumber } from './fromNumber.ts'\n\n/** Takes unknown value and tries our best to convert it to a hex string */\nexport const hexFrom = (\n /** Supported types are string, number, bigint, and ArrayBuffer */\n value: string | number | bigint | ArrayBufferLike,\n /** Configuration of output format and validation */\n config?: HexConfig,\n): Hex => {\n switch (typeof value) {\n case 'string': {\n return hexFromHexString(value, config)\n }\n case 'bigint': {\n return hexFromBigInt(value, config)\n }\n case 'number': {\n return hexFromNumber(value, config)\n }\n case 'object': {\n return hexFromArrayBuffer(value, config)\n }\n default: {\n throw new Error(`Invalid type: ${typeof value}`)\n }\n }\n}\n","import type { AssertConfig } from '../assert.ts'\nimport { assertError } from '../assert.ts'\nimport { hexFromHexString } from './from/index.ts'\nimport type { Hex } from './hex.ts'\nimport { isHex } from './is.ts'\n\nexport function asHex(value: unknown): Hex | undefined\nexport function asHex(value: unknown, assert: AssertConfig): Hex\nexport function asHex(value: unknown, assert?: AssertConfig): Hex | undefined {\n let stringValue: string | undefined = undefined\n\n switch (typeof value) {\n case 'string': {\n stringValue = hexFromHexString(value)\n break\n }\n default: {\n return assertError(value, assert, `Unsupported type [${typeof value}]`)\n }\n }\n\n return isHex(stringValue) ? stringValue : assertError(value, assert, `Value is not Hex [${value}]`)\n}\n","import type { Brand } from '@xylabs/typeof'\n// eslint-disable-next-line no-restricted-syntax\nimport * as z from 'zod'\n\nimport { HexRegEx } from '../HexRegEx.ts'\n\nexport const HexZod = z.string()\n .regex(HexRegEx, { message: 'Invalid hex format' }) as unknown as z.ZodType<Brand<Lowercase<string>, { readonly __hex: true }>>\n\nexport type Hex = z.infer<typeof HexZod>\n\n/** Configuration of validation and output format */\nexport interface HexConfig {\n bitLength?: number\n byteSize?: number\n prefix?: boolean\n}\n","import { isString } from '@xylabs/typeof'\n\nimport { hexFromHexString } from './from/index.ts'\n\nexport const isHexZero = (value?: string) => {\n return isString(value) ? BigInt(hexFromHexString(value, { prefix: true })) === 0n : undefined\n}\n","export const toHexLegacy = (buffer: ArrayBuffer) => {\n return [...new Uint8Array(buffer)].map(x => x.toString(16).padStart(2, '0')).join('')\n}\n","import { hexFrom } from './from/index.ts'\nimport type { HexConfig } from './hex.ts'\n\n/** takes any value and tries our best to convert it to a hex string */\nexport const toHex = (\n /** Supported types are string, number, bigint, and ArrayBuffer */\n value: string | number | bigint | ArrayBufferLike,\n /** Configuration of output format and validation */\n config: HexConfig = {},\n) => {\n const { prefix = false } = config\n return hexFrom(value, { prefix, ...config })\n}\n","// eslint-disable-next-line no-restricted-syntax\nimport * as z from 'zod'\n\nimport { type Address, ADDRESS_LENGTH } from './address.ts'\nimport { AddressValidationZod } from './AddressValidationZod.ts'\n\nexport const AddressTransformZod = z.union([z.string(), z.bigint(), z.number()])\n .transform((value) => {\n switch (typeof value) {\n case 'bigint': {\n return value.toString(16).padStart(ADDRESS_LENGTH, '0')\n }\n case 'string': {\n if (value.startsWith('0x')) {\n return value.slice(2)\n }\n return value\n }\n case 'number': {\n return BigInt(value).toString(16).padStart(ADDRESS_LENGTH, '0')\n }\n }\n })\n .refine(x => AddressValidationZod.safeParse(x).data)\n .transform(x => x as Address)\n\nexport type AddressTransformZodType = z.infer<typeof AddressTransformZod>\n","// eslint-disable-next-line no-restricted-syntax\nimport * as z from 'zod'\n\nimport { HexZod } from '../hex/index.ts'\nimport type { Address } from './address.ts'\nimport { ADDRESS_LENGTH } from './address.ts'\n\nexport const AddressValidationZod = z.string()\n .refine(x => HexZod.safeParse(x))\n .refine(x => x.length === ADDRESS_LENGTH, { error: e => new Error(`Address must have 40 characters [${e.input}]`) })\n .transform(v => v as Address)\n\nexport type AddressValidationZodType = z.infer<typeof AddressValidationZod>\n","import type { HexConfig } from '../hex/index.ts'\nimport { hexFrom } from '../hex/index.ts'\nimport type { Address } from './address.ts'\nimport { AddressTransformZod } from './AddressTransformZod.ts'\n\nexport const toAddress = (value: string | number | bigint | ArrayBufferLike, config: HexConfig = {}): Address => {\n const { bitLength = 160, prefix = false } = config\n return hexFrom(value, {\n bitLength, prefix, ...config,\n }) as unknown as Address\n}\n\n/** @alpha */\nexport function toAddressV2(value: unknown, assert: boolean = false): Address | undefined {\n return assert\n ? AddressTransformZod.parse(value)\n : AddressTransformZod.safeParse(value).data\n}\n","import { isObject } from '@xylabs/typeof'\n\nimport type { AssertConfig } from '../assert.ts'\nimport { assertError } from '../assert.ts'\nimport { hexFromHexString } from '../hex/index.ts'\nimport type { Address } from './address.ts'\nimport { AddressValidationZod } from './AddressValidationZod.ts'\nimport { isAddress } from './is.ts'\n\nexport function asAddress(value: unknown): Address | undefined\nexport function asAddress(value: unknown, assert: AssertConfig): Address\nexport function asAddress(value: unknown, assert?: AssertConfig): Address | undefined {\n try {\n let stringValue: string | undefined = undefined\n\n switch (typeof value) {\n case 'string': {\n stringValue = hexFromHexString(value, { prefix: false })\n break\n }\n default: {\n return isObject(assert) ? assertError(value, assert, `Unsupported type [${typeof value}]`) : undefined\n }\n }\n return isAddress(stringValue) ? stringValue : assertError(value, assert, `Value is not an Address [${value}]`)\n } catch (ex) {\n const error = ex as Error\n return assertError(undefined, assert, error.message)\n }\n}\n\n/** @alpha */\nexport function asAddressV2(value: unknown, assert: boolean = false): Address | undefined {\n return assert\n ? AddressValidationZod.parse(value)\n : AddressValidationZod.safeParse(value).data\n}\n","import type { HexConfig } from '../hex/index.ts'\nimport { isHex } from '../hex/index.ts'\nimport type { Address } from './address.ts'\nimport { AddressValidationZod } from './AddressValidationZod.ts'\n\nexport const isAddress = (value: unknown, config: HexConfig = {}): value is Address => {\n const { bitLength = 160, prefix = false } = config\n return isHex(value, { bitLength, prefix })\n}\n\n/** @alpha */\nexport function isAddressV2(value: unknown): value is Address {\n return AddressValidationZod.safeParse(value).success\n}\n","import type { Brand } from '@xylabs/typeof'\n// eslint-disable-next-line no-restricted-syntax\nimport * as z from 'zod'\n\nimport type { AssertConfig } from './assert.ts'\nimport { assertError } from './assert.ts'\nimport type { HexConfig } from './hex/index.ts'\nimport {\n hexFrom, hexFromHexString, isHex,\n} from './hex/index.ts'\nimport { HexRegExMinMaxMixedCaseWithPrefix } from './HexRegEx.ts'\n\nexport const EthAddressRegEx = HexRegExMinMaxMixedCaseWithPrefix(20, 20)\n\nexport const EthAddressToStringZod = z.string().regex(EthAddressRegEx)\n\n/** @deprecated use EthAddressToStringZod */\nexport const EthAddressToStringSchema = EthAddressToStringZod\n\nexport const EthAddressFromStringZod = z.string().regex(EthAddressRegEx).transform(v => toEthAddress(v))\n\n/** @deprecated use EthAddressFromStringZod */\nexport const EthAddressFromStringSchema = EthAddressFromStringZod\n\n// using true instead of unique symbol to avoid conflicts with other versions of library\nexport type EthAddress = Brand<string, { readonly __eth_address: true }>\n\nexport const ETH_ZERO_ADDRESS = '0x0000000000000000000000000000000000000000' as EthAddress\n\nexport const toEthAddress = (value: string | number | bigint | ArrayBufferLike, config: HexConfig = {}): EthAddress => {\n const { bitLength = 160, prefix = false } = config\n return `0x${hexFrom(value, {\n bitLength, prefix, ...config,\n })}` as EthAddress\n}\n\nexport const isEthAddress = (value: unknown, config: HexConfig = {}): value is EthAddress => {\n const { bitLength = 160, prefix = true } = config\n const loweredValue = typeof value === 'string' ? value.toLowerCase() : value\n return isHex(loweredValue, { bitLength, prefix })\n}\n\nexport const EthAddressZod = z.string()\n .regex(EthAddressRegEx, { message: 'Invalid address format' })\n .refine(\n isEthAddress,\n )\n\nexport function asEthAddress(value: unknown): EthAddress | undefined\nexport function asEthAddress(value: unknown, assert: AssertConfig): EthAddress\nexport function asEthAddress(value: unknown, assert?: AssertConfig): EthAddress | undefined {\n try {\n let stringValue: string | undefined = undefined\n\n switch (typeof value) {\n case 'string': {\n stringValue = hexFromHexString(value, { prefix: true, byteSize: 4 })\n break\n }\n default: {\n if (value !== undefined) {\n return assertError(value, assert, `Unsupported type [${typeof value}]`)\n }\n }\n }\n return isEthAddress(stringValue) ? stringValue : assertError(value, assert, `Value is not an EthAddress [${value}]`)\n } catch (ex) {\n const error = ex as Error\n return assertError(undefined, assert, error.message)\n }\n}\n","import { isUndefined } from '@xylabs/typeof'\n\nimport type { AssertConfig } from '../assert.ts'\nimport { assertError } from '../assert.ts'\nimport { hexFromHexString } from '../hex/index.ts'\nimport { type Hash } from './hash.ts'\nimport { isHash } from './is.ts'\n\nexport function asHash(value: unknown): Hash | undefined\nexport function asHash(value: unknown, assert: AssertConfig): Hash\nexport function asHash(value: unknown, assert?: AssertConfig): Hash | undefined {\n let stringValue: string | undefined = undefined\n\n switch (typeof value) {\n case 'string': {\n stringValue = hexFromHexString(value)\n break\n }\n default: {\n return isUndefined(assert) ? undefined : assertError(value, assert, `Unsupported type [${typeof value}]`)\n }\n }\n return isHash(stringValue) ? stringValue : assertError(value, assert, `Value is not a Hash [${value}]`)\n}\n","import { isHex } from '../hex/index.ts'\nimport type { Hash, HashBitLength } from './hash.ts'\n\nexport const isHash = (value: unknown, bitLength: HashBitLength = 256): value is Hash => {\n return isHex(value, { bitLength })\n}\n","import type { Brand } from '@xylabs/typeof'\n// eslint-disable-next-line no-restricted-syntax\nimport * as z from 'zod'\n\nimport type { Hex } from '../hex/index.ts'\nimport { HexRegExMinMax } from '../HexRegEx.ts'\n\nexport const HASH_LENGTH = 32 as const\n\nexport const HashRegEx = HexRegExMinMax(HASH_LENGTH, HASH_LENGTH)\n\nexport const ZERO_HASH = '0000000000000000000000000000000000000000000000000000000000000000' as Hash\n\nexport type HashBitLength = 32 | 64 | 128 | 256 | 512 | 1024 | 2048 | 4096\nexport const HashBitLength: HashBitLength[] = [32, 64, 128, 256, 512, 1024, 2048, 4096]\n\nexport const isHashBitLength = (value: unknown): value is HashBitLength => {\n return typeof value === 'number' && HashBitLength.includes(value as HashBitLength)\n}\n\nexport const HashZod = z.string()\n .regex(HashRegEx, { message: 'Invalid hex format' }) as unknown as z.ZodType<Brand<Hex, { readonly __hash: true }>>\n\nexport type Hash = z.infer<typeof HashZod>\n","// eslint-disable-next-line no-restricted-syntax\nimport * as z from 'zod'\n\nimport { asHash } from './as.ts'\nimport type { Hash } from './hash.ts'\nimport { HashZod } from './hash.ts'\n\nexport const HashToJsonZod = HashZod.transform<string>(v => v)\nexport const JsonToHashZod = z.string().transform<Hash>(v => asHash(v, true))\n","import { type Hex, hexFromHexString } from './hex/index.ts'\n\nexport function hexToBigInt(hex: Hex): bigint {\n return BigInt(hexFromHexString(hex, { prefix: true }))\n}\n"],"mappings":";AAEA,YAAY,OAAO;;;ACFZ,IAAM,iBAAiB,CAAC,WAAW,GAAG,WAAoB,OAAO,mBAAmB,MAAO;AAChG,SAAO,IAAI,OAAO,aAAa,WAAW,CAAC,IAAI,WAAW,CAAC,IAAI;AACjE;AAEO,IAAM,oCAAoC,CAAC,WAAW,GAAG,WAAoB,OAAO,mBAAmB,MAAO;AACnH,SAAO,IAAI,OAAO,kBAAkB,WAAW,CAAC,IAAI,WAAW,CAAC,IAAI;AACtE;AAEO,IAAM,WAAW;AACjB,IAAM,qBAAqB;;;ADF3B,IAAM,eAAe;AACrB,IAAM,iBAAiB;AAEvB,IAAM,eAAe,eAAe,iBAAiB,GAAG,iBAAiB,CAAC;AAE1E,IAAM,aAAe,SAAO,EAChC,MAAM,cAAc,EAAE,SAAS,qBAAqB,CAAC;;;AEZxD,YAAYA,QAAO;;;ACDnB,SAAS,UAAU,mBAAmB;AAM/B,IAAM,cAAc,CAAC,OAAgB,QAAkC,mBAA2B;AACvG,MAAI,CAAC,YAAY,MAAM,GAAG;AACxB,UAAM,eACF,OAAO,WAAW,WAChB,SACA,OAAO,WAAW,YAChB,iBACA,OAAO,OAAO,cAAc;AACpC,QAAI,SAAS,YAAY,KAAK,iBAAiB,MAAM;AACnD,YAAM,IAAI,MAAM,iBAAiB,OAAO,iBAAiB,YAAY;AAAA,IACvE;AAAA,EACF;AAEA,SAAO;AACT;;;ACpBA,SAAS,gBAAgB;;;ACClB,IAAM,gBAAgB,CAAC,UAA0B;AACtD,QAAM,UAAU,SAAS;AACzB,MAAI,UAAU,WAAW,EAAG,OAAM,IAAI,MAAM,qCAAqC;AACjF,SAAO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uB;AACvF,SAAO,MAAM,OAAO,EAAE,UAAU,CAAC;AACnC;;;ADKO,SAAS,OAAO,OAAgB,QAAyC;AAC9E,MAAI,cAAkC;AAEtC,UAAQ,OAAO,OAAO;AAAA,IACpB,KAAK,UAAU;AACb,oBAAc,iBAAiB,KAAK;AACpC;AAAA,IACF;AAAA,IACA,SAAS;AACP,aAAOC,aAAY,MAAM,IAAI,SAAY,YAAY,OAAO,QAAQ,qBAAqB,OAAO,KAAK,GAAG;AAAA,IAC1G;AAAA,EACF;AACA,SAAO,OAAO,WAAW,IAAI,cAAc,YAAY,OAAO,QAAQ,wBAAwB,KAAK,GAAG;AACxG;;;AErBA,YAAYC,QAAO;AAKZ,IAAM,cAAc;AAEpB,IAAM,YAAY,eAAe,aAAa,WAAW;AAEzD,IAAM,YAAY;AAGlB,IAAM,gBAAiC,CAAC,IAAI,IAAI,KAAK,KAAK,KAAK,MAAM,MAAM,IAAI;AAE/E,IAAM,kBAAkB,CAAC,UAA2C;AACzE,SAAO,OAAO,UAAU,YAAY,cAAc,SAAS,KAAsB;AACnF;AAEO,IAAM,UAAY,UAAO,EAC7B,MAAM,WAAW,EAAE,SAAS,qBAAqB,CAAC;;;ACpBrD,YAAYC,QAAO;AAMZ,IAAM,gBAAgB,QAAQ,UAAkB,OAAK,CAAC;AACtD,IAAM,gBAAkB,UAAO,EAAE,UAAgB,OAAK,OAAO,GAAG,IAAI,CAAC;;;ACNrE,SAAS,YAAY,KAAkB;AAC5C,SAAO,OAAO,iBAAiB,KAAK,EAAE,QAAQ,KAAK,CAAC,CAAC;AACvD;","names":["z","z","isString","isString","z","z","z","isUndefined","isUndefined","z","z"]}
@@ -242,7 +242,8 @@ var toEthAddress = (value, config = {}) => {
242
242
  };
243
243
  var isEthAddress = (value, config = {}) => {
244
244
  const { bitLength = 160, prefix = true } = config;
245
- return isHex(value, { bitLength, prefix });
245
+ const loweredValue = typeof value === "string" ? value.toLowerCase() : value;
246
+ return isHex(loweredValue, { bitLength, prefix });
246
247
  };
247
248
  var EthAddressZod = z6.string().regex(EthAddressRegEx, { message: "Invalid address format" }).refine(
248
249
  isEthAddress
@@ -252,7 +253,7 @@ function asEthAddress(value, assert) {
252
253
  let stringValue = void 0;
253
254
  switch (typeof value) {
254
255
  case "string": {
255
- stringValue = hexFromHexString(value, { prefix: true });
256
+ stringValue = hexFromHexString(value, { prefix: true, byteSize: 4 });
256
257
  break;
257
258
  }
258
259
  default: {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/address/address.ts","../../src/HexRegEx.ts","../../src/address/addressDeprecated.ts","../../src/assert.ts","../../src/hex/from/fromHexString.ts","../../src/hex/nibble.ts","../../src/hex/is.ts","../../src/hex/from/fromArrayBuffer.ts","../../src/hex/from/fromBigInt.ts","../../src/hex/from/fromNumber.ts","../../src/hex/from/from.ts","../../src/hex/as.ts","../../src/hex/hex.ts","../../src/hex/isHexZero.ts","../../src/hex/legacy.ts","../../src/hex/to.ts","../../src/address/AddressTransformZod.ts","../../src/address/AddressValidationZod.ts","../../src/address/to.ts","../../src/address/as.ts","../../src/address/is.ts","../../src/ethAddress.ts","../../src/hash/as.ts","../../src/hash/is.ts","../../src/hash/hash.ts","../../src/hash/zod.ts","../../src/hexToBigInt.ts","../../src/zod.ts"],"sourcesContent":["import type { Brand } from '@xylabs/typeof'\n// eslint-disable-next-line no-restricted-syntax\nimport * as z from 'zod'\n\nimport type { Hex } from '../hex/index.ts'\nimport { HexRegExMinMax } from '../HexRegEx.ts'\n\nexport const ZERO_ADDRESS = '0000000000000000000000000000000000000000' as Address\nexport const ADDRESS_LENGTH = 40 as const\n\nexport const AddressRegEx = HexRegExMinMax(ADDRESS_LENGTH / 2, ADDRESS_LENGTH / 2)\n\nexport const AddressZod = z.string()\n .regex(AddressRegEx, { message: 'Invalid hex format' }) as unknown as z.ZodType<Brand<Hex, { readonly __address: true }>>\n\nexport type Address = z.infer<typeof AddressZod>\n","export const HexRegExMinMax = (minBytes = 0, maxBytes: number = (Number.MAX_SAFE_INTEGER / 2)) => {\n return new RegExp(`^[a-f0-9]{${minBytes * 2},${maxBytes * 2}}$`)\n}\n\nexport const HexRegExMinMaxMixedCaseWithPrefix = (minBytes = 0, maxBytes: number = (Number.MAX_SAFE_INTEGER / 2)) => {\n return new RegExp(`^0x[a-fA-F0-9]{${minBytes * 2},${maxBytes * 2}}$`)\n}\n\nexport const HexRegEx = /^[0-9a-f]+$/\nexport const HexRegExWithPrefix = /^0x[0-9a-f]+$/\n","// eslint-disable-next-line no-restricted-syntax\nimport * as z from 'zod'\n\nimport { AddressRegEx } from './address.ts'\nimport { toAddress } from './to.ts'\n\n/** @deprecated use AddressZod */\nexport const AddressToStringZod = z.string().regex(AddressRegEx)\n\n/** @deprecated use AddressZod */\n// eslint-disable-next-line sonarjs/deprecation\nexport const AddressToStringSchema = AddressToStringZod\n\n/** @deprecated use AddressZod */\nexport const AddressFromStringZod = z.string().toLowerCase().regex(AddressRegEx).transform(v => toAddress(v))\n\n/** @deprecated use AddressZod */\n// eslint-disable-next-line sonarjs/deprecation\nexport const AddressFromStringSchema = AddressFromStringZod\n","import { isString, isUndefined } from '@xylabs/typeof'\n\ntype AssertCallback = (value: unknown, message: string) => string | boolean\n\nexport type AssertConfig = string | AssertCallback | boolean\n\nexport const assertError = (value: unknown, assert: AssertConfig | undefined, defaultMessage: string) => {\n if (!isUndefined(assert)) {\n const assertString\n = typeof assert === 'string'\n ? assert\n : typeof assert === 'boolean'\n ? defaultMessage\n : assert(value, defaultMessage)\n if (isString(assertString) || assertString === true) {\n throw new Error(assertString === true ? defaultMessage : assertString)\n }\n }\n // eslint-disable-next-line unicorn/no-useless-undefined\n return undefined\n}\n","import { isNumber } from '@xylabs/typeof'\n\nimport type { Hex, HexConfig } from '../hex.ts'\nimport { isHex } from '../is.ts'\nimport { bitsToNibbles } from '../nibble.ts'\n\nexport const hexFromHexString = (value: string, config: HexConfig = {}): Hex => {\n const {\n prefix = false, byteSize = 8, bitLength,\n } = config\n const nibbleBoundary = bitsToNibbles(byteSize)\n const unEvened = (value.startsWith('0x') ? value.slice(2) : value).toLowerCase()\n if (isHex(unEvened)) {\n const evenCharacters = unEvened.padStart(unEvened.length + (unEvened.length % nibbleBoundary), '0')\n const padded = isNumber(bitLength) ? evenCharacters.padStart(bitLength / 4, '0') : evenCharacters\n return (prefix ? `0x${padded}` : padded).toLowerCase() as Hex\n } else {\n throw new Error('Received string is not a value hex')\n }\n}\n","// determine the number of nibbles for a given number of bits\nexport const bitsToNibbles = (value: number): number => {\n const nibbles = value >> 2\n if (value !== nibbles << 2) throw new Error('Bits for nibbles must multiple of 4')\n return nibbles\n}\n\n// determine the number of nibbles for a given number of bits\nexport const nibblesToBits = (value: number): number => {\n return value << 2\n}\n","import { HexRegEx, HexRegExWithPrefix } from '../HexRegEx.ts'\nimport type { Hex, HexConfig } from './hex.ts'\nimport { bitsToNibbles } from './nibble.ts'\n\nexport const isHex = (value: unknown, config?: HexConfig): value is Hex => {\n // Is it a string?\n if (typeof value !== 'string') return false\n\n const valueCharLength = config?.prefix ? value.length - 2 : value.length\n\n // If a bitLength specified, does it conform?\n if (config?.bitLength !== undefined && valueCharLength !== bitsToNibbles(config?.bitLength)) return false\n\n // Does it only has hex values?\n return config?.prefix ? HexRegExWithPrefix.test(value) : HexRegEx.test(value)\n}\n","import type { Hex, HexConfig } from '../hex.ts'\nimport { hexFromHexString } from './fromHexString.ts'\n\n/** Convert an ArrayBuffer to a hex string */\nexport const hexFromArrayBuffer = (\n /** The buffer to be converted */\n buffer: ArrayBufferLike,\n /** Configuration of output format and validation */\n config?: HexConfig,\n): Hex => {\n const unPadded = [...new Uint8Array(buffer)].map(x => x.toString(16).padStart(2, '0')).join('')\n return hexFromHexString(unPadded, config)\n}\n","import type { Hex, HexConfig } from '../hex.ts'\nimport { hexFromHexString } from './fromHexString.ts'\n\n/** Convert a bigint to a hex string */\nexport const hexFromBigInt = (\n /** The bigint to be converted */\n value: bigint,\n /** Configuration of output format and validation */\n config: HexConfig = {},\n): Hex => {\n const unPadded = value.toString(16)\n return hexFromHexString(unPadded, config)\n}\n","import type { Hex, HexConfig } from '../hex.ts'\nimport { hexFromBigInt } from './fromBigInt.ts'\n\nexport const hexFromNumber = (value: number, config?: HexConfig): Hex => {\n return hexFromBigInt(BigInt(value), config)\n}\n","import type { Hex, HexConfig } from '../hex.ts'\nimport { hexFromArrayBuffer } from './fromArrayBuffer.ts'\nimport { hexFromBigInt } from './fromBigInt.ts'\nimport { hexFromHexString } from './fromHexString.ts'\nimport { hexFromNumber } from './fromNumber.ts'\n\n/** Takes unknown value and tries our best to convert it to a hex string */\nexport const hexFrom = (\n /** Supported types are string, number, bigint, and ArrayBuffer */\n value: string | number | bigint | ArrayBufferLike,\n /** Configuration of output format and validation */\n config?: HexConfig,\n): Hex => {\n switch (typeof value) {\n case 'string': {\n return hexFromHexString(value, config)\n }\n case 'bigint': {\n return hexFromBigInt(value, config)\n }\n case 'number': {\n return hexFromNumber(value, config)\n }\n case 'object': {\n return hexFromArrayBuffer(value, config)\n }\n default: {\n throw new Error(`Invalid type: ${typeof value}`)\n }\n }\n}\n","import type { AssertConfig } from '../assert.ts'\nimport { assertError } from '../assert.ts'\nimport { hexFromHexString } from './from/index.ts'\nimport type { Hex } from './hex.ts'\nimport { isHex } from './is.ts'\n\nexport function asHex(value: unknown): Hex | undefined\nexport function asHex(value: unknown, assert: AssertConfig): Hex\nexport function asHex(value: unknown, assert?: AssertConfig): Hex | undefined {\n let stringValue: string | undefined = undefined\n\n switch (typeof value) {\n case 'string': {\n stringValue = hexFromHexString(value)\n break\n }\n default: {\n return assertError(value, assert, `Unsupported type [${typeof value}]`)\n }\n }\n\n return isHex(stringValue) ? stringValue : assertError(value, assert, `Value is not Hex [${value}]`)\n}\n","import type { Brand } from '@xylabs/typeof'\n// eslint-disable-next-line no-restricted-syntax\nimport * as z from 'zod'\n\nimport { HexRegEx } from '../HexRegEx.ts'\n\nexport const HexZod = z.string()\n .regex(HexRegEx, { message: 'Invalid hex format' }) as unknown as z.ZodType<Brand<Lowercase<string>, { readonly __hex: true }>>\n\nexport type Hex = z.infer<typeof HexZod>\n\n/** Configuration of validation and output format */\nexport interface HexConfig {\n bitLength?: number\n byteSize?: number\n prefix?: boolean\n}\n","import { isString } from '@xylabs/typeof'\n\nimport { hexFromHexString } from './from/index.ts'\n\nexport const isHexZero = (value?: string) => {\n return isString(value) ? BigInt(hexFromHexString(value, { prefix: true })) === 0n : undefined\n}\n","export const toHexLegacy = (buffer: ArrayBuffer) => {\n return [...new Uint8Array(buffer)].map(x => x.toString(16).padStart(2, '0')).join('')\n}\n","import { hexFrom } from './from/index.ts'\nimport type { HexConfig } from './hex.ts'\n\n/** takes any value and tries our best to convert it to a hex string */\nexport const toHex = (\n /** Supported types are string, number, bigint, and ArrayBuffer */\n value: string | number | bigint | ArrayBufferLike,\n /** Configuration of output format and validation */\n config: HexConfig = {},\n) => {\n const { prefix = false } = config\n return hexFrom(value, { prefix, ...config })\n}\n","// eslint-disable-next-line no-restricted-syntax\nimport * as z from 'zod'\n\nimport { type Address, ADDRESS_LENGTH } from './address.ts'\nimport { AddressValidationZod } from './AddressValidationZod.ts'\n\nexport const AddressTransformZod = z.union([z.string(), z.bigint(), z.number()])\n .transform((value) => {\n switch (typeof value) {\n case 'bigint': {\n return value.toString(16).padStart(ADDRESS_LENGTH, '0')\n }\n case 'string': {\n if (value.startsWith('0x')) {\n return value.slice(2)\n }\n return value\n }\n case 'number': {\n return BigInt(value).toString(16).padStart(ADDRESS_LENGTH, '0')\n }\n }\n })\n .refine(x => AddressValidationZod.safeParse(x).data)\n .transform(x => x as Address)\n\nexport type AddressTransformZodType = z.infer<typeof AddressTransformZod>\n","// eslint-disable-next-line no-restricted-syntax\nimport * as z from 'zod'\n\nimport { HexZod } from '../hex/index.ts'\nimport type { Address } from './address.ts'\nimport { ADDRESS_LENGTH } from './address.ts'\n\nexport const AddressValidationZod = z.string()\n .refine(x => HexZod.safeParse(x))\n .refine(x => x.length === ADDRESS_LENGTH, { error: e => new Error(`Address must have 40 characters [${e.input}]`) })\n .transform(v => v as Address)\n\nexport type AddressValidationZodType = z.infer<typeof AddressValidationZod>\n","import type { HexConfig } from '../hex/index.ts'\nimport { hexFrom } from '../hex/index.ts'\nimport type { Address } from './address.ts'\nimport { AddressTransformZod } from './AddressTransformZod.ts'\n\nexport const toAddress = (value: string | number | bigint | ArrayBufferLike, config: HexConfig = {}): Address => {\n const { bitLength = 160, prefix = false } = config\n return hexFrom(value, {\n bitLength, prefix, ...config,\n }) as unknown as Address\n}\n\n/** @alpha */\nexport function toAddressV2(value: unknown, assert: boolean = false): Address | undefined {\n return assert\n ? AddressTransformZod.parse(value)\n : AddressTransformZod.safeParse(value).data\n}\n","import { isObject } from '@xylabs/typeof'\n\nimport type { AssertConfig } from '../assert.ts'\nimport { assertError } from '../assert.ts'\nimport { hexFromHexString } from '../hex/index.ts'\nimport type { Address } from './address.ts'\nimport { AddressValidationZod } from './AddressValidationZod.ts'\nimport { isAddress } from './is.ts'\n\nexport function asAddress(value: unknown): Address | undefined\nexport function asAddress(value: unknown, assert: AssertConfig): Address\nexport function asAddress(value: unknown, assert?: AssertConfig): Address | undefined {\n try {\n let stringValue: string | undefined = undefined\n\n switch (typeof value) {\n case 'string': {\n stringValue = hexFromHexString(value, { prefix: false })\n break\n }\n default: {\n return isObject(assert) ? assertError(value, assert, `Unsupported type [${typeof value}]`) : undefined\n }\n }\n return isAddress(stringValue) ? stringValue : assertError(value, assert, `Value is not an Address [${value}]`)\n } catch (ex) {\n const error = ex as Error\n return assertError(undefined, assert, error.message)\n }\n}\n\n/** @alpha */\nexport function asAddressV2(value: unknown, assert: boolean = false): Address | undefined {\n return assert\n ? AddressValidationZod.parse(value)\n : AddressValidationZod.safeParse(value).data\n}\n","import type { HexConfig } from '../hex/index.ts'\nimport { isHex } from '../hex/index.ts'\nimport type { Address } from './address.ts'\nimport { AddressValidationZod } from './AddressValidationZod.ts'\n\nexport const isAddress = (value: unknown, config: HexConfig = {}): value is Address => {\n const { bitLength = 160, prefix = false } = config\n return isHex(value, { bitLength, prefix })\n}\n\n/** @alpha */\nexport function isAddressV2(value: unknown): value is Address {\n return AddressValidationZod.safeParse(value).success\n}\n","import type { Brand } from '@xylabs/typeof'\n// eslint-disable-next-line no-restricted-syntax\nimport * as z from 'zod'\n\nimport type { AssertConfig } from './assert.ts'\nimport { assertError } from './assert.ts'\nimport type { HexConfig } from './hex/index.ts'\nimport {\n hexFrom, hexFromHexString, isHex,\n} from './hex/index.ts'\nimport { HexRegExMinMaxMixedCaseWithPrefix } from './HexRegEx.ts'\n\nexport const EthAddressRegEx = HexRegExMinMaxMixedCaseWithPrefix(20, 20)\n\nexport const EthAddressToStringZod = z.string().regex(EthAddressRegEx)\n\n/** @deprecated use EthAddressToStringZod */\nexport const EthAddressToStringSchema = EthAddressToStringZod\n\nexport const EthAddressFromStringZod = z.string().regex(EthAddressRegEx).transform(v => toEthAddress(v))\n\n/** @deprecated use EthAddressFromStringZod */\nexport const EthAddressFromStringSchema = EthAddressFromStringZod\n\n// using true instead of unique symbol to avoid conflicts with other versions of library\nexport type EthAddress = Brand<string, { readonly __eth_address: true }>\n\nexport const ETH_ZERO_ADDRESS = '0x0000000000000000000000000000000000000000' as EthAddress\n\nexport const toEthAddress = (value: string | number | bigint | ArrayBufferLike, config: HexConfig = {}): EthAddress => {\n const { bitLength = 160, prefix = false } = config\n return `0x${hexFrom(value, {\n bitLength, prefix, ...config,\n })}` as EthAddress\n}\n\nexport const isEthAddress = (value: unknown, config: HexConfig = {}): value is EthAddress => {\n const { bitLength = 160, prefix = true } = config\n return isHex(value, { bitLength, prefix })\n}\n\nexport const EthAddressZod = z.string()\n .regex(EthAddressRegEx, { message: 'Invalid address format' })\n .refine(\n isEthAddress,\n )\n\nexport function asEthAddress(value: unknown): EthAddress | undefined\nexport function asEthAddress(value: unknown, assert: AssertConfig): EthAddress\nexport function asEthAddress(value: unknown, assert?: AssertConfig): EthAddress | undefined {\n try {\n let stringValue: string | undefined = undefined\n\n switch (typeof value) {\n case 'string': {\n stringValue = hexFromHexString(value, { prefix: true })\n break\n }\n default: {\n if (value !== undefined) {\n return assertError(value, assert, `Unsupported type [${typeof value}]`)\n }\n }\n }\n return isEthAddress(stringValue) ? stringValue : assertError(value, assert, `Value is not an EthAddress [${value}]`)\n } catch (ex) {\n const error = ex as Error\n return assertError(undefined, assert, error.message)\n }\n}\n","import { isUndefined } from '@xylabs/typeof'\n\nimport type { AssertConfig } from '../assert.ts'\nimport { assertError } from '../assert.ts'\nimport { hexFromHexString } from '../hex/index.ts'\nimport { type Hash } from './hash.ts'\nimport { isHash } from './is.ts'\n\nexport function asHash(value: unknown): Hash | undefined\nexport function asHash(value: unknown, assert: AssertConfig): Hash\nexport function asHash(value: unknown, assert?: AssertConfig): Hash | undefined {\n let stringValue: string | undefined = undefined\n\n switch (typeof value) {\n case 'string': {\n stringValue = hexFromHexString(value)\n break\n }\n default: {\n return isUndefined(assert) ? undefined : assertError(value, assert, `Unsupported type [${typeof value}]`)\n }\n }\n return isHash(stringValue) ? stringValue : assertError(value, assert, `Value is not a Hash [${value}]`)\n}\n","import { isHex } from '../hex/index.ts'\nimport type { Hash, HashBitLength } from './hash.ts'\n\nexport const isHash = (value: unknown, bitLength: HashBitLength = 256): value is Hash => {\n return isHex(value, { bitLength })\n}\n","import type { Brand } from '@xylabs/typeof'\n// eslint-disable-next-line no-restricted-syntax\nimport * as z from 'zod'\n\nimport type { Hex } from '../hex/index.ts'\nimport { HexRegExMinMax } from '../HexRegEx.ts'\n\nexport const HASH_LENGTH = 32 as const\n\nexport const HashRegEx = HexRegExMinMax(HASH_LENGTH, HASH_LENGTH)\n\nexport const ZERO_HASH = '0000000000000000000000000000000000000000000000000000000000000000' as Hash\n\nexport type HashBitLength = 32 | 64 | 128 | 256 | 512 | 1024 | 2048 | 4096\nexport const HashBitLength: HashBitLength[] = [32, 64, 128, 256, 512, 1024, 2048, 4096]\n\nexport const isHashBitLength = (value: unknown): value is HashBitLength => {\n return typeof value === 'number' && HashBitLength.includes(value as HashBitLength)\n}\n\nexport const HashZod = z.string()\n .regex(HashRegEx, { message: 'Invalid hex format' }) as unknown as z.ZodType<Brand<Hex, { readonly __hash: true }>>\n\nexport type Hash = z.infer<typeof HashZod>\n","// eslint-disable-next-line no-restricted-syntax\nimport * as z from 'zod'\n\nimport { asHash } from './as.ts'\nimport type { Hash } from './hash.ts'\nimport { HashZod } from './hash.ts'\n\nexport const HashToJsonZod = HashZod.transform<string>(v => v)\nexport const JsonToHashZod = z.string().transform<Hash>(v => asHash(v, true))\n","import { type Hex, hexFromHexString } from './hex/index.ts'\n\nexport function hexToBigInt(hex: Hex): bigint {\n return BigInt(hexFromHexString(hex, { prefix: true }))\n}\n","// eslint-disable-next-line no-restricted-syntax\nimport * as z from 'zod'\n\nimport { toHex } from './hex/index.ts'\nimport { hexToBigInt } from './hexToBigInt.ts'\n\nexport const BigIntToJsonZod = z.bigint().nonnegative().transform(x => toHex(x))\nexport const JsonToBigIntZod = z.string().transform(x => toHex(x)).transform(x => hexToBigInt(x))\n"],"mappings":";AAEA,YAAY,OAAO;;;ACFZ,IAAM,iBAAiB,CAAC,WAAW,GAAG,WAAoB,OAAO,mBAAmB,MAAO;AAChG,SAAO,IAAI,OAAO,aAAa,WAAW,CAAC,IAAI,WAAW,CAAC,IAAI;AACjE;AAEO,IAAM,oCAAoC,CAAC,WAAW,GAAG,WAAoB,OAAO,mBAAmB,MAAO;AACnH,SAAO,IAAI,OAAO,kBAAkB,WAAW,CAAC,IAAI,WAAW,CAAC,IAAI;AACtE;AAEO,IAAM,WAAW;AACjB,IAAM,qBAAqB;;;ADF3B,IAAM,eAAe;AACrB,IAAM,iBAAiB;AAEvB,IAAM,eAAe,eAAe,iBAAiB,GAAG,iBAAiB,CAAC;AAE1E,IAAM,aAAe,SAAO,EAChC,MAAM,cAAc,EAAE,SAAS,qBAAqB,CAAC;;;AEZxD,YAAYA,QAAO;;;ACDnB,SAAS,UAAU,mBAAmB;AAM/B,IA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AK,OAAO,GAAG,IAAI,CAAC;;;ACNrE,SAAS,YAAY,KAAkB;AAC5C,SAAO,OAAO,iBAAiB,KAAK,EAAE,QAAQ,KAAK,CAAC,CAAC;AACvD;;;ACHA,YAAYC,QAAO;AAKZ,IAAM,kBAAoB,UAAO,EAAE,YAAY,EAAE,UAAU,OAAK,MAAM,CAAC,CAAC;AACxE,IAAM,kBAAoB,UAAO,EAAE,UAAU,OAAK,MAAM,CAAC,CAAC,EAAE,UAAU,OAAK,YAAY,CAAC,CAAC;","names":["z","z","isString","isString","z","z","z","isUndefined","isUndefined","z","z","z"]}
1
+ {"version":3,"sources":["../../src/address/address.ts","../../src/HexRegEx.ts","../../src/address/addressDeprecated.ts","../../src/assert.ts","../../src/hex/from/fromHexString.ts","../../src/hex/nibble.ts","../../src/hex/is.ts","../../src/hex/from/fromArrayBuffer.ts","../../src/hex/from/fromBigInt.ts","../../src/hex/from/fromNumber.ts","../../src/hex/from/from.ts","../../src/hex/as.ts","../../src/hex/hex.ts","../../src/hex/isHexZero.ts","../../src/hex/legacy.ts","../../src/hex/to.ts","../../src/address/AddressTransformZod.ts","../../src/address/AddressValidationZod.ts","../../src/address/to.ts","../../src/address/as.ts","../../src/address/is.ts","../../src/ethAddress.ts","../../src/hash/as.ts","../../src/hash/is.ts","../../src/hash/hash.ts","../../src/hash/zod.ts","../../src/hexToBigInt.ts","../../src/zod.ts"],"sourcesContent":["import type { Brand } from '@xylabs/typeof'\n// eslint-disable-next-line no-restricted-syntax\nimport * as z from 'zod'\n\nimport type { Hex } from '../hex/index.ts'\nimport { HexRegExMinMax } from '../HexRegEx.ts'\n\nexport const ZERO_ADDRESS = '0000000000000000000000000000000000000000' as Address\nexport const ADDRESS_LENGTH = 40 as const\n\nexport const AddressRegEx = HexRegExMinMax(ADDRESS_LENGTH / 2, ADDRESS_LENGTH / 2)\n\nexport const AddressZod = z.string()\n .regex(AddressRegEx, { message: 'Invalid hex format' }) as unknown as z.ZodType<Brand<Hex, { readonly __address: true }>>\n\nexport type Address = z.infer<typeof AddressZod>\n","export const HexRegExMinMax = (minBytes = 0, maxBytes: number = (Number.MAX_SAFE_INTEGER / 2)) => {\n return new RegExp(`^[a-f0-9]{${minBytes * 2},${maxBytes * 2}}$`)\n}\n\nexport const HexRegExMinMaxMixedCaseWithPrefix = (minBytes = 0, maxBytes: number = (Number.MAX_SAFE_INTEGER / 2)) => {\n return new RegExp(`^0x[a-fA-F0-9]{${minBytes * 2},${maxBytes * 2}}$`)\n}\n\nexport const HexRegEx = /^[0-9a-f]+$/\nexport const HexRegExWithPrefix = /^0x[0-9a-f]+$/\n","// eslint-disable-next-line no-restricted-syntax\nimport * as z from 'zod'\n\nimport { AddressRegEx } from './address.ts'\nimport { toAddress } from './to.ts'\n\n/** @deprecated use AddressZod */\nexport const AddressToStringZod = z.string().regex(AddressRegEx)\n\n/** @deprecated use AddressZod */\n// eslint-disable-next-line sonarjs/deprecation\nexport const AddressToStringSchema = AddressToStringZod\n\n/** @deprecated use AddressZod */\nexport const AddressFromStringZod = z.string().toLowerCase().regex(AddressRegEx).transform(v => toAddress(v))\n\n/** @deprecated use AddressZod */\n// eslint-disable-next-line sonarjs/deprecation\nexport const AddressFromStringSchema = AddressFromStringZod\n","import { isString, isUndefined } from '@xylabs/typeof'\n\ntype AssertCallback = (value: unknown, message: string) => string | boolean\n\nexport type AssertConfig = string | AssertCallback | boolean\n\nexport const assertError = (value: unknown, assert: AssertConfig | undefined, defaultMessage: string) => {\n if (!isUndefined(assert)) {\n const assertString\n = typeof assert === 'string'\n ? assert\n : typeof assert === 'boolean'\n ? defaultMessage\n : assert(value, defaultMessage)\n if (isString(assertString) || assertString === true) {\n throw new Error(assertString === true ? defaultMessage : assertString)\n }\n }\n // eslint-disable-next-line unicorn/no-useless-undefined\n return undefined\n}\n","import { isNumber } from '@xylabs/typeof'\n\nimport type { Hex, HexConfig } from '../hex.ts'\nimport { isHex } from '../is.ts'\nimport { bitsToNibbles } from '../nibble.ts'\n\nexport const hexFromHexString = (value: string, config: HexConfig = {}): Hex => {\n const {\n prefix = false, byteSize = 8, bitLength,\n } = config\n const nibbleBoundary = bitsToNibbles(byteSize)\n const unEvened = (value.startsWith('0x') ? value.slice(2) : value).toLowerCase()\n if (isHex(unEvened)) {\n const evenCharacters = unEvened.padStart(unEvened.length + (unEvened.length % nibbleBoundary), '0')\n const padded = isNumber(bitLength) ? evenCharacters.padStart(bitLength / 4, '0') : evenCharacters\n return (prefix ? `0x${padded}` : padded).toLowerCase() as Hex\n } else {\n throw new Error('Received string is not a value hex')\n }\n}\n","// determine the number of nibbles for a given number of bits\nexport const bitsToNibbles = (value: number): number => {\n const nibbles = value >> 2\n if (value !== nibbles << 2) throw new Error('Bits for nibbles must multiple of 4')\n return nibbles\n}\n\n// determine the number of nibbles for a given number of bits\nexport const nibblesToBits = (value: number): number => {\n return value << 2\n}\n","import { HexRegEx, HexRegExWithPrefix } from '../HexRegEx.ts'\nimport type { Hex, HexConfig } from './hex.ts'\nimport { bitsToNibbles } from './nibble.ts'\n\nexport const isHex = (value: unknown, config?: HexConfig): value is Hex => {\n // Is it a string?\n if (typeof value !== 'string') return false\n\n const valueCharLength = config?.prefix ? value.length - 2 : value.length\n\n // If a bitLength specified, does it conform?\n if (config?.bitLength !== undefined && valueCharLength !== bitsToNibbles(config?.bitLength)) return false\n\n // Does it only has hex values?\n return config?.prefix ? HexRegExWithPrefix.test(value) : HexRegEx.test(value)\n}\n","import type { Hex, HexConfig } from '../hex.ts'\nimport { hexFromHexString } from './fromHexString.ts'\n\n/** Convert an ArrayBuffer to a hex string */\nexport const hexFromArrayBuffer = (\n /** The buffer to be converted */\n buffer: ArrayBufferLike,\n /** Configuration of output format and validation */\n config?: HexConfig,\n): Hex => {\n const unPadded = [...new Uint8Array(buffer)].map(x => x.toString(16).padStart(2, '0')).join('')\n return hexFromHexString(unPadded, config)\n}\n","import type { Hex, HexConfig } from '../hex.ts'\nimport { hexFromHexString } from './fromHexString.ts'\n\n/** Convert a bigint to a hex string */\nexport const hexFromBigInt = (\n /** The bigint to be converted */\n value: bigint,\n /** Configuration of output format and validation */\n config: HexConfig = {},\n): Hex => {\n const unPadded = value.toString(16)\n return hexFromHexString(unPadded, config)\n}\n","import type { Hex, HexConfig } from '../hex.ts'\nimport { hexFromBigInt } from './fromBigInt.ts'\n\nexport const hexFromNumber = (value: number, config?: HexConfig): Hex => {\n return hexFromBigInt(BigInt(value), config)\n}\n","import type { Hex, HexConfig } from '../hex.ts'\nimport { hexFromArrayBuffer } from './fromArrayBuffer.ts'\nimport { hexFromBigInt } from './fromBigInt.ts'\nimport { hexFromHexString } from './fromHexString.ts'\nimport { hexFromNumber } from './fromNumber.ts'\n\n/** Takes unknown value and tries our best to convert it to a hex string */\nexport const hexFrom = (\n /** Supported types are string, number, bigint, and ArrayBuffer */\n value: string | number | bigint | ArrayBufferLike,\n /** Configuration of output format and validation */\n config?: HexConfig,\n): Hex => {\n switch (typeof value) {\n case 'string': {\n return hexFromHexString(value, config)\n }\n case 'bigint': {\n return hexFromBigInt(value, config)\n }\n case 'number': {\n return hexFromNumber(value, config)\n }\n case 'object': {\n return hexFromArrayBuffer(value, config)\n }\n default: {\n throw new Error(`Invalid type: ${typeof value}`)\n }\n }\n}\n","import type { AssertConfig } from '../assert.ts'\nimport { assertError } from '../assert.ts'\nimport { hexFromHexString } from './from/index.ts'\nimport type { Hex } from './hex.ts'\nimport { isHex } from './is.ts'\n\nexport function asHex(value: unknown): Hex | undefined\nexport function asHex(value: unknown, assert: AssertConfig): Hex\nexport function asHex(value: unknown, assert?: AssertConfig): Hex | undefined {\n let stringValue: string | undefined = undefined\n\n switch (typeof value) {\n case 'string': {\n stringValue = hexFromHexString(value)\n break\n }\n default: {\n return assertError(value, assert, `Unsupported type [${typeof value}]`)\n }\n }\n\n return isHex(stringValue) ? stringValue : assertError(value, assert, `Value is not Hex [${value}]`)\n}\n","import type { Brand } from '@xylabs/typeof'\n// eslint-disable-next-line no-restricted-syntax\nimport * as z from 'zod'\n\nimport { HexRegEx } from '../HexRegEx.ts'\n\nexport const HexZod = z.string()\n .regex(HexRegEx, { message: 'Invalid hex format' }) as unknown as z.ZodType<Brand<Lowercase<string>, { readonly __hex: true }>>\n\nexport type Hex = z.infer<typeof HexZod>\n\n/** Configuration of validation and output format */\nexport interface HexConfig {\n bitLength?: number\n byteSize?: number\n prefix?: boolean\n}\n","import { isString } from '@xylabs/typeof'\n\nimport { hexFromHexString } from './from/index.ts'\n\nexport const isHexZero = (value?: string) => {\n return isString(value) ? BigInt(hexFromHexString(value, { prefix: true })) === 0n : undefined\n}\n","export const toHexLegacy = (buffer: ArrayBuffer) => {\n return [...new Uint8Array(buffer)].map(x => x.toString(16).padStart(2, '0')).join('')\n}\n","import { hexFrom } from './from/index.ts'\nimport type { HexConfig } from './hex.ts'\n\n/** takes any value and tries our best to convert it to a hex string */\nexport const toHex = (\n /** Supported types are string, number, bigint, and ArrayBuffer */\n value: string | number | bigint | ArrayBufferLike,\n /** Configuration of output format and validation */\n config: HexConfig = {},\n) => {\n const { prefix = false } = config\n return hexFrom(value, { prefix, ...config })\n}\n","// eslint-disable-next-line no-restricted-syntax\nimport * as z from 'zod'\n\nimport { type Address, ADDRESS_LENGTH } from './address.ts'\nimport { AddressValidationZod } from './AddressValidationZod.ts'\n\nexport const AddressTransformZod = z.union([z.string(), z.bigint(), z.number()])\n .transform((value) => {\n switch (typeof value) {\n case 'bigint': {\n return value.toString(16).padStart(ADDRESS_LENGTH, '0')\n }\n case 'string': {\n if (value.startsWith('0x')) {\n return value.slice(2)\n }\n return value\n }\n case 'number': {\n return BigInt(value).toString(16).padStart(ADDRESS_LENGTH, '0')\n }\n }\n })\n .refine(x => AddressValidationZod.safeParse(x).data)\n .transform(x => x as Address)\n\nexport type AddressTransformZodType = z.infer<typeof AddressTransformZod>\n","// eslint-disable-next-line no-restricted-syntax\nimport * as z from 'zod'\n\nimport { HexZod } from '../hex/index.ts'\nimport type { Address } from './address.ts'\nimport { ADDRESS_LENGTH } from './address.ts'\n\nexport const AddressValidationZod = z.string()\n .refine(x => HexZod.safeParse(x))\n .refine(x => x.length === ADDRESS_LENGTH, { error: e => new Error(`Address must have 40 characters [${e.input}]`) })\n .transform(v => v as Address)\n\nexport type AddressValidationZodType = z.infer<typeof AddressValidationZod>\n","import type { HexConfig } from '../hex/index.ts'\nimport { hexFrom } from '../hex/index.ts'\nimport type { Address } from './address.ts'\nimport { AddressTransformZod } from './AddressTransformZod.ts'\n\nexport const toAddress = (value: string | number | bigint | ArrayBufferLike, config: HexConfig = {}): Address => {\n const { bitLength = 160, prefix = false } = config\n return hexFrom(value, {\n bitLength, prefix, ...config,\n }) as unknown as Address\n}\n\n/** @alpha */\nexport function toAddressV2(value: unknown, assert: boolean = false): Address | undefined {\n return assert\n ? AddressTransformZod.parse(value)\n : AddressTransformZod.safeParse(value).data\n}\n","import { isObject } from '@xylabs/typeof'\n\nimport type { AssertConfig } from '../assert.ts'\nimport { assertError } from '../assert.ts'\nimport { hexFromHexString } from '../hex/index.ts'\nimport type { Address } from './address.ts'\nimport { AddressValidationZod } from './AddressValidationZod.ts'\nimport { isAddress } from './is.ts'\n\nexport function asAddress(value: unknown): Address | undefined\nexport function asAddress(value: unknown, assert: AssertConfig): Address\nexport function asAddress(value: unknown, assert?: AssertConfig): Address | undefined {\n try {\n let stringValue: string | undefined = undefined\n\n switch (typeof value) {\n case 'string': {\n stringValue = hexFromHexString(value, { prefix: false })\n break\n }\n default: {\n return isObject(assert) ? assertError(value, assert, `Unsupported type [${typeof value}]`) : undefined\n }\n }\n return isAddress(stringValue) ? stringValue : assertError(value, assert, `Value is not an Address [${value}]`)\n } catch (ex) {\n const error = ex as Error\n return assertError(undefined, assert, error.message)\n }\n}\n\n/** @alpha */\nexport function asAddressV2(value: unknown, assert: boolean = false): Address | undefined {\n return assert\n ? AddressValidationZod.parse(value)\n : AddressValidationZod.safeParse(value).data\n}\n","import type { HexConfig } from '../hex/index.ts'\nimport { isHex } from '../hex/index.ts'\nimport type { Address } from './address.ts'\nimport { AddressValidationZod } from './AddressValidationZod.ts'\n\nexport const isAddress = (value: unknown, config: HexConfig = {}): value is Address => {\n const { bitLength = 160, prefix = false } = config\n return isHex(value, { bitLength, prefix })\n}\n\n/** @alpha */\nexport function isAddressV2(value: unknown): value is Address {\n return AddressValidationZod.safeParse(value).success\n}\n","import type { Brand } from '@xylabs/typeof'\n// eslint-disable-next-line no-restricted-syntax\nimport * as z from 'zod'\n\nimport type { AssertConfig } from './assert.ts'\nimport { assertError } from './assert.ts'\nimport type { HexConfig } from './hex/index.ts'\nimport {\n hexFrom, hexFromHexString, isHex,\n} from './hex/index.ts'\nimport { HexRegExMinMaxMixedCaseWithPrefix } from './HexRegEx.ts'\n\nexport const EthAddressRegEx = HexRegExMinMaxMixedCaseWithPrefix(20, 20)\n\nexport const EthAddressToStringZod = z.string().regex(EthAddressRegEx)\n\n/** @deprecated use EthAddressToStringZod */\nexport const EthAddressToStringSchema = EthAddressToStringZod\n\nexport const EthAddressFromStringZod = z.string().regex(EthAddressRegEx).transform(v => toEthAddress(v))\n\n/** @deprecated use EthAddressFromStringZod */\nexport const EthAddressFromStringSchema = EthAddressFromStringZod\n\n// using true instead of unique symbol to avoid conflicts with other versions of library\nexport type EthAddress = Brand<string, { readonly __eth_address: true }>\n\nexport const ETH_ZERO_ADDRESS = '0x0000000000000000000000000000000000000000' as EthAddress\n\nexport const toEthAddress = (value: string | number | bigint | ArrayBufferLike, config: HexConfig = {}): EthAddress => {\n const { bitLength = 160, prefix = false } = config\n return `0x${hexFrom(value, {\n bitLength, prefix, ...config,\n })}` as EthAddress\n}\n\nexport const isEthAddress = (value: unknown, config: HexConfig = {}): value is EthAddress => {\n const { bitLength = 160, prefix = true } = config\n const loweredValue = typeof value === 'string' ? value.toLowerCase() : value\n return isHex(loweredValue, { bitLength, prefix })\n}\n\nexport const EthAddressZod = z.string()\n .regex(EthAddressRegEx, { message: 'Invalid address format' })\n .refine(\n isEthAddress,\n )\n\nexport function asEthAddress(value: unknown): EthAddress | undefined\nexport function asEthAddress(value: unknown, assert: AssertConfig): EthAddress\nexport function asEthAddress(value: unknown, assert?: AssertConfig): EthAddress | undefined {\n try {\n let stringValue: string | undefined = undefined\n\n switch (typeof value) {\n case 'string': {\n stringValue = hexFromHexString(value, { prefix: true, byteSize: 4 })\n break\n }\n default: {\n if (value !== undefined) {\n return assertError(value, assert, `Unsupported type [${typeof value}]`)\n }\n }\n }\n return isEthAddress(stringValue) ? stringValue : assertError(value, assert, `Value is not an EthAddress [${value}]`)\n } catch (ex) {\n const error = ex as Error\n return assertError(undefined, assert, error.message)\n }\n}\n","import { isUndefined } from '@xylabs/typeof'\n\nimport type { AssertConfig } from '../assert.ts'\nimport { assertError } from '../assert.ts'\nimport { hexFromHexString } from '../hex/index.ts'\nimport { type Hash } from './hash.ts'\nimport { isHash } from './is.ts'\n\nexport function asHash(value: unknown): Hash | undefined\nexport function asHash(value: unknown, assert: AssertConfig): Hash\nexport function asHash(value: unknown, assert?: AssertConfig): Hash | undefined {\n let stringValue: string | undefined = undefined\n\n switch (typeof value) {\n case 'string': {\n stringValue = hexFromHexString(value)\n break\n }\n default: {\n return isUndefined(assert) ? undefined : assertError(value, assert, `Unsupported type [${typeof value}]`)\n }\n }\n return isHash(stringValue) ? stringValue : assertError(value, assert, `Value is not a Hash [${value}]`)\n}\n","import { isHex } from '../hex/index.ts'\nimport type { Hash, HashBitLength } from './hash.ts'\n\nexport const isHash = (value: unknown, bitLength: HashBitLength = 256): value is Hash => {\n return isHex(value, { bitLength })\n}\n","import type { Brand } from '@xylabs/typeof'\n// eslint-disable-next-line no-restricted-syntax\nimport * as z from 'zod'\n\nimport type { Hex } from '../hex/index.ts'\nimport { HexRegExMinMax } from '../HexRegEx.ts'\n\nexport const HASH_LENGTH = 32 as const\n\nexport const HashRegEx = HexRegExMinMax(HASH_LENGTH, HASH_LENGTH)\n\nexport const ZERO_HASH = '0000000000000000000000000000000000000000000000000000000000000000' as Hash\n\nexport type HashBitLength = 32 | 64 | 128 | 256 | 512 | 1024 | 2048 | 4096\nexport const HashBitLength: HashBitLength[] = [32, 64, 128, 256, 512, 1024, 2048, 4096]\n\nexport const isHashBitLength = (value: unknown): value is HashBitLength => {\n return typeof value === 'number' && HashBitLength.includes(value as HashBitLength)\n}\n\nexport const HashZod = z.string()\n .regex(HashRegEx, { message: 'Invalid hex format' }) as unknown as z.ZodType<Brand<Hex, { readonly __hash: true }>>\n\nexport type Hash = z.infer<typeof HashZod>\n","// eslint-disable-next-line no-restricted-syntax\nimport * as z from 'zod'\n\nimport { asHash } from './as.ts'\nimport type { Hash } from './hash.ts'\nimport { HashZod } from './hash.ts'\n\nexport const HashToJsonZod = HashZod.transform<string>(v => v)\nexport const JsonToHashZod = z.string().transform<Hash>(v => asHash(v, true))\n","import { type Hex, hexFromHexString } from './hex/index.ts'\n\nexport function hexToBigInt(hex: Hex): bigint {\n return BigInt(hexFromHexString(hex, { prefix: true }))\n}\n","// eslint-disable-next-line no-restricted-syntax\nimport * as z from 'zod'\n\nimport { toHex } from './hex/index.ts'\nimport { hexToBigInt } from './hexToBigInt.ts'\n\nexport const BigIntToJsonZod = z.bigint().nonnegative().transform(x => toHex(x))\nexport const JsonToBigIntZod = z.string().transform(x => toHex(x)).transform(x => hexToBigInt(x))\n"],"mappings":";AAEA,YAAY,OAAO;;;ACFZ,IAAM,iBAAiB,CAAC,WAAW,GAAG,WAAoB,OAAO,mBAAmB,MAAO;AAChG,SAAO,IAAI,OAAO,aAAa,WAAW,CAAC,IAAI,WAAW,CAAC,IAAI;AACjE;AAEO,IAAM,oCAAoC,CAAC,WAAW,GAAG,WAAoB,OAAO,mBAAmB,MAAO;AACnH,SAAO,IAAI,OAAO,kBAAkB,WAAW,CAAC,IAAI,WAAW,CAAC,IAAI;AACtE;AAEO,IAAM,WAAW;AACjB,IAAM,qBAAqB;;;ADF3B,IAAM,eAAe;AACrB,IAAM,iBAAiB;AAEvB,IAAM,eAAe,eAAe,iBAAiB,GAAG,iBAAiB,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SAAS,KAAsB;AACnF;AAEO,IAAM,UAAY,UAAO,EAC7B,MAAM,WAAW,EAAE,SAAS,qBAAqB,CAAC;;;ACpBrD,YAAYC,QAAO;AAMZ,IAAM,gBAAgB,QAAQ,UAAkB,OAAK,CAAC;AACtD,IAAM,gBAAkB,UAAO,EAAE,UAAgB,OAAK,OAAO,GAAG,IAAI,CAAC;;;ACNrE,SAAS,YAAY,KAAkB;AAC5C,SAAO,OAAO,iBAAiB,KAAK,EAAE,QAAQ,KAAK,CAAC,CAAC;AACvD;;;ACHA,YAAYC,QAAO;AAKZ,IAAM,kBAAoB,UAAO,EAAE,YAAY,EAAE,UAAU,OAAK,MAAM,CAAC,CAAC;AACxE,IAAM,kBAAoB,UAAO,EAAE,UAAU,OAAK,MAAM,CAAC,CAAC,EAAE,UAAU,OAAK,YAAY,CAAC,CAAC;","names":["z","z","isString","isString","z","z","z","isUndefined","isUndefined","z","z","z"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xylabs/hex",
3
- "version": "5.0.19",
3
+ "version": "5.0.21",
4
4
  "description": "Base functionality used throughout XY Labs TypeScript/JavaScript libraries",
5
5
  "keywords": [
6
6
  "hex",
@@ -47,13 +47,13 @@
47
47
  "src"
48
48
  ],
49
49
  "dependencies": {
50
- "@xylabs/typeof": "~5.0.19",
50
+ "@xylabs/typeof": "~5.0.21",
51
51
  "zod": "^4.1.12"
52
52
  },
53
53
  "devDependencies": {
54
- "@xylabs/ts-scripts-yarn3": "~7.2.4",
55
- "@xylabs/tsconfig": "~7.2.4",
56
- "@xylabs/vitest-extended": "~5.0.19",
54
+ "@xylabs/ts-scripts-yarn3": "~7.2.8",
55
+ "@xylabs/tsconfig": "~7.2.8",
56
+ "@xylabs/vitest-extended": "~5.0.21",
57
57
  "typescript": "~5.9.3",
58
58
  "vitest": "~4.0.8"
59
59
  },
package/src/ethAddress.ts CHANGED
@@ -36,7 +36,8 @@ export const toEthAddress = (value: string | number | bigint | ArrayBufferLike,
36
36
 
37
37
  export const isEthAddress = (value: unknown, config: HexConfig = {}): value is EthAddress => {
38
38
  const { bitLength = 160, prefix = true } = config
39
- return isHex(value, { bitLength, prefix })
39
+ const loweredValue = typeof value === 'string' ? value.toLowerCase() : value
40
+ return isHex(loweredValue, { bitLength, prefix })
40
41
  }
41
42
 
42
43
  export const EthAddressZod = z.string()
@@ -53,7 +54,7 @@ export function asEthAddress(value: unknown, assert?: AssertConfig): EthAddress
53
54
 
54
55
  switch (typeof value) {
55
56
  case 'string': {
56
- stringValue = hexFromHexString(value, { prefix: true })
57
+ stringValue = hexFromHexString(value, { prefix: true, byteSize: 4 })
57
58
  break
58
59
  }
59
60
  default: {
@@ -10,14 +10,14 @@ import {
10
10
  } from '../ethAddress.ts'
11
11
 
12
12
  describe('ethAddress', () => {
13
- const validAddresses = [
13
+ const isValidAddresses = [
14
14
  '0xCd9A7cf9A3b809b18a274cE648f6b59E40De8bd9',
15
15
  '0x9b59c7E7B758364c8e24a79ff8f84d9f073156fD',
16
16
  '0x0000000000000000000000000000000000000000',
17
17
  '0xffffffffffffffffffffffffffffffffffffffff',
18
18
  '0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF',
19
19
  ]
20
- const invalidAddresses = [
20
+ const isInvalidAddresses = [
21
21
  '0xCd9A7cf9A3b809b18a274cE648f6b59E40De8bd', // too short
22
22
  '0x9b59c7E7B758364c8e24a79ff8f84d9f073156fDD', // too long
23
23
  '0xfffffffffffffffffffffffffffffffffffffffg', // invalid chars
@@ -25,35 +25,59 @@ describe('ethAddress', () => {
25
25
  '', // empty string
26
26
  '0x12345', // way too short
27
27
  ]
28
+ const asValidAddresses = [
29
+ ...isValidAddresses,
30
+ 'Cd9A7cf9A3b809b18a274cE648f6b59E40De8bd9', // missing prefix
31
+ ]
32
+ const asInvalidAddresses = [
33
+ '0xCd9A7cf9A3b809b18a274cE648f6b59E40De8bd', // too short
34
+ '0x9b59c7E7B758364c8e24a79ff8f84d9f073156fDD', // too long
35
+ '0xfffffffffffffffffffffffffffffffffffffffg', // invalid chars
36
+ '', // empty string
37
+ '0x12345', // way too short
38
+ ]
39
+
40
+ const toValidAddresses = [
41
+ ...asValidAddresses,
42
+ 'Cd9A7cf9A3b809b18a274cE648f6b59E40De8bd9', // missing prefix
43
+ '0xCd9A7cf9A3b809b18a274cE648f6b59E40De8bd', // too short
44
+ ]
45
+
46
+ const toInvalidAddresses = [
47
+ '0x9b59c7E7B758364c8e24a79ff8f84d9f073156fDD', // too long
48
+ '0xfffffffffffffffffffffffffffffffffffffffg', // invalid chars
49
+ '', // empty string
50
+ '0x12345', // way too short
51
+ ]
28
52
  describe('EthAddressRegEx', () => {
29
- it.each(invalidAddresses)('should return false for invalid addresses', (address) => {
53
+ it.each(isInvalidAddresses)('should return false for invalid addresses', (address) => {
30
54
  expect(EthAddressRegEx.test(address)).toBeFalse()
31
55
  })
32
- it.each(validAddresses)('should return true for valid addresses', (address) => {
56
+ it.each(isValidAddresses)('should return true for valid addresses', (address) => {
33
57
  expect(EthAddressRegEx.test(address)).toBeTrue()
34
58
  })
35
59
  })
36
60
  describe('asEthAddress', () => {
37
- it.each(invalidAddresses)('should return undefined for invalid addresses', (address) => {
61
+ it.each(asInvalidAddresses)('should return undefined for invalid addresses', (address) => {
38
62
  expect(asEthAddress(address)).toBeUndefined()
39
63
  })
40
- it.each(validAddresses)('should return address for valid addresses', (address) => {
64
+ it.each(asValidAddresses)('should return address for valid addresses', (address) => {
41
65
  expect(asEthAddress(address)).toBeDefined()
42
66
  })
43
67
  })
44
68
  describe('isEthAddress', () => {
45
- it.each(invalidAddresses)('should return false for invalid addresses', (address) => {
69
+ it.each(isInvalidAddresses)('should return false for invalid addresses', (address) => {
46
70
  expect(isEthAddress(address)).toBeFalse()
47
71
  })
48
- it.each(validAddresses)('should return true for valid addresses', (address) => {
72
+ it.each(isValidAddresses)('should return true for valid addresses', (address) => {
49
73
  expect(isEthAddress(address)).toBeTrue()
50
74
  })
51
75
  })
52
- describe('toEthAddress', () => {
53
- it.each(invalidAddresses)('should throw for invalid addresses', (address) => {
76
+ describe.skip('toEthAddress', () => {
77
+ it.each(toInvalidAddresses)('should throw for invalid addresses', (address) => {
54
78
  expect(() => toEthAddress(address)).toThrow()
55
79
  })
56
- it.each(validAddresses)('should return address for valid addresses', (address) => {
80
+ it.each(toValidAddresses)('should return address for valid addresses', (address) => {
57
81
  expect(toEthAddress(address)).toBeDefined()
58
82
  })
59
83
  })