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.
Constructors
new Bool()
new Bool(x: boolean | FieldVar | Bool): Bool
Parameters
• x: boolean
| FieldVar
| Bool
Returns
Source
Properties
value
value: FieldVar;
Source
Unsafe
static Unsafe: {
"fromField": Bool;
};
fromField()
Converts a Field into a Bool. This is an unsafe operation as it assumes that the field element is either 0 or 1 (which might not be true).
Only use this if you have already constrained the Field element to be 0 or 1.
Parameters
• x: Field
a Field
Returns
Source
sizeInBytes
static sizeInBytes: number = 1;
Source
Methods
and()
and(y: boolean | Bool): Bool
Parameters
• y: boolean
| Bool
Returns
a new Bool that is set to true only if
this Bool and y
are also true.
Source
assertEquals()
assertEquals(y: boolean | Bool, message?: string): void
Proves that this Bool is equal to y
.
Parameters
• y: boolean
| Bool
a Bool.
• message?: string
Returns
void
Source
assertFalse()
assertFalse(message?: string): void
Proves that this Bool is false
.
Parameters
• message?: string
Returns
void
Source
assertTrue()
assertTrue(message?: string): void
Proves that this Bool is true
.
Parameters
• message?: string
Returns
void
Source
equals()
equals(y: boolean | Bool): Bool
Returns true if this Bool is equal to y
.
Parameters
• y: boolean
| Bool
a Bool.
Returns
Source
isConstant()
isConstant(): this is Object
Returns
this is Object
Source
not()
not(): Bool
Returns
a new Bool that is the negation of this Bool.
Source
or()
or(y: boolean | Bool): Bool
Parameters
• y: boolean
| Bool
Returns
a new Bool that is set to true if either
this Bool or y
is true.
Source
sizeInFields()
sizeInFields(): number
Returns the size of this type.
Returns
number
Source
toBoolean()
toBoolean(): boolean
This converts the Bool to a JS boolean
.
This can only be called on non-witness values.
Returns
boolean
Source
toField()
toField(): Field
Converts a Bool to a Field. false
becomes 0 and true
becomes 1.
Returns
Source
toFields()
toFields(): Field[]
Serializes this Bool into Field elements.
Returns
Field
[]
Source
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
Source
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
Source
and()
static and(x: boolean | Bool, y: boolean | Bool): Bool
Boolean AND operation.
Parameters
• x: boolean
| Bool
• y: boolean
| Bool
Returns
Source
assertEqual()
static assertEqual(x: Bool, y: boolean | Bool): void
Asserts if both Bool are equal.
Parameters
• x: Bool
• y: boolean
| Bool
Returns
void
Source
check()
static check(x: Bool): void
Parameters
• x: Bool
Returns
void
Source
empty()
static empty(): Bool
Returns
Source
equal()
static equal(x: boolean | Bool, y: boolean | Bool): Bool
Checks two Bool for equality.
Parameters
• x: boolean
| Bool
• y: boolean
| Bool
Returns
Source
fromBytes()
static fromBytes(bytes: number[]): Bool
Parameters
• bytes: number
[]
Returns
Source
fromFields()
static fromFields(fields: Field[]): Bool
Creates a data structure from an array of serialized Field elements.
Parameters
• fields: Field
[]
Returns
Source
fromJSON()
static fromJSON(b: boolean): 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
• b: boolean
Returns
Source
fromValue()
static fromValue(b: boolean | Bool): Bool
Provable<Bool>.fromValue()
Parameters
• b: boolean
| Bool
Returns
Source
not()
static not(x: boolean | Bool): Bool
Boolean negation.
Parameters
• x: boolean
| Bool
Returns
Source
or()
static or(x: boolean | Bool, y: boolean | Bool): Bool
Boolean OR operation.
Parameters
• x: boolean
| Bool
• y: boolean
| Bool
Returns
Source
readBytes()
static readBytes<N>(bytes: number[], offset: NonNegativeInteger<N>): [Bool, number]
Type parameters
• N extends number
Parameters
• bytes: number
[]
• offset: NonNegativeInteger
\<N
>
Returns
[Bool
, number
]
Source
sizeInFields()
static sizeInFields(): number
Returns the size of this type.
Returns
number
Source
toAuxiliary()
static toAuxiliary(_?: Bool): []
Static method to serialize a Bool into its auxiliary data.
Parameters
• _?: Bool
Returns
[]
Source
toBytes()
static toBytes(b: Bool): number[]
Parameters
• b: Bool
Returns
number
[]
Source
toField()
static toField(x: boolean | Bool): Field
Parameters
• x: boolean
| Bool
Returns
Source
toFields()
static toFields(x: Bool): Field[]
Static method to serialize a Bool into an array of Field elements.
Parameters
• x: Bool
Returns
Field
[]
Source
toInput()
static toInput(x: Bool): {
"packed": [Field, number][];
}
Parameters
• x: Bool
Returns
{
"packed": [Field, number][];
}
packed
packed: [Field, number][];
Source
toJSON()
static toJSON(x: Bool): 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
• x: Bool
Returns
boolean
Source
toValue()
static toValue(x: Bool): boolean
Provable<Bool>.toValue()
Parameters
• x: Bool
Returns
boolean