or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

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

tessl/npm-ecurve

Elliptic curve cryptography library for JavaScript with support for Bitcoin, Litecoin and other cryptocurrency curves

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/ecurve@1.0.x

To install, run

npx @tessl/cli install tessl/npm-ecurve@1.0.0

index.mddocs/

ecurve

ecurve is an elliptic curve cryptography library for JavaScript that works in both Node.js and browsers. It provides comprehensive elliptic curve functionality including curve definitions, point operations, and named curve access specifically designed for cryptocurrency applications like Bitcoin and Litecoin.

Package Information

  • Package Name: ecurve
  • Package Type: npm
  • Language: JavaScript
  • Installation: npm install ecurve

Core Imports

const ecurve = require('ecurve');
const { Curve, Point, getCurveByName } = ecurve;

For ES6:

import ecurve from 'ecurve';
import { Curve, Point, getCurveByName } from 'ecurve';

Basic Usage

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

// Get a predefined curve by name
const curve = ecurve.getCurveByName('secp256k1'); // Bitcoin curve

// Create a point from coordinates
const point = ecurve.Point.fromAffine(curve, 
  new BigInteger('79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798', 16),
  new BigInteger('483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8', 16)
);

// Perform scalar multiplication
const privateKey = new BigInteger('18e14a7b6a307f426a94f8114701e7c8e774e7f9a47e2c2035db29a206321725', 16);
const publicKey = curve.G.multiply(privateKey);

console.log(publicKey.getEncoded().toString('hex'));

Architecture

ecurve is built around three core components:

  • Curve Class: Defines elliptic curve parameters and provides curve-specific operations like point validation and recovery
  • Point Class: Represents elliptic curve points in Jacobian coordinates with support for all standard point operations
  • Named Curves: Predefined curve configurations for standard curves including Bitcoin's secp256k1

Capabilities

Elliptic Curve Operations

Core elliptic curve functionality for creating curves, validating points, and performing curve-specific operations.

/**
 * Creates an elliptic curve with the specified domain parameters
 * @param {BigInteger} p - Prime modulus of the finite field
 * @param {BigInteger} a - Curve parameter a in equation y² = x³ + ax + b
 * @param {BigInteger} b - Curve parameter b in equation y² = x³ + ax + b
 * @param {BigInteger} Gx - X coordinate of generator point
 * @param {BigInteger} Gy - Y coordinate of generator point
 * @param {BigInteger} n - Order of the generator point
 * @param {BigInteger} h - Cofactor of the curve
 */
function Curve(p, a, b, Gx, Gy, n, h);

Elliptic Curve Operations

Point Operations

Comprehensive point arithmetic for elliptic curve points including addition, doubling, scalar multiplication, and encoding/decoding.

/**
 * Creates an elliptic curve point in Jacobian coordinates
 * @param {Curve} curve - The curve this point belongs to
 * @param {BigInteger} x - X coordinate in Jacobian representation
 * @param {BigInteger} y - Y coordinate in Jacobian representation
 * @param {BigInteger} z - Z coordinate in Jacobian representation
 */
function Point(curve, x, y, z);

/**
 * Creates point from affine coordinates
 * @param {Curve} curve - The curve for this point
 * @param {BigInteger} x - X coordinate in affine representation
 * @param {BigInteger} y - Y coordinate in affine representation
 * @returns {Point} Point in Jacobian coordinates
 */
Point.fromAffine = function(curve, x, y);

Point Operations

Named Curve Access

Factory function for accessing predefined standard elliptic curves used in cryptographic applications.

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

Named Curves

Types

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