import { Buffer } from 'buffer/index.js'; import { AccountTransactionSignature, HexString, IpAddressString, TransactionStatusEnum } from './types.js'; /** * Replaces a string in a JSON string with the same string as a * number, i.e. removing quotes (") prior to and after the string. This * is needed as the default JSON stringify cannot serialize BigInts as numbers. * So one can turn them into strings, stringify the structure, and then use this function * to make those fields into JSON numbers. * @param jsonStruct the JSON structure as a string * @param keys the keys where the strings has to be unquoted * @returns the same JSON string where the strings at the supplied keys are unquoted */ export declare function stringToInt(jsonStruct: string, keys: string[]): string; /** * Transaction statuses in chronological order: a transaction is first received by the node, * then committed, and finally finalized on-chain. */ export declare function getTransactionStatusRank(status: TransactionStatusEnum): number; /** * Checks if the input string is a valid hexadecimal string. * @param str the string to check for hexadecimal */ export declare function isHex(str: string): boolean; /** * Checks if the input string is a valid utf8 string. Specifically, it checks if the string * contains any invalid surrogate pairs. * @param str the string to check */ export declare function isValidUTF8(str: string): boolean; /** * Checks whether the input string looks to be a valid hash, * i.e. it has length 64 and consists of hexadecimal characters. * @param hash the string to check * @returns false if the string cannot be a valid hash, otherwise true */ export declare function isValidHash(hash: HexString): boolean; export declare function isValidIp(ip: IpAddressString): boolean; /** * Counts the total number of signatures. * @param accountSignatures the signature structure to count */ export declare function countSignatures(accountSignatures: AccountTransactionSignature): bigint; /** * Convert a Date to seconds since epoch. */ export declare function secondsSinceEpoch(date: Date): bigint; export declare function unwrap(x: A | undefined): A; export declare function mapRecord(rec: Record, valMapper: (x: B) => D, keyMapper?: (x: A) => C): Record; /** * Maps an infinite stream of type A to an infinite stream of type B * @param mapper: function used to map each element from type A to B. */ export declare function mapStream(stream: AsyncIterable, mapper: (x: A) => B): AsyncIterable; /** * Filters entries from a record * @param rec the record, whose entries should be filtered. * @param predicate predicate to test entries, only if this returns true does the entry remain */ export declare function filterRecord(rec: Record, predicate: (k: A, v: B) => boolean): Record; export declare function streamToList(iterable: AsyncIterable): Promise; /** * Creates a function that takes either a `T` or `T[]` from a function that takes `T[]`. * * @param {(input: T[]) => R} fun - A function that takes `T[]` * * @example * const serializer = makeDynamicFunction(serialize); * const exampleStruct = { tokenId: ''; tokenAmount: 100n; from: { address: "3nsRkrtQVMRtD2Wvm88gEDi6UtqdUVvRN3oGZ1RqNJ3eto8owi" }; to: 3nsRkrtQVMRtD2Wvm88gEDi6UtqdUVvRN3oGZ1RqNJ3eto8owi; data: '48656c6c6f20776f726c6421'; }; * const bytesSingle = serializer(exampleStruct); * const bytesMulti = serializer([exampleStruct, exampleStruct]); */ export declare const makeDynamicFunction: (fun: (a: T[]) => R) => (input: T | T[]) => R; export declare function isDefined(v?: T): v is T; export declare function toBuffer(s: string, encoding?: string): Buffer; /** * Immediately returns an {@linkcode Error} with the message passed. This allows use of throwing errors as expressions. * @param error - The message to pass to the error * @throws an error immediately * * @example * const value = maybeValue ?? bail('Turns out there was not value anyway...'); */ export declare const bail: (error: string | Error) => never; /** * Takes a callback function taking 1 argument, returning a new function taking same argument, applying callback only if supplied argument is defined. */ export declare const orUndefined: (fun: (v: A) => R) => (v: A | undefined) => R | undefined; type AssertOptions = { descriptor?: string; error?: Error | string; }; /** * Asserts that a value is truthy, throwing an error if not. * * @param value - The value to check * @param options - Optional descriptor or custom error message * * @throws {Error} If value is falsy */ export declare function assert(value: unknown, { descriptor }: Pick): asserts value; export declare function assert(value: unknown, { error }: Pick): asserts value; export declare function assert(value: unknown): asserts value; /** * Asserts that a value is an object (not null), throwing an error if not. The value is * asserted to contain all keys of the type `T` with `unknown` values for each key. * * @template T - The expected object type, defaults to generic object * * @param value - The value to check * @param descriptor - Optional descriptor for error messages * * @throws {Error} If value is not an object */ export declare function assertObject(value: unknown, descriptor?: string): asserts value is Record; /** * Asserts that a value is a string, throwing an error if not. * * @param value - The value to check * @param descriptor - Optional descriptor for error messages * * @throws {Error} If value is not a string */ export declare function assertString(value: unknown, descriptor?: string): asserts value is string; /** * Asserts that a value is a safe integer (number or bigint), throwing an error if not. * * @param value - The value to check * @param descriptor - Optional descriptor for error messages * * @throws {Error} If value is not an integer */ export declare function assertInteger(value: unknown, descriptor?: string): asserts value is number | bigint; /** * Asserts that an object contains all specified properties, throwing an error if not. The value is * asserted to contain all keys of the type `T` with `unknown` values for each key. * * @template T - The expected object type * @template P - The property keys that must exist in the object * * @param value - The value to check * @param properties - Property names that must exist in the object * * @throws {Error} If value is not an object or is missing any properties */ export declare function assertIn(value: unknown, ...properties: P[]): asserts value is Record; export {};