Class: Field
Table of contents
Constructors
Properties
Methods
- add
- assertBoolean
- assertEquals
- assertGt
- assertGte
- assertLt
- assertLte
- div
- equals
- fromFields
- gt
- gte
- inv
- isConstant
- isZero
- lt
- lte
- mul
- neg
- rangeCheckHelper
- seal
- sizeInFields
- sqrt
- square
- sub
- toBigInt
- toBits
- toConstant
- toFields
- toJSON
- toString
- check
- fromBits
- fromBytes
- fromFields
- fromJSON
- random
- sizeInBytes
- sizeInFields
- toAuxiliary
- toBytes
- toFields
- toInput
- toJSON
Constructors
constructor
• new Field(x
)
Coerces anything field-like to a Field.
Parameters
Name | Type |
---|---|
x | string | number | bigint | boolean | Field |
Defined in
Properties
ORDER
▪ Static
ORDER: bigint
The field order as a bigint
.
Defined in
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
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
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
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
Name | Type |
---|---|
y | string | number | boolean | Field |
Returns
Defined in
assertBoolean
▸ assertBoolean(message?
): void
Assert that this Field is either 0 or 1.
Field(0).assertBoolean();
This function can only be called inside a checked computation, like a SmartContract method, and throws an error if the assertion fails.
Parameters
Name | Type |
---|---|
message? | string |
Returns
void
Defined in
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
Name | Type |
---|---|
y | string | number | boolean | Field |
message? | string |
Returns
void
Defined in
assertGt
▸ assertGt(y
, message?
): void
Assert that this Field is greater than another Field-like value.
Field(1).assertGt(0);
This function can only be called inside a checked computation, like a SmartContract method, and causes it to fail if the assertion fails.
Parameters
Name | Type |
---|---|
y | string | number | boolean | Field |
message? | string |
Returns
void
Defined in
assertGte
▸ assertGte(y
, message?
): void
Assert that this Field is greater than or equal to another Field-like value.
Field(1).assertGte(0);
This function can only be called inside a checked computation, like a SmartContract method, and causes it to fail if the assertion fails.
Parameters
Name | Type |
---|---|
y | string | number | boolean | Field |
message? | string |
Returns
void
Defined in
assertLt
▸ assertLt(y
, message?
): void
Assert that this Field is lower than another Field-like value.
Field(1).assertLt(2);
This function can only be called inside a checked computation, like a SmartContract method, and causes it to fail if the assertion fails.
Parameters
Name | Type |
---|---|
y | string | number | boolean | Field |
message? | string |
Returns
void
Defined in
assertLte
▸ assertLte(y
, message?
): void
Assert that this Field is lower than or equal to another Field-like value.
Field(1).assertLte(2);
This function can only be called inside a checked computation, like a SmartContract method, and causes it to fail if the assertion fails.
Parameters
Name | Type |
---|---|
y | string | number | boolean | Field |
message? | string |
Returns
void
Defined in
div
▸ div(y
): Field
Divides this Field element through another coercible to a field.
Parameters
Name | Type |
---|---|
y | string | number | boolean | Field |
Returns
Defined in
equals
▸ equals(y
): Bool
Check if this Field equals another Field-like value. Returns a Bool.
Field(2).equals(2); // Bool(true)
Parameters
Name | Type |
---|---|
y | string | number | boolean | Field |
Returns
Defined in
fromFields
▸ fromFields(fields
): Field
Creates a data structure from an array of serialized Field elements.
Parameters
Name | Type |
---|---|
fields | Field [] |
Returns
Defined in
gt
▸ gt(y
): Bool
Check if this Field is greater than another Field-like value. Returns a Bool.
Field(2).gt(1); // Bool(true)
Parameters
Name | Type |
---|---|
y | string | number | boolean | Field |
Returns
Defined in
gte
▸ gte(y
): Bool
Check if this Field is greater than or equal to another Field-like value. Returns a Bool.
Field(2).gte(1); // Bool(true)
Parameters
Name | Type |
---|---|
y | string | number | boolean | Field |
Returns
Defined in
inv
▸ inv(): Field
Inverts this Field element.
const invX = x.inv();
invX.assertEquals(Field(1).div(x));
Returns
A Field element that is equivalent to one divided by this element.
Defined in
isConstant
▸ isConstant(): boolean
Checks whether this is a hard-coded constant in the Circuit.
Returns
boolean
Defined in
isZero
▸ isZero(): Bool
Returns
Defined in
lt
▸ lt(y
): Bool
Check if this Field is lower than another Field-like value. Returns a Bool.
Field(2).lt(3); // Bool(true)
Parameters
Name | Type |
---|---|
y | string | number | boolean | Field |
Returns
Defined in
lte
▸ lte(y
): Bool
Check if this Field is lower than or equal to another Field-like value. Returns a Bool.
Field(2).lte(3); // Bool(true)
Parameters
Name | Type |
---|---|
y | string | number | boolean | Field |
Returns
Defined in
mul
▸ mul(y
): Field
Multiplies this Field element with another coercible to a field.
Parameters
Name | Type |
---|---|
y | string | number | boolean | Field |
Returns
Defined in
neg
▸ neg(): Field
Negates this Field. This is equivalent to multiplying the Field by -1.
const negOne = Field(1).neg();
negOne.assertEquals(-1);
Returns
Defined in
rangeCheckHelper
▸ rangeCheckHelper(numBits
): Field
Parameters
Name | Type |
---|---|
numBits | number |
Returns
Defined in
seal
▸ seal(): Field
Returns
Defined in
sizeInFields
▸ sizeInFields(): number
Returns the size of this type.
Returns
number
Defined in
sqrt
▸ sqrt(): Field
Square roots this Field element.
x.square().sqrt().assertEquals(x);
Returns
Defined in
square
▸ square(): Field
Squares this Field element.
const x2 = x.square();
x2.assertEquals(x.mul(x));
Returns
Defined in
sub
▸ sub(y
): Field
Subtracts another Field-like element from this one.
Parameters
Name | Type |
---|---|
y | string | number | boolean | Field |
Returns
Defined in
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
toBits
▸ toBits(): Bool
[]
Little endian binary representation of the field element.
Returns
Bool
[]
Defined in
▸ toBits(length
): Bool
[]
Little endian binary representation of the field element.
Fails if the field element cannot fit in length
bits.
Parameters
Name | Type |
---|---|
length | number |
Returns
Bool
[]
Defined in
toConstant
▸ toConstant(): Field
Returns a constant.
Returns
Defined in
toFields
▸ toFields(): Field
[]
Serializes this data structure into Field elements.
Returns
Field
[]
Defined in
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
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
check
▸ Static
check(x
): void
Parameters
Name | Type |
---|---|
x | Field |
Returns
void
Defined in
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
Name | Type |
---|---|
x | (boolean | Bool )[] |
Returns
Defined in
fromBytes
▸ Static
fromBytes(bytes
): Field
Parameters
Name | Type |
---|---|
bytes | number [] |
Returns
Defined in
fromFields
▸ Static
fromFields(fields
): Field
Creates a data structure from an array of serialized Field elements.
Parameters
Name | Type |
---|---|
fields | Field [] |
Returns
Defined in
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
Name | Type |
---|---|
x | string |
Returns
Defined in
random
▸ Static
random(): Field
A random field element.
Returns
Defined in
sizeInBytes
▸ Static
sizeInBytes(): number
Returns
number
Defined in
sizeInFields
▸ Static
sizeInFields(): number
Returns the size of this type.
Returns
number
Defined in
toAuxiliary
▸ Static
toAuxiliary(x?
): []
Static method to serialize a Field into its auxiliary data.
Parameters
Name | Type |
---|---|
x? | Field |
Returns
[]
Defined in
toBytes
▸ Static
toBytes(x
): number
[]
Parameters
Name | Type |
---|---|
x | Field |
Returns
number
[]
Defined in
toFields
▸ Static
toFields(x
): Field
[]
Static method to serialize a Field into an array of Field elements.
Parameters
Name | Type |
---|---|
x | Field |
Returns
Field
[]
Defined in
toInput
▸ Static
toInput(x
): Object
Parameters
Name | Type |
---|---|
x | Field |
Returns
Object
Name | Type |
---|---|
fields | Field [] |
Defined in
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
Name | Type |
---|---|
x | Field |
Returns
string