Project

mssmt

0.0
No release in over a year
Ruby implementation of Merkle Sum Sparse Merkle Tree
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies
 Project Readme

Merkle Sum Sparse Merkle Tree

This is the Merkle Sum Sparse Merkle Tree(MS-SMT) ruby library. MS-SMT is a tree that combines the Sparse Merkle Tree and the Merkle-Sum Tree and is defined by the Taro protocol.

Installation

Add this line to your application's Gemfile:

gem 'mssmt'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install mssmt

Usage

require 'mssmt'

# initialize tree
tree = MSSMT::Tree.new

# Add leaf node to tree with key.
leaf = MSSMT::LeafNode.new("Data", 1_000)
key = "5bc565ef18dbe0636cd3398a870ae24e1f184e5c484e1af3a502f77a0aceb0c5"
tree.insert(key, leaf)

# Get root node
root_node = tree.root_node
# Root hash
root_hash = tree.root_hash.unpack1('H*')
# or
root_node.node_hash.unpack1('H*')

# Get leaf node in tree
leaf = tree.get(key)

# Get merkle proof correspond to key
proof = tree.merkle_proof(key)

# Check merkle proof validity.
result = tree.valid_merkle_proof?(key, leaf, proof)

# Delete leaf node
tree.delete(key)

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/mssmt. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the Mssmt project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.