Skip to content

Instantly share code, notes, and snippets.

@matheusml
Created December 5, 2017 20:32
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 matheusml/47c7e46685bcf3e861c28bf7f52a9b47 to your computer and use it in GitHub Desktop.
Save matheusml/47c7e46685bcf3e861c28bf7f52a9b47 to your computer and use it in GitHub Desktop.
const sha256 = require('crypto-js/sha256')
class Block {
constructor(index = 0, previousHash = null, data = 'Genesis block') {
this.index = index
this.previousHash = previousHash
this.data = data
this.timestamp = new Date()
this.hash = this.generateHash()
}
generateHash() {
return sha256(this.index + this.previousHash + JSON.stringify(this.data) + this.timestamp).toString()
}
}
module.exports = Block
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment