You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.9 KiB

5 years ago
  1. const bigInt = require("big-integer");
  2. const ModuleBuilder = require("wasmbuilder");
  3. const buildF1m = require("../src/build_f1m.js");
  4. const buildF2m = require("../src/build_f2m.js");
  5. const buildF1 = require("../src/build_f1.js");
  6. const buildCurve = require("../src/build_curve.js");
  7. const buildTest = require("../src/build_testg1");
  8. const buildFFT = require("../src/build_fft");
  9. const buildMultiexp = require("../src/build_multiexp");
  10. const buildPol = require("../src/build_pol");
  11. const utils = require("../src/utils");
  12. const fs = require("fs");
  13. const path = require("path");
  14. function buildWasm() {
  15. const q = bigInt("21888242871839275222246405745257275088696311157297823662689037894645226208583");
  16. const r = bigInt("21888242871839275222246405745257275088548364400416034343698204186575808495617");
  17. const moduleBuilder = new ModuleBuilder();
  18. moduleBuilder.setMemory(1000);
  19. buildF1m(moduleBuilder, q, "f1m");
  20. buildF1(moduleBuilder, r, "fr", "frm");
  21. buildCurve(moduleBuilder, "g1", "f1m");
  22. buildMultiexp(moduleBuilder, "g1", "g1", "f1m", "fr");
  23. buildFFT(moduleBuilder, "fft", "frm");
  24. buildPol(moduleBuilder, "pol", "frm");
  25. const pNonResidueF2 = moduleBuilder.alloc(
  26. utils.bigInt2BytesLE(
  27. bigInt("15537367993719455909907449462855742678907882278146377936676643359958227611562"), // -1 in montgomery
  28. 32
  29. )
  30. );
  31. buildF2m(moduleBuilder, pNonResidueF2, "f2m", "f1m");
  32. buildCurve(moduleBuilder, "g2", "f2m");
  33. buildMultiexp(moduleBuilder, "g2", "g2", "f2m", "fr");
  34. buildTest(moduleBuilder);
  35. const code = moduleBuilder.build();
  36. fs.writeFileSync(
  37. path.join( __dirname, "..", "build", "groth16_wasm.js"),
  38. `
  39. exports.code = new Buffer("${Buffer.from(code).toString("base64")}", "base64");
  40. exports.pq = ${moduleBuilder.modules.f1m.pq};
  41. exports.pr = ${moduleBuilder.modules.frm.pq};
  42. `
  43. );
  44. }
  45. buildWasm();