Duels
We use EOS blockchain and cryptography to determine duel results. When a user creates a duel, a public seed is created, hashed with SHA256 based on 16 random bytes. After all participants have joined the duel, we choose an unobtained EOS block from the very near future. Once the EOS block becomes available, we use it as the secret key to determine the result of the duel. The duel result can be 0 (red), 1 (blue), 2 (green), or 3 (gold). The result is obtained by extracting a number from the HmacSha256 hash generated from the public seed and the secret key (the EOS block id). This process is described below. Thus, neither the user nor Sui Casino will know the result of the duel in advance, until all bets have been placed, which prevents the possibility of any changes and makes the system provably fair.
const duel_size = 2;
const public_seed =
"2a409f61287c45e7f0e8539384abc8f0581f11c6305b636ebe459c4e990906ef";
const eos_block_id =
"a75438d19ba87d02801f9e97362757dad36a102cb78ba927d3410a2f274a18f9"; // secret
const hmac = CryptoJS.HmacSHA256(public_seed, eos_block_id); // https://cryptojs.gitbook.io/docs/#hmac
const outcomeHash = hmac.toString(CryptoJS.enc.Hex);
// => f5422a078d5112ad6e7591f8c808db11f181a1af4ee27ac6f9461bd025b43300
const slice = outcomeHash.substr(0, 8);
// => ee8bc815
const random = parseInt(slice, 16) / 0xffffffff;
// => 0.9318203977150424
const outcome = Math.floor(random * duel_size);
// => 1 (BLUE)
Last updated