import { randomBytes } from "node:crypto"; import { sha256Hex } from "../hash"; const CODE_ALPHABET = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789"; export function normalizeRedeemCode(code: string) { return code.replace(/\s/g, "").toUpperCase(); } export function hashRedeemCode(code: string) { return sha256Hex(code); } export function generateRedeemCode() { const bytes = randomBytes(8); const token = Array.from(bytes, (byte) => CODE_ALPHABET[byte % CODE_ALPHABET.length]).join(""); return `JYOTISH-${token.slice(0, 4)}-${token.slice(4)}`; } export function maskRedeemCode(code: string) { return `JYOTISH-****-${code.slice(-4)}`; }