Class: Field
Table of contents
Constructors
Properties
Methods
- add
- assertBoolean
- assertEquals
- assertGt
- assertGte
- assertLt
- assertLte
- div
- equals
- gt
- gte
- inv
- isConstant
- isZero
- lt
- lte
- mul
- neg
- ofFields
- rangeCheckHelper
- seal
- sizeInFields
- sqrt
- square
- sub
- toBigInt
- toBits
- toConstant
- toFields
- toJSON
- toString
- check
- fromBigInt
- fromJSON
- fromNumber
- fromString
- ofBits
- ofFields
- random
- sizeInFields
- 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
The number -1 as a [[Field
]].
Defined in
one
▪ Static
one: Field
The number 1 as a [[Field
]].
Defined in
zero
▪ Static
zero: Field
The number 0 as a [[Field
]].
Defined in
Methods
add
▸ add(y
): Field
Adds this [[Field
]] element to another coercible to a field.
Parameters
Name | Type |
---|---|
y | string | number | boolean | Field |
Returns
Defined in
assertBoolean
▸ assertBoolean(): void
Assert that this [[Field
]] is either 0 or 1.
Field.zero.assertBoolean();
This function can only be called inside a checked computation, like a SmartContract method, and throws an error if the assertion fails.
Returns
void
Defined in
assertEquals
▸ assertEquals(y
): void
Assert that this [[Field
]] equals another Field-like value.
Throws an error if the assertion fails.
Field.one.assertEquals(1);
Parameters
Name | Type |
---|---|
y | string | number | boolean | Field |
Returns
void
Defined in
assertGt
▸ assertGt(y
): void
Assert that this [[Field
]] is greater than another Field-like value.
Field.one.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 |
Returns
void
Defined in
assertGte
▸ assertGte(y
): void
Assert that this [[Field
]] is greater than or equal to another Field-like value.
Field.one.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 |
Returns
void
Defined in
assertLt
▸ assertLt(y
): void
Assert that this [[Field
]] is lower than another Field-like value.
Field.one.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 |
Returns
void
Defined in
assertLte
▸ assertLte(y
): void
Assert that this [[Field
]] is lower than or equal to another Field-like value.
Field.one.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 |
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
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.one.div(x));
Returns
A field element that is equivalent to one divided by this element.
Defined in
isConstant
▸ isConstant(): boolean
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.one.neg();
negOne.assertEquals(-1);
Returns
Defined in
ofFields
▸ ofFields(fields
): Field
Parameters
Name | Type |
---|---|
fields | Field [] |
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
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 the [[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
Defined in
toFields
▸ toFields(): Field
[]
Returns
Field
[]
Defined in
toJSON
▸ toJSON(): JSONValue
Serialize the [[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
JSONValue
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
fromBigInt
▸ Static
fromBigInt(x
): Field
Parameters
Name | Type |
---|---|
x | bigint |
Returns
Defined in
fromJSON
▸ Static
fromJSON(x
): null
| Field
Parameters
Name | Type |
---|---|
x | JSONValue |
Returns
null
| Field
Defined in
fromNumber
▸ Static
fromNumber(x
): Field
Parameters
Name | Type |
---|---|
x | number |
Returns
Defined in
fromString
▸ Static
fromString(x
): Field
Parameters
Name | Type |
---|---|
x | string |
Returns
Defined in
ofBits
▸ Static
ofBits(x
): Field
Converts a bit array into a field element (little endian) Fails if the field element cannot fit given too many bits.
TODO: Rename to fromBits
Parameters
Name | Type |
---|---|
x | (boolean | Bool )[] |
Returns
Defined in
ofFields
▸ Static
ofFields(fields
): Field
Parameters
Name | Type |
---|---|
fields | Field [] |
Returns
Defined in
random
▸ Static
random(): Field
A random field element.
Returns
Defined in
sizeInFields
▸ Static
sizeInFields(): number
Returns
number
Defined in
toFields
▸ Static
toFields(x
): Field
[]
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
): JSONValue
Parameters
Name | Type |
---|---|
x | Field |
Returns
JSONValue