or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

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

curve-operations.mddocs/

Elliptic Curve Operations

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

Capabilities

Curve Constructor

Creates an elliptic curve with the specified domain parameters.

/**
 * 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);

Usage Example:

const BigInteger = require('bigi');
const { Curve } = require('ecurve');

// Create a custom curve (example parameters)
const p = new BigInteger('fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f', 16);
const a = new BigInteger('0', 16);
const b = new BigInteger('7', 16);
const n = new BigInteger('fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141', 16);
const h = new BigInteger('1', 16);
const Gx = new BigInteger('79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798', 16);
const Gy = new BigInteger('483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8', 16);

const curve = new Curve(p, a, b, Gx, Gy, n, h);

Point Recovery from X Coordinate

Recovers a point from its x-coordinate and a parity bit indicating whether y is odd or even.

/**
 * Recovers point from x-coordinate and parity bit
 * @param {boolean} isOdd - True if y coordinate should be odd, false if even
 * @param {BigInteger} x - X coordinate of the point
 * @returns {Point} Recovered point on the curve
 */
curve.pointFromX = function(isOdd, x);

Usage Example:

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

const curve = ecurve.getCurveByName('secp256k1');
const x = new BigInteger('79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798', 16);

// Recover point with even y coordinate
const point = curve.pointFromX(false, x);
console.log(point.affineY.isEven()); // true

Point Validation

Checks if a point is valid according to elliptic curve standards.

/**
 * Checks if point Q is the point at infinity
 * @param {Point} Q - Point to check
 * @returns {boolean} True if point is at infinity
 */
curve.isInfinity = function(Q);

/**
 * Validates that point Q lies on the curve
 * @param {Point} Q - Point to validate
 * @returns {boolean} True if point is on the curve
 */
curve.isOnCurve = function(Q);

/**
 * Full elliptic curve point validation per SEC 1 standard
 * @param {Point} Q - Point to validate
 * @returns {boolean} True if point passes all validation checks
 * @throws {Error} If validation fails
 */
curve.validate = function(Q);

Usage Example:

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

const curve = ecurve.getCurveByName('secp256k1');
const point = curve.G; // Generator point

// Check if point is at infinity
console.log(curve.isInfinity(point)); // false

// Check if point is on curve
console.log(curve.isOnCurve(point)); // true

// Perform full validation
try {
  curve.validate(point);
  console.log('Point is valid');
} catch (error) {
  console.log('Point validation failed:', error.message);
}

Curve Properties

Domain Parameters

interface CurveProperties {
  /** Prime modulus of the finite field */
  p: BigInteger;
  /** Curve parameter a in equation y² = x³ + ax + b */
  a: BigInteger;
  /** Curve parameter b in equation y² = x³ + ax + b */
  b: BigInteger;
  /** Generator point of the curve */
  G: Point;
  /** Order of the generator point */
  n: BigInteger;
  /** Cofactor of the curve */
  h: BigInteger;
  /** Point at infinity for this curve */
  infinity: Point;
  /** Cached value (p + 1) / 4 for point decompression */
  pOverFour: BigInteger;
  /** Byte length of prime p */
  pLength: number;
}