Skip to main content
Version: 2.15.0

Group

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

An element of a Group.

Constructors​

Constructor​

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

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

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


y​

y: Field;

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

Accessors​

generator​

Get Signature​

get static generator(): Group;

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

The generator g of the Group.

Returns​

Group


zero​

Get Signature​

get static zero(): Group;

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

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

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

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

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

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

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

Returns​

Bool


neg()​

neg(): Group;

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

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

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

Subtracts another Group element from this one.

Parameters​

g​

Group

Returns​

Group


toFields()​

toFields(): Field[];

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

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

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

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

Returns​

Group


from()​

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

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

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

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

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

Parameters​

g​

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

Returns​

Group


sizeInFields()​

static sizeInFields(): number;

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

Part of the Provable interface.

Returns 2.

Returns​

number


toAuxiliary()​

static toAuxiliary(_?: Group): never[];

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

Part of the Provable interface.

Returns an empty array.

Parameters​

_?​

Group

Returns​

never[]


toFields()​

static toFields(g: Group): Field[];

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

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

Parameters​

x​

Group

Returns​

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

toJSON()​

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

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

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

Parameters​

__namedParameters​

Group

Returns​

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