@semaphore-protocol/proof 3.15.1 → 4.0.0-alpha

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,800 @@
1
+ /**
2
+ * @module @semaphore-protocol/proof
3
+ * @version 4.0.0-alpha
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 { prove, verify } from '@zk-kit/groth16';
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 a proof into a format compatible with Semaphore.
104
+ * @param proof The Groth16 proof generated with SnarkJS.
105
+ * @returns The proof compatible with Semaphore.
106
+ */
107
+ function packProof(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 group 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, group, message, scope, merkleTreeDepth, snarkArtifacts) {
131
+ return __awaiter(this, void 0, void 0, function () {
132
+ var leafIndex, merkleProof, merkleProofLength, merkleProofIndices, merkleProofSiblings, i, _a, proof, publicSignals;
133
+ return __generator(this, function (_b) {
134
+ switch (_b.label) {
135
+ case 0:
136
+ leafIndex = group.indexOf(identity.commitment);
137
+ merkleProof = group.generateMerkleProof(leafIndex);
138
+ merkleProofLength = merkleProof.siblings.length;
139
+ if (merkleTreeDepth !== undefined) {
140
+ if (merkleTreeDepth < 1 || merkleTreeDepth > 12) {
141
+ throw new TypeError("The tree depth must be a number between 1 and 12");
142
+ }
143
+ }
144
+ else {
145
+ merkleTreeDepth = merkleProofLength;
146
+ }
147
+ if (!!snarkArtifacts) return [3 /*break*/, 2];
148
+ return [4 /*yield*/, getSnarkArtifacts(merkleTreeDepth)];
149
+ case 1:
150
+ snarkArtifacts = _b.sent();
151
+ _b.label = 2;
152
+ case 2:
153
+ merkleProofIndices = [];
154
+ merkleProofSiblings = merkleProof.siblings;
155
+ for (i = 0; i < merkleTreeDepth; i += 1) {
156
+ merkleProofIndices.push((merkleProof.index >> i) & 1);
157
+ if (merkleProofSiblings[i] === undefined) {
158
+ merkleProofSiblings[i] = "0";
159
+ }
160
+ }
161
+ return [4 /*yield*/, prove({
162
+ secret: identity.secretScalar,
163
+ merkleProofLength: merkleProofLength,
164
+ merkleProofIndices: merkleProofIndices,
165
+ merkleProofSiblings: merkleProofSiblings,
166
+ scope: hash(scope),
167
+ message: hash(message)
168
+ }, snarkArtifacts.wasmFilePath, snarkArtifacts.zkeyFilePath)];
169
+ case 3:
170
+ _a = _b.sent(), proof = _a.proof, publicSignals = _a.publicSignals;
171
+ return [2 /*return*/, {
172
+ merkleTreeDepth: merkleTreeDepth,
173
+ merkleTreeRoot: publicSignals[0],
174
+ nullifier: publicSignals[1],
175
+ message: BigNumber.from(message).toString(),
176
+ scope: BigNumber.from(scope).toString(),
177
+ proof: packProof(proof)
178
+ }];
179
+ }
180
+ });
181
+ });
182
+ }
183
+
184
+ /**
185
+ * Unpacks a proof into its original form.
186
+ * @param proof The proof compatible with Semaphore.
187
+ * @returns The proof compatible with SnarkJS.
188
+ */
189
+ function unpackProof(proof) {
190
+ return {
191
+ pi_a: [proof[0], proof[1]],
192
+ pi_b: [
193
+ [proof[3], proof[2]],
194
+ [proof[5], proof[4]]
195
+ ],
196
+ pi_c: [proof[6], proof[7]],
197
+ protocol: "groth16",
198
+ curve: "bn128"
199
+ };
200
+ }
201
+
202
+ var protocol = "groth16";
203
+ var curve = "bn128";
204
+ var nPublic = 4;
205
+ var vk_alpha_1 = [
206
+ "20491192805390485299153009773594534940189261866228447918068658471970481763042",
207
+ "9383485363053290200918347156157836566562967994039712273449902621266178545958",
208
+ "1"
209
+ ];
210
+ var vk_beta_2 = [
211
+ [
212
+ "6375614351688725206403948262868962793625744043794305715222011528459656738731",
213
+ "4252822878758300859123897981450591353533073413197771768651442665752259397132"
214
+ ],
215
+ [
216
+ "10505242626370262277552901082094356697409835680220590971873171140371331206856",
217
+ "21847035105528745403288232691147584728191162732299865338377159692350059136679"
218
+ ],
219
+ [
220
+ "1",
221
+ "0"
222
+ ]
223
+ ];
224
+ var vk_gamma_2 = [
225
+ [
226
+ "10857046999023057135944570762232829481370756359578518086990519993285655852781",
227
+ "11559732032986387107991004021392285783925812861821192530917403151452391805634"
228
+ ],
229
+ [
230
+ "8495653923123431417604973247489272438418190587263600148770280649306958101930",
231
+ "4082367875863433681332203403145435568316851327593401208105741076214120093531"
232
+ ],
233
+ [
234
+ "1",
235
+ "0"
236
+ ]
237
+ ];
238
+ var vk_delta_2 = [
239
+ [
240
+ [
241
+ "16293410697967515504861065986355060225819302510590370360517024529684437085892",
242
+ "563562783592406106461234396505774794044312891062077216951605541624542949349"
243
+ ],
244
+ [
245
+ "10971164449179097832515056670594147898894418081309026322805549037082528587660",
246
+ "718666295291146285397081607986058864287612968465033527894198098928522749430"
247
+ ],
248
+ [
249
+ "1",
250
+ "0"
251
+ ]
252
+ ],
253
+ [
254
+ [
255
+ "8087990171976409378525016197066789089596692733769545253942804888352233244331",
256
+ "6925326031648378844726759441690273332175949886518827719224741736678266471462"
257
+ ],
258
+ [
259
+ "15618724583521291135890928658458637081479213437530496494788106479523123480134",
260
+ "10115242383701466910539784663900956956505212347433548599529944880163612117847"
261
+ ],
262
+ [
263
+ "1",
264
+ "0"
265
+ ]
266
+ ],
267
+ [
268
+ [
269
+ "7699563868952902688273782470023919811229667532027732585467624469008534197561",
270
+ "7699900854308622607636895140107457213471038801393300399043779958706267744510"
271
+ ],
272
+ [
273
+ "15390497513810955087868026868634948499789494261604405008298272598684585331879",
274
+ "8605006500231713390564760089884965869867818332514275728271802101761117177706"
275
+ ],
276
+ [
277
+ "1",
278
+ "0"
279
+ ]
280
+ ],
281
+ [
282
+ [
283
+ "2561989864654045354260435368824127763249975523256535586391379695256700207392",
284
+ "9243647856126339588200227750973237380809101852206502177952556679680468734813"
285
+ ],
286
+ [
287
+ "18264861452415533737686303596832882667852638121244187636443702248458018416929",
288
+ "1308059969166897152269078839315249187046718124106168932020710683189419160756"
289
+ ],
290
+ [
291
+ "1",
292
+ "0"
293
+ ]
294
+ ],
295
+ [
296
+ [
297
+ "21307904757295729894500052152251151076177124351059746872940558537429181679313",
298
+ "12554869896570109663558999106053541183136083706372178136870048170147558661370"
299
+ ],
300
+ [
301
+ "11194665041440536766843756304212299788817698936187605770131686430625103172681",
302
+ "13447792161027167738515744919555311619301071111923271126707713963292614473975"
303
+ ],
304
+ [
305
+ "1",
306
+ "0"
307
+ ]
308
+ ],
309
+ [
310
+ [
311
+ "11706947284665470438085734275890584651957983546291282232304205898476084974953",
312
+ "6841243505372324564043525805425666596605335849634400049689614462868641599622"
313
+ ],
314
+ [
315
+ "2674642993002069213220912300725195098434544703961492590713058622848310061455",
316
+ "8134420958061302592465696766566203845441024351721660066575866529624350946525"
317
+ ],
318
+ [
319
+ "1",
320
+ "0"
321
+ ]
322
+ ],
323
+ [
324
+ [
325
+ "14347453588631116202352669855016330076170847581618919999243717038742915487177",
326
+ "16222168105567777760688113388791710300819703656136395550799888633073848798053"
327
+ ],
328
+ [
329
+ "5558376366205739247464101507558623934779699722049069497418188353860561540238",
330
+ "1551977748690015855031859376084014992267998166583511614295554470740621685494"
331
+ ],
332
+ [
333
+ "1",
334
+ "0"
335
+ ]
336
+ ],
337
+ [
338
+ [
339
+ "13742810756711208866393269789950822956196651488331544225304557369739035583007",
340
+ "8039261311473792027408130340265108867783988336829815266149766357424909552805"
341
+ ],
342
+ [
343
+ "1426283383724925735279168010737048062664480092231550167387716017170422478271",
344
+ "5732605965679620193714116075516176231919315490749768120227762344555213912038"
345
+ ],
346
+ [
347
+ "1",
348
+ "0"
349
+ ]
350
+ ],
351
+ [
352
+ [
353
+ "4869230832458710492613139050501069397194236257402947715710705773326736170245",
354
+ "12816421563768297608770270654146762017343826741755988834647936785087288245221"
355
+ ],
356
+ [
357
+ "11073344652802336528382437239976464979745376329678013840706100925574578891663",
358
+ "18301439700961740613282752163964601039402055729651579152511810295028351855917"
359
+ ],
360
+ [
361
+ "1",
362
+ "0"
363
+ ]
364
+ ],
365
+ [
366
+ [
367
+ "11544253490899949675932185200523769178642714850738952025947643180461452257027",
368
+ "10621957863293158040009666146187340406300006617270113507997717497098731431645"
369
+ ],
370
+ [
371
+ "49583159539136224825737189586941489049516773623689603831917260806184061698",
372
+ "19367886286197174023585178612664391272570357530876044259219178006444442279835"
373
+ ],
374
+ [
375
+ "1",
376
+ "0"
377
+ ]
378
+ ],
379
+ [
380
+ [
381
+ "20152340858374022568747410447956756883573367358669429548835673215400335225747",
382
+ "6919690594446594824660388293695365136302375315018989420609208580270256193473"
383
+ ],
384
+ [
385
+ "16509772385894559653132866836382733797078280267167499296517180188027714772070",
386
+ "11674218038035204128186342498577020603218612593894174060137243207689886423596"
387
+ ],
388
+ [
389
+ "1",
390
+ "0"
391
+ ]
392
+ ],
393
+ [
394
+ [
395
+ "21672319732433045166991956534762990382763080837755725716637027617201056105221",
396
+ "3246325158773052647788911340476235648870186305670446321333841273770228016262"
397
+ ],
398
+ [
399
+ "5332470123606111842725808071294486759248878958039162159296029608796276205941",
400
+ "1097625536358560225015844871776096852794298581720514105921271391131873344240"
401
+ ],
402
+ [
403
+ "1",
404
+ "0"
405
+ ]
406
+ ]
407
+ ];
408
+ var vk_alphabeta_12 = [
409
+ [
410
+ [
411
+ "2029413683389138792403550203267699914886160938906632433982220835551125967885",
412
+ "21072700047562757817161031222997517981543347628379360635925549008442030252106"
413
+ ],
414
+ [
415
+ "5940354580057074848093997050200682056184807770593307860589430076672439820312",
416
+ "12156638873931618554171829126792193045421052652279363021382169897324752428276"
417
+ ],
418
+ [
419
+ "7898200236362823042373859371574133993780991612861777490112507062703164551277",
420
+ "7074218545237549455313236346927434013100842096812539264420499035217050630853"
421
+ ]
422
+ ],
423
+ [
424
+ [
425
+ "7077479683546002997211712695946002074877511277312570035766170199895071832130",
426
+ "10093483419865920389913245021038182291233451549023025229112148274109565435465"
427
+ ],
428
+ [
429
+ "4595479056700221319381530156280926371456704509942304414423590385166031118820",
430
+ "19831328484489333784475432780421641293929726139240675179672856274388269393268"
431
+ ],
432
+ [
433
+ "11934129596455521040620786944827826205713621633706285934057045369193958244500",
434
+ "8037395052364110730298837004334506829870972346962140206007064471173334027475"
435
+ ]
436
+ ]
437
+ ];
438
+ var IC = [
439
+ [
440
+ [
441
+ "16397970494781113622140409380710514277504568512202481522431528914560031562762",
442
+ "15987991045804318696151558137607070651882190737142560406194591976742796145195",
443
+ "1"
444
+ ],
445
+ [
446
+ "19175554796060272870947844726785784415291967441071791144616572094703752022787",
447
+ "14708716857471570462880683190724447733812118518043273649838616424043548023127",
448
+ "1"
449
+ ],
450
+ [
451
+ "5109703116431086866657790821388182053265093586387384935734011036204399393630",
452
+ "1612476077210311180626421664389270104678910550524363357381847966959374674423",
453
+ "1"
454
+ ],
455
+ [
456
+ "16028984344157742576452936855797086856968817024956118691418341585143424903639",
457
+ "6905323418829609143361434077039383502192920586565275784934386988372483556465",
458
+ "1"
459
+ ],
460
+ [
461
+ "5037234187699234788733084505200789125332575456459095878140727750253994537245",
462
+ "5152780378461098676484401284161685966625077837157208907964141131514955942959",
463
+ "1"
464
+ ]
465
+ ],
466
+ [
467
+ [
468
+ "19573269191775350978579562905764743103417752180580176229566975904395505694207",
469
+ "2381522187377974692257359562587606852360557473353020907100590706767276986457",
470
+ "1"
471
+ ],
472
+ [
473
+ "3570865353993345507636525265023758855364727230473021611280650482974485897542",
474
+ "3026650225811133060402545160946181194870257210933662802529138266788423022235",
475
+ "1"
476
+ ],
477
+ [
478
+ "10948020004642082805202152014062303498984706484599503419636897666877701726029",
479
+ "16425328653566008388486740080892552688012772956429074139489785673820307770702",
480
+ "1"
481
+ ],
482
+ [
483
+ "20638502839000044414864636985783149953889799151008745227055624454042471377832",
484
+ "977321369609271151576827768083353705509746900519279122286818202637470656742",
485
+ "1"
486
+ ],
487
+ [
488
+ "18662986393280647182646025762677321210586855801774577114215804961111542726195",
489
+ "9182414327249389553719378979750943052880001176853490206379257023646169811116",
490
+ "1"
491
+ ]
492
+ ],
493
+ [
494
+ [
495
+ "1172653041469601107707030355715854571110526375194334139771259673595104816259",
496
+ "139822645729727942447876327389754883087551266970976361358585992124005959663",
497
+ "1"
498
+ ],
499
+ [
500
+ "807568760006422352594797418374693945705914727214443753238278163089338607471",
501
+ "19362805143026565781098954744725161233661862485826387437200176803022106919133",
502
+ "1"
503
+ ],
504
+ [
505
+ "9457043262004277983171082100772969689099515860060732671699192102623198243288",
506
+ "19229090298682361289811638032020124933114889462217199961448135904896325661193",
507
+ "1"
508
+ ],
509
+ [
510
+ "18883326163102164343877677909116984239805709949130729675634413304023108763212",
511
+ "2795333364660917174391473381893559091159208514832297547909172862364581446206",
512
+ "1"
513
+ ],
514
+ [
515
+ "18012979848063967305324818138773222084850070233834350625943804711450349870116",
516
+ "11425098272720529401115253745902976848228234025625773037823969253767737500443",
517
+ "1"
518
+ ]
519
+ ],
520
+ [
521
+ [
522
+ "5735580005765404165535708760854311053102182143614810924129912232734875728422",
523
+ "12547270286864340931439010083179993915942911007015778927394042746771813715897",
524
+ "1"
525
+ ],
526
+ [
527
+ "17861179987982979247789643870162154315308943006677455616368767345181299723498",
528
+ "12520843301982976970226379882714814545061255956743392202788539428471921045815",
529
+ "1"
530
+ ],
531
+ [
532
+ "709419095293140562723620898844593712074413125125086760533949250121053456086",
533
+ "20254885558410038279405227446341995510955697359900050994091569463713580982280",
534
+ "1"
535
+ ],
536
+ [
537
+ "8876829807505794597615690202974184696287415186921508358861381955321520402876",
538
+ "9692396410060123455009190221005078571838194435772371581970098240972280778466",
539
+ "1"
540
+ ],
541
+ [
542
+ "11541729643712807778212647011796800767186857085220105751644556558522744760878",
543
+ "7117533920695574619512162711113223946930183977424569115798612426749467545080",
544
+ "1"
545
+ ]
546
+ ],
547
+ [
548
+ [
549
+ "7022760843802757109079393624924627417630030139055381384837279305453559861026",
550
+ "14368180091281110030022253036601349874026580767275461373222397498585380849175",
551
+ "1"
552
+ ],
553
+ [
554
+ "20362090815079102760789516334841889611927869342884580401494938701237909313479",
555
+ "11683916255585393494577805363227207275174890005674166623110857790951330330248",
556
+ "1"
557
+ ],
558
+ [
559
+ "21680925564107543632769644144771629045807478787600735681275069556336841549441",
560
+ "1554686039880869088226596836931999292372497423378849142389700108361111176287",
561
+ "1"
562
+ ],
563
+ [
564
+ "9553151402225656007352139561853210183786116738154807824913092141416366824324",
565
+ "21774504332021003611111291017295441063483107704370481606906960187337904118400",
566
+ "1"
567
+ ],
568
+ [
569
+ "3472743162059388238264946309663113383560193397376658519781344886918012396958",
570
+ "21850707327192737842691835772722844106916466129654852946865863108319178245521",
571
+ "1"
572
+ ]
573
+ ],
574
+ [
575
+ [
576
+ "14007544454490183581525584522132854274412440955138184221862170710084681738226",
577
+ "9427297140302346741340407818949601657384670126565058224960470754064287232598",
578
+ "1"
579
+ ],
580
+ [
581
+ "9424279417196769259939653963004219272435595656090601392111859177294419276463",
582
+ "5159704841441138198509282351301933053602549958584575945916187562678590534936",
583
+ "1"
584
+ ],
585
+ [
586
+ "5934282708091541939003757621608766449985810436411564642900129758520734711260",
587
+ "6572936900512215029112509161886160866328777917297795430264727434969553346474",
588
+ "1"
589
+ ],
590
+ [
591
+ "17332317297867087005634642159909283377570778576256008720318658354552654813365",
592
+ "20469716791176463599463762213563135543375669917658488173798369718370224346075",
593
+ "1"
594
+ ],
595
+ [
596
+ "11895216520141526042182770992519307655836464153974170586288146149131884093776",
597
+ "2345310584279491449819095573562431881564998414485162753036518957549727207513",
598
+ "1"
599
+ ]
600
+ ],
601
+ [
602
+ [
603
+ "15084362489402846752495176069529022447007294106313236924068931072406922960482",
604
+ "17446301099629553693162731281967866078816607293341610477850995414321505446665",
605
+ "1"
606
+ ],
607
+ [
608
+ "15416633712259927998995598381829216728913683600537032862643171407716059372732",
609
+ "6910124994917236999728700744617337824847623550680442113266553962793201270115",
610
+ "1"
611
+ ],
612
+ [
613
+ "3240338086312503075747637551773566329150860621223080774242357236897458479365",
614
+ "9706162939164863315053907226494918827393300584078535638283184502242772542378",
615
+ "1"
616
+ ],
617
+ [
618
+ "3821371825593696440611637099905775310839636477646533943959149234595561019388",
619
+ "12220054708690507765048929995921680127285008492320123722886943219569231705313",
620
+ "1"
621
+ ],
622
+ [
623
+ "16484014909498227505527128570845947338361237083477117662394990633734193572570",
624
+ "15639273550026538537711009501005182488432976272250651065072907504931158455474",
625
+ "1"
626
+ ]
627
+ ],
628
+ [
629
+ [
630
+ "7289543915982634578897897440956973302403422297539950338836810160596047457980",
631
+ "15177295033774438197517772642364420015492974487860823338193520175227862903717",
632
+ "1"
633
+ ],
634
+ [
635
+ "5412509155867259433944542755241941469706034032614068890113478300647952353475",
636
+ "16755045912589178729548422106539306191579601567866216267685082373250783779841",
637
+ "1"
638
+ ],
639
+ [
640
+ "844425885324371282218176954530597075058496766373014736097970493596574863875",
641
+ "12323478340077628423886836431146436403221716179764806398442271274194718652143",
642
+ "1"
643
+ ],
644
+ [
645
+ "19468406721151512215981453048984639951787280312568894384216547824763527840472",
646
+ "6512636337641737270183934024333064400224464644359645491020358650071524340464",
647
+ "1"
648
+ ],
649
+ [
650
+ "8198878215192784492258585011520207242810327647198332623948351347768018051267",
651
+ "8014960150646978739731831763393714179490854831922196242908407049327430863238",
652
+ "1"
653
+ ]
654
+ ],
655
+ [
656
+ [
657
+ "9107882721143487446664847981273782313316003453386555221878701631432129058401",
658
+ "9441695541513726822451572070540177043748046411169636568582927338148104680158",
659
+ "1"
660
+ ],
661
+ [
662
+ "8987068930426301924419900826390508311526176863992306858982473479912439758010",
663
+ "1725109031239210601724581840155988791039497876559382612372874257775877974323",
664
+ "1"
665
+ ],
666
+ [
667
+ "18516110346729610211387987894593386281257834088357741109524145966500785499183",
668
+ "114078214476076549461901405178268623018026929846201249476869510133510589766",
669
+ "1"
670
+ ],
671
+ [
672
+ "15915940069177053049090451855582611051242699463952201407239272373068542013292",
673
+ "9373936080407194259749015269175580128112032582312467763484971165406599176646",
674
+ "1"
675
+ ],
676
+ [
677
+ "4922802633190996456945600288106639549790810185209505074744770090776471062338",
678
+ "8883001810279320778962047313612748029483858862205749774979015238684570049088",
679
+ "1"
680
+ ]
681
+ ],
682
+ [
683
+ [
684
+ "14718035764669896417897962215694711502145567157050183561348015124983050763912",
685
+ "16468329864686708461615593125586840110548434159129257976547738477143616225069",
686
+ "1"
687
+ ],
688
+ [
689
+ "19316680422470456517825967239402234468963225932355881906076897312088976727808",
690
+ "3793008941035953637072065313624049788550692955904011087840457148221740889857",
691
+ "1"
692
+ ],
693
+ [
694
+ "8994123619474927749524041243795236789619386871069943230512200348341409025802",
695
+ "2898455184193535874162795400065700362364113037155462125222703939894764399559",
696
+ "1"
697
+ ],
698
+ [
699
+ "7006987736985681119096469806956612323700302986805047546691419062106874738669",
700
+ "6578526693577992862738197741211972861837397562647850241473856881198749597774",
701
+ "1"
702
+ ],
703
+ [
704
+ "18253609658317686864081972526657430282945609846265497350129963610508303097865",
705
+ "20602454323920106770928127673050173555696255204782817307960073152139829286712",
706
+ "1"
707
+ ]
708
+ ],
709
+ [
710
+ [
711
+ "18387700354891683161007139598833533459740755646851082725263944626765753998128",
712
+ "8496770255291121655312305725645117658510206297162207504909146686627154245846",
713
+ "1"
714
+ ],
715
+ [
716
+ "3295351580633631545204707236418977224205703294426182202748223245617942752953",
717
+ "11318533876720817956139762907441156918032396007060817178042936071438547629319",
718
+ "1"
719
+ ],
720
+ [
721
+ "9798692489110933308397734193670030418121117030189402149994776248649813971130",
722
+ "7253879530870754821836349446054636336833607432103959373798000294248292966203",
723
+ "1"
724
+ ],
725
+ [
726
+ "21808645514001764351825515375665639285586999794992628373968527911077248645185",
727
+ "2859748802987042398453158245958377568437550705999358391809538153774651114865",
728
+ "1"
729
+ ],
730
+ [
731
+ "4373537692781319117201803895634857716202697229097770645380222493663057011429",
732
+ "21723556418902236605356947828522543021755681613733490227407492902239152334538",
733
+ "1"
734
+ ]
735
+ ],
736
+ [
737
+ [
738
+ "4147129560663007063799754603731275683761368247704376766576071776957227165800",
739
+ "7032402220603422034618210155106646820962552774510253688945919060625670415308",
740
+ "1"
741
+ ],
742
+ [
743
+ "5241022678363371404039324538224070321660623527603509392150146296843642044363",
744
+ "5281273397025328620822441453790518717375265972202147684745427714882287252791",
745
+ "1"
746
+ ],
747
+ [
748
+ "8109626675067152219533782552336308649905522111608563670382254454484448073029",
749
+ "4696661232179595878220108186097206302552300846640109174608389689072223809776",
750
+ "1"
751
+ ],
752
+ [
753
+ "13974026846148052806722306435446895222317781098029808723550029071117080027133",
754
+ "14451415757463182353662034231421738047130904367363697865823311429455557043904",
755
+ "1"
756
+ ],
757
+ [
758
+ "9490728148230530026163178051838213576627639298618884515939110001242292217290",
759
+ "227687333556127166330064214209948378192130717415165040791158610964406937909",
760
+ "1"
761
+ ]
762
+ ]
763
+ ];
764
+ var verificationKeys = {
765
+ protocol: protocol,
766
+ curve: curve,
767
+ nPublic: nPublic,
768
+ vk_alpha_1: vk_alpha_1,
769
+ vk_beta_2: vk_beta_2,
770
+ vk_gamma_2: vk_gamma_2,
771
+ vk_delta_2: vk_delta_2,
772
+ vk_alphabeta_12: vk_alphabeta_12,
773
+ IC: IC
774
+ };
775
+
776
+ /**
777
+ * Verifies a Semaphore proof.
778
+ * @param fullProof The SnarkJS Semaphore proof.
779
+ * @param treeDepth The depth of the tree.
780
+ * @returns True if the proof is valid, false otherwise.
781
+ */
782
+ function verifyProof(_a) {
783
+ var merkleTreeDepth = _a.merkleTreeDepth, merkleTreeRoot = _a.merkleTreeRoot, nullifier = _a.nullifier, message = _a.message, scope = _a.scope, proof = _a.proof;
784
+ return __awaiter(this, void 0, void 0, function () {
785
+ var verificationKey;
786
+ return __generator(this, function (_b) {
787
+ // TODO: support all tree depths after trusted-setup.
788
+ if (merkleTreeDepth < 1 || merkleTreeDepth > 12) {
789
+ throw new TypeError("The tree depth must be a number between 1 and 12");
790
+ }
791
+ verificationKey = __assign(__assign({}, verificationKeys), { vk_delta_2: verificationKeys.vk_delta_2[merkleTreeDepth - 1], IC: verificationKeys.IC[merkleTreeDepth - 1] });
792
+ return [2 /*return*/, verify(verificationKey, {
793
+ publicSignals: [merkleTreeRoot, nullifier, hash(message), hash(scope)],
794
+ proof: unpackProof(proof)
795
+ })];
796
+ });
797
+ });
798
+ }
799
+
800
+ export { generateProof, getSnarkArtifacts, packProof, unpackProof, verifyProof };