@citlayik/

tcmprovablyfair

Nodejs

proof of fairness for kriptode.com/tcm/play.html

fork
loading
Files
  • index.js
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
const roll = function(key, text) {
  // create HMAC using server seed as key and client seed as message
  const hash = crypto
    .createHmac('sha512', key)
    .update(text)
    .digest('hex');

  console.log("hash: ", 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;
};


var clientSeed = "dsx17ldr5yuf1tis26i0ilgwo2n4byu5";
var serverSeed = "p0dpe3uom22gubme66hvt4zzz2nqvvzc";
  
// bet made with seed pair (excluding current bet)
const nonce = 0;
var rollResult = roll(serverSeed, `${clientSeed}-${nonce}`);

console.log("you win if roll result < 45");
console.log("roll result: ", rollResult);
  
node v10.16.0