///
import { BufferReader } from '../serialize/buffer_reader';
/**
* Represents a field derived from BaseField.
*/
declare type DerivedField = {
new (value: any): T;
/**
* All derived fields will specify a MODULUS.
*/
MODULUS: bigint;
};
/**
* Base field class.
* Conversions from Buffer to BigInt and vice-versa are not cheap.
* We allow construction with either form and lazily convert to other as needed.
* We only check we are within the field modulus when initializing with bigint.
*/
declare abstract class BaseField {
static SIZE_IN_BYTES: number;
private asBuffer?;
private asBigInt?;
/**
* Return bigint representation.
* @deprecated Just to get things compiling. Use toBigInt().
* */
get value(): bigint;
/** Returns the size in bytes. */
get size(): number;
protected constructor(value: number | bigint | boolean | BaseField | Buffer);
protected abstract modulus(): bigint;
/**
* We return a copy of the Buffer to ensure this remains immutable.
*/
toBuffer(): Buffer;
toString(): string;
toBigInt(): bigint;
toBool(): boolean;
/**
* Converts this field to a number.
* Throws if the underlying value is greater than MAX_SAFE_INTEGER.
*/
toNumber(): number;
/**
* Converts this field to a number.
* May cause loss of precision if the underlying value is greater than MAX_SAFE_INTEGER.
*/
toNumberUnsafe(): number;
toShortString(): string;
equals(rhs: BaseField): boolean;
lt(rhs: BaseField): boolean;
cmp(rhs: BaseField): -1 | 0 | 1;
isZero(): boolean;
isEmpty(): boolean;
toFriendlyJSON(): string;
toField(): this;
}
/**
* Constructs a field from a Buffer of BufferReader.
* It maybe not read the full 32 bytes if the Buffer is shorter, but it will padded in BaseField constructor.
*/
export declare function fromBuffer(buffer: Buffer | BufferReader, f: DerivedField): T;
/** Branding to ensure fields are not interchangeable types. */
export interface Fr {
/** Brand. */
_branding: 'Fr';
}
/**
* Fr field class.
* @dev This class is used to represent elements of BN254 scalar field or elements in the base field of Grumpkin.
* (Grumpkin's scalar field corresponds to BN254's base field and vice versa.)
*/
export declare class Fr extends BaseField {
static ZERO: Fr;
static ONE: Fr;
static MODULUS: bigint;
static MAX_FIELD_VALUE: Fr;
constructor(value: number | bigint | boolean | Fr | Buffer);
protected modulus(): bigint;
static zero(): Fr;
static isZero(value: Fr): boolean;
static fromBuffer(buffer: Buffer | BufferReader): Fr;
static fromBufferReduce(buffer: Buffer): Fr;
/**
* Creates a Fr instance from a string.
* @param buf - the string to create a Fr from.
* @returns the Fr instance
* @remarks if the string only consists of numbers, we assume we are parsing a bigint,
* otherwise we require the hex string to be prepended with "0x", to ensure there is no misunderstanding
* as to what is being parsed.
*/
static fromString(buf: string): Fr;
/**
* Creates a Fr instance from a hex string.
* @param buf - a hex encoded string.
* @returns the Fr instance
*/
static fromHexString(buf: string): Fr;
}
/**
* Branding to ensure fields are not interchangeable types.
*/
export interface Fq {
/** Brand. */
_branding: 'Fq';
}
/**
* Fq field class.
* @dev This class is used to represent elements of BN254 base field or elements in the scalar field of Grumpkin.
* (Grumpkin's scalar field corresponds to BN254's base field and vice versa.)
*/
export declare class Fq extends BaseField {
static ZERO: Fq;
static MODULUS: bigint;
private static HIGH_SHIFT;
private static LOW_MASK;
get lo(): Fr;
get hi(): Fr;
constructor(value: number | bigint | boolean | Fq | Buffer);
protected modulus(): bigint;
static zero(): Fq;
static fromBuffer(buffer: Buffer | BufferReader): Fq;
static fromBufferReduce(buffer: Buffer): Fq;
/**
* Creates a Fq instance from a string.
* @param buf - the string to create a Fq from.
* @returns the Fq instance
* @remarks if the string only consists of numbers, we assume we are parsing a bigint,
* otherwise we require the hex string to be prepended with "0x", to ensure there is no misunderstanding
* as to what is being parsed.
*/
static fromString(buf: string): Fq;
/**
* Creates a Fq instance from a hex string.
* @param buf - a hex encoded string.
* @returns the Fq instance
*/
static fromHexString(buf: string): Fq;
static fromHighLow(high: Fr, low: Fr): Fq;
add(rhs: Fq): Fq;
toJSON(): string;
toFields(): Fr[];
}
/**
* GrumpkinScalar is an Fq.
* @remarks Called GrumpkinScalar because it is used to represent elements in Grumpkin's scalar field as defined in
* the Aztec Protocol Specs.
*/
export declare type GrumpkinScalar = Fq;
export declare const GrumpkinScalar: typeof Fq;
/** Wraps a function that returns a buffer so that all results are reduced into a field of the given type. */
export declare function reduceFn(fn: (input: TInput) => Buffer, field: DerivedField): (input: TInput) => TField;
export {};