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

fummpel

v0.0.4

Published

## API

Downloads

37,202

Readme

Usage

API

TokenIDs

Main class representing a set of token IDs as BigInts. Construct either with a list / set of BigInts or decode from compressed bytes.

Generate Merkle tree roots / multi-proofs with root() and proof(...) and retrieve a compact binary representation with 'encode()`

new TokenIDs(tokenIDs: Iterable<bigint>)

Create a new list of tokens from any Iterable, e.g. Set / Array. Token IDs must be 256-bit BigInts

TokenIDs.decode(bytes: Uint8Array): TokenIDs

Decode tokens from a compressed byte stream.

encode()

Gets compressed binary representation of all token IDs

proof(subset: Iterable<bigint>)

Generates Merkle multi-proof for subset of token IDs

root()

Gets Merkle tree root hash

tokens()

Gets list of token IDs represented by this TokenIDs instance as a sorted array

verify(proof: string[], flags: boolean[], leaves: string[][]): boolean

Verify multiproof using essentially the same algo in OpenZeppelin's smart contract

Example

import { TokenIDs } from 'fummpel';

// keccak256 needs to be initialized
await TokenIDs.init();

const tokens = new TokenIDs([2n,3n,5n,7n])

// Merkle root for these 4 tokens
const root = tokens.root();
// '0xc97e9e1eb896293c19f2649c796c9a276d997cfa58164c5f25d9a3f29b894cc9'

// Merkle multiproof for 2 of the tokens
const proof = tokens.proof([2n, 5n]);
// {
//   leaves: [ 5n, 2n ],
//   proof: [
//     '0xcff8e1781584200105067c0684580a1524c9539de52c1f9889e2cf73830cfccc'
//   ],
//   proofFlags: [ true, false ]
// }

// Leaf error if token is not in tree
const bad = tokens.proof([1n]);
// Error: Leaf is not in tree

// Verify multiproof
const verified = tokens.verify(proof.proof, proof.proofFlags, proof.leaves);
// true

// Get encoded tokens list
const encoded = tokens.encoded();
// Uint8Array(2) [ ... ]

// Decode encoded tokens list
const decoded_tokens = TokenIDs.decode(encoded);
// TokenIDs { ... }

const decoded_token_ids = decoded_tokens.tokens();
// [ 2n, 3n, 5n, 7n ]

Development

npm install

Test

uvu is used for testing.

All

npm test

Single test

npx ts-node src/token_ids.test.ts

Browser Benchmark

Install parcel then parcel public/bench.html or npx parcel public/bench.html.

Build / Publish

npm run build and then npm publish --access public