Skip to main content

Bool

SnarkyJS / 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:30

Properties

value

value: FieldVar

Defined in

lib/bool.ts:28


Unsafe

Static Unsafe: Object

Type declaration

NameType
ofField(x: Field) => Bool

Defined in

lib/bool.ts:317

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:68


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:91


assertFalse

assertFalse(message?): void

Proves that this Bool is false.

Parameters

NameType
message?string

Returns

void

Defined in

lib/bool.ts:122


assertTrue

assertTrue(message?): void

Proves that this Bool is true.

Parameters

NameType
message?string

Returns

void

Defined in

lib/bool.ts:108


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:137


isConstant

isConstant(): this is Object

Returns

this is Object

Defined in

lib/bool.ts:42


not

not(): Bool

Returns

Bool

a new Bool that is the negation of this Bool.

Defined in

lib/bool.ts:56


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:80


sizeInFields

sizeInFields(): number

Returns the size of this type.

Returns

number

Defined in

lib/bool.ts:147


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:178


toField

toField(): Field

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

Returns

Field

Defined in

lib/bool.ts:49


toFields

toFields(): Field[]

Serializes this Bool into Field elements.

Returns

Field[]

Defined in

lib/bool.ts:154


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:170


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:162


#isBool

Static Private #isBool(x): x is Bool

Parameters

NameType
xboolean | Bool | FieldVar

Returns

x is Bool

Defined in

lib/bool.ts:336


#toVar

Static Private #toVar(x): FieldVar

Parameters

NameType
xboolean | Bool

Returns

FieldVar

Defined in

lib/bool.ts:340


and

Static and(x, y): Bool

Boolean AND operation.

Parameters

NameType
xboolean | Bool
yboolean | Bool

Returns

Bool

Defined in

lib/bool.ts:205


assertEqual

Static assertEqual(x, y): void

Asserts if both Bool are equal.

Parameters

NameType
xBool
yboolean | Bool

Returns

void

Defined in

lib/bool.ts:225


check

Static check(x): void

Parameters

NameType
xBool

Returns

void

Defined in

lib/bool.ts:313


equal

Static equal(x, y): Bool

Checks two Bool for equality.

Parameters

NameType
xboolean | Bool
yboolean | Bool

Returns

Bool

Defined in

lib/bool.ts:236


fromBytes

Static fromBytes(bytes): Bool

Parameters

NameType
bytesnumber[]

Returns

Bool

Defined in

lib/bool.ts:298


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:260


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:279


not

Static not(x): Bool

Boolean negation.

Parameters

NameType
xboolean | Bool

Returns

Bool

Defined in

lib/bool.ts:195


or

Static or(x, y): Bool

Boolean OR operation.

Parameters

NameType
xboolean | Bool
yboolean | Bool

Returns

Bool

Defined in

lib/bool.ts:215


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:302


sizeInBytes

Static sizeInBytes(): number

Returns

number

Defined in

lib/bool.ts:309


sizeInFields

Static sizeInFields(): number

Returns the size of this type.

Returns

number

Defined in

lib/bool.ts:286


toAuxiliary

Static toAuxiliary(_?): []

Static method to serialize a Bool into its auxiliary data.

Parameters

NameType
_?Bool

Returns

[]

Defined in

lib/bool.ts:253


toBytes

Static toBytes(b): number[]

Parameters

NameType
bBool

Returns

number[]

Defined in

lib/bool.ts:294


toField

Static toField(x): Field

Parameters

NameType
xboolean | Bool

Returns

Field

Defined in

lib/bool.ts:188


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:246


toInput

Static toInput(x): Object

Parameters

NameType
xBool

Returns

Object

NameType
packed[Field, number][]

Defined in

lib/bool.ts:290


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:271