Crates.io | rs-merkletree |
lib.rs | rs-merkletree |
version | 0.1.0 |
source | src |
created_at | 2024-08-12 06:43:12.944135 |
updated_at | 2024-08-12 06:43:12.944135 |
description | Rust library to create Merkle Trees |
homepage | |
repository | https://github.com/varun-doshi/rs-merkletree |
max_upload_size | |
id | 1334012 |
size | 18,481 |
A Rust Library to generate Merkle Trees.
In cryptography and computer science, a hash tree or Merkle tree is a tree in which every "leaf" node is labelled with the cryptographic hash of a data block, and every node that is not a leaf (called a branch, inner node, or inode) is labelled with the cryptographic hash of the labels of its child nodes. A hash tree allows efficient and secure verification of the contents of a large data structure.
Hash trees can be used to verify any kind of data stored, handled and transferred in and between computers. They can help ensure that data blocks received from other peers in a peer-to-peer network are received undamaged and unaltered, and even to check that the other peers do not lie and send fake blocks.
Hash trees are used in:
Add the following to your cargo.toml
to start using rs-merkletree
[dependencies]
rs-merkletree = "0.1.0"
Create a Merkle Tree and print the Root Hash
use rs_merkletree::MerkleTree;
let data: Vec<&str> = vec!["Hello", "World", "From", "Rust"];
let mut tree = MerkleTree::new(None);
let rootNode = tree.build_tree(data);
let root_hash = rootNode.root_node().unwrap().hash();
assert_eq!(
String::from_utf8(root_hash),
Ok(String::from(
"725367a8cee028cf3360c19d20c175733191562b01e60d093e81d8570e865f81"
))
);
For more examples, check out the official docs or the tests
folder
Licensed under either of Apache License, Version 2.0 or MIT license at your option. Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.