Class: Scalar
Represents a Scalar.
Table of contents
Constructors
Methods
- add
- div
- mul
- neg
- sub
- toFields
- toJSON
- check
- fromBigInt
- fromBits
- fromFields
- fromJSON
- random
- sizeInFields
- toAuxiliary
- toFields
- toFieldsCompressed
- toJSON
Constructors
constructor
• new Scalar()
Methods
add
▸ add(y): Scalar
Add scalar field elements. Can only be called outside of circuit execution
Parameters
| Name | Type |
|---|---|
y | Scalar |
Returns
Defined in
div
▸ div(y): Scalar
Divide scalar field elements. Can only be called outside of circuit execution
Parameters
| Name | Type |
|---|---|
y | Scalar |
Returns
Defined in
mul
▸ mul(y): Scalar
Multiply scalar field elements. Can only be called outside of circuit execution
Parameters
| Name | Type |
|---|---|
y | Scalar |
Returns
Defined in
neg
▸ neg(): Scalar
Negate a scalar field element. Can only be called outside of circuit execution
Returns
Defined in
sub
▸ sub(y): Scalar
Subtract scalar field elements. Can only be called outside of circuit execution
Parameters
| Name | Type |
|---|---|
y | Scalar |
Returns
Defined in
toFields
▸ toFields(): Field[]
Serialize this Scalar to Field elements.
WARNING: This function is for internal usage by the proof system. It returns 255 field elements which represent the Scalar in a shifted, bitwise format. Check out toFieldsCompressed for a user-friendly serialization that can be used outside proofs.
Returns
Field[]
Defined in
toJSON
▸ toJSON(): string
Serializes this Scalar to a string
Returns
string
Defined in
check
▸ Static check(x): void
Parameters
| Name | Type |
|---|---|
x | Scalar |
Returns
void
Defined in
fromBigInt
▸ Static fromBigInt(s): Scalar
Create a constant Scalar from a bigint. If the bigint is too large, it is reduced modulo the scalar field order.
Parameters
| Name | Type |
|---|---|
s | bigint |
Returns
Defined in
fromBits
▸ Static fromBits(bits): Scalar
Creates a data structure from an array of serialized Bool.
Parameters
| Name | Type |
|---|---|
bits | Bool[] |
Returns
Defined in
fromFields
▸ Static fromFields(fields): Scalar
Creates a data structure from an array of serialized Field elements.
Parameters
| Name | Type |
|---|---|
fields | Field[] |
Returns
Defined in
fromJSON
▸ Static fromJSON(x): Scalar
Deserialize a JSON structure into a Scalar. This operation does NOT affect the circuit and can't be used to prove anything about the string representation of the Scalar.
Parameters
| Name | Type |
|---|---|
x | string | number | boolean |
Returns
Defined in
random
▸ Static random(): Scalar
Returns a random Scalar. Randomness can not be proven inside a circuit!
Returns
Defined in
sizeInFields
▸ Static sizeInFields(): number
Returns the size of this type.
Returns
number
Defined in
toAuxiliary
▸ Static toAuxiliary(x?): []
Static method to serialize a Scalar into its auxiliary data.
Parameters
| Name | Type |
|---|---|
x? | Scalar |
Returns
[]
Defined in
toFields
▸ Static toFields(x): Field[]
Static method to serialize a Scalar into an array of Field elements.
Parameters
| Name | Type |
|---|---|
x | Scalar |
Returns
Field[]
Defined in
toFieldsCompressed
▸ Static toFieldsCompressed(s): Object
Serialize a Scalar into a Field element plus one bit, where the bit is represented as a Bool.
Note: Since the Scalar field is slightly larger than the base Field, an additional high bit
is needed to represent all Scalars. However, for a random Scalar, the high bit will be false with overwhelming probability.
Parameters
| Name | Type |
|---|---|
s | Scalar |
Returns
Object
| Name | Type |
|---|---|
field | Field |
highBit | Bool |
Defined in
toJSON
▸ Static toJSON(x): string
Serialize a Scalar 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 Scalar.
Parameters
| Name | Type |
|---|---|
x | Scalar |
Returns
string