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

shell
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.

This code has never had a security audit. Do not use it in production, with real funds or with sensitive data. It is meant for agents, puzzles and local experiments only. Nothing here runs in constant time.

Your first curve

A curve here is y² = x³ + ax + b over the integers mod a prime p. Hand over a, b and p:

ts
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:

ts
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