Skip to main content

ForeignCurve

o1js / Modules / ForeignCurve

Class: ForeignCurve

Table of contents

Constructors

Properties

Accessors

Methods

Constructors

constructor

new ForeignCurve(g)

Create a new ForeignCurve from an object representing the (affine) x and y coordinates.

Parameters

NameType
gObject
g.xnumber | bigint | Field3 | AlmostForeignField
g.ynumber | bigint | Field3 | AlmostForeignField

Example

let x = new ForeignCurve({ x: 1n, y: 1n });

Important: By design, there is no way for a ForeignCurve to represent the zero point.

Warning: This fails for a constant input which does not represent an actual point on the curve.

Defined in

lib/foreign-curve.ts:45

Properties

x

x: AlmostForeignField

Defined in

lib/foreign-curve.ts:30


y

y: AlmostForeignField

Defined in

lib/foreign-curve.ts:31


_Bigint

Static Optional _Bigint: Object

Type declaration

NameType
Field{ M: bigint = twoadicity; inverse: (x: bigint) => undefined | bigint = exportedInverse; modulus: bigint = p; sizeInBits: number ; t: bigint = oddFactor; twoadicRoot: bigint ; add: (x: bigint, y: bigint) => bigint ; div: (x: bigint, y: bigint) => undefined | bigint ; dot: (x: bigint[], y: bigint[]) => bigint ; equal: (x: bigint, y: bigint) => boolean ; fromBigint: (x: bigint) => bigint ; fromNumber: (x: number) => bigint ; isEven: (x: bigint) => boolean ; isSquare: (x: bigint) => boolean ; leftShift: (x: bigint, bits: number, maxBitSize: number) => bigint ; mod: (x: bigint) => bigint ; mul: (x: bigint, y: bigint) => bigint ; negate: (x: bigint) => bigint ; not: (x: bigint, bits: number) => bigint ; power: (x: bigint, n: bigint) => bigint ; random: () => bigint ; rightShift: (x: bigint, bits: number) => bigint ; rot: (x: bigint, bits: bigint, direction: "left" | "right", maxBits: bigint) => bigint ; sqrt: (x: bigint) => undefined | bigint ; square: (x: bigint) => bigint ; sub: (x: bigint, y: bigint) => bigint }
Field.Mbigint
Field.inverse(x: bigint) => undefined | bigint
Field.modulusbigint
Field.sizeInBitsnumber
Field.tbigint
Field.twoadicRootbigint
Field.add[object Object]
Field.div[object Object]
Field.dot[object Object]
Field.equal[object Object]
Field.fromBigint[object Object]
Field.fromNumber[object Object]
Field.isEven[object Object]
Field.isSquare[object Object]
Field.leftShift[object Object]
Field.mod[object Object]
Field.mul[object Object]
Field.negate[object Object]
Field.not[object Object]
Field.power[object Object]
Field.random[object Object]
Field.rightShift[object Object]
Field.rot[object Object]
Field.sqrt[object Object]
Field.square[object Object]
Field.sub[object Object]
Scalar{ M: bigint = twoadicity; inverse: (x: bigint) => undefined | bigint = exportedInverse; modulus: bigint = p; sizeInBits: number ; t: bigint = oddFactor; twoadicRoot: bigint ; add: (x: bigint, y: bigint) => bigint ; div: (x: bigint, y: bigint) => undefined | bigint ; dot: (x: bigint[], y: bigint[]) => bigint ; equal: (x: bigint, y: bigint) => boolean ; fromBigint: (x: bigint) => bigint ; fromNumber: (x: number) => bigint ; isEven: (x: bigint) => boolean ; isSquare: (x: bigint) => boolean ; leftShift: (x: bigint, bits: number, maxBitSize: number) => bigint ; mod: (x: bigint) => bigint ; mul: (x: bigint, y: bigint) => bigint ; negate: (x: bigint) => bigint ; not: (x: bigint, bits: number) => bigint ; power: (x: bigint, n: bigint) => bigint ; random: () => bigint ; rightShift: (x: bigint, bits: number) => bigint ; rot: (x: bigint, bits: bigint, direction: "left" | "right", maxBits: bigint) => bigint ; sqrt: (x: bigint) => undefined | bigint ; square: (x: bigint) => bigint ; sub: (x: bigint, y: bigint) => bigint }
Scalar.Mbigint
Scalar.inverse(x: bigint) => undefined | bigint
Scalar.modulusbigint
Scalar.sizeInBitsnumber
Scalar.tbigint
Scalar.twoadicRootbigint
Scalar.add[object Object]
Scalar.div[object Object]
Scalar.dot[object Object]
Scalar.equal[object Object]
Scalar.fromBigint[object Object]
Scalar.fromNumber[object Object]
Scalar.isEven[object Object]
Scalar.isSquare[object Object]
Scalar.leftShift[object Object]
Scalar.mod[object Object]
Scalar.mul[object Object]
Scalar.negate[object Object]
Scalar.not[object Object]
Scalar.power[object Object]
Scalar.random[object Object]
Scalar.rightShift[object Object]
Scalar.rot[object Object]
Scalar.sqrt[object Object]
Scalar.square[object Object]
Scalar.sub[object Object]
abigint
bbigint
cofactorundefined | bigint
hasCofactorboolean
hasEndomorphismboolean
modulusbigint
namestring
one{ infinity: boolean = false; x: bigint ; y: bigint }
one.infinityboolean
one.xbigint
one.ybigint
orderbigint
zeroGroupAffine
get Endo(){ base: bigint = endoBase; decomposeMaxBits: number = glvData.maxBits; scalar: bigint = endoScalar; decompose: (s: bigint) => readonly [{ abs: bigint ; isNegative: boolean ; value: bigint = s0 }, { abs: bigint ; isNegative: boolean ; value: bigint = s1 }] ; endomorphism: (P: GroupAffine) => { x: bigint ; y: bigint = P.y } ; scale: (g: GroupAffine, s: bigint) => GroupAffine ; scaleProjective: (g: GroupProjective, s: bigint) => { x: bigint ; y: bigint ; z: bigint } }
add(g: GroupAffine, h: GroupAffine) => GroupAffine
double(g: GroupAffine) => GroupAffine
equal(g: GroupAffine, h: GroupAffine) => boolean
from(g: { x: bigint ; y: bigint }) => GroupAffine
fromNonzero(g: { x: bigint ; y: bigint }) => GroupAffine
isInSubgroup(g: GroupAffine) => boolean
isOnCurve(g: GroupAffine) => boolean
negate(g: GroupAffine) => GroupAffine
scale(g: GroupAffine, s: bigint | boolean[]) => GroupAffine
sub(g: GroupAffine, h: GroupAffine) => GroupAffine

Defined in

lib/foreign-curve.ts:240


_Field

Static Optional _Field: typeof AlmostForeignField

Defined in

lib/foreign-curve.ts:241


_Scalar

Static Optional _Scalar: typeof AlmostForeignField

Defined in

lib/foreign-curve.ts:242


_provable

Static Optional _provable: ProvablePureExtended\<ForeignCurve, { x: string ; y: string }>

Defined in

lib/foreign-curve.ts:243

Accessors

Constructor

get Constructor(): typeof ForeignCurve

Returns

typeof ForeignCurve

Defined in

lib/foreign-curve.ts:237


modulus

get modulus(): bigint

The size of the curve's base field.

Returns

bigint

Defined in

lib/foreign-curve.ts:81


Bigint

Static get Bigint(): Object

Curve arithmetic on JS bigints.

Returns

Object

NameType
Field{ M: bigint = twoadicity; inverse: (x: bigint) => undefined | bigint = exportedInverse; modulus: bigint = p; sizeInBits: number ; t: bigint = oddFactor; twoadicRoot: bigint ; add: (x: bigint, y: bigint) => bigint ; div: (x: bigint, y: bigint) => undefined | bigint ; dot: (x: bigint[], y: bigint[]) => bigint ; equal: (x: bigint, y: bigint) => boolean ; fromBigint: (x: bigint) => bigint ; fromNumber: (x: number) => bigint ; isEven: (x: bigint) => boolean ; isSquare: (x: bigint) => boolean ; leftShift: (x: bigint, bits: number, maxBitSize: number) => bigint ; mod: (x: bigint) => bigint ; mul: (x: bigint, y: bigint) => bigint ; negate: (x: bigint) => bigint ; not: (x: bigint, bits: number) => bigint ; power: (x: bigint, n: bigint) => bigint ; random: () => bigint ; rightShift: (x: bigint, bits: number) => bigint ; rot: (x: bigint, bits: bigint, direction: "left" | "right", maxBits: bigint) => bigint ; sqrt: (x: bigint) => undefined | bigint ; square: (x: bigint) => bigint ; sub: (x: bigint, y: bigint) => bigint }
Field.Mbigint
Field.inverse(x: bigint) => undefined | bigint
Field.modulusbigint
Field.sizeInBitsnumber
Field.tbigint
Field.twoadicRootbigint
Field.add[object Object]
Field.div[object Object]
Field.dot[object Object]
Field.equal[object Object]
Field.fromBigint[object Object]
Field.fromNumber[object Object]
Field.isEven[object Object]
Field.isSquare[object Object]
Field.leftShift[object Object]
Field.mod[object Object]
Field.mul[object Object]
Field.negate[object Object]
Field.not[object Object]
Field.power[object Object]
Field.random[object Object]
Field.rightShift[object Object]
Field.rot[object Object]
Field.sqrt[object Object]
Field.square[object Object]
Field.sub[object Object]
Scalar{ M: bigint = twoadicity; inverse: (x: bigint) => undefined | bigint = exportedInverse; modulus: bigint = p; sizeInBits: number ; t: bigint = oddFactor; twoadicRoot: bigint ; add: (x: bigint, y: bigint) => bigint ; div: (x: bigint, y: bigint) => undefined | bigint ; dot: (x: bigint[], y: bigint[]) => bigint ; equal: (x: bigint, y: bigint) => boolean ; fromBigint: (x: bigint) => bigint ; fromNumber: (x: number) => bigint ; isEven: (x: bigint) => boolean ; isSquare: (x: bigint) => boolean ; leftShift: (x: bigint, bits: number, maxBitSize: number) => bigint ; mod: (x: bigint) => bigint ; mul: (x: bigint, y: bigint) => bigint ; negate: (x: bigint) => bigint ; not: (x: bigint, bits: number) => bigint ; power: (x: bigint, n: bigint) => bigint ; random: () => bigint ; rightShift: (x: bigint, bits: number) => bigint ; rot: (x: bigint, bits: bigint, direction: "left" | "right", maxBits: bigint) => bigint ; sqrt: (x: bigint) => undefined | bigint ; square: (x: bigint) => bigint ; sub: (x: bigint, y: bigint) => bigint }
Scalar.Mbigint
Scalar.inverse(x: bigint) => undefined | bigint
Scalar.modulusbigint
Scalar.sizeInBitsnumber
Scalar.tbigint
Scalar.twoadicRootbigint
Scalar.add[object Object]
Scalar.div[object Object]
Scalar.dot[object Object]
Scalar.equal[object Object]
Scalar.fromBigint[object Object]
Scalar.fromNumber[object Object]
Scalar.isEven[object Object]
Scalar.isSquare[object Object]
Scalar.leftShift[object Object]
Scalar.mod[object Object]
Scalar.mul[object Object]
Scalar.negate[object Object]
Scalar.not[object Object]
Scalar.power[object Object]
Scalar.random[object Object]
Scalar.rightShift[object Object]
Scalar.rot[object Object]
Scalar.sqrt[object Object]
Scalar.square[object Object]
Scalar.sub[object Object]
abigint
bbigint
cofactorundefined | bigint
hasCofactorboolean
hasEndomorphismboolean
modulusbigint
namestring
one{ infinity: boolean = false; x: bigint ; y: bigint }
one.infinityboolean
one.xbigint
one.ybigint
orderbigint
zeroGroupAffine
get Endo(){ base: bigint = endoBase; decomposeMaxBits: number = glvData.maxBits; scalar: bigint = endoScalar; decompose: (s: bigint) => readonly [{ abs: bigint ; isNegative: boolean ; value: bigint = s0 }, { abs: bigint ; isNegative: boolean ; value: bigint = s1 }] ; endomorphism: (P: GroupAffine) => { x: bigint ; y: bigint = P.y } ; scale: (g: GroupAffine, s: bigint) => GroupAffine ; scaleProjective: (g: GroupProjective, s: bigint) => { x: bigint ; y: bigint ; z: bigint } }
add(g: GroupAffine, h: GroupAffine) => GroupAffine
double(g: GroupAffine) => GroupAffine
equal(g: GroupAffine, h: GroupAffine) => boolean
from(g: { x: bigint ; y: bigint }) => GroupAffine
fromNonzero(g: { x: bigint ; y: bigint }) => GroupAffine
isInSubgroup(g: GroupAffine) => boolean
isOnCurve(g: GroupAffine) => boolean
negate(g: GroupAffine) => GroupAffine
scale(g: GroupAffine, s: bigint | boolean[]) => GroupAffine
sub(g: GroupAffine, h: GroupAffine) => GroupAffine

Defined in

lib/foreign-curve.ts:251


Field

Static get Field(): typeof AlmostForeignField

The base field of this curve as a ForeignField.

Returns

typeof AlmostForeignField

Defined in

lib/foreign-curve.ts:258


Scalar

Static get Scalar(): typeof AlmostForeignField

The scalar field of this curve as a ForeignField.

Returns

typeof AlmostForeignField

Defined in

lib/foreign-curve.ts:265


generator

Static get generator(): ForeignCurve

The constant generator point.

Returns

ForeignCurve

Defined in

lib/foreign-curve.ts:69


modulus

Static get modulus(): bigint

The size of the curve's base field.

Returns

bigint

Defined in

lib/foreign-curve.ts:75


provable

Static get provable(): ProvablePureExtended\<ForeignCurve, { x: string ; y: string }>

Provable<ForeignCurve>

Returns

ProvablePureExtended\<ForeignCurve, { x: string ; y: string }>

Defined in

lib/foreign-curve.ts:272

Methods

add

add(h): ForeignCurve

Elliptic curve addition.

let r = p.add(q); // r = p + q

Important: this is incomplete addition and does not handle the degenerate cases:

  • Inputs are equal, g = h (where you would use double). In this case, the result of this method is garbage and can be manipulated arbitrarily by a malicious prover.
  • Inputs are inverses of each other, g = -h, so that the result would be the zero point. In this case, the proof fails.

If you want guaranteed soundness regardless of the input, use addSafe instead.

Parameters

NameType
hForeignCurve | FlexiblePoint

Returns

ForeignCurve

Throws

if the inputs are inverses of each other.

Defined in

lib/foreign-curve.ts:121


addSafe

addSafe(h): ForeignCurve

Safe elliptic curve addition.

This is the same as add, but additionally proves that the inputs are not equal. Therefore, the method is guaranteed to either fail or return a valid addition result.

Beware: this is more expensive than add, and is still incomplete in that it does not succeed on equal or inverse inputs.

Parameters

NameType
hForeignCurve | FlexiblePoint

Returns

ForeignCurve

Throws

if the inputs are equal or inverses of each other.

Defined in

lib/foreign-curve.ts:139


assertInSubgroup

assertInSubgroup(): void

Assert that this point lies in the subgroup defined by order*P = 0.

Note: this is a no-op if the curve has cofactor equal to 1. Otherwise it performs the full scalar multiplication order*P and is expensive.

Returns

void

Defined in

lib/foreign-curve.ts:219


assertOnCurve

assertOnCurve(): void

Assert that this point lies on the elliptic curve, which means it satisfies the equation y^2 = x^3 + ax + b

Returns

void

Defined in

lib/foreign-curve.ts:203


double

double(): ForeignCurve

Elliptic curve doubling.

Returns

ForeignCurve

Example

let r = p.double(); // r = 2 * p

Defined in

lib/foreign-curve.ts:158


isConstant

isConstant(): boolean

Checks whether this curve point is constant.

See FieldVar to understand constants vs variables.

Returns

boolean

Defined in

lib/foreign-curve.ts:90


negate

negate(): ForeignCurve

Elliptic curve negation.

Returns

ForeignCurve

Example

let r = p.negate(); // r = -p

Defined in

lib/foreign-curve.ts:172


scale

scale(scalar): ForeignCurve

Elliptic curve scalar multiplication, where the scalar is represented as a ForeignField element.

Important: this proves that the result of the scalar multiplication is not the zero point.

Parameters

NameType
scalarnumber | bigint | AlmostForeignField

Returns

ForeignCurve

Throws

if the scalar multiplication results in the zero point; for example, if the scalar is zero.

Example

let r = p.scale(s); // r = s * p

Defined in

lib/foreign-curve.ts:188


toBigint

toBigint(): GroupAffine

Convert this curve point to a point with bigint coordinates.

Returns

GroupAffine

Defined in

lib/foreign-curve.ts:97


assertInSubgroup

Static assertInSubgroup(g): void

Parameters

NameType
gForeignCurve

Returns

void

Defined in

lib/foreign-curve.ts:207


assertOnCurve

Static assertOnCurve(g): void

Parameters

NameType
gForeignCurve

Returns

void

Defined in

lib/foreign-curve.ts:195


check

Static check(g): void

Check that this is a valid element of the target subgroup of the curve:

  • Check that the coordinates are valid field elements
  • Use () to check that the point lies on the curve
  • If the curve has cofactor unequal to 1, use ().

Parameters

NameType
gForeignCurve

Returns

void

Defined in

lib/foreign-curve.ts:229


from

Static from(g): ForeignCurve

Coerce the input to a ForeignCurve.

Parameters

NameType
gForeignCurve | FlexiblePoint

Returns

ForeignCurve

Defined in

lib/foreign-curve.ts:61