const = require(“crypto”);
const roundSeed = “”; /YOUR SERVER SEED/
const clientSeed = “”; /YOUR CLIENT SEED/
const nonce = “”; /YOUR GAME’S NONCE/
function saltWithClientSeed(serverSeed, clientSeed) {
return crypto
.createHmac(“sha512”, serverSeed)
.update(clientSeed)
.digest(“hex”);
}
function generateHash(serverSeed) {
return crypto
.createHash(“sha256”)
.update(serverSeed)
.digest(“hex”);
}
function buildFinalHash(serverSeed, clientSeed, nonce) {
const noncedSeed = ${clientSeed} - ${nonce}
;
return saltWithClientSeed(serverSeed, noncedSeed);
}
function rollNumber(hash) {
let index = 0;
let lucky = parseInt(hash.substring(index * 5, index * 5 + 5), 16);
// keep grabbing characters from the hash while greater than
while (lucky >= Math.pow(10, 6)) {
index++;
lucky = parseInt(hash.substring(index * 5, index * 5 + 5), 16);
// if we reach the end of the hash, just default to highest number
if (index * 5 + 5 > 128) {
lucky = 9999;
break;
}
}
lucky %= Math.pow(10, 4);
lucky /= Math.pow(10, 2);
return lucky;
}
function verifyRoll() {
const hash = buildFinalHash(roundSeed, clientSeed, nonce);
return rollNumber(hash);
}
console.log(verifyRoll());