UNPKG

functionalscript

Version:

FunctionalScript is a purely functional subset of JavaScript

41 lines (40 loc) 1.12 kB
import type { Unary, Reduce } from '../../types/bigint/module.f.ts'; /** * A type representing a prime field and its associated operations. */ export type PrimeField = { readonly p: bigint; readonly middle: bigint; readonly max: bigint; readonly neg: Unary; readonly sub: Reduce; readonly add: Reduce; readonly abs: Unary; readonly mul: Reduce; readonly reciprocal: Unary; readonly div: Reduce; readonly pow: Reduce; readonly pow2: Unary; readonly pow3: Unary; }; /** * Creates a prime field with the specified prime modulus and associated operations. * * @param p - A prime number to define the field. * @returns The prime field object. */ export declare const prime_field: (p: bigint) => PrimeField; /** * Computes the square root of a number in a prime field. * * @throws If the prime modulus `p` does not satisfy `p % 4 == 3`. * * @example * * ```js * const field = prime_field(7n); * const root = sqrt(field)(4n); * if (root !== 2n) { throw root } * ``` */ export declare const sqrt: ({ p, mul, pow }: PrimeField) => (a: bigint) => bigint | null;