Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Field

Hierarchy

  • Field

Index

Constructors

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

Properties

ORDER: bigint

The field order as a bigint.

minusOne: Field

The number -1 as a Field.

one: Field

The number 1 as a Field.

zero: Field

The number 0 as a Field.

Methods

  • 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(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(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(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(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(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

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

    Parameters

    • y: string | number | boolean | Field

    Returns Field

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

  • 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(): boolean
  • 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(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

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

    Parameters

    • y: string | number | boolean | Field

    Returns Field

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

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

    Returns Field

  • rangeCheckHelper(numBits: number): Field
  • sizeInFields(): number
  • 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

  • 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[]

  • 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

  • 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

  • fromBigInt(x: bigint): Field
  • fromJSON(x: JSONValue): null | Field
  • fromNumber(x: number): Field
  • fromString(x: string): 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

    • x: (boolean | Bool)[]

    Returns Field

  • sizeInFields(): number
  • toJSON(x: Field): JSONValue

Generated using TypeDoc