Files
Jyotisha/frontend/src/lib/supabase/codes.ts
T
jesse-uxandGrok (agent loop) d2296c2654 把前后端共用的请求契约和小工具收成一份,避免再各抄一份。
报告创建请求、校正入口和同名类型改从 contracts 推导;同义的对象判断与 sha256 改走共享函数。调用处用 import 别名保留原名,使 diff 低于 1500 行。行为、哈希和状态字符串不变。

Co-Authored-By: Grok (agent loop)
2026-10-15 22:22:44 +08:00

23 lines
642 B
TypeScript

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)}`;
}