Bandersnatch elliptic curve primitives built on top of @noble/curves.
This package provides:
- A Bandersnatch curve instance (
Bandersnatch) configured with the official parameters. - A high-level helper class (
BandersnatchCurve) for point operations and arkworks-compatible serialization. - Public curve parameters (
BANDERSNATCH_PARAMS).
Note: VRF functionality and Elligator2 hash-to-curve are implemented in
@pbnjam/bandersnatch-vrf.
This repository uses Bun workspaces. From the monorepo root, install deps once:
bun installWithin another workspace package, add a dependency on @pbnjam/bandersnatch via the workspace tooling you use (Bun/npm/pnpm/yarn).
import { Bandersnatch, BandersnatchCurve, BANDERSNATCH_PARAMS } from '@pbnjam/bandersnatch'
import type { CurvePoint } from '@pbnjam/bandersnatch'BandersnatchCurve exposes common operations over Noble Bandersnatch points (EdwardsPoint from @noble/curves), such as:
GENERATOR: the canonical generator pointINFINITY: point at infinity (identity)add(P, Q),negate(P),scalarMultiply(P, k)
import { BandersnatchCurve } from '@pbnjam/bandersnatch'
const P = BandersnatchCurve.GENERATOR
const Q = BandersnatchCurve.scalarMultiply(P, 2n)
const R = BandersnatchCurve.add(P, Q)
const negR = BandersnatchCurve.negate(R)
// Access affine coordinates (BigInt) via Noble helpers
const { x, y } = R.toAffine()
void x
void yThe helper methods are intended to be compatible with arkworks’ Twisted Edwards compression format.
import { Bandersnatch, BandersnatchCurve } from '@pbnjam/bandersnatch'
// Noble point → compressed bytes (arkworks-compatible)
const noblePoint = Bandersnatch.BASE
const compressed = BandersnatchCurve.pointToBytes(noblePoint)
// Compressed bytes → Noble point (throws on invalid encoding)
const parsed = BandersnatchCurve.bytesToPoint(compressed)From src/index.ts:
BandersnatchCurveBandersnatchBANDERSNATCH_PARAMSCurvePoint(type)
CurvePoint is a simple structural representation used by some algorithms (notably @pbnjam/bandersnatch-vrf’s Elligator2 hash-to-curve helpers):
x: biginty: bigintisInfinity: boolean
All protocol constants are defined in src/config.ts as BANDERSNATCH_PARAMS (field modulus, curve order, generator, coefficients, and related configuration used by dependent packages).
From packages/bandersnatch:
bun run testbun run buildBandersnatchCurveuses BigInt arithmetic and performs modular operations over the Bandersnatch field.- When handling serialized points, treat all external inputs as untrusted and rely on parsing/validation helpers (avoid manual decoding).