import { createHmac } from "crypto"; export type CalculateCrashPointOptions = { clientSeed: string; serverSeed: string; houseEdge?: number; }; export const calculateCrashPoint = ({ serverSeed, clientSeed, houseEdge = 0.01, }: CalculateCrashPointOptions): number => { const hmac = createHmac("sha256", serverSeed); hmac.update(clientSeed); const uint32 = hmac.digest().readUInt32BE(0); const rawCrashPoint = (2 ** 32 / (uint32 + 1)) * (1 - houseEdge); const boundedCrashPoint = Math.min(Math.max(1, rawCrashPoint), 1_000_000); return Math.floor(boundedCrashPoint * 100) / 100; };