UNPKG

ox

Version:

Ethereum Standard Library

103 lines 3.96 kB
import type * as Bytes from '../Bytes.js'; import * as Hex from '../Hex.js'; import type { RecursiveArray } from './types.js'; /** * Encodes a transaction quantity (`bigint` or `number`) as an RLP scalar Hex. * Returns `'0x'` (RLP empty bytes) for `undefined`, `null`, or zero values. * * Replaces the per-envelope `value ? Hex.fromNumber(value) : '0x'` pattern. * * @internal */ export declare function quantityToHex(value: bigint | number | undefined | null): Hex.Hex; /** * Decodes an RLP-decoded scalar `Hex` into `bigint`, returning `undefined` * when the field was absent (`undefined`) or the empty RLP scalar (`'0x'`). * * Replaces the per-envelope * `Hex.validate(x) && x !== '0x' ? BigInt(x) : undefined` pattern. The * `Hex.validate` check is redundant for RLP-decoded fields (always a hex * string when present). * * @internal */ export declare function hexToBigIntOrUndefined(value: Hex.Hex | undefined): bigint | undefined; /** * Decodes an RLP-decoded scalar `Hex` into `bigint`, defaulting to `0n` when * the field was absent or the empty RLP scalar. * * Replaces the per-envelope * `Hex.validate(x) ? (x === '0x' ? 0n : BigInt(x)) : undefined` pattern used * for `nonce`-like fields where zero is meaningful. * * @internal */ export declare function hexToBigIntOrZero(value: Hex.Hex | undefined): bigint; /** * Decodes an RLP-decoded scalar `Hex` into `number` via `BigInt` to keep the * conversion overflow-safe. Returns `undefined` for absent / empty scalars. * * @internal */ export declare function hexToNumberOrUndefined(value: Hex.Hex | undefined): number | undefined; /** * Decodes an RLP-decoded scalar `Hex` into `Hex` (identity), returning * `undefined` for absent / empty scalars. Used for opaque hex fields like * `to` / `data`. * * @internal */ export declare function hexToHexOrUndefined(value: Hex.Hex | undefined): Hex.Hex | undefined; /** * Decodes a `Bytes` scalar (typically a `Uint8Array.subarray` view returned * by `Rlp.toBytes`) into `bigint`, or `undefined` when the field is absent * or empty. * * For payloads ≤ 6 bytes (the common case for `chainId`, `nonce`, `gas`, * `value`, etc.) the conversion is done with native `Number` accumulation, * skipping the per-leaf hex-string allocation that `Bytes.toBigInt` (which * round-trips through `Hex.fromBytes`) performs. * * @internal */ export declare function bytesToBigIntOrUndefined(value: Bytes.Bytes | undefined): bigint | undefined; /** * Decodes a `Bytes` scalar into `bigint`, defaulting to `0n` when the field * is empty. * * @internal */ export declare function bytesToBigIntOrZero(value: Bytes.Bytes | undefined): bigint; /** * Decodes a `Bytes` scalar into `number` via the same fast path as * {@link bytesToBigIntOrUndefined}. Returns `undefined` for absent / empty * scalars. * * @internal */ export declare function bytesToNumberOrUndefined(value: Bytes.Bytes | undefined): number | undefined; /** * Encodes a `Bytes` scalar to `Hex`, returning `undefined` when the field is * absent or empty. Used for opaque hex fields like `to` / `data` after * decoding via `Rlp.toBytes`. * * @internal */ export declare function bytesToHexOrUndefined(value: Bytes.Bytes | undefined): Hex.Hex | undefined; /** * Encodes a `Bytes` scalar to `Hex` (no `undefined` short-circuit). Used for * fields that flow into `Signature.fromTuple` etc., which expect hex inputs. * * @internal */ export declare function bytesToHex(value: Bytes.Bytes): Hex.Hex; /** * Recursively maps a `RecursiveArray<Bytes>` (e.g. as returned by * `Rlp.toBytes`) to a `RecursiveArray<Hex>`. Used by envelope decoders to * hand the (rarely-large) access list / authorization list sub-trees off to * their existing hex-typed `fromTupleList` codecs without re-running RLP. * * @internal */ export declare function bytesTreeToHex(value: RecursiveArray<Bytes.Bytes>): RecursiveArray<Hex.Hex>; //# sourceMappingURL=tx.d.ts.map