import { type AssertSizeErrorType } from '../data/assertSize.js'; import { type IsBytesErrorType } from '../data/isBytes.js'; import { type IsHexErrorType } from '../data/isHex.js'; import { type PadErrorType } from '../data/pad.js'; import type { ErrorType } from '../errors/utils.js'; import type { Bytes, Hex } from '../types/data.js'; import { type NumberToHexErrorType, type NumberToHexOpts } from './toHex.js'; export type ToBytesParameters = { /** Size of the output bytes. */ size?: number | undefined; }; export type ToBytesErrorType = IsBytesErrorType | NumberToBytesErrorType | BoolToBytesErrorType | HexToBytesErrorType | StringToBytesErrorType | IsHexErrorType | ErrorType; /** * Encodes a value to a byte array. * * - Docs: https://viem.sh/docs/utilities/toBytes * - Example: https://viem.sh/docs/utilities/toBytes#usage * * @param value Value to encode. * @param opts Options. * @returns Byte array value. * * @example * import { toBytes } from 'viem' * const data = toBytes('Hello world') * // Uint8Array([72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 33]) * * @example * import { Encoding } from 'viem' * const data = Encoding.toBytes(420) * // Uint8Array([1, 164]) * * @example * import { Encoding } from 'viem' * const data = Encoding.toBytes(420, { size: 4 }) * // Uint8Array([0, 0, 1, 164]) */ export declare function toBytes(value: string | bigint | number | boolean | Hex | Bytes, opts?: ToBytesParameters): Bytes; export type BoolToBytesOpts = { /** Size of the output bytes. */ size?: number | undefined; }; export type BoolToBytesErrorType = AssertSizeErrorType | PadErrorType | ErrorType; /** * Encodes a boolean into a byte array. * * - Docs: https://viem.sh/docs/utilities/toBytes#booltobytes * * @param value Boolean value to encode. * @param opts Options. * @returns Byte array value. * * @example * import { Encoding } from 'viem' * const data = Encoding.boolToBytes(true) * // Uint8Array([1]) * * @example * import { Encoding } from 'viem' * const data = Encoding.boolToBytes(true, { size: 32 }) * // Uint8Array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]) */ export declare function boolToBytes(value: boolean, opts?: BoolToBytesOpts): Uint8Array; export type HexToBytesOpts = { /** Size of the output bytes. */ size?: number | undefined; }; export type HexToBytesErrorType = AssertSizeErrorType | PadErrorType | ErrorType; /** * Encodes a hex string into a byte array. * * - Docs: https://viem.sh/docs/utilities/toBytes#hextobytes * * @param hex Hex string to encode. * @param opts Options. * @returns Byte array value. * * @example * import { Encoding } from 'viem' * const data = Encoding.hexToBytes('0x48656c6c6f20776f726c6421') * // Uint8Array([72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 33]) * * @example * import { Encoding } from 'viem' * const data = Encoding.hexToBytes('0x48656c6c6f20776f726c6421', { size: 32 }) * // Uint8Array([72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 33, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) */ export declare function hexToBytes(hex_: Hex, opts?: HexToBytesOpts): Bytes; export type NumberToBytesErrorType = NumberToHexErrorType | HexToBytesErrorType | ErrorType; /** * Encodes a number into a byte array. * * - Docs: https://viem.sh/docs/utilities/toBytes#numbertobytes * * @param value Number to encode. * @param opts Options. * @returns Byte array value. * * @example * import { Encoding } from 'viem' * const data = Encoding.numberToBytes(420) * // Uint8Array([1, 164]) * * @example * import { Encoding } from 'viem' * const data = Encoding.numberToBytes(420, { size: 4 }) * // Uint8Array([0, 0, 1, 164]) */ export declare function numberToBytes(value: bigint | number, opts?: NumberToHexOpts | undefined): Uint8Array; export type StringToBytesOpts = { /** Size of the output bytes. */ size?: number | undefined; }; export type StringToBytesErrorType = AssertSizeErrorType | PadErrorType | ErrorType; /** * Encodes a UTF-8 string into a byte array. * * - Docs: https://viem.sh/docs/utilities/toBytes#stringtobytes * * @param value String to encode. * @param opts Options. * @returns Byte array value. * * @example * import { Encoding } from 'viem' * const data = Encoding.stringToBytes('Hello world!') * // Uint8Array([72, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100, 33]) * * @example * import { Encoding } from 'viem' * const data = Encoding.stringToBytes('Hello world!', { size: 32 }) * // Uint8Array([72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 33, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) */ export declare function stringToBytes(value: string, opts?: StringToBytesOpts): Bytes; //# sourceMappingURL=toBytes.d.ts.map