2020-07-11 10:31:52 +02:00
|
|
|
import * as utils from "./powersoftau_utils.js";
|
|
|
|
import * as binFileUtils from "./binfileutils.js";
|
2020-06-14 17:37:22 +02:00
|
|
|
|
2020-07-11 10:31:52 +02:00
|
|
|
export default async function exportJson(pTauFilename, verbose) {
|
2020-06-14 17:37:22 +02:00
|
|
|
const {fd, sections} = await binFileUtils.readBinFile(pTauFilename, "ptau", 1);
|
|
|
|
|
|
|
|
const {curve, power} = await utils.readPTauHeader(fd, sections);
|
|
|
|
|
|
|
|
const pTau = {};
|
|
|
|
pTau.q = curve.q;
|
|
|
|
pTau.power = power;
|
|
|
|
pTau.contributions = await utils.readContributions(fd, curve, sections);
|
|
|
|
|
|
|
|
pTau.tauG1 = await exportSection(2, "G1", (1 << power)*2 -1, "tauG1");
|
|
|
|
pTau.tauG2 = await exportSection(3, "G2", (1 << power), "tauG2");
|
|
|
|
pTau.alphaTauG1 = await exportSection(4, "G1", (1 << power), "alphaTauG1");
|
|
|
|
pTau.betaTauG1 = await exportSection(5, "G1", (1 << power), "betaTauG1");
|
|
|
|
pTau.betaG2 = await exportSection(6, "G2", 1, "betaG2");
|
|
|
|
|
|
|
|
pTau.lTauG1 = await exportLagrange(12, "G1", "lTauG1");
|
|
|
|
pTau.lTauG2 = await exportLagrange(13, "G2", "lTauG2");
|
|
|
|
pTau.lAlphaTauG1 = await exportLagrange(14, "G1", "lAlphaTauG2");
|
|
|
|
pTau.lBetaTauG1 = await exportLagrange(15, "G1", "lBetaTauG2");
|
|
|
|
|
|
|
|
await fd.close();
|
|
|
|
|
2020-07-11 10:31:52 +02:00
|
|
|
return pTau;
|
|
|
|
|
2020-06-14 17:37:22 +02:00
|
|
|
|
|
|
|
|
|
|
|
async function exportSection(sectionId, groupName, nPoints, sectionName) {
|
|
|
|
const G = curve[groupName];
|
|
|
|
const sG = G.F.n8*2;
|
|
|
|
|
|
|
|
const res = [];
|
|
|
|
await binFileUtils.startReadUniqueSection(fd, sections, sectionId);
|
|
|
|
for (let i=0; i< nPoints; i++) {
|
|
|
|
if ((verbose)&&i&&(i%10000 == 0)) console.log(`${sectionName}: ` + i);
|
|
|
|
const buff = await fd.read(sG);
|
|
|
|
res.push(G.fromRprLEM(buff, 0));
|
|
|
|
}
|
|
|
|
await binFileUtils.endReadSection(fd);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
async function exportLagrange(sectionId, groupName, sectionName) {
|
|
|
|
const G = curve[groupName];
|
|
|
|
const sG = G.F.n8*2;
|
|
|
|
|
|
|
|
const res = [];
|
|
|
|
await binFileUtils.startReadUniqueSection(fd, sections, sectionId);
|
|
|
|
for (let p=0; p<=power; p++) {
|
|
|
|
if (verbose) console.log(`${sectionName}: Power: ${p}`);
|
|
|
|
res[p] = [];
|
|
|
|
const nPoints = (1<<p);
|
|
|
|
for (let i=0; i<nPoints; i++) {
|
|
|
|
if ((verbose)&&i&&(i%10000 == 0)) console.log(`${sectionName}: ${i}/${nPoints}`);
|
|
|
|
const buff = await fd.read(sG);
|
|
|
|
res[p].push(G.fromRprLEM(buff, 0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
await binFileUtils.endReadSection(fd);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|