Skip to content

Instantly share code, notes, and snippets.

@obale
Created September 4, 2015 22:51
Show Gist options
  • Save obale/3dfd4a57641f798ca2ea to your computer and use it in GitHub Desktop.
Save obale/3dfd4a57641f798ca2ea to your computer and use it in GitHub Desktop.
# Magic that computes a sha-256 hash for any content
crypto = require('crypto')
SHA256 = (data) ->
new Buffer(crypto.createHash('sha256').update(data).digest('binary'), 'binary')
# Hexadecimal representation of the Genesis Block
rawBlock = new Buffer('5df6e0e2761359d30a8275058e299fcc0381534545f55cf43e41983f5d4c945641d57c3200000000ffffffff0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', 'hex')
# Computes the double SHA256 hash of the Genesis Block
blockId = SHA256(SHA256(rawBlock.toString('hex')))
# Printing the hash in a readable way, as hexadecimal representation
console.log blockId.toString('hex')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment