Group
An element of a Group.
Constructors
new Group()
new Group(__namedParameters: {
"x": | string
| number
| bigint
| FieldVar
| Field;
"y": | string
| number
| bigint
| FieldVar
| Field;
}): Group
Coerces anything group-like to a Group.
Parameters
• __namedParameters
• __namedParameters.x:
| string
| number
| bigint
| FieldVar
| Field
• __namedParameters.y:
| string
| number
| bigint
| FieldVar
| Field
Returns
Source
Properties
x
x: Field;
Source
y
y: Field;
Source
Accessors
generator
get static generator(): Group
The generator g
of the Group.
Returns
Source
zero
get static zero(): Group
Unique representation of the zero
element of the Group (the identity element of addition in this Group).
Note: The zero
element is represented as (0, 0)
.
// g + -g = 0
g.add(g.neg()).assertEquals(zero);
// g + 0 = g
g.add(zero).assertEquals(g);
Returns
Source
Methods
add()
add(g: Group): Group
Adds this Group element to another Group element.
let g1 = Group({ x: -1, y: 2})
let g2 = g1.add(g1)
Parameters
• g: Group
Returns
Source
addNonZero()
addNonZero(g2: Group, allowZeroOutput: boolean): Group
Lower-level variant of add which doesn't handle the case where one of the operands is zero, and asserts that the output is non-zero.
Optionally, zero outputs can be allowed by setting allowZeroOutput
to true
.
Warning: If one of the inputs is zero, the result will be garbage and the proof useless. This case has to be prevented or handled separately by the caller of this method.
Parameters
• g2: Group
• allowZeroOutput: boolean
= false
Returns
Source
assertEquals()
assertEquals(g: Group, message?: string): void
Assert that this Group element equals another Group element. Throws an error if the assertion fails.
g1.assertEquals(g2);
Parameters
• g: Group
• message?: string
Returns
void
Source
equals()
equals(g: Group): Bool
Check if this Group element equals another Group element. Returns a Bool.
g1.equals(g1); // Bool(true)
Parameters
• g: Group
Returns
Source
isZero()
isZero(): Bool
Checks if this element is the zero
element {x: 0, y: 0}
.
Returns
Source
neg()
neg(): Group
Negates this Group. Under the hood, it simply negates the y
coordinate and leaves the x
coordinate as is.
Returns
Source
scale()
scale(s: number | bigint | Field | Scalar): Group
Elliptic curve scalar multiplication. Scales the Group element n
-times by itself, where n
is the Scalar.
let s = Scalar(5);
let 5g = g.scale(s);
Parameters
• s: number
| bigint
| Field
| Scalar
Returns
Source
sub()
sub(g: Group): Group
Subtracts another Group element from this one.
Parameters
• g: Group
Returns
Source
toFields()
toFields(): Field[]
Part of the Provable interface.
Returns an array containing this Group element as an array of Field elements.
Returns
Field
[]
Source
toJSON()
toJSON(): {
"x": string;
"y": string;
}
Serializes this Group element to a JSON object.
This operation does NOT affect the circuit and can't be used to prove anything about the representation of the element.
Returns
{
"x": string;
"y": string;
}
x
x: string;
y
y: string;
Source
check()
static check(g: Group): unknown
Checks that a Group element is constraint properly by checking that the element is on the curve.
Parameters
• g: Group
Returns
unknown
Source
empty()
static empty(): Group
Returns
Source
from()
static from(x:
| string
| number
| bigint
| FieldVar
| Field, y:
| string
| number
| bigint
| FieldVar
| Field): Group
Coerces two x and y coordinates into a Group element.
Parameters
• x:
| string
| number
| bigint
| FieldVar
| Field
• y:
| string
| number
| bigint
| FieldVar
| Field
Returns
Source
fromFields()
static fromFields(__namedParameters: Field[]): Group
Part of the Provable interface.
Deserializes a Group element from a list of field elements.
Parameters
• __namedParameters: Field
[]
Returns
Source
fromJSON()
static fromJSON(__namedParameters: {
"x": | string
| number
| bigint
| FieldVar
| Field;
"y": | string
| number
| bigint
| FieldVar
| Field;
}): Group
Deserializes a JSON-like structure to a Group element.
This operation does NOT affect the circuit and can't be used to prove anything about the representation of the element.
Parameters
• __namedParameters
• __namedParameters.x:
| string
| number
| bigint
| FieldVar
| Field
• __namedParameters.y:
| string
| number
| bigint
| FieldVar
| Field
Returns
Source
fromValue()
static fromValue(g: Group | {
"x": number | bigint | Field;
"y": number | bigint | Field;
}): Group
Parameters
• g: Group
| {
"x"
: number
| bigint
| Field
;
"y"
: number
| bigint
| Field
;
}
Returns
Source
sizeInFields()
static sizeInFields(): number
Part of the Provable interface.
Returns 2.
Returns
number
Source
toAuxiliary()
static toAuxiliary(g?: Group): never[]
Part of the Provable interface.
Returns an empty array.
Parameters
• g?: Group
Returns
never
[]
Source
toFields()
static toFields(g: Group): Field[]
Part of the Provable interface.
Returns an array containing a Group element as an array of Field elements.
Parameters
• g: Group
Returns
Field
[]
Source
toInput()
static toInput(x: Group): {
"fields": Field[];
}
Parameters
• x: Group
Returns
{
"fields": Field[];
}
fields
fields: Field[];
Source
toJSON()
static toJSON(g: Group): {
"x": string;
"y": string;
}
Serializes a Group element to a JSON object.
This operation does NOT affect the circuit and can't be used to prove anything about the representation of the element.
Parameters
• g: Group
Returns
{
"x": string;
"y": string;
}
x
x: string;
y
y: string;
Source
toValue()
static toValue(__namedParameters: Group): {
"x": bigint;
"y": bigint;
}
Parameters
• __namedParameters: Group
Returns
{
"x": bigint;
"y": bigint;
}
x
x: bigint;
y
y: bigint;