import crypto from 'crypto';

/**
 * Generates a secure 256-bit API key
 * @returns {string} A 64-character hexadecimal string
 */
export const generateApiKey = (): string => {
    return crypto.randomBytes(32).toString('hex');
};

/**
 * Validates if a string is a valid API key format
 * @param {string} key - The key to validate
 * @returns {boolean} True if the key is 64 characters and hexadecimal
 */
export const isValidApiKeyFormat = (key: string): boolean => {
    // Check if it's exactly 64 characters and contains only hexadecimal characters
    const hexPattern = /^[a-fA-F0-9]{64}$/;
    return hexPattern.test(key);
};

/**
 * Checks if a string looks like an API key (64 characters)
 * @param {string} token - The token to check
 * @returns {boolean} True if it might be an API key
 */
export const looksLikeApiKey = (token: string): boolean => {
    return token.length === 64;
}; 