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 this.two = this.add(this.one, this.one);
20 this.twoinv = this.inverse(this.two);
21 }
22
23 copy(a) {
24 return bigInt(a);
25 }
26
27 div(a, b) {
28 return this.mul(a, this.inverse(b));
29 }
30
31 mulEscalar(base, e) {
32 return fUtils.mulEscalar(this, base, e);
33 }
34
35 exp(base, e) {
36 return fUtils.exp(this, base, e);
37 }
38
39 toString(a) {
40 const ca = this.affine(a);
41 return `"0x${ca.toString(16)}"`;
42 }
43}
44
45
46module.exports = ZqField;