Wolf.bet - dice provably fair
Code snippet of form which allows you to verify provably fair of wolf.bet dice bets.
by suchijs
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.2/rollups/hmac-sha256.js"></script>
<h1>WOLF.BET</h1>
<p>Dice Provalby fair verification form</p>
<div>
Server seed: <input id="server_seed" placeholder="Type your server seed" />
</div>
<div>
Client seed: <input id="client_seed" placeholder="Type your client seed" />
</div>
<div>
Nonce: <input id="nonce" placeholder="Type your nonce" />
</div>
<div>
Result: <input id="result" disabled />
</div>
SCSS
body {
font-family: 'AvantGardeLT-Bold', sans-serif;
font-size: 12px;
background: #0c1420;
color: white;
padding: 10px 20px;
}
input {
background: rgb(7, 35, 73);
border: none;
padding: 10px 15px;
border-radius: 6px;
margin-left: 15px;
color: white;
font-family: 'AvantGardeLT-Bold', sans-serif;
}
input::placeholder {
font-family: 'AvantGardeLT-Bold', sans-serif;
color: #a8a8a8;
}
div {
padding: 5px;
&:last-of-type {
input::placeholder {
font-family: 'AvantGardeLT-Bold', sans-serif;
color: white;
}
margin-top: 40px;
}
}
JavaScript
const verify = (server_seed, client_seed, nonce) => {
const hash = CryptoJS.HmacSHA256(
server_seed,
`${client_seed}_${nonce}`,
).toString();
let index = 0;
let lucky = parseInt(hash.substr(index, 5), 16);
while (lucky >= 1000000) {
lucky = parseInt(hash.substr(index, 5), 16);
index += 5;
}
return (lucky % 10000 / 100).toFixed(2);
}
let server_seed = '';
let client_seed = '';
let nonce = '';
const setResult = () => {
if (!server_seed) return $('#result').val('No server seed');
if (!client_seed) return $('#result').val('No client seed');
if (!nonce) return $('#result').val('No nonce');
const result = verify(server_seed, client_seed, nonce);
$('#result').val(result);
};
$('#server_seed').keyup(e => {
server_seed = e.target.value;
setResult();
});
$('#client_seed').keyup(e => {
client_seed = e.target.value;
setResult();
});
$('#nonce').keyup(e => {
nonce = e.target.value;
setResult();
});