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

@zgdb/prolly-tree

v0.0.2

Published

A TypeScript implementation of a Prolly Tree (Probabilistic B-Tree), a content-addressed data structure that provides history-independent, verifiable storage for key-value data.

Readme

@tk/prolly-tree

A TypeScript implementation of a Prolly Tree (Probabilistic B-Tree), a content-addressed data structure that provides history-independent, verifiable storage for key-value data.

This structure is ideal for applications requiring verifiable, tamper-proof data storage, such as decentralized databases, version control systems, and secure logs.

Features

  • Content-Addressable: Each node in the tree is identified by the hash of its content, making the entire structure self-verifying.
  • History-Independent: The final state of the tree (and its root hash) is identical regardless of the order in which data is inserted. Two users with the same dataset will always produce the exact same tree.
  • Efficient Storage: Uses content-defined chunking to efficiently store and update large values.
  • Fast Lookups: Logarithmic time complexity for gets, puts, and deletes.

Installation

pnpm install @tk/prolly-tree

API Design Proposal

The primary interface for the library is the ProllyTree class.

Creating and Loading a Tree

A tree is always associated with a BlockManager for handling the underlying storage of nodes.

ProllyTree.create(blockManager)

Creates a new, empty Prolly Tree.

Arguments:

  • blockManager: An instance of BlockManager. The tree will use the configuration associated with this manager.

Returns: Promise<ProllyTree>

Example:

import { ProllyTree } from "@tk/prolly-tree";
import { BlockManager } from "@tk/prolly-tree";

// The BlockManager will merge this partial config with the default configuration.
const config = {
  hashingAlgorithm: "sha2-256",
};

const blockManager = new BlockManager(config);
const tree = await ProllyTree.create(blockManager);

ProllyTree.load(rootAddress, blockManager)

Loads an existing tree from a known root address.

Arguments:

  • rootAddress: The Address (hash) of the tree's root node.
  • blockManager: An instance of BlockManager. The configuration of this manager must be compatible with the configuration used to create the tree.

Returns: Promise<ProllyTree>

Example:

const knownRootAddress = // ... get a root hash from somewhere
const tree = await ProllyTree.load(knownRootAddress, blockManager);

Reading and Writing Data

Once you have a ProllyTree instance, you can get and put key-value pairs. All keys and values are Uint8Array.

The put operation is immutable. It does not change the existing tree instance but instead returns a new ProllyTree instance representing the state of the tree after the insertion.

tree.put(key, value)

Inserts a key-value pair into the tree.

Returns: Promise<{ tree: ProllyTree; changed: boolean }> - An object containing the new tree instance and a boolean indicating if the operation resulted in a change.

Example:

import { fromString } from "uint8arrays/from-string";

const key = fromString("hello");
const value = fromString("world");

const { tree: newTree, changed } = await tree.put(key, value);

console.log(`Tree was changed: ${changed}`);

// The original tree instance is unchanged
console.log("Original root:", tree.root);
console.log("New root:     ", newTree.root);

tree.get(key)

Retrieves the value associated with a key.

Returns: Promise<Uint8Array | undefined> - The value if the key exists, otherwise undefined.

Example:

const value = await newTree.get(key);
if (value) {
  console.log(new TextDecoder().decode(value)); // "world"
}

tree.root

A getter property that returns the Address (hash) of the current root node of the tree. This address is the single identifier for the tree's entire state and can be used with ProllyTree.load to reconstruct it later.

Returns: Address

Example:

const rootHash = newTree.root;
// You can now store or transmit this rootHash