import { randomBytes, createHash } from "crypto" const API_KEY_PREFIX = "asa_" export function generateApiKey(): { fullKey: string keyHash: string keyPrefix: string } { const randomPart = randomBytes(20).toString("hex") const fullKey = `${API_KEY_PREFIX}${randomPart}` const keyHash = hashApiKey(fullKey) const keyPrefix = fullKey.slice(0, 8) return { fullKey, keyHash, keyPrefix } } export function hashApiKey(key: string): string { return createHash("sha256").update(key).digest("hex") }