forked from iden3/ffjavascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbn128.js
More file actions
35 lines (28 loc) · 1.04 KB
/
bn128.js
File metadata and controls
35 lines (28 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import wasmcurves from "wasmcurves";
import buildEngine from "./engine.js";
import * as Scalar from "./scalar.js";
global.curve_bn128 = null;
export default async function buildBn128(singleThread) {
if ((!singleThread)&&(global.curve_bn128)) return global.curve_bn128;
const params = {
name: "bn128",
wasm: wasmcurves.bn128_wasm,
q: Scalar.e("21888242871839275222246405745257275088696311157297823662689037894645226208583"),
r: Scalar.e("21888242871839275222246405745257275088548364400416034343698204186575808495617"),
n8q: 32,
n8r: 32,
cofactorG2: Scalar.e("30644e72e131a029b85045b68181585e06ceecda572a2489345f2299c0f9fa8d", 16),
singleThread: singleThread ? true : false
};
const curve = await buildEngine(params);
curve.terminate = async function() {
if (!params.singleThread) {
global.curve_bn128 = null;
await this.tm.terminate();
}
};
if (!singleThread) {
global.curve_bn128 = curve;
}
return curve;
}