or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

curve-operations.mdindex.mdnamed-curves.mdpoint-operations.md
tile.json

named-curves.mddocs/

Named Curves

Factory function for accessing predefined standard elliptic curves used in cryptographic applications. The library includes definitions for commonly used curves in cryptocurrency and general cryptographic applications.

Capabilities

Get Curve by Name

Returns a curve instance for a predefined curve name, or null if the curve name is not recognized.

/**
 * Returns curve instance for predefined curve name
 * @param {string} name - Name of the curve
 * @returns {Curve|null} Curve instance or null if unknown curve name
 */
function getCurveByName(name);

Usage Example:

const ecurve = require('ecurve');

// Get Bitcoin curve
const secp256k1 = ecurve.getCurveByName('secp256k1');
if (secp256k1) {
  console.log('Bitcoin curve loaded');
  console.log('Generator point:', secp256k1.G.toString());
}

// Get NIST P-256 curve
const secp256r1 = ecurve.getCurveByName('secp256r1');
if (secp256r1) {
  console.log('NIST P-256 curve loaded');
}

// Handle unknown curve
const unknown = ecurve.getCurveByName('nonexistent');
console.log(unknown); // null

Supported Curves

The library includes the following predefined elliptic curves:

secp256k1

/**
 * Bitcoin and Ethereum curve - 256-bit Koblitz curve
 * Used by: Bitcoin, Ethereum, many cryptocurrencies
 */
const secp256k1 = getCurveByName('secp256k1');

The secp256k1 curve is defined by the equation y² = x³ + 7 over a 256-bit prime field. This is the curve used by Bitcoin and many other cryptocurrencies.

Usage Example:

const ecurve = require('ecurve');
const BigInteger = require('bigi');

const curve = ecurve.getCurveByName('secp256k1');

// Generate a private key (random 256-bit number)
const privateKey = new BigInteger('18e14a7b6a307f426a94f8114701e7c8e774e7f9a47e2c2035db29a206321725', 16);

// Generate corresponding public key
const publicKey = curve.G.multiply(privateKey);

// Get public key in compressed format (33 bytes)
const compressedPubKey = publicKey.getEncoded(true);
console.log('Compressed public key:', compressedPubKey.toString('hex'));

secp256r1

/**
 * NIST P-256 curve - 256-bit NIST recommended curve
 * Also known as: prime256v1, P-256
 * Used by: TLS, many government applications
 */
const secp256r1 = getCurveByName('secp256r1');

secp192k1

/**
 * 192-bit Koblitz curve
 * Smaller key size, faster operations but lower security
 */
const secp192k1 = getCurveByName('secp192k1');

secp192r1

/**
 * NIST P-192 curve - 192-bit NIST recommended curve
 * Also known as: prime192v1, P-192
 */
const secp192r1 = getCurveByName('secp192r1');

secp160k1

/**
 * 160-bit Koblitz curve
 * Lower security, suitable for constrained environments
 */
const secp160k1 = getCurveByName('secp160k1');

secp160r1

/**
 * 160-bit NIST recommended curve
 * Lower security, suitable for constrained environments
 */
const secp160r1 = getCurveByName('secp160r1');

secp128r1

/**
 * 128-bit NIST recommended curve
 * Minimal security, suitable for very constrained environments
 */
const secp128r1 = getCurveByName('secp128r1');

Curve Comparison

Curve NameBit LengthTypePrimary Use CaseSecurity Level
secp256k1256KoblitzBitcoin, EthereumHigh
secp256r1256NISTTLS, GovernmentHigh
secp192k1192KoblitzLegacy cryptoMedium
secp192r1192NISTLegacy systemsMedium
secp160k1160KoblitzConstrained devicesLow
secp160r1160NISTConstrained devicesLow
secp128r1128NISTVery constrainedMinimal

Usage Example:

const ecurve = require('ecurve');

// Compare different curves
const curves = ['secp256k1', 'secp256r1', 'secp192k1'];

curves.forEach(name => {
  const curve = ecurve.getCurveByName(name);
  if (curve) {
    console.log(`${name}:`);
    console.log(`  Field size: ${curve.p.bitLength()} bits`);
    console.log(`  Order: ${curve.n.bitLength()} bits`);
    console.log(`  Cofactor: ${curve.h.toString()}`);
    console.log(`  Generator: (${curve.G.affineX.toString(16)}, ${curve.G.affineY.toString(16)})`);
    console.log('');
  }
});

Types

/**
 * All supported curve names
 */
type CurveName = 'secp128r1' | 'secp160k1' | 'secp160r1' | 'secp192k1' | 'secp192r1' | 'secp256k1' | 'secp256r1';

/**
 * Curve categories
 */
type KoblitzCurve = 'secp160k1' | 'secp192k1' | 'secp256k1';
type NISTCurve = 'secp128r1' | 'secp160r1' | 'secp192r1' | 'secp256r1';