DocsReference@proto-kit/libraryClassesBalance

@proto-kit/libraryDocs


Documentation / @proto-kit/library / Balance

Class: Balance

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

Constructors

new Balance()

new Balance(value): Balance

Parameters

value

value.value: Field

Returns

Balance

Inherited from

UInt64.constructor

Defined in

packages/library/src/math/UInt.ts:72

Properties

value

value: Field = Field

Inherited from

UInt64.value

Defined in

packages/library/src/math/UInt.ts:45


_isStruct

static _isStruct: true

Inherited from

UInt64._isStruct

Defined in

node_modules/o1js/dist/node/lib/provable/types/struct.d.ts:104


assertionFunction()

readonly static assertionFunction: (bool, msg?) => void

Parameters

bool: Bool

msg?: string

Returns

void

Inherited from

UInt64.assertionFunction

Defined in

packages/library/src/math/UInt.ts:47


empty()

static empty: () => object

Returns

object

value

value: Field = Field

Inherited from

UInt64.empty

Defined in

node_modules/o1js/dist/node/lib/provable/types/struct.d.ts:113


fromFields()

static fromFields: (fields) => object

Parameters

fields: Field[]

Returns

object

value

value: Field = Field

Inherited from

UInt64.fromFields

Defined in

node_modules/o1js/dist/node/lib/provable/types/provable-intf.d.ts:95


fromJSON()

static fromJSON: (x) => object

Parameters

x

x.value: string = Field

Returns

object

value

value: Field = Field

Inherited from

UInt64.fromJSON

Defined in

node_modules/o1js/dist/node/lib/provable/types/struct.d.ts:112


fromValue

static fromValue: (x) => object & (value) => object

Convert provable type from a normal JS type.

Inherited from

UInt64.fromValue

Defined in

node_modules/o1js/dist/node/lib/provable/types/provable-intf.d.ts:68


Safe

static Safe: object

fromField()

Parameters

value: Field

Returns

UInt64

Inherited from

UInt64.Safe

Defined in

packages/library/src/math/UInt64.ts:12


toAuxiliary()

static toAuxiliary: (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

UInt64.toAuxiliary

Defined in

node_modules/o1js/dist/node/lib/provable/types/provable-intf.d.ts:34


toCanonical()?

static optional toCanonical: (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

UInt64.toCanonical

Defined in

node_modules/o1js/dist/node/lib/provable/types/provable-intf.d.ts:85


toFields()

static toFields: (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

UInt64.toFields

Defined in

node_modules/o1js/dist/node/lib/provable/types/provable-intf.d.ts:24


toInput()

static toInput: (x) => object

Parameters

x

x.value: Field = Field

Returns

object

fields?

optional fields: Field[]

packed?

optional packed: [Field, number][]

Inherited from

UInt64.toInput

Defined in

node_modules/o1js/dist/node/lib/provable/types/struct.d.ts:107


toJSON()

static toJSON: (x) => object

Parameters

x

x.value: Field = Field

Returns

object

value

value: string = Field

Inherited from

UInt64.toJSON

Defined in

node_modules/o1js/dist/node/lib/provable/types/struct.d.ts:111


toValue()

static toValue: (x) => object

Convert provable type to a normal JS type.

Parameters

x

x.value: Field = Field

Returns

object

value

value: bigint = Field

Inherited from

UInt64.toValue

Defined in

node_modules/o1js/dist/node/lib/provable/types/provable-intf.d.ts:64


Unsafe

static Unsafe: object

fromField()

Parameters

value: Field

Returns

UInt64

Inherited from

UInt64.Unsafe

Defined in

packages/library/src/math/UInt64.ts:6

Accessors

max

Get Signature

get static max(): UInt64

Returns

UInt64

Inherited from

UInt64.max

Defined in

packages/library/src/math/UInt64.ts:35


zero

Get Signature

get static zero(): UInt64

Returns

UInt64

Inherited from

UInt64.zero

Defined in

packages/library/src/math/UInt64.ts:31

Methods

add()

add(y): UInt<64>

Addition with overflow checking.

Parameters

y: number | bigint | UInt<64>

Returns

UInt<64>

Inherited from

UInt64.add

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<64>

message?: string

Returns

void

Inherited from

UInt64.assertEquals

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<64>

message?: string

Returns

void

Inherited from

UInt64.assertGreaterThan

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<64>

message?: string

Returns

void

Inherited from

UInt64.assertGreaterThanOrEqual

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<64>

message?: string

Returns

void

Inherited from

UInt64.assertLessThan

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<64>

message?: string

Returns

void

Inherited from

UInt64.assertLessThanOrEqual

Defined in

packages/library/src/math/UInt.ts:339


constructorReference()

constructorReference(): UIntConstructor<64>

Returns

UIntConstructor<64>

Inherited from

UInt64.constructorReference

Defined in

packages/library/src/math/UInt64.ts:39


div()

div(y): UInt<64>

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<64>

Returns

UInt<64>

Inherited from

UInt64.div

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<64>

Returns

object

quotient

quotient: UInt<64>

rest

rest: UInt<64>

Inherited from

UInt64.divMod

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<64>

Returns

Bool

Inherited from

UInt64.equals

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<64>

Returns

Bool

Inherited from

UInt64.greaterThan

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<64>

Returns

Bool

Inherited from

UInt64.greaterThanOrEqual

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<64>

Returns

Bool

Inherited from

UInt64.lessThan

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<64>

Returns

Bool

Inherited from

UInt64.lessThanOrEqual

Defined in

packages/library/src/math/UInt.ts:323


mod()

mod(y): UInt<64>

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<64>

Returns

UInt<64>

Inherited from

UInt64.mod

Defined in

packages/library/src/math/UInt.ts:273


mul()

mul(y): UInt<64>

Multiplication with overflow checking.

Parameters

y: number | bigint | UInt<64>

Returns

UInt<64>

Inherited from

UInt64.mul

Defined in

packages/library/src/math/UInt.ts:280


numBits()

numBits(): 64

Returns

64

Inherited from

UInt64.numBits

Defined in

packages/library/src/math/UInt64.ts:43


sqrtFloor()

sqrtFloor(): UInt<64>

Wraps sqrtMod() by only returning the sqrt and omitting the rest field.

Returns

UInt<64>

Inherited from

UInt64.sqrtFloor

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<64>

sqrt

sqrt: UInt<64>

Inherited from

UInt64.sqrtMod

Defined in

packages/library/src/math/UInt.ts:200


sub()

sub(y): UInt<64>

Subtraction with underflow checking.

Parameters

y: number | bigint | UInt<64>

Returns

UInt<64>

Inherited from

UInt64.sub

Defined in

packages/library/src/math/UInt.ts:311


toBigInt()

toBigInt(): bigint

Turns the UInt into a BigInt.

Returns

bigint

Inherited from

UInt64.toBigInt

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

Inherited from

UInt64.toO1UInt64

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

Inherited from

UInt64.toO1UInt64Clamped

Defined in

packages/library/src/math/UInt.ts:428


toString()

toString(): string

Turns the UInt into a string.

Returns

string

Inherited from

UInt64.toString

Defined in

packages/library/src/math/UInt.ts:103


check()

static check(x): 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

x

x.value: Field

Returns

void

Inherited from

UInt64.check

Defined in

packages/library/src/math/UInt64.ts:20


checkConstant()

static checkConstant(x, numBits): Field

Parameters

x: Field

numBits: number

Returns

Field

Inherited from

UInt64.checkConstant

Defined in

packages/library/src/math/UInt.ts:52


from()

static from(x): UInt64

Parameters

x: string | number | bigint | UInt64

Returns

UInt64

Inherited from

UInt64.from

Defined in

packages/library/src/math/UInt64.ts:24


maxIntField()

static maxIntField(numBits): Field

Creates a UInt with a value of 18,446,744,073,709,551,615.

Parameters

numBits: number

Returns

Field

Inherited from

UInt64.maxIntField

Defined in

packages/library/src/math/UInt.ts:68


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

UInt64.sizeInFields

Defined in

node_modules/o1js/dist/node/lib/provable/types/provable-intf.d.ts:51