import crypto from "crypto"; export const generateOneTimeKey = async (length = 32) => { const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; let key = ""; const bytes = crypto.randomBytes(length); for (let i = 0; i < length; i++) { key += chars[bytes[i] % chars.length]; } return key.match(/.{1,4}/g)!.join("-"); // group by 4 chars };