Created
March 29, 2018 16:55
-
-
Save tacyarg/c3c81444a7b54a94bd912a389d6bd82b to your computer and use it in GitHub Desktop.
Provable Outcome Verification // source http://jsbin.com/yagidew
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>Provable Outcome Verification</title> | |
<script src="https://rawgit.com/daywiss/provable/master/dist/provable.min.js"></script> | |
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/skeleton/2.0.4/skeleton.min.css"></script> | |
</head> | |
<body> | |
<div class="container"> | |
<table class="u-full-width"> | |
<thead> | |
<tr> | |
<th colspan='3'>Game Hashes</th> | |
</tr> | |
<tr> | |
<th>Round</th> | |
<th>Hash</th> | |
<th>Outcome</th> | |
</tr> | |
</thead> | |
<tbody id='table'></tbody> | |
</table> | |
</div> | |
<script id="jsbin-javascript"> | |
//see https://github.com/daywiss/provable for full documentation | |
function refreshTable(hashes,round){ | |
var tableBody = document.getElementById("table"); | |
tableBody.innerHTML = ""; | |
tableBody.innerHTML = hashes.map(function(hash,index){ | |
var result = calcOutcome(hash) | |
return "<tr><td>"+(round-index)+"</td><td>"+hash+"</td><td>"+result+"</td></tr>"; | |
}).join('') | |
} | |
function calcOutcome(hash){ | |
//rehash with public seed if you need to | |
//hash = Provable.rehash(hash,publicSeed) | |
return (Provable.toFloat(hash) * 100).toFixed(2) + '%' | |
} | |
//get query parameters from the url | |
function getParams(name, url) { | |
if (!url) url = window.location.href; | |
name = name.replace(/[\[\]]/g, "\\$&"); | |
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)") | |
var results = regex.exec(url); | |
if (!results) return null; | |
if (!results[2]) return ''; | |
return decodeURIComponent(results[2].replace(/\+/g, " ")); | |
} | |
function run(){ | |
//this is just some hash you want to verify. It can be passed in as url params | |
var currentHash = getParams('hash') || 'e8f5ef5297228142a9a49633bb0d8d051fb31b643580bde00c977bd593d3e654' | |
//our current round, must be > 0 to be able to do any verification | |
var currentRound = getParams('round') || 100 | |
//limit the rounds we are checking to 20 | |
var hashCount = Math.min(currentRound,20) | |
//initialize provable | |
var provable = Provable({ | |
seed:currentHash, //the current hash we are checking | |
count:hashCount, //the number of previous hashes we want to list with it | |
}) | |
//here we get all hashes (20 or hashCount), including seed hash, and reverse them so seed is first. | |
//see docs for full function specification | |
var hashes = provable.hashes(null,null,true,true) | |
refreshTable(hashes,currentRound) | |
} | |
run() | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">//see https://github.com/daywiss/provable for full documentation | |
function refreshTable(hashes,round){ | |
var tableBody = document.getElementById("table"); | |
tableBody.innerHTML = ""; | |
tableBody.innerHTML = hashes.map(function(hash,index){ | |
var result = calcOutcome(hash) | |
return "<tr><td>"+(round-index)+"</td><td>"+hash+"</td><td>"+result+"</td></tr>"; | |
}).join('') | |
} | |
function calcOutcome(hash){ | |
//rehash with public seed if you need to | |
//hash = Provable.rehash(hash,publicSeed) | |
return (Provable.toFloat(hash) * 100).toFixed(2) + '%' | |
} | |
//get query parameters from the url | |
function getParams(name, url) { | |
if (!url) url = window.location.href; | |
name = name.replace(/[\[\]]/g, "\\$&"); | |
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)") | |
var results = regex.exec(url); | |
if (!results) return null; | |
if (!results[2]) return ''; | |
return decodeURIComponent(results[2].replace(/\+/g, " ")); | |
} | |
function run(){ | |
//this is just some hash you want to verify. It can be passed in as url params | |
var currentHash = getParams('hash') || 'e8f5ef5297228142a9a49633bb0d8d051fb31b643580bde00c977bd593d3e654' | |
//our current round, must be > 0 to be able to do any verification | |
var currentRound = getParams('round') || 100 | |
//limit the rounds we are checking to 20 | |
var hashCount = Math.min(currentRound,20) | |
//initialize provable | |
var provable = Provable({ | |
seed:currentHash, //the current hash we are checking | |
count:hashCount, //the number of previous hashes we want to list with it | |
}) | |
//here we get all hashes (20 or hashCount), including seed hash, and reverse them so seed is first. | |
//see docs for full function specification | |
var hashes = provable.hashes(null,null,true,true) | |
refreshTable(hashes,currentRound) | |
} | |
run()</script></body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//see https://github.com/daywiss/provable for full documentation | |
function refreshTable(hashes,round){ | |
var tableBody = document.getElementById("table"); | |
tableBody.innerHTML = ""; | |
tableBody.innerHTML = hashes.map(function(hash,index){ | |
var result = calcOutcome(hash) | |
return "<tr><td>"+(round-index)+"</td><td>"+hash+"</td><td>"+result+"</td></tr>"; | |
}).join('') | |
} | |
function calcOutcome(hash){ | |
//rehash with public seed if you need to | |
//hash = Provable.rehash(hash,publicSeed) | |
return (Provable.toFloat(hash) * 100).toFixed(2) + '%' | |
} | |
//get query parameters from the url | |
function getParams(name, url) { | |
if (!url) url = window.location.href; | |
name = name.replace(/[\[\]]/g, "\\$&"); | |
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)") | |
var results = regex.exec(url); | |
if (!results) return null; | |
if (!results[2]) return ''; | |
return decodeURIComponent(results[2].replace(/\+/g, " ")); | |
} | |
function run(){ | |
//this is just some hash you want to verify. It can be passed in as url params | |
var currentHash = getParams('hash') || 'e8f5ef5297228142a9a49633bb0d8d051fb31b643580bde00c977bd593d3e654' | |
//our current round, must be > 0 to be able to do any verification | |
var currentRound = getParams('round') || 100 | |
//limit the rounds we are checking to 20 | |
var hashCount = Math.min(currentRound,20) | |
//initialize provable | |
var provable = Provable({ | |
seed:currentHash, //the current hash we are checking | |
count:hashCount, //the number of previous hashes we want to list with it | |
}) | |
//here we get all hashes (20 or hashCount), including seed hash, and reverse them so seed is first. | |
//see docs for full function specification | |
var hashes = provable.hashes(null,null,true,true) | |
refreshTable(hashes,currentRound) | |
} | |
run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment