Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Field

An element of a finite field.

Hierarchy

  • Field

Index

Constructors

constructor

  • new Field(x: string | number | boolean | Field): Field

Properties

Static one

one: Field

The number 1 as a Field.

Static zero

zero: Field

The number 0 as a Field.

Methods

add

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

assertEquals

  • assertEquals(y: string | number | boolean | Field): void
  • Assert that this Field equals another Field-like value. Throws an error if the assertion fails.

    Field.one.assertEquals(1);
    

    Parameters

    • y: string | number | boolean | Field

    Returns void

assertGt

  • assertGt(y: string | number | boolean | Field): 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

    • y: string | number | boolean | Field

    Returns void

assertGte

  • assertGte(y: string | number | boolean | Field): 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

    • y: string | number | boolean | Field

    Returns void

assertLt

  • assertLt(y: string | number | boolean | Field): 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

    • y: string | number | boolean | Field

    Returns void

assertLte

  • assertLte(y: string | number | boolean | Field): 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

    • y: string | number | boolean | Field

    Returns void

div

  • Divides this Field element through another coercible to a field.

    Parameters

    • y: string | number | boolean | Field

    Returns Field

equals

  • equals(y: string | number | boolean | Field): Bool

gt

  • gt(y: string | number | boolean | Field): Bool
  • Check if this Field is greater than another Field-like value. Returns a Bool.

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

    Parameters

    • y: string | number | boolean | Field

    Returns Bool

gte

  • gte(y: string | number | boolean | Field): 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

    • y: string | number | boolean | Field

    Returns Bool

inv

  • Inverts this Field element.

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

    Returns Field

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

isConstant

  • isConstant(): boolean

isZero

lt

  • lt(y: string | number | boolean | Field): Bool
  • Check if this Field is lower than another Field-like value. Returns a Bool.

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

    Parameters

    • y: string | number | boolean | Field

    Returns Bool

lte

  • lte(y: string | number | boolean | Field): 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

    • y: string | number | boolean | Field

    Returns Bool

mul

  • Multiplies this Field element with another coercible to a field.

    Parameters

    • y: string | number | boolean | Field

    Returns Field

neg

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

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

    Returns Field

ofFields

rangeCheckHelper

  • rangeCheckHelper(numBits: number): Field

seal

sizeInFields

  • sizeInFields(): number

sqrt

square

sub

toBits

  • toBits(): Bool[]
  • toBits(length: number): Bool[]
  • Little endian binary representation of the field element.

    Returns Bool[]

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

    Parameters

    • length: number

    Returns Bool[]

toConstant

toFields

toJSON

  • 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

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

Static fromJSON

Static ofBits

  • 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

    • x: (boolean | Bool)[]

    Returns Field

Static ofFields

Static random

Static sizeInFields

  • sizeInFields(): number

Static toFields

Generated using TypeDoc