UNPKG

@xylabs/hex

Version:

Base functionality used throughout XY Labs TypeScript/JavaScript libraries

45 lines 2.71 kB
import type { AssertConfig } from '@xylabs/error'; import type { Brand } from '@xylabs/typeof'; import * as z from 'zod'; 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.ZodString; /** @deprecated use EthAddressToStringZod */ export declare const EthAddressToStringSchema: z.ZodString; /** Zod schema that validates and transforms a string into an EthAddress type. */ export declare const EthAddressFromStringZod: z.ZodPipe<z.ZodString, z.ZodTransform<EthAddress, string>>; /** @deprecated use EthAddressFromStringZod */ export declare const EthAddressFromStringSchema: z.ZodPipe<z.ZodString, z.ZodTransform<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.ZodString & z.ZodType<EthAddress, string, z.core.$ZodTypeInternals<EthAddress, 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