Skip to content

Instantly share code, notes, and snippets.

@hackervera
Created August 16, 2017 03:14
Show Gist options
  • Save hackervera/e4335299dd4a135e0757ed9a277af823 to your computer and use it in GitHub Desktop.
Save hackervera/e4335299dd4a135e0757ed9a277af823 to your computer and use it in GitHub Desktop.
require "sequel"
require "merkle-hash-tree"
require "rbnacl"
require "digest"
DB = Sequel.connect('postgres://[email protected]/merk')
def build_chain(head)
chain = DB.from(:chains)[head: head]
if chain[:previous_head] == "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
[chain[:body]]
else
build_chain(chain[:previous_head]) << chain[:body]
end
end
head = "529da179869b61355f106f22074b7be466d2f2335ebb464f7e71b360cd62fc40"
mht_head = RbNaCl::Util.bin2hex(MerkleHashTree.new(build_chain(head), Digest::SHA256).head)
p head == mht_head
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment