UInt8
Class: UInt8
A 8 bit unsigned integer with values ranging from 0 to 255.
Hierarchy
{
value
:Field
= Field }↳
UInt8
Table of contents
Constructors
Properties
Methods
- add
- assertEquals
- assertGreaterThan
- assertGreaterThanOrEqual
- assertLessThan
- assertLessThanOrEqual
- div
- divMod
- greaterThan
- greaterThanOrEqual
- lessThan
- lessThanOrEqual
- mod
- mul
- sub
- toBigInt
- toNumber
- toString
- toUInt32
- toUInt64
- MAXINT
- check
- checkConstant
- from
- sizeInFields
- toInput
Constructors
constructor
• new UInt8(x
)
Create a UInt8 from a bigint or number.
The max value of a UInt8 is 2^8 - 1 = 255
.
Warning: Cannot overflow past 255, an error is thrown if the result is greater than 255.
Parameters
Name | Type |
---|---|
x | number | bigint | FieldVar | UInt8 |
Overrides
Struct({ value: Field, }).constructor
Defined in
Properties
value
• value: Field
= Field
Inherited from
Struct({ value: Field, }).value
Defined in
NUM_BITS
▪ Static
NUM_BITS: number
= 8
Defined in
Unsafe
▪ Static
Unsafe: Object
Type declaration
Name | Type |
---|---|
fromField | (x : Field ) => UInt8 |
Defined in
_isStruct
▪ Static
_isStruct: true
Inherited from
Struct({ value: Field, })._isStruct
Defined in
empty
▪ Static
empty: () => { value
: Field
= Field }
Type declaration
▸ (): Object
Returns
Object
Name | Type |
---|---|
value | Field |
Inherited from
Struct({ value: Field, }).empty
Defined in
fromFields
▪ Static
fromFields: (fields
: Field
[]) => { value
: Field
= Field }
Type declaration
▸ (fields
): Object
A function that returns an element of type T
from the given provable data.
Important: For any element of type T
, this function is the reverse operation of calling toFields method on an element of type T
.
Parameters
Name | Type | Description |
---|---|---|
fields | Field [] | an array of Field elements describing the provable data of the new T element. |
Returns
Object
An element of type T
generated from the given provable data.
Name | Type |
---|---|
value | Field |
Inherited from
Struct({ value: Field, }).fromFields
Defined in
fromJSON
▪ Static
fromJSON: (x
: { value
: string
= Field }) => { value
: Field
= Field }
Type declaration
▸ (x
): Object
Parameters
Name | Type | Default value |
---|---|---|
x | Object | undefined |
x.value | string | Field |
Returns
Object
Name | Type |
---|---|
value | Field |
Inherited from
Struct({ value: Field, }).fromJSON
Defined in
toAuxiliary
▪ Static
toAuxiliary: (value?
: { value
: Field
= Field }) => any
[]
Type declaration
▸ (value?
): any
[]
A function that takes value
(optional), an element of type T
, as argument and returns an array of any type that make up the "auxiliary" (non-provable) data of value
.
As any element of the interface ProvablePure<T>
includes no "auxiliary" data by definition, this function always returns a default value.
Parameters
Name | Type | Default value | Description |
---|---|---|---|
value? | Object | undefined | the element of type T to generate the auxiliary data array from, optional. If not provided, a default value for auxiliary data is returned. |
value.value | Field | Field | - |
Returns
any
[]
An empty array, as any element of the interface ProvablePure<T>
includes no "auxiliary" data by definition.
Inherited from
Struct({ value: Field, }).toAuxiliary
Defined in
toFields
▪ Static
toFields: (value
: { value
: Field
= Field }) => Field
[]
Type declaration
▸ (value
): Field
[]
A function that takes value
, an element of type T
, as argument and returns an array of Field elements that make up the provable data of value
.
Parameters
Name | Type | Default value | Description |
---|---|---|---|
value | Object | undefined | the element of type T to generate the Field array from. |
value.value | Field | Field | - |
Returns
Field
[]
A Field array describing how this T
element is made up of Field elements.
Inherited from
Struct({ value: Field, }).toFields
Defined in
toJSON
▪ Static
toJSON: (x
: { value
: Field
= Field }) => { value
: string
= Field }
Type declaration
▸ (x
): Object
Parameters
Name | Type | Default value |
---|---|---|
x | Object | undefined |
x.value | Field | Field |
Returns
Object
Name | Type |
---|---|
value | string |
Inherited from
Struct({ value: Field, }).toJSON
Defined in
Methods
add
▸ add(y
): UInt8
Add a UInt8 to another UInt8 without allowing overflow.
Parameters
Name | Type |
---|---|
y | number | bigint | UInt8 |
Returns
Example
const x = UInt8.from(3);
const sum = x.add(5);
sum.assertEquals(8);
Throws
if the result is greater than 255.
Defined in
assertEquals
▸ assertEquals(y
, message?
): void
Assert that this UInt8 is equal another UInt8 value.
Important: If an assertion fails, the code throws an error.
Parameters
Name | Type | Description |
---|---|---|
y | number | bigint | UInt8 | the UInt8 value to compare & assert with this UInt8. |
message? | string | - |
Returns
void
Defined in
assertGreaterThan
▸ assertGreaterThan(y
, message?
): void
Assert that this UInt8 is greater than another UInt8 value.
Important: If an assertion fails, the code throws an error.
Parameters
Name | Type | Description |
---|---|---|
y | number | bigint | UInt8 | the UInt8 value to compare & assert with this UInt8. |
message? | string | - |
Returns
void
Defined in
assertGreaterThanOrEqual
▸ assertGreaterThanOrEqual(y
, message?
): void
Assert that this UInt8 is greater than or equal to another UInt8 value.
Important: If an assertion fails, the code throws an error.
Parameters
Name | Type | Description |
---|---|---|
y | UInt8 | the UInt8 value to compare & assert with this UInt8. |
message? | string | - |
Returns
void
Defined in
assertLessThan
▸ assertLessThan(y
, message?
): void
Assert that this UInt8 is less than another UInt8 value.
Important: If an assertion fails, the code throws an error.
Parameters
Name | Type | Description |
---|---|---|
y | number | bigint | UInt8 | the UInt8 value to compare & assert with this UInt8. |
message? | string | - |
Returns
void
Defined in
assertLessThanOrEqual
▸ assertLessThanOrEqual(y
, message?
): void
Assert that this UInt8 is less than or equal to another UInt8 value.
Important: If an assertion fails, the code throws an error.
Parameters
Name | Type | Description |
---|---|---|
y | number | bigint | UInt8 | the UInt8 value to compare & assert with this UInt8. |
message? | string | - |
Returns
void
Defined in
div
▸ div(y
): UInt8
Divide a UInt8 by another UInt8. This is integer division that rounds down.
Parameters
Name | Type |
---|---|
y | number | bigint | UInt8 |
Returns
Example
const x = UInt8.from(7);
const quotient = x.div(2);
quotient.assertEquals(3);
Defined in
divMod
▸ divMod(y
): Object
Get the quotient and remainder of a UInt8 divided by another UInt8:
x == y * q + r
, where 0 <= r < y
.
Parameters
Name | Type | Description |
---|---|---|
y | number | bigint | UInt8 | a UInt8 to get the quotient and remainder of another UInt8. |
Returns
Object
The quotient q
and remainder r
.
Name | Type |
---|---|
quotient | UInt8 |
remainder | UInt8 |
Defined in
greaterThan
▸ greaterThan(y
): Bool
Check if this UInt8 is greater than another UInt8. Returns a Bool.
Parameters
Name | Type |
---|---|
y | number | bigint | UInt8 |
Returns
Example
// 5 > 3
UInt8.from(5).greaterThan(3);
Defined in
greaterThanOrEqual
▸ greaterThanOrEqual(y
): Bool
Check if this UInt8 is greater than or equal another UInt8 value. Returns a Bool.
Parameters
Name | Type |
---|---|
y | number | bigint | UInt8 |
Returns
Example
// 3 >= 3
UInt8.from(3).greaterThanOrEqual(3);
Defined in
lessThan
▸ lessThan(y
): Bool
Check if this UInt8 is less than another UInt8 value. Returns a Bool.
Parameters
Name | Type |
---|---|
y | number | bigint | UInt8 |
Returns
Example
UInt8.from(2).lessThan(UInt8.from(3));
Defined in
lessThanOrEqual
▸ lessThanOrEqual(y
): Bool
Check if this UInt8 is less than or equal to another UInt8 value. Returns a Bool.
Parameters
Name | Type |
---|---|
y | number | bigint | UInt8 |
Returns
Example
UInt8.from(3).lessThanOrEqual(UInt8.from(5));
Defined in
mod
▸ mod(y
): UInt8
Get the remainder a UInt8 of division of another UInt8.
Parameters
Name | Type |
---|---|
y | number | bigint | UInt8 |
Returns
Example
const x = UInt8.from(50);
const mod = x.mod(30);
mod.assertEquals(20);
Defined in
mul
▸ mul(y
): UInt8
Multiply a UInt8 by another UInt8 without allowing overflow.
Parameters
Name | Type |
---|---|
y | number | bigint | UInt8 |
Returns
Example
const x = UInt8.from(3);
const product = x.mul(5);
product.assertEquals(15);
Throws
if the result is greater than 255.
Defined in
sub
▸ sub(y
): UInt8
Subtract a UInt8 from another UInt8 without allowing underflow.
Parameters
Name | Type |
---|---|
y | number | bigint | UInt8 |
Returns
Example
const x = UInt8.from(8);
const difference = x.sub(5);
difference.assertEquals(3);
Throws
if the result is less than 0.
Defined in
toBigInt
▸ toBigInt(): bigint
Serialize the UInt8 to a bigint.
Warning: This operation is not provable.
Returns
bigint
Defined in
toNumber
▸ toNumber(): number
Serialize the UInt8 to a number.
Warning: This operation is not provable.
Returns
number
Defined in
toString
▸ toString(): string
Serialize the UInt8 to a string, e.g. for printing.
Warning: This operation is not provable.
Returns
string
Defined in
toUInt32
▸ toUInt32(): UInt32
Returns
Defined in
toUInt64
▸ toUInt64(): UInt64
Returns
Defined in
MAXINT
▸ Static
MAXINT(): UInt8
Creates a UInt8 with a value of 255.
Returns
Defined in
check
▸ Static
check(x
): void
check for UInt8. Proves that the input is in the [0, 255] range.
Parameters
Name | Type |
---|---|
x | Field | { value : Field } |
Returns
void
Overrides
Struct({ value: Field, }).check
Defined in
checkConstant
▸ Static
Private
checkConstant(x
): void
Parameters
Name | Type |
---|---|
x | Field |
Returns
void
Defined in
from
▸ Static
from(x
): UInt8
Creates a new UInt8.
Parameters
Name | Type |
---|---|
x | number | bigint | Field | UInt64 | UInt32 | UInt8 |
Returns
Defined in
sizeInFields
▸ Static
sizeInFields(): number
Return the size of the T
type in terms of Field type, as Field is the primitive type.
Warning: This function returns a number
, so you cannot use it to prove something on chain. You can use it during debugging or to understand the memory complexity of some type.
Returns
number
A number
representing the size of the T
type in terms of Field type.
Inherited from
Struct({ value: Field, }).sizeInFields
Defined in
toInput
▸ Static
toInput(x
): HashInput
Parameters
Name | Type |
---|---|
x | Object |
x.value | Field |
Returns
HashInput
Overrides
Struct({ value: Field, }).toInput