/** * Unified Checksum class that handles both Buffer and Uint8Array representations. * * This class provides a consistent interface for working with checksums, * eliminating the need for manual type conversions between Buffer and Uint8Array. * * @example * ```typescript * // Create from Buffer * const checksum1 = Checksum.fromBuffer(buffer); * * // Create from Uint8Array * const checksum2 = Checksum.fromUint8Array(uint8Array); * * // Create from hex string * const checksum3 = Checksum.fromHex('a1b2c3...'); * * // Compare checksums * if (checksum1.equals(checksum2)) { * console.log('Checksums match'); * } * * // Convert to different formats * const buffer = checksum1.toBuffer(); * const uint8Array = checksum1.toUint8Array(); * const hex = checksum1.toHex(); * ``` * * @see Requirements 1.1, 1.2, 1.3, 1.4, 1.5 */ export { ChecksumErrorType } from '../errors/checksumError'; /** * Unified checksum class that handles both Buffer and Uint8Array representations. * * The class uses Uint8Array internally for efficiency and provides conversion * methods to Buffer and hex string formats. * * @remarks * - The constructor is private; use factory methods to create instances * - All checksums must be exactly SHA3_BUFFER_LENGTH bytes (64 bytes for SHA3-512) * - The equals() method performs byte-by-byte comparison * - toString() is an alias for toHex() * * @see Requirements 1.1, 1.2, 1.3, 1.4, 1.5 */ export declare class Checksum { /** * Internal storage for checksum data. * Uses Uint8Array for efficiency. */ private readonly data; /** * Private constructor to enforce factory pattern. * * @param data - The checksum data as Uint8Array * @throws ChecksumError if data length is not equal to SHA3_BUFFER_LENGTH * * @internal */ private constructor(); /** * Create a Checksum from a Buffer. * * @param buffer - The buffer containing checksum data * @returns A new Checksum instance * @throws ChecksumError if buffer length is not equal to SHA3_BUFFER_LENGTH * * @deprecated Use `Checksum.fromUint8Array()` instead for browser compatibility. * This method exists for backward compatibility with Node.js code that uses Buffer. * Buffer extends Uint8Array, so `fromUint8Array()` accepts Buffer values directly. * @platform Node.js — accepts Node.js `Buffer` type * * @example * ```typescript * const buffer = Buffer.from('a'.repeat(128), 'hex'); // 64 bytes * const checksum = Checksum.fromBuffer(buffer); * ``` * * @see Requirement 1.2 * @see Requirement 18.4 — platform-specific convenience method */ static fromBuffer(buffer: Buffer): Checksum; /** * Create a Checksum from a Uint8Array. * * @param array - The Uint8Array containing checksum data * @returns A new Checksum instance * @throws ChecksumError if array length is not equal to SHA3_BUFFER_LENGTH * * @example * ```typescript * const array = new Uint8Array(64); * crypto.getRandomValues(array); * const checksum = Checksum.fromUint8Array(array); * ``` * * @see Requirement 1.2 */ static fromUint8Array(array: Uint8Array): Checksum; /** * Create a Checksum from a hex string. * * @param hex - The hex string representation of the checksum * @returns A new Checksum instance * @throws ChecksumError if hex string is invalid or results in wrong length * * @example * ```typescript * const hex = 'a1b2c3d4...'; // 128 hex characters = 64 bytes * const checksum = Checksum.fromHex(hex); * ``` * * @see Requirement 1.2 */ static fromHex(hex: string): Checksum; /** * Compare this checksum with another for equality. * * Performs a byte-by-byte comparison of the underlying data. * * @param other - The other Checksum to compare with * @returns true if the checksums are equal, false otherwise * * @example * ```typescript * const checksum1 = Checksum.fromBuffer(buffer1); * const checksum2 = Checksum.fromBuffer(buffer2); * if (checksum1.equals(checksum2)) { * console.log('Checksums match'); * } * ``` * * @see Requirement 1.3 */ equals(other: Checksum): boolean; /** * Convert the checksum to a Buffer. * * @returns A new Buffer containing the checksum data * * @deprecated Use `toUint8Array()` instead for browser compatibility. * This method exists for backward compatibility with Node.js code that expects Buffer. * @platform Node.js — returns Node.js `Buffer` type * * @example * ```typescript * const checksum = Checksum.fromHex(hexString); * const buffer = checksum.toBuffer(); * ``` * * @see Requirement 1.5 * @see Requirement 18.4 — platform-specific convenience method */ toBuffer(): Buffer; /** * Convert the checksum to a Uint8Array. * * @returns A new Uint8Array containing the checksum data * * @remarks * Returns a copy of the internal data to maintain immutability. * * @example * ```typescript * const checksum = Checksum.fromBuffer(buffer); * const array = checksum.toUint8Array(); * ``` * * @see Requirement 1.5 */ toUint8Array(): Uint8Array; /** * Convert the checksum to a lowercase hex string. * * @returns The checksum as a lowercase hex string * * @example * ```typescript * const checksum = Checksum.fromBuffer(buffer); * const hex = checksum.toHex(); // 'a1b2c3d4...' * ``` * * @see Requirement 1.4 */ toHex(): string; /** * Convert the checksum to a string representation. * * This is an alias for toHex() for consistent behavior. * * @returns The checksum as a lowercase hex string * * @example * ```typescript * const checksum = Checksum.fromBuffer(buffer); * console.log(`Checksum: ${checksum}`); // Uses toString() implicitly * ``` * * @see Requirement 1.4 */ toString(): string; /** * Get the length of the checksum in bytes. * * @returns The length of the checksum data in bytes */ get length(): number; } /** * Type guard to check if a value is a Checksum instance. * * @param value - The value to check * @returns true if the value is a Checksum instance * * @example * ```typescript * if (isChecksum(value)) { * // value is narrowed to Checksum type * console.log(value.toHex()); * } * ``` * * @see Requirement 14.1 */ export declare function isChecksum(value: unknown): value is Checksum; //# sourceMappingURL=checksum.d.ts.map