@citlayik/

tcmprovablyfair

Nodejs

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

fork
loading
Files
  • index.js

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.386846802873273","path":"index.js","file":{"path":"index.js","content":{"asEncoding":{"base64":"Y29uc3Qgcm9sbCA9IGZ1bmN0aW9uKGtleSwgdGV4dCkgewogIC8vIGNyZWF0ZSBITUFDIHVzaW5nIHNlcnZlciBzZWVkIGFzIGtleSBhbmQgY2xpZW50IHNlZWQgYXMgbWVzc2FnZQogIGNvbnN0IGhhc2ggPSBjcnlwdG8KICAgIC5jcmVhdGVIbWFjKCdzaGE1MTInLCBrZXkpCiAgICAudXBkYXRlKHRleHQpCiAgICAuZGlnZXN0KCdoZXgnKTsKCiAgY29uc29sZS5sb2coImhhc2g6ICIsIGhhc2gpOwogIGxldCBpbmRleCA9IDA7CgogIGxldCBsdWNreSA9IHBhcnNlSW50KGhhc2guc3Vic3RyaW5nKGluZGV4ICogNSwgaW5kZXggKiA1ICsgNSksIDE2KTsKCiAgLy8ga2VlcCBncmFiYmluZyBjaGFyYWN0ZXJzIGZyb20gdGhlIGhhc2ggd2hpbGUgZ3JlYXRlciB0aGFuCiAgd2hpbGUgKGx1Y2t5ID49IE1hdGgucG93KDEwLCA2KSkgewogICAgaW5kZXgrKzsKICAgIGx1Y2t5ID0gcGFyc2VJbnQoaGFzaC5zdWJzdHJpbmcoaW5kZXggKiA1LCBpbmRleCAqIDUgKyA1KSwgMTYpOwoKICAgIC8vIGlmIHdlIHJlYWNoIHRoZSBlbmQgb2YgdGhlIGhhc2gsIGp1c3QgZGVmYXVsdCB0byBoaWdoZXN0IG51bWJlcgogICAgaWYgKGluZGV4ICogNSArIDUgPiAxMjgpIHsKICAgICAgbHVja3kgPSA5OTk5OwogICAgICBicmVhazsKICAgIH0KICB9CgogIGx1Y2t5ICU9IE1hdGgucG93KDEwLCA0KTsKICBsdWNreSAvPSBNYXRoLnBvdygxMCwgMik7CgogIHJldHVybiBsdWNreTsKfTsKCgp2YXIgY2xpZW50U2VlZCA9ICJkc3gxN2xkcjV5dWYxdGlzMjZpMGlsZ3dvMm40Ynl1NSI7CnZhciBzZXJ2ZXJTZWVkID0gInAwZHBlM3VvbTIyZ3VibWU2Nmh2dDR6enoybnF2dnpjIjsKICAKLy8gYmV0IG1hZGUgd2l0aCBzZWVkIHBhaXIgKGV4Y2x1ZGluZyBjdXJyZW50IGJldCkKY29uc3Qgbm9uY2UgPSAwOwp2YXIgcm9sbFJlc3VsdCA9IHJvbGwoc2VydmVyU2VlZCwgYCR7Y2xpZW50U2VlZH0tJHtub25jZX1gKTsKCmNvbnNvbGUubG9nKCJ5b3Ugd2luIGlmIHJvbGwgcmVzdWx0IDwgNDUiKTsKY29uc29sZS5sb2coInJvbGwgcmVzdWx0OiAiLCByb2xsUmVzdWx0KTsKICAK"},"asBuffer":null},"loaded":true}}
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