import { SmartContractLib } from "../smartContractLib.js"; import { ByteString, UInt32, UInt64 } from "../types/primitives.js"; export declare const UINT64_MAX = 18446744073709551615n; export declare const UINT64_MIN = 0n; export declare const UINT32_MAX = 4294967295n; export declare const UINT32_MIN = 0n; type ReadVarintResult = { data: ByteString; nextPos: bigint; }; /** * A utility class providing standard helper methods for working with ByteStrings and numeric conversions. * Includes methods for: * - Checking ByteString length divisibility * - Converting between numeric types (UInt32, UInt64) and ByteStrings * - Little-endian unsigned integer conversions * - Variable-length integer (VarInt) serialization/deserialization * - Push data serialization for Bitcoin script * All methods are static and annotated with @method() decorator. */ export declare class StdUtils extends SmartContractLib { static readonly VARINT_2BYTE: ByteString; static readonly VARINT_4BYTE: ByteString; static readonly VARINT_8BYTE: ByteString; static readonly OP_PUSHDATA1_VAL: bigint; static readonly OP_PUSHDATA2_VAL: bigint; static readonly OP_PUSHDATA4_VAL: bigint; /** * Checks if the length of a ByteString is divisible by a given number and returns the quotient. * @param b The ByteString to check * @param n The divisor to check against * @returns The quotient of the division (length / n) * @throws If the length is not divisible by n */ static checkLenDivisibleBy(b: ByteString, n: bigint): bigint; /** * Converts a UInt64 value to a little-endian ByteString. * @param n The UInt64 value to convert * @returns The little-endian ByteString representation * @throws If the input value is outside UInt64 range (0 to 2^64-1) */ static uint64ToByteString(n: UInt64): ByteString; /** * Converts a UInt32 number to a 4-byte little-endian ByteString. * @param n The UInt32 number to convert * @returns The resulting 4-byte little-endian ByteString * @throws If the input number is outside the UInt32 range (0 to 4294967295) */ static uint32ToByteString(n: UInt32): ByteString; /** * Converts a 4-byte ByteString to an unsigned 32-bit integer in little-endian format. * @param b - The ByteString to convert (must be exactly 4 bytes long) * @returns The converted UInt32 value * @throws Will throw an error if the input ByteString length is not 4 bytes */ static byteStringToUInt32(b: ByteString): UInt32; /** * convert signed integer `n` to unsigned integer of `l` string, in little endian * @param {bigint} n the number to be converted * @param {bigint} l expected length * @returns {ByteString} returns a `ByteString` */ static toLEUnsigned(n: bigint, l: bigint): ByteString; /** * convert `ByteString` to unsigned integer, in sign-magnitude little endian * @param {ByteString} bytes the `ByteString` to be converted * @returns {bigint} returns a number */ static fromLEUnsigned(b: ByteString): bigint; /** * Encodes a bigint into a variable-length integer (VarInt) format as ByteString. * The encoding follows the standard VarInt scheme: * - Values < 0xfd: encoded as 1 byte * - Values < 0x10000: prefixed with 0xfd and encoded as 2 bytes (little-endian) * - Values < 0x100000000: prefixed with 0xfe and encoded as 4 bytes (little-endian) * - Larger values: prefixed with 0xff and encoded as 8 bytes (little-endian) * @param n - The bigint value to encode * @returns ByteString containing the VarInt encoded value */ static writeVarInt(n: bigint): ByteString; /** * Pushes data to a buffer with appropriate size header. * * @param buf - The input data as a ByteString * @returns The input data prefixed with appropriate size header in little-endian format * @remarks The header format follows standard Bitcoin script pushdata rules: * - 0x4c for 1-byte length (0-255 bytes) * - 0x4d for 2-byte length (256-65535 bytes) * - 0x4e for 4-byte length (65536-4294967295 bytes) * @throws Will assert if input size exceeds 32-bit limit (4294967295 bytes) */ static pushData(buf: ByteString): ByteString; /** * read [VarInt (variable integer)]{@link https://learnmeabitcoin.com/technical/general/compact-size/}-encoded data from the beginning of 'buf' * @param {ByteString} buf a buffer `ByteString` of format: [prefix FD/FE/FF +] length + data * @returns return data */ static readVarint(buf: ByteString, pos: bigint): ReadVarintResult; } export {}; //# sourceMappingURL=stdUtils.d.ts.map