Great tutorial, was easy to understand for a novice TypeScript coder.
You can use nodejs built in hashing library for making the sha256 hash so no need to import js-sha256 libraries ;)
var crypto = require('crypto');
var hash = crypto.createHash('sha256').update(block.key).digest("hex");
here is my complete generateHash method:
public generateHash(block: BlockData): string {
let hash = crypto.createHash('sha256').digest("hex");
// mining
while(!hash.startsWith(Array(this.difficulty + 1).join('0'))) {
block.nonce += 1;
hash = crypto.createHash('sha256').update(block.key).digest("hex");
console.log(block.nonce, hash);
}
return hash;
}
I din know that, was finding a library which supporr types haha. Thanks for sharing about this.