PROVABLY FAIR

RAFFLESGAMESROULETTECRASHJACKPOT

Each time a user places a bet in the Jackpot, the time of the bet is recorded. In case of multiple bets, they are simply added to the existing bet without changing the registration time. Once the countdown reaches 0, the bets are sorted chronologically, the total coins wagered are summed, and a random number between 1 and the total coins is generated.

For example, if there are 3 bets of 500, 700, and 100 coins respectively, the total would be 1300 coins. In this case, a number between 1 and 1300 (inclusive) is generated. If the generated number is 1000, the winner would be the user who bet 700 coins.

import crypto from "crypto";const serverSeed = "1234";const publicSeed = "abcd";const nonce = 3;const roundBets = [{ user: "Macaco", betAmount: 500, createdAt: "2025-11-23T22:04:02.324Z" },{ user: "Tarifa", betAmount: 700, createdAt: "2025-11-23T22:04:03.324Z" },{ user: "Mono", betAmount: 100, createdAt: "2025-11-23T22:04:05.324Z" }];const seed = `JACKPOT-${serverSeed}-${publicSeed}:${nonce}`;const MACACO_WINS = doesBotMacacoWins(seed);if (MACACO_WINS) {console.log("Ganador: MACACO BOT");return;}const WINNER = calculateWinner(seed, roundBets);console.log("El ganador del Jackpot es", WINNER);function doesBotMacacoWins(seed) {const hash = crypto.createHmac("sha256", seed).digest("hex");const h = Number.parseInt(hash.slice(0, 52 / 4), 16);const e = Math.pow(2, 52);const roll = Math.floor(h/e * 100);return roll < 7;}function calculateWinner(seed, roundBets) {roundBets.sort((a, b) => new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime());const totalCoins = roundBets.reduce((sum, bet) => sum + bet.betAmount, 0);const hash = crypto.createHmac("sha256", seed).digest("hex");const h = Number.parseInt(hash.slice(0, 52 / 4), 16);const e = Math.pow(2, 52);const WINNER_TICKET = Math.floor(h/e * totalCoins) + 1;let cumulative = 0;for (const bet of roundBets) {const start = cumulative + 1;cumulative += bet.betAmount;if (WINNER_TICKET >= start && WINNER_TICKET <= cumulative) {return bet.user;}}throw new Error("No winner calculated. This should never happen if roundBets is valid.");}