Coder Social home page Coder Social logo

lemerk's Introduction

LeMerk

A custom Merkle Tree Implementation built on Rust.

Example usage

The constructor for LeMerkTree is LeMerkBuilder:

    use hex_literal::hex;
    use lemerk::LeMerkTree;
    use lemerk::builder::LeMerkBuilder;

    const SIZE: usize = 32;
    let max_depth = 7;
    let mut builder: LeMerkBuilder<SIZE> = LeMerkBuilder::<SIZE>::new();
    let custom_block = hex!("abababababababababababababababababababababababababababababababab");
    let different_custom_block = hex!("ababababababaffbabababababababababababababababababababababababab");
    let mut tree: LeMerkTree<SIZE> = builder
        .with_max_depth(max_depth)
        .with_initial_block(custom_block)  // A custom block.
        .try_build::<sha3::Sha3_256>()
        .expect("Unexpected build.");
    let original_root_data = tree.get_root_data().unwrap();
    let leaves = tree.get_leaves_indexes();

    let leaf_index = leaves[0];
    let (updated_root, updated_proof) = tree.set_update_generate_proof(leaf_index, different_custom_block).unwrap();
    let new_root = tree.verify_proof(leaf_index, updated_proof).unwrap().unwrap();
    assert_eq!(new_root, tree.get_root_data().unwrap());
    assert_eq!(new_root, updated_root);
    assert_ne!(new_root, original_root_data);
    

Docs

cargo doc --release

Tests

cargo test --release

lemerk's People

Contributors

labormedia avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.