UNPKG

@crtxio/abi

Version:

A tiny Solidity ABI encoder and decoder

78 lines (77 loc) 2.81 kB
export declare type BinaryLike = string | number | bigint | ArrayBufferLike | number[]; export declare const stripPrefix: (value: string) => string; /** * Returns an instance of `TextEncoder` that works with both Node.js and web browsers. */ export declare const getTextEncoder: () => TextEncoder; /** * Returns an instance of `TextDecoder` that works with both Node.js and web browsers. */ export declare const getTextDecoder: (encoding?: string) => TextDecoder; /** * Get a buffer as UTF-8 encoded string. * * @param data The buffer to convert to UTF-8. * @return The buffer as UTF-8 encoded string. */ export declare const toUtf8: (data: Uint8Array) => string; /** * Get a UTF-8 encoded string as buffer. * * @param data The string to convert to a buffer. * @return The buffer. */ export declare const fromUtf8: (data: string) => Uint8Array; /** * Get a Uint8Array as hexadecimal string. * * @param data The buffer to convert to a hexadecimal string. * @return The buffer as hexadecimal string. */ export declare const toHex: (data: Uint8Array) => string; /** * Get a hexadecimal string as Uint8Array. * * @param data The hexadecimal string to convert to a buffer. * @return The buffer. */ export declare const fromHex: (data: string) => Uint8Array; /** * Attempt to parse a value as Uint8Array. If `data` is a number, this will pad the buffer to 32 bytes. * * @param data The value to parse as Uint8Array. * @return The resulting Uint8Array. */ export declare const toBuffer: (data: BinaryLike) => Uint8Array; /** * Safe function to merge multiple Uint8Arrays into a single Uint8array. This works with buffers of any size. * * @param buffers The buffers to combine. * @return The combined buffers. */ export declare const concat: (buffers: Uint8Array[]) => Uint8Array; /** * Set `buffer` in `target` at the specified position. * * @param target The buffer to set to. * @param buffer The buffer to set in the target. * @param position The position at which to set the target. * @return The combined buffer. */ export declare const set: (target: Uint8Array, buffer: Uint8Array, position: number) => Uint8Array; /** * Add padding to a buffer. If the buffer is larger than `length`, this function won't do anything. If it's smaller, the * buffer will be padded to the specified length, with extra zeroes at the end. * * @param buffer The buffer to add padding to. * @param [length] The number of bytes to pad the buffer to. * @return The padded buffer. */ export declare const addPadding: (buffer: Uint8Array, length?: number) => Uint8Array; /** * Get a number from a buffer. Returns zero if the buffer is empty. * * @param buffer The buffer to get a number for. * @return The parsed number. */ export declare const toNumber: (buffer: Uint8Array) => bigint;