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
| Param | Type | Description |
|---|---|---|
| field | string | String representation of a field element |
| return | Field | Field object |
toString
Returns the string representation of the field element
toString() ► string
| Param | Type |
|---|---|
| return | string |
fromBytesLe
Create a field element from a Uint8Array of left endian bytes
fromBytesLe(bytes) ► Field
| Param | Type | Description |
|---|---|---|
| bytes | Uint8Array | Byte array representation |
| return | Field | Field object |
toBytesLe
Encode the field element as a Uint8Array of left endian bytes
toBytesLe() ► Uint8Array
| Param | Type |
|---|---|
| return | Uint8Array |
fromBitsLe
Reconstruct a field element from a boolean array representation
fromBitsLe(bits) ► Field
| Param | Type | Description |
|---|---|---|
| bits | Array.<any> | Boolean array representation |
| return | Field | Field object |
toBitsLe
Get the left endian boolean array representation of the field element
toBitsLe() ► Array.<any>
| Param | Type |
|---|---|
| return | Array.<any> |
toPlaintext
Create a plaintext from the field element
toPlaintext() ► Plaintext
| Param | Type |
|---|---|
| return | Plaintext |
clone
Clone the field element
clone() ► Field
| Param | Type |
|---|---|
| return | Field |
random
Generate a random field element
random() ► Field
| Param | Type |
|---|---|
| return | Field |
add
Add two field elements
add(other) ► Field
| Param | Type | Description |
|---|---|---|
| other | Field | Field element to add |
| return | Field | Sum of the field elements |
subtract
Subtract two field elements
subtract(other) ► Field
| Param | Type | Description |
|---|---|---|
| other | Field | Field element to subtract |
| return | Field | Difference of the field elements |
multiply
Multiply two field elements
multiply(other) ► Field
| Param | Type | Description |
|---|---|---|
| other | Field | Field element to multiply |
| return | Field | Product of the field elements |
divide
Divide two field elements
divide(other) ► Field
| Param | Type | Description |
|---|---|---|
| other | Field | Field element to divide by |
| return | Field | Quotient of the field elements |
pow
Power of a field element
pow(other) ► Field
| Param | Type | Description |
|---|---|---|
| other | Field | Field element as exponent |
| return | Field | Result of the power operation |
inverse
Invert the field element
inverse() ► Field
| Param | Type |
|---|---|
| return | Field |
zero
Get the additive identity element of the field
zero() ► Field
| Param | Type |
|---|---|
| return | Field |
one
Get the multiplicative identity of the field
one() ► Field
| Param | Type |
|---|---|
| return | Field |
double
Double the field element
double() ► Field
| Param | Type |
|---|---|
| return | Field |
equals
Check if one field element equals another
equals(other) ► boolean
| Param | Type | Description |
|---|---|---|
| other | Field | Field element to compare |
| return | boolean | Whether the field elements are equal |