@proto-kit/library • Docs
Documentation / @proto-kit/library / UInt
Class: abstract UInt<BITS>
UInt is a base class for all soft-failing UInt* implementations. It has to be overridden for every bitlength that should be available.
For this, the developer has to create a subclass of UInt implementing the static methods from interface UIntConstructor
Extends
object
Extended by
Type Parameters
• BITS extends number
Constructors
new UInt()
new UInt<
BITS>(value):UInt<BITS>
Parameters
• value
• value.value: Field
Returns
UInt<BITS>
Overrides
Struct({ value: Field, }).constructor
Defined in
packages/library/src/math/UInt.ts:72
Properties
value
value:
Field=Field
Inherited from
Struct({ value: Field, }).value
Defined in
packages/library/src/math/UInt.ts:45
_isStruct
static_isStruct:true
Inherited from
Struct({ value: Field, })._isStruct
Defined in
node_modules/o1js/dist/node/lib/provable/types/struct.d.ts:104
assertionFunction()
readonlystaticassertionFunction: (bool,msg?) =>void
Parameters
• bool: Bool
• msg?: string
Returns
void
Defined in
packages/library/src/math/UInt.ts:47
check()
staticcheck: (value) =>void
Add assertions to the proof to check if value is a valid member of type T.
This function does not return anything, instead it creates any number of assertions to prove that value is a valid member of the type T.
For instance, calling check function on the type Bool asserts that the value of the element is either 1 or 0.
Parameters
• value
the element of type T to put assertions on.
• value.value: Field = Field
Returns
void
Inherited from
Struct({ value: Field, }).check
Defined in
node_modules/o1js/dist/node/lib/provable/types/provable-intf.d.ts:60
empty()
staticempty: () =>object
Returns
object
value
value:
Field=Field
Inherited from
Struct({ value: Field, }).empty
Defined in
node_modules/o1js/dist/node/lib/provable/types/struct.d.ts:113
fromFields()
staticfromFields: (fields) =>object
Parameters
• fields: Field[]
Returns
object
value
value:
Field=Field
Inherited from
Struct({ value: Field, }).fromFields
Defined in
node_modules/o1js/dist/node/lib/provable/types/provable-intf.d.ts:95
fromJSON()
staticfromJSON: (x) =>object
Parameters
• x
• x.value: string = Field
Returns
object
value
value:
Field=Field
Inherited from
Struct({ value: Field, }).fromJSON
Defined in
node_modules/o1js/dist/node/lib/provable/types/struct.d.ts:112
fromValue
staticfromValue: (x) =>object& (value) =>object
Convert provable type from a normal JS type.
Inherited from
Struct({ value: Field, }).fromValue
Defined in
node_modules/o1js/dist/node/lib/provable/types/provable-intf.d.ts:68
toAuxiliary()
statictoAuxiliary: (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.
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[]
An array of any type describing how this T element is made up of “auxiliary” (non-provable) data.
Inherited from
Struct({ value: Field, }).toAuxiliary
Defined in
node_modules/o1js/dist/node/lib/provable/types/provable-intf.d.ts:34
toCanonical()?
staticoptionaltoCanonical: (x) =>object
Optional method which transforms a provable type into its canonical representation.
This is needed for types that have multiple representations of the same underlying value, and might even not have perfect completeness for some of those representations.
An example is the ForeignField class, which allows non-native field elements to exist in unreduced form.
The unreduced form is not perfectly complete, for example, addition of two unreduced field elements can cause a prover error.
Specific protocols need to be able to protect themselves against incomplete operations at all costs.
For example, when using actions and reducer, the reducer must be able to produce a proof regardless of the input action.
toCanonical() converts any input into a safe form and enables us to handle cases like this generically.
Note: For most types, this method is the identity function.
The identity function will also be used when the toCanonical() is not present on a type.
Parameters
• x
• x.value: Field = Field
Returns
object
value
value:
Field=Field
Inherited from
Struct({ value: Field, }).toCanonical
Defined in
node_modules/o1js/dist/node/lib/provable/types/provable-intf.d.ts:85
toFields()
statictoFields: (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
• value
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
node_modules/o1js/dist/node/lib/provable/types/provable-intf.d.ts:24
toInput()
statictoInput: (x) =>object
Parameters
• x
• x.value: Field = Field
Returns
object
fields?
optionalfields:Field[]
packed?
optionalpacked: [Field,number][]
Inherited from
Struct({ value: Field, }).toInput
Defined in
node_modules/o1js/dist/node/lib/provable/types/struct.d.ts:107
toJSON()
statictoJSON: (x) =>object
Parameters
• x
• x.value: Field = Field
Returns
object
value
value:
string=Field
Inherited from
Struct({ value: Field, }).toJSON
Defined in
node_modules/o1js/dist/node/lib/provable/types/struct.d.ts:111
toValue()
statictoValue: (x) =>object
Convert provable type to a normal JS type.
Parameters
• x
• x.value: Field = Field
Returns
object
value
value:
bigint=Field
Inherited from
Struct({ value: Field, }).toValue
Defined in
node_modules/o1js/dist/node/lib/provable/types/provable-intf.d.ts:64
Methods
add()
add(
y):UInt<BITS>
Addition with overflow checking.
Parameters
• y: number | bigint | UInt<BITS>
Returns
UInt<BITS>
Defined in
packages/library/src/math/UInt.ts:299
assertEquals()
assertEquals(
y,message?):void
Asserts that a UInt is equal to another one.
Parameters
• y: number | bigint | UInt<BITS>
• message?: string
Returns
void
Defined in
packages/library/src/math/UInt.ts:411
assertGreaterThan()
assertGreaterThan(
y,message?):void
Asserts that a UInt is greater than another one.
Parameters
• y: UInt<BITS>
• message?: string
Returns
void
Defined in
packages/library/src/math/UInt.ts:383
assertGreaterThanOrEqual()
assertGreaterThanOrEqual(
y,message?):void
Asserts that a UInt is greater than or equal to another one.
Parameters
• y: UInt<BITS>
• message?: string
Returns
void
Defined in
packages/library/src/math/UInt.ts:397
assertLessThan()
assertLessThan(
y,message?):void
Asserts that a UInt is less than another one.
Parameters
• y: UInt<BITS>
• message?: string
Returns
void
Defined in
packages/library/src/math/UInt.ts:369
assertLessThanOrEqual()
assertLessThanOrEqual(
y,message?):void
Asserts that a UInt is less than or equal to another one.
Parameters
• y: UInt<BITS>
• message?: string
Returns
void
Defined in
packages/library/src/math/UInt.ts:339
constructorReference()
abstractconstructorReference():UIntConstructor<BITS>
Returns
UIntConstructor<BITS>
Defined in
packages/library/src/math/UInt.ts:89
div()
div(
y):UInt<BITS>
Integer division.
x.div(y) returns the floor of x / y, that is, the greatest
z such that z * y <= x.
Parameters
• y: number | bigint | UInt<BITS>
Returns
UInt<BITS>
Defined in
packages/library/src/math/UInt.ts:181
divMod()
divMod(
divisor):object
Integer division with remainder.
x.divMod(y) returns the quotient and the remainder.
Parameters
• divisor: string | number | bigint | UInt<BITS>
Returns
object
quotient
quotient:
UInt<BITS>
rest
rest:
UInt<BITS>
Defined in
packages/library/src/math/UInt.ts:120
equals()
equals(
y):Bool
Checks if a UInt is equal to another one.
Parameters
• y: number | bigint | UInt<BITS>
Returns
Bool
Defined in
packages/library/src/math/UInt.ts:404
greaterThan()
greaterThan(
y):Bool
Checks if a UInt is greater than another one.
Parameters
• y: UInt<BITS>
Returns
Bool
Defined in
packages/library/src/math/UInt.ts:376
greaterThanOrEqual()
greaterThanOrEqual(
y):Bool
Checks if a UInt is greater than or equal to another one.
Parameters
• y: UInt<BITS>
Returns
Bool
Defined in
packages/library/src/math/UInt.ts:390
lessThan()
lessThan(
y):Bool
Checks if a UInt is less than another one.
Parameters
• y: UInt<BITS>
Returns
Bool
Defined in
packages/library/src/math/UInt.ts:362
lessThanOrEqual()
lessThanOrEqual(
y):Bool
Checks if a UInt is less than or equal to another one.
Parameters
• y: UInt<BITS>
Returns
Bool
Defined in
packages/library/src/math/UInt.ts:323
mod()
mod(
y):UInt<BITS>
Integer remainder.
x.mod(y) returns the value z such that 0 <= z < y and
x - z is divisble by y.
Parameters
• y: number | bigint | UInt<BITS>
Returns
UInt<BITS>
Defined in
packages/library/src/math/UInt.ts:273
mul()
mul(
y):UInt<BITS>
Multiplication with overflow checking.
Parameters
• y: number | bigint | UInt<BITS>
Returns
UInt<BITS>
Defined in
packages/library/src/math/UInt.ts:280
numBits()
abstractnumBits():BITS
Returns
BITS
Defined in
packages/library/src/math/UInt.ts:87
sqrtFloor()
sqrtFloor():
UInt<BITS>
Wraps sqrtMod() by only returning the sqrt and omitting the rest field.
Returns
UInt<BITS>
Defined in
packages/library/src/math/UInt.ts:263
sqrtMod()
sqrtMod():
object
Implements a non-overflowing square-root with rest. Normal Field.sqrt() provides the sqrt as it is defined by the finite field operations. This implementation however mimics the natural-numbers style of sqrt to be used inside applications with the tradeoff that it also returns a “rest” that indicates the amount the actual result is off (since we floor the result to stay inside the ff).
Some assertions are hard-failing, because they represent malicious witness values
Returns
object
sqrt: The non-overflowing sqrt
rest: The remainder indicating how far off the result is from the “real” sqrt
rest
rest:
UInt<BITS>
sqrt
sqrt:
UInt<BITS>
Defined in
packages/library/src/math/UInt.ts:200
sub()
sub(
y):UInt<BITS>
Subtraction with underflow checking.
Parameters
• y: number | bigint | UInt<BITS>
Returns
UInt<BITS>
Defined in
packages/library/src/math/UInt.ts:311
toBigInt()
toBigInt():
bigint
Turns the UInt into a BigInt.
Returns
bigint
Defined in
packages/library/src/math/UInt.ts:111
toO1UInt64()
toO1UInt64():
UInt64
Turns the UInt into a o1js UInt64, asserting that it fits in 32 bits.
Returns
UInt64
Defined in
packages/library/src/math/UInt.ts:418
toO1UInt64Clamped()
toO1UInt64Clamped():
UInt64
Turns the UInt into a o1js UInt64, clamping to the 64 bits range if it’s too large.
Returns
UInt64
Defined in
packages/library/src/math/UInt.ts:428
toString()
toString():
string
Turns the UInt into a string.
Returns
string
Defined in
packages/library/src/math/UInt.ts:103
checkConstant()
staticcheckConstant(x,numBits):Field
Parameters
• x: Field
• numBits: number
Returns
Field
Defined in
packages/library/src/math/UInt.ts:52
maxIntField()
staticmaxIntField(numBits):Field
Creates a UInt with a value of 18,446,744,073,709,551,615.
Parameters
• numBits: number
Returns
Field
Defined in
packages/library/src/math/UInt.ts:68
sizeInFields()
staticsizeInFields():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
Defined in
node_modules/o1js/dist/node/lib/provable/types/provable-intf.d.ts:51