snarkjs/src/zqfield.js
src/zqfield.jsRaw
1const bigInt = require("./bigint");
2const fUtils = require("./futils.js");
3
4class ZqField {
5 constructor(q) {
6 this.q = q;
7 this.zero = bigInt.zero;
8 this.one = bigInt.one;
9 this.add = bigInt.genAdd();
10 this.double = bigInt.genDouble();
11 this.sub = bigInt.genSub();
12 this.neg = bigInt.genNeg();
13 this.mul = bigInt.genMul(q);
14 this.inverse = bigInt.genInverse(q);
15 this.square = bigInt.genSquare(q);
16 this.equals = bigInt.genEquals(q);
17 this.affine = bigInt.genAffine(q);
18 this.isZero = bigInt.genIsZero(q);
19 }
20
21 copy(a) {
22 return bigInt(a);
23 }
24
25 div(a, b) {
26 return this.mul(a, this.inverse(b));
27 }
28
29 mulEscalar(base, e) {
30 return fUtils.mulEscalar(this, base, e);
31 }
32
33 exp(base, e) {
34 return fUtils.exp(this, base, e);
35 }
36
37 toString(a) {
38 const ca = this.affine(a);
39 return `"0x${ca.toString(16)}"`;
40 }
41}
42
43
44module.exports = ZqField;