UNPKG

@hiprax/crypto

Version:

High-security encryption/decryption library using AES-256-GCM and Argon2id

122 lines 3.98 kB
import type { ValidationResult, FileInfo, RetryConfig } from './types.js'; /** * Validate if a file exists and is accessible * @param filePath - Path to the file * @returns Promise that resolves to validation result */ export declare function validateFile(filePath: string): Promise<ValidationResult>; /** * Validate if a path is valid for writing * @param filePath - Path to validate * @returns Validation result */ export declare function validatePath(filePath: string): ValidationResult; /** * Generate a secure random string * @param length - Length of the string (default: 32) * @returns Random string * @throws CryptoError if length is invalid */ export declare function generateRandomString(length?: number): string; /** * Format file size in human readable format * @param bytes - Size in bytes * @returns Formatted size string */ export declare function formatFileSize(bytes: number): string; /** * Get file extension * @param filePath - File path * @returns File extension (lowercase) */ export declare function getFileExtension(filePath: string): string; /** * Check if file is a text file based on extension * @param filePath - File path * @returns True if text file */ export declare function isTextFile(filePath: string): boolean; /** * Sanitize filename for security * @param filename - Original filename * @returns Sanitized filename */ export declare function sanitizeFilename(filename: string): string; /** * Create a backup filename * @param originalPath - Original file path * @param suffix - Suffix to add (default: '.backup') * @returns Backup file path */ export declare function createBackupPath(originalPath: string, suffix?: string): string; /** * Validate base64 string * @param str - String to validate * @returns True if valid base64 */ export declare function isValidBase64(str: string): boolean; /** * Secure string comparison (constant time) * @param a - First string * @param b - Second string * @returns True if strings are equal */ export declare function secureStringCompare(a: string, b: string): boolean; /** * Generate a progress bar * @param current - Current value * @param total - Total value * @param width - Bar width (default: 30) * @returns Progress bar string */ export declare function createProgressBar(current: number, total: number, width?: number): string; /** * Sleep for a specified number of milliseconds * @param ms - Milliseconds to sleep * @returns Promise that resolves after the specified time */ export declare function sleep(ms: number): Promise<void>; /** * Retry a function with exponential backoff * @param fn - Function to retry * @param config - Retry configuration * @returns Promise that resolves to function result * @throws Last error if all retries fail */ export declare function retryWithBackoff<T>(fn: () => Promise<T>, config?: RetryConfig): Promise<T>; /** * Get file information * @param filePath - Path to the file * @returns Promise that resolves to file information * @throws CryptoError if file access fails */ export declare function getFileInfo(filePath: string): Promise<FileInfo>; /** * Validate password strength with detailed feedback * @param password - Password to validate * @returns Object with validation result and feedback */ export declare function validatePasswordStrength(password: string): { isValid: boolean; score: number; feedback: string[]; }; /** * Generate a secure random UUID v4 * @returns UUID string */ export declare function generateUUID(): string; /** * Hash a string using SHA-256 * @param input - String to hash * @returns SHA-256 hash as hex string */ export declare function sha256(input: string): string; /** * Generate a secure random hex string * @param length - Length of hex string (default: 32) * @returns Hex string * @throws CryptoError if length is invalid */ export declare function generateRandomHex(length?: number): string; //# sourceMappingURL=utils.d.ts.map