import { Buffer } from 'buffer/index.js'; import { HexString } from './types.js'; /** * A wrapper around some data, which enables reading from the data without * having to keep track of what has already been read. */ export declare class Cursor { private data; private cursor; /** * Constructs a `Cursor`. * * @param {Buffer} data - the data */ private constructor(); /** * Constructs a `Cursor` from hex encoded data. * * @param {HexString} data - the (hex encoded) data * @returns {Cursor} a Cursor wrapping the data */ static fromHex(data: HexString): Cursor; /** * Constructs a `Cursor` from a buffer of bytes. * * @param {ArrayBuffer} buffer - the buffer containing bytes. * @returns {Cursor} a Cursor wrapping the data. */ static fromBuffer(buffer: ArrayBuffer): Cursor; /** * Read a number of bytes from the cursor. * * @param {number} [numBytes=this.remainingBytes.length] - The number of bytes to read. Defaults to the remaining bytes from the cursor position. * @throws If the buffer contains fewer bytes than being read. * @returns {Buffer} A buffer containing the number of bytes specified from the cursor position */ read(numBytes?: number): Buffer; /** * Skip a number of bytes from the cursor. * * @param {number} [numBytes=this.remainingBytes.length] - The number of bytes to read. Defaults to the remaining bytes from the cursor position. * @throws If the buffer contains fewer bytes than being read. */ skip(numBytes?: number): void; /** * Read a number of bytes from the cursor without advancing the internal pointer. * * @param {number} [numBytes=this.remainingBytes.length] - The number of bytes to read. Defaults to the remaining bytes from the cursor position. * @returns {Buffer} A buffer containing the number of bytes specified from the cursor position * @throws If the buffer contains fewer bytes than being read. */ peek(numBytes?: number): Buffer; /** The remaining bytes, i.e. not including the bytes already read. */ get remainingBytes(): Buffer; } /** * Represents function for deserilizing some value from a {@link Cursor}. * @template A The value to deserialize. */ export interface Deserializer { (cursor: Cursor): A; } /** * Deserialize a single byte from the cursor. * @param {Cursor} cursor Cursor over the data to deserialize from. * @returns {number} The value of the single byte. * @throws If the buffer contains fewer bytes than being read. */ export declare function deserializeUInt8(cursor: Cursor): number; /** * Deserialize a u16 little endian from the cursor. * @param {Cursor} cursor Cursor over the data to deserialize from. * @returns {number} The deserialized value. * @throws If the buffer contains fewer bytes than being read. */ export declare function deserializeUInt16LE(cursor: Cursor): number; /** * Deserialize a u32 little endian from the cursor. * @param {Cursor} cursor Cursor over the data to deserialize from. * @returns {number} The deserialized value. * @throws If the buffer contains fewer bytes than being read. */ export declare function deserializeUInt32LE(cursor: Cursor): number; /** * Deserialize a u64 little endian from the cursor. * @param {Cursor} cursor Cursor over the data to deserialize from. * @returns {bigint} The deserialized value. * @throws If the buffer contains fewer bytes than being read. */ export declare function deserializeBigUInt64LE(cursor: Cursor): bigint; /** * Deserialize a u16 big endian from the cursor. * @param {Cursor} cursor Cursor over the data to deserialize from. * @returns {number} The deserialized value. * @throws If the buffer contains fewer bytes than being read. */ export declare function deserializeUInt16BE(cursor: Cursor): number; /** * Deserialize a u32 big endian from the cursor. * @param {Cursor} cursor Cursor over the data to deserialize from. * @returns {number} The deserialized value. * @throws If the buffer contains fewer bytes than being read. */ export declare function deserializeUInt32BE(cursor: Cursor): number; /** * Deserialize a u64 big endian from the cursor. * @param {Cursor} cursor Cursor over the data to deserialize from. * @returns {bigint} The deserialized value. * @throws If the buffer contains fewer bytes than being read. */ export declare function deserializeBigUInt64BE(cursor: Cursor): bigint; /** * Helper function to create a function that deserializes a `HexString` value received in a smart contract response into a list of dynamic type values * determined by the deserialization logic defined in the callback function. * * @param {Function} deserializer - A callback function invoked with a {@link Cursor} pointing to the remaining slice of the full value given by the `input` * The callback function is expected to return the deserialized value of type `R` * * @returns {Function} A function taking a single `HexString` input, returning a list of dynamic type values deserialized according to the `deserializer` function. */ export declare const makeDeserializeListResponse: (deserializer: (value: Cursor) => R) => (value: HexString) => R[]; /** * Helper function to create a function that deserializes a `HexString` value into either a value or a list of values, * depending on a given input value. The returned function will produce a single value if the input is not an array * or an array of length 1, and a list of values of the same length as the input if it is an array. * * @param {T} input - The input value to compare the deserialized value against. * @param {Function} deserializer - A deserialization function that takes a `HexString` value and returns a list of deserialized values. * * @returns {Function} A function taking a single `HexString` input, returning either a single value or a list of values. */ export declare const ensureMatchesInput: (input: T, deserializer: (value: HexString) => R[]) => (value: HexString) => R | R[];