Skip to main content

Class: Field

Table of contents

Constructors

Properties

Methods

Constructors

constructor

new Field(x)

Coerces anything field-like to a Field.

Parameters

NameType
xstring | number | bigint | boolean | Field

Defined in

snarky.d.ts:61

Properties

ORDER

Static ORDER: bigint

The field order as a bigint.

Defined in

snarky.d.ts:432


minusOne

Static minusOne: Field

Deprecated

Static constant values on Field are deprecated in favor of using the constructor Field(-1).

The number -1 as a [[Field]].

Defined in

snarky.d.ts:428


one

Static one: Field

Deprecated

Static constant values on Field are deprecated in favor of using the constructor Field(1).

The number 1 as a [[Field]].

Defined in

snarky.d.ts:416


zero

Static zero: Field

Deprecated

Static constant values on Field are deprecated in favor of using the constructor Field(0).

The number 0 as a [[Field]].

Defined in

snarky.d.ts:422

Methods

add

add(y): Field

Adds this Field element to another to a Field element.

let a = Field(3);
let sum = a.add(5)

Parameters

NameType
ystring | number | boolean | Field

Returns

Field

Defined in

snarky.d.ts:94


assertBool

assertBool(message?): void

Assert that this Field is either 0 or 1.

Field(0).assertBool();

Parameters

NameType
message?string

Returns

void

Defined in

snarky.d.ts:356


assertBoolean

assertBoolean(message?): void

Deprecated

Deprecated - use assertBool instead

Assert that this Field is either 0 or 1.

Field(0).assertBoolean();

Parameters

NameType
message?string

Returns

void

Defined in

snarky.d.ts:368


assertEquals

assertEquals(y, message?): void

Assert that this Field equals another Field-like value. Throws an error if the assertion fails.

Field(1).assertEquals(1);

Parameters

NameType
ystring | number | boolean | Field
message?string

Returns

void

Defined in

snarky.d.ts:346


assertGreaterThan

assertGreaterThan(y, message?): void

Assert that this Field is greater than another Field-like value.

Field(1).assertGt(0);

Parameters

NameType
ystring | number | boolean | Field
message?string

Returns

void

Defined in

snarky.d.ts:230


assertGreaterThanOrEqual

assertGreaterThanOrEqual(y, message?): void

Assert that this Field is greater than or equal to another Field-like value.

Field(1).assertGte(0);

Parameters

NameType
ystring | number | boolean | Field
message?string

Returns

void

Defined in

snarky.d.ts:243


assertGt

assertGt(y, message?): void

Deprecated

Deprecated - use assertGreaterThan instead

Assert that this Field is greater than another Field-like value.

Field(1).assertGt(0);

Parameters

NameType
ystring | number | boolean | Field
message?string

Returns

void

Defined in

snarky.d.ts:325


assertGte

assertGte(y, message?): void

Deprecated

Deprecated - use assertGreaterThanOrEqual instead

Assert that this Field is greater than or equal to another Field-like value.

Field(1).assertGte(0);

Parameters

NameType
ystring | number | boolean | Field
message?string

Returns

void

Defined in

snarky.d.ts:336


assertLessThan

assertLessThan(y, message?): void

Assert that this Field is lower than another Field-like value.

Field(1).assertLessThan(2);

Parameters

NameType
ystring | number | boolean | Field
message?string

Returns

void

Defined in

snarky.d.ts:207


assertLessThanOrEqual

assertLessThanOrEqual(y, message?): void

Assert that this Field is lower than or equal to another Field-like value.

Field(1).assertLessThanOrEqual(2);

Parameters

NameType
ystring | number | boolean | Field
message?string

Returns

void

Defined in

snarky.d.ts:217


assertLt

assertLt(y, message?): void

Deprecated

Deprecated - use assertLessThan instead

Assert that this Field is lower than another Field-like value.

Field(1).assertLessThan(2);

Parameters

NameType
ystring | number | boolean | Field
message?string

Returns

void

Defined in

snarky.d.ts:304


assertLte

assertLte(y, message?): void

Deprecated

Deprecated - use assertLessThanOrEqualinstead

Assert that this Field is lower than or equal to another Field-like value.

Field(1).assertLte(2);

Parameters

NameType
ystring | number | boolean | Field
message?string

Returns

void

Defined in

snarky.d.ts:314


div

div(y): Field

Divides this Field element through another coercible to a field.

Parameters

NameType
ystring | number | boolean | Field

Returns

Field

Defined in

snarky.d.ts:109


equals

equals(y): Bool

Check if this Field equals another Field-like value. Returns a Bool.

Field(2).equals(2); // Bool(true)

Parameters

NameType
ystring | number | boolean | Field

Returns

Bool

Defined in

snarky.d.ts:391


fromFields

fromFields(fields): Field

Creates a data structure from an array of serialized Field elements.

Parameters

NameType
fieldsField[]

Returns

Field

Defined in

snarky.d.ts:469


greaterThan

greaterThan(y): Bool

Check if this Field is greater than another Field-like value. Returns a Bool.

Field(2).greaterThan(1); // Bool(true)

Parameters

NameType
ystring | number | boolean | Field

Returns

Bool

Defined in

snarky.d.ts:185


greaterThanOrEqual

greaterThanOrEqual(y): Bool

Check if this Field is greater than or equal to another Field-like value. Returns a Bool.

Field(2).greaterThanOrEqual(1); // Bool(true)

Parameters

NameType
ystring | number | boolean | Field

Returns

Bool

Defined in

snarky.d.ts:195


gt

gt(y): Bool

Deprecated

Deprecated - use {@link greaterThan} instead

Check if this Field is greater than another Field-like value. Returns a Bool.

Field(2).gt(1); // Bool(true)

Parameters

NameType
ystring | number | boolean | Field

Returns

Bool

Defined in

snarky.d.ts:280


gte

gte(y): Bool

Deprecated

Deprecated - use greaterThanOrEqual instead

Check if this Field is greater than or equal to another Field-like value. Returns a Bool.

Field(2).gte(1); // Bool(true)

Parameters

NameType
ystring | number | boolean | Field

Returns

Bool

Defined in

snarky.d.ts:291


inv

inv(): Field

Inverts this Field element.

const invX = x.inv();
invX.assertEquals(Field(1).div(x));

Returns

Field

A Field element that is equivalent to one divided by this element.

Defined in

snarky.d.ts:84


isConstant

isConstant(): boolean

Checks whether this is a hard-coded constant in the Circuit.

Returns

boolean

Defined in

snarky.d.ts:401


isZero

isZero(): Bool

Returns

Bool

Defined in

snarky.d.ts:370


lessThan

lessThan(y): Bool

Check if this Field is lower than another Field-like value. Returns a Bool.

Field(2).lessThan(3); // Bool(true)

Parameters

NameType
ystring | number | boolean | Field

Returns

Bool

Defined in

snarky.d.ts:165


lessThanOrEqual

lessThanOrEqual(y): Bool

Check if this Field is lower than or equal to another Field-like value. Returns a Bool.

Field(2).lessThanOrEqual(3); // Bool(true)

Parameters

NameType
ystring | number | boolean | Field

Returns

Bool

Defined in

snarky.d.ts:175


lt

lt(y): Bool

Deprecated

Deprecated - use lessThan instead

Check if this Field is lower than another Field-like value. Returns a Bool.

Field(2).lt(3); // Bool(true)

Parameters

NameType
ystring | number | boolean | Field

Returns

Bool

Defined in

snarky.d.ts:258


lte

lte(y): Bool

Deprecated

Deprecated - use lessThanOrEqual instead

Check if this Field is lower than or equal to another Field-like value. Returns a Bool.

Field(2).lte(3); // Bool(true)

Parameters

NameType
ystring | number | boolean | Field

Returns

Bool

Defined in

snarky.d.ts:269


mul

mul(y): Field

Multiplies this Field element with another coercible to a field.

Parameters

NameType
ystring | number | boolean | Field

Returns

Field

Defined in

snarky.d.ts:104


neg

neg(): Field

Negates this Field. This is equivalent to multiplying the Field by -1.

const negOne = Field(1).neg();
negOne.assertEquals(-1);

Returns

Field

Defined in

snarky.d.ts:72


rangeCheckHelper

rangeCheckHelper(numBits): Field

Parameters

NameType
numBitsnumber

Returns

Field

Defined in

snarky.d.ts:396


seal

seal(): Field

Returns

Field

Defined in

snarky.d.ts:394


sizeInFields

sizeInFields(): number

Returns the size of this type.

Returns

number

Defined in

snarky.d.ts:149


sqrt

sqrt(): Field

Square roots this Field element.

x.square().sqrt().assertEquals(x);

Returns

Field

Defined in

snarky.d.ts:128


square

square(): Field

Squares this Field element.

const x2 = x.square();
x2.assertEquals(x.mul(x));

Returns

Field

Defined in

snarky.d.ts:119


sub

sub(y): Field

Subtracts another Field-like element from this one.

Parameters

NameType
ystring | number | boolean | Field

Returns

Field

Defined in

snarky.d.ts:99


toBigInt

toBigInt(): bigint

Serialize this instance of a Field to a bigint. This operation does NOT affect the circuit and can't be used to prove anything about the bigint representation of the Field.

Returns

bigint

Defined in

snarky.d.ts:139


toBits

toBits(): Bool[]

Little endian binary representation of the field element.

Returns

Bool[]

Defined in

snarky.d.ts:375

toBits(length): Bool[]

Little endian binary representation of the field element. Fails if the field element cannot fit in length bits.

Parameters

NameType
lengthnumber

Returns

Bool[]

Defined in

snarky.d.ts:381


toConstant

toConstant(): Field

Returns a constant.

Returns

Field

Defined in

snarky.d.ts:406


toFields

toFields(): Field[]

Serializes this data structure into Field elements.

Returns

Field[]

Defined in

snarky.d.ts:154


toJSON

toJSON(): string

Serialize this instance of a Field to a JSON string. This operation does NOT affect the circuit and can't be used to prove anything about the string representation of the Field.

Returns

string

Defined in

snarky.d.ts:144


toString

toString(): string

Serialize the Field to a string, e.g. for printing. This operation does NOT affect the circuit and can't be used to prove anything about the string representation of the Field.

Returns

string

Defined in

snarky.d.ts:134


check

Static check(x): void

Parameters

NameType
xField

Returns

void

Defined in

snarky.d.ts:527


fromBits

Static fromBits(x): Field

Converts a bit array into a field element (little endian) Fails if the field element cannot fit given too many bits.

Parameters

NameType
x(boolean | Bool)[]

Returns

Field

Defined in

snarky.d.ts:503


fromBytes

Static fromBytes(bytes): Field

Parameters

NameType
bytesnumber[]

Returns

Field

Defined in

snarky.d.ts:532


fromFields

Static fromFields(fields): Field

Creates a data structure from an array of serialized Field elements.

Parameters

NameType
fieldsField[]

Returns

Field

Defined in

snarky.d.ts:474


fromJSON

Static fromJSON(x): Field

Deserialize a JSON structure into a Field. This operation does NOT affect the circuit and can't be used to prove anything about the string representation of the Field.

Parameters

NameType
xstring

Returns

Field

Defined in

snarky.d.ts:525


random

Static random(): Field

A random field element.

Returns

Field

Defined in

snarky.d.ts:437


readBytes

Static readBytes(bytes, offset): [value: Field, offset: number]

Parameters

NameType
bytesnumber[]
offsetnumber

Returns

[value: Field, offset: number]

Defined in

snarky.d.ts:533


sizeInBytes

Static sizeInBytes(): number

Returns

number

Defined in

snarky.d.ts:537


sizeInFields

Static sizeInFields(): number

Returns the size of this type.

Returns

number

Defined in

snarky.d.ts:479


toAuxiliary

Static toAuxiliary(x?): []

Static method to serialize a Field into its auxiliary data.

Parameters

NameType
x?Field

Returns

[]

Defined in

snarky.d.ts:488


toBytes

Static toBytes(x): number[]

Parameters

NameType
xField

Returns

number[]

Defined in

snarky.d.ts:531


toFields

Static toFields(x): Field[]

Static method to serialize a Field into an array of Field elements.

Parameters

NameType
xField

Returns

Field[]

Defined in

snarky.d.ts:484


toInput

Static toInput(x): Object

Parameters

NameType
xField

Returns

Object

NameType
fieldsField[]

Defined in

snarky.d.ts:530


toJSON

Static toJSON(x): string

Serialize a Field to a JSON string. This operation does NOT affect the circuit and can't be used to prove anything about the string representation of the Field.

Parameters

NameType
xField

Returns

string

Defined in

snarky.d.ts:519