circomlib-testvectors/test/babyjubjub.test.js
test/babyjubjub.test.jsRaw
1const chai = require("chai");
2
3const Scalar = require("ffjavascript").Scalar;
4const utils = require("ffjavascript").utils;
5
6// const babyjub = require("../../iden3/circomlib/src/babyjub.js");
7const eddsa = require("circomlib").eddsa;
8const babyjub = require("circomlib").babyJub;
9
10const assert = chai.assert;
11
12describe("BabyJubJub EDDSA javascript testvectors", function () {
13 it("BabyJubJub Keys test", async () => {
14 let sk = Buffer.from("0001020304050607080900010203040506070809000102030405060708090001", "hex");
15 let pk = eddsa.prv2pub(sk);
16 assert.equal(pk.toString("hex"), "13277427435165878497778222415993513565335242147425444199013288855685581939618,13622229784656158136036771217484571176836296686641868549125388198837476602820");
17 assert.equal(pk[0].toString(),
18 "13277427435165878497778222415993513565335242147425444199013288855685581939618");
19 assert.equal(pk[1].toString(),
20 "13622229784656158136036771217484571176836296686641868549125388198837476602820");
21
22 const msgBuf = Buffer.from("00010203040506070809", "hex");
23 const msg = utils.leBuff2int(msgBuf);
24
25 const signature = eddsa.signPoseidon(sk, msg);
26 assert.equal(signature.R8[0].toString(),
27 "11384336176656855268977457483345535180380036354188103142384839473266348197733");
28 assert.equal(signature.R8[1].toString(),
29 "15383486972088797283337779941324724402501462225528836549661220478783371668959");
30 assert.equal(signature.S.toString(),
31 "1672775540645840396591609181675628451599263765380031905495115170613215233181");
32
33 const pkPacked = babyjub.packPoint(pk);
34 assert.equal(pkPacked.toString("hex"), "c433f7a696b7aa3a5224efb3993baf0ccd9e92eecee0c29a3f6c8208a9e81d9e");
35 });
36});