Git Product home page Git Product logo

content-hash-tree's Introduction

@dcl/content-hash-tree

NPM version Install Size

Idea from @uniswap/merkle-distributor

Local Development

The following assumes the use of node@>=10.

Install Dependencies

npm ci

Lib

Generate a tree

import { generateTree } from '@dcl/content-hash-tree'

const contentHashes = ['hash1', 'hash2', 'hash3']

const tree = generateTree(contentHashes)

Verify whether a contnet hash is part of the tree or not

import { verifyProof } from '@dcl/content-hash-tree'

const contentHashes = ['hash1', 'hash2', 'hash3']
const proof = tree.getProof(0, contentHashes[0])
const root = tree.getHexRoot()

const isPartOfTheTree = verifyProof(0, contentHashes[0], proof, root)

CLI (Benchmark)

Generate a tree with content hashes

npm run generate-merkle-root:data

~10k items: time to completion 788.8ms. Json size: 10mb ~100k items: time to completion 6.7s. Json size: 124mb

This will generate a proofs.json file in the root of the project.

Verify a single proof of a tree with ~100k leafs

npm run verify-merkle-root:proof

Time to completion 9.294ms. Json size: 4kb

content-hash-tree's People

Contributors

nachomazzara 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.