Skip to main content
Version: 2.4.0

Group

Defined in: lib/provable/group.ts:16

An element of a Group.

Constructors​

new Group()​

new Group(__namedParameters: {
x: string | number | bigint | FieldVar | Field;
y: string | number | bigint | FieldVar | Field;
}): Group

Defined in: lib/provable/group.ts:46

Coerces anything group-like to a Group.

Parameters​

__namedParameters​
x​

string | number | bigint | FieldVar | Field

y​

string | number | bigint | FieldVar | Field

Returns​

Group

Properties​

x​

x: Field;

Defined in: lib/provable/group.ts:17


y​

y: Field;

Defined in: lib/provable/group.ts:18

Accessors​

generator​

Get Signature​

get static generator(): Group

Defined in: lib/provable/group.ts:23

The generator g of the Group.

Returns​

Group


zero​

Get Signature​

get static zero(): Group

Defined in: lib/provable/group.ts:39

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​

Group

Methods​

add()​

add(g: Group): Group

Defined in: lib/provable/group.ts:89

Adds this Group element to another Group element.

let g1 = Group({ x: -1, y: 2})
let g2 = g1.add(g1)

Parameters​

g​

Group

Returns​

Group


addNonZero()​

addNonZero(g2: Group, allowZeroOutput: boolean): Group

Defined in: lib/provable/group.ts:128

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​

Group


assertEquals()​

assertEquals(g: Group, message?: string): void

Defined in: lib/provable/group.ts:189

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


equals()​

equals(g: Group): Bool

Defined in: lib/provable/group.ts:205

Check if this Group element equals another Group element. Returns a Bool.

g1.equals(g1); // Bool(true)

Parameters​

g​

Group

Returns​

Bool


isZero()​

isZero(): Bool

Defined in: lib/provable/group.ts:76

Checks if this element is the zero element {x: 0, y: 0}.

Returns​

Bool


neg()​

neg(): Group

Defined in: lib/provable/group.ts:154

Negates this Group. Under the hood, it simply negates the y coordinate and leaves the x coordinate as is.

Returns​

Group


scale()​

scale(s: number | bigint | Field | Scalar): Group

Defined in: lib/provable/group.ts:168

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​

Group


sub()​

sub(g: Group): Group

Defined in: lib/provable/group.ts:147

Subtracts another Group element from this one.

Parameters​

g​

Group

Returns​

Group


toFields()​

toFields(): Field[]

Defined in: lib/provable/group.ts:240

Part of the Provable interface.

Returns an array containing this Group element as an array of Field elements.

Returns​

Field[]


toJSON()​

toJSON(): {
x: string;
y: string;
}

Defined in: lib/provable/group.ts:225

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;

check()​

static check(g: Group): unknown

Defined in: lib/provable/group.ts:317

Checks that a Group element is constraint properly by checking that the element is on the curve.

Parameters​

g​

Group

Returns​

unknown


empty()​

static empty(): Group

Defined in: lib/provable/group.ts:341

Returns​

Group


from()​

static from(x: string | number | bigint | FieldVar | Field, y: string | number | bigint | FieldVar | Field): Group

Defined in: lib/provable/group.ts:247

Coerces two x and y coordinates into a Group element.

Parameters​

x​

string | number | bigint | FieldVar | Field

y​

string | number | bigint | FieldVar | Field

Returns​

Group


fromFields()​

static fromFields(__namedParameters: Field[]): Group

Defined in: lib/provable/group.ts:277

Part of the Provable interface.

Deserializes a Group element from a list of field elements.

Parameters​

__namedParameters​

Field[]

Returns​

Group


fromJSON()​

static fromJSON(__namedParameters: {
x: string | number | bigint | FieldVar | Field;
y: string | number | bigint | FieldVar | Field;
}): Group

Defined in: lib/provable/group.ts:304

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​
x​

string | number | bigint | FieldVar | Field

y​

string | number | bigint | FieldVar | Field

Returns​

Group


fromValue()​

static fromValue(g: 
| Group
| {
x: number | bigint | Field;
y: number | bigint | Field;
}): Group

Defined in: lib/provable/group.ts:216

Parameters​

g​

Group | { x: number | bigint | Field; y: number | bigint | Field; }

Returns​

Group


sizeInFields()​

static sizeInFields(): number

Defined in: lib/provable/group.ts:286

Part of the Provable interface.

Returns 2.

Returns​

number


toAuxiliary()​

static toAuxiliary(g?: Group): never[]

Defined in: lib/provable/group.ts:268

Part of the Provable interface.

Returns an empty array.

Parameters​

g?​

Group

Returns​

never[]


toFields()​

static toFields(g: Group): Field[]

Defined in: lib/provable/group.ts:259

Part of the Provable interface.

Returns an array containing a Group element as an array of Field elements.

Parameters​

g​

Group

Returns​

Field[]


toInput()​

static toInput(x: Group): {
fields: Field[];
}

Defined in: lib/provable/group.ts:335

Parameters​

x​

Group

Returns​

{
fields: Field[];
}
fields​
fields: Field[];

toJSON()​

static toJSON(g: Group): {
x: string;
y: string;
}

Defined in: lib/provable/group.ts:295

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;

toValue()​

static toValue(__namedParameters: Group): {
x: bigint;
y: bigint;
}

Defined in: lib/provable/group.ts:212

Parameters​

__namedParameters​

Group

Returns​

{
x: bigint;
y: bigint;
}
x​
x: bigint;
y​
y: bigint;