UNPKG

functionalscript

Version:

FunctionalScript is a purely functional subset of JavaScript

77 lines (76 loc) 2.15 kB
import type { Reduce } from '../../types/function/operator/module.f.ts'; import { type PrimeField } from '../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. */ type Curve = { readonly pf: PrimeField; readonly nf: PrimeField; readonly y2: (x: bigint) => bigint; readonly y: (x: bigint) => bigint | null; readonly neg: (a: Point) => Point; readonly add: Reduce<Point>; readonly mul: (a: Point) => (n: 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 }: Init) => Curve; export declare const eq: (a: Point) => (b: Point) => boolean; /** * https://neuromancer.sk/std/secg/secp192r1 */ export declare const secp192r1: Init; /** * https://en.bitcoin.it/wiki/Secp256k1 * https://neuromancer.sk/std/secg/secp256k1 */ export declare const secp256k1: Init; /** * https://neuromancer.sk/std/secg/secp256r1 */ export declare const secp256r1: Init; /** * https://neuromancer.sk/std/secg/secp384r1 */ export declare const secp384r1: Init; /** * https://neuromancer.sk/std/secg/secp521r1 */ export declare const secp521r1: Init; export {};