Skip to content

Commit

Permalink
refactor(baby-jubjub): created and exported identity point
Browse files Browse the repository at this point in the history
  • Loading branch information
ChinoCribioli committed Sep 12, 2024
1 parent 56fcd9f commit b7dec5b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
4 changes: 3 additions & 1 deletion packages/baby-jubjub/src/baby-jubjub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export const Base8: Point<bigint> = [
const a = Fr.e(BigInt("168700"))
const d = Fr.e(BigInt("168696"))

export const id: Point<bigint> = [0n, 1n]

// The Baby JubJub curve 'E(F_r)' is equal to the subgroup of 'F_r'-rational points of 'E'.
export const order = BigInt("21888242871839275222246405745257275088614511777268538073601725287587578984328")
export const subOrder = scalar.shiftRight(order, BigInt(3))
Expand Down Expand Up @@ -78,7 +80,7 @@ export function addPoint(p1: Point<bigint>, p2: Point<bigint>): Point<bigint> {
export function mulPointEscalar(base: Point<bigint>, e: bigint): Point<bigint> {
e %= order

let R0: Point<bigint> = [0n, 1n]
let R0: Point<bigint> = id
let R1: Point<bigint> = base

// 'order' is a number of 254 bits, such as 1n<<253n. Therefore, we initialize the mask as 1<<253
Expand Down
15 changes: 13 additions & 2 deletions packages/baby-jubjub/tests/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
import { babyjub } from "circomlibjs"
import { utils } from "ffjavascript"
import * as scalar from "@zk-kit/utils/scalar"
import { Base8, Point, addPoint, inCurve, mulPointEscalar, packPoint, r, unpackPoint, order, subOrder } from "../src"
import {
Base8,
Point,
addPoint,
inCurve,
mulPointEscalar,
packPoint,
r,
unpackPoint,
order,
subOrder,
id
} from "../src"
import { tonelliShanks } from "../src/sqrt"

describe("BabyJubjub", () => {
const secretScalar = BigInt(324)
const id: Point<bigint> = [BigInt(0), BigInt(1)]

let publicKey: Point<bigint>

Expand Down

0 comments on commit b7dec5b

Please sign in to comment.