---
title: "Getting started"
description: "Install @agntn/curves and define a curve and count its points and find a discrete log in a few lines"
canonical_url: "https://curves.agntn.dev/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

```bash
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.

<caution title="Not audited">

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. Multiplying by a secret on secp256k1, P-256, P-384, P-521, brainpoolP256r1, brainpoolP384r1, brainpoolP512r1, ed25519, ristretto255 and sr25519 takes the same steps for every scalar. Your own curves don't.

</caution>

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

## Or a Polkadot key

sr25519 has an entry too, with the `//Alice` of every Substrate dev chain one derivation away:

```ts
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](https://curves.agntn.dev/math/curves): defining a curve and doing arithmetic on it.
- [Orders and logs](https://curves.agntn.dev/math/groups): counting, listing, orders, discrete logs and their limits.
- [secp256k1](https://curves.agntn.dev/math/secp256k1): SEC1 points, scalars mod n, lifting x, ECDSA and BIP340 signatures.
- [sr25519](https://curves.agntn.dev/math/sr25519): Polkadot keys, signatures and HDKD.
- [ed25519](https://curves.agntn.dev/math/ed25519): RFC 8032 points, Monero's subgroup check and Ed25519 signatures.
- [Ed448](https://curves.agntn.dev/math/ed448): Ed448 signatures, verify only. Bring the context.
- [P-256](https://curves.agntn.dev/math/p256): Point math and ECDSA, signing included.
- [P-384](https://curves.agntn.dev/math/p384): The same, 48 bytes wide.
- [P-521](https://curves.agntn.dev/math/p521): The same again, 66 bytes wide. Yes, 521.
- [brainpoolP256r1](https://curves.agntn.dev/math/brainpoolp256r1): Same point sizes as P-256, different curve. Don't trust the length.
- [brainpoolP384r1](https://curves.agntn.dev/math/brainpoolp384r1): Same point lengths as P-384. Length doesn't identify the curve.
- [brainpoolP512r1](https://curves.agntn.dev/math/brainpoolp512r1): Its point length has no twin here.
- [CLI](https://curves.agntn.dev/guide/cli) and [Agents](https://curves.agntn.dev/guide/agents): the same math from a terminal or a model.


## Sitemap

See the full [sitemap](https://curves.agntn.dev/sitemap.md) for all pages.
