/** * Cryptographic utilities for security-sensitive operations * * These utilities are designed to prevent timing attacks and other * side-channel vulnerabilities in authentication and validation code. */ /** * Performs a constant-time comparison of two strings. * * This function is designed to prevent timing attacks where an attacker * could measure response times to determine how many characters of a * secret value they have guessed correctly. * * The comparison always takes the same amount of time regardless of: * - How many characters match * - Where the first difference occurs * - The length difference between strings * * @param a - First string to compare * @param b - Second string to compare * @returns true if the strings are equal, false otherwise * * @example * ```typescript * // Use for token validation * const isValid = constantTimeCompare(userToken, storedToken) * * // Use for API key validation * const isValidKey = constantTimeCompare(providedKey, expectedKey) * ``` */ export declare function constantTimeCompare(a: string, b: string): boolean; /** * Performs a constant-time comparison of two Uint8Arrays. * * Similar to constantTimeCompare but for binary data. * * @param a - First buffer to compare * @param b - Second buffer to compare * @returns true if the buffers are equal, false otherwise */ export declare function constantTimeCompareBuffers(a: Uint8Array, b: Uint8Array): boolean; /** * Generates a cryptographically secure random token. * * Uses the Web Crypto API for secure random number generation, * which is available in both browser and Cloudflare Workers environments. * * @param length - The number of random bytes (output will be 2x this in hex) * @returns A hex-encoded random string * * @example * ```typescript * const sessionToken = generateSecureToken(32) // 64 hex characters * const apiKey = generateSecureToken(16) // 32 hex characters * ``` */ export declare function generateSecureToken(length?: number): string; /** * Generates a URL-safe base64-encoded secure random token. * * @param length - The number of random bytes * @returns A URL-safe base64-encoded random string * * @example * ```typescript * const token = generateSecureTokenBase64(32) * ``` */ export declare function generateSecureTokenBase64(length?: number): string; //# sourceMappingURL=crypto.d.ts.map