138 lines
4.5 KiB
JavaScript
138 lines
4.5 KiB
JavaScript
|
|
const bn128 = require("./index").bn128;
|
|
const utils = require("./index").utils;
|
|
|
|
const Fq = bn128.F1;
|
|
|
|
const blake2b = require("blake2b");
|
|
|
|
const ChaCha = require("./src/chacha");
|
|
|
|
const pubKey = {
|
|
tau_g1_s: [
|
|
Fq.e("0x1403cf4fed293e66a8cd522be9f938524111f6f08762371bff53ee387a39cf13"),
|
|
Fq.e("0x2accbda355c222301a1bd802db7454d86a4ec2ee89ae895ca21f147d6b705740"),
|
|
Fq.e("1")
|
|
],
|
|
tau_g1_sx: [
|
|
Fq.e("0x12996cf89d854246f1ab002e446436b77a64349117ec1fb2aa57a304890e81ef"),
|
|
Fq.e("0x0c17fd067df52c480a1db3c6890821f975932d89d0d53c6c60777cc56f1dd712"),
|
|
Fq.e("1")
|
|
],
|
|
alpha_g1_s:[
|
|
Fq.e("0x12a64bbe8af7fcb19052e25e188c1fcdac454928142f8e89f58e03249e18b223"),
|
|
Fq.e("0x22be31a388d0ec551530e1b1581b671b4340e88990de805a7bfed8bdb9c1accd"),
|
|
Fq.e("1")
|
|
],
|
|
alpha_g1_sx: [
|
|
Fq.e("0x262ff8dd594374c6ed5e892ba31315f6e47c500784a12ea8d2c573730888a392"),
|
|
Fq.e("0x0b3a94f2b61178f2974e039cfd671e7405ec43eb2c09dc8f43a34f450917a62f"),
|
|
Fq.e("1")
|
|
],
|
|
beta_g1_s: [
|
|
Fq.e("0x0d9b3088b69daf6746c6bba4f9b359234abbfd3306bce14b198e7a5556c777e6"),
|
|
Fq.e("0x066d1acac914883df6a9dc57dc2037a481ba4b8646efe13e2584b9258bd52d0c"),
|
|
Fq.e("1")
|
|
],
|
|
beta_g1_sx: [
|
|
Fq.e("0x248232878c359dbe632c387dc0d955520e8d3363f1cd9621ec9fd4a05460c754"),
|
|
Fq.e("0x12074f06ef232a472cb36c328e760c4acfb4bedad4ca3ee09971578a0fe185ab"),
|
|
Fq.e("1")
|
|
],
|
|
tau_g2_spx: [
|
|
[
|
|
Fq.e("0x0fe02fcc3aee51c1f3a37f3f152ebe5476ae659468f2ee81cdeb19d0dad366c5"),
|
|
Fq.e("0x01aeb4db892bcb273aada80f5eab10e2e50ae59a5c274b0d7303f5c5a52ee88b"),
|
|
],[
|
|
Fq.e("0x2d00022d840d493fb93c68a63b29e2692c0cd3caf354fe60eae1ebacefc2c948"),
|
|
Fq.e("0x204065ff10344153a08cfe4ae543c47fba883ef8a54530fa6a52c87e5c28ef2b"),
|
|
],[
|
|
Fq.e("1"),
|
|
Fq.e("0")
|
|
]
|
|
],
|
|
alpha_g2_spx: [
|
|
[
|
|
Fq.e("0x2e649d01a58a7795762df8f0634c273ebce6950a9a2ba3d4459458620d3164a0"),
|
|
Fq.e("0x1b58044d3e205a918124fea3983583199b4f99fd0abb39ede2c684b0810bdc1e"),
|
|
],[
|
|
Fq.e("0x021d41558cea5fa32c9f3de5834cb2ee45ce4cdf471353395d019dfe0c9c2509"),
|
|
Fq.e("0x1c04148bac3f17b219c2655cd63ad2596ea63293103487be488a1d5a9054ddbf"),
|
|
],[
|
|
Fq.e("1"),
|
|
Fq.e("0")
|
|
]
|
|
],
|
|
beta_g2_spx: [
|
|
[
|
|
Fq.e("0x029251aed5163109667300035ce200b7195fc6e261581ba38776d87d7f0b1a7d"),
|
|
Fq.e("0x09d6847f1b945ccdc00418a807f4b0af67ec5c0030c4f203581eff9d4af4347f"),
|
|
],[
|
|
Fq.e("0x04b62ecdc94bf94fcefdf93f06ca4f63026a47a0d4138941b8ee45b9f7177e5c"),
|
|
Fq.e("0x1f0a6bff3945f207f407ff1c813b66a28b495f55a3788c3e200c74817e86f7ce"),
|
|
],[
|
|
Fq.e("1"),
|
|
Fq.e("0")
|
|
]
|
|
]
|
|
};
|
|
|
|
|
|
const challange = Buffer.from(
|
|
"bc0bde7980381fa642b2097591dd83f1"+
|
|
"ed15b003e15c35520af32c95eb519149"+
|
|
"2a6f3175215635cfc10e6098e2c612d0"+
|
|
"ca84f1a9f90b5333560c8af59b9209f4", "hex");
|
|
|
|
function getG2sp(persinalization, challange, g1s, g1sx) {
|
|
|
|
const h = blake2b(64);
|
|
h.update(Buffer.from([persinalization]));
|
|
h.update(challange);
|
|
h.update( utils.beInt2Buff(g1s[0],32));
|
|
h.update( utils.beInt2Buff(g1s[1],32));
|
|
h.update( utils.beInt2Buff(g1sx[0],32));
|
|
h.update( utils.beInt2Buff(g1sx[1],32));
|
|
const hash = Buffer.from(h.digest());
|
|
|
|
const seed = [];
|
|
for (let i=0; i<8; i++) {
|
|
seed[i] = hash.readUInt32BE(i*4);
|
|
}
|
|
|
|
const rng = new ChaCha(seed);
|
|
|
|
const g2_sp = bn128.G2.fromRng(rng);
|
|
|
|
return g2_sp;
|
|
|
|
}
|
|
|
|
const tau_g2_sp = getG2sp(0, challange, pubKey.tau_g1_s, pubKey.tau_g1_sx);
|
|
if (bn128.F12.eq(
|
|
bn128.pairing(pubKey.tau_g1_sx,tau_g2_sp),
|
|
bn128.pairing(pubKey.tau_g1_s, pubKey.tau_g2_spx))) {
|
|
console.log("Key tau matches!!");
|
|
} else {
|
|
console.log("ERROR Key tau does not match!!");
|
|
}
|
|
|
|
const alpha_g2_sp = getG2sp(1, challange, pubKey.alpha_g1_s, pubKey.alpha_g1_sx);
|
|
if (bn128.F12.eq(
|
|
bn128.pairing(pubKey.alpha_g1_sx, alpha_g2_sp),
|
|
bn128.pairing(pubKey.alpha_g1_s , pubKey.alpha_g2_spx))) {
|
|
console.log("Key alfa matches!!");
|
|
} else {
|
|
console.log("ERROR Alfa tau does not match!!");
|
|
}
|
|
|
|
const beta_g2_sp = getG2sp(2, challange, pubKey.beta_g1_s, pubKey.beta_g1_sx);
|
|
if (bn128.F12.eq(
|
|
bn128.pairing(pubKey.beta_g1_sx, beta_g2_sp),
|
|
bn128.pairing(pubKey.beta_g1_s , pubKey.beta_g2_spx))) {
|
|
console.log("Key beta matches!!");
|
|
} else {
|
|
console.log("ERROR Beta tau does not match!!");
|
|
}
|
|
|