import { createHmac, timingSafeEqual } from "crypto"; export function ruleExportToken(ruleId: string, pepper: string): string { return createHmac("sha256", pepper) .update(`rule-export:${ruleId}`) .digest("base64url"); } export function ruleExportTokenMatches( ruleId: string, token: string, pepper: string, ): boolean { if (token.length === 0) return false; const expected = Buffer.from(ruleExportToken(ruleId, pepper)); const actual = Buffer.from(token); if (expected.length !== actual.length) return false; return timingSafeEqual(expected, actual); }