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

@platus-xyz/poseidon2

v0.0.4

Published

High-performance Poseidon2 hash function for BN254

Readme

@platus-xyz/poseidon2

A high-performance, pure TypeScript implementation of the Poseidon2 hash function over the BN254 scalar field, optimized for zero-knowledge proof systems.

It is a modern algebraic hash function designed specifically for ZK systems like SNARKs, STARKs, Plonk, and Halo2. Unlike SHA-256 or Keccak, it operates directly over finite fields, making it significantly more efficient inside arithmetic circuits.


Why Poseidon2?

Poseidon2 improves on the original Poseidon design with fewer constraints and faster execution without sacrificing security.

| Property | Poseidon | Poseidon2 | | ------------------ | ---------- | ----------------------------- | | External matrix | Cauchy MDS | Optimized M4 (additions only) | | Internal matrix | Full MDS | Diagonal + identity | | Constraint count | Higher | ~30% fewer | | Native performance | Moderate | Faster | | Security margin | Strong | Strong (unchanged) |


Installation

# bun
bun add @platus-xyz/poseidon2

# pnpm
pnpm add @platus-xyz/poseidon2

# npm
npm install @platus-xyz/poseidon2

Quick Start

import {
  poseidon2Hash,
  poseidon2Permutation,
  poseidon2HashAsync,
  bn254Field
} from '@platus-xyz/poseidon2';

// Basic hash
const hash = poseidon2Hash([0n, 1n, 2n]);

// Raw permutation (advanced usage)
const state = poseidon2Permutation([0n, 1n, 2n, 3n], bn254Field);

// Async hashing (non-blocking in browsers)
const result = await poseidon2HashAsync(largeArray);

API

Hashing

poseidon2Hash(inputs: bigint[]): bigint

Deterministic hash of fixed-length inputs.

poseidon2HashAsync(inputs: bigint[]): Promise<bigint>

Async version that avoids blocking the event loop.

poseidon2HashVarLen(inputs: bigint[]): bigint

Variable-length hash with domain separation.

poseidon2HashMulti(inputs: bigint[], outLen: number): bigint[]

Multi-output hash (sponge squeeze).


Permutation

poseidon2Permutation(state: bigint[], F: F1Field): bigint[]

Low-level Poseidon2 permutation over a 4-element state.

Use this only if you're building custom constructions.


Sponge API

FieldSponge

Fine-grained control over absorb/squeeze phases:

import { FieldSponge } from '@platus-xyz/poseidon2';

const sponge = new FieldSponge(domainIV);

sponge.absorb(value1);
sponge.absorb(value2);

const output = sponge.squeeze();

Usage Patterns

Merkle Tree

const parent = poseidon2Hash([left, right]);

Parameters

| Parameter | Value | | --------------- | ------------------ | | Field | BN254 scalar field | | State width (t) | 4 | | S-box | x⁵ | | Full rounds | 8 (4 + 4) | | Partial rounds | 56 | | Total rounds | 64 | | Rate | 3 | | Capacity | 1 |


Security

Design Guarantees

Poseidon2 is designed to resist:

  • Algebraic attacks (e.g. Gröbner basis, interpolation)
  • Differential & linear cryptanalysis
  • Statistical distinguishers

The round structure (8 full + 56 partial) provides a conservative security margin.


Constants

  • Deterministically generated
  • Compatible with common ZK ecosystems (Circom, Noir, etc.)
  • No hidden randomness or backdoors

Performance

Run benchmarks:

bun bench

Example Results

| Operation | Throughput | Latency | | ----------------- | --------------- | -------- | | Permutation (t=4) | ~14,160 ops/sec | 70.6 µs | | Hash (1 input) | ~14,420 ops/sec | 69.3 µs | | Hash (2 inputs) | ~16,500 ops/sec | 60.6 µs | | Hash (3 inputs) | ~17,720 ops/sec | 56.4 µs | | Hash (4 inputs) | ~8,860 ops/sec | 112.9 µs | | Hash (8 inputs) | ~5,550 ops/sec | 180.0 µs | | Hash (16 inputs) | ~2,410 ops/sec | 414.7 µs | | Hash (32 inputs) | ~1,280 ops/sec | 779.5 µs |


License

MIT


Contributing

Feel free to open a PR or discussion.