import * as Bytes from './Bytes.js'; import * as Errors from './Errors.js'; import * as Hex from './Hex.js'; import * as Cursor from './internal/cursor.js'; import type { ExactPartial, RecursiveArray } from './internal/types.js'; /** * Decodes a Recursive-Length Prefix (RLP) value into a {@link ox#Bytes.Bytes} value. * * @example * ```ts twoslash * import { Rlp } from 'ox' * Rlp.toBytes('0x8b68656c6c6f20776f726c64') * // Uint8Array([139, 104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100]) * ``` * * @param value - The value to decode. * @returns The decoded {@link ox#Bytes.Bytes} value. */ export declare function toBytes(value: Bytes.Bytes | Hex.Hex): RecursiveArray; export declare namespace toBytes { type ErrorType = to.ErrorType; } /** * Decodes a Recursive-Length Prefix (RLP) value into a {@link ox#Hex.Hex} value. * * @example * ```ts twoslash * import { Rlp } from 'ox' * Rlp.toHex('0x8b68656c6c6f20776f726c64') * // 0x68656c6c6f20776f726c64 * ``` * * @param value - The value to decode. * @returns The decoded {@link ox#Hex.Hex} value. */ export declare function toHex(value: Bytes.Bytes | Hex.Hex): RecursiveArray; export declare namespace toHex { type ErrorType = to.ErrorType; } /** @internal */ export declare function to(value: value, to: to | 'Hex' | 'Bytes'): to.ReturnType; /** @internal */ export declare namespace to { type ReturnType = (to extends 'Bytes' ? RecursiveArray : never) | (to extends 'Hex' ? RecursiveArray : never); type ErrorType = Bytes.fromHex.ErrorType | decodeRlpCursor.ErrorType | Cursor.create.ErrorType | Hex.InvalidLengthError | TrailingBytesError | Errors.GlobalErrorType; } /** @internal */ /** @internal */ export declare function decodeRlpCursor(cursor: Cursor.Cursor, to?: to | 'Hex' | 'Bytes' | undefined, depth?: number): decodeRlpCursor.ReturnType; /** @internal */ export declare namespace decodeRlpCursor { type ReturnType = to.ReturnType; type ErrorType = Hex.fromBytes.ErrorType | readLength.ErrorType | readList.ErrorType | DepthLimitExceededError | Errors.GlobalErrorType; } /** @internal */ export declare function readLength(cursor: Cursor.Cursor, prefix: number, offset: number): number; /** @internal */ export declare namespace readLength { type ErrorType = Errors.BaseError | Errors.GlobalErrorType; } /** @internal */ export declare function readList(cursor: Cursor.Cursor, length: number, to: to | 'Hex' | 'Bytes', depth?: number): decodeRlpCursor.ReturnType[]; /** @internal */ export declare namespace readList { type ErrorType = DepthLimitExceededError | ListBoundaryExceededError | Errors.GlobalErrorType; } /** * Encodes a value as Recursive-Length Prefix (RLP) and writes the encoded bytes * through a synchronous callback without allocating the complete encoding. * * Ox validates the complete input before the first write. If the callback * throws, the error propagates and earlier callback side effects remain. * * Ox does not mutate a chunk after the callback returns. A chunk may alias a * byte-array leaf from the encoded value. The callback must not mutate the * chunk before `encodeTo` returns. * * @example * ```ts twoslash * import { Bytes, Rlp } from 'ox' * * const chunks: Uint8Array[] = [] * Rlp.encodeTo(['0x01', '0x0203'], (chunk) => { * chunks.push(chunk) * }) * * const encoded = Bytes.concat(...chunks) * // @log: Uint8Array([196, 1, 130, 2, 3]) * ``` * * @param value - The bytes or Hex value, or nested list of values, to encode. * @param write - The synchronous callback for encoded chunks. * @returns Nothing. */ export declare function encodeTo(value: RecursiveArray | RecursiveArray, write: (chunk: Bytes.Bytes) => undefined): void; export declare namespace encodeTo { type ErrorType = Errors.BaseError | Errors.GlobalErrorType; } /** * Encodes a {@link ox#Bytes.Bytes} or {@link ox#Hex.Hex} value into a Recursive-Length Prefix (RLP) value. * * @example * ```ts twoslash * import { Bytes, Rlp } from 'ox' * * Rlp.from('0x68656c6c6f20776f726c64', { as: 'Hex' }) * // @log: 0x8b68656c6c6f20776f726c64 * * Rlp.from( * Bytes.from([ * 139, 104, 101, 108, 108, 111, 32, 119, 111, 114, 108, * 100 * ]), * { as: 'Bytes' } * ) * // @log: Uint8Array([104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100]) * ``` * * @param value - The {@link ox#Bytes.Bytes} or {@link ox#Hex.Hex} value to encode. * @param options - Options. * @returns The RLP value. */ export declare function from(value: RecursiveArray | RecursiveArray, options: from.Options): from.ReturnType; export declare namespace from { type Options = { /** The type to convert the RLP value to. */ as: as | 'Hex' | 'Bytes'; }; type ReturnType = (as extends 'Bytes' ? Bytes.Bytes : never) | (as extends 'Hex' ? Hex.Hex : never); type ErrorType = Cursor.create.ErrorType | Hex.fromBytes.ErrorType | Bytes.fromHex.ErrorType | Errors.GlobalErrorType; } /** * Encodes a {@link ox#Bytes.Bytes} value into a Recursive-Length Prefix (RLP) value. * * @example * ```ts twoslash * import { Bytes, Rlp } from 'ox' * * Rlp.fromBytes( * Bytes.from([ * 139, 104, 101, 108, 108, 111, 32, 119, 111, 114, 108, * 100 * ]) * ) * // @log: Uint8Array([104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100]) * ``` * * @param bytes - The {@link ox#Bytes.Bytes} value to encode. * @param options - Options. * @returns The RLP value. */ export declare function fromBytes(bytes: RecursiveArray, options?: fromBytes.Options): fromBytes.ReturnType; export declare namespace fromBytes { type Options = ExactPartial>; type ReturnType = from.ReturnType; type ErrorType = from.ErrorType | Errors.GlobalErrorType; } /** * Encodes a {@link ox#Hex.Hex} value into a Recursive-Length Prefix (RLP) value. * * @example * ```ts twoslash * import { Rlp } from 'ox' * * Rlp.fromHex('0x68656c6c6f20776f726c64') * // @log: 0x8b68656c6c6f20776f726c64 * ``` * * @param hex - The {@link ox#Hex.Hex} value to encode. * @param options - Options. * @returns The RLP value. */ export declare function fromHex(hex: RecursiveArray, options?: fromHex.Options): fromHex.ReturnType; export declare namespace fromHex { type Options = ExactPartial>; type ReturnType = from.ReturnType; type ErrorType = from.ErrorType | Errors.GlobalErrorType; } /** Thrown when an RLP value nests deeper than the decode depth limit. */ export declare class DepthLimitExceededError extends Errors.BaseError { readonly name = "Rlp.DepthLimitExceededError"; constructor({ limit }: { limit: number; }); } /** Thrown when RLP list items overrun the list's declared length. */ export declare class ListBoundaryExceededError extends Errors.BaseError { readonly name = "Rlp.ListBoundaryExceededError"; constructor({ consumed, declared }: { consumed: number; declared: number; }); } /** Thrown when an RLP payload contains bytes after the decoded item. */ export declare class TrailingBytesError extends Errors.BaseError { readonly name = "Rlp.TrailingBytesError"; constructor({ count }: { count: number; }); } //# sourceMappingURL=Rlp.d.ts.map