npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@aztec/merkle-tree

v0.63.1

Published

## Overview

Downloads

771

Readme

Merkle Tree

Overview

The Merkle Trees package contains typescript implementations of the various Merkle Trees required by the system.

  • Append only 'Standard' merkle trees. New values are inserted into the next available leaf index. Values are never updated.
  • Indexed trees are also append only in nature but retain the ability to update leaves. The reason for this is that the Indexed Tree leaves not only store the value but the index of the next highest leaf. New insertions can require prior leaves to be updated.
  • Sparse trees that can be updated at any index. The 'size' of the tree is defined by the number of non-empty leaves, not by the highest populated leaf index as is the case with a Standard Tree.

Implementations

All implementations require the following arguments:

  • An instance of level db for storing information at a tree node level as well as some tree level metadata.
  • An instance of a Hasher object. Used for hashing the nodes of the Merkle Tree.
  • A name, for namespacing the tree's nodes within the db.
  • The depth of the tree, this is exclusive of the root.

Implementations have commit/rollback semantics with modifications stored only in memory until being committed. Rolling back returns the tree discards the cached modifications and returns the tree to it's previous committed state.

Tree Operations

The primary operations available on the various implementations are:

  • Create a new, empty tree
  • Restore a tree from the provided DB
  • Append new leaves (Standard and Indexed trees only)
  • Update a leaf (Sparse tree and Indexed trees only)
  • Retrieve the number of leaves. This is the number of non empty leaves for a Sparse tree and the highest populated index for Standard and Indexed trees.
  • Commit modifications
  • Rollback modifications
  • Retrieve a Sibling Path for a given index. For performing Merkle proofs it is necessary to derive the set of nodes from a leaf index to the root of the tree, known as the 'hash path'. Given a leaf, it is therefore required to have the 'sibling' node at each tree level in order for the hash path to be computed.

Note: Tree operations are not 'thread' safe. Operations should be queued or otherwise executed serially to ensure consistency of the data structures and any data retrieved from them.

Building/Testing

To build the package, execute yarn build in the root.

To run the tests, execute yarn test.