Skip to main content

Bool

o1js / Modules / Bool

Class: Bool

A boolean value. You can use it like this:

const x = new Bool(true);

You can also combine multiple booleans via [[not]], [[and]], [[or]].

Use [[assertEquals]] to enforce the value of a Bool.

Table of contents

Constructors

Properties

Methods

Constructors

constructor

new Bool(x)

Parameters

NameType
xboolean | Bool | FieldVar

Defined in

lib/bool.ts:36

Properties

value

value: FieldVar

Defined in

lib/bool.ts:34


Unsafe

Static Unsafe: Object

Type declaration

NameType
ofField(x: Field) => Bool

Defined in

lib/bool.ts:327


sizeInBytes

Static sizeInBytes: number = 1

Defined in

lib/bool.ts:321

Methods

and

and(y): Bool

Parameters

NameTypeDescription
yboolean | BoolA Bool to AND with this Bool.

Returns

Bool

a new Bool that is set to true only if this Bool and y are also true.

Defined in

lib/bool.ts:74


assertEquals

assertEquals(y, message?): void

Proves that this Bool is equal to y.

Parameters

NameTypeDescription
yboolean | Boola Bool.
message?string-

Returns

void

Defined in

lib/bool.ts:97


assertFalse

assertFalse(message?): void

Proves that this Bool is false.

Parameters

NameType
message?string

Returns

void

Defined in

lib/bool.ts:128


assertTrue

assertTrue(message?): void

Proves that this Bool is true.

Parameters

NameType
message?string

Returns

void

Defined in

lib/bool.ts:114


equals

equals(y): Bool

Returns true if this Bool is equal to y.

Parameters

NameTypeDescription
yboolean | Boola Bool.

Returns

Bool

Defined in

lib/bool.ts:143


isConstant

isConstant(): this is Object

Returns

this is Object

Defined in

lib/bool.ts:48


not

not(): Bool

Returns

Bool

a new Bool that is the negation of this Bool.

Defined in

lib/bool.ts:62


or

or(y): Bool

Parameters

NameTypeDescription
yboolean | Boola Bool to OR with this Bool.

Returns

Bool

a new Bool that is set to true if either this Bool or y is true.

Defined in

lib/bool.ts:86


sizeInFields

sizeInFields(): number

Returns the size of this type.

Returns

number

Defined in

lib/bool.ts:153


toBoolean

toBoolean(): boolean

This converts the Bool to a javascript [[boolean]]. This can only be called on non-witness values.

Returns

boolean

Defined in

lib/bool.ts:184


toField

toField(): Field

Converts a Bool to a Field. false becomes 0 and true becomes 1.

Returns

Field

Defined in

lib/bool.ts:55


toFields

toFields(): Field[]

Serializes this Bool into Field elements.

Returns

Field[]

Defined in

lib/bool.ts:160


toJSON

toJSON(): boolean

Serialize the Bool to a JSON string. This operation does not affect the circuit and can't be used to prove anything about the string representation of the Field.

Returns

boolean

Defined in

lib/bool.ts:176


toString

toString(): string

Serialize the Bool to a string, e.g. for printing. This operation does not affect the circuit and can't be used to prove anything about the string representation of the Field.

Returns

string

Defined in

lib/bool.ts:168


and

Static and(x, y): Bool

Boolean AND operation.

Parameters

NameType
xboolean | Bool
yboolean | Bool

Returns

Bool

Defined in

lib/bool.ts:213


assertEqual

Static assertEqual(x, y): void

Asserts if both Bool are equal.

Parameters

NameType
xBool
yboolean | Bool

Returns

void

Defined in

lib/bool.ts:233


check

Static check(x): void

Parameters

NameType
xBool

Returns

void

Defined in

lib/bool.ts:323


empty

Static empty(): Bool

Returns

Bool

Defined in

lib/bool.ts:298


equal

Static equal(x, y): Bool

Checks two Bool for equality.

Parameters

NameType
xboolean | Bool
yboolean | Bool

Returns

Bool

Defined in

lib/bool.ts:244


fromBytes

Static fromBytes(bytes): Bool

Parameters

NameType
bytesnumber[]

Returns

Bool

Defined in

lib/bool.ts:310


fromFields

Static fromFields(fields): Bool

Creates a data structure from an array of serialized Field elements.

Parameters

NameType
fieldsField[]

Returns

Bool

Defined in

lib/bool.ts:268


fromJSON

Static fromJSON(b): Bool

Deserialize a JSON structure into a Bool. This operation does not affect the circuit and can't be used to prove anything about the string representation of the Field.

Parameters

NameType
bboolean

Returns

Bool

Defined in

lib/bool.ts:287


not

Static not(x): Bool

Boolean negation.

Parameters

NameType
xboolean | Bool

Returns

Bool

Defined in

lib/bool.ts:203


or

Static or(x, y): Bool

Boolean OR operation.

Parameters

NameType
xboolean | Bool
yboolean | Bool

Returns

Bool

Defined in

lib/bool.ts:223


readBytes

Static readBytes\<N>(bytes, offset): [value: Bool, offset: number]

Type parameters

NameType
Nextends number

Parameters

NameType
bytesnumber[]
offsetNonNegativeInteger\<N>

Returns

[value: Bool, offset: number]

Defined in

lib/bool.ts:314


sizeInFields

Static sizeInFields(): number

Returns the size of this type.

Returns

number

Defined in

lib/bool.ts:294


toAuxiliary

Static toAuxiliary(_?): []

Static method to serialize a Bool into its auxiliary data.

Parameters

NameType
_?Bool

Returns

[]

Defined in

lib/bool.ts:261


toBytes

Static toBytes(b): number[]

Parameters

NameType
bBool

Returns

number[]

Defined in

lib/bool.ts:306


toField

Static toField(x): Field

Parameters

NameType
xboolean | Bool

Returns

Field

Defined in

lib/bool.ts:196


toFields

Static toFields(x): Field[]

Static method to serialize a Bool into an array of Field elements.

Parameters

NameType
xBool

Returns

Field[]

Defined in

lib/bool.ts:254


toInput

Static toInput(x): Object

Parameters

NameType
xBool

Returns

Object

NameType
packed[Field, number][]

Defined in

lib/bool.ts:302


toJSON

Static toJSON(x): boolean

Serialize a Bool to a JSON string. This operation does not affect the circuit and can't be used to prove anything about the string representation of the Field.

Parameters

NameType
xBool

Returns

boolean

Defined in

lib/bool.ts:279