UNPKG

libnexa-ts

Version:

A pure and powerful Nexa SDK library.

128 lines 4.12 kB
export default class BufferUtils { /** * Tests for both node's Buffer and Uint8Array * * @param arg * @return Returns true if the given argument is an instance of a Uint8Array. */ static isBuffer(arg: unknown): arg is Uint8Array; /** * Tests for both node's Buffer and Uint8Array * * @param arg * @return Returns true if the given argument is an instance of a hash160 or hash256 buffer. */ static isHashBuffer(arg: unknown): boolean; /** * Reverse a Uint8Array * @param param * @return new reversed Uint8Array */ static reverse(param: Uint8Array): Uint8Array; /** * Convert a Uint8Array to a UTF-8 string. * * @param buffer - Uint8Array containing UTF-8 encoded bytes * @returns Decoded string */ static bufferToUtf8(buffer: Uint8Array): string; /** * Convert a UTF-8 string to a Uint8Array. * * @param str - UTF-8 string * @returns Encoded Uint8Array */ static utf8ToBuffer(str: string): Uint8Array; /** * Convert a Uint8Array to a Base64 string. * * @param buffer - Uint8Array containing Base64 encoded bytes * @returns Decoded string */ static bufferToBase64(buffer: Uint8Array): string; /** * Convert a Base64 string to a Uint8Array. * * @param str - Base64 string * @returns Encoded Uint8Array */ static base64ToBuffer(str: string): Uint8Array; /** * Transforms a buffer into a string with a number in hexa representation * * Similar for <tt>buffer.toString('hex')</tt> * * @param buffer * @return string */ static bufferToHex(buffer: Uint8Array): string; /** * Convert a hexadecimal string into a Uint8Array. * * @param hex - Hex string (must have even length) * @returns Uint8Array representing the bytes */ static hexToBuffer(hex: string): Uint8Array; /** * Concatenate multiple Uint8Arrays into a single Uint8Array. * * Mimics Node.js Buffer.concat(list, totalLength?): * - list: Array of Uint8Arrays * - totalLength: Optional precomputed total length * * @param list - Array of Uint8Arrays to concatenate * @param totalLength - Optional total length to preallocate * @returns New Uint8Array containing all bytes from input arrays * * @example * const a = new Uint8Array([1,2]); * const b = new Uint8Array([3,4]); * const result = Uint8ArrayUtils.concat([a,b]); * console.log(result); // Uint8Array(4) [1,2,3,4] */ static concat(list: Uint8Array[], totalLength?: number): Uint8Array; /** * Compares two Uint8Arrays for byte-wise equality. * * This function checks whether the two arrays have the same length * and the same content. * * @param a - The first Uint8Array to compare. * @param b - The second Uint8Array to compare. * @returns `true` if the arrays have the same length and contents, `false` otherwise. */ static equals(a: Uint8Array, b: Uint8Array): boolean; /** * Transforms a number from 0 to 255 into a Uint8Array of size 1 with that value * * @param integer * @return Uint8Array */ static integerAsSingleByteBuffer(integer: number): Uint8Array; /** * Transforms the first byte of an array into a number ranging from -128 to 127 * * @param buffer * @return number */ static integerFromSingleByteBuffer(buffer: Uint8Array): number; /** * Transform a 4-byte integer into a Uint8Array of length 4. * * @param integer * @return Uint8Array */ static integerAsBuffer(integer: number): Uint8Array; /** * Transform the first 4 values of a Uint8Array into a number, in little endian encoding * * @param buffer * @return integer */ static integerFromBuffer(buffer: Uint8Array): number; /** * @return secure random bytes */ static getRandomBuffer(size: number): Uint8Array; } //# sourceMappingURL=buffer.utils.d.ts.map