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.
Or a Polkadot key
sr25519 has an entry too, with the //Alice of every Substrate dev chain one derivation away:
import { deriveHard, expandSeed, getPublicKey } from "@agntn/curves/sr25519";
const root = expandSeed("fac7959dbfe72f052e5a0c3c8d6530f202b02fd8f9f5ca3580ec8deb7797479e");
getPublicKey(deriveHard(root, "14416c696365".padEnd(64, "0"))); // "d43593c715fdd31c…a27d"
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, ECDSA and BIP340 signatures.
- sr25519: Polkadot keys, signatures and HDKD.
- ed25519: RFC 8032 points, Monero's subgroup check and Ed25519 signatures.
- Ed448: Ed448 signatures, verify only. Bring the context.
- P-256: Point math and ECDSA, signing included.
- P-384: The same, 48 bytes wide.
- P-521: The same again, 66 bytes wide. Yes, 521.
- brainpoolP256r1: Same point sizes as P-256, different curve. Don't trust the length.
- brainpoolP384r1: Same point lengths as P-384. Length doesn't identify the curve.
- brainpoolP512r1: Its point length has no twin here.
- CLI and Agents: the same math from a terminal or a model.