functionalscript
Version:
FunctionalScript is a purely functional subset of JavaScript
80 lines (79 loc) • 2.2 kB
TypeScript
import type { Equal, Fold, Reduce } from '../../types/function/operator/module.f.ts';
import { type PrimeField } from '../../types/prime_field/module.f.ts';
/**
* A 2D point represented as a pair of `bigint` values `[x, y]`.
*/
type Point2D = readonly [bigint, bigint];
/**
* A 2D point on an elliptic curve, represented as a pair of `bigint` values.
* `null` represents the point at infinity (`O`).
*/
export type Point = Point2D | null;
/**
* Initialization parameters for an elliptic curve.
*/
export type Init = {
readonly p: bigint;
readonly a: readonly [bigint, bigint];
readonly g: readonly [bigint, bigint];
readonly n: bigint;
};
/**
* Represents an elliptic curve and its associated operations.
*/
export type Curve = {
readonly pf: PrimeField;
readonly nf: PrimeField;
readonly g: Point;
readonly y2: (x: bigint) => bigint;
readonly y: (x: bigint) => bigint | null;
readonly neg: (a: Point) => Point;
readonly add: Reduce<Point>;
readonly mul: Fold<bigint, Point>;
};
/**
* Constructs an elliptic curve with the given initialization parameters.
*
* @example
*
* ```js
* const curveParams = {
* p: 23n,
* a: [0n, 1n],
* g: [1n, 1n],
* n: 19n
* };
* const curveInstance = curve(curveParams);
*
* // Access curve operations
* const point = curveInstance.add([1n, 1n])([2n, 5n]); // Add two points
* const negPoint = curveInstance.neg([1n, 1n]); // Negate a point
* const mulPoint = curveInstance.mul([1n, 1n])(3n); // Multiply a point by 3
* ```
*/
export declare const curve: ({ p, a: [a0, a1], n, g }: Init) => Curve;
export declare const eq: Equal<Point>;
/**
* https://neuromancer.sk/std/secg/secp192r1
* NIST P-192
*/
export declare const secp192r1: Curve;
/**
* https://en.bitcoin.it/wiki/Secp256k1
* https://neuromancer.sk/std/secg/secp256k1
*/
export declare const secp256k1: Curve;
/**
* https://neuromancer.sk/std/secg/secp256r1
* NIST P-256
*/
export declare const secp256r1: Curve;
/**
* https://neuromancer.sk/std/secg/secp384r1
*/
export declare const secp384r1: Curve;
/**
* https://neuromancer.sk/std/secg/secp521r1
*/
export declare const secp521r1: Curve;
export {};