@bsv/sdk
Version:
BSV Blockchain Software Development Kit
128 lines • 5.07 kB
TypeScript
import BigNumber from './BigNumber.js';
/**
* Prepends a '0' to an odd character length word to ensure it has an even number of characters.
* @param {string} word - The input word.
* @returns {string} - The word with a leading '0' if it's an odd character length; otherwise, the original word.
*/
export declare const zero2: (word: string) => string;
/**
* Converts an array of numbers to a hexadecimal string representation.
* @param {number[]} msg - The input array of numbers.
* @returns {string} - The hexadecimal string representation of the input array.
*/
export declare const toHex: (msg: number[]) => string;
/**
* Converts various message formats into an array of numbers.
* Supports arrays, hexadecimal strings, base64 strings, and UTF-8 strings.
*
* @param {any} msg - The input message (array or string).
* @param {('hex' | 'utf8' | 'base64')} enc - Specifies the string encoding, if applicable.
* @returns {any[]} - Array representation of the input.
*/
export declare const toArray: (msg: any, enc?: 'hex' | 'utf8' | 'base64') => any[];
/**
* Converts an array of numbers to a UTF-8 encoded string.
* @param {number[]} arr - The input array of numbers.
* @returns {string} - The UTF-8 encoded string.
*/
export declare const toUTF8: (arr: number[]) => string;
/**
* Encodes an array of numbers into a specified encoding ('hex' or 'utf8'). If no encoding is provided, returns the original array.
* @param {number[]} arr - The input array of numbers.
* @param {('hex' | 'utf8')} enc - The desired encoding.
* @returns {string | number[]} - The encoded message as a string (for 'hex' and 'utf8') or the original array.
*/
export declare const encode: (arr: number[], enc?: 'hex' | 'utf8') => string | number[];
/**
* Converts an array of bytes (each between 0 and 255) into a base64 encoded string.
*
* @param {number[]} byteArray - An array of numbers where each number is a byte (0-255).
* @returns {string} The base64 encoded string.
*
* @example
* const bytes = [72, 101, 108, 108, 111]; // Represents the string "Hello"
* console.log(toBase64(bytes)); // Outputs: SGVsbG8=
*/
export declare function toBase64(byteArray: number[]): string;
/**
* Converts a string from base58 to a binary array
* @param str - The string representation
* @returns The binary representation
*/
export declare const fromBase58: (str: string) => number[];
/**
* Converts a binary array into a base58 string
* @param bin - The binary array to convert to base58
* @returns The base58 string representation
*/
export declare const toBase58: (bin: number[]) => string;
/**
* Converts a binary array into a base58check string with a checksum
* @param bin - The binary array to convert to base58check
* @returns The base58check string representation
*/
export declare const toBase58Check: (bin: number[], prefix?: number[]) => string;
/**
* Converts a base58check string into a binary array after validating the checksum
* @param str - The base58check string to convert to binary
* @param enc - If hex, the return values will be hex strings, arrays of numbers otherwise
* @param prefixLength - The length of the prefix. Optional, defaults to 1.
* @returns The binary array representation
*/
export declare const fromBase58Check: (str: string, enc?: 'hex', prefixLength?: number) => {
data: number[] | string;
prefix: number[] | string;
};
export declare class Writer {
bufs: number[][];
private length;
constructor(bufs?: number[][]);
getLength(): number;
toArray(): number[];
write(buf: number[]): this;
writeReverse(buf: number[]): this;
writeUInt8(n: number): this;
writeInt8(n: number): this;
writeUInt16BE(n: number): this;
writeInt16BE(n: number): this;
writeUInt16LE(n: number): this;
writeInt16LE(n: number): this;
writeUInt32BE(n: number): this;
writeInt32BE(n: number): this;
writeUInt32LE(n: number): this;
writeInt32LE(n: number): this;
writeUInt64BEBn(bn: BigNumber): this;
writeUInt64LEBn(bn: BigNumber): this;
writeUInt64LE(n: number): this;
writeVarIntNum(n: number): this;
writeVarIntBn(bn: BigNumber): this;
static varIntNum(n: number): number[];
static varIntBn(bn: BigNumber): number[];
}
export declare class Reader {
bin: number[];
pos: number;
private readonly length;
constructor(bin?: number[], pos?: number);
eof(): boolean;
read(len?: number): number[];
readReverse(len?: number): number[];
readUInt8(): number;
readInt8(): number;
readUInt16BE(): number;
readInt16BE(): number;
readUInt16LE(): number;
readInt16LE(): number;
readUInt32BE(): number;
readInt32BE(): number;
readUInt32LE(): number;
readInt32LE(): number;
readUInt64BEBn(): BigNumber;
readUInt64LEBn(): BigNumber;
readInt64LEBn(): BigNumber;
readVarIntNum(signed?: boolean): number;
readVarInt(): number[];
readVarIntBn(): BigNumber;
}
export declare const minimallyEncode: (buf: number[]) => number[];
//# sourceMappingURL=utils.d.ts.map