import { Schema } from 'effect'; import { Hex } from 'viem'; /** Schema for a `0x`-prefixed hex string. */ export declare const HexString: Schema.TemplateLiteral<`0x${string}`>; /** A `0x`-prefixed hex-encoded string (e.g. `"0xdeadbeef"`). */ export type HexString = typeof HexString.Type; /** A value that can represent raw bytes — either a hex string or a `Uint8Array`. */ export type BytesIsh = string | Uint8Array; /** * Converts a `Uint8Array` to a `bigint`. Returns `0n` for empty arrays. * @param byteArray - The byte array to convert. * @returns The unsigned big-endian integer representation of the bytes. */ export declare function bytesToBigInt(byteArray: Uint8Array): bigint; /** * Converts a `Buffer` to a `bigint`. * @param buffer - The buffer to convert. * @returns The unsigned big-endian integer representation of the buffer. */ export declare function bufferToBigInt(buffer: Buffer): bigint; /** * Converts a `bigint` to a 32-byte `Buffer`, zero-padded on the left. * @param value - The bigint to convert. * @returns A 32-byte big-endian buffer. * @throws If the bigint is negative or too large to fit in 32 bytes. */ export declare function bigintToBytes(value: bigint): Buffer; /** * Converts a `bigint` to a {@link Bytes32} hex string, left-padded to 32 bytes. * @param value - The bigint to convert. * @returns A `Bytes32` hex string. * @throws If the bigint is negative or too large to fit in 32 bytes. */ export declare function bigintToBytes32(value: bigint): Bytes32; /** * Left-pads a byte array with zeros to the specified length. * @param bs - The byte array to pad. * @param n - The desired total length in bytes. * @returns A new `Buffer` of length `n` with `bs` right-aligned. * @throws If `bs` is longer than `n` (would require truncation). */ export declare function padLeft(bs: Uint8Array, n: number): Buffer; /** * Parses a {@link BytesIsh} value as a 32-byte value and converts it to a `bigint`. * @param bs - A hex string or `Uint8Array` representing exactly 32 bytes. * @returns The `bigint` representation of the 32-byte value. * @throws If the input is not exactly 32 bytes. */ export declare function bytes32ToBigint(bs: BytesIsh): bigint; /** * Decodes a hex string into a `Buffer`. Handles both `0x`-prefixed and bare hex strings. * @param hexString - The hex string to decode. * @returns A `Buffer` containing the decoded bytes. */ export declare function bytesFromHexString(hexString: string): Buffer; /** * Asserts that a string is a valid `0x`-prefixed hex string and narrows its type to `Hex`. * @param value - The string to validate. * @returns The input typed as `Hex`. * @throws If `value` is not a valid hex string. */ export declare function mustBeHex(value: string): Hex; /** * Normalises a string to a `0x`-prefixed `Hex` value, adding the prefix if missing. * @param value - A hex string, with or without a `0x` prefix. * @returns The `0x`-prefixed `Hex` string. * @throws If the resulting string is not valid hex. */ export declare function normaliseToHex(value: string): Hex; /** * Encodes a `Uint8Array` as a `0x`-prefixed hex string. * @param bs - The byte array to encode. * @returns A `Hex` string representation of the bytes. */ export declare function bytesToHex(bs: Uint8Array): Hex; /** Schema for a 32-byte (66-character with `0x` prefix) hex string, branded as `Bytes32`. Accepts both hex strings and `Uint8Array` inputs. */ export declare const Bytes32: Schema.brand, Schema.Schema>]>, Schema.TemplateLiteral<`0x${string}`>, never>>, "Bytes32">; /** * Parses and validates a {@link BytesIsh} value as a {@link Bytes32}. * @param x - A hex string or `Uint8Array` to parse. * @returns A validated `Bytes32` value. * @throws If the input is not exactly 32 bytes. */ export declare function asBytes32(x: BytesIsh): Bytes32; /** A branded 32-byte hex string type (`0x` + 64 hex characters). */ export type Bytes32 = typeof Bytes32.Type; /** A branded 20-byte Ethereum address type (`0x` + 40 hex characters). */ export type Address = typeof Address.Type; /** Schema for a 20-byte `0x`-prefixed Ethereum address, branded as `Address`. */ export declare const Address: Schema.brand>, "Address">; /** * Parses and validates a string as an Ethereum {@link Address} (20-byte, `0x`-prefixed). * @param address - The string to parse. * @returns A validated `Address` value. * @throws If the input is not a valid 20-byte hex address. */ export declare function parseAddress(address: string): Address; /** * Parses and validates a string as a {@link HexString} (`0x`-prefixed). * @param hex - The string to parse. * @returns A validated `HexString` value. * @throws If the input is not a valid `0x`-prefixed hex string. */ export declare function parseHex(hex: string): HexString;