In the
Provably Fair tab, you can change the client seed and regenerate the server seed.
Server seed is SHA-256 hash generated from random 32 bytes. You can regenerate server seed in any time. You cannot see the original server seed, yet you will be able to check that it was unmodified later after regenerating the server seed.
Client seed is generated first time for user, same way like server seed. As the client seed affects every roll result, changing it to any seed of your choice at any time means you can ensure that it's impossible for us to manipulate the result.
However, the SHA-256 function we use to generate the roll is deterministic, if the client seed is combined with the same server seed, it will generate exactly the same roll result every time. This could be used to abuse the system, so we use something called a 'nonce' which prevents this from being abusable. Each roll done using the same server seed & client seed pair will also be paired with a different nonce, which is simply a number starting at 0 and incremented by 1 for each roll done.
The nonce is based on numbers that we can't manipulate (they naturally increment by 1 after each roll).
SHA-256 returns the hash value for the salt hash combination in a hex-encoded form. We then take the first 8 characters from this hash and convert this hex string to a number.
A mine game is generated with 24 separate salts. Each salt is generated by using the index of tile from board and the main salt who is generated using the server seed, client seed and the nonce. Each output is multiplied by the number of possible unique tiles still remaining on the board. This is done by subtracting the number of tiles remaining by 1 for each iteration game result generated using the corresponding output provided. The location of the mine is plotted using a grid position from left to right, top to bottom.
The fisher-yates shuffle implementation is utilised to prevent duplicate possible hits being generated. Between 1 and 24 game results are used, based on the settings chosen.
Each roll can be verified using this formula as soon as you have revealed your server seed for the previous rolls. The published unhashed server seeds can be checked by simply applying the SHA-256 function to it, this will produce the previously published hashed version of the server seed, which was made visible to you before any roll using it was ever made. Each user can check the integrity of every roll made using this information.
var crypto = require('crypto');
var roll_server_seed = '2c3eea4603280f3cadfb0046b248e7b756930b0b6886997ac73f96d478c823f3';
var roll_client_seed = '0b3eeb63c10796f00e3faff36207b369';
var roll_nonce = 43;
function fair_getCombinedSeed(server_seed, public_seed, nonce) {
return [server_seed, public_seed, nonce].join('-');
}
function fair_generateSaltHash(seed) {
return crypto.createHmac('sha256', seed).digest('hex');
}
function fair_getRoll(salt, max) {
return Math.abs(parseInt(salt.substr(0, 12), 16)) % max;
}
function fair_getShuffle(salt, max) {
var array = [];
for(var i = 0; i < max; i++) array.push(i);
var k = 0;
for(var i = array.length - 1; i > 0; i--, k++) {
var salt_possition = fair_generateSaltHash(salt + '-' + k);
var roll = fair_getRoll(salt_possition, Math.pow(10, 8)) / Math.pow(10, 8);
var j = Math.floor(roll * (i + 1));
[array[i], array[j]] = [array[j], array[i]];
}
return array;
}
var generated_seed = fair_getCombinedSeed(roll_server_seed, roll_client_seed, roll_nonce);
var generated_salt = fair_generateSaltHash(generated_seed);
var generated_array = fair_getShuffle(generated_salt, 25);
var generated_roll = '';
generated_array.forEach(function(item){
if(item < 10) generated_roll += '0' + item;
else generated_roll += item;
});
console.log('Roll: ' + generated_roll);