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 🙏

© 2026 – Pkg Stats / Ryan Hefner

proofbridge-mmr

v1.0.8

Published

Merkle Mountain Range implementation compatible with Solidity, using Poseidon2 hashing and LevelDB persistence

Readme

ProofBridge MMR

A TypeScript implementation of Merkle Mountain Range (MMR) data structure with full compatibility with Solidity implementations. Uses Poseidon2 hashing for zero-knowledge proof applications and LevelDB for persistent storage.

Features

  • Solidity Compatible - Produces identical cryptographic outputs to Solidity MMR implementations
  • Poseidon2 Hashing - Optimized for zero-knowledge proofs
  • Persistent Storage - LevelDB-backed storage for production use
  • Merkle Proofs - Generate and verify inclusion proofs
  • Type-Safe - Full TypeScript support with type definitions
  • Tested - Cross-platform verification with Solidity test suite

Installation

npm install proofbridge-mmr

Quick Start

import { MerkleMountainRange, Poseidon2Hasher, LevelDB } from "proofbridge-mmr";
import { keccak256 } from "ethers";

// Initialize database and hasher
const db = new LevelDB("./mmr-data");
await db.init();

const hasher = new Poseidon2Hasher();
const mmr = new MerkleMountainRange("my-mmr", db, hasher);
await mmr.init();

// Hash your data (using keccak256 or any hash function)
function hashData(data: string): Buffer {
  const hash = keccak256(data);
  return Buffer.from(hash, "hex");
}

// Append leaves to the MMR
await mmr.append(hashData("0x0001"));
await mmr.append(hashData("0x0002"));
await mmr.append(hashData("0x0003"));

// Get the root
console.log("Root:", mmr.root.toString("hex"));
console.log("Width:", mmr.width);
console.log("Size:", mmr.size);

// Generate a Merkle proof
const proof = await mmr.getMerkleProof(2);
console.log("Proof:", {
  root: proof.root.toString("hex"),
  width: proof.width,
  peakBagging: proof.peakBagging.map(p => p.toString("hex")),
  siblings: proof.siblings.map(s => s.toString("hex"))
});

// Clean up
await db.close();

API Reference

MerkleMountainRange

Main MMR class for managing the tree structure.

Constructor

constructor(prefix: string, db: LevelDB, hasher: Poseidon2Hasher)
  • prefix: Namespace prefix for database keys
  • db: LevelDB instance for storage
  • hasher: Poseidon2Hasher instance

Methods

async init(): Promise<void>

Initialize the MMR by loading state from database.

async append(elem: Buffer | number | bigint): Promise<number>

Append a new leaf to the MMR.

  • Parameters: Pre-hashed data as Buffer, number, or bigint
  • Returns: Index where the element was stored
async getMerkleProof(index: number): Promise<MerkleProof>

Generate a Merkle proof for a specific index.

  • Parameters: Index of the leaf
  • Returns: MerkleProof object containing root, width, peaks, and siblings
async getPeaks(): Promise<Buffer[]>

Get all current peaks of the MMR.

  • Returns: Array of peak hashes

Properties

  • root: Buffer - Current root hash
  • width: number - Number of leaves in the MMR
  • size: number - Total number of nodes (including internal nodes)

Poseidon2Hasher

Hasher implementation using Poseidon2.

const hasher = new Poseidon2Hasher();
const hash = hasher.hash([data1, data2]);

LevelDB

Persistent storage backend.

const db = new LevelDB("./data-path");
await db.init();
// ... use db
await db.close();

How It Works

Merkle Mountain Range

MMR is an append-only Merkle tree structure that forms "peaks" as elements are added:

Appending 10 items creates:
             15
      7             14
   3     6      10      13      18
 1  2  4  5   8  9   11  12  16  17

Poseidon2 Hashing

The MMR uses Poseidon2, a ZK-friendly hash function optimized for use in zero-knowledge proof systems. All internal nodes are hashed using:

hash_2(left, right) // For internal nodes

Peak Bagging

Multiple peaks are combined into a single root using an iterative hashing process:

acc = size
acc = hash_2(size, peak[0])
acc = hash_2(acc, peak[1])
...
innerHash = acc
root = hash_2(size, innerHash)

Use Cases

  • Blockchain State Commitments - Efficient append-only commitment schemes
  • Audit Logs - Tamper-proof append-only logs with proof generation
  • Zero-Knowledge Proofs - ZK-friendly accumulator for set membership proofs
  • Cross-Chain Bridges - State synchronization between chains (e.g., Hedera)

Development

Build

npm run build

Test

npm test

Clean

npm run clean

License

MIT

Credits

This implementation builds on several open-source projects and specifications that shaped its design and cryptographic foundations:

  • Solidity-MMR by @wanseob Original reference implementation of the Merkle Mountain Range (MMR) in Solidity. Licensed under MIT.

  • Poseidon2 Library — @zkpassport/poseidon2 Used for efficient field-based Poseidon2 hashing and finite-field arithmetic. Licensed under MIT.

  • MerkleTreeJS — @miguelmota Inspiration for JavaScript-side proof generation and verification utilities. Licensed under MIT.

Contributing

Contributions welcome! This implementation is designed to maintain exact compatibility with Solidity MMR implementations, so any changes must preserve cryptographic output equivalence.