function isGoldenRound(hash) {
return new chance(hash).integer({ min: 1, max: 100 }) <= 1;
}
const sha256 = require("crypto-js/sha256");
import { createHmac } from "crypto";
function getPreviousHash(gameHash) {
return sha256(gameHash).toString();
}
function gameResultToColor(bet) {
if (bet === 0) return "green";
if (1 <= bet && bet <= 7) return "purple";
if (8 <= bet && bet <= 15) return "black";
}
const salt = '0000000000000000000126e13e7225feff5fd0d9a8cf1229d1ee718601491a49';
function saltHash(hash) {
return createHmac("sha256", hash).update(salt).digest("hex");
}
function gameResultFromSeed(seed) {
// warning: slightly biased because of modulo!
const num = parseInt(seed.substr(0, 52 / 4), 16);
return num % 15;
}
function getGameInformation(hash) {
const seed = saltHash(hash),
result = gameResultFromSeed(seed);
return {
result,
hash,
seed,
color: gameResultToColor(result)
};
}
function getPreviousResults(gameHash, count) {
const results = [];
for (let i = 0; i < count; i++) {
results.push(getGameInformation(gameHash));
gameHash = getPreviousHash(gameHash);
}
return results;
}