3 ms·
const crypto = require('crypto') const Block = (index, data, prevHash) => ({ index, data, prevHash, hash: crypto.createHash('sha256
by jonahx 4y ago
const crypto = require('crypto')
const Block = (index, data, prevHash) => ({
index,
data,
prevHash,
hash: crypto.createHash('sha256').update(index + data + prevHash).digest('hex'),
})
const Blockchain = () => ({
chain: [Block(0, 'Genesis', '0')],
add(data) {
return this.chain.push(
Block(this.chain.at(-1).index + 1, data, this.chain.at(-1).hash)
)
},
})