Skip to main content

UInt8

A 8 bit unsigned integer with values ranging from 0 to 255.

Extends

  • {"value": Field; }

Constructors

new UInt8()

new UInt8(x: number | bigint | FieldVar | UInt8): UInt8

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

x: number | bigint | FieldVar | UInt8

Returns

UInt8

Overrides

Struct({ value: Field, }).constructor

Source

lib/provable/int.ts:1239

Properties

value

value: Field = Field;

Inherited from

Struct({ value: Field, }).value

Source

lib/provable/int.ts:1229


NUM_BITS

static NUM_BITS: number = 8;

Source

lib/provable/int.ts:1231


Unsafe

static Unsafe: {
"fromField": UInt8;
};

fromField()

Create a UInt8 from a Field without constraining its range.

Warning: This is unsafe, because it does not prove that the input Field actually fits in 8 bits.\ Only use this if you know what you are doing, otherwise use the safe UInt8.from.

Parameters

x: Field

Returns

UInt8

Source

lib/provable/int.ts:1245


_isStruct

static _isStruct: true;

Inherited from

Struct({ value: Field, })._isStruct

Source

lib/provable/types/struct.ts:145


empty()

static empty: () => {
"value": Field;
};

Returns

{
"value": Field;
}
value
value: Field = Field;

Inherited from

Struct({ value: Field, }).empty

Source

lib/provable/types/struct.ts:155


fromFields()

static fromFields: (fields: Field[]) => {
"value": Field;
};

Parameters

fields: Field[]

Returns

{
"value": Field;
}
value
value: Field = Field;

Inherited from

Struct({ value: Field, }).fromFields

Source

lib/provable/types/provable-intf.ts:87


fromJSON()

static fromJSON: (x: {
"value": Field;
}) => {
"value": Field;
};

Parameters

x

x.value: string= Field

Returns

{
"value": Field;
}
value
value: Field = Field;

Inherited from

Struct({ value: Field, }).fromJSON

Source

lib/provable/types/struct.ts:154


fromValue

static fromValue: (x: {
"value": Field;
} | {
"value": Field;
}) => {
"value": Field;
} & (value: {
"value": Field;
}) => {
"value": Field;
};

Convert provable type from a normal JS type.

Inherited from

Struct({ value: Field, }).fromValue

Source

lib/provable/types/provable-intf.ts:76


toAuxiliary()

static toAuxiliary: (value?: {
"value": Field;
}) => 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.

Parameters

value?

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

Inherited from

Struct({ value: Field, }).toAuxiliary

Source

lib/provable/types/provable-intf.ts:37


toFields()

static toFields: (value: {
"value": Field;
}) => 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

value

the element of type T to generate the Field array from.

value.value: Field= Field

Returns

Field[]

Inherited from

Struct({ value: Field, }).toFields

Source

lib/provable/types/provable-intf.ts:26


toJSON()

static toJSON: (x: {
"value": Field;
}) => {
"value": Field;
};

Parameters

x

x.value: Field= Field

Returns

{
"value": Field;
}
value
value: string = Field;

Inherited from

Struct({ value: Field, }).toJSON

Source

lib/provable/types/struct.ts:153


toValue()

static toValue: (x: {
"value": Field;
}) => {
"value": Field;
};

Convert provable type to a normal JS type.

Parameters

x

x.value: Field= Field

Returns

{
"value": Field;
}
value
value: bigint = Field;

Inherited from

Struct({ value: Field, }).toValue

Source

lib/provable/types/provable-intf.ts:71

Methods

add()

add(y: number | bigint | UInt8): UInt8

Add a UInt8 to another UInt8 without allowing overflow.

Parameters

y: number | bigint | UInt8

Returns

UInt8

Example

const x = UInt8.from(3);
const sum = x.add(5);
sum.assertEquals(8);

Throws

if the result is greater than 255.

Source

lib/provable/int.ts:1269


assertEquals()

assertEquals(y: number | bigint | UInt8, message?: string): void

Assert that this UInt8 is equal another UInt8 value.

Important: If an assertion fails, the code throws an error.

Parameters

y: number | bigint | UInt8

the UInt8 value to compare & assert with this UInt8.

message?: string

Returns

void

Source

lib/provable/int.ts:1535


assertGreaterThan()

assertGreaterThan(y: number | bigint | UInt8, message?: string): void

Assert that this UInt8 is greater than another UInt8 value.

Important: If an assertion fails, the code throws an error.

Parameters

y: number | bigint | UInt8

the UInt8 value to compare & assert with this UInt8.

message?: string

Returns

void

Source

lib/provable/int.ts:1511


assertGreaterThanOrEqual()

assertGreaterThanOrEqual(y: UInt8, message?: string): 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

y: UInt8

the UInt8 value to compare & assert with this UInt8.

message?: string

Returns

void

Source

lib/provable/int.ts:1523


assertLessThan()

assertLessThan(y: number | bigint | UInt8, message?: string): void

Assert that this UInt8 is less than another UInt8 value.

Important: If an assertion fails, the code throws an error.

Parameters

y: number | bigint | UInt8

the UInt8 value to compare & assert with this UInt8.

message?: string

Returns

void

Source

lib/provable/int.ts:1429


assertLessThanOrEqual()

assertLessThanOrEqual(y: number | bigint | UInt8, message?: string): 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

y: number | bigint | UInt8

the UInt8 value to compare & assert with this UInt8.

message?: string

Returns

void

Source

lib/provable/int.ts:1454


div()

div(y: number | bigint | UInt8): UInt8

Divide a UInt8 by another UInt8. This is integer division that rounds down.

Parameters

y: number | bigint | UInt8

Returns

UInt8

Example

const x = UInt8.from(7);
const quotient = x.div(2);
quotient.assertEquals(3);

Source

lib/provable/int.ts:1322


divMod()

divMod(y: number | bigint | UInt8): {
"quotient": UInt8;
"remainder": UInt8;
}

Get the quotient and remainder of a UInt8 divided by another UInt8:

x == y * q + r, where 0 <= r < y.

Parameters

y: number | bigint | UInt8

a UInt8 to get the quotient and remainder of another UInt8.

Returns

{
"quotient": UInt8;
"remainder": UInt8;
}

The quotient q and remainder r.

quotient
quotient: UInt8;
remainder
remainder: UInt8;

Source

lib/provable/int.ts:1349


greaterThan()

greaterThan(y: number | bigint | UInt8): Bool

Check if this UInt8 is greater than another UInt8. Returns a Bool.

Parameters

y: number | bigint | UInt8

Returns

Bool

Example

// 5 > 3
UInt8.from(5).greaterThan(3);

Source

lib/provable/int.ts:1485


greaterThanOrEqual()

greaterThanOrEqual(y: number | bigint | UInt8): Bool

Check if this UInt8 is greater than or equal another UInt8 value. Returns a Bool.

Parameters

y: number | bigint | UInt8

Returns

Bool

Example

// 3 >= 3
UInt8.from(3).greaterThanOrEqual(3);

Source

lib/provable/int.ts:1499


lessThan()

lessThan(y: number | bigint | UInt8): Bool

Check if this UInt8 is less than another UInt8 value. Returns a Bool.

Parameters

y: number | bigint | UInt8

Returns

Bool

Example

UInt8.from(2).lessThan(UInt8.from(3));

Source

lib/provable/int.ts:1408


lessThanOrEqual()

lessThanOrEqual(y: number | bigint | UInt8): Bool

Check if this UInt8 is less than or equal to another UInt8 value. Returns a Bool.

Parameters

y: number | bigint | UInt8

Returns

Bool

Example

UInt8.from(3).lessThanOrEqual(UInt8.from(5));

Source

lib/provable/int.ts:1386


mod()

mod(y: number | bigint | UInt8): UInt8

Get the remainder a UInt8 of division of another UInt8.

Parameters

y: number | bigint | UInt8

Returns

UInt8

Example

const x = UInt8.from(50);
const mod = x.mod(30);
mod.assertEquals(20);

Source

lib/provable/int.ts:1336


mul()

mul(y: number | bigint | UInt8): UInt8

Multiply a UInt8 by another UInt8 without allowing overflow.

Parameters

y: number | bigint | UInt8

Returns

UInt8

Example

const x = UInt8.from(3);
const product = x.mul(5);
product.assertEquals(15);

Throws

if the result is greater than 255.

Source

lib/provable/int.ts:1305


sub()

sub(y: number | bigint | UInt8): UInt8

Subtract a UInt8 from another UInt8 without allowing underflow.

Parameters

y: number | bigint | UInt8

Returns

UInt8

Example

const x = UInt8.from(8);
const difference = x.sub(5);
difference.assertEquals(3);

Throws

if the result is less than 0.

Source

lib/provable/int.ts:1287


toBigInt()

toBigInt(): bigint

Serialize the UInt8 to a bigint.

Warning: This operation is not provable.

Returns

bigint

Source

lib/provable/int.ts:1563


toNumber()

toNumber(): number

Serialize the UInt8 to a number.

Warning: This operation is not provable.

Returns

number

Source

lib/provable/int.ts:1554


toString()

toString(): string

Serialize the UInt8 to a string, e.g. for printing.

Warning: This operation is not provable.

Returns

string

Source

lib/provable/int.ts:1545


toUInt32()

toUInt32(): UInt32

Turns a UInt8 into a UInt32.

Returns

UInt32

Source

lib/provable/int.ts:1583


toUInt64()

toUInt64(): UInt64

Turns a UInt8 into a UInt64.

Returns

UInt64

Source

lib/provable/int.ts:1590


MAXINT()

static MAXINT(): UInt8

Creates a UInt8 with a value of 255.

Returns

UInt8

Source

lib/provable/int.ts:1597


check()

static check(x: Field | {
"value": Field;
}): void

Provable.check for UInt8. Proves that the input is in the [0, 255] range.

Parameters

x: Field | { "value": Field; }

Returns

void

Overrides

Struct({ value: Field, }).check

Source

lib/provable/int.ts:1571


from()

static from(x: 
| number
| bigint
| Field
| UInt64
| UInt32
| UInt8): UInt8

Creates a new UInt8.

Parameters

x: | number | bigint | Field | UInt64 | UInt32 | UInt8

Returns

UInt8

Source

lib/provable/int.ts:1604


sizeInFields()

static sizeInFields(): number

Return the size of the T type in terms of Field type, as Field is the primitive type.

Returns

number

A number representing the size of the T type in terms of Field type.

Inherited from

Struct({ value: Field, }).sizeInFields

Source

lib/provable/types/provable-intf.ts:56


toInput()

static toInput(x: {
"value": Field;
}): HashInput

Parameters

x

x.value: Field

Returns

HashInput

Overrides

Struct({ value: Field, }).toInput

Source

lib/provable/int.ts:1576