Skip to main content

Group

SnarkyJS / Modules / Group

Class: Group

An element of a Group.

Table of contents

Constructors

Properties

Accessors

Methods

Constructors

constructor

new Group(«destructured»)

Coerces anything group-like to a Group.

Parameters

NameType
«destructured»Object
› xstring | number | bigint | FieldVar | Field
› ystring | number | bigint | FieldVar | Field

Defined in

lib/group.ts:27

Properties

x

x: Field

Defined in

lib/group.ts:14


y

y: Field

Defined in

lib/group.ts:15

Accessors

generator

Static get generator(): Group

The generator g of the Group.

Returns

Group

Defined in

lib/group.ts:20

Methods

#isConstant

Private #isConstant(): boolean

Returns

boolean

Defined in

lib/group.ts:68


#toProjective

Private #toProjective(): Object

Returns

Object

NameType
xbigint
ybigint
zbigint

Defined in

lib/group.ts:72


#toTuple

Private #toTuple(): [0, FieldVar, FieldVar]

Returns

[0, FieldVar, FieldVar]

Defined in

lib/group.ts:64


add

add(g): Group

Adds this Group element to another Group element.

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

Parameters

NameType
gGroup

Returns

Group

Defined in

lib/group.ts:88


assertEquals

assertEquals(g, message?): void

Assert that this Group element equals another Group element. Throws an error if the assertion fails.

g1.assertEquals(g2);

Parameters

NameType
gGroup
message?string

Returns

void

Defined in

lib/group.ts:149


equals

equals(g): Bool

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

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

Parameters

NameType
gGroup

Returns

Bool

Defined in

lib/group.ts:165


neg

neg(): Group

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

Returns

Group

Defined in

lib/group.ts:114


scale

scale(s): 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

NameType
snumber | bigint | Scalar

Returns

Group

Defined in

lib/group.ts:127


sub

sub(y): Group

Subtracts another Group element from this one.

Parameters

NameType
yGroup

Returns

Group

Defined in

lib/group.ts:107


toFields

toFields(): Field[]

Part of the Provable interface.

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

Returns

Field[]

Defined in

lib/group.ts:197


toJSON

toJSON(): Object

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

Object

NameType
xstring
ystring

Defined in

lib/group.ts:182


#fromAffine

Static Private #fromAffine(«destructured»): Group

Parameters

NameType
«destructured»Object
› infinityboolean
› xbigint
› ybigint

Returns

Group

Defined in

lib/group.ts:56


#fromProjective

Static Private #fromProjective(«destructured»): Group

Parameters

NameType
«destructured»Object
› xbigint
› ybigint
› zbigint

Returns

Group

Defined in

lib/group.ts:60


add

Static add(g1, g2): Group

Deprecated

Please use the method .add on the instance instead

Adds a Group element to another one.

Parameters

NameType
g1Group
g2Group

Returns

Group

Defined in

lib/group.ts:216


assertEqual

Static assertEqual(g1, g2): void

Deprecated

Please use the method .assertEqual on the instance instead.

Assert that two Group elements are equal to another. Throws an error if the assertion fails.

Group.assertEquals(g1, g2);

Parameters

NameType
g1Group
g2Group

Returns

void

Defined in

lib/group.ts:266


check

Static check(g): unknown

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

Parameters

NameType
gGroup

Returns

unknown

Defined in

lib/group.ts:347


equal

Static equal(g1, g2): Bool

Deprecated

Please use the method .equals on the instance instead.

Checks if a Group element is equal to another Group element. Returns a Bool.

Group.equal(g1, g2); // Bool(true)

Parameters

NameType
g1Group
g2Group

Returns

Bool

Defined in

lib/group.ts:280


from

Static from(x, y): Group

Coerces two x and y coordinates into a Group element.

Parameters

NameType
xstring | number | bigint | FieldVar | Field
ystring | number | bigint | FieldVar | Field

Returns

Group

Defined in

lib/group.ts:204


fromFields

Static fromFields(«destructured»): Group

Part of the Provable interface.

Deserializes a Group element from a list of field elements.

Parameters

NameType
«destructured»Field[]

Returns

Group

Defined in

lib/group.ts:307


fromJSON

Static fromJSON(«destructured»): 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

NameType
«destructured»Object
› xstring | number | bigint | FieldVar | Field
› ystring | number | bigint | FieldVar | Field

Returns

Group

Defined in

lib/group.ts:334


neg

Static neg(g): Group

Deprecated

Please use the method .neg on the instance instead

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

let gNeg = Group.neg(g);

Parameters

NameType
gGroup

Returns

Group

Defined in

lib/group.ts:238


scale

Static scale(g, s): Group

Deprecated

Please use the method .scale on the instance instead

Elliptic curve scalar multiplication. Scales a Group element n-times by itself, where n is the Scalar.

let s = Scalar(5);
let 5g = Group.scale(g, s);

Parameters

NameType
gGroup
sScalar

Returns

Group

Defined in

lib/group.ts:252


sizeInFields

Static sizeInFields(): number

Part of the Provable interface.

Returns 2.

Returns

number

Defined in

lib/group.ts:316


sub

Static sub(g1, g2): Group

Deprecated

Please use the method .sub on the instance instead

Subtracts a Group element from another one.

Parameters

NameType
g1Group
g2Group

Returns

Group

Defined in

lib/group.ts:225


toAuxiliary

Static toAuxiliary(g?): never[]

Part of the Provable interface.

Returns an empty array.

Parameters

NameType
g?Group

Returns

never[]

Defined in

lib/group.ts:298


toFields

Static toFields(g): Field[]

Part of the Provable interface.

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

Parameters

NameType
gGroup

Returns

Field[]

Defined in

lib/group.ts:289


toJSON

Static toJSON(g): Object

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

NameType
gGroup

Returns

Object

NameType
xstring
ystring

Defined in

lib/group.ts:325