BC.Games Mines Provably Fair Verifier

node v14.20.1
version: 1.2.1
endpointsharetweet
This takes the provided script from BC.Games and provides instructions on how to generate the outcome of your seed/client/nonce combination. To use this, simply clone to edit and then scroll to the bottom of the code section and edit the part of the code where the Server Seed, Client Seed, and Nonce are by replacing them with your own, making sure to keep the quotation marks in place.
"How Are the Results Calculated? To get the results, we calculate the hash value of the combination with HMAC_SHA256. This gives us a 64-character hexadecimal string: hash = HMAC_SHA256 (clientSeed : nonce, server Seed)."
const crypto = require("crypto"); function getResult(hash) { const allNums = [ 7, 2, 19, 25, 1, 13, 5, 24, 14, 6, 15, 9, 22, 16, 3, 17, 18, 20, 8, 21, 4, 12, 10, 23, 11, ]; let seed = hash; let finalNums = createNums(allNums, seed); seed = crypto.createHash("SHA256").update(seed).digest("hex"); finalNums = createNums(finalNums, seed); return finalNums.map((m) => m.num.num); } function createNums(allNums, hash) { let nums = []; let h = crypto.createHash("SHA256").update(hash).digest("hex"); allNums.forEach((c) => { nums.push({ num: c, hash: h }); h = h.substring(1) + h.charAt(0); }); nums.sort(function (o1, o2) { if (o1.hash < o2.hash) { return -1; } else if (o1.hash === o2.hash) { return 0; } else { return 1; } }); return nums; } function main (serverSeed, clientSeed, nonce) { let resultArr = [clientSeed, nonce]; let hmacSha256Result = crypto.createHmac("sha256", serverSeed).update(resultArr.join(":")).digest("hex") let resultList = getResult(hmacSha256Result); console.log(resultList); } // main ("server seed", "client seed", "nonce"); // *****Directions // simply uncomment the "main" line (delete the "//") after you've replaced // the server seed, client seed, and nonce. Then hit shift+enter // to run. The numbers will be listed below.
I'm trying to find a way to add an easy input area, either though here or through a design on codepen.io which proves to be a challenge as I have no background in programming and am trying to combine 2 differrent things. Please feel free to take a look at https://codepen.io/nucleare/pen/ExLxeRb?editors=1010 Below was a started attempted at an alternatve form of adding in user input fields to be used with the main function that provides the numbers used for mine placement.
// ********below is a work in progress // I'm doing this by trial and error, but I think it would be easier to simple include // the form input into the same function // var serverSeed = document.getElementById('server_seed').value; // var client_seed = document.getElementById('client_seed').value; // but maybe we confused ourselves and thought we'll call this function // from another function function main (serverSeed, clientSeed, nonce) { var serverSeed = document.getElementById('server_seed').value; var clientSeed = document.getElementById('client_seed').value; var nonce = document.getElementById('nonce_in').value; let resultArr = [clientSeed, nonce]; let hmacSha256Result = crypto.createHmac("sha256", serverSeed).update(resultArr.join(":")).digest("hex") let resultList = getResult(hmacSha256Result); console.log(resultList); return(resultList).toString; } // attempting to add custome code for easier user input and use <form> <label for="server_seed">Server Seed:</label><input type="text" name="server_seed" id="server_seed"><br> <label for="client_seed">Client Seed:</label><input type="text" name="client_seed" id="clientseed"><br> <label for="nonce_in">Nonce:</label><input type="text" name="nonce_in" id="nonce_in"><br> <button onclick="main(server_seed, client_seed, nonce_in)">Update</button> </form> <script><form autocomplete="off" novalidate> <label for="server_seed">Server Seed:</label><input type="text" name="server_seed" id="server_seed"></input><br> <label for="client_seed">Client Seed:</label><input type="text" name="client_seed" id="clientseed"></input></br><br> <label for="nonce_in">Nonce:</label><input type="text" name="nonce_in" id="nonce_in"></input></br><br> <button onclick="uadd()">Update</button> </br></form></script>
Loading…

no comments

    sign in to comment