@semaphore-protocol/proof 3.13.0 → 3.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.browser.mjs +62 -44
- package/dist/index.node.js +62 -44
- package/dist/index.node.mjs +62 -44
- package/package.json +3 -3
- package/src/groth16/verify.ts +2 -1
- package/src/groth16/zkey-utils.ts +4 -1
package/dist/index.browser.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module @semaphore-protocol/proof
|
|
3
|
-
* @version 3.
|
|
3
|
+
* @version 3.14.0
|
|
4
4
|
* @file A library to generate and verify Semaphore proofs.
|
|
5
5
|
* @copyright Ethereum Foundation 2022
|
|
6
6
|
* @license MIT
|
|
@@ -2062,76 +2062,87 @@ function readG2(fd, curve, toObject) {
|
|
|
2062
2062
|
});
|
|
2063
2063
|
}
|
|
2064
2064
|
function readHeaderGroth16(fd, sections, toObject) {
|
|
2065
|
+
var _a;
|
|
2065
2066
|
return __awaiter(this, void 0, void 0, function () {
|
|
2066
|
-
var zkey, n8q,
|
|
2067
|
-
return __generator(this, function (
|
|
2068
|
-
switch (
|
|
2067
|
+
var zkey, n8q, _b, n8r, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
2068
|
+
return __generator(this, function (_q) {
|
|
2069
|
+
switch (_q.label) {
|
|
2069
2070
|
case 0:
|
|
2070
2071
|
zkey = {};
|
|
2071
2072
|
zkey.protocol = "groth16";
|
|
2072
2073
|
return [4 /*yield*/, startReadUniqueSection_1(fd, sections, 2)];
|
|
2073
2074
|
case 1:
|
|
2074
|
-
|
|
2075
|
+
_q.sent();
|
|
2075
2076
|
return [4 /*yield*/, fd.readULE32()];
|
|
2076
2077
|
case 2:
|
|
2077
|
-
n8q =
|
|
2078
|
+
n8q = _q.sent();
|
|
2078
2079
|
zkey.n8q = n8q;
|
|
2079
|
-
|
|
2080
|
+
_b = zkey;
|
|
2080
2081
|
return [4 /*yield*/, readBigInt_1(fd, n8q)];
|
|
2081
2082
|
case 3:
|
|
2082
|
-
|
|
2083
|
+
_b.q = _q.sent();
|
|
2083
2084
|
return [4 /*yield*/, fd.readULE32()];
|
|
2084
2085
|
case 4:
|
|
2085
|
-
n8r =
|
|
2086
|
+
n8r = _q.sent();
|
|
2086
2087
|
zkey.n8r = n8r;
|
|
2087
|
-
_b = zkey;
|
|
2088
|
-
return [4 /*yield*/, readBigInt_1(fd, n8r)];
|
|
2089
|
-
case 5:
|
|
2090
|
-
_b.r = _o.sent();
|
|
2091
2088
|
_c = zkey;
|
|
2092
|
-
return [4 /*yield*/,
|
|
2093
|
-
|
|
2094
|
-
|
|
2089
|
+
return [4 /*yield*/, readBigInt_1(fd, n8r)
|
|
2090
|
+
// @ts-ignore
|
|
2091
|
+
];
|
|
2092
|
+
case 5:
|
|
2093
|
+
_c.r = _q.sent();
|
|
2094
|
+
// @ts-ignore
|
|
2095
2095
|
_d = zkey;
|
|
2096
|
-
return [
|
|
2096
|
+
if (!((_a = globalThis.curve_bn128) !== null && _a !== void 0)) return [3 /*break*/, 6];
|
|
2097
|
+
_e = _a;
|
|
2098
|
+
return [3 /*break*/, 8];
|
|
2099
|
+
case 6: return [4 /*yield*/, buildBn128(undefined, undefined)];
|
|
2097
2100
|
case 7:
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
return [4 /*yield*/, fd.readULE32()];
|
|
2101
|
+
_e = (_q.sent());
|
|
2102
|
+
_q.label = 8;
|
|
2101
2103
|
case 8:
|
|
2102
|
-
|
|
2104
|
+
// @ts-ignore
|
|
2105
|
+
_d.curve = _e;
|
|
2103
2106
|
_f = zkey;
|
|
2104
2107
|
return [4 /*yield*/, fd.readULE32()];
|
|
2105
2108
|
case 9:
|
|
2106
|
-
_f.
|
|
2107
|
-
zkey.power = log2(zkey.domainSize);
|
|
2109
|
+
_f.nVars = _q.sent();
|
|
2108
2110
|
_g = zkey;
|
|
2109
|
-
return [4 /*yield*/,
|
|
2111
|
+
return [4 /*yield*/, fd.readULE32()];
|
|
2110
2112
|
case 10:
|
|
2111
|
-
_g.
|
|
2113
|
+
_g.nPublic = _q.sent();
|
|
2112
2114
|
_h = zkey;
|
|
2113
|
-
return [4 /*yield*/,
|
|
2115
|
+
return [4 /*yield*/, fd.readULE32()];
|
|
2114
2116
|
case 11:
|
|
2115
|
-
_h.
|
|
2117
|
+
_h.domainSize = _q.sent();
|
|
2118
|
+
zkey.power = log2(zkey.domainSize);
|
|
2116
2119
|
_j = zkey;
|
|
2117
|
-
return [4 /*yield*/,
|
|
2120
|
+
return [4 /*yield*/, readG1(fd, zkey.curve, toObject)];
|
|
2118
2121
|
case 12:
|
|
2119
|
-
_j.
|
|
2122
|
+
_j.vk_alpha_1 = _q.sent();
|
|
2120
2123
|
_k = zkey;
|
|
2121
|
-
return [4 /*yield*/,
|
|
2124
|
+
return [4 /*yield*/, readG1(fd, zkey.curve, toObject)];
|
|
2122
2125
|
case 13:
|
|
2123
|
-
_k.
|
|
2126
|
+
_k.vk_beta_1 = _q.sent();
|
|
2124
2127
|
_l = zkey;
|
|
2125
|
-
return [4 /*yield*/,
|
|
2128
|
+
return [4 /*yield*/, readG2(fd, zkey.curve, toObject)];
|
|
2126
2129
|
case 14:
|
|
2127
|
-
_l.
|
|
2130
|
+
_l.vk_beta_2 = _q.sent();
|
|
2128
2131
|
_m = zkey;
|
|
2129
2132
|
return [4 /*yield*/, readG2(fd, zkey.curve, toObject)];
|
|
2130
2133
|
case 15:
|
|
2131
|
-
_m.
|
|
2132
|
-
|
|
2134
|
+
_m.vk_gamma_2 = _q.sent();
|
|
2135
|
+
_o = zkey;
|
|
2136
|
+
return [4 /*yield*/, readG1(fd, zkey.curve, toObject)];
|
|
2133
2137
|
case 16:
|
|
2134
|
-
_o.sent();
|
|
2138
|
+
_o.vk_delta_1 = _q.sent();
|
|
2139
|
+
_p = zkey;
|
|
2140
|
+
return [4 /*yield*/, readG2(fd, zkey.curve, toObject)];
|
|
2141
|
+
case 17:
|
|
2142
|
+
_p.vk_delta_2 = _q.sent();
|
|
2143
|
+
return [4 /*yield*/, endReadSection_1(fd)];
|
|
2144
|
+
case 18:
|
|
2145
|
+
_q.sent();
|
|
2135
2146
|
return [2 /*return*/, zkey];
|
|
2136
2147
|
}
|
|
2137
2148
|
});
|
|
@@ -3380,17 +3391,24 @@ function publicInputsAreValid(curve, publicInputs) {
|
|
|
3380
3391
|
return true;
|
|
3381
3392
|
}
|
|
3382
3393
|
function groth16Verify(_vk_verifier, _publicSignals, _proof) {
|
|
3394
|
+
var _a;
|
|
3383
3395
|
return __awaiter(this, void 0, void 0, function () {
|
|
3384
|
-
var vk_verifier, proof, publicSignals, curve, IC0, IC, w, i, buffP, cpub, pi_a, pi_b, pi_c, vk_gamma_2, vk_delta_2, vk_alpha_1, vk_beta_2;
|
|
3385
|
-
return __generator(this, function (
|
|
3386
|
-
switch (
|
|
3396
|
+
var vk_verifier, proof, publicSignals, curve, _b, IC0, IC, w, i, buffP, cpub, pi_a, pi_b, pi_c, vk_gamma_2, vk_delta_2, vk_alpha_1, vk_beta_2;
|
|
3397
|
+
return __generator(this, function (_c) {
|
|
3398
|
+
switch (_c.label) {
|
|
3387
3399
|
case 0:
|
|
3388
3400
|
vk_verifier = unstringifyBigInts(_vk_verifier);
|
|
3389
3401
|
proof = unstringifyBigInts(_proof);
|
|
3390
3402
|
publicSignals = unstringifyBigInts(_publicSignals);
|
|
3391
|
-
return [
|
|
3392
|
-
|
|
3393
|
-
|
|
3403
|
+
if (!((_a = globalThis.curve_bn128) !== null && _a !== void 0)) return [3 /*break*/, 1];
|
|
3404
|
+
_b = _a;
|
|
3405
|
+
return [3 /*break*/, 3];
|
|
3406
|
+
case 1: return [4 /*yield*/, buildBn128(undefined, undefined)];
|
|
3407
|
+
case 2:
|
|
3408
|
+
_b = (_c.sent());
|
|
3409
|
+
_c.label = 3;
|
|
3410
|
+
case 3:
|
|
3411
|
+
curve = _b;
|
|
3394
3412
|
IC0 = curve.G1.fromObject(vk_verifier.IC[0]);
|
|
3395
3413
|
IC = new Uint8Array(curve.G1.F.n8 * 2 * publicSignals.length);
|
|
3396
3414
|
w = new Uint8Array(curve.Fr.n8 * publicSignals.length);
|
|
@@ -3403,8 +3421,8 @@ function groth16Verify(_vk_verifier, _publicSignals, _proof) {
|
|
|
3403
3421
|
Scalar.toRprLE(w, curve.Fr.n8 * i, publicSignals[i], curve.Fr.n8);
|
|
3404
3422
|
}
|
|
3405
3423
|
return [4 /*yield*/, curve.G1.multiExpAffine(IC, w)];
|
|
3406
|
-
case
|
|
3407
|
-
cpub =
|
|
3424
|
+
case 4:
|
|
3425
|
+
cpub = _c.sent();
|
|
3408
3426
|
cpub = curve.G1.add(cpub, IC0);
|
|
3409
3427
|
pi_a = curve.G1.fromObject(proof.pi_a);
|
|
3410
3428
|
pi_b = curve.G2.fromObject(proof.pi_b);
|
package/dist/index.node.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module @semaphore-protocol/proof
|
|
3
|
-
* @version 3.
|
|
3
|
+
* @version 3.14.0
|
|
4
4
|
* @file A library to generate and verify Semaphore proofs.
|
|
5
5
|
* @copyright Ethereum Foundation 2022
|
|
6
6
|
* @license MIT
|
|
@@ -2064,76 +2064,87 @@ function readG2(fd, curve, toObject) {
|
|
|
2064
2064
|
});
|
|
2065
2065
|
}
|
|
2066
2066
|
function readHeaderGroth16(fd, sections, toObject) {
|
|
2067
|
+
var _a;
|
|
2067
2068
|
return __awaiter(this, void 0, void 0, function () {
|
|
2068
|
-
var zkey, n8q,
|
|
2069
|
-
return __generator(this, function (
|
|
2070
|
-
switch (
|
|
2069
|
+
var zkey, n8q, _b, n8r, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
2070
|
+
return __generator(this, function (_q) {
|
|
2071
|
+
switch (_q.label) {
|
|
2071
2072
|
case 0:
|
|
2072
2073
|
zkey = {};
|
|
2073
2074
|
zkey.protocol = "groth16";
|
|
2074
2075
|
return [4 /*yield*/, startReadUniqueSection_1(fd, sections, 2)];
|
|
2075
2076
|
case 1:
|
|
2076
|
-
|
|
2077
|
+
_q.sent();
|
|
2077
2078
|
return [4 /*yield*/, fd.readULE32()];
|
|
2078
2079
|
case 2:
|
|
2079
|
-
n8q =
|
|
2080
|
+
n8q = _q.sent();
|
|
2080
2081
|
zkey.n8q = n8q;
|
|
2081
|
-
|
|
2082
|
+
_b = zkey;
|
|
2082
2083
|
return [4 /*yield*/, readBigInt_1(fd, n8q)];
|
|
2083
2084
|
case 3:
|
|
2084
|
-
|
|
2085
|
+
_b.q = _q.sent();
|
|
2085
2086
|
return [4 /*yield*/, fd.readULE32()];
|
|
2086
2087
|
case 4:
|
|
2087
|
-
n8r =
|
|
2088
|
+
n8r = _q.sent();
|
|
2088
2089
|
zkey.n8r = n8r;
|
|
2089
|
-
_b = zkey;
|
|
2090
|
-
return [4 /*yield*/, readBigInt_1(fd, n8r)];
|
|
2091
|
-
case 5:
|
|
2092
|
-
_b.r = _o.sent();
|
|
2093
2090
|
_c = zkey;
|
|
2094
|
-
return [4 /*yield*/,
|
|
2095
|
-
|
|
2096
|
-
|
|
2091
|
+
return [4 /*yield*/, readBigInt_1(fd, n8r)
|
|
2092
|
+
// @ts-ignore
|
|
2093
|
+
];
|
|
2094
|
+
case 5:
|
|
2095
|
+
_c.r = _q.sent();
|
|
2096
|
+
// @ts-ignore
|
|
2097
2097
|
_d = zkey;
|
|
2098
|
-
return [
|
|
2098
|
+
if (!((_a = globalThis.curve_bn128) !== null && _a !== void 0)) return [3 /*break*/, 6];
|
|
2099
|
+
_e = _a;
|
|
2100
|
+
return [3 /*break*/, 8];
|
|
2101
|
+
case 6: return [4 /*yield*/, ffjavascript$1.buildBn128(undefined, undefined)];
|
|
2099
2102
|
case 7:
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
return [4 /*yield*/, fd.readULE32()];
|
|
2103
|
+
_e = (_q.sent());
|
|
2104
|
+
_q.label = 8;
|
|
2103
2105
|
case 8:
|
|
2104
|
-
|
|
2106
|
+
// @ts-ignore
|
|
2107
|
+
_d.curve = _e;
|
|
2105
2108
|
_f = zkey;
|
|
2106
2109
|
return [4 /*yield*/, fd.readULE32()];
|
|
2107
2110
|
case 9:
|
|
2108
|
-
_f.
|
|
2109
|
-
zkey.power = log2(zkey.domainSize);
|
|
2111
|
+
_f.nVars = _q.sent();
|
|
2110
2112
|
_g = zkey;
|
|
2111
|
-
return [4 /*yield*/,
|
|
2113
|
+
return [4 /*yield*/, fd.readULE32()];
|
|
2112
2114
|
case 10:
|
|
2113
|
-
_g.
|
|
2115
|
+
_g.nPublic = _q.sent();
|
|
2114
2116
|
_h = zkey;
|
|
2115
|
-
return [4 /*yield*/,
|
|
2117
|
+
return [4 /*yield*/, fd.readULE32()];
|
|
2116
2118
|
case 11:
|
|
2117
|
-
_h.
|
|
2119
|
+
_h.domainSize = _q.sent();
|
|
2120
|
+
zkey.power = log2(zkey.domainSize);
|
|
2118
2121
|
_j = zkey;
|
|
2119
|
-
return [4 /*yield*/,
|
|
2122
|
+
return [4 /*yield*/, readG1(fd, zkey.curve, toObject)];
|
|
2120
2123
|
case 12:
|
|
2121
|
-
_j.
|
|
2124
|
+
_j.vk_alpha_1 = _q.sent();
|
|
2122
2125
|
_k = zkey;
|
|
2123
|
-
return [4 /*yield*/,
|
|
2126
|
+
return [4 /*yield*/, readG1(fd, zkey.curve, toObject)];
|
|
2124
2127
|
case 13:
|
|
2125
|
-
_k.
|
|
2128
|
+
_k.vk_beta_1 = _q.sent();
|
|
2126
2129
|
_l = zkey;
|
|
2127
|
-
return [4 /*yield*/,
|
|
2130
|
+
return [4 /*yield*/, readG2(fd, zkey.curve, toObject)];
|
|
2128
2131
|
case 14:
|
|
2129
|
-
_l.
|
|
2132
|
+
_l.vk_beta_2 = _q.sent();
|
|
2130
2133
|
_m = zkey;
|
|
2131
2134
|
return [4 /*yield*/, readG2(fd, zkey.curve, toObject)];
|
|
2132
2135
|
case 15:
|
|
2133
|
-
_m.
|
|
2134
|
-
|
|
2136
|
+
_m.vk_gamma_2 = _q.sent();
|
|
2137
|
+
_o = zkey;
|
|
2138
|
+
return [4 /*yield*/, readG1(fd, zkey.curve, toObject)];
|
|
2135
2139
|
case 16:
|
|
2136
|
-
_o.sent();
|
|
2140
|
+
_o.vk_delta_1 = _q.sent();
|
|
2141
|
+
_p = zkey;
|
|
2142
|
+
return [4 /*yield*/, readG2(fd, zkey.curve, toObject)];
|
|
2143
|
+
case 17:
|
|
2144
|
+
_p.vk_delta_2 = _q.sent();
|
|
2145
|
+
return [4 /*yield*/, endReadSection_1(fd)];
|
|
2146
|
+
case 18:
|
|
2147
|
+
_q.sent();
|
|
2137
2148
|
return [2 /*return*/, zkey];
|
|
2138
2149
|
}
|
|
2139
2150
|
});
|
|
@@ -3382,17 +3393,24 @@ function publicInputsAreValid(curve, publicInputs) {
|
|
|
3382
3393
|
return true;
|
|
3383
3394
|
}
|
|
3384
3395
|
function groth16Verify(_vk_verifier, _publicSignals, _proof) {
|
|
3396
|
+
var _a;
|
|
3385
3397
|
return __awaiter(this, void 0, void 0, function () {
|
|
3386
|
-
var vk_verifier, proof, publicSignals, curve, IC0, IC, w, i, buffP, cpub, pi_a, pi_b, pi_c, vk_gamma_2, vk_delta_2, vk_alpha_1, vk_beta_2;
|
|
3387
|
-
return __generator(this, function (
|
|
3388
|
-
switch (
|
|
3398
|
+
var vk_verifier, proof, publicSignals, curve, _b, IC0, IC, w, i, buffP, cpub, pi_a, pi_b, pi_c, vk_gamma_2, vk_delta_2, vk_alpha_1, vk_beta_2;
|
|
3399
|
+
return __generator(this, function (_c) {
|
|
3400
|
+
switch (_c.label) {
|
|
3389
3401
|
case 0:
|
|
3390
3402
|
vk_verifier = unstringifyBigInts(_vk_verifier);
|
|
3391
3403
|
proof = unstringifyBigInts(_proof);
|
|
3392
3404
|
publicSignals = unstringifyBigInts(_publicSignals);
|
|
3393
|
-
return [
|
|
3394
|
-
|
|
3395
|
-
|
|
3405
|
+
if (!((_a = globalThis.curve_bn128) !== null && _a !== void 0)) return [3 /*break*/, 1];
|
|
3406
|
+
_b = _a;
|
|
3407
|
+
return [3 /*break*/, 3];
|
|
3408
|
+
case 1: return [4 /*yield*/, ffjavascript$1.buildBn128(undefined, undefined)];
|
|
3409
|
+
case 2:
|
|
3410
|
+
_b = (_c.sent());
|
|
3411
|
+
_c.label = 3;
|
|
3412
|
+
case 3:
|
|
3413
|
+
curve = _b;
|
|
3396
3414
|
IC0 = curve.G1.fromObject(vk_verifier.IC[0]);
|
|
3397
3415
|
IC = new Uint8Array(curve.G1.F.n8 * 2 * publicSignals.length);
|
|
3398
3416
|
w = new Uint8Array(curve.Fr.n8 * publicSignals.length);
|
|
@@ -3405,8 +3423,8 @@ function groth16Verify(_vk_verifier, _publicSignals, _proof) {
|
|
|
3405
3423
|
ffjavascript$1.Scalar.toRprLE(w, curve.Fr.n8 * i, publicSignals[i], curve.Fr.n8);
|
|
3406
3424
|
}
|
|
3407
3425
|
return [4 /*yield*/, curve.G1.multiExpAffine(IC, w)];
|
|
3408
|
-
case
|
|
3409
|
-
cpub =
|
|
3426
|
+
case 4:
|
|
3427
|
+
cpub = _c.sent();
|
|
3410
3428
|
cpub = curve.G1.add(cpub, IC0);
|
|
3411
3429
|
pi_a = curve.G1.fromObject(proof.pi_a);
|
|
3412
3430
|
pi_b = curve.G2.fromObject(proof.pi_b);
|
package/dist/index.node.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module @semaphore-protocol/proof
|
|
3
|
-
* @version 3.
|
|
3
|
+
* @version 3.14.0
|
|
4
4
|
* @file A library to generate and verify Semaphore proofs.
|
|
5
5
|
* @copyright Ethereum Foundation 2022
|
|
6
6
|
* @license MIT
|
|
@@ -2042,76 +2042,87 @@ function readG2(fd, curve, toObject) {
|
|
|
2042
2042
|
});
|
|
2043
2043
|
}
|
|
2044
2044
|
function readHeaderGroth16(fd, sections, toObject) {
|
|
2045
|
+
var _a;
|
|
2045
2046
|
return __awaiter(this, void 0, void 0, function () {
|
|
2046
|
-
var zkey, n8q,
|
|
2047
|
-
return __generator(this, function (
|
|
2048
|
-
switch (
|
|
2047
|
+
var zkey, n8q, _b, n8r, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
2048
|
+
return __generator(this, function (_q) {
|
|
2049
|
+
switch (_q.label) {
|
|
2049
2050
|
case 0:
|
|
2050
2051
|
zkey = {};
|
|
2051
2052
|
zkey.protocol = "groth16";
|
|
2052
2053
|
return [4 /*yield*/, startReadUniqueSection_1(fd, sections, 2)];
|
|
2053
2054
|
case 1:
|
|
2054
|
-
|
|
2055
|
+
_q.sent();
|
|
2055
2056
|
return [4 /*yield*/, fd.readULE32()];
|
|
2056
2057
|
case 2:
|
|
2057
|
-
n8q =
|
|
2058
|
+
n8q = _q.sent();
|
|
2058
2059
|
zkey.n8q = n8q;
|
|
2059
|
-
|
|
2060
|
+
_b = zkey;
|
|
2060
2061
|
return [4 /*yield*/, readBigInt_1(fd, n8q)];
|
|
2061
2062
|
case 3:
|
|
2062
|
-
|
|
2063
|
+
_b.q = _q.sent();
|
|
2063
2064
|
return [4 /*yield*/, fd.readULE32()];
|
|
2064
2065
|
case 4:
|
|
2065
|
-
n8r =
|
|
2066
|
+
n8r = _q.sent();
|
|
2066
2067
|
zkey.n8r = n8r;
|
|
2067
|
-
_b = zkey;
|
|
2068
|
-
return [4 /*yield*/, readBigInt_1(fd, n8r)];
|
|
2069
|
-
case 5:
|
|
2070
|
-
_b.r = _o.sent();
|
|
2071
2068
|
_c = zkey;
|
|
2072
|
-
return [4 /*yield*/,
|
|
2073
|
-
|
|
2074
|
-
|
|
2069
|
+
return [4 /*yield*/, readBigInt_1(fd, n8r)
|
|
2070
|
+
// @ts-ignore
|
|
2071
|
+
];
|
|
2072
|
+
case 5:
|
|
2073
|
+
_c.r = _q.sent();
|
|
2074
|
+
// @ts-ignore
|
|
2075
2075
|
_d = zkey;
|
|
2076
|
-
return [
|
|
2076
|
+
if (!((_a = globalThis.curve_bn128) !== null && _a !== void 0)) return [3 /*break*/, 6];
|
|
2077
|
+
_e = _a;
|
|
2078
|
+
return [3 /*break*/, 8];
|
|
2079
|
+
case 6: return [4 /*yield*/, buildBn128(undefined, undefined)];
|
|
2077
2080
|
case 7:
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
return [4 /*yield*/, fd.readULE32()];
|
|
2081
|
+
_e = (_q.sent());
|
|
2082
|
+
_q.label = 8;
|
|
2081
2083
|
case 8:
|
|
2082
|
-
|
|
2084
|
+
// @ts-ignore
|
|
2085
|
+
_d.curve = _e;
|
|
2083
2086
|
_f = zkey;
|
|
2084
2087
|
return [4 /*yield*/, fd.readULE32()];
|
|
2085
2088
|
case 9:
|
|
2086
|
-
_f.
|
|
2087
|
-
zkey.power = log2(zkey.domainSize);
|
|
2089
|
+
_f.nVars = _q.sent();
|
|
2088
2090
|
_g = zkey;
|
|
2089
|
-
return [4 /*yield*/,
|
|
2091
|
+
return [4 /*yield*/, fd.readULE32()];
|
|
2090
2092
|
case 10:
|
|
2091
|
-
_g.
|
|
2093
|
+
_g.nPublic = _q.sent();
|
|
2092
2094
|
_h = zkey;
|
|
2093
|
-
return [4 /*yield*/,
|
|
2095
|
+
return [4 /*yield*/, fd.readULE32()];
|
|
2094
2096
|
case 11:
|
|
2095
|
-
_h.
|
|
2097
|
+
_h.domainSize = _q.sent();
|
|
2098
|
+
zkey.power = log2(zkey.domainSize);
|
|
2096
2099
|
_j = zkey;
|
|
2097
|
-
return [4 /*yield*/,
|
|
2100
|
+
return [4 /*yield*/, readG1(fd, zkey.curve, toObject)];
|
|
2098
2101
|
case 12:
|
|
2099
|
-
_j.
|
|
2102
|
+
_j.vk_alpha_1 = _q.sent();
|
|
2100
2103
|
_k = zkey;
|
|
2101
|
-
return [4 /*yield*/,
|
|
2104
|
+
return [4 /*yield*/, readG1(fd, zkey.curve, toObject)];
|
|
2102
2105
|
case 13:
|
|
2103
|
-
_k.
|
|
2106
|
+
_k.vk_beta_1 = _q.sent();
|
|
2104
2107
|
_l = zkey;
|
|
2105
|
-
return [4 /*yield*/,
|
|
2108
|
+
return [4 /*yield*/, readG2(fd, zkey.curve, toObject)];
|
|
2106
2109
|
case 14:
|
|
2107
|
-
_l.
|
|
2110
|
+
_l.vk_beta_2 = _q.sent();
|
|
2108
2111
|
_m = zkey;
|
|
2109
2112
|
return [4 /*yield*/, readG2(fd, zkey.curve, toObject)];
|
|
2110
2113
|
case 15:
|
|
2111
|
-
_m.
|
|
2112
|
-
|
|
2114
|
+
_m.vk_gamma_2 = _q.sent();
|
|
2115
|
+
_o = zkey;
|
|
2116
|
+
return [4 /*yield*/, readG1(fd, zkey.curve, toObject)];
|
|
2113
2117
|
case 16:
|
|
2114
|
-
_o.sent();
|
|
2118
|
+
_o.vk_delta_1 = _q.sent();
|
|
2119
|
+
_p = zkey;
|
|
2120
|
+
return [4 /*yield*/, readG2(fd, zkey.curve, toObject)];
|
|
2121
|
+
case 17:
|
|
2122
|
+
_p.vk_delta_2 = _q.sent();
|
|
2123
|
+
return [4 /*yield*/, endReadSection_1(fd)];
|
|
2124
|
+
case 18:
|
|
2125
|
+
_q.sent();
|
|
2115
2126
|
return [2 /*return*/, zkey];
|
|
2116
2127
|
}
|
|
2117
2128
|
});
|
|
@@ -3360,17 +3371,24 @@ function publicInputsAreValid(curve, publicInputs) {
|
|
|
3360
3371
|
return true;
|
|
3361
3372
|
}
|
|
3362
3373
|
function groth16Verify(_vk_verifier, _publicSignals, _proof) {
|
|
3374
|
+
var _a;
|
|
3363
3375
|
return __awaiter(this, void 0, void 0, function () {
|
|
3364
|
-
var vk_verifier, proof, publicSignals, curve, IC0, IC, w, i, buffP, cpub, pi_a, pi_b, pi_c, vk_gamma_2, vk_delta_2, vk_alpha_1, vk_beta_2;
|
|
3365
|
-
return __generator(this, function (
|
|
3366
|
-
switch (
|
|
3376
|
+
var vk_verifier, proof, publicSignals, curve, _b, IC0, IC, w, i, buffP, cpub, pi_a, pi_b, pi_c, vk_gamma_2, vk_delta_2, vk_alpha_1, vk_beta_2;
|
|
3377
|
+
return __generator(this, function (_c) {
|
|
3378
|
+
switch (_c.label) {
|
|
3367
3379
|
case 0:
|
|
3368
3380
|
vk_verifier = unstringifyBigInts(_vk_verifier);
|
|
3369
3381
|
proof = unstringifyBigInts(_proof);
|
|
3370
3382
|
publicSignals = unstringifyBigInts(_publicSignals);
|
|
3371
|
-
return [
|
|
3372
|
-
|
|
3373
|
-
|
|
3383
|
+
if (!((_a = globalThis.curve_bn128) !== null && _a !== void 0)) return [3 /*break*/, 1];
|
|
3384
|
+
_b = _a;
|
|
3385
|
+
return [3 /*break*/, 3];
|
|
3386
|
+
case 1: return [4 /*yield*/, buildBn128(undefined, undefined)];
|
|
3387
|
+
case 2:
|
|
3388
|
+
_b = (_c.sent());
|
|
3389
|
+
_c.label = 3;
|
|
3390
|
+
case 3:
|
|
3391
|
+
curve = _b;
|
|
3374
3392
|
IC0 = curve.G1.fromObject(vk_verifier.IC[0]);
|
|
3375
3393
|
IC = new Uint8Array(curve.G1.F.n8 * 2 * publicSignals.length);
|
|
3376
3394
|
w = new Uint8Array(curve.Fr.n8 * publicSignals.length);
|
|
@@ -3383,8 +3401,8 @@ function groth16Verify(_vk_verifier, _publicSignals, _proof) {
|
|
|
3383
3401
|
Scalar.toRprLE(w, curve.Fr.n8 * i, publicSignals[i], curve.Fr.n8);
|
|
3384
3402
|
}
|
|
3385
3403
|
return [4 /*yield*/, curve.G1.multiExpAffine(IC, w)];
|
|
3386
|
-
case
|
|
3387
|
-
cpub =
|
|
3404
|
+
case 4:
|
|
3405
|
+
cpub = _c.sent();
|
|
3388
3406
|
cpub = curve.G1.add(cpub, IC0);
|
|
3389
3407
|
pi_a = curve.G1.fromObject(proof.pi_a);
|
|
3390
3408
|
pi_b = curve.G2.fromObject(proof.pi_b);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@semaphore-protocol/proof",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.14.0",
|
|
4
4
|
"description": "A library to generate and verify Semaphore proofs.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.node.js",
|
|
@@ -48,8 +48,8 @@
|
|
|
48
48
|
"rollup-plugin-typescript2": "^0.31.2"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
|
-
"@semaphore-protocol/group": "3.
|
|
52
|
-
"@semaphore-protocol/identity": "3.
|
|
51
|
+
"@semaphore-protocol/group": "3.14.0",
|
|
52
|
+
"@semaphore-protocol/identity": "3.14.0"
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
55
|
"@ethersproject/bignumber": "^5.5.0",
|
package/src/groth16/verify.ts
CHANGED
|
@@ -27,7 +27,8 @@ export default async function groth16Verify(_vk_verifier: any, _publicSignals: a
|
|
|
27
27
|
const proof = unstringifyBigInts(_proof)
|
|
28
28
|
const publicSignals = unstringifyBigInts(_publicSignals)
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
// @ts-ignore
|
|
31
|
+
const curve = globalThis.curve_bn128 ?? (await buildBn128(undefined, undefined))
|
|
31
32
|
|
|
32
33
|
const IC0 = curve.G1.fromObject(vk_verifier.IC[0])
|
|
33
34
|
const IC = new Uint8Array(curve.G1.F.n8 * 2 * publicSignals.length)
|
|
@@ -31,7 +31,10 @@ async function readHeaderGroth16(fd: any, sections: any, toObject: any) {
|
|
|
31
31
|
const n8r = await fd.readULE32()
|
|
32
32
|
zkey.n8r = n8r
|
|
33
33
|
zkey.r = await binFileUtils.readBigInt(fd, n8r)
|
|
34
|
-
|
|
34
|
+
|
|
35
|
+
// @ts-ignore
|
|
36
|
+
zkey.curve = globalThis.curve_bn128 ?? (await buildBn128(undefined, undefined))
|
|
37
|
+
|
|
35
38
|
zkey.nVars = await fd.readULE32()
|
|
36
39
|
zkey.nPublic = await fd.readULE32()
|
|
37
40
|
zkey.domainSize = await fd.readULE32()
|