UNPKG

xypriss-security

Version:

Advanced High-Performance Security Framework. Military-grade encryption, post-quantum resilience, and fortified data structures.

321 lines 11.3 kB
/** * Enhanced encoding utilities for various formats */ /** * Convert a buffer to a hexadecimal string * @param buffer - The buffer to convert * @param uppercase - Whether to use uppercase letters (default: false) * @param separator - Optional separator between bytes (e.g., ':', ' ', '-') * @returns Hexadecimal string representation */ export declare function bufferToHex(buffer: Uint8Array, uppercase?: boolean, separator?: string): string; /** * Convert a hexadecimal string to a buffer * @param hex - The hexadecimal string to convert * @returns Uint8Array representation */ export declare function hexToBuffer(hex: string): Uint8Array; /** * Convert a buffer to a binary string * @param buffer - The buffer to convert * @param separator - Optional separator between bytes (e.g., ' ', '-') * @returns Binary string representation */ export declare function bufferToBinary(buffer: Uint8Array, separator?: string): string; /** * Convert a binary string to a buffer * @param binary - The binary string to convert * @returns Uint8Array representation */ export declare function binaryToBuffer(binary: string): Uint8Array; /** * Convert a number to binary string with specified bit width * @param num - The number to convert * @param bits - The number of bits (default: 8) * @returns Binary string representation */ export declare function numberToBinary(num: number, bits?: number): string; /** * Convert a binary string to a number * @param binary - The binary string to convert * @returns Number representation */ export declare function binaryToNumber(binary: string): number; /** * Convert a buffer to a Base64 string * @param buffer - The buffer to convert * @param urlSafe - Whether to use URL-safe Base64 (default: false) * @returns Base64 string representation */ export declare function bufferToBase64(buffer: Uint8Array, urlSafe?: boolean): string; /** * Convert a Base64 string to a buffer * @param base64 - The Base64 string to convert * @param urlSafe - Whether the input is URL-safe Base64 (default: false) * @returns Uint8Array representation */ export declare function base64ToBuffer(base64: string, urlSafe?: boolean): Uint8Array; /** * Convert a buffer to a Base58 string (Bitcoin style) * @param buffer - The buffer to convert * @returns Base58 string representation */ export declare function bufferToBase58(buffer: Uint8Array): string; /** * Convert a Base58 string to a buffer * @param base58 - The Base58 string to convert * @returns Uint8Array representation */ export declare function base58ToBuffer(base58: string): Uint8Array; /** * Convert a buffer to a Base32 string (RFC 4648) * @param buffer - The buffer to convert * @param padding - Whether to include padding (default: true) * @returns Base32 string representation */ export declare function bufferToBase32(buffer: Uint8Array, padding?: boolean): string; /** * Convert a Base32 string to a buffer * @param base32 - The Base32 string to convert * @returns Uint8Array representation */ export declare function base32ToBuffer(base32: string): Uint8Array; /** * Convert a buffer to an octal string * @param buffer - The buffer to convert * @param separator - Optional separator between bytes * @returns Octal string representation */ export declare function bufferToOctal(buffer: Uint8Array, separator?: string): string; /** * Convert an octal string to a buffer * @param octal - The octal string to convert * @returns Uint8Array representation */ export declare function octalToBuffer(octal: string): Uint8Array; /** * Convert a number to octal string * @param num - The number to convert * @returns Octal string representation */ export declare function numberToOctal(num: number): string; /** * Convert an octal string to a number * @param octal - The octal string to convert * @returns Number representation */ export declare function octalToNumber(octal: string): number; /** * Convert a string to a buffer using UTF-8 encoding * @param str - The string to convert * @returns Uint8Array representation */ export declare function stringToBuffer(str: string): Uint8Array; /** * Convert a string directly to hexadecimal representation * @param str - The string to convert * @param uppercase - Whether to use uppercase letters (default: false) * @param separator - Optional separator between bytes * @returns Hexadecimal string representation */ export declare function stringToHex(str: string, uppercase?: boolean, separator?: string): string; /** * Convert a hexadecimal string back to a string * @param hex - The hexadecimal string to convert * @returns String representation */ export declare function hexToString(hex: string): string; /** * Convert a string directly to Base64 encoding * @param str - The string to encode * @param urlSafe - Whether to use URL-safe Base64 (default: false) * @returns Base64 encoded string */ export declare function stringToBase64(str: string, urlSafe?: boolean): string; /** * Convert a Base64 encoded string back to string * @param base64 - The Base64 encoded string * @param urlSafe - Whether the input is URL-safe Base64 (default: false) * @returns Decoded string */ export declare function base64ToString(base64: string, urlSafe?: boolean): string; /** * Convert a buffer to a string using UTF-8 decoding * @param buffer - The buffer to convert * @returns String representation */ export declare function bufferToString(buffer: Uint8Array): string; /** * Convert a string to ASCII bytes * @param str - The string to convert * @returns Uint8Array with ASCII codes */ export declare function stringToAscii(str: string): Uint8Array; /** * Convert ASCII bytes to a string * @param buffer - The buffer with ASCII codes * @returns String representation */ export declare function asciiToString(buffer: Uint8Array): string; /** * Convert a string to Base64URL encoding * @param str - The string to encode * @returns Base64URL encoded string */ export declare function stringToBase64Url(str: string): string; /** * Convert a Base64URL encoded string back to string * @param base64url - The Base64URL encoded string * @returns Decoded string */ export declare function base64UrlToString(base64url: string): string; /** * Convert regular Base64 to Base64URL * @param base64 - The regular Base64 string * @returns Base64URL string */ export declare function base64ToBase64Url(base64: string): string; /** * Convert Base64URL to regular Base64 * @param base64url - The Base64URL string * @returns Regular Base64 string */ export declare function base64UrlToBase64(base64url: string): string; /** * Convert a buffer to Base64URL encoding * @param buffer - The buffer to convert * @returns Base64URL encoded string */ export declare function bufferToBase64Url(buffer: Uint8Array): string; /** * Convert a Base64URL string to a buffer * @param base64url - The Base64URL string to convert * @returns Uint8Array representation */ export declare function base64UrlToBuffer(base64url: string): Uint8Array; /** * URL encode a string * @param str - The string to encode * @returns URL encoded string */ export declare function urlEncode(str: string): string; /** * URL decode a string * @param str - The URL encoded string to decode * @returns Decoded string */ export declare function urlDecode(str: string): string; /** * Convert a buffer to URL encoded string * @param buffer - The buffer to convert * @returns URL encoded string */ export declare function bufferToUrlEncoded(buffer: Uint8Array): string; /** * Convert a number to any base (2-36) * @param num - The number to convert * @param base - The target base (2-36) * @returns String representation in the specified base */ export declare function numberToBase(num: number, base: number): string; /** * Convert a string from any base (2-36) to a number * @param str - The string to convert * @param base - The base of the input string (2-36) * @returns Number representation */ export declare function baseToNumber(str: string, base: number): number; /** * Convert between different number bases * @param str - The input string * @param fromBase - The base of the input string * @param toBase - The target base * @returns String representation in the target base */ export declare function convertBase(str: string, fromBase: number, toBase: number): string; /** * Convert a 16-bit number to bytes (little-endian) * @param num - The 16-bit number * @returns Uint8Array with 2 bytes */ export declare function uint16ToBytes(num: number): Uint8Array; /** * Convert bytes to a 16-bit number (little-endian) * @param buffer - The buffer with 2 bytes * @returns 16-bit number */ export declare function bytesToUint16(buffer: Uint8Array): number; /** * Convert a 32-bit number to bytes (little-endian) * @param num - The 32-bit number * @returns Uint8Array with 4 bytes */ export declare function uint32ToBytes(num: number): Uint8Array; /** * Convert bytes to a 32-bit number (little-endian) * @param buffer - The buffer with 4 bytes * @returns 32-bit number */ export declare function bytesToUint32(buffer: Uint8Array): number; /** * Reverse byte order (swap endianness) * @param buffer - The buffer to reverse * @returns New buffer with reversed byte order */ export declare function reverseBytes(buffer: Uint8Array): Uint8Array; /** * Compare two buffers for equality * @param a - First buffer * @param b - Second buffer * @returns True if buffers are equal */ export declare function buffersEqual(a: Uint8Array, b: Uint8Array): boolean; /** * Concatenate multiple buffers * @param buffers - Array of buffers to concatenate * @returns New buffer containing all input buffers */ export declare function concatBuffers(...buffers: Uint8Array[]): Uint8Array; /** * XOR two buffers * @param a - First buffer * @param b - Second buffer * @returns New buffer with XOR result */ export declare function xorBuffers(a: Uint8Array, b: Uint8Array): Uint8Array; /** * Generate a random buffer * @param length - The length of the buffer * @returns Random buffer */ export declare function randomBuffer(length: number): Uint8Array; /** * Pad a buffer to a specific length * @param buffer - The buffer to pad * @param length - The target length * @param value - The padding value (default: 0) * @param left - Whether to pad on the left (default: false) * @returns Padded buffer */ export declare function padBuffer(buffer: Uint8Array, length: number, value?: number, left?: boolean): Uint8Array; /** * Split a buffer into chunks * @param buffer - The buffer to split * @param chunkSize - The size of each chunk * @returns Array of buffer chunks */ export declare function chunkBuffer(buffer: Uint8Array, chunkSize: number): Uint8Array[]; /** * Format bytes as human-readable string * @param bytes - The number of bytes * @param decimals - Number of decimal places (default: 2) * @returns Formatted string (e.g., "1.23 KB") */ export declare function formatBytes(bytes: number, decimals?: number): string; /** * Auto-detect encoding format of a string * @param str - The string to analyze * @returns Detected format or 'unknown' */ export declare function detectEncoding(str: string): string; //# sourceMappingURL=encoding.d.ts.map