/** * Checksum Utilities * * Provides hash verification for downloaded files * Supports SHA-256, SHA-512, SHA-1, and MD5 */ import { type BinaryLike } from 'node:crypto'; /** * Supported hash algorithms */ export type HashAlgorithm = 'sha256' | 'sha512' | 'sha1' | 'md5'; /** * Hash result with algorithm and value */ export interface HashResult { algorithm: HashAlgorithm; hash: string; } /** * Checksum verification result */ export interface VerifyResult { valid: boolean; expected: string; actual: string; algorithm: HashAlgorithm; } /** * Calculate hash of a buffer */ export declare function hashBuffer(data: BinaryLike, algorithm?: HashAlgorithm): string; /** * Calculate hash of a string */ export declare function hashString(data: string, algorithm?: HashAlgorithm): string; /** * Calculate hash of a file (loads entire file into memory) * Use for small files < 100MB */ export declare function hashFile(filePath: string, algorithm?: HashAlgorithm): Promise; /** * Calculate hash of a file using streams (memory efficient) * Use for large files */ export declare function hashFileStream(filePath: string, algorithm?: HashAlgorithm): Promise; /** * Calculate multiple hashes of a file in a single pass */ export declare function hashFileMultiple(filePath: string, algorithms?: HashAlgorithm[]): Promise>; /** * Verify a file's checksum against an expected value */ export declare function verifyChecksum(filePath: string, expected: string, algorithm?: HashAlgorithm): Promise; /** * Verify multiple checksums for a file * Returns true only if all provided checksums match */ export declare function verifyChecksums(filePath: string, checksums: Partial>): Promise<{ valid: boolean; results: VerifyResult[]; }>; /** * Detect hash algorithm from hash string length */ export declare function detectAlgorithm(hash: string): HashAlgorithm; /** * Check if a string looks like a valid hash */ export declare function isValidHashFormat(hash: string, algorithm?: HashAlgorithm): boolean; /** * Format a hash for display (truncated with ellipsis) */ export declare function formatHash(hash: string, maxLength?: number): string; /** * Calculate hash of an entire directory * * Recursively hashes all files and combines them into a single hash. * File paths are included in the hash to detect renames/moves. * * @since v1.41.0 */ export declare function hashDirectory(dirPath: string, algorithm?: HashAlgorithm): Promise; /** * Compare two hash strings using timing-safe comparison * * This prevents timing attacks where an attacker could infer * the correct hash by measuring comparison time. * * @since v1.41.4 */ export declare function hashesEqual(a: string, b: string): boolean; //# sourceMappingURL=checksum.d.ts.map