@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,323 @@
1
+ export { PallasConstants, PoseidonConstants };
2
+ const PallasConstants = {
3
+ name: "Pallas",
4
+ modulus: 28948022309329048855892746252171976963363056481941560715954676764349967630337n,
5
+ order: 28948022309329048855892746252171976963363056481941647379679742748393362948097n,
6
+ cofactor: 1n,
7
+ zero: { x: 1n, y: 1n, z: 0n },
8
+ one: {
9
+ x: 1n,
10
+ y: 12418654782883325593414442427049395787963493412651469444558597405572177144507n,
11
+ z: 1n,
12
+ },
13
+ hasEndomorphism: true,
14
+ a: 0n,
15
+ b: 5n,
16
+ hasCofactor: false,
17
+ p: 28948022309329048855892746252171976963363056481941560715954676764349967630337n,
18
+ twoadicRoot: 19814229590243028906643993866117402072516588566294623396325693409366934201135n,
19
+ twoadicity: 32n,
20
+ oddFactor: 6739986666787659948666753771754907668419893943225396963757154709741n,
21
+ };
22
+ const PoseidonConstants = {
23
+ stateSize: 3,
24
+ rate: 2,
25
+ fullRounds: 55,
26
+ power: 7n,
27
+ hasInitialRoundConstant: false,
28
+ mds: [
29
+ [
30
+ 12035446894107573964500871153637039653510326950134440362813193268448863222019n,
31
+ 25461374787957152039031444204194007219326765802730624564074257060397341542093n,
32
+ 27667907157110496066452777015908813333407980290333709698851344970789663080149n,
33
+ ],
34
+ [
35
+ 4491931056866994439025447213644536587424785196363427220456343191847333476930n,
36
+ 14743631939509747387607291926699970421064627808101543132147270746750887019919n,
37
+ 9448400033389617131295304336481030167723486090288313334230651810071857784477n,
38
+ ],
39
+ [
40
+ 10525578725509990281643336361904863911009900817790387635342941550657754064843n,
41
+ 27437632000253211280915908546961303399777448677029255413769125486614773776695n,
42
+ 27566319851776897085443681456689352477426926500749993803132851225169606086988n,
43
+ ],
44
+ ],
45
+ roundConstants: [
46
+ [
47
+ 21155079691556475130150866428468322463125560312786319980770950159250751855431n,
48
+ 16883442198399350202652499677723930673110172289234921799701652810789093522349n,
49
+ 17030687036425314703519085065002231920937594822150793091243263847382891822670n,
50
+ ],
51
+ [
52
+ 25216718237129482752721276445368692059997901880654047883630276346421457427360n,
53
+ 9054264347380455706540423067244764093107767235485930776517975315876127782582n,
54
+ 26439087121446593160953570192891907825526260324480347638727375735543609856888n,
55
+ ],
56
+ [
57
+ 15251000790817261169639394496851831733819930596125214313084182526610855787494n,
58
+ 10861916012597714684433535077722887124099023163589869801449218212493070551767n,
59
+ 18597653523270601187312528478986388028263730767495975370566527202946430104139n,
60
+ ],
61
+ [
62
+ 15831416454198644276563319006805490049460322229057756462580029181847589006611n,
63
+ 15171856919255965617705854914448645702014039524159471542852132430360867202292n,
64
+ 15488495958879593647482715143904752785889816789652405888927117106448507625751n,
65
+ ],
66
+ [
67
+ 19039802679983063488134304670998725949842655199289961967801223969839823940152n,
68
+ 4720101937153217036737330058775388037616286510783561045464678919473230044408n,
69
+ 10226318327254973427513859412126640040910264416718766418164893837597674300190n,
70
+ ],
71
+ [
72
+ 20878756131129218406920515859235137275859844638301967889441262030146031838819n,
73
+ 7178475685651744631172532830973371642652029385893667810726019303466125436953n,
74
+ 1996970955918516145107673266490486752153434673064635795711751450164177339618n,
75
+ ],
76
+ [
77
+ 15205545916434157464929420145756897321482314798910153575340430817222504672630n,
78
+ 25660296961552699573824264215804279051322332899472350724416657386062327210698n,
79
+ 13842611741937412200312851417353455040950878279339067816479233688850376089318n,
80
+ ],
81
+ [
82
+ 1383799642177300432144836486981606294838630135265094078921115713566691160459n,
83
+ 1135532281155277588005319334542025976079676424839948500020664227027300010929n,
84
+ 4384117336930380014868572224801371377488688194169758696438185377724744869360n,
85
+ ],
86
+ [
87
+ 21725577575710270071808882335900370909424604447083353471892004026180492193649n,
88
+ 676128913284806802699862508051022306366147359505124346651466289788974059668n,
89
+ 25186611339598418732666781049829183886812651492845008333418424746493100589207n,
90
+ ],
91
+ [
92
+ 10402240124664763733060094237696964473609580414190944671778761753887884341073n,
93
+ 11918307118590866200687906627767559273324023585642003803337447146531313172441n,
94
+ 16895677254395661024186292503536662354181715337630376909778003268311296637301n,
95
+ ],
96
+ [
97
+ 23818602699032741669874498456696325705498383130221297580399035778119213224810n,
98
+ 4285193711150023248690088154344086684336247475445482883105661485741762600154n,
99
+ 19133204443389422404056150665863951250222934590192266371578950735825153238612n,
100
+ ],
101
+ [
102
+ 5515589673266504033533906836494002702866463791762187140099560583198974233395n,
103
+ 11830435563729472715615302060564876527985621376031612798386367965451821182352n,
104
+ 7510711479224915247011074129666445216001563200717943545636462819681638560128n,
105
+ ],
106
+ [
107
+ 24694843201907722940091503626731830056550128225297370217610328578733387733444n,
108
+ 27361655066973784653563425664091383058914302579694897188019422193564924110528n,
109
+ 21606788186194534241166833954371013788633495786419718955480491478044413102713n,
110
+ ],
111
+ [
112
+ 19934060063390905409309407607814787335159021816537006003398035237707924006757n,
113
+ 8495813630060004961768092461554180468161254914257386012937942498774724649553n,
114
+ 27524960680529762202005330464726908693944660961000958842417927307941561848461n,
115
+ ],
116
+ [
117
+ 15178481650950399259757805400615635703086255035073919114667254549690862896985n,
118
+ 16164780354695672259791105197274509251141405713012804937107314962551600380870n,
119
+ 10529167793600778056702353412758954281652843049850979705476598375597148191979n,
120
+ ],
121
+ [
122
+ 721141070179074082553302896292167103755384741083338957818644728290501449040n,
123
+ 22044408985956234023934090378372374883099115753118261312473550998188148912041n,
124
+ 27068254103241989852888872162525066148367014691482601147536314217249046186315n,
125
+ ],
126
+ [
127
+ 3880429241956357176819112098792744584376727450211873998699580893624868748961n,
128
+ 17387097125522937623262508065966749501583017524609697127088211568136333655623n,
129
+ 6256814421247770895467770393029354017922744712896100913895513234184920631289n,
130
+ ],
131
+ [
132
+ 2942627347777337187690939671601251987500285937340386328746818861972711408579n,
133
+ 24031654937764287280548628128490074801809101323243546313826173430897408945397n,
134
+ 14401457902976567713827506689641442844921449636054278900045849050301331732143n,
135
+ ],
136
+ [
137
+ 20170632877385406450742199836933900257692624353889848352407590794211839130727n,
138
+ 24056496193857444725324410428861722338174099794084586764867109123681727290181n,
139
+ 11257913009612703357266904349759250619633397075667824800196659858304604714965n,
140
+ ],
141
+ [
142
+ 22228158921984425749199071461510152694025757871561406897041788037116931009246n,
143
+ 9152163378317846541430311327336774331416267016980485920222768197583559318682n,
144
+ 13906695403538884432896105059360907560653506400343268230130536740148070289175n,
145
+ ],
146
+ [
147
+ 7220714562509721437034241786731185291972496952091254931195414855962344025067n,
148
+ 27608867305903811397208862801981345878179337369367554478205559689592889691927n,
149
+ 13288465747219756218882697408422850918209170830515545272152965967042670763153n,
150
+ ],
151
+ [
152
+ 8251343892709140154567051772980662609566359215743613773155065627504813327653n,
153
+ 22035238365102171608166944627493632660244312563934708756134297161332908879090n,
154
+ 13560937766273321037807329177749403409731524715067067740487246745322577571823n,
155
+ ],
156
+ [
157
+ 21652518608959234550262559135285358020552897349934571164032339186996805408040n,
158
+ 22479086963324173427634460342145551255011746993910136574926173581069603086891n,
159
+ 13676501958531751140966255121288182631772843001727158043704693838707387130095n,
160
+ ],
161
+ [
162
+ 5680310394102577950568930199056707827608275306479994663197187031893244826674n,
163
+ 25125360450906166639190392763071557410047335755341060350879819485506243289998n,
164
+ 22659254028501616785029594492374243581602744364859762239504348429834224676676n,
165
+ ],
166
+ [
167
+ 23101411405087512171421838856759448177512679869882987631073569441496722536782n,
168
+ 24149774013240355952057123660656464942409328637280437515964899830988178868108n,
169
+ 5782097512368226173095183217893826020351125522160843964147125728530147423065n,
170
+ ],
171
+ [
172
+ 13540762114500083869920564649399977644344247485313990448129838910231204868111n,
173
+ 20421637734328811337527547703833013277831804985438407401987624070721139913982n,
174
+ 7742664118615900772129122541139124149525273579639574972380600206383923500701n,
175
+ ],
176
+ [
177
+ 1109643801053963021778418773196543643970146666329661268825691230294798976318n,
178
+ 16580663920817053843121063692728699890952505074386761779275436996241901223840n,
179
+ 14638514680222429058240285918830106208025229459346033470787111294847121792366n,
180
+ ],
181
+ [
182
+ 17080385857812672649489217965285727739557573467014392822992021264701563205891n,
183
+ 26176268111736737558502775993925696791974738793095023824029827577569530708665n,
184
+ 4382756253392449071896813428140986330161215829425086284611219278674857536001n,
185
+ ],
186
+ [
187
+ 13934033814940585315406666445960471293638427404971553891617533231178815348902n,
188
+ 27054912732979753314774418228399230433963143177662848084045249524271046173121n,
189
+ 28916070403698593376490976676534962592542013020010643734621202484860041243391n,
190
+ ],
191
+ [
192
+ 24820015636966360150164458094894587765384135259446295278101998130934963922381n,
193
+ 7969535238488580655870884015145760954416088335296905520306227531221721881868n,
194
+ 7690547696740080985104189563436871930607055124031711216224219523236060212249n,
195
+ ],
196
+ [
197
+ 9712576468091272384496248353414290908377825697488757134833205246106605867289n,
198
+ 12148698031438398980683630141370402088785182722473169207262735228500190477924n,
199
+ 14359657643133476969781351728574842164124292705609900285041476162075031948227n,
200
+ ],
201
+ [
202
+ 23563839965372067275137992801035780013422228997724286060975035719045352435470n,
203
+ 4184634822776323233231956802962638484057536837393405750680645555481330909086n,
204
+ 16249511905185772125762038789038193114431085603985079639889795722501216492487n,
205
+ ],
206
+ [
207
+ 11001863048692031559800673473526311616702863826063550559568315794438941516621n,
208
+ 4702354107983530219070178410740869035350641284373933887080161024348425080464n,
209
+ 23751680507533064238793742311430343910720206725883441625894258483004979501613n,
210
+ ],
211
+ [
212
+ 28670526516158451470169873496541739545860177757793329093045522432279094518766n,
213
+ 3568312993091537758218792253361873752799472566055209125947589819564395417072n,
214
+ 1819755756343439646550062754332039103654718693246396323207323333948654200950n,
215
+ ],
216
+ [
217
+ 5372129954699791301953948907349887257752247843844511069896766784624930478273n,
218
+ 17512156688034945920605615850550150476471921176481039715733979181538491476080n,
219
+ 25777105342317622165159064911913148785971147228777677435200128966844208883059n,
220
+ ],
221
+ [
222
+ 25350392006158741749134238306326265756085455157012701586003300872637887157982n,
223
+ 20096724945283767296886159120145376967480397366990493578897615204296873954844n,
224
+ 8063283381910110762785892100479219642751540456251198202214433355775540036851n,
225
+ ],
226
+ [
227
+ 4393613870462297385565277757207010824900723217720226130342463666351557475823n,
228
+ 9874972555132910032057499689351411450892722671352476280351715757363137891038n,
229
+ 23590926474329902351439438151596866311245682682435235170001347511997242904868n,
230
+ ],
231
+ [
232
+ 17723373371137275859467518615551278584842947963894791032296774955869958211070n,
233
+ 2350345015303336966039836492267992193191479606566494799781846958620636621159n,
234
+ 27755207882790211140683010581856487965587066971982625511152297537534623405016n,
235
+ ],
236
+ [
237
+ 6584607987789185408123601849106260907671314994378225066806060862710814193906n,
238
+ 609759108847171587253578490536519506369136135254150754300671591987320319770n,
239
+ 28435187585965602110074342250910608316032945187476441868666714022529803033083n,
240
+ ],
241
+ [
242
+ 16016664911651770663938916450245705908287192964254704641717751103464322455303n,
243
+ 17551273293154696089066968171579395800922204266630874071186322718903959339163n,
244
+ 20414195497994754529479032467015716938594722029047207834858832838081413050198n,
245
+ ],
246
+ [
247
+ 19773307918850685463180290966774465805537520595602496529624568184993487593855n,
248
+ 24598603838812162820757838364185126333280131847747737533989799467867231166980n,
249
+ 11040972566103463398651864390163813377135738019556270484707889323659789290225n,
250
+ ],
251
+ [
252
+ 5189242080957784038860188184443287562488963023922086723850863987437818393811n,
253
+ 1435203288979376557721239239445613396009633263160237764653161500252258220144n,
254
+ 13066591163578079667911016543985168493088721636164837520689376346534152547210n,
255
+ ],
256
+ [
257
+ 17345901407013599418148210465150865782628422047458024807490502489711252831342n,
258
+ 22139633362249671900128029132387275539363684188353969065288495002671733200348n,
259
+ 1061056418502836172283188490483332922126033656372467737207927075184389487061n,
260
+ ],
261
+ [
262
+ 10241738906190857416046229928455551829189196941239601756375665129874835232299n,
263
+ 27808033332417845112292408673209999320983657696373938259351951416571545364415n,
264
+ 18820154989873674261497645724903918046694142479240549687085662625471577737140n,
265
+ ],
266
+ [
267
+ 7983688435214640842673294735439196010654951226956101271763849527529940619307n,
268
+ 17067928657801807648925755556866676899145460770352731818062909643149568271566n,
269
+ 24472070825156236829515738091791182856425635433388202153358580534810244942762n,
270
+ ],
271
+ [
272
+ 25752201169361795911258625731016717414310986450004737514595241038036936283227n,
273
+ 26041505376284666160132119888949817249574689146924196064963008712979256107535n,
274
+ 23977050489096115210391718599021827780049209314283111721864956071820102846008n,
275
+ ],
276
+ [
277
+ 26678257097278788410676026718736087312816016749016738933942134600725962413805n,
278
+ 10480026985951498884090911619636977502506079971893083605102044931823547311729n,
279
+ 21126631300593007055117122830961273871167754554670317425822083333557535463396n,
280
+ ],
281
+ [
282
+ 1564862894215434177641156287699106659379648851457681469848362532131406827573n,
283
+ 13247162472821152334486419054854847522301612781818744556576865965657773174584n,
284
+ 8673615954922496961704442777870253767001276027366984739283715623634850885984n,
285
+ ],
286
+ [
287
+ 2794525076937490807476666942602262298677291735723129868457629508555429470085n,
288
+ 4656175953888995612264371467596648522808911819700660048695373348629527757049n,
289
+ 23221574237857660318443567292601561932489621919104226163978909845174616477329n,
290
+ ],
291
+ [
292
+ 1878392460078272317716114458784636517603142716091316893054365153068227117145n,
293
+ 2370412714505757731457251173604396662292063533194555369091306667486647634097n,
294
+ 17409784861870189930766639925394191888667317762328427589153989811980152373276n,
295
+ ],
296
+ [
297
+ 25869136641898166514111941708608048269584233242773814014385564101168774293194n,
298
+ 11361209360311194794795494027949518465383235799633128250259863567683341091323n,
299
+ 14913258820718821235077379851098720071902170702113538811112331615559409988569n,
300
+ ],
301
+ [
302
+ 12957012022018304419868287033513141736995211906682903915897515954290678373899n,
303
+ 17128889547450684566010972445328859295804027707361763477802050112063630550300n,
304
+ 23329219085372232771288306767242735245018143857623151155581182779769305489903n,
305
+ ],
306
+ [
307
+ 1607741027962933685476527275858938699728586794398382348454736018784568853937n,
308
+ 2611953825405141009309433982109911976923326848135736099261873796908057448476n,
309
+ 7372230383134982628913227482618052530364724821976589156840317933676130378411n,
310
+ ],
311
+ [
312
+ 20203606758501212620842735123770014952499754751430660463060696990317556818571n,
313
+ 4678361398979174017885631008335559529633853759463947250620930343087749944307n,
314
+ 27176462634198471376002287271754121925750749676999036165457559387195124025594n,
315
+ ],
316
+ [
317
+ 6361981813552614697928697527332318530502852015189048838072565811230204474643n,
318
+ 13815234633287489023151647353581705241145927054858922281829444557905946323248n,
319
+ 10888828634279127981352133512429657747610298502219125571406085952954136470354n,
320
+ ],
321
+ ],
322
+ };
323
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/curve/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,CAAC;AAE9C,MAAM,eAAe,GAAG;IACtB,IAAI,EAAE,QAAQ;IACd,OAAO,EACL,8EAA8E;IAChF,KAAK,EACH,8EAA8E;IAChF,QAAQ,EAAE,EAAE;IACZ,IAAI,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE;IAC7B,GAAG,EAAE;QACH,CAAC,EAAE,EAAE;QACL,CAAC,EAAE,8EAA8E;QACjF,CAAC,EAAE,EAAE;KACN;IACD,eAAe,EAAE,IAAI;IACrB,CAAC,EAAE,EAAE;IACL,CAAC,EAAE,EAAE;IACL,WAAW,EAAE,KAAK;IAClB,CAAC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AA8E;YAC9E,6EAA6E;SAC9E;QACD;YACE,6EAA6E;YAC7E,6EAA6E;YAC7E,8EAA8E;SAC/E;QACD;YACE,8EAA8E;YAC9E,6EAA6E;YAC7E,8EAA8E;SAC/E;QACD;YACE,6EAA6E;YAC7E,4EAA4E;YAC5E,8EAA8E;SAC/E;QACD;YACE,8EAA8E;YAC9E,8EAA8E;YAC9E,8EAA8E;SAC/E;QACD;YACE,8EAA8E;YAC9E,8EAA8E;YAC9E,8EAA8E;SAC/E;QACD;YACE,6EAA6E;YAC7E,6EAA6E;YAC7E,8EAA8E;SAC/E;QACD;YACE,8EAA8E;YAC9E,8EAA8E;YAC9E,6EAA6E;SAC9E;QACD;YACE,8EAA8E;YAC9E,8EAA8E;YAC9E,8EAA8E;SAC/E;QACD;YACE,6EAA6E;YAC7E,8EAA8E;YAC9E,8EAA8E;SAC/E;QACD;YACE,8EAA8E;YAC9E,8EAA8E;YAC9E,8EAA8E;SAC/E;QACD;YACE,8EAA8E;YAC9E,8EAA8E;YAC9E,8EAA8E;SAC/E;QACD;YACE,6EAA6E;YAC7E,8EAA8E;YAC9E,6EAA6E;SAC9E;QACD;YACE,6EAA6E;YAC7E,6EAA6E;YAC7E,8EAA8E;SAC/E;QACD;YACE,6EAA6E;YAC7E,6EAA6E;YAC7E,8EAA8E;SAC/E;QACD;YACE,8EAA8E;YAC9E,8EAA8E;YAC9E,8EAA8E;SAC/E;QACD;YACE,8EAA8E;YAC9E,8EAA8E;YAC9E,8EAA8E;SAC/E;QACD;YACE,6EAA6E;YAC7E,6EAA6E;YAC7E,6EAA6E;SAC9E;QACD;YACE,8EAA8E;YAC9E,6EAA6E;YAC7E,8EAA8E;SAC/E;QACD;YACE,6EAA6E;YAC7E,8EAA8E;YAC9E,8EAA8E;SAC/E;KACF;CACF,CAAC"}
@@ -0,0 +1,50 @@
1
+ export { Field, Bool, Scalar, PublicKey, Signature, Group, publicKeyToGroup, scale, sub, isEven, equal, power, add, mul, sqrt, dot, };
2
+ type Field = bigint;
3
+ type Bool = boolean;
4
+ type Group = {
5
+ x: Field;
6
+ y: Field;
7
+ };
8
+ type PublicKey = {
9
+ x: Field;
10
+ isOdd: Bool;
11
+ };
12
+ type Scalar = bigint;
13
+ type Signature = {
14
+ r: Field;
15
+ s: Scalar;
16
+ };
17
+ type GroupProjective = {
18
+ x: bigint;
19
+ y: bigint;
20
+ z: bigint;
21
+ };
22
+ /**
23
+ * A non-zero point on the Pallas curve in affine form { x, y }
24
+ */
25
+ declare const Group: {
26
+ toProjective({ x, y }: Group): GroupProjective;
27
+ /**
28
+ * Convert a projective point to a non-zero affine point.
29
+ * Throws an error if the point is zero / infinity, i.e. if z === 0
30
+ */
31
+ fromProjective(point: GroupProjective): Group;
32
+ };
33
+ declare function sub(g: GroupProjective, h: GroupProjective): {
34
+ x: bigint;
35
+ y: bigint;
36
+ z: bigint;
37
+ };
38
+ declare function scale(g: GroupProjective, s: bigint): {
39
+ x: bigint;
40
+ y: bigint;
41
+ z: bigint;
42
+ };
43
+ declare function isEven(x: bigint): boolean;
44
+ declare function equal(x: bigint, y: bigint): boolean;
45
+ declare function power(a: bigint, n: bigint): bigint;
46
+ declare function add(x: bigint, y: bigint): bigint;
47
+ declare function mul(x: bigint, y: bigint): bigint;
48
+ declare function dot(x: bigint[], y: bigint[]): bigint;
49
+ declare function sqrt(n_: bigint, p: bigint, Q: bigint, c: bigint, M: bigint): bigint | undefined;
50
+ declare function publicKeyToGroup({ x, isOdd }: PublicKey): Group;
@@ -0,0 +1,307 @@
1
+ import { PallasConstants } from "./constants.js";
2
+ export { Group, publicKeyToGroup, scale, sub, isEven, equal, power, add, mul, sqrt, dot, };
3
+ const projectiveZero = { x: 1n, y: 1n, z: 0n };
4
+ /**
5
+ * A non-zero point on the Pallas curve in affine form { x, y }
6
+ */
7
+ const Group = {
8
+ toProjective({ x, y }) {
9
+ return projectiveFromAffine({ x, y, infinity: false });
10
+ },
11
+ /**
12
+ * Convert a projective point to a non-zero affine point.
13
+ * Throws an error if the point is zero / infinity, i.e. if z === 0
14
+ */
15
+ fromProjective(point) {
16
+ let { x, y, infinity } = projectiveToAffine(point);
17
+ if (infinity)
18
+ throw Error("Group.fromProjective: point is infinity");
19
+ return { x, y };
20
+ },
21
+ };
22
+ const { p, a, b, twoadicRoot, twoadicity, oddFactor } = PallasConstants;
23
+ function mod(x, p) {
24
+ x = x % p;
25
+ if (x < 0)
26
+ return x + p;
27
+ return x;
28
+ }
29
+ function projectiveDoubleA0(g, p) {
30
+ if (g.z === 0n)
31
+ return g;
32
+ let X1 = g.x, Y1 = g.y, Z1 = g.z;
33
+ if (Y1 === 0n)
34
+ throw Error("projectiveDouble: unhandled case");
35
+ // http://www.hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-0.html#doubling-dbl-2009-l
36
+ // A = X1^2
37
+ let A = mod(X1 * X1, p);
38
+ // B = Y1^2
39
+ let B = mod(Y1 * Y1, p);
40
+ // C = B^2
41
+ let C = mod(B * B, p);
42
+ // D = 2*((X1+B)^2-A-C)
43
+ let D = mod(2n * ((X1 + B) * (X1 + B) - A - C), p);
44
+ // E = 3*A
45
+ let E = 3n * A;
46
+ // F = E^2
47
+ let F = mod(E * E, p);
48
+ // X3 = F-2*D
49
+ let X3 = mod(F - 2n * D, p);
50
+ // Y3 = E*(D-X3)-8*C
51
+ let Y3 = mod(E * (D - X3) - 8n * C, p);
52
+ // Z3 = 2*Y1*Z1
53
+ let Z3 = mod(2n * Y1 * Z1, p);
54
+ return { x: X3, y: Y3, z: Z3 };
55
+ }
56
+ function projectiveDoubleAminus3(g, p) {
57
+ if (g.z === 0n)
58
+ return g;
59
+ let X1 = g.x, Y1 = g.y, Z1 = g.z;
60
+ if (Y1 === 0n)
61
+ throw Error("projectiveDouble: unhandled case");
62
+ // http://www.hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-3.html#doubling-dbl-2001-b
63
+ // delta = Z1^2
64
+ let delta = mod(Z1 * Z1, p);
65
+ // gamma = Y1^2
66
+ let gamma = mod(Y1 * Y1, p);
67
+ // beta = X1*gamma
68
+ let beta = mod(X1 * gamma, p);
69
+ // alpha = 3*(X1-delta)*(X1+delta)
70
+ let alpha = mod((X1 - delta) * (X1 + delta), p);
71
+ alpha = alpha + alpha + alpha;
72
+ // X3 = alpha^2-8*beta
73
+ let X3 = mod(alpha * alpha - 8n * beta, p);
74
+ // Z3 = (Y1+Z1)^2-gamma-delta
75
+ let Z3 = mod((Y1 + Z1) * (Y1 + Z1) - gamma - delta, p);
76
+ // Y3 = alpha*(4*beta-X3)-8*gamma^2
77
+ let Y3 = mod(alpha * (4n * beta - X3) - 8n * gamma * gamma, p);
78
+ return { x: X3, y: Y3, z: Z3 };
79
+ }
80
+ function projectiveDouble(g, p, a) {
81
+ if (a === 0n)
82
+ return projectiveDoubleA0(g, p);
83
+ if (a + 3n === p)
84
+ return projectiveDoubleAminus3(g, p);
85
+ throw Error("Projective doubling is not implemented for general curve parameter a, only a = 0 and a = -3");
86
+ }
87
+ function projectiveNeg({ x, y, z }, p) {
88
+ return { x, y: y === 0n ? 0n : p - y, z };
89
+ }
90
+ function projectiveAdd(g, h, p, a) {
91
+ if (g.z === 0n)
92
+ return h;
93
+ if (h.z === 0n)
94
+ return g;
95
+ let X1 = g.x, Y1 = g.y, Z1 = g.z, X2 = h.x, Y2 = h.y, Z2 = h.z;
96
+ // http://www.hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-0.html#addition-add-2007-bl
97
+ // Z1Z1 = Z1^2
98
+ let Z1Z1 = mod(Z1 * Z1, p);
99
+ // Z2Z2 = Z2^2
100
+ let Z2Z2 = mod(Z2 * Z2, p);
101
+ // U1 = X1*Z2Z2
102
+ let U1 = mod(X1 * Z2Z2, p);
103
+ // U2 = X2*Z1Z1
104
+ let U2 = mod(X2 * Z1Z1, p);
105
+ // S1 = Y1*Z2*Z2Z2
106
+ let S1 = mod(Y1 * Z2 * Z2Z2, p);
107
+ // S2 = Y2*Z1*Z1Z1
108
+ let S2 = mod(Y2 * Z1 * Z1Z1, p);
109
+ // H = U2-U1
110
+ let H = mod(U2 - U1, p);
111
+ // H = 0 <==> x1 = X1/Z1^2 = X2/Z2^2 = x2 <==> degenerate case (Z3 would become 0)
112
+ if (H === 0n) {
113
+ // if S1 = S2 <==> y1 = y2, the points are equal, so we double instead
114
+ if (S1 === S2)
115
+ return projectiveDouble(g, p, a);
116
+ // if S1 = -S2, the points are inverse, so return zero
117
+ if (mod(S1 + S2, p) === 0n)
118
+ return projectiveZero;
119
+ throw Error("projectiveAdd: invalid point");
120
+ }
121
+ // I = (2*H)^2
122
+ let I = mod((H * H) << 2n, p);
123
+ // J = H*I
124
+ let J = mod(H * I, p);
125
+ // r = 2*(S2-S1)
126
+ let r = 2n * (S2 - S1);
127
+ // V = U1*I
128
+ let V = mod(U1 * I, p);
129
+ // X3 = r^2-J-2*V
130
+ let X3 = mod(r * r - J - 2n * V, p);
131
+ // Y3 = r*(V-X3)-2*S1*J
132
+ let Y3 = mod(r * (V - X3) - 2n * S1 * J, p);
133
+ // Z3 = ((Z1+Z2)^2-Z1Z1-Z2Z2)*H
134
+ let Z3 = mod(((Z1 + Z2) * (Z1 + Z2) - Z1Z1 - Z2Z2) * H, p);
135
+ return { x: X3, y: Y3, z: Z3 };
136
+ }
137
+ function projectiveSub(g, h, p, a) {
138
+ return projectiveAdd(g, projectiveNeg(h, p), p, a);
139
+ }
140
+ function getProjectiveDouble(p, a) {
141
+ if (a === 0n)
142
+ return projectiveDoubleA0;
143
+ if (a + 3n === p)
144
+ return projectiveDoubleAminus3;
145
+ throw Error("Projective doubling is not implemented for general curve parameter a, only a = 0 and a = -3");
146
+ }
147
+ function bigIntToBits(x) {
148
+ if (x < 0n) {
149
+ throw Error(`bigIntToBits: negative numbers are not supported, got ${x}`);
150
+ }
151
+ let bits = [];
152
+ for (; x > 0n; x >>= 1n) {
153
+ let bit = !!(x & 1n);
154
+ bits.push(bit);
155
+ }
156
+ return bits;
157
+ }
158
+ function projectiveScale(g, x, p, a) {
159
+ let double = getProjectiveDouble(p, a);
160
+ let bits = typeof x === "bigint" ? bigIntToBits(x) : x;
161
+ let h = projectiveZero;
162
+ for (let bit of bits) {
163
+ if (bit)
164
+ h = projectiveAdd(h, g, p, a);
165
+ g = double(g, p);
166
+ }
167
+ return h;
168
+ }
169
+ function sub(g, h) {
170
+ return projectiveSub(g, h, p, PallasConstants.a);
171
+ }
172
+ function scale(g, s) {
173
+ return projectiveScale(g, s, p, PallasConstants.a);
174
+ }
175
+ function projectiveFromAffine({ x, y, infinity, }) {
176
+ if (infinity)
177
+ return projectiveZero;
178
+ return { x, y, z: 1n };
179
+ }
180
+ function projectiveToAffine(g) {
181
+ let z = g.z;
182
+ if (z === 0n) {
183
+ // infinity
184
+ return { x: 0n, y: 0n, infinity: true };
185
+ }
186
+ else if (z === 1n) {
187
+ // already normalized affine form
188
+ return { x: g.x, y: g.y, infinity: false };
189
+ }
190
+ else {
191
+ let zinv = inverse(z, p); // we checked for z === 0, so inverse exists
192
+ let zinv_squared = mod(zinv * zinv, p);
193
+ // x/z^2
194
+ let x = mod(g.x * zinv_squared, p);
195
+ // y/z^3
196
+ let y = mod(g.y * zinv * zinv_squared, p);
197
+ return { x: x, y: y, infinity: false };
198
+ }
199
+ }
200
+ // inverting with EGCD, 1/a in Z_p
201
+ function inverse(a, p) {
202
+ a = mod(a, p);
203
+ if (a === 0n)
204
+ return undefined;
205
+ let b = p;
206
+ let x = 0n;
207
+ let y = 1n;
208
+ let u = 1n;
209
+ let v = 0n;
210
+ while (a !== 0n) {
211
+ let q = b / a;
212
+ let r = mod(b, a);
213
+ let m = x - u * q;
214
+ let n = y - v * q;
215
+ b = a;
216
+ a = r;
217
+ x = u;
218
+ y = v;
219
+ u = m;
220
+ v = n;
221
+ }
222
+ if (b !== 1n)
223
+ return undefined;
224
+ return mod(x, p);
225
+ }
226
+ function isEven(x) {
227
+ return !(mod(x, p) & 1n);
228
+ }
229
+ function equal(x, y) {
230
+ // We check if x and y are both in the range [0, p). If they are, can do a simple comparison. Otherwise, we need to reduce them to the proper canonical field range.
231
+ let x_ = x >= 0n && x < p ? x : mod(x, p);
232
+ let y_ = y >= 0n && y < p ? y : mod(y, p);
233
+ return x_ === y_;
234
+ }
235
+ // modular exponentiation, a^n % p
236
+ function power(a, n) {
237
+ a = mod(a, p);
238
+ let x = 1n;
239
+ for (; n > 0n; n >>= 1n) {
240
+ if (n & 1n)
241
+ x = mod(x * a, p);
242
+ a = mod(a * a, p);
243
+ }
244
+ return x;
245
+ }
246
+ function add(x, y) {
247
+ return mod(x + y, p);
248
+ }
249
+ function mul(x, y) {
250
+ return mod(x * y, p);
251
+ }
252
+ function dot(x, y) {
253
+ let z = 0n;
254
+ let n = x.length;
255
+ for (let i = 0; i < n; i++) {
256
+ z += x[i] * y[i];
257
+ }
258
+ return mod(z, p);
259
+ }
260
+ function sqrt(n_, p, Q, c, M) {
261
+ // https://en.wikipedia.org/wiki/Tonelli-Shanks_algorithm#The_algorithm
262
+ // variable naming is the same as in that link ^
263
+ // Q is what we call `t` elsewhere - the odd factor in p - 1
264
+ // c is a known primitive root of unity
265
+ // M is the twoadicity = exponent of 2 in factorization of p - 1
266
+ const n = mod(n_, p);
267
+ if (n === 0n)
268
+ return 0n;
269
+ let t = power(n, (Q - 1n) >> 1n); // n^(Q - 1)/2
270
+ let R = mod(t * n, p); // n^((Q - 1)/2 + 1) = n^((Q + 1)/2)
271
+ t = mod(t * R, p); // n^((Q - 1)/2 + (Q + 1)/2) = n^Q
272
+ while (true) {
273
+ if (t === 1n)
274
+ return R;
275
+ // use repeated squaring to find the least i, 0 < i < M, such that t^(2^i) = 1
276
+ let i = 0n;
277
+ let s = t;
278
+ while (s !== 1n) {
279
+ s = mod(s * s, p);
280
+ i = i + 1n;
281
+ }
282
+ if (i === M)
283
+ return undefined; // no solution
284
+ let b = power(c, 1n << (M - i - 1n)); // c^(2^(M-i-1))
285
+ M = i;
286
+ c = mod(b * b, p);
287
+ t = mod(t * c, p);
288
+ R = mod(R * b, p);
289
+ }
290
+ }
291
+ function sqrt_internal(x) {
292
+ return sqrt(x, p, oddFactor, twoadicRoot, twoadicity);
293
+ }
294
+ function negate(x) {
295
+ return x === 0n ? 0n : mod(-x, p);
296
+ }
297
+ function publicKeyToGroup({ x, isOdd }) {
298
+ const ySquared = add(mul(x, mul(x, x)), b);
299
+ let y = sqrt_internal(ySquared);
300
+ if (y === undefined) {
301
+ throw Error("PublicKey.toGroup: not a valid group element");
302
+ }
303
+ if (isOdd !== !!(y & 1n))
304
+ y = negate(y);
305
+ return { x, y };
306
+ }
307
+ //# sourceMappingURL=curve.js.map