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 🙏

© 2025 – Pkg Stats / Ryan Hefner

indexed-merkle-noir

v0.0.5

Published

[Indexed Merkle Tree](https://docs.aztec.network/aztec/concepts/advanced/storage/indexed_merkle_tree) implementation in Javascript and Noir

Readme

indexed-merkle-noir

Indexed Merkle Tree implementation in Javascript and Noir

  • Keys can be max 64-bit uints
  • Values can be any field element
  • Max tree size: 2^32 items

TODO

  • Multi-inserts

Installation

$ git clone https://github.com/numtel/indexed-merkle-noir
$ cd indexed-merkle-noir
$ npm install

# Test javascript implementation
$ npm test

# Test noir implementation
$ nargo test

JavaScript Usage

The IndexedMerkleTree class provides methods to create and manage an indexed Merkle tree.

import {IndexedMerkleTree} from 'indexed-merkle-noir';

// Create a new tree
const tree = new IndexedMerkleTree();

// Insert an item (key must be bigint > 0, value must be bigint >= 0)
tree.insertItem(10n, 345n);
tree.insertItem(20n, 234n);
const transitionProof = tree.insertItem(30n, 123n);

// Generate proof for a key
const proof = tree.generateProof(20n);
// Returns { leafIdx, leaf, root, siblings }

// Generate exclusion proof (proves a key does NOT exist)
const exclusionProof = tree.generateExclusionProof(13n);
// Returns proof for neighboring key that proves 13n doesn't exist

// Verify a proof
const isValid = tree.verifyProof(proof);
const isValidInsert = tree.verifyInsertionProof(transitionProof);
// Returns true if proof is valid

IndexedMerkleTree Methods

  • constructor(): Creates a new indexed Merkle tree
  • insertItem(key, value): Inserts a new item with the given key and value
    • key: bigint greater than 0
    • value: bigint greater than or equal to 0
    • Returns insertion proof data object
  • generateProof(key): Generates a Merkle proof for the given key
    • Returns {leafIdx, leaf, root, siblings}
  • generateExclusionProof(key): Generates a proof that a key doesn't exist in the tree
    • Returns proof for a neighboring key that proves the target key doesn't exist
  • verifyProof(proof): Verifies a Merkle proof
    • Returns true if valid, false otherwise
  • verifyInsertionProof(insertionProof): Verifies an insertion proof
    • Returns true if valid, false otherwise

Noir Library Functions

The Noir library includes functions for verifying proofs generated by the JavaScript implementation:

verifyProof

Verifies that a leaf with the given properties exists in the Merkle tree.

fn verifyProof(
    leafIdx: u32,
    leafKey: u64,
    leafNextIdx: u32,
    leafNextKey: u64,
    leafValue: Field,
    root: Field,
    siblings: [Field; 32]
)

verifyExclusionProof

Verifies that a key does NOT exist in the Merkle tree.

fn verifyExclusionProof(
    leafIdx: u32,
    leafKey: u64,
    leafNextIdx: u32,
    leafNextKey: u64,
    leafValue: Field,
    root: Field,
    siblings: [Field; 32],
    excludedKey: u64
)

This function verifies:

  1. The proof is valid (calls verifyProof)
  2. The excluded key is greater than the leaf key
  3. The excluded key is less than the next key (if next key exists)

verifyInsertionProof

Verifies that the tree root state transition is valid for the given insertion

fn verifyInsertionProof(
    ogLeafIdx: u32,
    ogLeafKey: u64,
    ogLeafNextIdx: u32,
    ogLeafNextKey: u64,
    ogLeafValue: Field,
    newLeafIdx: u32,
    newLeafKey: u64,
    newLeafValue: Field,
    rootBefore: Field,
    rootAfter: Field,
    siblingsBefore: [Field; 32],
    siblingsAfterOg: [Field; 32],
    siblingsAfterNew: [Field; 32]
)

This function verifies:

  1. All three individual proofs must be valid
  2. Sibling arrays for both leaves are same length
  3. The "sub-roots" of both changed leaves match

License

MIT