Code Monkey home page Code Monkey logo

merkletools-solidity's Introduction

MerkleTools

MerkleTools-solidity is a .NET library to create and validate Merkle trees and receipts compatible with @openzeppelin/contracts/utils/cryptography/MerkleProof.sol using keccak256 hash algorithm.

How to use?

With nuget :

Install-Package MerkleTools-solidity

Go on the nuget website for more information.

Example

using MerkleTools;
using System.Text;

MerkleTree tree = new MerkleTree();

string[] addresses = {  "0xa18FBe02d2f247922a8e7A9B3962cfd3b8aEE0Ca", 
                        "0x5B38Da6a701c568545dCfcB03FcB875f56beddC4", 
                        "0x25f7fF7917555132eDD3294626D105eA1C797250", 
                        "0xF6574D878f99D94896Da75B6762fc935F34C1300"};

for (int i = 0; i < addresses.Length; i++)
{
    byte[] temp = Encoding.ASCII.GetBytes(addresses[i]);
    tree.AddLeaf(temp, true);
}

var root = Encoding.UTF8.GetString(tree.MerkleRootHash);
Console.WriteLine(root);

//0x2bd66355c24f675a8a9411593198b3aacaec256d58a2ce950c798b7e9a378f28


var proof = tree.GetProof(0);
Console.WriteLine(proof.ToJson());

/*[ "0x5931b4ed56ace4c46b68524cb5bcbf4195f1bbaacbe5228fbd090546c88dd229",
    "0x1f957db768cd7253fad82a8a30755840d536fb0ffca7c5c73fe9d815b1bc2f2f"]*/


var address = Encoding.ASCII.GetBytes(addresses[0]);
var addressHash = MerkleTree.keccakFromByte(address);
var isValid = tree.ValidateProof(proof, addressHash);
Console.WriteLine(isValid); //true

Contact

Contact [email protected] with questions

merkletools-solidity's People

Contributors

erentl avatar lontivero 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.