Created
January 24, 2018 10:16
-
-
Save thecreazy/141346e51efd6ef03fd3620bdf65861b to your computer and use it in GitHub Desktop.
Gist for my medium article on blockchain
This file contains hidden or 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
validProof (lastProof, proof) { | |
const guessHash = crypto.createHmac(process.env.HASH_TYPE, process.env.CRYPTO_SECRET) | |
.update(`${lastProof}${proof}`) | |
.digest('hex') | |
return guessHash.substr(0, 5) === process.env.RESOLUTION_HASH | |
} | |
proofOfWork (lastProof) { | |
let proof = 0 | |
while (true) { | |
if (!this.validProof(lastProof, proof)) { | |
proof++ | |
} else { | |
break | |
} | |
} | |
return proof | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment