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

@zktools/fields

v0.1.0

Published

Limb-based BN254 finite field arithmetic in Montgomery form — pure JavaScript, zero runtime dependencies

Downloads

19

Readme

@zktools/fields

CI

BN254 finite field arithmetic in pure JavaScript — no WASM, no native addons, no eval.

Implements Fr (scalar field), Fp (base field), and Fp2 (quadratic extension) using a 10 × 26-bit limb representation in Montgomery form (CIOS). Zero runtime dependencies.

Status: experimental. Not production-hardened, not audited. Built to find the JS runtime ceiling for this class of problem.

Install

npm install @zktools/fields

Quick example

import { Fr, Fp, Fp2, batchInverse } from "@zktools/fields";

const a = Fr.fromBigInt(12345n);
const b = Fr.fromBigInt(67890n);

Fr.toBigInt(Fr.mul(a, b));
Fr.toBigInt(Fr.inv(a));

batchInverse([a, b], Fr); // 3(n-1) muls + 1 inv

Zero-alloc offset API

Fr and Fp expose mulInto, sqrInto, addInto, subInto. These operate inside a pre-allocated FieldBuf with no per-op allocation. Use this when throughput matters and you can manage buffer lifetimes manually.

import { Fr, allocFieldBuf, writeElement, readElement, ELEMENT_STRIDE } from "@zktools/fields";

const buf = allocFieldBuf(3); // slots 0, 1, 2
writeElement(buf, 1, Fr.fromBigInt(111n));
writeElement(buf, 2, Fr.fromBigInt(222n));

// slot 1 × slot 2 → slot 0, no allocation
Fr.mulInto(buf, 0 * ELEMENT_STRIDE, 1 * ELEMENT_STRIDE, 2 * ELEMENT_STRIDE);

Fr.toBigInt(readElement(buf, 0));

Note: addInto and subInto produce values in [0, 2p). Call toBigInt at boundaries to normalise.

Performance

Measured with tinybench on Node.js 22 (2 s per task, 1 k warmup iterations).

Standard API

| Operation | ops/sec | |-----------|--------:| | Fr.mul | 804,000 | | Fr.sqr | 502,000 | | Fr.inv | 1,920 | | Fr.add | 3,360,000 | | Fr.sub | 3,550,000 | | Fp.mul | 796,000 | | Fp.sqr | 517,000 | | Fp.inv | 2,014 | | Fp2.mul | 187,000 |

Offset API (zero allocation)

| Operation | ops/sec | |-----------|--------:| | Fr.mulInto | 1,083,000 | | Fr.sqrInto | 553,000 | | Fr.addInto | 9,269,000 |

When to use

  • Serverless / embedded environments where WASM is unavailable or restricted. Any JS runtime works.
  • Batch inversion over Fr or Fp without pulling in a full curve library. @noble/curves exposes no equivalent.

API

See docs/api.md for full reference.

Exports

| Export | Description | |--------|-------------| | Fr | BN254 scalar field | | Fp | BN254 base field | | Fp2 | Quadratic extension Fp[u] / (u² + 1) | | batchInverse(els, field) | 3(n-1) muls + 1 inv across a batch | | makeField(m, mu0, r2, mulKernel, sqrKernel) | Custom modulus field | | allocFieldBuf(n) | Allocate a flat buffer for n elements | | readElement(buf, i) | Zero-copy subarray view of element i | | writeElement(buf, i, el) | Write element i into buf | | ELEMENT_STRIDE | Limbs per element (10) |

Fr and Fp implement FieldOps. Fp2 implements Fp2Ops.

Environments

Node ≥ 20, browser (ESM + CJS), Cloudflare Workers, Deno, Bun, Hermes.

Internals

Implementation notes and algorithm derivations:

License

MIT