Guide
Getting started
Install @agntn/curves and define a curve and count its points and find a discrete log in a few lines
Install it
pnpm add @agntn/curves
Node.js 26 or newer. One install gets you the library, the curves CLI and the MCP server. Nothing to configure.
Your first curve
A curve here is y² = x³ + ax + b over the integers mod a prime p. Hand over a, b and p:
import { countPoints, defineCurve, discreteLog, multiplyPoint } from "@agntn/curves";
const curve = defineCurve({ a: 2n, b: 2n, p: 17n });
countPoints(curve); // 19n
multiplyPoint(curve, { x: 5n, y: 1n }, 2n); // { x: 6n, y: 3n }
discreteLog(curve, { x: 5n, y: 1n }, { x: 16n, y: 4n }); // 13n
That's the textbook curve from Paar and Pelzl. Nineteen points with infinity. And (16, 4) is 13 times (5, 1). Want to see all nineteen? listPoints(curve) gives them by x, then y.
Everything is a bigint. The point at infinity is null. A point off the curve throws a RangeError before any arithmetic runs on it.
Or secp256k1
The real curve lives in its own entry, with points as SEC1 hex:
import { liftX, multiplyGenerator } from "@agntn/curves/secp256k1";
multiplyGenerator("03"); // "02f9308a019258c3…36f9"
liftX("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798").odd; // "0379be66…1798"
The generic code and secp256k1 never mix. Importing one doesn't load the other.
From here
- Curves and points: defining a curve and doing arithmetic on it.
- Orders and logs: counting, listing, orders, discrete logs and their limits.
- secp256k1: SEC1 points, scalars mod n, lifting x.
- CLI and Agents: the same math from a terminal or a model.