@xylabs/hex
Advanced tools
@@ -1,8 +0,2 @@ | ||
| export * from './address/index.ts'; | ||
| export * from './ethAddress.ts'; | ||
| export * from './hash/index.ts'; | ||
| export * from './hex/index.ts'; | ||
| export * from './HexRegEx.ts'; | ||
| export * from './hexToBigInt.ts'; | ||
| export * from './zod.ts'; | ||
| export * from '@ariestools/sdk/hex'; | ||
| //# sourceMappingURL=index.d.ts.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAA;AAClC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,eAAe,CAAA;AAC7B,cAAc,kBAAkB,CAAA;AAChC,cAAc,UAAU,CAAA"} | ||
| {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA"} |
+2
-380
@@ -1,381 +0,3 @@ | ||
| // src/address/address.ts | ||
| import * as z from "zod/mini"; | ||
| // src/HexRegEx.ts | ||
| var HexRegExMinMax = (minBytes = 0, maxBytes = Number.MAX_SAFE_INTEGER / 2) => { | ||
| return new RegExp(`^[a-f0-9]{${minBytes * 2},${maxBytes * 2}}$`); | ||
| }; | ||
| var HexRegExMinMaxMixedCaseWithPrefix = (minBytes = 0, maxBytes = Number.MAX_SAFE_INTEGER / 2) => { | ||
| return new RegExp(`^0x[a-fA-F0-9]{${minBytes * 2},${maxBytes * 2}}$`); | ||
| }; | ||
| var HexRegEx = /^[0-9a-f]+$/; | ||
| var HexRegExWithPrefix = /^0x[0-9a-f]+$/; | ||
| // src/address/address.ts | ||
| var ZERO_ADDRESS = "0000000000000000000000000000000000000000"; | ||
| var ADDRESS_LENGTH = 40; | ||
| var AddressRegEx = HexRegExMinMax(ADDRESS_LENGTH / 2, ADDRESS_LENGTH / 2); | ||
| var AddressZod = z.pipe( | ||
| z.string().check(z.regex(AddressRegEx)), | ||
| z.transform((v) => v) | ||
| ); | ||
| // src/address/AddressTransformZod.ts | ||
| import * as z4 from "zod/mini"; | ||
| // src/address/AddressValidationZod.ts | ||
| import * as z3 from "zod/mini"; | ||
| // src/hex/as.ts | ||
| import { assertError } from "@xylabs/error"; | ||
| // src/hex/from/fromHexString.ts | ||
| import { isNumber } from "@xylabs/typeof"; | ||
| // src/hex/nibble.ts | ||
| var bitsToNibbles = (value) => { | ||
| const nibbles = value >> 2; | ||
| if (value !== nibbles << 2) throw new Error("Bits for nibbles must multiple of 4"); | ||
| return nibbles; | ||
| }; | ||
| var nibblesToBits = (value) => { | ||
| return value << 2; | ||
| }; | ||
| // src/hex/is.ts | ||
| var isHex = (value, config) => { | ||
| if (typeof value !== "string") return false; | ||
| const valueCharLength = value.length - (config?.prefix === true ? 2 : 0); | ||
| if (config?.bitLength !== void 0 && valueCharLength !== bitsToNibbles(config?.bitLength)) return false; | ||
| const regex5 = config?.prefix === true ? HexRegExWithPrefix : HexRegEx; | ||
| return regex5.test(value); | ||
| }; | ||
| // src/hex/from/fromHexString.ts | ||
| var hexFromHexString = (value, config = {}) => { | ||
| const { | ||
| prefix: isPrefix = false, | ||
| byteSize = 8, | ||
| bitLength | ||
| } = config; | ||
| const nibbleBoundary = bitsToNibbles(byteSize); | ||
| const unEvened = (value.startsWith("0x") ? value.slice(2) : value).toLowerCase(); | ||
| if (isHex(unEvened)) { | ||
| const evenCharacters = unEvened.padStart(Math.ceil(unEvened.length / nibbleBoundary) * nibbleBoundary, "0"); | ||
| const padded = isNumber(bitLength) ? evenCharacters.padStart(bitLength / 4, "0") : evenCharacters; | ||
| return (isPrefix ? `0x${padded}` : padded).toLowerCase(); | ||
| } | ||
| throw new Error("Received string is not a value hex"); | ||
| }; | ||
| // src/hex/from/fromArrayBuffer.ts | ||
| var hexFromArrayBuffer = (buffer, config) => { | ||
| const unPadded = [...new Uint8Array(buffer)].map((x) => x.toString(16).padStart(2, "0")).join(""); | ||
| return hexFromHexString(unPadded, config); | ||
| }; | ||
| // src/hex/from/fromBigInt.ts | ||
| var hexFromBigInt = (value, config = {}) => { | ||
| const unPadded = value.toString(16); | ||
| return hexFromHexString(unPadded, config); | ||
| }; | ||
| // src/hex/from/fromNumber.ts | ||
| var hexFromNumber = (value, config) => { | ||
| return hexFromBigInt(BigInt(value), config); | ||
| }; | ||
| // src/hex/from/from.ts | ||
| var hexFrom = (value, config) => { | ||
| switch (typeof value) { | ||
| case "string": { | ||
| return hexFromHexString(value, config); | ||
| } | ||
| case "bigint": { | ||
| return hexFromBigInt(value, config); | ||
| } | ||
| case "number": { | ||
| return hexFromNumber(value, config); | ||
| } | ||
| case "object": { | ||
| return hexFromArrayBuffer(value, config); | ||
| } | ||
| default: { | ||
| throw new Error(`Invalid type: ${typeof value}`); | ||
| } | ||
| } | ||
| }; | ||
| // src/hex/as.ts | ||
| function asHex(value, assert) { | ||
| switch (typeof value) { | ||
| case "string": { | ||
| const stringValue = hexFromHexString(value); | ||
| return isHex(stringValue) ? stringValue : assertError(value, assert, `Value is not Hex [${value}]`); | ||
| } | ||
| default: { | ||
| return assertError(value, assert, `Unsupported type [${typeof value}]`); | ||
| } | ||
| } | ||
| } | ||
| // src/hex/hex.ts | ||
| import * as z2 from "zod/mini"; | ||
| var HexZod = z2.pipe( | ||
| z2.string().check(z2.regex(HexRegEx, { error: "Invalid hex format" })), | ||
| z2.transform((val) => val) | ||
| ); | ||
| // src/hex/isHexZero.ts | ||
| import { isString } from "@xylabs/typeof"; | ||
| var isHexZero = (value) => { | ||
| return isString(value) ? BigInt(hexFromHexString(value, { prefix: true })) === 0n : void 0; | ||
| }; | ||
| // src/hex/legacy.ts | ||
| var toHexLegacy = (buffer) => { | ||
| return [...new Uint8Array(buffer)].map((x) => x.toString(16).padStart(2, "0")).join(""); | ||
| }; | ||
| // src/hex/to.ts | ||
| var toHex = (value, config = {}) => { | ||
| const { prefix: isPrefix = false } = config; | ||
| return hexFrom(value, { prefix: isPrefix, ...config }); | ||
| }; | ||
| // src/address/AddressValidationZod.ts | ||
| var AddressValidationZod = z3.pipe( | ||
| z3.string().check( | ||
| z3.refine((x) => HexZod.safeParse(x).success), | ||
| z3.refine((x) => x.length === ADDRESS_LENGTH, { error: (e) => new Error(`Address must have 40 characters [${String(e.input)}]`) }) | ||
| ), | ||
| z3.transform((v) => v) | ||
| ); | ||
| // src/address/AddressTransformZod.ts | ||
| var AddressTransformZod = z4.pipe( | ||
| z4.pipe( | ||
| z4.union([z4.string(), z4.bigint(), z4.number()]), | ||
| z4.transform((value) => { | ||
| if (typeof value === "bigint") { | ||
| return value.toString(16).padStart(ADDRESS_LENGTH, "0"); | ||
| } | ||
| if (typeof value === "string") { | ||
| return value.startsWith("0x") ? value.slice(2) : value; | ||
| } | ||
| return BigInt(value).toString(16).padStart(ADDRESS_LENGTH, "0"); | ||
| }) | ||
| ).check(z4.refine((x) => AddressValidationZod.safeParse(x).success)), | ||
| z4.transform((x) => x) | ||
| ); | ||
| // src/address/as.ts | ||
| import { assertError as assertError2 } from "@xylabs/error"; | ||
| import { isObject } from "@xylabs/typeof"; | ||
| // src/address/is.ts | ||
| var isAddress = (value, config = {}) => { | ||
| const { bitLength = 160, prefix: isPrefix = false } = config; | ||
| return isHex(value, { bitLength, prefix: isPrefix }); | ||
| }; | ||
| function isAddressV2(value) { | ||
| return AddressValidationZod.safeParse(value).success; | ||
| } | ||
| // src/address/as.ts | ||
| function asAddress(value, assert) { | ||
| try { | ||
| let stringValue; | ||
| switch (typeof value) { | ||
| case "string": { | ||
| stringValue = hexFromHexString(value, { prefix: false, byteSize: 4 }); | ||
| break; | ||
| } | ||
| default: { | ||
| return isObject(assert) ? assertError2(value, assert, `Unsupported type [${typeof value}]`) : void 0; | ||
| } | ||
| } | ||
| return isAddress(stringValue) ? stringValue : assertError2(value, assert, `Value is not an Address [${value}]`); | ||
| } catch (ex) { | ||
| const error = ex; | ||
| return assertError2(void 0, assert, error.message); | ||
| } | ||
| } | ||
| function asAddressV2(value, assert = false) { | ||
| return assert ? AddressValidationZod.parse(value) : AddressValidationZod.safeParse(value).data; | ||
| } | ||
| // src/address/to.ts | ||
| var toAddress = (value, config = {}) => { | ||
| const { bitLength = 160, prefix: isPrefix = false } = config; | ||
| return hexFrom(value, { | ||
| bitLength, | ||
| prefix: isPrefix, | ||
| ...config | ||
| }); | ||
| }; | ||
| function toAddressV2(value, assert = false) { | ||
| return assert ? AddressTransformZod.parse(value) : AddressTransformZod.safeParse(value).data; | ||
| } | ||
| // src/ethAddress.ts | ||
| import { assertError as assertError3 } from "@xylabs/error"; | ||
| import * as z5 from "zod/mini"; | ||
| var EthAddressRegEx = HexRegExMinMaxMixedCaseWithPrefix(20, 20); | ||
| var EthAddressToStringZod = z5.string().check(z5.regex(EthAddressRegEx)); | ||
| var EthAddressToStringSchema = EthAddressToStringZod; | ||
| var EthAddressFromStringZod = z5.pipe( | ||
| z5.string().check(z5.regex(EthAddressRegEx)), | ||
| z5.transform((v) => toEthAddress(v)) | ||
| ); | ||
| var EthAddressFromStringSchema = EthAddressFromStringZod; | ||
| var ETH_ZERO_ADDRESS = "0x0000000000000000000000000000000000000000"; | ||
| var toEthAddress = (value, config = {}) => { | ||
| const { bitLength = 160, prefix: isPrefix = false } = config; | ||
| return `0x${hexFrom(value, { | ||
| bitLength, | ||
| prefix: isPrefix, | ||
| ...config | ||
| })}`; | ||
| }; | ||
| var isEthAddress = (value, config = {}) => { | ||
| const { bitLength = 160, prefix: isPrefix = true } = config; | ||
| const loweredValue = typeof value === "string" ? value.toLowerCase() : value; | ||
| return isHex(loweredValue, { bitLength, prefix: isPrefix }); | ||
| }; | ||
| var EthAddressZod = z5.string().check( | ||
| z5.regex(EthAddressRegEx, { error: "Invalid address format" }), | ||
| z5.refine(isEthAddress) | ||
| ); | ||
| function asEthAddress(value, assert) { | ||
| try { | ||
| let stringValue; | ||
| switch (typeof value) { | ||
| case "string": { | ||
| stringValue = hexFromHexString(value, { prefix: true, byteSize: 4 }); | ||
| break; | ||
| } | ||
| default: { | ||
| if (value !== void 0) { | ||
| return assertError3(value, assert, `Unsupported type [${typeof value}]`); | ||
| } | ||
| } | ||
| } | ||
| return isEthAddress(stringValue) ? stringValue : assertError3(value, assert, `Value is not an EthAddress [${value}]`); | ||
| } catch (ex) { | ||
| const error = ex; | ||
| return assertError3(void 0, assert, error.message); | ||
| } | ||
| } | ||
| // src/hash/as.ts | ||
| import { assertError as assertError4 } from "@xylabs/error"; | ||
| import { isUndefined } from "@xylabs/typeof"; | ||
| // src/hash/is.ts | ||
| var isHash = (value, bitLength = 256) => { | ||
| return isHex(value, { bitLength }); | ||
| }; | ||
| // src/hash/as.ts | ||
| function asHash(value, assert) { | ||
| switch (typeof value) { | ||
| case "string": { | ||
| const stringValue = hexFromHexString(value); | ||
| return isHash(stringValue) ? stringValue : assertError4(value, assert, `Value is not a Hash [${value}]`); | ||
| } | ||
| default: { | ||
| return isUndefined(assert) ? void 0 : assertError4(value, assert, `Unsupported type [${typeof value}]`); | ||
| } | ||
| } | ||
| } | ||
| // src/hash/hash.ts | ||
| import * as z6 from "zod/mini"; | ||
| var HASH_LENGTH = 32; | ||
| var HashRegEx = HexRegExMinMax(HASH_LENGTH, HASH_LENGTH); | ||
| var ZERO_HASH = "0000000000000000000000000000000000000000000000000000000000000000"; | ||
| var HashBitLength = [32, 64, 128, 256, 512, 1024, 2048, 4096]; | ||
| var isHashBitLength = (value) => { | ||
| return typeof value === "number" && HashBitLength.includes(value); | ||
| }; | ||
| var HashZod = z6.pipe( | ||
| z6.string().check(z6.regex(HashRegEx, { error: "Invalid hex format" })), | ||
| z6.transform((val) => val) | ||
| ); | ||
| // src/hash/zod.ts | ||
| import * as z7 from "zod/mini"; | ||
| var HashToJsonZod = z7.pipe(HashZod, z7.transform((v) => v)); | ||
| var JsonToHashZod = z7.pipe(z7.string(), z7.transform((v) => asHash(v, true))); | ||
| // src/hexToBigInt.ts | ||
| function hexToBigInt(hex) { | ||
| return BigInt(hexFromHexString(hex, { prefix: true })); | ||
| } | ||
| // src/zod.ts | ||
| import * as z8 from "zod/mini"; | ||
| var BigIntToJsonZod = z8.pipe( | ||
| z8.bigint().check(z8.nonnegative()), | ||
| z8.transform((x) => toHex(x)) | ||
| ); | ||
| var JsonToBigIntZod = z8.pipe( | ||
| z8.string(), | ||
| z8.transform((x) => hexToBigInt(toHex(x))) | ||
| ); | ||
| export { | ||
| ADDRESS_LENGTH, | ||
| AddressRegEx, | ||
| AddressTransformZod, | ||
| AddressValidationZod, | ||
| AddressZod, | ||
| BigIntToJsonZod, | ||
| ETH_ZERO_ADDRESS, | ||
| EthAddressFromStringSchema, | ||
| EthAddressFromStringZod, | ||
| EthAddressRegEx, | ||
| EthAddressToStringSchema, | ||
| EthAddressToStringZod, | ||
| EthAddressZod, | ||
| HASH_LENGTH, | ||
| HashBitLength, | ||
| HashRegEx, | ||
| HashToJsonZod, | ||
| HashZod, | ||
| HexRegEx, | ||
| HexRegExMinMax, | ||
| HexRegExMinMaxMixedCaseWithPrefix, | ||
| HexRegExWithPrefix, | ||
| HexZod, | ||
| JsonToBigIntZod, | ||
| JsonToHashZod, | ||
| ZERO_ADDRESS, | ||
| ZERO_HASH, | ||
| asAddress, | ||
| asAddressV2, | ||
| asEthAddress, | ||
| asHash, | ||
| asHex, | ||
| bitsToNibbles, | ||
| hexFrom, | ||
| hexFromArrayBuffer, | ||
| hexFromBigInt, | ||
| hexFromHexString, | ||
| hexFromNumber, | ||
| hexToBigInt, | ||
| isAddress, | ||
| isAddressV2, | ||
| isEthAddress, | ||
| isHash, | ||
| isHashBitLength, | ||
| isHex, | ||
| isHexZero, | ||
| nibblesToBits, | ||
| toAddress, | ||
| toAddressV2, | ||
| toEthAddress, | ||
| toHex, | ||
| toHexLegacy | ||
| }; | ||
| // src/index.ts | ||
| export * from "@ariestools/sdk/hex"; | ||
| //# sourceMappingURL=index.mjs.map |
| { | ||
| "version": 3, | ||
| "sources": ["../../src/address/address.ts", "../../src/HexRegEx.ts", "../../src/address/AddressTransformZod.ts", "../../src/address/AddressValidationZod.ts", "../../src/hex/as.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/hex.ts", "../../src/hex/isHexZero.ts", "../../src/hex/legacy.ts", "../../src/hex/to.ts", "../../src/address/as.ts", "../../src/address/is.ts", "../../src/address/to.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'\nimport * as z from 'zod/mini'\n\nimport { type Hex } from '../hex/index.ts'\nimport { HexRegExMinMax } from '../HexRegEx.ts'\n\n/** A 160-bit zero address constant. */\nexport const ZERO_ADDRESS = '0000000000000000000000000000000000000000' as Address\n/** The character length of an address hex string (40 hex characters / 20 bytes). */\nexport const ADDRESS_LENGTH = 40 as const\n\n/** Regular expression matching a 20-byte (40 hex character) address string. */\nexport const AddressRegEx = HexRegExMinMax(ADDRESS_LENGTH / 2, ADDRESS_LENGTH / 2)\n\ntype BrandedAddress = Brand<Hex, { readonly __address: true }>\n\n/** Zod schema that validates and transforms a string into a branded Address type. */\nexport const AddressZod = z.pipe(\n z.string().check(z.regex(AddressRegEx)),\n z.transform((v: string): BrandedAddress => v as BrandedAddress),\n)\n\n/** A validated 20-byte address string type, inferred from the AddressZod schema. */\nexport type Address = z.infer<typeof AddressZod>\n", "/**\n * Creates a RegExp matching lowercase hex strings with a byte length in the given range.\n * @param minBytes - Minimum number of bytes (default 0)\n * @param maxBytes - Maximum number of bytes\n * @returns A RegExp for validating hex strings within the byte range\n */\nexport const HexRegExMinMax = (minBytes = 0, maxBytes: number = (Number.MAX_SAFE_INTEGER / 2)) => {\n return new RegExp(`^[a-f0-9]{${minBytes * 2},${maxBytes * 2}}$`)\n}\n\n/**\n * Creates a RegExp matching mixed-case hex strings with a 0x prefix and a byte length in the given range.\n * @param minBytes - Minimum number of bytes (default 0)\n * @param maxBytes - Maximum number of bytes\n * @returns A RegExp for validating prefixed hex strings within the byte range\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\n/** Regular expression matching a lowercase hex string without prefix. */\nexport const HexRegEx = /^[0-9a-f]+$/\n/** Regular expression matching a lowercase hex string with a 0x prefix. */\nexport const HexRegExWithPrefix = /^0x[0-9a-f]+$/\n", "import * as z from 'zod/mini'\n\nimport { type Address, ADDRESS_LENGTH } from './address.ts'\nimport { AddressValidationZod } from './AddressValidationZod.ts'\n\n/** Zod schema that accepts a string, bigint, or number and transforms it into a validated Address. */\nexport const AddressTransformZod = z.pipe(\n z.pipe(\n z.union([z.string(), z.bigint(), z.number()]),\n z.transform((value: string | bigint | number): string => {\n if (typeof value === 'bigint') {\n return value.toString(16).padStart(ADDRESS_LENGTH, '0')\n }\n if (typeof value === 'string') {\n return value.startsWith('0x') ? value.slice(2) : value\n }\n return BigInt(value).toString(16).padStart(ADDRESS_LENGTH, '0')\n }),\n ).check(z.refine((x: string) => AddressValidationZod.safeParse(x).success)),\n z.transform((x: string): Address => x as Address),\n)\n\n/** The output type of AddressTransformZod after parsing and transformation. */\nexport type AddressTransformZodType = z.infer<typeof AddressTransformZod>\n", "import * as z from 'zod/mini'\n\nimport { HexZod } from '../hex/index.ts'\nimport type { Address } from './address.ts'\nimport { ADDRESS_LENGTH } from './address.ts'\n\n/** Zod schema that validates a string is a properly formatted 40-character hex address. */\nexport const AddressValidationZod = z.pipe(\n z.string().check(\n z.refine((x: string) => HexZod.safeParse(x).success),\n z.refine((x: string) => x.length === ADDRESS_LENGTH, { error: e => new Error(`Address must have 40 characters [${String(e.input)}]`) }),\n ),\n z.transform((v: string): Address => v as Address),\n)\n\n/** The output type of AddressValidationZod after parsing. */\nexport type AddressValidationZodType = z.infer<typeof AddressValidationZod>\n", "import type { AssertConfig } from '@xylabs/error'\nimport { assertError } from '@xylabs/error'\n\nimport { hexFromHexString } from './from/index.ts'\nimport type { Hex } from './hex.ts'\nimport { isHex } from './is.ts'\n\n/**\n * Attempts to coerce a value into a Hex type, returning undefined or throwing based on the assert config.\n * @param value - The value to coerce (must be a string)\n * @param assert - If provided, throws on failure instead of returning undefined\n * @returns The value as Hex, or undefined if coercion fails and assert is not set\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 switch (typeof value) {\n case 'string': {\n const stringValue = hexFromHexString(value)\n return isHex(stringValue) ? stringValue : assertError(value, assert, `Value is not Hex [${value}]`)\n }\n default: {\n return assertError(value, assert, `Unsupported type [${typeof value}]`)\n }\n }\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\n/**\n * Normalizes a hex string by stripping an optional 0x prefix, lowercasing, and padding to byte/bit boundaries.\n * @param value - The hex string to normalize (with or without 0x prefix)\n * @param config - Configuration for prefix, byteSize, and bitLength padding\n * @returns The normalized Hex string\n */\nexport const hexFromHexString = (value: string, config: HexConfig = {}): Hex => {\n const {\n prefix: isPrefix = 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(Math.ceil(unEvened.length / nibbleBoundary) * nibbleBoundary, '0')\n const padded = isNumber(bitLength) ? evenCharacters.padStart(bitLength / 4, '0') : evenCharacters\n return (isPrefix ? `0x${padded}` : padded).toLowerCase() as Hex\n }\n throw new Error('Received string is not a value hex')\n}\n", "/**\n * Converts a bit count to the equivalent number of hex nibbles (4 bits each).\n * @param value - The number of bits (must be a multiple of 4)\n * @returns The number of nibbles\n */\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/**\n * Converts a nibble count to the equivalent number of bits.\n * @param value - The number of nibbles\n * @returns The number of bits\n */\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\n/**\n * Type guard that checks whether a value is a valid hex string.\n * @param value - The value to check\n * @param config - Optional configuration for prefix and bit length validation\n * @returns True if the value is a valid Hex string\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 = value.length - (config?.prefix === true ? 2 : 0)\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 const regex = config?.prefix === true ? HexRegExWithPrefix : HexRegEx\n return regex.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\n/**\n * Converts a number to a hex string by converting to BigInt first.\n * @param value - The number to convert\n * @param config - Optional hex output configuration\n * @returns The hex string representation\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 { Brand } from '@xylabs/typeof'\nimport * as z from 'zod/mini'\n\nimport { HexRegEx } from '../HexRegEx.ts'\n\n/** Branded type representing a validated lowercase hex string. */\nexport type BrandedHex = Brand<Lowercase<string>, { readonly __hex: true }>\n\n/** Zod schema that validates and transforms a string into a branded Hex type. */\nexport const HexZod = z.pipe(\n z.string().check(z.regex(HexRegEx, { error: 'Invalid hex format' })),\n z.transform((val: string) => val as BrandedHex),\n)\n\n/** Configuration of validation and output format */\nexport interface HexConfig {\n bitLength?: number\n byteSize?: number\n prefix?: boolean\n}\n\n/** A validated hex string type, inferred from the HexZod schema. */\nexport type Hex = z.infer<typeof HexZod>\n", "import { isString } from '@xylabs/typeof'\n\nimport { hexFromHexString } from './from/index.ts'\n\n/**\n * Checks whether a hex string represents a zero value.\n * @param value - The hex string to check\n * @returns True if zero, false if non-zero, or undefined if the input is not a string\n */\nexport const isHexZero = (value?: string) => {\n return isString(value) ? BigInt(hexFromHexString(value, { prefix: true })) === 0n : undefined\n}\n", "/**\n * Converts an ArrayBuffer to a hex string without padding or normalization.\n * @param buffer - The ArrayBuffer to convert\n * @returns A lowercase hex string representation of the buffer\n */\nexport 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: isPrefix = false } = config\n return hexFrom(value, { prefix: isPrefix, ...config })\n}\n", "import type { AssertConfig } from '@xylabs/error'\nimport { assertError } from '@xylabs/error'\nimport { isObject } from '@xylabs/typeof'\n\nimport { hexFromHexString } from '../hex/index.ts'\nimport type { Address } from './address.ts'\nimport { AddressValidationZod } from './AddressValidationZod.ts'\nimport { isAddress } from './is.ts'\n\n/**\n * Attempts to coerce a value into an Address type, returning undefined or throwing based on the assert config.\n * @param value - The value to coerce (must be a string)\n * @param assert - If provided, throws on failure instead of returning undefined\n * @returns The value as Address, or undefined if coercion fails and assert is not set\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\n\n switch (typeof value) {\n case 'string': {\n stringValue = hexFromHexString(value, { prefix: false, byteSize: 4 })\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 = 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\n/**\n * Type guard that checks whether a value is a valid 160-bit address.\n * @param value - The value to check\n * @param config - Optional hex config (defaults to 160-bit, no prefix)\n * @returns True if the value is a valid Address\n */\nexport const isAddress = (value?: unknown, config: HexConfig = {}): value is Address => {\n const { bitLength = 160, prefix: isPrefix = false } = config\n return isHex(value, { bitLength, prefix: isPrefix })\n}\n\n/** @alpha */\nexport function isAddressV2(value?: unknown): value is Address {\n return AddressValidationZod.safeParse(value).success\n}\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\n/**\n * Converts a value to a 160-bit Address hex string.\n * @param value - The value to convert (string, number, bigint, or ArrayBuffer)\n * @param config - Optional hex config (defaults to 160-bit, no prefix)\n * @returns The value as an Address\n */\nexport const toAddress = (value: string | number | bigint | ArrayBufferLike, config: HexConfig = {}): Address => {\n const { bitLength = 160, prefix: isPrefix = false } = config\n return hexFrom(value, {\n bitLength, prefix: isPrefix, ...config,\n }) as unknown as Address\n}\n\n/** @alpha */\nexport function toAddressV2(value: unknown, assert = false): Address | undefined {\n return assert\n ? AddressTransformZod.parse(value)\n : AddressTransformZod.safeParse(value).data\n}\n", "import type { AssertConfig } from '@xylabs/error'\nimport { assertError } from '@xylabs/error'\nimport type { Brand } from '@xylabs/typeof'\nimport * as z from 'zod/mini'\n\nimport type { HexConfig } from './hex/index.ts'\nimport {\n hexFrom, hexFromHexString, isHex,\n} from './hex/index.ts'\nimport { HexRegExMinMaxMixedCaseWithPrefix } from './HexRegEx.ts'\n\n/** Regular expression matching a 20-byte Ethereum address with 0x prefix (mixed case). */\nexport const EthAddressRegEx = HexRegExMinMaxMixedCaseWithPrefix(20, 20)\n\n/** Zod schema that validates a string is a properly formatted Ethereum address. */\nexport const EthAddressToStringZod = z.string().check(z.regex(EthAddressRegEx))\n\n/** @deprecated use EthAddressToStringZod */\nexport const EthAddressToStringSchema = EthAddressToStringZod\n\n/** Zod schema that validates and transforms a string into an EthAddress type. */\nexport const EthAddressFromStringZod = z.pipe(\n z.string().check(z.regex(EthAddressRegEx)),\n z.transform((v: string) => toEthAddress(v)),\n)\n\n/** @deprecated use EthAddressFromStringZod */\nexport const EthAddressFromStringSchema = EthAddressFromStringZod\n\n/** Branded type representing a validated Ethereum address with 0x prefix. */\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\n/** The zero Ethereum address constant (0x followed by 40 zero characters). */\nexport const ETH_ZERO_ADDRESS = '0x0000000000000000000000000000000000000000' as EthAddress\n\n/**\n * Converts a value to a 0x-prefixed Ethereum address string.\n * @param value - The value to convert (string, number, bigint, or ArrayBuffer)\n * @param config - Optional hex config (defaults to 160-bit, no inner prefix)\n * @returns The value as an EthAddress\n */\nexport const toEthAddress = (value: string | number | bigint | ArrayBufferLike, config: HexConfig = {}): EthAddress => {\n const { bitLength = 160, prefix: isPrefix = false } = config\n return `0x${hexFrom(value, {\n bitLength, prefix: isPrefix, ...config,\n })}` as EthAddress\n}\n\n/**\n * Type guard that checks whether a value is a valid 0x-prefixed Ethereum address.\n * @param value - The value to check\n * @param config - Optional hex config (defaults to 160-bit with prefix)\n * @returns True if the value is a valid EthAddress\n */\nexport const isEthAddress = (value?: unknown, config: HexConfig = {}): value is EthAddress => {\n const { bitLength = 160, prefix: isPrefix = true } = config\n const loweredValue = typeof value === 'string' ? value.toLowerCase() : value\n return isHex(loweredValue, { bitLength, prefix: isPrefix })\n}\n\n/** Zod schema that validates a string as a properly formatted Ethereum address using regex and type guard. */\nexport const EthAddressZod = z.string().check(\n z.regex(EthAddressRegEx, { error: 'Invalid address format' }),\n z.refine(isEthAddress),\n)\n\n/**\n * Attempts to coerce a value into an EthAddress, returning undefined or throwing based on the assert config.\n * @param value - The value to coerce (must be a string)\n * @param assert - If provided, throws on failure instead of returning undefined\n * @returns The value as EthAddress, or undefined if coercion fails and assert is not set\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\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 type { AssertConfig } from '@xylabs/error'\nimport { assertError } from '@xylabs/error'\nimport { isUndefined } from '@xylabs/typeof'\n\nimport { hexFromHexString } from '../hex/index.ts'\nimport { type Hash } from './hash.ts'\nimport { isHash } from './is.ts'\n\n/**\n * Attempts to coerce a value into a Hash type, returning undefined or throwing based on the assert config.\n * @param value - The value to coerce (must be a string)\n * @param assert - If provided, throws on failure instead of returning undefined\n * @returns The value as Hash, or undefined if coercion fails and assert is not set\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 switch (typeof value) {\n case 'string': {\n const stringValue = hexFromHexString(value)\n return isHash(stringValue) ? stringValue : assertError(value, assert, `Value is not a Hash [${value}]`)\n }\n default: {\n return isUndefined(assert) ? undefined : assertError(value, assert, `Unsupported type [${typeof value}]`)\n }\n }\n}\n", "import { isHex } from '../hex/index.ts'\nimport type { Hash, HashBitLength } from './hash.ts'\n\n/**\n * Type guard that checks whether a value is a valid hash of the specified bit length.\n * @param value - The value to check\n * @param bitLength - The expected bit length of the hash (defaults to 256)\n * @returns True if the value is a valid Hash\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'\nimport * as z from 'zod/mini'\n\nimport type { Hex } from '../hex/index.ts'\nimport { HexRegExMinMax } from '../HexRegEx.ts'\n\n/** The byte length of a standard hash (32 bytes / 256 bits). */\nexport const HASH_LENGTH = 32 as const\n\n/** Regular expression matching a 32-byte (64 hex character) hash string. */\nexport const HashRegEx = HexRegExMinMax(HASH_LENGTH, HASH_LENGTH)\n\n/** A 256-bit zero hash constant. */\nexport const ZERO_HASH = '0000000000000000000000000000000000000000000000000000000000000000' as Hash\n\n/** Valid bit lengths for hash values. */\nexport type HashBitLength = 32 | 64 | 128 | 256 | 512 | 1024 | 2048 | 4096\n/** Array of all valid hash bit lengths for runtime validation. */\nexport const HashBitLength: HashBitLength[] = [32, 64, 128, 256, 512, 1024, 2048, 4096]\n\n/**\n * Type guard that checks whether a value is a valid hash bit length.\n * @param value - The value to check\n * @returns True if the value is one of the supported HashBitLength values\n */\nexport const isHashBitLength = (value: unknown): value is HashBitLength => {\n return typeof value === 'number' && HashBitLength.includes(value as HashBitLength)\n}\n\n/** Branded type representing a validated hash hex string. */\nexport type BrandedHash = Brand<Hex, { readonly __hash: true }>\n\n/** Zod schema that validates and transforms a string into a branded Hash type. */\nexport const HashZod = z.pipe(\n z.string().check(z.regex(HashRegEx, { error: 'Invalid hex format' })),\n z.transform((val: string) => val as BrandedHash),\n)\n\n/** A validated hash string type, inferred from the HashZod schema. */\nexport type Hash = z.infer<typeof HashZod>\n", "import * as z from 'zod/mini'\n\nimport { asHash } from './as.ts'\nimport type { Hash } from './hash.ts'\nimport { HashZod } from './hash.ts'\n\n/** Zod schema that transforms a Hash to a plain string for JSON serialization. */\nexport const HashToJsonZod = z.pipe(HashZod, z.transform((v: Hash): string => v))\n/** Zod schema that parses a JSON string into a validated Hash, throwing on invalid input. */\nexport const JsonToHashZod = z.pipe(z.string(), z.transform((v: string): Hash => asHash(v, true)))\n", "import { type Hex, hexFromHexString } from './hex/index.ts'\n\n/**\n * Converts a Hex string to a BigInt.\n * @param hex - The hex string to convert\n * @returns The BigInt representation of the hex value\n */\nexport function hexToBigInt(hex: Hex): bigint {\n return BigInt(hexFromHexString(hex, { prefix: true }))\n}\n", "import * as z from 'zod/mini'\n\nimport { toHex } from './hex/index.ts'\nimport { hexToBigInt } from './hexToBigInt.ts'\n\n/** Zod schema that transforms a non-negative BigInt into a hex string for JSON serialization. */\nexport const BigIntToJsonZod = z.pipe(\n z.bigint().check(z.nonnegative()),\n z.transform((x: bigint) => toHex(x)),\n)\n/** Zod schema that parses a JSON hex string into a BigInt. */\nexport const JsonToBigIntZod = z.pipe(\n z.string(),\n z.transform((x: string) => hexToBigInt(toHex(x))),\n)\n"], | ||
| "mappings": ";AACA,YAAY,OAAO;;;ACKZ,IAAM,iBAAiB,CAAC,WAAW,GAAG,WAAoB,OAAO,mBAAmB,MAAO;AAChG,SAAO,IAAI,OAAO,aAAa,WAAW,CAAC,IAAI,WAAW,CAAC,IAAI;AACjE;AAQO,IAAM,oCAAoC,CAAC,WAAW,GAAG,WAAoB,OAAO,mBAAmB,MAAO;AACnH,SAAO,IAAI,OAAO,kBAAkB,WAAW,CAAC,IAAI,WAAW,CAAC,IAAI;AACtE;AAGO,IAAM,WAAW;AAEjB,IAAM,qBAAqB;;;ADhB3B,IAAM,eAAe;AAErB,IAAM,iBAAiB;AAGvB,IAAM,eAAe,eAAe,iBAAiB,GAAG,iBAAiB,CAAC;AAK1E,IAAM,aAAe;AAAA,EACxB,SAAO,EAAE,MAAQ,QAAM,YAAY,CAAC;AAAA,EACpC,YAAU,CAAC,MAA8B,CAAmB;AAChE;;;AEpBA,YAAYA,QAAO;;;ACAnB,YAAYC,QAAO;;;AC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AAoB,OAAO,GAAG,IAAI,CAAC,CAAC;;;ACF1F,SAAS,YAAY,KAAkB;AAC5C,SAAO,OAAO,iBAAiB,KAAK,EAAE,QAAQ,KAAK,CAAC,CAAC;AACvD;;;ACTA,YAAYC,QAAO;AAMZ,IAAM,kBAAoB;AAAA,EAC7B,UAAO,EAAE,MAAQ,eAAY,CAAC;AAAA,EAC9B,aAAU,CAAC,MAAc,MAAM,CAAC,CAAC;AACrC;AAEO,IAAM,kBAAoB;AAAA,EAC7B,UAAO;AAAA,EACP,aAAU,CAAC,MAAc,YAAY,MAAM,CAAC,CAAC,CAAC;AAClD;", | ||
| "names": ["z", "z", "regex", "z", "assertError", "assertError", "assertError", "z", "assertError", "assertError", "assertError", "z", "z", "z"] | ||
| "sources": ["../../src/index.ts"], | ||
| "sourcesContent": ["export * from '@ariestools/sdk/hex'\n"], | ||
| "mappings": ";AAAA,cAAc;", | ||
| "names": [] | ||
| } |
@@ -1,3 +0,2 @@ | ||
| export type { EthAddress } from './ethAddress.ts'; | ||
| export type { BrandedHex, Hex, HexConfig, } from './hex/index.ts'; | ||
| export type * from '@ariestools/sdk/hex/model'; | ||
| //# sourceMappingURL=model.d.ts.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../src/model.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AACjD,YAAY,EACV,UAAU,EACV,GAAG,EACH,SAAS,GACV,MAAM,gBAAgB,CAAA"} | ||
| {"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../src/model.ts"],"names":[],"mappings":"AAAA,mBAAmB,2BAA2B,CAAA"} |
+16
-14
| { | ||
| "name": "@xylabs/hex", | ||
| "version": "7.0.2", | ||
| "description": "Base functionality used throughout XY Labs TypeScript/JavaScript libraries", | ||
| "version": "7.0.3", | ||
| "description": "DEPRECATED — use @ariestools/sdk/hex. Backward-compatibility re-export shim.", | ||
| "keywords": [ | ||
| "hex", | ||
| "xylabs", | ||
@@ -34,7 +33,7 @@ "utility", | ||
| }, | ||
| "./package.json": "./package.json", | ||
| "./model": { | ||
| "types": "./dist/neutral/model.d.ts", | ||
| "default": "./dist/neutral/model.mjs" | ||
| }, | ||
| "./package.json": "./package.json" | ||
| } | ||
| }, | ||
@@ -49,8 +48,10 @@ "files": [ | ||
| "dependencies": { | ||
| "@xylabs/error": "~7.0.2", | ||
| "@xylabs/typeof": "~7.0.2" | ||
| "@ariestools/sdk": "~7.0.3" | ||
| }, | ||
| "devDependencies": { | ||
| "@xylabs/toolchain": "^8.5.3", | ||
| "@xylabs/tsconfig": "^8.5.3", | ||
| "@opentelemetry/api": "^1.9.1", | ||
| "@opentelemetry/sdk-trace-base": "^2.8.0", | ||
| "@xylabs/toolchain": "^8.5.5", | ||
| "@xylabs/tsconfig": "^8.5.5", | ||
| "async-mutex": "^0.5.0", | ||
| "browserslist": "4.28.4", | ||
@@ -60,8 +61,8 @@ "eslint": "^10.6.0", | ||
| "typescript": "^6.0.3", | ||
| "vite": "^8.1.0", | ||
| "vitest": "^4.1.9", | ||
| "zod": "^4.4.3", | ||
| "@xylabs/vitest-extended": "~7.0.2" | ||
| "zod": "^4.4.3" | ||
| }, | ||
| "peerDependencies": { | ||
| "@opentelemetry/api": "^1.9", | ||
| "@opentelemetry/sdk-trace-base": "^2.7", | ||
| "async-mutex": "^0.5", | ||
| "zod": "^4.4" | ||
@@ -74,3 +75,4 @@ }, | ||
| "access": "public" | ||
| } | ||
| }, | ||
| "deprecated": "Use @ariestools/sdk/hex instead. @xylabs/hex is a compatibility shim only and will not receive further updates." | ||
| } |
+6
-4
@@ -0,1 +1,3 @@ | ||
| > **Deprecated.** Use [`@ariestools/sdk`](../../ariestools-sdk/README.md) instead. This package is a backward-compatibility re-export shim. | ||
| [![logo][]](https://xylabs.com) | ||
@@ -15,3 +17,3 @@ | ||
| ```sh | ||
| npm install {{name}} | ||
| npm install @xylabs/hex | ||
| ``` | ||
@@ -22,3 +24,3 @@ | ||
| ```sh | ||
| yarn add {{name}} | ||
| yarn add @xylabs/hex | ||
| ``` | ||
@@ -29,3 +31,3 @@ | ||
| ```sh | ||
| pnpm add {{name}} | ||
| pnpm add @xylabs/hex | ||
| ``` | ||
@@ -36,3 +38,3 @@ | ||
| ```sh | ||
| bun add {{name}} | ||
| bun add @xylabs/hex | ||
| ``` | ||
@@ -39,0 +41,0 @@ |
| import type { Brand } from '@xylabs/typeof'; | ||
| import * as z from 'zod/mini'; | ||
| import { type Hex } from '../hex/index.ts'; | ||
| /** A 160-bit zero address constant. */ | ||
| export declare const ZERO_ADDRESS: Address; | ||
| /** The character length of an address hex string (40 hex characters / 20 bytes). */ | ||
| export declare const ADDRESS_LENGTH: 40; | ||
| /** Regular expression matching a 20-byte (40 hex character) address string. */ | ||
| export declare const AddressRegEx: RegExp; | ||
| type BrandedAddress = Brand<Hex, { | ||
| readonly __address: true; | ||
| }>; | ||
| /** Zod schema that validates and transforms a string into a branded Address type. */ | ||
| export declare const AddressZod: z.ZodMiniPipe<z.ZodMiniString<string>, z.ZodMiniTransform<BrandedAddress, string>>; | ||
| /** A validated 20-byte address string type, inferred from the AddressZod schema. */ | ||
| export type Address = z.infer<typeof AddressZod>; | ||
| export {}; | ||
| //# sourceMappingURL=address.d.ts.map |
| {"version":3,"file":"address.d.ts","sourceRoot":"","sources":["../../../src/address/address.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAA;AAC3C,OAAO,KAAK,CAAC,MAAM,UAAU,CAAA;AAE7B,OAAO,EAAE,KAAK,GAAG,EAAE,MAAM,iBAAiB,CAAA;AAG1C,uCAAuC;AACvC,eAAO,MAAM,YAAY,EAAiD,OAAO,CAAA;AACjF,oFAAoF;AACpF,eAAO,MAAM,cAAc,EAAG,EAAW,CAAA;AAEzC,+EAA+E;AAC/E,eAAO,MAAM,YAAY,QAAyD,CAAA;AAElF,KAAK,cAAc,GAAG,KAAK,CAAC,GAAG,EAAE;IAAE,QAAQ,CAAC,SAAS,EAAE,IAAI,CAAA;CAAE,CAAC,CAAA;AAE9D,qFAAqF;AACrF,eAAO,MAAM,UAAU,oFAGtB,CAAA;AAED,oFAAoF;AACpF,MAAM,MAAM,OAAO,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,UAAU,CAAC,CAAA"} |
| import * as z from 'zod/mini'; | ||
| /** Zod schema that accepts a string, bigint, or number and transforms it into a validated Address. */ | ||
| export declare const AddressTransformZod: z.ZodMiniPipe<z.ZodMiniPipe<z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniBigInt<bigint>, z.ZodMiniNumber<number>]>, z.ZodMiniTransform<string, string | number | bigint>>, z.ZodMiniTransform<Lowercase<string> & { | ||
| readonly __hex: true; | ||
| } & { | ||
| readonly __address: true; | ||
| }, string>>; | ||
| /** The output type of AddressTransformZod after parsing and transformation. */ | ||
| export type AddressTransformZodType = z.infer<typeof AddressTransformZod>; | ||
| //# sourceMappingURL=AddressTransformZod.d.ts.map |
| {"version":3,"file":"AddressTransformZod.d.ts","sourceRoot":"","sources":["../../../src/address/AddressTransformZod.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,UAAU,CAAA;AAK7B,sGAAsG;AACtG,eAAO,MAAM,mBAAmB;;;;WAc/B,CAAA;AAED,+EAA+E;AAC/E,MAAM,MAAM,uBAAuB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAA"} |
| import * as z from 'zod/mini'; | ||
| /** Zod schema that validates a string is a properly formatted 40-character hex address. */ | ||
| export declare const AddressValidationZod: z.ZodMiniPipe<z.ZodMiniString<string>, z.ZodMiniTransform<Lowercase<string> & { | ||
| readonly __hex: true; | ||
| } & { | ||
| readonly __address: true; | ||
| }, string>>; | ||
| /** The output type of AddressValidationZod after parsing. */ | ||
| export type AddressValidationZodType = z.infer<typeof AddressValidationZod>; | ||
| //# sourceMappingURL=AddressValidationZod.d.ts.map |
| {"version":3,"file":"AddressValidationZod.d.ts","sourceRoot":"","sources":["../../../src/address/AddressValidationZod.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,UAAU,CAAA;AAM7B,2FAA2F;AAC3F,eAAO,MAAM,oBAAoB;;;;WAMhC,CAAA;AAED,6DAA6D;AAC7D,MAAM,MAAM,wBAAwB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAA"} |
| import type { AssertConfig } from '@xylabs/error'; | ||
| import type { Address } from './address.ts'; | ||
| /** | ||
| * Attempts to coerce a value into an Address type, returning undefined or throwing based on the assert config. | ||
| * @param value - The value to coerce (must be a string) | ||
| * @param assert - If provided, throws on failure instead of returning undefined | ||
| * @returns The value as Address, or undefined if coercion fails and assert is not set | ||
| */ | ||
| export declare function asAddress(value?: unknown): Address | undefined; | ||
| export declare function asAddress(value: unknown, assert: AssertConfig): Address; | ||
| /** @alpha */ | ||
| export declare function asAddressV2(value?: unknown, assert?: boolean): Address | undefined; | ||
| //# sourceMappingURL=as.d.ts.map |
| {"version":3,"file":"as.d.ts","sourceRoot":"","sources":["../../../src/address/as.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAKjD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAI3C;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,KAAK,CAAC,EAAE,OAAO,GAAG,OAAO,GAAG,SAAS,CAAA;AAC/D,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,YAAY,GAAG,OAAO,CAAA;AAqBxE,aAAa;AACb,wBAAgB,WAAW,CAAC,KAAK,CAAC,EAAE,OAAO,EAAE,MAAM,UAAQ,GAAG,OAAO,GAAG,SAAS,CAIhF"} |
| export * from './address.ts'; | ||
| export * from './AddressTransformZod.ts'; | ||
| export * from './AddressValidationZod.ts'; | ||
| export * from './as.ts'; | ||
| export * from './is.ts'; | ||
| export * from './to.ts'; | ||
| //# sourceMappingURL=index.d.ts.map |
| {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/address/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,0BAA0B,CAAA;AACxC,cAAc,2BAA2B,CAAA;AACzC,cAAc,SAAS,CAAA;AACvB,cAAc,SAAS,CAAA;AACvB,cAAc,SAAS,CAAA"} |
| import type { HexConfig } from '../hex/index.ts'; | ||
| import type { Address } from './address.ts'; | ||
| /** | ||
| * Type guard that checks whether a value is a valid 160-bit address. | ||
| * @param value - The value to check | ||
| * @param config - Optional hex config (defaults to 160-bit, no prefix) | ||
| * @returns True if the value is a valid Address | ||
| */ | ||
| export declare const isAddress: (value?: unknown, config?: HexConfig) => value is Address; | ||
| /** @alpha */ | ||
| export declare function isAddressV2(value?: unknown): value is Address; | ||
| //# sourceMappingURL=is.d.ts.map |
| {"version":3,"file":"is.d.ts","sourceRoot":"","sources":["../../../src/address/is.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAEhD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAG3C;;;;;GAKG;AACH,eAAO,MAAM,SAAS,GAAI,QAAQ,OAAO,EAAE,SAAQ,SAAc,KAAG,KAAK,IAAI,OAG5E,CAAA;AAED,aAAa;AACb,wBAAgB,WAAW,CAAC,KAAK,CAAC,EAAE,OAAO,GAAG,KAAK,IAAI,OAAO,CAE7D"} |
| import type { HexConfig } from '../hex/index.ts'; | ||
| import type { Address } from './address.ts'; | ||
| /** | ||
| * Converts a value to a 160-bit Address hex string. | ||
| * @param value - The value to convert (string, number, bigint, or ArrayBuffer) | ||
| * @param config - Optional hex config (defaults to 160-bit, no prefix) | ||
| * @returns The value as an Address | ||
| */ | ||
| export declare const toAddress: (value: string | number | bigint | ArrayBufferLike, config?: HexConfig) => Address; | ||
| /** @alpha */ | ||
| export declare function toAddressV2(value: unknown, assert?: boolean): Address | undefined; | ||
| //# sourceMappingURL=to.d.ts.map |
| {"version":3,"file":"to.d.ts","sourceRoot":"","sources":["../../../src/address/to.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAEhD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAG3C;;;;;GAKG;AACH,eAAO,MAAM,SAAS,GAAI,OAAO,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,eAAe,EAAE,SAAQ,SAAc,KAAG,OAKrG,CAAA;AAED,aAAa;AACb,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,UAAQ,GAAG,OAAO,GAAG,SAAS,CAI/E"} |
| import type { AssertConfig } from '@xylabs/error'; | ||
| import type { Brand } from '@xylabs/typeof'; | ||
| import * as z from 'zod/mini'; | ||
| import type { HexConfig } from './hex/index.ts'; | ||
| /** Regular expression matching a 20-byte Ethereum address with 0x prefix (mixed case). */ | ||
| export declare const EthAddressRegEx: RegExp; | ||
| /** Zod schema that validates a string is a properly formatted Ethereum address. */ | ||
| export declare const EthAddressToStringZod: z.ZodMiniString<string>; | ||
| /** @deprecated use EthAddressToStringZod */ | ||
| export declare const EthAddressToStringSchema: z.ZodMiniString<string>; | ||
| /** Zod schema that validates and transforms a string into an EthAddress type. */ | ||
| export declare const EthAddressFromStringZod: z.ZodMiniPipe<z.ZodMiniString<string>, z.ZodMiniTransform<EthAddress, string>>; | ||
| /** @deprecated use EthAddressFromStringZod */ | ||
| export declare const EthAddressFromStringSchema: z.ZodMiniPipe<z.ZodMiniString<string>, z.ZodMiniTransform<EthAddress, string>>; | ||
| /** Branded type representing a validated Ethereum address with 0x prefix. */ | ||
| export type EthAddress = Brand<string, { | ||
| readonly __eth_address: true; | ||
| }>; | ||
| /** The zero Ethereum address constant (0x followed by 40 zero characters). */ | ||
| export declare const ETH_ZERO_ADDRESS: EthAddress; | ||
| /** | ||
| * Converts a value to a 0x-prefixed Ethereum address string. | ||
| * @param value - The value to convert (string, number, bigint, or ArrayBuffer) | ||
| * @param config - Optional hex config (defaults to 160-bit, no inner prefix) | ||
| * @returns The value as an EthAddress | ||
| */ | ||
| export declare const toEthAddress: (value: string | number | bigint | ArrayBufferLike, config?: HexConfig) => EthAddress; | ||
| /** | ||
| * Type guard that checks whether a value is a valid 0x-prefixed Ethereum address. | ||
| * @param value - The value to check | ||
| * @param config - Optional hex config (defaults to 160-bit with prefix) | ||
| * @returns True if the value is a valid EthAddress | ||
| */ | ||
| export declare const isEthAddress: (value?: unknown, config?: HexConfig) => value is EthAddress; | ||
| /** Zod schema that validates a string as a properly formatted Ethereum address using regex and type guard. */ | ||
| export declare const EthAddressZod: z.ZodMiniString<string>; | ||
| /** | ||
| * Attempts to coerce a value into an EthAddress, returning undefined or throwing based on the assert config. | ||
| * @param value - The value to coerce (must be a string) | ||
| * @param assert - If provided, throws on failure instead of returning undefined | ||
| * @returns The value as EthAddress, or undefined if coercion fails and assert is not set | ||
| */ | ||
| export declare function asEthAddress(value: unknown): EthAddress | undefined; | ||
| export declare function asEthAddress(value: unknown, assert: AssertConfig): EthAddress; | ||
| //# sourceMappingURL=ethAddress.d.ts.map |
| {"version":3,"file":"ethAddress.d.ts","sourceRoot":"","sources":["../../src/ethAddress.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAEjD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAA;AAC3C,OAAO,KAAK,CAAC,MAAM,UAAU,CAAA;AAE7B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAM/C,0FAA0F;AAC1F,eAAO,MAAM,eAAe,QAA4C,CAAA;AAExE,mFAAmF;AACnF,eAAO,MAAM,qBAAqB,yBAA6C,CAAA;AAE/E,4CAA4C;AAC5C,eAAO,MAAM,wBAAwB,yBAAwB,CAAA;AAE7D,iFAAiF;AACjF,eAAO,MAAM,uBAAuB,gFAGnC,CAAA;AAED,8CAA8C;AAC9C,eAAO,MAAM,0BAA0B,gFAA0B,CAAA;AAEjE,6EAA6E;AAE7E,MAAM,MAAM,UAAU,GAAG,KAAK,CAAC,MAAM,EAAE;IAAE,QAAQ,CAAC,aAAa,EAAE,IAAI,CAAA;CAAE,CAAC,CAAA;AAExE,8EAA8E;AAC9E,eAAO,MAAM,gBAAgB,EAAmD,UAAU,CAAA;AAE1F;;;;;GAKG;AACH,eAAO,MAAM,YAAY,GAAI,OAAO,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,eAAe,EAAE,SAAQ,SAAc,KAAG,UAKxG,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,YAAY,GAAI,QAAQ,OAAO,EAAE,SAAQ,SAAc,KAAG,KAAK,IAAI,UAI/E,CAAA;AAED,8GAA8G;AAC9G,eAAO,MAAM,aAAa,yBAGzB,CAAA;AAED;;;;;GAKG;AACH,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"} |
| import type { AssertConfig } from '@xylabs/error'; | ||
| import { type Hash } from './hash.ts'; | ||
| /** | ||
| * Attempts to coerce a value into a Hash type, returning undefined or throwing based on the assert config. | ||
| * @param value - The value to coerce (must be a string) | ||
| * @param assert - If provided, throws on failure instead of returning undefined | ||
| * @returns The value as Hash, or undefined if coercion fails and assert is not set | ||
| */ | ||
| export declare function asHash(value: unknown): Hash | undefined; | ||
| export declare function asHash(value: unknown, assert: AssertConfig): Hash; | ||
| //# sourceMappingURL=as.d.ts.map |
| {"version":3,"file":"as.d.ts","sourceRoot":"","sources":["../../../src/hash/as.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAKjD,OAAO,EAAE,KAAK,IAAI,EAAE,MAAM,WAAW,CAAA;AAGrC;;;;;GAKG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,GAAG,SAAS,CAAA;AACxD,wBAAgB,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,YAAY,GAAG,IAAI,CAAA"} |
| import type { Brand } from '@xylabs/typeof'; | ||
| import * as z from 'zod/mini'; | ||
| import type { Hex } from '../hex/index.ts'; | ||
| /** The byte length of a standard hash (32 bytes / 256 bits). */ | ||
| export declare const HASH_LENGTH: 32; | ||
| /** Regular expression matching a 32-byte (64 hex character) hash string. */ | ||
| export declare const HashRegEx: RegExp; | ||
| /** A 256-bit zero hash constant. */ | ||
| export declare const ZERO_HASH: Hash; | ||
| /** Valid bit lengths for hash values. */ | ||
| export type HashBitLength = 32 | 64 | 128 | 256 | 512 | 1024 | 2048 | 4096; | ||
| /** Array of all valid hash bit lengths for runtime validation. */ | ||
| export declare const HashBitLength: HashBitLength[]; | ||
| /** | ||
| * Type guard that checks whether a value is a valid hash bit length. | ||
| * @param value - The value to check | ||
| * @returns True if the value is one of the supported HashBitLength values | ||
| */ | ||
| export declare const isHashBitLength: (value: unknown) => value is HashBitLength; | ||
| /** Branded type representing a validated hash hex string. */ | ||
| export type BrandedHash = Brand<Hex, { | ||
| readonly __hash: true; | ||
| }>; | ||
| /** Zod schema that validates and transforms a string into a branded Hash type. */ | ||
| export declare const HashZod: z.ZodMiniPipe<z.ZodMiniString<string>, z.ZodMiniTransform<BrandedHash, string>>; | ||
| /** A validated hash string type, inferred from the HashZod schema. */ | ||
| export type Hash = z.infer<typeof HashZod>; | ||
| //# sourceMappingURL=hash.d.ts.map |
| {"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../../../src/hash/hash.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAA;AAC3C,OAAO,KAAK,CAAC,MAAM,UAAU,CAAA;AAE7B,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAA;AAG1C,gEAAgE;AAChE,eAAO,MAAM,WAAW,EAAG,EAAW,CAAA;AAEtC,4EAA4E;AAC5E,eAAO,MAAM,SAAS,QAA2C,CAAA;AAEjE,oCAAoC;AACpC,eAAO,MAAM,SAAS,EAAyE,IAAI,CAAA;AAEnG,yCAAyC;AACzC,MAAM,MAAM,aAAa,GAAG,EAAE,GAAG,EAAE,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAA;AAC1E,kEAAkE;AAClE,eAAO,MAAM,aAAa,EAAE,aAAa,EAA8C,CAAA;AAEvF;;;;GAIG;AACH,eAAO,MAAM,eAAe,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,aAEzD,CAAA;AAED,6DAA6D;AAC7D,MAAM,MAAM,WAAW,GAAG,KAAK,CAAC,GAAG,EAAE;IAAE,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAA;CAAE,CAAC,CAAA;AAE/D,kFAAkF;AAClF,eAAO,MAAM,OAAO,iFAGnB,CAAA;AAED,sEAAsE;AACtE,MAAM,MAAM,IAAI,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,OAAO,CAAC,CAAA"} |
| export * from './as.ts'; | ||
| export * from './hash.ts'; | ||
| export * from './is.ts'; | ||
| export * from './zod.ts'; | ||
| //# sourceMappingURL=index.d.ts.map |
| {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hash/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAA;AACvB,cAAc,WAAW,CAAA;AACzB,cAAc,SAAS,CAAA;AACvB,cAAc,UAAU,CAAA"} |
| import type { Hash, HashBitLength } from './hash.ts'; | ||
| /** | ||
| * Type guard that checks whether a value is a valid hash of the specified bit length. | ||
| * @param value - The value to check | ||
| * @param bitLength - The expected bit length of the hash (defaults to 256) | ||
| * @returns True if the value is a valid Hash | ||
| */ | ||
| export declare const isHash: (value: unknown, bitLength?: HashBitLength) => value is Hash; | ||
| //# sourceMappingURL=is.d.ts.map |
| {"version":3,"file":"is.d.ts","sourceRoot":"","sources":["../../../src/hash/is.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AAEpD;;;;;GAKG;AACH,eAAO,MAAM,MAAM,GAAI,OAAO,OAAO,EAAE,YAAW,aAAmB,KAAG,KAAK,IAAI,IAEhF,CAAA"} |
| import * as z from 'zod/mini'; | ||
| /** Zod schema that transforms a Hash to a plain string for JSON serialization. */ | ||
| export declare const HashToJsonZod: z.ZodMiniPipe<z.ZodMiniPipe<z.ZodMiniString<string>, z.ZodMiniTransform<import("./hash.ts").BrandedHash, string>>, z.ZodMiniTransform<string, import("./hash.ts").BrandedHash>>; | ||
| /** Zod schema that parses a JSON string into a validated Hash, throwing on invalid input. */ | ||
| export declare const JsonToHashZod: z.ZodMiniPipe<z.ZodMiniString<string>, z.ZodMiniTransform<import("./hash.ts").BrandedHash, string>>; | ||
| //# sourceMappingURL=zod.d.ts.map |
| {"version":3,"file":"zod.d.ts","sourceRoot":"","sources":["../../../src/hash/zod.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,UAAU,CAAA;AAM7B,kFAAkF;AAClF,eAAO,MAAM,aAAa,iLAAuD,CAAA;AACjF,6FAA6F;AAC7F,eAAO,MAAM,aAAa,qGAAwE,CAAA"} |
| import type { AssertConfig } from '@xylabs/error'; | ||
| import type { Hex } from './hex.ts'; | ||
| /** | ||
| * Attempts to coerce a value into a Hex type, returning undefined or throwing based on the assert config. | ||
| * @param value - The value to coerce (must be a string) | ||
| * @param assert - If provided, throws on failure instead of returning undefined | ||
| * @returns The value as Hex, or undefined if coercion fails and assert is not set | ||
| */ | ||
| export declare function asHex(value: unknown): Hex | undefined; | ||
| export declare function asHex(value: unknown, assert: AssertConfig): Hex; | ||
| //# sourceMappingURL=as.d.ts.map |
| {"version":3,"file":"as.d.ts","sourceRoot":"","sources":["../../../src/hex/as.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAIjD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAGnC;;;;;GAKG;AACH,wBAAgB,KAAK,CAAC,KAAK,EAAE,OAAO,GAAG,GAAG,GAAG,SAAS,CAAA;AACtD,wBAAgB,KAAK,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,YAAY,GAAG,GAAG,CAAA"} |
| import type { Hex, HexConfig } from '../hex.ts'; | ||
| /** Takes unknown value and tries our best to convert it to a hex string */ | ||
| export declare const hexFrom: ( | ||
| /** Supported types are string, number, bigint, and ArrayBuffer */ | ||
| value: string | number | bigint | ArrayBufferLike, | ||
| /** Configuration of output format and validation */ | ||
| config?: HexConfig) => Hex; | ||
| //# sourceMappingURL=from.d.ts.map |
| {"version":3,"file":"from.d.ts","sourceRoot":"","sources":["../../../../src/hex/from/from.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAM/C,2EAA2E;AAC3E,eAAO,MAAM,OAAO;AAClB,kEAAkE;AAClE,OAAO,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,eAAe;AACjD,oDAAoD;AACpD,SAAS,SAAS,KACjB,GAkBF,CAAA"} |
| import type { Hex, HexConfig } from '../hex.ts'; | ||
| /** Convert an ArrayBuffer to a hex string */ | ||
| export declare const hexFromArrayBuffer: ( | ||
| /** The buffer to be converted */ | ||
| buffer: ArrayBufferLike, | ||
| /** Configuration of output format and validation */ | ||
| config?: HexConfig) => Hex; | ||
| //# sourceMappingURL=fromArrayBuffer.d.ts.map |
| {"version":3,"file":"fromArrayBuffer.d.ts","sourceRoot":"","sources":["../../../../src/hex/from/fromArrayBuffer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAG/C,6CAA6C;AAC7C,eAAO,MAAM,kBAAkB;AAC7B,iCAAiC;AACjC,QAAQ,eAAe;AACvB,oDAAoD;AACpD,SAAS,SAAS,KACjB,GAGF,CAAA"} |
| import type { Hex, HexConfig } from '../hex.ts'; | ||
| /** Convert a bigint to a hex string */ | ||
| export declare const hexFromBigInt: ( | ||
| /** The bigint to be converted */ | ||
| value: bigint, | ||
| /** Configuration of output format and validation */ | ||
| config?: HexConfig) => Hex; | ||
| //# sourceMappingURL=fromBigInt.d.ts.map |
| {"version":3,"file":"fromBigInt.d.ts","sourceRoot":"","sources":["../../../../src/hex/from/fromBigInt.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAG/C,uCAAuC;AACvC,eAAO,MAAM,aAAa;AACxB,iCAAiC;AACjC,OAAO,MAAM;AACb,oDAAoD;AACpD,SAAQ,SAAc,KACrB,GAGF,CAAA"} |
| import type { Hex, HexConfig } from '../hex.ts'; | ||
| /** | ||
| * Normalizes a hex string by stripping an optional 0x prefix, lowercasing, and padding to byte/bit boundaries. | ||
| * @param value - The hex string to normalize (with or without 0x prefix) | ||
| * @param config - Configuration for prefix, byteSize, and bitLength padding | ||
| * @returns The normalized Hex string | ||
| */ | ||
| export declare const hexFromHexString: (value: string, config?: HexConfig) => Hex; | ||
| //# sourceMappingURL=fromHexString.d.ts.map |
| {"version":3,"file":"fromHexString.d.ts","sourceRoot":"","sources":["../../../../src/hex/from/fromHexString.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAI/C;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,GAAI,OAAO,MAAM,EAAE,SAAQ,SAAc,KAAG,GAYxE,CAAA"} |
| import type { Hex, HexConfig } from '../hex.ts'; | ||
| /** | ||
| * Converts a number to a hex string by converting to BigInt first. | ||
| * @param value - The number to convert | ||
| * @param config - Optional hex output configuration | ||
| * @returns The hex string representation | ||
| */ | ||
| export declare const hexFromNumber: (value: number, config?: HexConfig) => Hex; | ||
| //# sourceMappingURL=fromNumber.d.ts.map |
| {"version":3,"file":"fromNumber.d.ts","sourceRoot":"","sources":["../../../../src/hex/from/fromNumber.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAG/C;;;;;GAKG;AACH,eAAO,MAAM,aAAa,GAAI,OAAO,MAAM,EAAE,SAAS,SAAS,KAAG,GAEjE,CAAA"} |
| export * from './from.ts'; | ||
| export * from './fromArrayBuffer.ts'; | ||
| export * from './fromBigInt.ts'; | ||
| export * from './fromHexString.ts'; | ||
| export * from './fromNumber.ts'; | ||
| //# sourceMappingURL=index.d.ts.map |
| {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/hex/from/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,sBAAsB,CAAA;AACpC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,oBAAoB,CAAA;AAClC,cAAc,iBAAiB,CAAA"} |
| import type { Brand } from '@xylabs/typeof'; | ||
| import * as z from 'zod/mini'; | ||
| /** Branded type representing a validated lowercase hex string. */ | ||
| export type BrandedHex = Brand<Lowercase<string>, { | ||
| readonly __hex: true; | ||
| }>; | ||
| /** Zod schema that validates and transforms a string into a branded Hex type. */ | ||
| export declare const HexZod: z.ZodMiniPipe<z.ZodMiniString<string>, z.ZodMiniTransform<BrandedHex, string>>; | ||
| /** Configuration of validation and output format */ | ||
| export interface HexConfig { | ||
| bitLength?: number; | ||
| byteSize?: number; | ||
| prefix?: boolean; | ||
| } | ||
| /** A validated hex string type, inferred from the HexZod schema. */ | ||
| export type Hex = z.infer<typeof HexZod>; | ||
| //# sourceMappingURL=hex.d.ts.map |
| {"version":3,"file":"hex.d.ts","sourceRoot":"","sources":["../../../src/hex/hex.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAA;AAC3C,OAAO,KAAK,CAAC,MAAM,UAAU,CAAA;AAI7B,kEAAkE;AAClE,MAAM,MAAM,UAAU,GAAG,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE;IAAE,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAA;CAAE,CAAC,CAAA;AAE3E,iFAAiF;AACjF,eAAO,MAAM,MAAM,gFAGlB,CAAA;AAED,oDAAoD;AACpD,MAAM,WAAW,SAAS;IACxB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,MAAM,CAAC,EAAE,OAAO,CAAA;CACjB;AAED,oEAAoE;AACpE,MAAM,MAAM,GAAG,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,MAAM,CAAC,CAAA"} |
| export * from './as.ts'; | ||
| export * from './from/index.ts'; | ||
| export * from './hex.ts'; | ||
| export * from './is.ts'; | ||
| export * from './isHexZero.ts'; | ||
| export * from './legacy.ts'; | ||
| export * from './nibble.ts'; | ||
| export * from './to.ts'; | ||
| //# sourceMappingURL=index.d.ts.map |
| {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hex/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAA;AACvB,cAAc,iBAAiB,CAAA;AAC/B,cAAc,UAAU,CAAA;AACxB,cAAc,SAAS,CAAA;AACvB,cAAc,gBAAgB,CAAA;AAC9B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,SAAS,CAAA"} |
| import type { Hex, HexConfig } from './hex.ts'; | ||
| /** | ||
| * Type guard that checks whether a value is a valid hex string. | ||
| * @param value - The value to check | ||
| * @param config - Optional configuration for prefix and bit length validation | ||
| * @returns True if the value is a valid Hex string | ||
| */ | ||
| export declare const isHex: (value: unknown, config?: HexConfig) => value is Hex; | ||
| //# sourceMappingURL=is.d.ts.map |
| {"version":3,"file":"is.d.ts","sourceRoot":"","sources":["../../../src/hex/is.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAG9C;;;;;GAKG;AACH,eAAO,MAAM,KAAK,GAAI,OAAO,OAAO,EAAE,SAAS,SAAS,KAAG,KAAK,IAAI,GAYnE,CAAA"} |
| /** | ||
| * Checks whether a hex string represents a zero value. | ||
| * @param value - The hex string to check | ||
| * @returns True if zero, false if non-zero, or undefined if the input is not a string | ||
| */ | ||
| export declare const isHexZero: (value?: string) => boolean | undefined; | ||
| //# sourceMappingURL=isHexZero.d.ts.map |
| {"version":3,"file":"isHexZero.d.ts","sourceRoot":"","sources":["../../../src/hex/isHexZero.ts"],"names":[],"mappings":"AAIA;;;;GAIG;AACH,eAAO,MAAM,SAAS,GAAI,QAAQ,MAAM,wBAEvC,CAAA"} |
| /** | ||
| * Converts an ArrayBuffer to a hex string without padding or normalization. | ||
| * @param buffer - The ArrayBuffer to convert | ||
| * @returns A lowercase hex string representation of the buffer | ||
| */ | ||
| export declare const toHexLegacy: (buffer: ArrayBuffer) => string; | ||
| //# sourceMappingURL=legacy.d.ts.map |
| {"version":3,"file":"legacy.d.ts","sourceRoot":"","sources":["../../../src/hex/legacy.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,eAAO,MAAM,WAAW,GAAI,QAAQ,WAAW,WAE9C,CAAA"} |
| /** | ||
| * Converts a bit count to the equivalent number of hex nibbles (4 bits each). | ||
| * @param value - The number of bits (must be a multiple of 4) | ||
| * @returns The number of nibbles | ||
| */ | ||
| export declare const bitsToNibbles: (value: number) => number; | ||
| /** | ||
| * Converts a nibble count to the equivalent number of bits. | ||
| * @param value - The number of nibbles | ||
| * @returns The number of bits | ||
| */ | ||
| export declare const nibblesToBits: (value: number) => number; | ||
| //# sourceMappingURL=nibble.d.ts.map |
| {"version":3,"file":"nibble.d.ts","sourceRoot":"","sources":["../../../src/hex/nibble.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,eAAO,MAAM,aAAa,GAAI,OAAO,MAAM,KAAG,MAI7C,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,aAAa,GAAI,OAAO,MAAM,KAAG,MAE7C,CAAA"} |
| import type { HexConfig } from './hex.ts'; | ||
| /** takes any value and tries our best to convert it to a hex string */ | ||
| export declare const toHex: ( | ||
| /** Supported types are string, number, bigint, and ArrayBuffer */ | ||
| value: string | number | bigint | ArrayBufferLike, | ||
| /** Configuration of output format and validation */ | ||
| config?: HexConfig) => import("./hex.ts").BrandedHex; | ||
| //# sourceMappingURL=to.d.ts.map |
| {"version":3,"file":"to.d.ts","sourceRoot":"","sources":["../../../src/hex/to.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAEzC,uEAAuE;AACvE,eAAO,MAAM,KAAK;AAChB,kEAAkE;AAClE,OAAO,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,eAAe;AACjD,oDAAoD;AACpD,SAAQ,SAAc,kCAIvB,CAAA"} |
| /** | ||
| * Creates a RegExp matching lowercase hex strings with a byte length in the given range. | ||
| * @param minBytes - Minimum number of bytes (default 0) | ||
| * @param maxBytes - Maximum number of bytes | ||
| * @returns A RegExp for validating hex strings within the byte range | ||
| */ | ||
| export declare const HexRegExMinMax: (minBytes?: number, maxBytes?: number) => RegExp; | ||
| /** | ||
| * Creates a RegExp matching mixed-case hex strings with a 0x prefix and a byte length in the given range. | ||
| * @param minBytes - Minimum number of bytes (default 0) | ||
| * @param maxBytes - Maximum number of bytes | ||
| * @returns A RegExp for validating prefixed hex strings within the byte range | ||
| */ | ||
| export declare const HexRegExMinMaxMixedCaseWithPrefix: (minBytes?: number, maxBytes?: number) => RegExp; | ||
| /** Regular expression matching a lowercase hex string without prefix. */ | ||
| export declare const HexRegEx: RegExp; | ||
| /** Regular expression matching a lowercase hex string with a 0x prefix. */ | ||
| export declare const HexRegExWithPrefix: RegExp; | ||
| //# sourceMappingURL=HexRegEx.d.ts.map |
| {"version":3,"file":"HexRegEx.d.ts","sourceRoot":"","sources":["../../src/HexRegEx.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,eAAO,MAAM,cAAc,GAAI,iBAAY,EAAE,WAAU,MAAsC,WAE5F,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,iCAAiC,GAAI,iBAAY,EAAE,WAAU,MAAsC,WAE/G,CAAA;AAED,yEAAyE;AACzE,eAAO,MAAM,QAAQ,QAAgB,CAAA;AACrC,2EAA2E;AAC3E,eAAO,MAAM,kBAAkB,QAAkB,CAAA"} |
| import { type Hex } from './hex/index.ts'; | ||
| /** | ||
| * Converts a Hex string to a BigInt. | ||
| * @param hex - The hex string to convert | ||
| * @returns The BigInt representation of the hex value | ||
| */ | ||
| export declare function hexToBigInt(hex: Hex): bigint; | ||
| //# sourceMappingURL=hexToBigInt.d.ts.map |
| {"version":3,"file":"hexToBigInt.d.ts","sourceRoot":"","sources":["../../src/hexToBigInt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,GAAG,EAAoB,MAAM,gBAAgB,CAAA;AAE3D;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,GAAG,GAAG,MAAM,CAE5C"} |
| import * as z from 'zod/mini'; | ||
| /** Zod schema that transforms a non-negative BigInt into a hex string for JSON serialization. */ | ||
| export declare const BigIntToJsonZod: z.ZodMiniPipe<z.ZodMiniBigInt<bigint>, z.ZodMiniTransform<import("./hex/hex.ts").BrandedHex, bigint>>; | ||
| /** Zod schema that parses a JSON hex string into a BigInt. */ | ||
| export declare const JsonToBigIntZod: z.ZodMiniPipe<z.ZodMiniString<string>, z.ZodMiniTransform<bigint, string>>; | ||
| //# sourceMappingURL=zod.d.ts.map |
| {"version":3,"file":"zod.d.ts","sourceRoot":"","sources":["../../src/zod.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,UAAU,CAAA;AAK7B,iGAAiG;AACjG,eAAO,MAAM,eAAe,uGAG3B,CAAA;AACD,8DAA8D;AAC9D,eAAO,MAAM,eAAe,4EAG3B,CAAA"} |
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
1412
0.14%33323
-68.27%5
66.67%11
-84.51%6
-99.11%1
Infinity%2
Infinity%+ Added
- Removed
- Removed
- Removed
- Removed