Skip to content

Instantly share code, notes, and snippets.

@numtel
Created January 5, 2018 09:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save numtel/79dea6af99edbd9795417b954c97944e to your computer and use it in GitHub Desktop.
Save numtel/79dea6af99edbd9795417b954c97944e to your computer and use it in GitHub Desktop.
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