Integer Types
Overview
The SDK provides signed and unsigned integer types that match Aleo's native integer types. All integer types share a common API for creation, conversion, and arithmetic operations.
Unsigned Integers
U8- 8-bit unsigned integer (0 to 255)U16- 16-bit unsigned integer (0 to 65,535)U32- 32-bit unsigned integer (0 to 4,294,967,295)U64- 64-bit unsigned integer (0 to 18,446,744,073,709,551,615)U128- 128-bit unsigned integer
Signed Integers
I8- 8-bit signed integer (-128 to 127)I16- 16-bit signed integer (-32,768 to 32,767)I32- 32-bit signed integer (-2,147,483,648 to 2,147,483,647)I64- 64-bit signed integerI128- 128-bit signed integer
Common Methods
All integer types share the following methods:
fromString
Construct an integer from a string representation
fromString(s) ► Integer
| Param | Type | Description |
|---|---|---|
| s | string | String representation of the integer (e.g., "42u32") |
| return | Integer | The integer object |
toString
Get the string representation of the integer
toString() ► string
| Param | Type |
|---|---|
| return | string |
fromBytesLe
Construct an integer from a byte array representation
fromBytesLe(bytes) ► Integer
| Param | Type | Description |
|---|---|---|
| bytes | Uint8Array | Left endian byte array |
| return | Integer | The integer object |
toBytesLe
Get the byte array representation of the integer
toBytesLe() ► Uint8Array
| Param | Type |
|---|---|
| return | Uint8Array |
fromBitsLe
Construct an integer from a boolean array representation
fromBitsLe(bits) ► Integer
| Param | Type | Description |
|---|---|---|
| bits | Array | Left endian boolean array |
| return | Integer | The integer object |
toBitsLe
Get the boolean array representation of the integer
toBitsLe() ► Array
| Param | Type |
|---|---|
| return | Array |
absChecked
Checked absolute value
absChecked() ► Integer
| Param | Type |
|---|---|
| return | Integer |
absWrapped
Wrapped absolute value
absWrapped() ► Integer
| Param | Type |
|---|---|
| return | Integer |
addWrapped
Wrapped addition with another integer
addWrapped(other) ► Integer
| Param | Type | Description |
|---|---|---|
| other | Integer | The integer to add |
| return | Integer | The result of the addition |
subWrapped
Wrapped subtraction with another integer
subWrapped(other) ► Integer
| Param | Type | Description |
|---|---|---|
| other | Integer | The integer to subtract |
| return | Integer | The result of the subtraction |
mulWrapped
Wrapped multiplication with another integer
mulWrapped(other) ► Integer
| Param | Type | Description |
|---|---|---|
| other | Integer | The integer to multiply |
| return | Integer | The result of the multiplication |
divWrapped
Wrapped division
divWrapped(other) ► Integer
| Param | Type | Description |
|---|---|---|
| other | Integer | The divisor |
| return | Integer | The result of the division |
powU8
Exponentiate the integer with a U8 exponent
powU8(exponent) ► Integer
| Param | Type | Description |
|---|---|---|
| exponent | U8 | The exponent |
| return | Integer | The result of exponentiation |
powU16
Exponentiate the integer with a U16 exponent
powU16(exponent) ► Integer
| Param | Type | Description |
|---|---|---|
| exponent | U16 | The exponent |
| return | Integer | The result of exponentiation |
powU32
Exponentiate the integer with a U32 exponent
powU32(exponent) ► Integer
| Param | Type | Description |
|---|---|---|
| exponent | U32 | The exponent |
| return | Integer | The result of exponentiation |
neg
Negate the integer (e.g., 5 → -5)
neg() ► Integer
| Param | Type |
|---|---|
| return | Integer |
equals
Check equality with another integer
equals(other) ► boolean
| Param | Type | Description |
|---|---|---|
| other | Integer | The integer to compare |
| return | boolean | True if the integers are equal |
rem
Get the remainder from integer division
rem(other) ► Integer
| Param | Type | Description |
|---|---|---|
| other | Integer | The divisor |
| return | Integer | The remainder |
remWrapped
Get the remainder from an integer division which wraps if there's an overflow
remWrapped(other) ► Integer
| Param | Type | Description |
|---|---|---|
| other | Integer | The divisor |
| return | Integer | The remainder |
toScalar
Convert the integer to a Scalar value
toScalar() ► Scalar
| Param | Type |
|---|---|
| return | Scalar |
toPlaintext
Convert the integer to the Plaintext type. This must be done before hashing an integer to ensure it matches hashes with a Leo/Aleo program.
toPlaintext() ► Plaintext
| Param | Type |
|---|---|
| return | Plaintext |
fromField
Attempt to construct the integer from a field element
fromField(field) ► Integer
| Param | Type | Description |
|---|---|---|
| field | Field | The field element |
| return | Integer | The integer object |
fromFields
Attempt to construct the integer from a list of field elements
fromFields(fields) ► Integer
| Param | Type | Description |
|---|---|---|
| fields | Array | Array of field elements |
| return | Integer | The integer object |
clone
Clone the integer in wasm memory
clone() ► Integer
| Param | Type |
|---|---|
| return | Integer |