Created
January 5, 2018 09:25
-
-
Save numtel/79dea6af99edbd9795417b954c97944e to your computer and use it in GitHub Desktop.
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
function genPow(hash, timeout) { | |
timeout = timeout || 15000000; | |
const start = Date.now(); | |
const hashBytes = hex_uint8(hash); | |
let i=0; | |
while(Date.now() - start < timeout) { | |
const workBytes = nacl.randomBytes(8); | |
for(let j=0;j<256;j++) { | |
workBytes[7] = j; | |
const context = blake2bInit(8, null); | |
blake2bUpdate(context, workBytes.reverse()); | |
blake2bUpdate(context, hashBytes); | |
const score = blake2bFinal(context); | |
i++; | |
if(score[7] == 0xff && score[6] == 0xff && score[5] == 0xff && score[4] > 0xc0) { | |
console.log(i, Date.now() -start); | |
return workBytes; | |
} | |
} | |
} | |
console.log(i, Date.now() -start); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment