@silvana-one/mina-curves 0.3.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.
Files changed (61) hide show
  1. package/README.md +3 -0
  2. package/dist/node/curve/constants.d.ts +34 -0
  3. package/dist/node/curve/constants.js +323 -0
  4. package/dist/node/curve/constants.js.map +1 -0
  5. package/dist/node/curve/curve.d.ts +50 -0
  6. package/dist/node/curve/curve.js +307 -0
  7. package/dist/node/curve/curve.js.map +1 -0
  8. package/dist/node/curve/hash.d.ts +6 -0
  9. package/dist/node/curve/hash.js +89 -0
  10. package/dist/node/curve/hash.js.map +1 -0
  11. package/dist/node/curve/index.d.ts +4 -0
  12. package/dist/node/curve/index.js +5 -0
  13. package/dist/node/curve/index.js.map +1 -0
  14. package/dist/node/curve/verify.d.ts +4 -0
  15. package/dist/node/curve/verify.js +19 -0
  16. package/dist/node/curve/verify.js.map +1 -0
  17. package/dist/node/index.cjs +711 -0
  18. package/dist/node/index.d.ts +2 -0
  19. package/dist/node/index.js +3 -0
  20. package/dist/node/index.js.map +1 -0
  21. package/dist/node/poseidon.d.ts +1 -0
  22. package/dist/node/poseidon.js +5 -0
  23. package/dist/node/poseidon.js.map +1 -0
  24. package/dist/node/signature.d.ts +6 -0
  25. package/dist/node/signature.js +6 -0
  26. package/dist/node/signature.js.map +1 -0
  27. package/dist/tsconfig.node.tsbuildinfo +1 -0
  28. package/dist/tsconfig.web.tsbuildinfo +1 -0
  29. package/dist/web/curve/constants.d.ts +34 -0
  30. package/dist/web/curve/constants.js +323 -0
  31. package/dist/web/curve/constants.js.map +1 -0
  32. package/dist/web/curve/curve.d.ts +50 -0
  33. package/dist/web/curve/curve.js +307 -0
  34. package/dist/web/curve/curve.js.map +1 -0
  35. package/dist/web/curve/hash.d.ts +6 -0
  36. package/dist/web/curve/hash.js +89 -0
  37. package/dist/web/curve/hash.js.map +1 -0
  38. package/dist/web/curve/index.d.ts +4 -0
  39. package/dist/web/curve/index.js +5 -0
  40. package/dist/web/curve/index.js.map +1 -0
  41. package/dist/web/curve/verify.d.ts +4 -0
  42. package/dist/web/curve/verify.js +19 -0
  43. package/dist/web/curve/verify.js.map +1 -0
  44. package/dist/web/index.d.ts +2 -0
  45. package/dist/web/index.js +3 -0
  46. package/dist/web/index.js.map +1 -0
  47. package/dist/web/poseidon.d.ts +1 -0
  48. package/dist/web/poseidon.js +5 -0
  49. package/dist/web/poseidon.js.map +1 -0
  50. package/dist/web/signature.d.ts +6 -0
  51. package/dist/web/signature.js +6 -0
  52. package/dist/web/signature.js.map +1 -0
  53. package/package.json +59 -0
  54. package/src/curve/constants.ts +328 -0
  55. package/src/curve/curve.ts +370 -0
  56. package/src/curve/hash.ts +108 -0
  57. package/src/curve/index.ts +4 -0
  58. package/src/curve/verify.ts +31 -0
  59. package/src/index.ts +2 -0
  60. package/src/poseidon.ts +5 -0
  61. package/src/signature.ts +11 -0
@@ -0,0 +1,711 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod2) => __copyProps(__defProp({}, "__esModule", { value: true }), mod2);
19
+
20
+ // dist/node/index.js
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ poseidon: () => poseidon,
24
+ verifySignature: () => verifySignature
25
+ });
26
+ module.exports = __toCommonJS(index_exports);
27
+
28
+ // dist/node/curve/constants.js
29
+ var PallasConstants = {
30
+ name: "Pallas",
31
+ modulus: 28948022309329048855892746252171976963363056481941560715954676764349967630337n,
32
+ order: 28948022309329048855892746252171976963363056481941647379679742748393362948097n,
33
+ cofactor: 1n,
34
+ zero: { x: 1n, y: 1n, z: 0n },
35
+ one: {
36
+ x: 1n,
37
+ y: 12418654782883325593414442427049395787963493412651469444558597405572177144507n,
38
+ z: 1n
39
+ },
40
+ hasEndomorphism: true,
41
+ a: 0n,
42
+ b: 5n,
43
+ hasCofactor: false,
44
+ p: 28948022309329048855892746252171976963363056481941560715954676764349967630337n,
45
+ twoadicRoot: 19814229590243028906643993866117402072516588566294623396325693409366934201135n,
46
+ twoadicity: 32n,
47
+ oddFactor: 6739986666787659948666753771754907668419893943225396963757154709741n
48
+ };
49
+ var PoseidonConstants = {
50
+ stateSize: 3,
51
+ rate: 2,
52
+ fullRounds: 55,
53
+ power: 7n,
54
+ hasInitialRoundConstant: false,
55
+ mds: [
56
+ [
57
+ 12035446894107573964500871153637039653510326950134440362813193268448863222019n,
58
+ 25461374787957152039031444204194007219326765802730624564074257060397341542093n,
59
+ 27667907157110496066452777015908813333407980290333709698851344970789663080149n
60
+ ],
61
+ [
62
+ 4491931056866994439025447213644536587424785196363427220456343191847333476930n,
63
+ 14743631939509747387607291926699970421064627808101543132147270746750887019919n,
64
+ 9448400033389617131295304336481030167723486090288313334230651810071857784477n
65
+ ],
66
+ [
67
+ 10525578725509990281643336361904863911009900817790387635342941550657754064843n,
68
+ 27437632000253211280915908546961303399777448677029255413769125486614773776695n,
69
+ 27566319851776897085443681456689352477426926500749993803132851225169606086988n
70
+ ]
71
+ ],
72
+ roundConstants: [
73
+ [
74
+ 21155079691556475130150866428468322463125560312786319980770950159250751855431n,
75
+ 16883442198399350202652499677723930673110172289234921799701652810789093522349n,
76
+ 17030687036425314703519085065002231920937594822150793091243263847382891822670n
77
+ ],
78
+ [
79
+ 25216718237129482752721276445368692059997901880654047883630276346421457427360n,
80
+ 9054264347380455706540423067244764093107767235485930776517975315876127782582n,
81
+ 26439087121446593160953570192891907825526260324480347638727375735543609856888n
82
+ ],
83
+ [
84
+ 15251000790817261169639394496851831733819930596125214313084182526610855787494n,
85
+ 10861916012597714684433535077722887124099023163589869801449218212493070551767n,
86
+ 18597653523270601187312528478986388028263730767495975370566527202946430104139n
87
+ ],
88
+ [
89
+ 15831416454198644276563319006805490049460322229057756462580029181847589006611n,
90
+ 15171856919255965617705854914448645702014039524159471542852132430360867202292n,
91
+ 15488495958879593647482715143904752785889816789652405888927117106448507625751n
92
+ ],
93
+ [
94
+ 19039802679983063488134304670998725949842655199289961967801223969839823940152n,
95
+ 4720101937153217036737330058775388037616286510783561045464678919473230044408n,
96
+ 10226318327254973427513859412126640040910264416718766418164893837597674300190n
97
+ ],
98
+ [
99
+ 20878756131129218406920515859235137275859844638301967889441262030146031838819n,
100
+ 7178475685651744631172532830973371642652029385893667810726019303466125436953n,
101
+ 1996970955918516145107673266490486752153434673064635795711751450164177339618n
102
+ ],
103
+ [
104
+ 15205545916434157464929420145756897321482314798910153575340430817222504672630n,
105
+ 25660296961552699573824264215804279051322332899472350724416657386062327210698n,
106
+ 13842611741937412200312851417353455040950878279339067816479233688850376089318n
107
+ ],
108
+ [
109
+ 1383799642177300432144836486981606294838630135265094078921115713566691160459n,
110
+ 1135532281155277588005319334542025976079676424839948500020664227027300010929n,
111
+ 4384117336930380014868572224801371377488688194169758696438185377724744869360n
112
+ ],
113
+ [
114
+ 21725577575710270071808882335900370909424604447083353471892004026180492193649n,
115
+ 676128913284806802699862508051022306366147359505124346651466289788974059668n,
116
+ 25186611339598418732666781049829183886812651492845008333418424746493100589207n
117
+ ],
118
+ [
119
+ 10402240124664763733060094237696964473609580414190944671778761753887884341073n,
120
+ 11918307118590866200687906627767559273324023585642003803337447146531313172441n,
121
+ 16895677254395661024186292503536662354181715337630376909778003268311296637301n
122
+ ],
123
+ [
124
+ 23818602699032741669874498456696325705498383130221297580399035778119213224810n,
125
+ 4285193711150023248690088154344086684336247475445482883105661485741762600154n,
126
+ 19133204443389422404056150665863951250222934590192266371578950735825153238612n
127
+ ],
128
+ [
129
+ 5515589673266504033533906836494002702866463791762187140099560583198974233395n,
130
+ 11830435563729472715615302060564876527985621376031612798386367965451821182352n,
131
+ 7510711479224915247011074129666445216001563200717943545636462819681638560128n
132
+ ],
133
+ [
134
+ 24694843201907722940091503626731830056550128225297370217610328578733387733444n,
135
+ 27361655066973784653563425664091383058914302579694897188019422193564924110528n,
136
+ 21606788186194534241166833954371013788633495786419718955480491478044413102713n
137
+ ],
138
+ [
139
+ 19934060063390905409309407607814787335159021816537006003398035237707924006757n,
140
+ 8495813630060004961768092461554180468161254914257386012937942498774724649553n,
141
+ 27524960680529762202005330464726908693944660961000958842417927307941561848461n
142
+ ],
143
+ [
144
+ 15178481650950399259757805400615635703086255035073919114667254549690862896985n,
145
+ 16164780354695672259791105197274509251141405713012804937107314962551600380870n,
146
+ 10529167793600778056702353412758954281652843049850979705476598375597148191979n
147
+ ],
148
+ [
149
+ 721141070179074082553302896292167103755384741083338957818644728290501449040n,
150
+ 22044408985956234023934090378372374883099115753118261312473550998188148912041n,
151
+ 27068254103241989852888872162525066148367014691482601147536314217249046186315n
152
+ ],
153
+ [
154
+ 3880429241956357176819112098792744584376727450211873998699580893624868748961n,
155
+ 17387097125522937623262508065966749501583017524609697127088211568136333655623n,
156
+ 6256814421247770895467770393029354017922744712896100913895513234184920631289n
157
+ ],
158
+ [
159
+ 2942627347777337187690939671601251987500285937340386328746818861972711408579n,
160
+ 24031654937764287280548628128490074801809101323243546313826173430897408945397n,
161
+ 14401457902976567713827506689641442844921449636054278900045849050301331732143n
162
+ ],
163
+ [
164
+ 20170632877385406450742199836933900257692624353889848352407590794211839130727n,
165
+ 24056496193857444725324410428861722338174099794084586764867109123681727290181n,
166
+ 11257913009612703357266904349759250619633397075667824800196659858304604714965n
167
+ ],
168
+ [
169
+ 22228158921984425749199071461510152694025757871561406897041788037116931009246n,
170
+ 9152163378317846541430311327336774331416267016980485920222768197583559318682n,
171
+ 13906695403538884432896105059360907560653506400343268230130536740148070289175n
172
+ ],
173
+ [
174
+ 7220714562509721437034241786731185291972496952091254931195414855962344025067n,
175
+ 27608867305903811397208862801981345878179337369367554478205559689592889691927n,
176
+ 13288465747219756218882697408422850918209170830515545272152965967042670763153n
177
+ ],
178
+ [
179
+ 8251343892709140154567051772980662609566359215743613773155065627504813327653n,
180
+ 22035238365102171608166944627493632660244312563934708756134297161332908879090n,
181
+ 13560937766273321037807329177749403409731524715067067740487246745322577571823n
182
+ ],
183
+ [
184
+ 21652518608959234550262559135285358020552897349934571164032339186996805408040n,
185
+ 22479086963324173427634460342145551255011746993910136574926173581069603086891n,
186
+ 13676501958531751140966255121288182631772843001727158043704693838707387130095n
187
+ ],
188
+ [
189
+ 5680310394102577950568930199056707827608275306479994663197187031893244826674n,
190
+ 25125360450906166639190392763071557410047335755341060350879819485506243289998n,
191
+ 22659254028501616785029594492374243581602744364859762239504348429834224676676n
192
+ ],
193
+ [
194
+ 23101411405087512171421838856759448177512679869882987631073569441496722536782n,
195
+ 24149774013240355952057123660656464942409328637280437515964899830988178868108n,
196
+ 5782097512368226173095183217893826020351125522160843964147125728530147423065n
197
+ ],
198
+ [
199
+ 13540762114500083869920564649399977644344247485313990448129838910231204868111n,
200
+ 20421637734328811337527547703833013277831804985438407401987624070721139913982n,
201
+ 7742664118615900772129122541139124149525273579639574972380600206383923500701n
202
+ ],
203
+ [
204
+ 1109643801053963021778418773196543643970146666329661268825691230294798976318n,
205
+ 16580663920817053843121063692728699890952505074386761779275436996241901223840n,
206
+ 14638514680222429058240285918830106208025229459346033470787111294847121792366n
207
+ ],
208
+ [
209
+ 17080385857812672649489217965285727739557573467014392822992021264701563205891n,
210
+ 26176268111736737558502775993925696791974738793095023824029827577569530708665n,
211
+ 4382756253392449071896813428140986330161215829425086284611219278674857536001n
212
+ ],
213
+ [
214
+ 13934033814940585315406666445960471293638427404971553891617533231178815348902n,
215
+ 27054912732979753314774418228399230433963143177662848084045249524271046173121n,
216
+ 28916070403698593376490976676534962592542013020010643734621202484860041243391n
217
+ ],
218
+ [
219
+ 24820015636966360150164458094894587765384135259446295278101998130934963922381n,
220
+ 7969535238488580655870884015145760954416088335296905520306227531221721881868n,
221
+ 7690547696740080985104189563436871930607055124031711216224219523236060212249n
222
+ ],
223
+ [
224
+ 9712576468091272384496248353414290908377825697488757134833205246106605867289n,
225
+ 12148698031438398980683630141370402088785182722473169207262735228500190477924n,
226
+ 14359657643133476969781351728574842164124292705609900285041476162075031948227n
227
+ ],
228
+ [
229
+ 23563839965372067275137992801035780013422228997724286060975035719045352435470n,
230
+ 4184634822776323233231956802962638484057536837393405750680645555481330909086n,
231
+ 16249511905185772125762038789038193114431085603985079639889795722501216492487n
232
+ ],
233
+ [
234
+ 11001863048692031559800673473526311616702863826063550559568315794438941516621n,
235
+ 4702354107983530219070178410740869035350641284373933887080161024348425080464n,
236
+ 23751680507533064238793742311430343910720206725883441625894258483004979501613n
237
+ ],
238
+ [
239
+ 28670526516158451470169873496541739545860177757793329093045522432279094518766n,
240
+ 3568312993091537758218792253361873752799472566055209125947589819564395417072n,
241
+ 1819755756343439646550062754332039103654718693246396323207323333948654200950n
242
+ ],
243
+ [
244
+ 5372129954699791301953948907349887257752247843844511069896766784624930478273n,
245
+ 17512156688034945920605615850550150476471921176481039715733979181538491476080n,
246
+ 25777105342317622165159064911913148785971147228777677435200128966844208883059n
247
+ ],
248
+ [
249
+ 25350392006158741749134238306326265756085455157012701586003300872637887157982n,
250
+ 20096724945283767296886159120145376967480397366990493578897615204296873954844n,
251
+ 8063283381910110762785892100479219642751540456251198202214433355775540036851n
252
+ ],
253
+ [
254
+ 4393613870462297385565277757207010824900723217720226130342463666351557475823n,
255
+ 9874972555132910032057499689351411450892722671352476280351715757363137891038n,
256
+ 23590926474329902351439438151596866311245682682435235170001347511997242904868n
257
+ ],
258
+ [
259
+ 17723373371137275859467518615551278584842947963894791032296774955869958211070n,
260
+ 2350345015303336966039836492267992193191479606566494799781846958620636621159n,
261
+ 27755207882790211140683010581856487965587066971982625511152297537534623405016n
262
+ ],
263
+ [
264
+ 6584607987789185408123601849106260907671314994378225066806060862710814193906n,
265
+ 609759108847171587253578490536519506369136135254150754300671591987320319770n,
266
+ 28435187585965602110074342250910608316032945187476441868666714022529803033083n
267
+ ],
268
+ [
269
+ 16016664911651770663938916450245705908287192964254704641717751103464322455303n,
270
+ 17551273293154696089066968171579395800922204266630874071186322718903959339163n,
271
+ 20414195497994754529479032467015716938594722029047207834858832838081413050198n
272
+ ],
273
+ [
274
+ 19773307918850685463180290966774465805537520595602496529624568184993487593855n,
275
+ 24598603838812162820757838364185126333280131847747737533989799467867231166980n,
276
+ 11040972566103463398651864390163813377135738019556270484707889323659789290225n
277
+ ],
278
+ [
279
+ 5189242080957784038860188184443287562488963023922086723850863987437818393811n,
280
+ 1435203288979376557721239239445613396009633263160237764653161500252258220144n,
281
+ 13066591163578079667911016543985168493088721636164837520689376346534152547210n
282
+ ],
283
+ [
284
+ 17345901407013599418148210465150865782628422047458024807490502489711252831342n,
285
+ 22139633362249671900128029132387275539363684188353969065288495002671733200348n,
286
+ 1061056418502836172283188490483332922126033656372467737207927075184389487061n
287
+ ],
288
+ [
289
+ 10241738906190857416046229928455551829189196941239601756375665129874835232299n,
290
+ 27808033332417845112292408673209999320983657696373938259351951416571545364415n,
291
+ 18820154989873674261497645724903918046694142479240549687085662625471577737140n
292
+ ],
293
+ [
294
+ 7983688435214640842673294735439196010654951226956101271763849527529940619307n,
295
+ 17067928657801807648925755556866676899145460770352731818062909643149568271566n,
296
+ 24472070825156236829515738091791182856425635433388202153358580534810244942762n
297
+ ],
298
+ [
299
+ 25752201169361795911258625731016717414310986450004737514595241038036936283227n,
300
+ 26041505376284666160132119888949817249574689146924196064963008712979256107535n,
301
+ 23977050489096115210391718599021827780049209314283111721864956071820102846008n
302
+ ],
303
+ [
304
+ 26678257097278788410676026718736087312816016749016738933942134600725962413805n,
305
+ 10480026985951498884090911619636977502506079971893083605102044931823547311729n,
306
+ 21126631300593007055117122830961273871167754554670317425822083333557535463396n
307
+ ],
308
+ [
309
+ 1564862894215434177641156287699106659379648851457681469848362532131406827573n,
310
+ 13247162472821152334486419054854847522301612781818744556576865965657773174584n,
311
+ 8673615954922496961704442777870253767001276027366984739283715623634850885984n
312
+ ],
313
+ [
314
+ 2794525076937490807476666942602262298677291735723129868457629508555429470085n,
315
+ 4656175953888995612264371467596648522808911819700660048695373348629527757049n,
316
+ 23221574237857660318443567292601561932489621919104226163978909845174616477329n
317
+ ],
318
+ [
319
+ 1878392460078272317716114458784636517603142716091316893054365153068227117145n,
320
+ 2370412714505757731457251173604396662292063533194555369091306667486647634097n,
321
+ 17409784861870189930766639925394191888667317762328427589153989811980152373276n
322
+ ],
323
+ [
324
+ 25869136641898166514111941708608048269584233242773814014385564101168774293194n,
325
+ 11361209360311194794795494027949518465383235799633128250259863567683341091323n,
326
+ 14913258820718821235077379851098720071902170702113538811112331615559409988569n
327
+ ],
328
+ [
329
+ 12957012022018304419868287033513141736995211906682903915897515954290678373899n,
330
+ 17128889547450684566010972445328859295804027707361763477802050112063630550300n,
331
+ 23329219085372232771288306767242735245018143857623151155581182779769305489903n
332
+ ],
333
+ [
334
+ 1607741027962933685476527275858938699728586794398382348454736018784568853937n,
335
+ 2611953825405141009309433982109911976923326848135736099261873796908057448476n,
336
+ 7372230383134982628913227482618052530364724821976589156840317933676130378411n
337
+ ],
338
+ [
339
+ 20203606758501212620842735123770014952499754751430660463060696990317556818571n,
340
+ 4678361398979174017885631008335559529633853759463947250620930343087749944307n,
341
+ 27176462634198471376002287271754121925750749676999036165457559387195124025594n
342
+ ],
343
+ [
344
+ 6361981813552614697928697527332318530502852015189048838072565811230204474643n,
345
+ 13815234633287489023151647353581705241145927054858922281829444557905946323248n,
346
+ 10888828634279127981352133512429657747610298502219125571406085952954136470354n
347
+ ]
348
+ ]
349
+ };
350
+
351
+ // dist/node/curve/curve.js
352
+ var projectiveZero = { x: 1n, y: 1n, z: 0n };
353
+ var Group = {
354
+ toProjective({ x, y }) {
355
+ return projectiveFromAffine({ x, y, infinity: false });
356
+ },
357
+ /**
358
+ * Convert a projective point to a non-zero affine point.
359
+ * Throws an error if the point is zero / infinity, i.e. if z === 0
360
+ */
361
+ fromProjective(point) {
362
+ let { x, y, infinity } = projectiveToAffine(point);
363
+ if (infinity)
364
+ throw Error("Group.fromProjective: point is infinity");
365
+ return { x, y };
366
+ }
367
+ };
368
+ var { p, a, b, twoadicRoot, twoadicity, oddFactor } = PallasConstants;
369
+ function mod(x, p2) {
370
+ x = x % p2;
371
+ if (x < 0)
372
+ return x + p2;
373
+ return x;
374
+ }
375
+ function projectiveDoubleA0(g, p2) {
376
+ if (g.z === 0n)
377
+ return g;
378
+ let X1 = g.x, Y1 = g.y, Z1 = g.z;
379
+ if (Y1 === 0n)
380
+ throw Error("projectiveDouble: unhandled case");
381
+ let A = mod(X1 * X1, p2);
382
+ let B = mod(Y1 * Y1, p2);
383
+ let C = mod(B * B, p2);
384
+ let D = mod(2n * ((X1 + B) * (X1 + B) - A - C), p2);
385
+ let E = 3n * A;
386
+ let F = mod(E * E, p2);
387
+ let X3 = mod(F - 2n * D, p2);
388
+ let Y3 = mod(E * (D - X3) - 8n * C, p2);
389
+ let Z3 = mod(2n * Y1 * Z1, p2);
390
+ return { x: X3, y: Y3, z: Z3 };
391
+ }
392
+ function projectiveDoubleAminus3(g, p2) {
393
+ if (g.z === 0n)
394
+ return g;
395
+ let X1 = g.x, Y1 = g.y, Z1 = g.z;
396
+ if (Y1 === 0n)
397
+ throw Error("projectiveDouble: unhandled case");
398
+ let delta = mod(Z1 * Z1, p2);
399
+ let gamma = mod(Y1 * Y1, p2);
400
+ let beta = mod(X1 * gamma, p2);
401
+ let alpha = mod((X1 - delta) * (X1 + delta), p2);
402
+ alpha = alpha + alpha + alpha;
403
+ let X3 = mod(alpha * alpha - 8n * beta, p2);
404
+ let Z3 = mod((Y1 + Z1) * (Y1 + Z1) - gamma - delta, p2);
405
+ let Y3 = mod(alpha * (4n * beta - X3) - 8n * gamma * gamma, p2);
406
+ return { x: X3, y: Y3, z: Z3 };
407
+ }
408
+ function projectiveDouble(g, p2, a2) {
409
+ if (a2 === 0n)
410
+ return projectiveDoubleA0(g, p2);
411
+ if (a2 + 3n === p2)
412
+ return projectiveDoubleAminus3(g, p2);
413
+ throw Error("Projective doubling is not implemented for general curve parameter a, only a = 0 and a = -3");
414
+ }
415
+ function projectiveNeg({ x, y, z }, p2) {
416
+ return { x, y: y === 0n ? 0n : p2 - y, z };
417
+ }
418
+ function projectiveAdd(g, h, p2, a2) {
419
+ if (g.z === 0n)
420
+ return h;
421
+ if (h.z === 0n)
422
+ return g;
423
+ let X1 = g.x, Y1 = g.y, Z1 = g.z, X2 = h.x, Y2 = h.y, Z2 = h.z;
424
+ let Z1Z1 = mod(Z1 * Z1, p2);
425
+ let Z2Z2 = mod(Z2 * Z2, p2);
426
+ let U1 = mod(X1 * Z2Z2, p2);
427
+ let U2 = mod(X2 * Z1Z1, p2);
428
+ let S1 = mod(Y1 * Z2 * Z2Z2, p2);
429
+ let S2 = mod(Y2 * Z1 * Z1Z1, p2);
430
+ let H = mod(U2 - U1, p2);
431
+ if (H === 0n) {
432
+ if (S1 === S2)
433
+ return projectiveDouble(g, p2, a2);
434
+ if (mod(S1 + S2, p2) === 0n)
435
+ return projectiveZero;
436
+ throw Error("projectiveAdd: invalid point");
437
+ }
438
+ let I = mod(H * H << 2n, p2);
439
+ let J = mod(H * I, p2);
440
+ let r = 2n * (S2 - S1);
441
+ let V = mod(U1 * I, p2);
442
+ let X3 = mod(r * r - J - 2n * V, p2);
443
+ let Y3 = mod(r * (V - X3) - 2n * S1 * J, p2);
444
+ let Z3 = mod(((Z1 + Z2) * (Z1 + Z2) - Z1Z1 - Z2Z2) * H, p2);
445
+ return { x: X3, y: Y3, z: Z3 };
446
+ }
447
+ function projectiveSub(g, h, p2, a2) {
448
+ return projectiveAdd(g, projectiveNeg(h, p2), p2, a2);
449
+ }
450
+ function getProjectiveDouble(p2, a2) {
451
+ if (a2 === 0n)
452
+ return projectiveDoubleA0;
453
+ if (a2 + 3n === p2)
454
+ return projectiveDoubleAminus3;
455
+ throw Error("Projective doubling is not implemented for general curve parameter a, only a = 0 and a = -3");
456
+ }
457
+ function bigIntToBits(x) {
458
+ if (x < 0n) {
459
+ throw Error(`bigIntToBits: negative numbers are not supported, got ${x}`);
460
+ }
461
+ let bits = [];
462
+ for (; x > 0n; x >>= 1n) {
463
+ let bit = !!(x & 1n);
464
+ bits.push(bit);
465
+ }
466
+ return bits;
467
+ }
468
+ function projectiveScale(g, x, p2, a2) {
469
+ let double = getProjectiveDouble(p2, a2);
470
+ let bits = typeof x === "bigint" ? bigIntToBits(x) : x;
471
+ let h = projectiveZero;
472
+ for (let bit of bits) {
473
+ if (bit)
474
+ h = projectiveAdd(h, g, p2, a2);
475
+ g = double(g, p2);
476
+ }
477
+ return h;
478
+ }
479
+ function sub(g, h) {
480
+ return projectiveSub(g, h, p, PallasConstants.a);
481
+ }
482
+ function scale(g, s) {
483
+ return projectiveScale(g, s, p, PallasConstants.a);
484
+ }
485
+ function projectiveFromAffine({ x, y, infinity }) {
486
+ if (infinity)
487
+ return projectiveZero;
488
+ return { x, y, z: 1n };
489
+ }
490
+ function projectiveToAffine(g) {
491
+ let z = g.z;
492
+ if (z === 0n) {
493
+ return { x: 0n, y: 0n, infinity: true };
494
+ } else if (z === 1n) {
495
+ return { x: g.x, y: g.y, infinity: false };
496
+ } else {
497
+ let zinv = inverse(z, p);
498
+ let zinv_squared = mod(zinv * zinv, p);
499
+ let x = mod(g.x * zinv_squared, p);
500
+ let y = mod(g.y * zinv * zinv_squared, p);
501
+ return { x, y, infinity: false };
502
+ }
503
+ }
504
+ function inverse(a2, p2) {
505
+ a2 = mod(a2, p2);
506
+ if (a2 === 0n)
507
+ return void 0;
508
+ let b2 = p2;
509
+ let x = 0n;
510
+ let y = 1n;
511
+ let u = 1n;
512
+ let v = 0n;
513
+ while (a2 !== 0n) {
514
+ let q = b2 / a2;
515
+ let r = mod(b2, a2);
516
+ let m = x - u * q;
517
+ let n = y - v * q;
518
+ b2 = a2;
519
+ a2 = r;
520
+ x = u;
521
+ y = v;
522
+ u = m;
523
+ v = n;
524
+ }
525
+ if (b2 !== 1n)
526
+ return void 0;
527
+ return mod(x, p2);
528
+ }
529
+ function isEven(x) {
530
+ return !(mod(x, p) & 1n);
531
+ }
532
+ function equal(x, y) {
533
+ let x_ = x >= 0n && x < p ? x : mod(x, p);
534
+ let y_ = y >= 0n && y < p ? y : mod(y, p);
535
+ return x_ === y_;
536
+ }
537
+ function power(a2, n) {
538
+ a2 = mod(a2, p);
539
+ let x = 1n;
540
+ for (; n > 0n; n >>= 1n) {
541
+ if (n & 1n)
542
+ x = mod(x * a2, p);
543
+ a2 = mod(a2 * a2, p);
544
+ }
545
+ return x;
546
+ }
547
+ function add(x, y) {
548
+ return mod(x + y, p);
549
+ }
550
+ function mul(x, y) {
551
+ return mod(x * y, p);
552
+ }
553
+ function dot(x, y) {
554
+ let z = 0n;
555
+ let n = x.length;
556
+ for (let i = 0; i < n; i++) {
557
+ z += x[i] * y[i];
558
+ }
559
+ return mod(z, p);
560
+ }
561
+ function sqrt(n_, p2, Q, c, M) {
562
+ const n = mod(n_, p2);
563
+ if (n === 0n)
564
+ return 0n;
565
+ let t = power(n, Q - 1n >> 1n);
566
+ let R = mod(t * n, p2);
567
+ t = mod(t * R, p2);
568
+ while (true) {
569
+ if (t === 1n)
570
+ return R;
571
+ let i = 0n;
572
+ let s = t;
573
+ while (s !== 1n) {
574
+ s = mod(s * s, p2);
575
+ i = i + 1n;
576
+ }
577
+ if (i === M)
578
+ return void 0;
579
+ let b2 = power(c, 1n << M - i - 1n);
580
+ M = i;
581
+ c = mod(b2 * b2, p2);
582
+ t = mod(t * c, p2);
583
+ R = mod(R * b2, p2);
584
+ }
585
+ }
586
+ function sqrt_internal(x) {
587
+ return sqrt(x, p, oddFactor, twoadicRoot, twoadicity);
588
+ }
589
+ function negate(x) {
590
+ return x === 0n ? 0n : mod(-x, p);
591
+ }
592
+ function publicKeyToGroup({ x, isOdd }) {
593
+ const ySquared = add(mul(x, mul(x, x)), b);
594
+ let y = sqrt_internal(ySquared);
595
+ if (y === void 0) {
596
+ throw Error("PublicKey.toGroup: not a valid group element");
597
+ }
598
+ if (isOdd !== !!(y & 1n))
599
+ y = negate(y);
600
+ return { x, y };
601
+ }
602
+
603
+ // dist/node/curve/hash.js
604
+ function poseidonInitialState() {
605
+ return Array(PoseidonConstants.stateSize).fill(0n);
606
+ }
607
+ function poseidonUpdate([...state], input) {
608
+ const { rate } = PoseidonConstants;
609
+ if (input.length === 0) {
610
+ permutation(state);
611
+ return state;
612
+ }
613
+ const n = Math.ceil(input.length / rate) * rate;
614
+ input = input.concat(Array(n - input.length).fill(0n));
615
+ for (let blockIndex = 0; blockIndex < n; blockIndex += rate) {
616
+ for (let i = 0; i < rate; i++) {
617
+ state[i] = add(state[i], input[blockIndex + i]);
618
+ }
619
+ permutation(state);
620
+ }
621
+ return state;
622
+ }
623
+ function hashMessage(message, publicKey, r) {
624
+ let { x, y } = publicKey;
625
+ let input = append(message, { fields: [x, y, r] });
626
+ return hashWithPrefix(packToFields(input));
627
+ }
628
+ function append(input1, input2) {
629
+ return {
630
+ fields: (input1.fields ?? []).concat(input2.fields ?? []),
631
+ packed: (input1.packed ?? []).concat(input2.packed ?? [])
632
+ };
633
+ }
634
+ function packToFields({ fields = [], packed = [] }) {
635
+ if (packed.length === 0)
636
+ return fields;
637
+ const packedBits = [];
638
+ let currentPackedField = 0n;
639
+ let currentSize = 0;
640
+ for (let [field, size] of packed) {
641
+ currentSize += size;
642
+ if (currentSize < 255) {
643
+ currentPackedField = currentPackedField * (1n << BigInt(size)) + field;
644
+ } else {
645
+ packedBits.push(currentPackedField);
646
+ currentSize = size;
647
+ currentPackedField = field;
648
+ }
649
+ }
650
+ packedBits.push(currentPackedField);
651
+ return fields.concat(packedBits);
652
+ }
653
+ var prefix = 240717916736854602989207148466022993262069182275n;
654
+ function salt() {
655
+ return poseidonUpdate(poseidonInitialState(), [prefix]);
656
+ }
657
+ function hashWithPrefix(input) {
658
+ let init = salt();
659
+ return poseidonUpdate(init, input)[0];
660
+ }
661
+ function permutation(state) {
662
+ const { hasInitialRoundConstant, stateSize, roundConstants, fullRounds, power: power_, mds } = PoseidonConstants;
663
+ let offset = 0;
664
+ if (hasInitialRoundConstant) {
665
+ for (let i = 0; i < stateSize; i++) {
666
+ state[i] = add(state[i], roundConstants[0][i]);
667
+ }
668
+ offset = 1;
669
+ }
670
+ for (let round = 0; round < fullRounds; round++) {
671
+ for (let i = 0; i < stateSize; i++) {
672
+ state[i] = power(state[i], power_);
673
+ }
674
+ let oldState = [...state];
675
+ for (let i = 0; i < stateSize; i++) {
676
+ state[i] = dot(mds[i], oldState);
677
+ state[i] = add(state[i], roundConstants[round + offset][i]);
678
+ }
679
+ }
680
+ }
681
+
682
+ // dist/node/curve/verify.js
683
+ function verify(signature, message, publicKey) {
684
+ const { r, s } = signature;
685
+ const pk = publicKeyToGroup(publicKey);
686
+ const e = hashMessage(message, pk, r);
687
+ const { one } = PallasConstants;
688
+ const R = sub(scale(one, s), scale(Group.toProjective(pk), e));
689
+ try {
690
+ const { x: rx, y: ry } = Group.fromProjective(R);
691
+ return isEven(ry) && equal(rx, r);
692
+ } catch {
693
+ return false;
694
+ }
695
+ }
696
+
697
+ // dist/node/poseidon.js
698
+ function poseidon(message) {
699
+ return poseidonUpdate(poseidonInitialState(), message)[0];
700
+ }
701
+
702
+ // dist/node/signature.js
703
+ function verifySignature(params) {
704
+ const { data, signature, publicKey } = params;
705
+ return verify(signature, { fields: data }, publicKey);
706
+ }
707
+ // Annotate the CommonJS export names for ESM import in node:
708
+ 0 && (module.exports = {
709
+ poseidon,
710
+ verifySignature
711
+ });