可證公平
每一局 BC 自研遊戲的結果,都可以用伺服器端種子、用戶端種子和 nonce 自行驗證。選擇遊戲,查看它的結果是怎麼算出來的。
Keno Multiplayer
去驗證Starting with a secret we've generated a chain of SHA256 hashes in advance. Each element is the hash of the lowercase, hexadecimal string representation of the previous hash.
The chain is released in reverse order, each hash corresponding to one game. The SHA256 of a game's hash equals the hash of the previous game, so the results cannot be changed once the chain is published.
Each result is calculated from the game's hash and a salt (the hash of a Bitcoin block that had not been mined when the chain was published).
To calculate a game's result from its hash:
Code:
const CryptoJS = require("crypto-js");
function seedGenerator(hash, salt) {
const hmac = CryptoJS.HmacSHA256(CryptoJS.enc.Hex.parse(hash), salt);
return hmac.toString(CryptoJS.enc.Hex);
}
function createNums(allNums, hash) {
const nums = [];
let h = CryptoJS.SHA256(hash).toString(CryptoJS.enc.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 keno(hash, salt) {
const allNums = [
1, 30, 11, 40, 2, 29, 12, 39, 3,
28, 13, 38, 4, 27, 14, 37, 5, 26,
15, 36, 6, 25, 16, 35, 7, 24, 17,
34, 8, 23, 18, 33, 9, 22, 19, 32,
10, 21, 20, 31
];
let seed = seedGenerator(hash, salt);
let finalNums = createNums(allNums, seed);
seed = String(CryptoJS.SHA256(seed));
finalNums = createNums(finalNums, seed);
return finalNums.slice(0, 10).map((m) => m.num);
}
let hash = "game hash";
let salt = "salt shown on the verification page";
console.log( "result =>", keno(hash, salt).map((item) => item.num).join(","));This is our multiplayer keno seed event in{" "} bitcointalk
The salt is replaced from time to time, and the verification page shows the salt it uses.