Crates.io | merkle_light |
lib.rs | merkle_light |
version | 0.4.0 |
source | src |
created_at | 2017-11-22 08:07:33.008469 |
updated_at | 2022-06-21 08:35:56.82144 |
description | Light merkle tree implementation with SPV support and dependency agnostic. |
homepage | https://github.com/sitano/merkle_light |
repository | https://github.com/sitano/merkle_light |
max_upload_size | |
id | 40214 |
size | 88,630 |
merkle is a lightweight Rust implementation of a Merkle tree.
core::hash::Hasher
compatibility#[derive(Hashable)]
support for simple structDocumentation is available.
test_sip.rs
: algorithm implementation example for std sip hasher, u64 hash itemstest_xor128.rs
: custom hash example xor128test_cmh.rs
: custom merkle hasher implementation examplecrypto_bitcoin_mt.rs
: bitcoin merkle tree using crypto libcrypto_chaincore_mt.rs
: chain core merkle tree using crypto libring_bitcoin_mt.rs
: bitcoin merkle tree using ring libextern crate crypto;
extern crate merkle_light;
use std::fmt;
use std::hash::Hasher;
use std::iter::FromIterator;
use crypto::sha3::{Sha3, Sha3Mode};
use crypto::digest::Digest;
use merkle_light::hash::{Algorithm, Hashable};
use merkle_light::merkle::MerkleTree;
pub struct ExampleAlgorithm(Sha3);
impl ExampleAlgorithm {
pub fn new() -> ExampleAlgorithm {
ExampleAlgorithm(Sha3::new(Sha3Mode::Sha3_256))
}
}
impl Default for ExampleAlgorithm {
fn default() -> ExampleAlgorithm {
ExampleAlgorithm::new()
}
}
impl Hasher for ExampleAlgorithm {
#[inline]
fn write(&mut self, msg: &[u8]) {
self.0.input(msg)
}
#[inline]
fn finish(&self) -> u64 {
unimplemented!()
}
}
impl Algorithm<[u8; 32]> for ExampleAlgorithm {
#[inline]
fn hash(&mut self) -> [u8; 32] {
let mut h = [0u8; 32];
self.0.result(&mut h);
h
}
#[inline]
fn reset(&mut self) {
self.0.reset();
}
}
fn main() {
let mut h1 = [0u8; 32];
let mut h2 = [0u8; 32];
let mut h3 = [0u8; 32];
h1[0] = 0x11;
h2[0] = 0x22;
h3[0] = 0x33;
let t: MerkleTree<[u8; 32], ExampleAlgorithm> = MerkleTree::from_iter(vec![h1, h2, h3]);
println!("{:?}", t.root());
}
Please report bugs either as pull requests or as issues in the issue tracker. merkle has a full disclosure vulnerability policy. Please do NOT attempt to report any security vulnerability in this code privately to anybody.
See LICENSE.