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

@ada-anvil/merkle

v0.0.0

Published

TypeScript utilities for working with Merkle trees

Readme

@ada-anvil/merkle

TypeScript utilities for working with Merkle trees.

Installation

npm install @ada-anvil/merkle

Optional peer dependency

If using the CSL implementation:

npm install @emurgo/cardano-serialization-lib-nodejs-gc

Entry points

@ada-anvil/merkle

Core functions and factory primitives. No peer dependencies.

import {
  createMerkleTree,
  buildTree,
  getProof,
  verifyProof,
} from "@ada-anvil/merkle";

@ada-anvil/merkle/crypto

Merkle tree implementations using node:crypto (Node.js only).

import {
  createCryptoMerkleTree,
  createCryptoSerialMerkleTree,
} from "@ada-anvil/merkle/crypto";

@ada-anvil/merkle/csl

Merkle tree implementations using @emurgo/cardano-serialization-lib-nodejs-gc. Requires the Emurgo library as an optional peer dependency.

import {
  createCslMerkleTree,
  createCslSerialMerkleTree,
} from "@ada-anvil/merkle/csl";

Usage

Merkle tree (arbitrary elements)

import { createCryptoMerkleTree } from "@ada-anvil/merkle/crypto";

// Create tree from UUIDs
const uuids = [
  "550e8400-e29b-41d4-a716-446655440000",
  "6ba7b810-9dad-11d1-80b4-00c04fd430c8",
  "6ba7b811-9dad-11d1-80b4-00c04fd430c8",
  "6ba7b812-9dad-11d1-80b4-00c04fd430c8",
];

const tree = createCryptoMerkleTree(uuids);

// Get root
const root = tree.getRoot();

// Generate proof for element
const proof = tree.getProof(uuids[1]);

// Verify proof
if (proof) {
  const isValid = tree.verifyProof(uuids[1], proof);
  console.log(isValid); // true
}

// Get leaf node
const leaf = tree.getLeaf(uuids[0]);
console.log(leaf); // { node: Buffer, index: 0 }

// Get sibling
const sibling = tree.getSibling(leaf.index);

Serial Merkle tree (consecutive integers)

import { createCryptoSerialMerkleTree } from "@ada-anvil/merkle/crypto";

// Create tree from consecutive integers
const ids = [1, 2, 3, 4, 5, 6, 7, 8];

const tree = createCryptoSerialMerkleTree(ids);

if (tree) {
  // Get root
  const root = tree.getRoot();

  // Generate range proof
  const rangeProof = tree.getRangeProof([3, 6]);

  // Verify range proof
  const isValid = tree.verifyRangeProof([3, 6], rangeProof);
  console.log(isValid); // true

  // Single element proof
  const singleProof = tree.getProof(5);
  if (singleProof) {
    console.log(tree.verifyProof(5, singleProof)); // true
  }
}

Custom implementation

Use the core library to build your own Merkle tree with custom hash functions:

import { createMerkleTree, type MerkleTreeConfig } from "@ada-anvil/merkle";

type CustomNode = { hash: string };
type CustomElement = { id: string; data: string };

const config: MerkleTreeConfig<CustomNode, CustomElement> = {
  elementToNode: (element) => ({
    hash: customHash(element.id + element.data),
  }),
  combineNodes: (left, right) => ({
    hash: customHash(left.hash + right.hash),
  }),
  compareNodes: (left, right) => left.hash === right.hash,
};

const elements = [
  { id: "1", data: "foo" },
  { id: "2", data: "bar" },
];

const tree = createMerkleTree(elements, config);

API

Tree instance methods

  • getRoot() - Returns the root node
  • getLeaf(element) - Returns leaf node and index for element
  • getLeaves() - Returns all leaf nodes
  • getSibling(index, layerIndex?) - Returns sibling node at index
  • getProof(element) - Generates inclusion proof for element
  • verifyProof(element, proof) - Verifies inclusion proof

Serial tree additional methods

  • getRangeProof([start, end]) - Generates proof for range of consecutive elements
  • verifyRangeProof([start, end], proof) - Verifies range proof