Skip to main content

Field

Overview

Field element class for operations on field elements in the Aleo network. Provides methods for creating, converting, and manipulating field elements with support for various formats including strings, bytes, and BigInt.

Methods

fromString

Creates a field object from a string representation of a field element

fromString(field)Field
ParamTypeDescription
fieldstringString representation of a field element
returnFieldField object

toString

Returns the string representation of the field element

toString() ► string
ParamType
returnstring

fromBytesLe

Create a field element from a Uint8Array of left endian bytes

fromBytesLe(bytes)Field
ParamTypeDescription
bytesUint8ArrayByte array representation
returnFieldField object

toBytesLe

Encode the field element as a Uint8Array of left endian bytes

toBytesLe()Uint8Array
ParamType
returnUint8Array

fromBitsLe

Reconstruct a field element from a boolean array representation

fromBitsLe(bits)Field
ParamTypeDescription
bitsArray.<any>Boolean array representation
returnFieldField object

toBitsLe

Get the left endian boolean array representation of the field element

toBitsLe()Array.<any>
ParamType
returnArray.<any>

toPlaintext

Create a plaintext from the field element

toPlaintext()Plaintext
ParamType
returnPlaintext

clone

Clone the field element

clone()Field
ParamType
returnField

random

Generate a random field element

random()Field
ParamType
returnField

add

Add two field elements

add(other)Field
ParamTypeDescription
otherFieldField element to add
returnFieldSum of the field elements

subtract

Subtract two field elements

subtract(other)Field
ParamTypeDescription
otherFieldField element to subtract
returnFieldDifference of the field elements

multiply

Multiply two field elements

multiply(other)Field
ParamTypeDescription
otherFieldField element to multiply
returnFieldProduct of the field elements

divide

Divide two field elements

divide(other)Field
ParamTypeDescription
otherFieldField element to divide by
returnFieldQuotient of the field elements

pow

Power of a field element

pow(other)Field
ParamTypeDescription
otherFieldField element as exponent
returnFieldResult of the power operation

inverse

Invert the field element

inverse()Field
ParamType
returnField

zero

Get the additive identity element of the field

zero()Field
ParamType
returnField

one

Get the multiplicative identity of the field

one()Field
ParamType
returnField

double

Double the field element

double()Field
ParamType
returnField

equals

Check if one field element equals another

equals(other) ► boolean
ParamTypeDescription
otherFieldField element to compare
returnbooleanWhether the field elements are equal