@semaphore-protocol/proof 3.15.2 → 4.0.0-alpha.1

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.
@@ -0,0 +1,802 @@
1
+ /**
2
+ * @module @semaphore-protocol/proof
3
+ * @version 4.0.0-alpha.1
4
+ * @file A library to generate and verify Semaphore proofs.
5
+ * @copyright Ethereum Foundation 2024
6
+ * @license MIT
7
+ * @see [Github]{@link https://github.com/semaphore-protocol/semaphore/tree/main/packages/proof}
8
+ */
9
+ import { BigNumber } from '@ethersproject/bignumber';
10
+ import { groth16 } from 'snarkjs';
11
+ import { zeroPad } from '@ethersproject/bytes';
12
+ import { keccak256 } from '@ethersproject/keccak256';
13
+
14
+ /******************************************************************************
15
+ Copyright (c) Microsoft Corporation.
16
+
17
+ Permission to use, copy, modify, and/or distribute this software for any
18
+ purpose with or without fee is hereby granted.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
21
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
22
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
23
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
24
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
25
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
26
+ PERFORMANCE OF THIS SOFTWARE.
27
+ ***************************************************************************** */
28
+ /* global Reflect, Promise */
29
+
30
+
31
+ var __assign = function() {
32
+ __assign = Object.assign || function __assign(t) {
33
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
34
+ s = arguments[i];
35
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
36
+ }
37
+ return t;
38
+ };
39
+ return __assign.apply(this, arguments);
40
+ };
41
+
42
+ function __awaiter(thisArg, _arguments, P, generator) {
43
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
44
+ return new (P || (P = Promise))(function (resolve, reject) {
45
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
46
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
47
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
48
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
49
+ });
50
+ }
51
+
52
+ function __generator(thisArg, body) {
53
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
54
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
55
+ function verb(n) { return function (v) { return step([n, v]); }; }
56
+ function step(op) {
57
+ if (f) throw new TypeError("Generator is already executing.");
58
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
59
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
60
+ if (y = 0, t) op = [op[0] & 2, t.value];
61
+ switch (op[0]) {
62
+ case 0: case 1: t = op; break;
63
+ case 4: _.label++; return { value: op[1], done: false };
64
+ case 5: _.label++; y = op[1]; op = [0]; continue;
65
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
66
+ default:
67
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
68
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
69
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
70
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
71
+ if (t[2]) _.ops.pop();
72
+ _.trys.pop(); continue;
73
+ }
74
+ op = body.call(thisArg, _);
75
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
76
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
77
+ }
78
+ }
79
+
80
+ function getSnarkArtifacts(treeDepth) {
81
+ return __awaiter(this, void 0, void 0, function () {
82
+ return __generator(this, function (_a) {
83
+ return [2 /*return*/, {
84
+ wasmFilePath: "https://semaphore.cedoor.dev/artifacts/".concat(treeDepth, "/semaphore.wasm"),
85
+ zkeyFilePath: "https://semaphore.cedoor.dev/artifacts/".concat(treeDepth, "/semaphore.zkey")
86
+ }];
87
+ });
88
+ });
89
+ }
90
+
91
+ /**
92
+ * Creates a keccak256 hash of a message compatible with the SNARK scalar modulus.
93
+ * @param message The message to be hashed.
94
+ * @returns The message digest.
95
+ */
96
+ function hash(message) {
97
+ message = BigNumber.from(message).toTwos(256).toHexString();
98
+ message = zeroPad(message, 32);
99
+ return (BigInt(keccak256(message)) >> BigInt(8)).toString();
100
+ }
101
+
102
+ /**
103
+ * Packs the Groth16 proof points into a format compatible with Semaphore.
104
+ * @param proof The proof points generated with SnarkJS.
105
+ * @returns The proof points compatible with Semaphore.
106
+ */
107
+ function packPoints(proof) {
108
+ return [
109
+ proof.pi_a[0],
110
+ proof.pi_a[1],
111
+ proof.pi_b[0][1],
112
+ proof.pi_b[0][0],
113
+ proof.pi_b[1][1],
114
+ proof.pi_b[1][0],
115
+ proof.pi_c[0],
116
+ proof.pi_c[1]
117
+ ];
118
+ }
119
+
120
+ /**
121
+ * Generates a Semaphore proof.
122
+ * @param identity The Semaphore identity.
123
+ * @param groupOrMerkleProof The Semaphore group or its Merkle proof.
124
+ * @param scope The external nullifier.
125
+ * @param message The Semaphore signal.
126
+ * @param merkleTreeDepth The depth of the tree with which the circuit was compiled.
127
+ * @param snarkArtifacts The SNARK artifacts.
128
+ * @returns The Semaphore proof ready to be verified.
129
+ */
130
+ function generateProof(identity, groupOrMerkleProof, message, scope, merkleTreeDepth, snarkArtifacts) {
131
+ return __awaiter(this, void 0, void 0, function () {
132
+ var merkleProof, leafIndex, merkleProofLength, merkleProofIndices, merkleProofSiblings, i, _a, proof, publicSignals;
133
+ return __generator(this, function (_b) {
134
+ switch (_b.label) {
135
+ case 0:
136
+ if ("siblings" in groupOrMerkleProof) {
137
+ merkleProof = groupOrMerkleProof;
138
+ }
139
+ else {
140
+ leafIndex = groupOrMerkleProof.indexOf(identity.commitment);
141
+ merkleProof = groupOrMerkleProof.generateMerkleProof(leafIndex);
142
+ }
143
+ merkleProofLength = merkleProof.siblings.length;
144
+ if (merkleTreeDepth !== undefined) {
145
+ if (merkleTreeDepth < 1 || merkleTreeDepth > 12) {
146
+ throw new TypeError("The tree depth must be a number between 1 and 12");
147
+ }
148
+ }
149
+ else {
150
+ merkleTreeDepth = merkleProofLength;
151
+ }
152
+ if (!!snarkArtifacts) return [3 /*break*/, 2];
153
+ return [4 /*yield*/, getSnarkArtifacts(merkleTreeDepth)];
154
+ case 1:
155
+ snarkArtifacts = _b.sent();
156
+ _b.label = 2;
157
+ case 2:
158
+ merkleProofIndices = [];
159
+ merkleProofSiblings = merkleProof.siblings;
160
+ for (i = 0; i < merkleTreeDepth; i += 1) {
161
+ merkleProofIndices.push((merkleProof.index >> i) & 1);
162
+ if (merkleProofSiblings[i] === undefined) {
163
+ merkleProofSiblings[i] = "0";
164
+ }
165
+ }
166
+ return [4 /*yield*/, groth16.fullProve({
167
+ secret: identity.secretScalar,
168
+ merkleProofLength: merkleProofLength,
169
+ merkleProofIndices: merkleProofIndices,
170
+ merkleProofSiblings: merkleProofSiblings,
171
+ scope: hash(scope),
172
+ message: hash(message)
173
+ }, snarkArtifacts.wasmFilePath, snarkArtifacts.zkeyFilePath)];
174
+ case 3:
175
+ _a = _b.sent(), proof = _a.proof, publicSignals = _a.publicSignals;
176
+ return [2 /*return*/, {
177
+ merkleTreeDepth: merkleTreeDepth,
178
+ merkleTreeRoot: publicSignals[0],
179
+ nullifier: publicSignals[1],
180
+ message: BigNumber.from(message).toString(),
181
+ scope: BigNumber.from(scope).toString(),
182
+ points: packPoints(proof)
183
+ }];
184
+ }
185
+ });
186
+ });
187
+ }
188
+
189
+ /**
190
+ * Unpacks the Groth16 proof points into their original form.
191
+ * @param proof The proof points compatible with Semaphore.
192
+ * @returns The proof points compatible with SnarkJS.
193
+ */
194
+ function unpackPoints(proof) {
195
+ return {
196
+ pi_a: [proof[0], proof[1]],
197
+ pi_b: [
198
+ [proof[3], proof[2]],
199
+ [proof[5], proof[4]]
200
+ ],
201
+ pi_c: [proof[6], proof[7]],
202
+ protocol: "groth16",
203
+ curve: "bn128"
204
+ };
205
+ }
206
+
207
+ var protocol = "groth16";
208
+ var curve = "bn128";
209
+ var nPublic = 4;
210
+ var vk_alpha_1 = [
211
+ "20491192805390485299153009773594534940189261866228447918068658471970481763042",
212
+ "9383485363053290200918347156157836566562967994039712273449902621266178545958",
213
+ "1"
214
+ ];
215
+ var vk_beta_2 = [
216
+ [
217
+ "6375614351688725206403948262868962793625744043794305715222011528459656738731",
218
+ "4252822878758300859123897981450591353533073413197771768651442665752259397132"
219
+ ],
220
+ [
221
+ "10505242626370262277552901082094356697409835680220590971873171140371331206856",
222
+ "21847035105528745403288232691147584728191162732299865338377159692350059136679"
223
+ ],
224
+ [
225
+ "1",
226
+ "0"
227
+ ]
228
+ ];
229
+ var vk_gamma_2 = [
230
+ [
231
+ "10857046999023057135944570762232829481370756359578518086990519993285655852781",
232
+ "11559732032986387107991004021392285783925812861821192530917403151452391805634"
233
+ ],
234
+ [
235
+ "8495653923123431417604973247489272438418190587263600148770280649306958101930",
236
+ "4082367875863433681332203403145435568316851327593401208105741076214120093531"
237
+ ],
238
+ [
239
+ "1",
240
+ "0"
241
+ ]
242
+ ];
243
+ var vk_delta_2 = [
244
+ [
245
+ [
246
+ "16293410697967515504861065986355060225819302510590370360517024529684437085892",
247
+ "563562783592406106461234396505774794044312891062077216951605541624542949349"
248
+ ],
249
+ [
250
+ "10971164449179097832515056670594147898894418081309026322805549037082528587660",
251
+ "718666295291146285397081607986058864287612968465033527894198098928522749430"
252
+ ],
253
+ [
254
+ "1",
255
+ "0"
256
+ ]
257
+ ],
258
+ [
259
+ [
260
+ "8087990171976409378525016197066789089596692733769545253942804888352233244331",
261
+ "6925326031648378844726759441690273332175949886518827719224741736678266471462"
262
+ ],
263
+ [
264
+ "15618724583521291135890928658458637081479213437530496494788106479523123480134",
265
+ "10115242383701466910539784663900956956505212347433548599529944880163612117847"
266
+ ],
267
+ [
268
+ "1",
269
+ "0"
270
+ ]
271
+ ],
272
+ [
273
+ [
274
+ "7699563868952902688273782470023919811229667532027732585467624469008534197561",
275
+ "7699900854308622607636895140107457213471038801393300399043779958706267744510"
276
+ ],
277
+ [
278
+ "15390497513810955087868026868634948499789494261604405008298272598684585331879",
279
+ "8605006500231713390564760089884965869867818332514275728271802101761117177706"
280
+ ],
281
+ [
282
+ "1",
283
+ "0"
284
+ ]
285
+ ],
286
+ [
287
+ [
288
+ "2561989864654045354260435368824127763249975523256535586391379695256700207392",
289
+ "9243647856126339588200227750973237380809101852206502177952556679680468734813"
290
+ ],
291
+ [
292
+ "18264861452415533737686303596832882667852638121244187636443702248458018416929",
293
+ "1308059969166897152269078839315249187046718124106168932020710683189419160756"
294
+ ],
295
+ [
296
+ "1",
297
+ "0"
298
+ ]
299
+ ],
300
+ [
301
+ [
302
+ "21307904757295729894500052152251151076177124351059746872940558537429181679313",
303
+ "12554869896570109663558999106053541183136083706372178136870048170147558661370"
304
+ ],
305
+ [
306
+ "11194665041440536766843756304212299788817698936187605770131686430625103172681",
307
+ "13447792161027167738515744919555311619301071111923271126707713963292614473975"
308
+ ],
309
+ [
310
+ "1",
311
+ "0"
312
+ ]
313
+ ],
314
+ [
315
+ [
316
+ "11706947284665470438085734275890584651957983546291282232304205898476084974953",
317
+ "6841243505372324564043525805425666596605335849634400049689614462868641599622"
318
+ ],
319
+ [
320
+ "2674642993002069213220912300725195098434544703961492590713058622848310061455",
321
+ "8134420958061302592465696766566203845441024351721660066575866529624350946525"
322
+ ],
323
+ [
324
+ "1",
325
+ "0"
326
+ ]
327
+ ],
328
+ [
329
+ [
330
+ "14347453588631116202352669855016330076170847581618919999243717038742915487177",
331
+ "16222168105567777760688113388791710300819703656136395550799888633073848798053"
332
+ ],
333
+ [
334
+ "5558376366205739247464101507558623934779699722049069497418188353860561540238",
335
+ "1551977748690015855031859376084014992267998166583511614295554470740621685494"
336
+ ],
337
+ [
338
+ "1",
339
+ "0"
340
+ ]
341
+ ],
342
+ [
343
+ [
344
+ "13742810756711208866393269789950822956196651488331544225304557369739035583007",
345
+ "8039261311473792027408130340265108867783988336829815266149766357424909552805"
346
+ ],
347
+ [
348
+ "1426283383724925735279168010737048062664480092231550167387716017170422478271",
349
+ "5732605965679620193714116075516176231919315490749768120227762344555213912038"
350
+ ],
351
+ [
352
+ "1",
353
+ "0"
354
+ ]
355
+ ],
356
+ [
357
+ [
358
+ "4869230832458710492613139050501069397194236257402947715710705773326736170245",
359
+ "12816421563768297608770270654146762017343826741755988834647936785087288245221"
360
+ ],
361
+ [
362
+ "11073344652802336528382437239976464979745376329678013840706100925574578891663",
363
+ "18301439700961740613282752163964601039402055729651579152511810295028351855917"
364
+ ],
365
+ [
366
+ "1",
367
+ "0"
368
+ ]
369
+ ],
370
+ [
371
+ [
372
+ "11544253490899949675932185200523769178642714850738952025947643180461452257027",
373
+ "10621957863293158040009666146187340406300006617270113507997717497098731431645"
374
+ ],
375
+ [
376
+ "49583159539136224825737189586941489049516773623689603831917260806184061698",
377
+ "19367886286197174023585178612664391272570357530876044259219178006444442279835"
378
+ ],
379
+ [
380
+ "1",
381
+ "0"
382
+ ]
383
+ ],
384
+ [
385
+ [
386
+ "20152340858374022568747410447956756883573367358669429548835673215400335225747",
387
+ "6919690594446594824660388293695365136302375315018989420609208580270256193473"
388
+ ],
389
+ [
390
+ "16509772385894559653132866836382733797078280267167499296517180188027714772070",
391
+ "11674218038035204128186342498577020603218612593894174060137243207689886423596"
392
+ ],
393
+ [
394
+ "1",
395
+ "0"
396
+ ]
397
+ ],
398
+ [
399
+ [
400
+ "21672319732433045166991956534762990382763080837755725716637027617201056105221",
401
+ "3246325158773052647788911340476235648870186305670446321333841273770228016262"
402
+ ],
403
+ [
404
+ "5332470123606111842725808071294486759248878958039162159296029608796276205941",
405
+ "1097625536358560225015844871776096852794298581720514105921271391131873344240"
406
+ ],
407
+ [
408
+ "1",
409
+ "0"
410
+ ]
411
+ ]
412
+ ];
413
+ var vk_alphabeta_12 = [
414
+ [
415
+ [
416
+ "2029413683389138792403550203267699914886160938906632433982220835551125967885",
417
+ "21072700047562757817161031222997517981543347628379360635925549008442030252106"
418
+ ],
419
+ [
420
+ "5940354580057074848093997050200682056184807770593307860589430076672439820312",
421
+ "12156638873931618554171829126792193045421052652279363021382169897324752428276"
422
+ ],
423
+ [
424
+ "7898200236362823042373859371574133993780991612861777490112507062703164551277",
425
+ "7074218545237549455313236346927434013100842096812539264420499035217050630853"
426
+ ]
427
+ ],
428
+ [
429
+ [
430
+ "7077479683546002997211712695946002074877511277312570035766170199895071832130",
431
+ "10093483419865920389913245021038182291233451549023025229112148274109565435465"
432
+ ],
433
+ [
434
+ "4595479056700221319381530156280926371456704509942304414423590385166031118820",
435
+ "19831328484489333784475432780421641293929726139240675179672856274388269393268"
436
+ ],
437
+ [
438
+ "11934129596455521040620786944827826205713621633706285934057045369193958244500",
439
+ "8037395052364110730298837004334506829870972346962140206007064471173334027475"
440
+ ]
441
+ ]
442
+ ];
443
+ var IC = [
444
+ [
445
+ [
446
+ "16397970494781113622140409380710514277504568512202481522431528914560031562762",
447
+ "15987991045804318696151558137607070651882190737142560406194591976742796145195",
448
+ "1"
449
+ ],
450
+ [
451
+ "19175554796060272870947844726785784415291967441071791144616572094703752022787",
452
+ "14708716857471570462880683190724447733812118518043273649838616424043548023127",
453
+ "1"
454
+ ],
455
+ [
456
+ "5109703116431086866657790821388182053265093586387384935734011036204399393630",
457
+ "1612476077210311180626421664389270104678910550524363357381847966959374674423",
458
+ "1"
459
+ ],
460
+ [
461
+ "16028984344157742576452936855797086856968817024956118691418341585143424903639",
462
+ "6905323418829609143361434077039383502192920586565275784934386988372483556465",
463
+ "1"
464
+ ],
465
+ [
466
+ "5037234187699234788733084505200789125332575456459095878140727750253994537245",
467
+ "5152780378461098676484401284161685966625077837157208907964141131514955942959",
468
+ "1"
469
+ ]
470
+ ],
471
+ [
472
+ [
473
+ "19573269191775350978579562905764743103417752180580176229566975904395505694207",
474
+ "2381522187377974692257359562587606852360557473353020907100590706767276986457",
475
+ "1"
476
+ ],
477
+ [
478
+ "3570865353993345507636525265023758855364727230473021611280650482974485897542",
479
+ "3026650225811133060402545160946181194870257210933662802529138266788423022235",
480
+ "1"
481
+ ],
482
+ [
483
+ "10948020004642082805202152014062303498984706484599503419636897666877701726029",
484
+ "16425328653566008388486740080892552688012772956429074139489785673820307770702",
485
+ "1"
486
+ ],
487
+ [
488
+ "20638502839000044414864636985783149953889799151008745227055624454042471377832",
489
+ "977321369609271151576827768083353705509746900519279122286818202637470656742",
490
+ "1"
491
+ ],
492
+ [
493
+ "18662986393280647182646025762677321210586855801774577114215804961111542726195",
494
+ "9182414327249389553719378979750943052880001176853490206379257023646169811116",
495
+ "1"
496
+ ]
497
+ ],
498
+ [
499
+ [
500
+ "1172653041469601107707030355715854571110526375194334139771259673595104816259",
501
+ "139822645729727942447876327389754883087551266970976361358585992124005959663",
502
+ "1"
503
+ ],
504
+ [
505
+ "807568760006422352594797418374693945705914727214443753238278163089338607471",
506
+ "19362805143026565781098954744725161233661862485826387437200176803022106919133",
507
+ "1"
508
+ ],
509
+ [
510
+ "9457043262004277983171082100772969689099515860060732671699192102623198243288",
511
+ "19229090298682361289811638032020124933114889462217199961448135904896325661193",
512
+ "1"
513
+ ],
514
+ [
515
+ "18883326163102164343877677909116984239805709949130729675634413304023108763212",
516
+ "2795333364660917174391473381893559091159208514832297547909172862364581446206",
517
+ "1"
518
+ ],
519
+ [
520
+ "18012979848063967305324818138773222084850070233834350625943804711450349870116",
521
+ "11425098272720529401115253745902976848228234025625773037823969253767737500443",
522
+ "1"
523
+ ]
524
+ ],
525
+ [
526
+ [
527
+ "5735580005765404165535708760854311053102182143614810924129912232734875728422",
528
+ "12547270286864340931439010083179993915942911007015778927394042746771813715897",
529
+ "1"
530
+ ],
531
+ [
532
+ "17861179987982979247789643870162154315308943006677455616368767345181299723498",
533
+ "12520843301982976970226379882714814545061255956743392202788539428471921045815",
534
+ "1"
535
+ ],
536
+ [
537
+ "709419095293140562723620898844593712074413125125086760533949250121053456086",
538
+ "20254885558410038279405227446341995510955697359900050994091569463713580982280",
539
+ "1"
540
+ ],
541
+ [
542
+ "8876829807505794597615690202974184696287415186921508358861381955321520402876",
543
+ "9692396410060123455009190221005078571838194435772371581970098240972280778466",
544
+ "1"
545
+ ],
546
+ [
547
+ "11541729643712807778212647011796800767186857085220105751644556558522744760878",
548
+ "7117533920695574619512162711113223946930183977424569115798612426749467545080",
549
+ "1"
550
+ ]
551
+ ],
552
+ [
553
+ [
554
+ "7022760843802757109079393624924627417630030139055381384837279305453559861026",
555
+ "14368180091281110030022253036601349874026580767275461373222397498585380849175",
556
+ "1"
557
+ ],
558
+ [
559
+ "20362090815079102760789516334841889611927869342884580401494938701237909313479",
560
+ "11683916255585393494577805363227207275174890005674166623110857790951330330248",
561
+ "1"
562
+ ],
563
+ [
564
+ "21680925564107543632769644144771629045807478787600735681275069556336841549441",
565
+ "1554686039880869088226596836931999292372497423378849142389700108361111176287",
566
+ "1"
567
+ ],
568
+ [
569
+ "9553151402225656007352139561853210183786116738154807824913092141416366824324",
570
+ "21774504332021003611111291017295441063483107704370481606906960187337904118400",
571
+ "1"
572
+ ],
573
+ [
574
+ "3472743162059388238264946309663113383560193397376658519781344886918012396958",
575
+ "21850707327192737842691835772722844106916466129654852946865863108319178245521",
576
+ "1"
577
+ ]
578
+ ],
579
+ [
580
+ [
581
+ "14007544454490183581525584522132854274412440955138184221862170710084681738226",
582
+ "9427297140302346741340407818949601657384670126565058224960470754064287232598",
583
+ "1"
584
+ ],
585
+ [
586
+ "9424279417196769259939653963004219272435595656090601392111859177294419276463",
587
+ "5159704841441138198509282351301933053602549958584575945916187562678590534936",
588
+ "1"
589
+ ],
590
+ [
591
+ "5934282708091541939003757621608766449985810436411564642900129758520734711260",
592
+ "6572936900512215029112509161886160866328777917297795430264727434969553346474",
593
+ "1"
594
+ ],
595
+ [
596
+ "17332317297867087005634642159909283377570778576256008720318658354552654813365",
597
+ "20469716791176463599463762213563135543375669917658488173798369718370224346075",
598
+ "1"
599
+ ],
600
+ [
601
+ "11895216520141526042182770992519307655836464153974170586288146149131884093776",
602
+ "2345310584279491449819095573562431881564998414485162753036518957549727207513",
603
+ "1"
604
+ ]
605
+ ],
606
+ [
607
+ [
608
+ "15084362489402846752495176069529022447007294106313236924068931072406922960482",
609
+ "17446301099629553693162731281967866078816607293341610477850995414321505446665",
610
+ "1"
611
+ ],
612
+ [
613
+ "15416633712259927998995598381829216728913683600537032862643171407716059372732",
614
+ "6910124994917236999728700744617337824847623550680442113266553962793201270115",
615
+ "1"
616
+ ],
617
+ [
618
+ "3240338086312503075747637551773566329150860621223080774242357236897458479365",
619
+ "9706162939164863315053907226494918827393300584078535638283184502242772542378",
620
+ "1"
621
+ ],
622
+ [
623
+ "3821371825593696440611637099905775310839636477646533943959149234595561019388",
624
+ "12220054708690507765048929995921680127285008492320123722886943219569231705313",
625
+ "1"
626
+ ],
627
+ [
628
+ "16484014909498227505527128570845947338361237083477117662394990633734193572570",
629
+ "15639273550026538537711009501005182488432976272250651065072907504931158455474",
630
+ "1"
631
+ ]
632
+ ],
633
+ [
634
+ [
635
+ "7289543915982634578897897440956973302403422297539950338836810160596047457980",
636
+ "15177295033774438197517772642364420015492974487860823338193520175227862903717",
637
+ "1"
638
+ ],
639
+ [
640
+ "5412509155867259433944542755241941469706034032614068890113478300647952353475",
641
+ "16755045912589178729548422106539306191579601567866216267685082373250783779841",
642
+ "1"
643
+ ],
644
+ [
645
+ "844425885324371282218176954530597075058496766373014736097970493596574863875",
646
+ "12323478340077628423886836431146436403221716179764806398442271274194718652143",
647
+ "1"
648
+ ],
649
+ [
650
+ "19468406721151512215981453048984639951787280312568894384216547824763527840472",
651
+ "6512636337641737270183934024333064400224464644359645491020358650071524340464",
652
+ "1"
653
+ ],
654
+ [
655
+ "8198878215192784492258585011520207242810327647198332623948351347768018051267",
656
+ "8014960150646978739731831763393714179490854831922196242908407049327430863238",
657
+ "1"
658
+ ]
659
+ ],
660
+ [
661
+ [
662
+ "9107882721143487446664847981273782313316003453386555221878701631432129058401",
663
+ "9441695541513726822451572070540177043748046411169636568582927338148104680158",
664
+ "1"
665
+ ],
666
+ [
667
+ "8987068930426301924419900826390508311526176863992306858982473479912439758010",
668
+ "1725109031239210601724581840155988791039497876559382612372874257775877974323",
669
+ "1"
670
+ ],
671
+ [
672
+ "18516110346729610211387987894593386281257834088357741109524145966500785499183",
673
+ "114078214476076549461901405178268623018026929846201249476869510133510589766",
674
+ "1"
675
+ ],
676
+ [
677
+ "15915940069177053049090451855582611051242699463952201407239272373068542013292",
678
+ "9373936080407194259749015269175580128112032582312467763484971165406599176646",
679
+ "1"
680
+ ],
681
+ [
682
+ "4922802633190996456945600288106639549790810185209505074744770090776471062338",
683
+ "8883001810279320778962047313612748029483858862205749774979015238684570049088",
684
+ "1"
685
+ ]
686
+ ],
687
+ [
688
+ [
689
+ "14718035764669896417897962215694711502145567157050183561348015124983050763912",
690
+ "16468329864686708461615593125586840110548434159129257976547738477143616225069",
691
+ "1"
692
+ ],
693
+ [
694
+ "19316680422470456517825967239402234468963225932355881906076897312088976727808",
695
+ "3793008941035953637072065313624049788550692955904011087840457148221740889857",
696
+ "1"
697
+ ],
698
+ [
699
+ "8994123619474927749524041243795236789619386871069943230512200348341409025802",
700
+ "2898455184193535874162795400065700362364113037155462125222703939894764399559",
701
+ "1"
702
+ ],
703
+ [
704
+ "7006987736985681119096469806956612323700302986805047546691419062106874738669",
705
+ "6578526693577992862738197741211972861837397562647850241473856881198749597774",
706
+ "1"
707
+ ],
708
+ [
709
+ "18253609658317686864081972526657430282945609846265497350129963610508303097865",
710
+ "20602454323920106770928127673050173555696255204782817307960073152139829286712",
711
+ "1"
712
+ ]
713
+ ],
714
+ [
715
+ [
716
+ "18387700354891683161007139598833533459740755646851082725263944626765753998128",
717
+ "8496770255291121655312305725645117658510206297162207504909146686627154245846",
718
+ "1"
719
+ ],
720
+ [
721
+ "3295351580633631545204707236418977224205703294426182202748223245617942752953",
722
+ "11318533876720817956139762907441156918032396007060817178042936071438547629319",
723
+ "1"
724
+ ],
725
+ [
726
+ "9798692489110933308397734193670030418121117030189402149994776248649813971130",
727
+ "7253879530870754821836349446054636336833607432103959373798000294248292966203",
728
+ "1"
729
+ ],
730
+ [
731
+ "21808645514001764351825515375665639285586999794992628373968527911077248645185",
732
+ "2859748802987042398453158245958377568437550705999358391809538153774651114865",
733
+ "1"
734
+ ],
735
+ [
736
+ "4373537692781319117201803895634857716202697229097770645380222493663057011429",
737
+ "21723556418902236605356947828522543021755681613733490227407492902239152334538",
738
+ "1"
739
+ ]
740
+ ],
741
+ [
742
+ [
743
+ "4147129560663007063799754603731275683761368247704376766576071776957227165800",
744
+ "7032402220603422034618210155106646820962552774510253688945919060625670415308",
745
+ "1"
746
+ ],
747
+ [
748
+ "5241022678363371404039324538224070321660623527603509392150146296843642044363",
749
+ "5281273397025328620822441453790518717375265972202147684745427714882287252791",
750
+ "1"
751
+ ],
752
+ [
753
+ "8109626675067152219533782552336308649905522111608563670382254454484448073029",
754
+ "4696661232179595878220108186097206302552300846640109174608389689072223809776",
755
+ "1"
756
+ ],
757
+ [
758
+ "13974026846148052806722306435446895222317781098029808723550029071117080027133",
759
+ "14451415757463182353662034231421738047130904367363697865823311429455557043904",
760
+ "1"
761
+ ],
762
+ [
763
+ "9490728148230530026163178051838213576627639298618884515939110001242292217290",
764
+ "227687333556127166330064214209948378192130717415165040791158610964406937909",
765
+ "1"
766
+ ]
767
+ ]
768
+ ];
769
+ var verificationKeys = {
770
+ protocol: protocol,
771
+ curve: curve,
772
+ nPublic: nPublic,
773
+ vk_alpha_1: vk_alpha_1,
774
+ vk_beta_2: vk_beta_2,
775
+ vk_gamma_2: vk_gamma_2,
776
+ vk_delta_2: vk_delta_2,
777
+ vk_alphabeta_12: vk_alphabeta_12,
778
+ IC: IC
779
+ };
780
+
781
+ /**
782
+ * Verifies a Semaphore proof.
783
+ * @param fullProof The SnarkJS Semaphore proof.
784
+ * @param treeDepth The depth of the tree.
785
+ * @returns True if the proof is valid, false otherwise.
786
+ */
787
+ function verifyProof(_a) {
788
+ var merkleTreeDepth = _a.merkleTreeDepth, merkleTreeRoot = _a.merkleTreeRoot, nullifier = _a.nullifier, message = _a.message, scope = _a.scope, points = _a.points;
789
+ return __awaiter(this, void 0, void 0, function () {
790
+ var verificationKey;
791
+ return __generator(this, function (_b) {
792
+ // TODO: support all tree depths after trusted-setup.
793
+ if (merkleTreeDepth < 1 || merkleTreeDepth > 12) {
794
+ throw new TypeError("The tree depth must be a number between 1 and 12");
795
+ }
796
+ verificationKey = __assign(__assign({}, verificationKeys), { vk_delta_2: verificationKeys.vk_delta_2[merkleTreeDepth - 1], IC: verificationKeys.IC[merkleTreeDepth - 1] });
797
+ return [2 /*return*/, groth16.verify(verificationKey, [merkleTreeRoot, nullifier, hash(message), hash(scope)], unpackPoints(points))];
798
+ });
799
+ });
800
+ }
801
+
802
+ export { generateProof, getSnarkArtifacts, packPoints, unpackPoints, verifyProof };