Added hash verifier with reconstruction

This commit is contained in:
Kevin Froman 2020-09-30 19:51:19 +00:00
parent 54b4225e5d
commit ef5548b0d3
3 changed files with 15 additions and 2 deletions

View File

@ -60,7 +60,6 @@ async function findMessages(){
apiGET("getdata", "/" + block).then(function(d){
console.debug(d)
})
})
}

View File

@ -16,7 +16,7 @@
<script src="sha3.js" defer></script>
<script src="onionr-jspow/index.js" defer></script>
<script src="hush-hush.js" defer></script>
<script src="worker-handler.js"></script>
<script src="onionr-blocks.js" defer></script>
</head>
<body>

14
onionr-blocks.js Normal file
View File

@ -0,0 +1,14 @@
function reconstructHash(hash){
return hash.padStart(64, 0)
}
function verifyBlock(raw, hash){
var encoder = new TextEncoder("utf-8")
hash = reconstructHash(hash)
if (doHashHex(encoder.encode(raw)) != hash){
throw new Error("Hash does not match")
}
}