crypto.js 317 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569
  1. "use strict";
  2. var __create = Object.create;
  3. var __defProp = Object.defineProperty;
  4. var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  5. var __getOwnPropNames = Object.getOwnPropertyNames;
  6. var __getProtoOf = Object.getPrototypeOf;
  7. var __hasOwnProp = Object.prototype.hasOwnProperty;
  8. var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
  9. var __esm = (fn, res) => function __init() {
  10. return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
  11. };
  12. var __commonJS = (cb, mod) => function __require() {
  13. return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
  14. };
  15. var __export = (target, all) => {
  16. for (var name in all)
  17. __defProp(target, name, { get: all[name], enumerable: true });
  18. };
  19. var __copyProps = (to, from, except, desc) => {
  20. if (from && typeof from === "object" || typeof from === "function") {
  21. for (let key of __getOwnPropNames(from))
  22. if (!__hasOwnProp.call(to, key) && key !== except)
  23. __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  24. }
  25. return to;
  26. };
  27. var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  28. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  29. mod
  30. ));
  31. var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
  32. var __privateAdd = (obj, member, value) => {
  33. if (member.has(obj))
  34. throw TypeError("Cannot add the same private member more than once");
  35. member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
  36. };
  37. // <define:process>
  38. var init_define_process = __esm({
  39. "<define:process>"() {
  40. }
  41. });
  42. // ../../node_modules/.pnpm/tslib@2.4.0/node_modules/tslib/tslib.js
  43. var require_tslib = __commonJS({
  44. "../../node_modules/.pnpm/tslib@2.4.0/node_modules/tslib/tslib.js"(exports, module2) {
  45. init_define_process();
  46. var __extends2;
  47. var __assign2;
  48. var __rest2;
  49. var __decorate2;
  50. var __param2;
  51. var __metadata2;
  52. var __awaiter2;
  53. var __generator2;
  54. var __exportStar2;
  55. var __values2;
  56. var __read2;
  57. var __spread2;
  58. var __spreadArrays2;
  59. var __spreadArray2;
  60. var __await2;
  61. var __asyncGenerator2;
  62. var __asyncDelegator2;
  63. var __asyncValues2;
  64. var __makeTemplateObject2;
  65. var __importStar2;
  66. var __importDefault2;
  67. var __classPrivateFieldGet2;
  68. var __classPrivateFieldSet2;
  69. var __classPrivateFieldIn2;
  70. var __createBinding2;
  71. (function(factory) {
  72. var root = typeof global === "object" ? global : typeof self === "object" ? self : typeof this === "object" ? this : {};
  73. if (typeof define === "function" && define.amd) {
  74. define("tslib", ["exports"], function(exports2) {
  75. factory(createExporter(root, createExporter(exports2)));
  76. });
  77. } else if (typeof module2 === "object" && typeof module2.exports === "object") {
  78. factory(createExporter(root, createExporter(module2.exports)));
  79. } else {
  80. factory(createExporter(root));
  81. }
  82. function createExporter(exports2, previous) {
  83. if (exports2 !== root) {
  84. if (typeof Object.create === "function") {
  85. Object.defineProperty(exports2, "__esModule", { value: true });
  86. } else {
  87. exports2.__esModule = true;
  88. }
  89. }
  90. return function(id, v) {
  91. return exports2[id] = previous ? previous(id, v) : v;
  92. };
  93. }
  94. __name(createExporter, "createExporter");
  95. })(function(exporter) {
  96. var extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(d, b) {
  97. d.__proto__ = b;
  98. } || function(d, b) {
  99. for (var p in b)
  100. if (Object.prototype.hasOwnProperty.call(b, p))
  101. d[p] = b[p];
  102. };
  103. __extends2 = /* @__PURE__ */ __name(function(d, b) {
  104. if (typeof b !== "function" && b !== null)
  105. throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
  106. extendStatics(d, b);
  107. function __() {
  108. this.constructor = d;
  109. }
  110. __name(__, "__");
  111. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  112. }, "__extends");
  113. __assign2 = Object.assign || function(t) {
  114. for (var s, i = 1, n = arguments.length; i < n; i++) {
  115. s = arguments[i];
  116. for (var p in s)
  117. if (Object.prototype.hasOwnProperty.call(s, p))
  118. t[p] = s[p];
  119. }
  120. return t;
  121. };
  122. __rest2 = /* @__PURE__ */ __name(function(s, e) {
  123. var t = {};
  124. for (var p in s)
  125. if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
  126. t[p] = s[p];
  127. if (s != null && typeof Object.getOwnPropertySymbols === "function")
  128. for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
  129. if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
  130. t[p[i]] = s[p[i]];
  131. }
  132. return t;
  133. }, "__rest");
  134. __decorate2 = /* @__PURE__ */ __name(function(decorators, target, key, desc) {
  135. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  136. if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
  137. r = Reflect.decorate(decorators, target, key, desc);
  138. else
  139. for (var i = decorators.length - 1; i >= 0; i--)
  140. if (d = decorators[i])
  141. r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  142. return c > 3 && r && Object.defineProperty(target, key, r), r;
  143. }, "__decorate");
  144. __param2 = /* @__PURE__ */ __name(function(paramIndex, decorator) {
  145. return function(target, key) {
  146. decorator(target, key, paramIndex);
  147. };
  148. }, "__param");
  149. __metadata2 = /* @__PURE__ */ __name(function(metadataKey, metadataValue) {
  150. if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
  151. return Reflect.metadata(metadataKey, metadataValue);
  152. }, "__metadata");
  153. __awaiter2 = /* @__PURE__ */ __name(function(thisArg, _arguments, P, generator) {
  154. function adopt(value) {
  155. return value instanceof P ? value : new P(function(resolve) {
  156. resolve(value);
  157. });
  158. }
  159. __name(adopt, "adopt");
  160. return new (P || (P = Promise))(function(resolve, reject) {
  161. function fulfilled(value) {
  162. try {
  163. step(generator.next(value));
  164. } catch (e) {
  165. reject(e);
  166. }
  167. }
  168. __name(fulfilled, "fulfilled");
  169. function rejected(value) {
  170. try {
  171. step(generator["throw"](value));
  172. } catch (e) {
  173. reject(e);
  174. }
  175. }
  176. __name(rejected, "rejected");
  177. function step(result) {
  178. result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
  179. }
  180. __name(step, "step");
  181. step((generator = generator.apply(thisArg, _arguments || [])).next());
  182. });
  183. }, "__awaiter");
  184. __generator2 = /* @__PURE__ */ __name(function(thisArg, body) {
  185. var _ = { label: 0, sent: function() {
  186. if (t[0] & 1)
  187. throw t[1];
  188. return t[1];
  189. }, trys: [], ops: [] }, f, y, t, g;
  190. return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
  191. return this;
  192. }), g;
  193. function verb(n) {
  194. return function(v) {
  195. return step([n, v]);
  196. };
  197. }
  198. __name(verb, "verb");
  199. function step(op) {
  200. if (f)
  201. throw new TypeError("Generator is already executing.");
  202. while (_)
  203. try {
  204. 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)
  205. return t;
  206. if (y = 0, t)
  207. op = [op[0] & 2, t.value];
  208. switch (op[0]) {
  209. case 0:
  210. case 1:
  211. t = op;
  212. break;
  213. case 4:
  214. _.label++;
  215. return { value: op[1], done: false };
  216. case 5:
  217. _.label++;
  218. y = op[1];
  219. op = [0];
  220. continue;
  221. case 7:
  222. op = _.ops.pop();
  223. _.trys.pop();
  224. continue;
  225. default:
  226. if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
  227. _ = 0;
  228. continue;
  229. }
  230. if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
  231. _.label = op[1];
  232. break;
  233. }
  234. if (op[0] === 6 && _.label < t[1]) {
  235. _.label = t[1];
  236. t = op;
  237. break;
  238. }
  239. if (t && _.label < t[2]) {
  240. _.label = t[2];
  241. _.ops.push(op);
  242. break;
  243. }
  244. if (t[2])
  245. _.ops.pop();
  246. _.trys.pop();
  247. continue;
  248. }
  249. op = body.call(thisArg, _);
  250. } catch (e) {
  251. op = [6, e];
  252. y = 0;
  253. } finally {
  254. f = t = 0;
  255. }
  256. if (op[0] & 5)
  257. throw op[1];
  258. return { value: op[0] ? op[1] : void 0, done: true };
  259. }
  260. __name(step, "step");
  261. }, "__generator");
  262. __exportStar2 = /* @__PURE__ */ __name(function(m, o) {
  263. for (var p in m)
  264. if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p))
  265. __createBinding2(o, m, p);
  266. }, "__exportStar");
  267. __createBinding2 = Object.create ? function(o, m, k, k2) {
  268. if (k2 === void 0)
  269. k2 = k;
  270. var desc = Object.getOwnPropertyDescriptor(m, k);
  271. if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
  272. desc = { enumerable: true, get: function() {
  273. return m[k];
  274. } };
  275. }
  276. Object.defineProperty(o, k2, desc);
  277. } : function(o, m, k, k2) {
  278. if (k2 === void 0)
  279. k2 = k;
  280. o[k2] = m[k];
  281. };
  282. __values2 = /* @__PURE__ */ __name(function(o) {
  283. var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
  284. if (m)
  285. return m.call(o);
  286. if (o && typeof o.length === "number")
  287. return {
  288. next: function() {
  289. if (o && i >= o.length)
  290. o = void 0;
  291. return { value: o && o[i++], done: !o };
  292. }
  293. };
  294. throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
  295. }, "__values");
  296. __read2 = /* @__PURE__ */ __name(function(o, n) {
  297. var m = typeof Symbol === "function" && o[Symbol.iterator];
  298. if (!m)
  299. return o;
  300. var i = m.call(o), r, ar = [], e;
  301. try {
  302. while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
  303. ar.push(r.value);
  304. } catch (error) {
  305. e = { error };
  306. } finally {
  307. try {
  308. if (r && !r.done && (m = i["return"]))
  309. m.call(i);
  310. } finally {
  311. if (e)
  312. throw e.error;
  313. }
  314. }
  315. return ar;
  316. }, "__read");
  317. __spread2 = /* @__PURE__ */ __name(function() {
  318. for (var ar = [], i = 0; i < arguments.length; i++)
  319. ar = ar.concat(__read2(arguments[i]));
  320. return ar;
  321. }, "__spread");
  322. __spreadArrays2 = /* @__PURE__ */ __name(function() {
  323. for (var s = 0, i = 0, il = arguments.length; i < il; i++)
  324. s += arguments[i].length;
  325. for (var r = Array(s), k = 0, i = 0; i < il; i++)
  326. for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
  327. r[k] = a[j];
  328. return r;
  329. }, "__spreadArrays");
  330. __spreadArray2 = /* @__PURE__ */ __name(function(to, from, pack) {
  331. if (pack || arguments.length === 2)
  332. for (var i = 0, l = from.length, ar; i < l; i++) {
  333. if (ar || !(i in from)) {
  334. if (!ar)
  335. ar = Array.prototype.slice.call(from, 0, i);
  336. ar[i] = from[i];
  337. }
  338. }
  339. return to.concat(ar || Array.prototype.slice.call(from));
  340. }, "__spreadArray");
  341. __await2 = /* @__PURE__ */ __name(function(v) {
  342. return this instanceof __await2 ? (this.v = v, this) : new __await2(v);
  343. }, "__await");
  344. __asyncGenerator2 = /* @__PURE__ */ __name(function(thisArg, _arguments, generator) {
  345. if (!Symbol.asyncIterator)
  346. throw new TypeError("Symbol.asyncIterator is not defined.");
  347. var g = generator.apply(thisArg, _arguments || []), i, q = [];
  348. return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function() {
  349. return this;
  350. }, i;
  351. function verb(n) {
  352. if (g[n])
  353. i[n] = function(v) {
  354. return new Promise(function(a, b) {
  355. q.push([n, v, a, b]) > 1 || resume(n, v);
  356. });
  357. };
  358. }
  359. __name(verb, "verb");
  360. function resume(n, v) {
  361. try {
  362. step(g[n](v));
  363. } catch (e) {
  364. settle(q[0][3], e);
  365. }
  366. }
  367. __name(resume, "resume");
  368. function step(r) {
  369. r.value instanceof __await2 ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r);
  370. }
  371. __name(step, "step");
  372. function fulfill(value) {
  373. resume("next", value);
  374. }
  375. __name(fulfill, "fulfill");
  376. function reject(value) {
  377. resume("throw", value);
  378. }
  379. __name(reject, "reject");
  380. function settle(f, v) {
  381. if (f(v), q.shift(), q.length)
  382. resume(q[0][0], q[0][1]);
  383. }
  384. __name(settle, "settle");
  385. }, "__asyncGenerator");
  386. __asyncDelegator2 = /* @__PURE__ */ __name(function(o) {
  387. var i, p;
  388. return i = {}, verb("next"), verb("throw", function(e) {
  389. throw e;
  390. }), verb("return"), i[Symbol.iterator] = function() {
  391. return this;
  392. }, i;
  393. function verb(n, f) {
  394. i[n] = o[n] ? function(v) {
  395. return (p = !p) ? { value: __await2(o[n](v)), done: n === "return" } : f ? f(v) : v;
  396. } : f;
  397. }
  398. __name(verb, "verb");
  399. }, "__asyncDelegator");
  400. __asyncValues2 = /* @__PURE__ */ __name(function(o) {
  401. if (!Symbol.asyncIterator)
  402. throw new TypeError("Symbol.asyncIterator is not defined.");
  403. var m = o[Symbol.asyncIterator], i;
  404. return m ? m.call(o) : (o = typeof __values2 === "function" ? __values2(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function() {
  405. return this;
  406. }, i);
  407. function verb(n) {
  408. i[n] = o[n] && function(v) {
  409. return new Promise(function(resolve, reject) {
  410. v = o[n](v), settle(resolve, reject, v.done, v.value);
  411. });
  412. };
  413. }
  414. __name(verb, "verb");
  415. function settle(resolve, reject, d, v) {
  416. Promise.resolve(v).then(function(v2) {
  417. resolve({ value: v2, done: d });
  418. }, reject);
  419. }
  420. __name(settle, "settle");
  421. }, "__asyncValues");
  422. __makeTemplateObject2 = /* @__PURE__ */ __name(function(cooked, raw) {
  423. if (Object.defineProperty) {
  424. Object.defineProperty(cooked, "raw", { value: raw });
  425. } else {
  426. cooked.raw = raw;
  427. }
  428. return cooked;
  429. }, "__makeTemplateObject");
  430. var __setModuleDefault = Object.create ? function(o, v) {
  431. Object.defineProperty(o, "default", { enumerable: true, value: v });
  432. } : function(o, v) {
  433. o["default"] = v;
  434. };
  435. __importStar2 = /* @__PURE__ */ __name(function(mod) {
  436. if (mod && mod.__esModule)
  437. return mod;
  438. var result = {};
  439. if (mod != null) {
  440. for (var k in mod)
  441. if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
  442. __createBinding2(result, mod, k);
  443. }
  444. __setModuleDefault(result, mod);
  445. return result;
  446. }, "__importStar");
  447. __importDefault2 = /* @__PURE__ */ __name(function(mod) {
  448. return mod && mod.__esModule ? mod : { "default": mod };
  449. }, "__importDefault");
  450. __classPrivateFieldGet2 = /* @__PURE__ */ __name(function(receiver, state, kind, f) {
  451. if (kind === "a" && !f)
  452. throw new TypeError("Private accessor was defined without a getter");
  453. if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
  454. throw new TypeError("Cannot read private member from an object whose class did not declare it");
  455. return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
  456. }, "__classPrivateFieldGet");
  457. __classPrivateFieldSet2 = /* @__PURE__ */ __name(function(receiver, state, value, kind, f) {
  458. if (kind === "m")
  459. throw new TypeError("Private method is not writable");
  460. if (kind === "a" && !f)
  461. throw new TypeError("Private accessor was defined without a setter");
  462. if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
  463. throw new TypeError("Cannot write private member to an object whose class did not declare it");
  464. return kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value), value;
  465. }, "__classPrivateFieldSet");
  466. __classPrivateFieldIn2 = /* @__PURE__ */ __name(function(state, receiver) {
  467. if (receiver === null || typeof receiver !== "object" && typeof receiver !== "function")
  468. throw new TypeError("Cannot use 'in' operator on non-object");
  469. return typeof state === "function" ? receiver === state : state.has(receiver);
  470. }, "__classPrivateFieldIn");
  471. exporter("__extends", __extends2);
  472. exporter("__assign", __assign2);
  473. exporter("__rest", __rest2);
  474. exporter("__decorate", __decorate2);
  475. exporter("__param", __param2);
  476. exporter("__metadata", __metadata2);
  477. exporter("__awaiter", __awaiter2);
  478. exporter("__generator", __generator2);
  479. exporter("__exportStar", __exportStar2);
  480. exporter("__createBinding", __createBinding2);
  481. exporter("__values", __values2);
  482. exporter("__read", __read2);
  483. exporter("__spread", __spread2);
  484. exporter("__spreadArrays", __spreadArrays2);
  485. exporter("__spreadArray", __spreadArray2);
  486. exporter("__await", __await2);
  487. exporter("__asyncGenerator", __asyncGenerator2);
  488. exporter("__asyncDelegator", __asyncDelegator2);
  489. exporter("__asyncValues", __asyncValues2);
  490. exporter("__makeTemplateObject", __makeTemplateObject2);
  491. exporter("__importStar", __importStar2);
  492. exporter("__importDefault", __importDefault2);
  493. exporter("__classPrivateFieldGet", __classPrivateFieldGet2);
  494. exporter("__classPrivateFieldSet", __classPrivateFieldSet2);
  495. exporter("__classPrivateFieldIn", __classPrivateFieldIn2);
  496. });
  497. }
  498. });
  499. // ../../node_modules/.pnpm/uuid@8.3.2/node_modules/uuid/dist/rng.js
  500. var require_rng = __commonJS({
  501. "../../node_modules/.pnpm/uuid@8.3.2/node_modules/uuid/dist/rng.js"(exports) {
  502. "use strict";
  503. init_define_process();
  504. Object.defineProperty(exports, "__esModule", {
  505. value: true
  506. });
  507. exports.default = rng;
  508. var _crypto = _interopRequireDefault(require("crypto"));
  509. function _interopRequireDefault(obj) {
  510. return obj && obj.__esModule ? obj : { default: obj };
  511. }
  512. __name(_interopRequireDefault, "_interopRequireDefault");
  513. var rnds8Pool = new Uint8Array(256);
  514. var poolPtr = rnds8Pool.length;
  515. function rng() {
  516. if (poolPtr > rnds8Pool.length - 16) {
  517. _crypto.default.randomFillSync(rnds8Pool);
  518. poolPtr = 0;
  519. }
  520. return rnds8Pool.slice(poolPtr, poolPtr += 16);
  521. }
  522. __name(rng, "rng");
  523. }
  524. });
  525. // ../../node_modules/.pnpm/uuid@8.3.2/node_modules/uuid/dist/regex.js
  526. var require_regex = __commonJS({
  527. "../../node_modules/.pnpm/uuid@8.3.2/node_modules/uuid/dist/regex.js"(exports) {
  528. "use strict";
  529. init_define_process();
  530. Object.defineProperty(exports, "__esModule", {
  531. value: true
  532. });
  533. exports.default = void 0;
  534. var _default = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;
  535. exports.default = _default;
  536. }
  537. });
  538. // ../../node_modules/.pnpm/uuid@8.3.2/node_modules/uuid/dist/validate.js
  539. var require_validate = __commonJS({
  540. "../../node_modules/.pnpm/uuid@8.3.2/node_modules/uuid/dist/validate.js"(exports) {
  541. "use strict";
  542. init_define_process();
  543. Object.defineProperty(exports, "__esModule", {
  544. value: true
  545. });
  546. exports.default = void 0;
  547. var _regex = _interopRequireDefault(require_regex());
  548. function _interopRequireDefault(obj) {
  549. return obj && obj.__esModule ? obj : { default: obj };
  550. }
  551. __name(_interopRequireDefault, "_interopRequireDefault");
  552. function validate2(uuid2) {
  553. return typeof uuid2 === "string" && _regex.default.test(uuid2);
  554. }
  555. __name(validate2, "validate");
  556. var _default = validate2;
  557. exports.default = _default;
  558. }
  559. });
  560. // ../../node_modules/.pnpm/uuid@8.3.2/node_modules/uuid/dist/stringify.js
  561. var require_stringify = __commonJS({
  562. "../../node_modules/.pnpm/uuid@8.3.2/node_modules/uuid/dist/stringify.js"(exports) {
  563. "use strict";
  564. init_define_process();
  565. Object.defineProperty(exports, "__esModule", {
  566. value: true
  567. });
  568. exports.default = void 0;
  569. var _validate = _interopRequireDefault(require_validate());
  570. function _interopRequireDefault(obj) {
  571. return obj && obj.__esModule ? obj : { default: obj };
  572. }
  573. __name(_interopRequireDefault, "_interopRequireDefault");
  574. var byteToHex = [];
  575. for (let i = 0; i < 256; ++i) {
  576. byteToHex.push((i + 256).toString(16).substr(1));
  577. }
  578. function stringify2(arr, offset = 0) {
  579. const uuid2 = (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + "-" + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + "-" + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + "-" + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + "-" + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase();
  580. if (!(0, _validate.default)(uuid2)) {
  581. throw TypeError("Stringified UUID is invalid");
  582. }
  583. return uuid2;
  584. }
  585. __name(stringify2, "stringify");
  586. var _default = stringify2;
  587. exports.default = _default;
  588. }
  589. });
  590. // ../../node_modules/.pnpm/uuid@8.3.2/node_modules/uuid/dist/v1.js
  591. var require_v1 = __commonJS({
  592. "../../node_modules/.pnpm/uuid@8.3.2/node_modules/uuid/dist/v1.js"(exports) {
  593. "use strict";
  594. init_define_process();
  595. Object.defineProperty(exports, "__esModule", {
  596. value: true
  597. });
  598. exports.default = void 0;
  599. var _rng = _interopRequireDefault(require_rng());
  600. var _stringify = _interopRequireDefault(require_stringify());
  601. function _interopRequireDefault(obj) {
  602. return obj && obj.__esModule ? obj : { default: obj };
  603. }
  604. __name(_interopRequireDefault, "_interopRequireDefault");
  605. var _nodeId;
  606. var _clockseq;
  607. var _lastMSecs = 0;
  608. var _lastNSecs = 0;
  609. function v12(options, buf, offset) {
  610. let i = buf && offset || 0;
  611. const b = buf || new Array(16);
  612. options = options || {};
  613. let node = options.node || _nodeId;
  614. let clockseq = options.clockseq !== void 0 ? options.clockseq : _clockseq;
  615. if (node == null || clockseq == null) {
  616. const seedBytes = options.random || (options.rng || _rng.default)();
  617. if (node == null) {
  618. node = _nodeId = [seedBytes[0] | 1, seedBytes[1], seedBytes[2], seedBytes[3], seedBytes[4], seedBytes[5]];
  619. }
  620. if (clockseq == null) {
  621. clockseq = _clockseq = (seedBytes[6] << 8 | seedBytes[7]) & 16383;
  622. }
  623. }
  624. let msecs = options.msecs !== void 0 ? options.msecs : Date.now();
  625. let nsecs = options.nsecs !== void 0 ? options.nsecs : _lastNSecs + 1;
  626. const dt = msecs - _lastMSecs + (nsecs - _lastNSecs) / 1e4;
  627. if (dt < 0 && options.clockseq === void 0) {
  628. clockseq = clockseq + 1 & 16383;
  629. }
  630. if ((dt < 0 || msecs > _lastMSecs) && options.nsecs === void 0) {
  631. nsecs = 0;
  632. }
  633. if (nsecs >= 1e4) {
  634. throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");
  635. }
  636. _lastMSecs = msecs;
  637. _lastNSecs = nsecs;
  638. _clockseq = clockseq;
  639. msecs += 122192928e5;
  640. const tl = ((msecs & 268435455) * 1e4 + nsecs) % 4294967296;
  641. b[i++] = tl >>> 24 & 255;
  642. b[i++] = tl >>> 16 & 255;
  643. b[i++] = tl >>> 8 & 255;
  644. b[i++] = tl & 255;
  645. const tmh = msecs / 4294967296 * 1e4 & 268435455;
  646. b[i++] = tmh >>> 8 & 255;
  647. b[i++] = tmh & 255;
  648. b[i++] = tmh >>> 24 & 15 | 16;
  649. b[i++] = tmh >>> 16 & 255;
  650. b[i++] = clockseq >>> 8 | 128;
  651. b[i++] = clockseq & 255;
  652. for (let n = 0; n < 6; ++n) {
  653. b[i + n] = node[n];
  654. }
  655. return buf || (0, _stringify.default)(b);
  656. }
  657. __name(v12, "v1");
  658. var _default = v12;
  659. exports.default = _default;
  660. }
  661. });
  662. // ../../node_modules/.pnpm/uuid@8.3.2/node_modules/uuid/dist/parse.js
  663. var require_parse = __commonJS({
  664. "../../node_modules/.pnpm/uuid@8.3.2/node_modules/uuid/dist/parse.js"(exports) {
  665. "use strict";
  666. init_define_process();
  667. Object.defineProperty(exports, "__esModule", {
  668. value: true
  669. });
  670. exports.default = void 0;
  671. var _validate = _interopRequireDefault(require_validate());
  672. function _interopRequireDefault(obj) {
  673. return obj && obj.__esModule ? obj : { default: obj };
  674. }
  675. __name(_interopRequireDefault, "_interopRequireDefault");
  676. function parse2(uuid2) {
  677. if (!(0, _validate.default)(uuid2)) {
  678. throw TypeError("Invalid UUID");
  679. }
  680. let v;
  681. const arr = new Uint8Array(16);
  682. arr[0] = (v = parseInt(uuid2.slice(0, 8), 16)) >>> 24;
  683. arr[1] = v >>> 16 & 255;
  684. arr[2] = v >>> 8 & 255;
  685. arr[3] = v & 255;
  686. arr[4] = (v = parseInt(uuid2.slice(9, 13), 16)) >>> 8;
  687. arr[5] = v & 255;
  688. arr[6] = (v = parseInt(uuid2.slice(14, 18), 16)) >>> 8;
  689. arr[7] = v & 255;
  690. arr[8] = (v = parseInt(uuid2.slice(19, 23), 16)) >>> 8;
  691. arr[9] = v & 255;
  692. arr[10] = (v = parseInt(uuid2.slice(24, 36), 16)) / 1099511627776 & 255;
  693. arr[11] = v / 4294967296 & 255;
  694. arr[12] = v >>> 24 & 255;
  695. arr[13] = v >>> 16 & 255;
  696. arr[14] = v >>> 8 & 255;
  697. arr[15] = v & 255;
  698. return arr;
  699. }
  700. __name(parse2, "parse");
  701. var _default = parse2;
  702. exports.default = _default;
  703. }
  704. });
  705. // ../../node_modules/.pnpm/uuid@8.3.2/node_modules/uuid/dist/v35.js
  706. var require_v35 = __commonJS({
  707. "../../node_modules/.pnpm/uuid@8.3.2/node_modules/uuid/dist/v35.js"(exports) {
  708. "use strict";
  709. init_define_process();
  710. Object.defineProperty(exports, "__esModule", {
  711. value: true
  712. });
  713. exports.default = _default;
  714. exports.URL = exports.DNS = void 0;
  715. var _stringify = _interopRequireDefault(require_stringify());
  716. var _parse = _interopRequireDefault(require_parse());
  717. function _interopRequireDefault(obj) {
  718. return obj && obj.__esModule ? obj : { default: obj };
  719. }
  720. __name(_interopRequireDefault, "_interopRequireDefault");
  721. function stringToBytes(str) {
  722. str = unescape(encodeURIComponent(str));
  723. const bytes = [];
  724. for (let i = 0; i < str.length; ++i) {
  725. bytes.push(str.charCodeAt(i));
  726. }
  727. return bytes;
  728. }
  729. __name(stringToBytes, "stringToBytes");
  730. var DNS = "6ba7b810-9dad-11d1-80b4-00c04fd430c8";
  731. exports.DNS = DNS;
  732. var URL = "6ba7b811-9dad-11d1-80b4-00c04fd430c8";
  733. exports.URL = URL;
  734. function _default(name, version3, hashfunc) {
  735. function generateUUID(value, namespace, buf, offset) {
  736. if (typeof value === "string") {
  737. value = stringToBytes(value);
  738. }
  739. if (typeof namespace === "string") {
  740. namespace = (0, _parse.default)(namespace);
  741. }
  742. if (namespace.length !== 16) {
  743. throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");
  744. }
  745. let bytes = new Uint8Array(16 + value.length);
  746. bytes.set(namespace);
  747. bytes.set(value, namespace.length);
  748. bytes = hashfunc(bytes);
  749. bytes[6] = bytes[6] & 15 | version3;
  750. bytes[8] = bytes[8] & 63 | 128;
  751. if (buf) {
  752. offset = offset || 0;
  753. for (let i = 0; i < 16; ++i) {
  754. buf[offset + i] = bytes[i];
  755. }
  756. return buf;
  757. }
  758. return (0, _stringify.default)(bytes);
  759. }
  760. __name(generateUUID, "generateUUID");
  761. try {
  762. generateUUID.name = name;
  763. } catch (err) {
  764. }
  765. generateUUID.DNS = DNS;
  766. generateUUID.URL = URL;
  767. return generateUUID;
  768. }
  769. __name(_default, "_default");
  770. }
  771. });
  772. // ../../node_modules/.pnpm/uuid@8.3.2/node_modules/uuid/dist/md5.js
  773. var require_md5 = __commonJS({
  774. "../../node_modules/.pnpm/uuid@8.3.2/node_modules/uuid/dist/md5.js"(exports) {
  775. "use strict";
  776. init_define_process();
  777. Object.defineProperty(exports, "__esModule", {
  778. value: true
  779. });
  780. exports.default = void 0;
  781. var _crypto = _interopRequireDefault(require("crypto"));
  782. function _interopRequireDefault(obj) {
  783. return obj && obj.__esModule ? obj : { default: obj };
  784. }
  785. __name(_interopRequireDefault, "_interopRequireDefault");
  786. function md5(bytes) {
  787. if (Array.isArray(bytes)) {
  788. bytes = Buffer.from(bytes);
  789. } else if (typeof bytes === "string") {
  790. bytes = Buffer.from(bytes, "utf8");
  791. }
  792. return _crypto.default.createHash("md5").update(bytes).digest();
  793. }
  794. __name(md5, "md5");
  795. var _default = md5;
  796. exports.default = _default;
  797. }
  798. });
  799. // ../../node_modules/.pnpm/uuid@8.3.2/node_modules/uuid/dist/v3.js
  800. var require_v3 = __commonJS({
  801. "../../node_modules/.pnpm/uuid@8.3.2/node_modules/uuid/dist/v3.js"(exports) {
  802. "use strict";
  803. init_define_process();
  804. Object.defineProperty(exports, "__esModule", {
  805. value: true
  806. });
  807. exports.default = void 0;
  808. var _v = _interopRequireDefault(require_v35());
  809. var _md = _interopRequireDefault(require_md5());
  810. function _interopRequireDefault(obj) {
  811. return obj && obj.__esModule ? obj : { default: obj };
  812. }
  813. __name(_interopRequireDefault, "_interopRequireDefault");
  814. var v32 = (0, _v.default)("v3", 48, _md.default);
  815. var _default = v32;
  816. exports.default = _default;
  817. }
  818. });
  819. // ../../node_modules/.pnpm/uuid@8.3.2/node_modules/uuid/dist/v4.js
  820. var require_v4 = __commonJS({
  821. "../../node_modules/.pnpm/uuid@8.3.2/node_modules/uuid/dist/v4.js"(exports) {
  822. "use strict";
  823. init_define_process();
  824. Object.defineProperty(exports, "__esModule", {
  825. value: true
  826. });
  827. exports.default = void 0;
  828. var _rng = _interopRequireDefault(require_rng());
  829. var _stringify = _interopRequireDefault(require_stringify());
  830. function _interopRequireDefault(obj) {
  831. return obj && obj.__esModule ? obj : { default: obj };
  832. }
  833. __name(_interopRequireDefault, "_interopRequireDefault");
  834. function v42(options, buf, offset) {
  835. options = options || {};
  836. const rnds = options.random || (options.rng || _rng.default)();
  837. rnds[6] = rnds[6] & 15 | 64;
  838. rnds[8] = rnds[8] & 63 | 128;
  839. if (buf) {
  840. offset = offset || 0;
  841. for (let i = 0; i < 16; ++i) {
  842. buf[offset + i] = rnds[i];
  843. }
  844. return buf;
  845. }
  846. return (0, _stringify.default)(rnds);
  847. }
  848. __name(v42, "v4");
  849. var _default = v42;
  850. exports.default = _default;
  851. }
  852. });
  853. // ../../node_modules/.pnpm/uuid@8.3.2/node_modules/uuid/dist/sha1.js
  854. var require_sha1 = __commonJS({
  855. "../../node_modules/.pnpm/uuid@8.3.2/node_modules/uuid/dist/sha1.js"(exports) {
  856. "use strict";
  857. init_define_process();
  858. Object.defineProperty(exports, "__esModule", {
  859. value: true
  860. });
  861. exports.default = void 0;
  862. var _crypto = _interopRequireDefault(require("crypto"));
  863. function _interopRequireDefault(obj) {
  864. return obj && obj.__esModule ? obj : { default: obj };
  865. }
  866. __name(_interopRequireDefault, "_interopRequireDefault");
  867. function sha1(bytes) {
  868. if (Array.isArray(bytes)) {
  869. bytes = Buffer.from(bytes);
  870. } else if (typeof bytes === "string") {
  871. bytes = Buffer.from(bytes, "utf8");
  872. }
  873. return _crypto.default.createHash("sha1").update(bytes).digest();
  874. }
  875. __name(sha1, "sha1");
  876. var _default = sha1;
  877. exports.default = _default;
  878. }
  879. });
  880. // ../../node_modules/.pnpm/uuid@8.3.2/node_modules/uuid/dist/v5.js
  881. var require_v5 = __commonJS({
  882. "../../node_modules/.pnpm/uuid@8.3.2/node_modules/uuid/dist/v5.js"(exports) {
  883. "use strict";
  884. init_define_process();
  885. Object.defineProperty(exports, "__esModule", {
  886. value: true
  887. });
  888. exports.default = void 0;
  889. var _v = _interopRequireDefault(require_v35());
  890. var _sha = _interopRequireDefault(require_sha1());
  891. function _interopRequireDefault(obj) {
  892. return obj && obj.__esModule ? obj : { default: obj };
  893. }
  894. __name(_interopRequireDefault, "_interopRequireDefault");
  895. var v52 = (0, _v.default)("v5", 80, _sha.default);
  896. var _default = v52;
  897. exports.default = _default;
  898. }
  899. });
  900. // ../../node_modules/.pnpm/uuid@8.3.2/node_modules/uuid/dist/nil.js
  901. var require_nil = __commonJS({
  902. "../../node_modules/.pnpm/uuid@8.3.2/node_modules/uuid/dist/nil.js"(exports) {
  903. "use strict";
  904. init_define_process();
  905. Object.defineProperty(exports, "__esModule", {
  906. value: true
  907. });
  908. exports.default = void 0;
  909. var _default = "00000000-0000-0000-0000-000000000000";
  910. exports.default = _default;
  911. }
  912. });
  913. // ../../node_modules/.pnpm/uuid@8.3.2/node_modules/uuid/dist/version.js
  914. var require_version = __commonJS({
  915. "../../node_modules/.pnpm/uuid@8.3.2/node_modules/uuid/dist/version.js"(exports) {
  916. "use strict";
  917. init_define_process();
  918. Object.defineProperty(exports, "__esModule", {
  919. value: true
  920. });
  921. exports.default = void 0;
  922. var _validate = _interopRequireDefault(require_validate());
  923. function _interopRequireDefault(obj) {
  924. return obj && obj.__esModule ? obj : { default: obj };
  925. }
  926. __name(_interopRequireDefault, "_interopRequireDefault");
  927. function version3(uuid2) {
  928. if (!(0, _validate.default)(uuid2)) {
  929. throw TypeError("Invalid UUID");
  930. }
  931. return parseInt(uuid2.substr(14, 1), 16);
  932. }
  933. __name(version3, "version");
  934. var _default = version3;
  935. exports.default = _default;
  936. }
  937. });
  938. // ../../node_modules/.pnpm/uuid@8.3.2/node_modules/uuid/dist/index.js
  939. var require_dist = __commonJS({
  940. "../../node_modules/.pnpm/uuid@8.3.2/node_modules/uuid/dist/index.js"(exports) {
  941. "use strict";
  942. init_define_process();
  943. Object.defineProperty(exports, "__esModule", {
  944. value: true
  945. });
  946. Object.defineProperty(exports, "v1", {
  947. enumerable: true,
  948. get: function() {
  949. return _v.default;
  950. }
  951. });
  952. Object.defineProperty(exports, "v3", {
  953. enumerable: true,
  954. get: function() {
  955. return _v2.default;
  956. }
  957. });
  958. Object.defineProperty(exports, "v4", {
  959. enumerable: true,
  960. get: function() {
  961. return _v3.default;
  962. }
  963. });
  964. Object.defineProperty(exports, "v5", {
  965. enumerable: true,
  966. get: function() {
  967. return _v4.default;
  968. }
  969. });
  970. Object.defineProperty(exports, "NIL", {
  971. enumerable: true,
  972. get: function() {
  973. return _nil.default;
  974. }
  975. });
  976. Object.defineProperty(exports, "version", {
  977. enumerable: true,
  978. get: function() {
  979. return _version.default;
  980. }
  981. });
  982. Object.defineProperty(exports, "validate", {
  983. enumerable: true,
  984. get: function() {
  985. return _validate.default;
  986. }
  987. });
  988. Object.defineProperty(exports, "stringify", {
  989. enumerable: true,
  990. get: function() {
  991. return _stringify.default;
  992. }
  993. });
  994. Object.defineProperty(exports, "parse", {
  995. enumerable: true,
  996. get: function() {
  997. return _parse.default;
  998. }
  999. });
  1000. var _v = _interopRequireDefault(require_v1());
  1001. var _v2 = _interopRequireDefault(require_v3());
  1002. var _v3 = _interopRequireDefault(require_v4());
  1003. var _v4 = _interopRequireDefault(require_v5());
  1004. var _nil = _interopRequireDefault(require_nil());
  1005. var _version = _interopRequireDefault(require_version());
  1006. var _validate = _interopRequireDefault(require_validate());
  1007. var _stringify = _interopRequireDefault(require_stringify());
  1008. var _parse = _interopRequireDefault(require_parse());
  1009. function _interopRequireDefault(obj) {
  1010. return obj && obj.__esModule ? obj : { default: obj };
  1011. }
  1012. __name(_interopRequireDefault, "_interopRequireDefault");
  1013. }
  1014. });
  1015. // src/primitives/crypto.js
  1016. var crypto_exports = {};
  1017. __export(crypto_exports, {
  1018. Crypto: () => Crypto3,
  1019. CryptoKey: () => CryptoKey,
  1020. SubtleCrypto: () => SubtleCrypto3,
  1021. crypto: () => crypto2
  1022. });
  1023. module.exports = __toCommonJS(crypto_exports);
  1024. init_define_process();
  1025. // ../../node_modules/.pnpm/@peculiar+webcrypto@1.4.0/node_modules/@peculiar/webcrypto/build/webcrypto.es.js
  1026. init_define_process();
  1027. // ../../node_modules/.pnpm/webcrypto-core@1.7.5/node_modules/webcrypto-core/build/webcrypto-core.es.js
  1028. init_define_process();
  1029. // ../../node_modules/.pnpm/pvtsutils@1.3.2/node_modules/pvtsutils/build/index.es.js
  1030. init_define_process();
  1031. var ARRAY_BUFFER_NAME = "[object ArrayBuffer]";
  1032. var BufferSourceConverter = class {
  1033. static isArrayBuffer(data) {
  1034. return Object.prototype.toString.call(data) === ARRAY_BUFFER_NAME;
  1035. }
  1036. static toArrayBuffer(data) {
  1037. if (this.isArrayBuffer(data)) {
  1038. return data;
  1039. }
  1040. if (data.byteLength === data.buffer.byteLength) {
  1041. return data.buffer;
  1042. }
  1043. return this.toUint8Array(data).slice().buffer;
  1044. }
  1045. static toUint8Array(data) {
  1046. return this.toView(data, Uint8Array);
  1047. }
  1048. static toView(data, type) {
  1049. if (data.constructor === type) {
  1050. return data;
  1051. }
  1052. if (this.isArrayBuffer(data)) {
  1053. return new type(data);
  1054. }
  1055. if (this.isArrayBufferView(data)) {
  1056. return new type(data.buffer, data.byteOffset, data.byteLength);
  1057. }
  1058. throw new TypeError("The provided value is not of type '(ArrayBuffer or ArrayBufferView)'");
  1059. }
  1060. static isBufferSource(data) {
  1061. return this.isArrayBufferView(data) || this.isArrayBuffer(data);
  1062. }
  1063. static isArrayBufferView(data) {
  1064. return ArrayBuffer.isView(data) || data && this.isArrayBuffer(data.buffer);
  1065. }
  1066. static isEqual(a, b) {
  1067. const aView = BufferSourceConverter.toUint8Array(a);
  1068. const bView = BufferSourceConverter.toUint8Array(b);
  1069. if (aView.length !== bView.byteLength) {
  1070. return false;
  1071. }
  1072. for (let i = 0; i < aView.length; i++) {
  1073. if (aView[i] !== bView[i]) {
  1074. return false;
  1075. }
  1076. }
  1077. return true;
  1078. }
  1079. static concat(...args) {
  1080. if (Array.isArray(args[0])) {
  1081. const buffers = args[0];
  1082. let size = 0;
  1083. for (const buffer of buffers) {
  1084. size += buffer.byteLength;
  1085. }
  1086. const res = new Uint8Array(size);
  1087. let offset = 0;
  1088. for (const buffer of buffers) {
  1089. const view = this.toUint8Array(buffer);
  1090. res.set(view, offset);
  1091. offset += view.length;
  1092. }
  1093. if (args[1]) {
  1094. return this.toView(res, args[1]);
  1095. }
  1096. return res.buffer;
  1097. } else {
  1098. return this.concat(args);
  1099. }
  1100. }
  1101. };
  1102. __name(BufferSourceConverter, "BufferSourceConverter");
  1103. var Utf8Converter = class {
  1104. static fromString(text) {
  1105. const s = unescape(encodeURIComponent(text));
  1106. const uintArray = new Uint8Array(s.length);
  1107. for (let i = 0; i < s.length; i++) {
  1108. uintArray[i] = s.charCodeAt(i);
  1109. }
  1110. return uintArray.buffer;
  1111. }
  1112. static toString(buffer) {
  1113. const buf = BufferSourceConverter.toUint8Array(buffer);
  1114. let encodedString = "";
  1115. for (let i = 0; i < buf.length; i++) {
  1116. encodedString += String.fromCharCode(buf[i]);
  1117. }
  1118. const decodedString = decodeURIComponent(escape(encodedString));
  1119. return decodedString;
  1120. }
  1121. };
  1122. __name(Utf8Converter, "Utf8Converter");
  1123. var Utf16Converter = class {
  1124. static toString(buffer, littleEndian = false) {
  1125. const arrayBuffer = BufferSourceConverter.toArrayBuffer(buffer);
  1126. const dataView = new DataView(arrayBuffer);
  1127. let res = "";
  1128. for (let i = 0; i < arrayBuffer.byteLength; i += 2) {
  1129. const code = dataView.getUint16(i, littleEndian);
  1130. res += String.fromCharCode(code);
  1131. }
  1132. return res;
  1133. }
  1134. static fromString(text, littleEndian = false) {
  1135. const res = new ArrayBuffer(text.length * 2);
  1136. const dataView = new DataView(res);
  1137. for (let i = 0; i < text.length; i++) {
  1138. dataView.setUint16(i * 2, text.charCodeAt(i), littleEndian);
  1139. }
  1140. return res;
  1141. }
  1142. };
  1143. __name(Utf16Converter, "Utf16Converter");
  1144. var Convert = class {
  1145. static isHex(data) {
  1146. return typeof data === "string" && /^[a-z0-9]+$/i.test(data);
  1147. }
  1148. static isBase64(data) {
  1149. return typeof data === "string" && /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(data);
  1150. }
  1151. static isBase64Url(data) {
  1152. return typeof data === "string" && /^[a-zA-Z0-9-_]+$/i.test(data);
  1153. }
  1154. static ToString(buffer, enc = "utf8") {
  1155. const buf = BufferSourceConverter.toUint8Array(buffer);
  1156. switch (enc.toLowerCase()) {
  1157. case "utf8":
  1158. return this.ToUtf8String(buf);
  1159. case "binary":
  1160. return this.ToBinary(buf);
  1161. case "hex":
  1162. return this.ToHex(buf);
  1163. case "base64":
  1164. return this.ToBase64(buf);
  1165. case "base64url":
  1166. return this.ToBase64Url(buf);
  1167. case "utf16le":
  1168. return Utf16Converter.toString(buf, true);
  1169. case "utf16":
  1170. case "utf16be":
  1171. return Utf16Converter.toString(buf);
  1172. default:
  1173. throw new Error(`Unknown type of encoding '${enc}'`);
  1174. }
  1175. }
  1176. static FromString(str, enc = "utf8") {
  1177. if (!str) {
  1178. return new ArrayBuffer(0);
  1179. }
  1180. switch (enc.toLowerCase()) {
  1181. case "utf8":
  1182. return this.FromUtf8String(str);
  1183. case "binary":
  1184. return this.FromBinary(str);
  1185. case "hex":
  1186. return this.FromHex(str);
  1187. case "base64":
  1188. return this.FromBase64(str);
  1189. case "base64url":
  1190. return this.FromBase64Url(str);
  1191. case "utf16le":
  1192. return Utf16Converter.fromString(str, true);
  1193. case "utf16":
  1194. case "utf16be":
  1195. return Utf16Converter.fromString(str);
  1196. default:
  1197. throw new Error(`Unknown type of encoding '${enc}'`);
  1198. }
  1199. }
  1200. static ToBase64(buffer) {
  1201. const buf = BufferSourceConverter.toUint8Array(buffer);
  1202. if (typeof btoa !== "undefined") {
  1203. const binary = this.ToString(buf, "binary");
  1204. return btoa(binary);
  1205. } else {
  1206. return Buffer.from(buf).toString("base64");
  1207. }
  1208. }
  1209. static FromBase64(base64) {
  1210. const formatted = this.formatString(base64);
  1211. if (!formatted) {
  1212. return new ArrayBuffer(0);
  1213. }
  1214. if (!Convert.isBase64(formatted)) {
  1215. throw new TypeError("Argument 'base64Text' is not Base64 encoded");
  1216. }
  1217. if (typeof atob !== "undefined") {
  1218. return this.FromBinary(atob(formatted));
  1219. } else {
  1220. return new Uint8Array(Buffer.from(formatted, "base64")).buffer;
  1221. }
  1222. }
  1223. static FromBase64Url(base64url) {
  1224. const formatted = this.formatString(base64url);
  1225. if (!formatted) {
  1226. return new ArrayBuffer(0);
  1227. }
  1228. if (!Convert.isBase64Url(formatted)) {
  1229. throw new TypeError("Argument 'base64url' is not Base64Url encoded");
  1230. }
  1231. return this.FromBase64(this.Base64Padding(formatted.replace(/\-/g, "+").replace(/\_/g, "/")));
  1232. }
  1233. static ToBase64Url(data) {
  1234. return this.ToBase64(data).replace(/\+/g, "-").replace(/\//g, "_").replace(/\=/g, "");
  1235. }
  1236. static FromUtf8String(text, encoding = Convert.DEFAULT_UTF8_ENCODING) {
  1237. switch (encoding) {
  1238. case "ascii":
  1239. return this.FromBinary(text);
  1240. case "utf8":
  1241. return Utf8Converter.fromString(text);
  1242. case "utf16":
  1243. case "utf16be":
  1244. return Utf16Converter.fromString(text);
  1245. case "utf16le":
  1246. case "usc2":
  1247. return Utf16Converter.fromString(text, true);
  1248. default:
  1249. throw new Error(`Unknown type of encoding '${encoding}'`);
  1250. }
  1251. }
  1252. static ToUtf8String(buffer, encoding = Convert.DEFAULT_UTF8_ENCODING) {
  1253. switch (encoding) {
  1254. case "ascii":
  1255. return this.ToBinary(buffer);
  1256. case "utf8":
  1257. return Utf8Converter.toString(buffer);
  1258. case "utf16":
  1259. case "utf16be":
  1260. return Utf16Converter.toString(buffer);
  1261. case "utf16le":
  1262. case "usc2":
  1263. return Utf16Converter.toString(buffer, true);
  1264. default:
  1265. throw new Error(`Unknown type of encoding '${encoding}'`);
  1266. }
  1267. }
  1268. static FromBinary(text) {
  1269. const stringLength = text.length;
  1270. const resultView = new Uint8Array(stringLength);
  1271. for (let i = 0; i < stringLength; i++) {
  1272. resultView[i] = text.charCodeAt(i);
  1273. }
  1274. return resultView.buffer;
  1275. }
  1276. static ToBinary(buffer) {
  1277. const buf = BufferSourceConverter.toUint8Array(buffer);
  1278. let res = "";
  1279. for (let i = 0; i < buf.length; i++) {
  1280. res += String.fromCharCode(buf[i]);
  1281. }
  1282. return res;
  1283. }
  1284. static ToHex(buffer) {
  1285. const buf = BufferSourceConverter.toUint8Array(buffer);
  1286. const splitter = "";
  1287. const res = [];
  1288. const len = buf.length;
  1289. for (let i = 0; i < len; i++) {
  1290. const char = buf[i].toString(16).padStart(2, "0");
  1291. res.push(char);
  1292. }
  1293. return res.join(splitter);
  1294. }
  1295. static FromHex(hexString) {
  1296. let formatted = this.formatString(hexString);
  1297. if (!formatted) {
  1298. return new ArrayBuffer(0);
  1299. }
  1300. if (!Convert.isHex(formatted)) {
  1301. throw new TypeError("Argument 'hexString' is not HEX encoded");
  1302. }
  1303. if (formatted.length % 2) {
  1304. formatted = `0${formatted}`;
  1305. }
  1306. const res = new Uint8Array(formatted.length / 2);
  1307. for (let i = 0; i < formatted.length; i = i + 2) {
  1308. const c = formatted.slice(i, i + 2);
  1309. res[i / 2] = parseInt(c, 16);
  1310. }
  1311. return res.buffer;
  1312. }
  1313. static ToUtf16String(buffer, littleEndian = false) {
  1314. return Utf16Converter.toString(buffer, littleEndian);
  1315. }
  1316. static FromUtf16String(text, littleEndian = false) {
  1317. return Utf16Converter.fromString(text, littleEndian);
  1318. }
  1319. static Base64Padding(base64) {
  1320. const padCount = 4 - base64.length % 4;
  1321. if (padCount < 4) {
  1322. for (let i = 0; i < padCount; i++) {
  1323. base64 += "=";
  1324. }
  1325. }
  1326. return base64;
  1327. }
  1328. static formatString(data) {
  1329. return (data === null || data === void 0 ? void 0 : data.replace(/[\n\r\t ]/g, "")) || "";
  1330. }
  1331. };
  1332. __name(Convert, "Convert");
  1333. Convert.DEFAULT_UTF8_ENCODING = "utf8";
  1334. function combine(...buf) {
  1335. const totalByteLength = buf.map((item) => item.byteLength).reduce((prev, cur) => prev + cur);
  1336. const res = new Uint8Array(totalByteLength);
  1337. let currentPos = 0;
  1338. buf.map((item) => new Uint8Array(item)).forEach((arr) => {
  1339. for (const item2 of arr) {
  1340. res[currentPos++] = item2;
  1341. }
  1342. });
  1343. return res.buffer;
  1344. }
  1345. __name(combine, "combine");
  1346. // ../../node_modules/.pnpm/@peculiar+asn1-schema@2.3.0/node_modules/@peculiar/asn1-schema/build/es2015/index.js
  1347. init_define_process();
  1348. // ../../node_modules/.pnpm/@peculiar+asn1-schema@2.3.0/node_modules/@peculiar/asn1-schema/build/es2015/converters.js
  1349. init_define_process();
  1350. // ../../node_modules/.pnpm/asn1js@3.0.5/node_modules/asn1js/build/index.es.js
  1351. var index_es_exports = {};
  1352. __export(index_es_exports, {
  1353. Any: () => Any,
  1354. BaseBlock: () => BaseBlock,
  1355. BaseStringBlock: () => BaseStringBlock,
  1356. BitString: () => BitString,
  1357. BmpString: () => BmpString,
  1358. Boolean: () => Boolean,
  1359. CharacterString: () => CharacterString,
  1360. Choice: () => Choice,
  1361. Constructed: () => Constructed,
  1362. DATE: () => DATE,
  1363. DateTime: () => DateTime,
  1364. Duration: () => Duration,
  1365. EndOfContent: () => EndOfContent,
  1366. Enumerated: () => Enumerated,
  1367. GeneralString: () => GeneralString,
  1368. GeneralizedTime: () => GeneralizedTime,
  1369. GraphicString: () => GraphicString,
  1370. HexBlock: () => HexBlock,
  1371. IA5String: () => IA5String,
  1372. Integer: () => Integer,
  1373. Null: () => Null,
  1374. NumericString: () => NumericString,
  1375. ObjectIdentifier: () => ObjectIdentifier,
  1376. OctetString: () => OctetString,
  1377. Primitive: () => Primitive,
  1378. PrintableString: () => PrintableString,
  1379. RawData: () => RawData,
  1380. RelativeObjectIdentifier: () => RelativeObjectIdentifier,
  1381. Repeated: () => Repeated,
  1382. Sequence: () => Sequence,
  1383. Set: () => Set,
  1384. TIME: () => TIME,
  1385. TeletexString: () => TeletexString,
  1386. TimeOfDay: () => TimeOfDay,
  1387. UTCTime: () => UTCTime,
  1388. UniversalString: () => UniversalString,
  1389. Utf8String: () => Utf8String,
  1390. ValueBlock: () => ValueBlock,
  1391. VideotexString: () => VideotexString,
  1392. ViewWriter: () => ViewWriter,
  1393. VisibleString: () => VisibleString,
  1394. compareSchema: () => compareSchema,
  1395. fromBER: () => fromBER,
  1396. verifySchema: () => verifySchema
  1397. });
  1398. init_define_process();
  1399. // ../../node_modules/.pnpm/pvutils@1.1.3/node_modules/pvutils/build/utils.es.js
  1400. init_define_process();
  1401. function utilFromBase(inputBuffer, inputBase) {
  1402. let result = 0;
  1403. if (inputBuffer.length === 1) {
  1404. return inputBuffer[0];
  1405. }
  1406. for (let i = inputBuffer.length - 1; i >= 0; i--) {
  1407. result += inputBuffer[inputBuffer.length - 1 - i] * Math.pow(2, inputBase * i);
  1408. }
  1409. return result;
  1410. }
  1411. __name(utilFromBase, "utilFromBase");
  1412. function utilToBase(value, base, reserved = -1) {
  1413. const internalReserved = reserved;
  1414. let internalValue = value;
  1415. let result = 0;
  1416. let biggest = Math.pow(2, base);
  1417. for (let i = 1; i < 8; i++) {
  1418. if (value < biggest) {
  1419. let retBuf;
  1420. if (internalReserved < 0) {
  1421. retBuf = new ArrayBuffer(i);
  1422. result = i;
  1423. } else {
  1424. if (internalReserved < i) {
  1425. return new ArrayBuffer(0);
  1426. }
  1427. retBuf = new ArrayBuffer(internalReserved);
  1428. result = internalReserved;
  1429. }
  1430. const retView = new Uint8Array(retBuf);
  1431. for (let j = i - 1; j >= 0; j--) {
  1432. const basis = Math.pow(2, j * base);
  1433. retView[result - j - 1] = Math.floor(internalValue / basis);
  1434. internalValue -= retView[result - j - 1] * basis;
  1435. }
  1436. return retBuf;
  1437. }
  1438. biggest *= Math.pow(2, base);
  1439. }
  1440. return new ArrayBuffer(0);
  1441. }
  1442. __name(utilToBase, "utilToBase");
  1443. function utilConcatView(...views) {
  1444. let outputLength = 0;
  1445. let prevLength = 0;
  1446. for (const view of views) {
  1447. outputLength += view.length;
  1448. }
  1449. const retBuf = new ArrayBuffer(outputLength);
  1450. const retView = new Uint8Array(retBuf);
  1451. for (const view of views) {
  1452. retView.set(view, prevLength);
  1453. prevLength += view.length;
  1454. }
  1455. return retView;
  1456. }
  1457. __name(utilConcatView, "utilConcatView");
  1458. function utilDecodeTC() {
  1459. const buf = new Uint8Array(this.valueHex);
  1460. if (this.valueHex.byteLength >= 2) {
  1461. const condition1 = buf[0] === 255 && buf[1] & 128;
  1462. const condition2 = buf[0] === 0 && (buf[1] & 128) === 0;
  1463. if (condition1 || condition2) {
  1464. this.warnings.push("Needlessly long format");
  1465. }
  1466. }
  1467. const bigIntBuffer = new ArrayBuffer(this.valueHex.byteLength);
  1468. const bigIntView = new Uint8Array(bigIntBuffer);
  1469. for (let i = 0; i < this.valueHex.byteLength; i++) {
  1470. bigIntView[i] = 0;
  1471. }
  1472. bigIntView[0] = buf[0] & 128;
  1473. const bigInt = utilFromBase(bigIntView, 8);
  1474. const smallIntBuffer = new ArrayBuffer(this.valueHex.byteLength);
  1475. const smallIntView = new Uint8Array(smallIntBuffer);
  1476. for (let j = 0; j < this.valueHex.byteLength; j++) {
  1477. smallIntView[j] = buf[j];
  1478. }
  1479. smallIntView[0] &= 127;
  1480. const smallInt = utilFromBase(smallIntView, 8);
  1481. return smallInt - bigInt;
  1482. }
  1483. __name(utilDecodeTC, "utilDecodeTC");
  1484. function utilEncodeTC(value) {
  1485. const modValue = value < 0 ? value * -1 : value;
  1486. let bigInt = 128;
  1487. for (let i = 1; i < 8; i++) {
  1488. if (modValue <= bigInt) {
  1489. if (value < 0) {
  1490. const smallInt = bigInt - modValue;
  1491. const retBuf2 = utilToBase(smallInt, 8, i);
  1492. const retView2 = new Uint8Array(retBuf2);
  1493. retView2[0] |= 128;
  1494. return retBuf2;
  1495. }
  1496. let retBuf = utilToBase(modValue, 8, i);
  1497. let retView = new Uint8Array(retBuf);
  1498. if (retView[0] & 128) {
  1499. const tempBuf = retBuf.slice(0);
  1500. const tempView = new Uint8Array(tempBuf);
  1501. retBuf = new ArrayBuffer(retBuf.byteLength + 1);
  1502. retView = new Uint8Array(retBuf);
  1503. for (let k = 0; k < tempBuf.byteLength; k++) {
  1504. retView[k + 1] = tempView[k];
  1505. }
  1506. retView[0] = 0;
  1507. }
  1508. return retBuf;
  1509. }
  1510. bigInt *= Math.pow(2, 8);
  1511. }
  1512. return new ArrayBuffer(0);
  1513. }
  1514. __name(utilEncodeTC, "utilEncodeTC");
  1515. function isEqualBuffer(inputBuffer1, inputBuffer2) {
  1516. if (inputBuffer1.byteLength !== inputBuffer2.byteLength) {
  1517. return false;
  1518. }
  1519. const view1 = new Uint8Array(inputBuffer1);
  1520. const view2 = new Uint8Array(inputBuffer2);
  1521. for (let i = 0; i < view1.length; i++) {
  1522. if (view1[i] !== view2[i]) {
  1523. return false;
  1524. }
  1525. }
  1526. return true;
  1527. }
  1528. __name(isEqualBuffer, "isEqualBuffer");
  1529. function padNumber(inputNumber, fullLength) {
  1530. const str = inputNumber.toString(10);
  1531. if (fullLength < str.length) {
  1532. return "";
  1533. }
  1534. const dif = fullLength - str.length;
  1535. const padding = new Array(dif);
  1536. for (let i = 0; i < dif; i++) {
  1537. padding[i] = "0";
  1538. }
  1539. const paddingString = padding.join("");
  1540. return paddingString.concat(str);
  1541. }
  1542. __name(padNumber, "padNumber");
  1543. var log2 = Math.log(2);
  1544. // ../../node_modules/.pnpm/asn1js@3.0.5/node_modules/asn1js/build/index.es.js
  1545. function assertBigInt() {
  1546. if (typeof BigInt === "undefined") {
  1547. throw new Error("BigInt is not defined. Your environment doesn't implement BigInt.");
  1548. }
  1549. }
  1550. __name(assertBigInt, "assertBigInt");
  1551. function concat(buffers) {
  1552. let outputLength = 0;
  1553. let prevLength = 0;
  1554. for (let i = 0; i < buffers.length; i++) {
  1555. const buffer = buffers[i];
  1556. outputLength += buffer.byteLength;
  1557. }
  1558. const retView = new Uint8Array(outputLength);
  1559. for (let i = 0; i < buffers.length; i++) {
  1560. const buffer = buffers[i];
  1561. retView.set(new Uint8Array(buffer), prevLength);
  1562. prevLength += buffer.byteLength;
  1563. }
  1564. return retView.buffer;
  1565. }
  1566. __name(concat, "concat");
  1567. function checkBufferParams(baseBlock, inputBuffer, inputOffset, inputLength) {
  1568. if (!(inputBuffer instanceof Uint8Array)) {
  1569. baseBlock.error = "Wrong parameter: inputBuffer must be 'Uint8Array'";
  1570. return false;
  1571. }
  1572. if (!inputBuffer.byteLength) {
  1573. baseBlock.error = "Wrong parameter: inputBuffer has zero length";
  1574. return false;
  1575. }
  1576. if (inputOffset < 0) {
  1577. baseBlock.error = "Wrong parameter: inputOffset less than zero";
  1578. return false;
  1579. }
  1580. if (inputLength < 0) {
  1581. baseBlock.error = "Wrong parameter: inputLength less than zero";
  1582. return false;
  1583. }
  1584. if (inputBuffer.byteLength - inputOffset - inputLength < 0) {
  1585. baseBlock.error = "End of input reached before message was fully decoded (inconsistent offset and length values)";
  1586. return false;
  1587. }
  1588. return true;
  1589. }
  1590. __name(checkBufferParams, "checkBufferParams");
  1591. var ViewWriter = class {
  1592. constructor() {
  1593. this.items = [];
  1594. }
  1595. write(buf) {
  1596. this.items.push(buf);
  1597. }
  1598. final() {
  1599. return concat(this.items);
  1600. }
  1601. };
  1602. __name(ViewWriter, "ViewWriter");
  1603. var powers2 = [new Uint8Array([1])];
  1604. var digitsString = "0123456789";
  1605. var NAME = "name";
  1606. var VALUE_HEX_VIEW = "valueHexView";
  1607. var IS_HEX_ONLY = "isHexOnly";
  1608. var ID_BLOCK = "idBlock";
  1609. var TAG_CLASS = "tagClass";
  1610. var TAG_NUMBER = "tagNumber";
  1611. var IS_CONSTRUCTED = "isConstructed";
  1612. var FROM_BER = "fromBER";
  1613. var TO_BER = "toBER";
  1614. var LOCAL = "local";
  1615. var EMPTY_STRING = "";
  1616. var EMPTY_BUFFER = new ArrayBuffer(0);
  1617. var EMPTY_VIEW = new Uint8Array(0);
  1618. var END_OF_CONTENT_NAME = "EndOfContent";
  1619. var OCTET_STRING_NAME = "OCTET STRING";
  1620. var BIT_STRING_NAME = "BIT STRING";
  1621. function HexBlock(BaseClass) {
  1622. var _a2;
  1623. return _a2 = /* @__PURE__ */ __name(class Some extends BaseClass {
  1624. constructor(...args) {
  1625. var _a3;
  1626. super(...args);
  1627. const params = args[0] || {};
  1628. this.isHexOnly = (_a3 = params.isHexOnly) !== null && _a3 !== void 0 ? _a3 : false;
  1629. this.valueHexView = params.valueHex ? BufferSourceConverter.toUint8Array(params.valueHex) : EMPTY_VIEW;
  1630. }
  1631. get valueHex() {
  1632. return this.valueHexView.slice().buffer;
  1633. }
  1634. set valueHex(value) {
  1635. this.valueHexView = new Uint8Array(value);
  1636. }
  1637. fromBER(inputBuffer, inputOffset, inputLength) {
  1638. const view = inputBuffer instanceof ArrayBuffer ? new Uint8Array(inputBuffer) : inputBuffer;
  1639. if (!checkBufferParams(this, view, inputOffset, inputLength)) {
  1640. return -1;
  1641. }
  1642. const endLength = inputOffset + inputLength;
  1643. this.valueHexView = view.subarray(inputOffset, endLength);
  1644. if (!this.valueHexView.length) {
  1645. this.warnings.push("Zero buffer length");
  1646. return inputOffset;
  1647. }
  1648. this.blockLength = inputLength;
  1649. return endLength;
  1650. }
  1651. toBER(sizeOnly = false) {
  1652. if (!this.isHexOnly) {
  1653. this.error = "Flag 'isHexOnly' is not set, abort";
  1654. return EMPTY_BUFFER;
  1655. }
  1656. if (sizeOnly) {
  1657. return new ArrayBuffer(this.valueHexView.byteLength);
  1658. }
  1659. return this.valueHexView.byteLength === this.valueHexView.buffer.byteLength ? this.valueHexView.buffer : this.valueHexView.slice().buffer;
  1660. }
  1661. toJSON() {
  1662. return {
  1663. ...super.toJSON(),
  1664. isHexOnly: this.isHexOnly,
  1665. valueHex: Convert.ToHex(this.valueHexView)
  1666. };
  1667. }
  1668. }, "Some"), _a2.NAME = "hexBlock", _a2;
  1669. }
  1670. __name(HexBlock, "HexBlock");
  1671. var LocalBaseBlock = class {
  1672. constructor({ blockLength = 0, error = EMPTY_STRING, warnings = [], valueBeforeDecode = EMPTY_VIEW } = {}) {
  1673. this.blockLength = blockLength;
  1674. this.error = error;
  1675. this.warnings = warnings;
  1676. this.valueBeforeDecodeView = BufferSourceConverter.toUint8Array(valueBeforeDecode);
  1677. }
  1678. static blockName() {
  1679. return this.NAME;
  1680. }
  1681. get valueBeforeDecode() {
  1682. return this.valueBeforeDecodeView.slice().buffer;
  1683. }
  1684. set valueBeforeDecode(value) {
  1685. this.valueBeforeDecodeView = new Uint8Array(value);
  1686. }
  1687. toJSON() {
  1688. return {
  1689. blockName: this.constructor.NAME,
  1690. blockLength: this.blockLength,
  1691. error: this.error,
  1692. warnings: this.warnings,
  1693. valueBeforeDecode: Convert.ToHex(this.valueBeforeDecodeView)
  1694. };
  1695. }
  1696. };
  1697. __name(LocalBaseBlock, "LocalBaseBlock");
  1698. LocalBaseBlock.NAME = "baseBlock";
  1699. var ValueBlock = class extends LocalBaseBlock {
  1700. fromBER(inputBuffer, inputOffset, inputLength) {
  1701. throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'");
  1702. }
  1703. toBER(sizeOnly, writer) {
  1704. throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'");
  1705. }
  1706. };
  1707. __name(ValueBlock, "ValueBlock");
  1708. ValueBlock.NAME = "valueBlock";
  1709. var LocalIdentificationBlock = class extends HexBlock(LocalBaseBlock) {
  1710. constructor({ idBlock = {} } = {}) {
  1711. var _a2, _b, _c, _d;
  1712. super();
  1713. if (idBlock) {
  1714. this.isHexOnly = (_a2 = idBlock.isHexOnly) !== null && _a2 !== void 0 ? _a2 : false;
  1715. this.valueHexView = idBlock.valueHex ? BufferSourceConverter.toUint8Array(idBlock.valueHex) : EMPTY_VIEW;
  1716. this.tagClass = (_b = idBlock.tagClass) !== null && _b !== void 0 ? _b : -1;
  1717. this.tagNumber = (_c = idBlock.tagNumber) !== null && _c !== void 0 ? _c : -1;
  1718. this.isConstructed = (_d = idBlock.isConstructed) !== null && _d !== void 0 ? _d : false;
  1719. } else {
  1720. this.tagClass = -1;
  1721. this.tagNumber = -1;
  1722. this.isConstructed = false;
  1723. }
  1724. }
  1725. toBER(sizeOnly = false) {
  1726. let firstOctet = 0;
  1727. switch (this.tagClass) {
  1728. case 1:
  1729. firstOctet |= 0;
  1730. break;
  1731. case 2:
  1732. firstOctet |= 64;
  1733. break;
  1734. case 3:
  1735. firstOctet |= 128;
  1736. break;
  1737. case 4:
  1738. firstOctet |= 192;
  1739. break;
  1740. default:
  1741. this.error = "Unknown tag class";
  1742. return EMPTY_BUFFER;
  1743. }
  1744. if (this.isConstructed)
  1745. firstOctet |= 32;
  1746. if (this.tagNumber < 31 && !this.isHexOnly) {
  1747. const retView2 = new Uint8Array(1);
  1748. if (!sizeOnly) {
  1749. let number = this.tagNumber;
  1750. number &= 31;
  1751. firstOctet |= number;
  1752. retView2[0] = firstOctet;
  1753. }
  1754. return retView2.buffer;
  1755. }
  1756. if (!this.isHexOnly) {
  1757. const encodedBuf = utilToBase(this.tagNumber, 7);
  1758. const encodedView = new Uint8Array(encodedBuf);
  1759. const size = encodedBuf.byteLength;
  1760. const retView2 = new Uint8Array(size + 1);
  1761. retView2[0] = firstOctet | 31;
  1762. if (!sizeOnly) {
  1763. for (let i = 0; i < size - 1; i++)
  1764. retView2[i + 1] = encodedView[i] | 128;
  1765. retView2[size] = encodedView[size - 1];
  1766. }
  1767. return retView2.buffer;
  1768. }
  1769. const retView = new Uint8Array(this.valueHexView.byteLength + 1);
  1770. retView[0] = firstOctet | 31;
  1771. if (!sizeOnly) {
  1772. const curView = this.valueHexView;
  1773. for (let i = 0; i < curView.length - 1; i++)
  1774. retView[i + 1] = curView[i] | 128;
  1775. retView[this.valueHexView.byteLength] = curView[curView.length - 1];
  1776. }
  1777. return retView.buffer;
  1778. }
  1779. fromBER(inputBuffer, inputOffset, inputLength) {
  1780. const inputView = BufferSourceConverter.toUint8Array(inputBuffer);
  1781. if (!checkBufferParams(this, inputView, inputOffset, inputLength)) {
  1782. return -1;
  1783. }
  1784. const intBuffer = inputView.subarray(inputOffset, inputOffset + inputLength);
  1785. if (intBuffer.length === 0) {
  1786. this.error = "Zero buffer length";
  1787. return -1;
  1788. }
  1789. const tagClassMask = intBuffer[0] & 192;
  1790. switch (tagClassMask) {
  1791. case 0:
  1792. this.tagClass = 1;
  1793. break;
  1794. case 64:
  1795. this.tagClass = 2;
  1796. break;
  1797. case 128:
  1798. this.tagClass = 3;
  1799. break;
  1800. case 192:
  1801. this.tagClass = 4;
  1802. break;
  1803. default:
  1804. this.error = "Unknown tag class";
  1805. return -1;
  1806. }
  1807. this.isConstructed = (intBuffer[0] & 32) === 32;
  1808. this.isHexOnly = false;
  1809. const tagNumberMask = intBuffer[0] & 31;
  1810. if (tagNumberMask !== 31) {
  1811. this.tagNumber = tagNumberMask;
  1812. this.blockLength = 1;
  1813. } else {
  1814. let count = 1;
  1815. let intTagNumberBuffer = this.valueHexView = new Uint8Array(255);
  1816. let tagNumberBufferMaxLength = 255;
  1817. while (intBuffer[count] & 128) {
  1818. intTagNumberBuffer[count - 1] = intBuffer[count] & 127;
  1819. count++;
  1820. if (count >= intBuffer.length) {
  1821. this.error = "End of input reached before message was fully decoded";
  1822. return -1;
  1823. }
  1824. if (count === tagNumberBufferMaxLength) {
  1825. tagNumberBufferMaxLength += 255;
  1826. const tempBufferView2 = new Uint8Array(tagNumberBufferMaxLength);
  1827. for (let i = 0; i < intTagNumberBuffer.length; i++)
  1828. tempBufferView2[i] = intTagNumberBuffer[i];
  1829. intTagNumberBuffer = this.valueHexView = new Uint8Array(tagNumberBufferMaxLength);
  1830. }
  1831. }
  1832. this.blockLength = count + 1;
  1833. intTagNumberBuffer[count - 1] = intBuffer[count] & 127;
  1834. const tempBufferView = new Uint8Array(count);
  1835. for (let i = 0; i < count; i++)
  1836. tempBufferView[i] = intTagNumberBuffer[i];
  1837. intTagNumberBuffer = this.valueHexView = new Uint8Array(count);
  1838. intTagNumberBuffer.set(tempBufferView);
  1839. if (this.blockLength <= 9)
  1840. this.tagNumber = utilFromBase(intTagNumberBuffer, 7);
  1841. else {
  1842. this.isHexOnly = true;
  1843. this.warnings.push("Tag too long, represented as hex-coded");
  1844. }
  1845. }
  1846. if (this.tagClass === 1 && this.isConstructed) {
  1847. switch (this.tagNumber) {
  1848. case 1:
  1849. case 2:
  1850. case 5:
  1851. case 6:
  1852. case 9:
  1853. case 13:
  1854. case 14:
  1855. case 23:
  1856. case 24:
  1857. case 31:
  1858. case 32:
  1859. case 33:
  1860. case 34:
  1861. this.error = "Constructed encoding used for primitive type";
  1862. return -1;
  1863. }
  1864. }
  1865. return inputOffset + this.blockLength;
  1866. }
  1867. toJSON() {
  1868. return {
  1869. ...super.toJSON(),
  1870. tagClass: this.tagClass,
  1871. tagNumber: this.tagNumber,
  1872. isConstructed: this.isConstructed
  1873. };
  1874. }
  1875. };
  1876. __name(LocalIdentificationBlock, "LocalIdentificationBlock");
  1877. LocalIdentificationBlock.NAME = "identificationBlock";
  1878. var LocalLengthBlock = class extends LocalBaseBlock {
  1879. constructor({ lenBlock = {} } = {}) {
  1880. var _a2, _b, _c;
  1881. super();
  1882. this.isIndefiniteForm = (_a2 = lenBlock.isIndefiniteForm) !== null && _a2 !== void 0 ? _a2 : false;
  1883. this.longFormUsed = (_b = lenBlock.longFormUsed) !== null && _b !== void 0 ? _b : false;
  1884. this.length = (_c = lenBlock.length) !== null && _c !== void 0 ? _c : 0;
  1885. }
  1886. fromBER(inputBuffer, inputOffset, inputLength) {
  1887. const view = BufferSourceConverter.toUint8Array(inputBuffer);
  1888. if (!checkBufferParams(this, view, inputOffset, inputLength)) {
  1889. return -1;
  1890. }
  1891. const intBuffer = view.subarray(inputOffset, inputOffset + inputLength);
  1892. if (intBuffer.length === 0) {
  1893. this.error = "Zero buffer length";
  1894. return -1;
  1895. }
  1896. if (intBuffer[0] === 255) {
  1897. this.error = "Length block 0xFF is reserved by standard";
  1898. return -1;
  1899. }
  1900. this.isIndefiniteForm = intBuffer[0] === 128;
  1901. if (this.isIndefiniteForm) {
  1902. this.blockLength = 1;
  1903. return inputOffset + this.blockLength;
  1904. }
  1905. this.longFormUsed = !!(intBuffer[0] & 128);
  1906. if (this.longFormUsed === false) {
  1907. this.length = intBuffer[0];
  1908. this.blockLength = 1;
  1909. return inputOffset + this.blockLength;
  1910. }
  1911. const count = intBuffer[0] & 127;
  1912. if (count > 8) {
  1913. this.error = "Too big integer";
  1914. return -1;
  1915. }
  1916. if (count + 1 > intBuffer.length) {
  1917. this.error = "End of input reached before message was fully decoded";
  1918. return -1;
  1919. }
  1920. const lenOffset = inputOffset + 1;
  1921. const lengthBufferView = view.subarray(lenOffset, lenOffset + count);
  1922. if (lengthBufferView[count - 1] === 0)
  1923. this.warnings.push("Needlessly long encoded length");
  1924. this.length = utilFromBase(lengthBufferView, 8);
  1925. if (this.longFormUsed && this.length <= 127)
  1926. this.warnings.push("Unnecessary usage of long length form");
  1927. this.blockLength = count + 1;
  1928. return inputOffset + this.blockLength;
  1929. }
  1930. toBER(sizeOnly = false) {
  1931. let retBuf;
  1932. let retView;
  1933. if (this.length > 127)
  1934. this.longFormUsed = true;
  1935. if (this.isIndefiniteForm) {
  1936. retBuf = new ArrayBuffer(1);
  1937. if (sizeOnly === false) {
  1938. retView = new Uint8Array(retBuf);
  1939. retView[0] = 128;
  1940. }
  1941. return retBuf;
  1942. }
  1943. if (this.longFormUsed) {
  1944. const encodedBuf = utilToBase(this.length, 8);
  1945. if (encodedBuf.byteLength > 127) {
  1946. this.error = "Too big length";
  1947. return EMPTY_BUFFER;
  1948. }
  1949. retBuf = new ArrayBuffer(encodedBuf.byteLength + 1);
  1950. if (sizeOnly)
  1951. return retBuf;
  1952. const encodedView = new Uint8Array(encodedBuf);
  1953. retView = new Uint8Array(retBuf);
  1954. retView[0] = encodedBuf.byteLength | 128;
  1955. for (let i = 0; i < encodedBuf.byteLength; i++)
  1956. retView[i + 1] = encodedView[i];
  1957. return retBuf;
  1958. }
  1959. retBuf = new ArrayBuffer(1);
  1960. if (sizeOnly === false) {
  1961. retView = new Uint8Array(retBuf);
  1962. retView[0] = this.length;
  1963. }
  1964. return retBuf;
  1965. }
  1966. toJSON() {
  1967. return {
  1968. ...super.toJSON(),
  1969. isIndefiniteForm: this.isIndefiniteForm,
  1970. longFormUsed: this.longFormUsed,
  1971. length: this.length
  1972. };
  1973. }
  1974. };
  1975. __name(LocalLengthBlock, "LocalLengthBlock");
  1976. LocalLengthBlock.NAME = "lengthBlock";
  1977. var typeStore = {};
  1978. var BaseBlock = class extends LocalBaseBlock {
  1979. constructor({ name = EMPTY_STRING, optional = false, primitiveSchema, ...parameters } = {}, valueBlockType) {
  1980. super(parameters);
  1981. this.name = name;
  1982. this.optional = optional;
  1983. if (primitiveSchema) {
  1984. this.primitiveSchema = primitiveSchema;
  1985. }
  1986. this.idBlock = new LocalIdentificationBlock(parameters);
  1987. this.lenBlock = new LocalLengthBlock(parameters);
  1988. this.valueBlock = valueBlockType ? new valueBlockType(parameters) : new ValueBlock(parameters);
  1989. }
  1990. fromBER(inputBuffer, inputOffset, inputLength) {
  1991. const resultOffset = this.valueBlock.fromBER(inputBuffer, inputOffset, this.lenBlock.isIndefiniteForm ? inputLength : this.lenBlock.length);
  1992. if (resultOffset === -1) {
  1993. this.error = this.valueBlock.error;
  1994. return resultOffset;
  1995. }
  1996. if (!this.idBlock.error.length)
  1997. this.blockLength += this.idBlock.blockLength;
  1998. if (!this.lenBlock.error.length)
  1999. this.blockLength += this.lenBlock.blockLength;
  2000. if (!this.valueBlock.error.length)
  2001. this.blockLength += this.valueBlock.blockLength;
  2002. return resultOffset;
  2003. }
  2004. toBER(sizeOnly, writer) {
  2005. const _writer = writer || new ViewWriter();
  2006. if (!writer) {
  2007. prepareIndefiniteForm(this);
  2008. }
  2009. const idBlockBuf = this.idBlock.toBER(sizeOnly);
  2010. _writer.write(idBlockBuf);
  2011. if (this.lenBlock.isIndefiniteForm) {
  2012. _writer.write(new Uint8Array([128]).buffer);
  2013. this.valueBlock.toBER(sizeOnly, _writer);
  2014. _writer.write(new ArrayBuffer(2));
  2015. } else {
  2016. const valueBlockBuf = this.valueBlock.toBER(sizeOnly);
  2017. this.lenBlock.length = valueBlockBuf.byteLength;
  2018. const lenBlockBuf = this.lenBlock.toBER(sizeOnly);
  2019. _writer.write(lenBlockBuf);
  2020. _writer.write(valueBlockBuf);
  2021. }
  2022. if (!writer) {
  2023. return _writer.final();
  2024. }
  2025. return EMPTY_BUFFER;
  2026. }
  2027. toJSON() {
  2028. const object = {
  2029. ...super.toJSON(),
  2030. idBlock: this.idBlock.toJSON(),
  2031. lenBlock: this.lenBlock.toJSON(),
  2032. valueBlock: this.valueBlock.toJSON(),
  2033. name: this.name,
  2034. optional: this.optional
  2035. };
  2036. if (this.primitiveSchema)
  2037. object.primitiveSchema = this.primitiveSchema.toJSON();
  2038. return object;
  2039. }
  2040. toString(encoding = "ascii") {
  2041. if (encoding === "ascii") {
  2042. return this.onAsciiEncoding();
  2043. }
  2044. return Convert.ToHex(this.toBER());
  2045. }
  2046. onAsciiEncoding() {
  2047. return `${this.constructor.NAME} : ${Convert.ToHex(this.valueBlock.valueBeforeDecodeView)}`;
  2048. }
  2049. isEqual(other) {
  2050. if (this === other) {
  2051. return true;
  2052. }
  2053. if (!(other instanceof this.constructor)) {
  2054. return false;
  2055. }
  2056. const thisRaw = this.toBER();
  2057. const otherRaw = other.toBER();
  2058. return isEqualBuffer(thisRaw, otherRaw);
  2059. }
  2060. };
  2061. __name(BaseBlock, "BaseBlock");
  2062. BaseBlock.NAME = "BaseBlock";
  2063. function prepareIndefiniteForm(baseBlock) {
  2064. if (baseBlock instanceof typeStore.Constructed) {
  2065. for (const value of baseBlock.valueBlock.value) {
  2066. if (prepareIndefiniteForm(value)) {
  2067. baseBlock.lenBlock.isIndefiniteForm = true;
  2068. }
  2069. }
  2070. }
  2071. return !!baseBlock.lenBlock.isIndefiniteForm;
  2072. }
  2073. __name(prepareIndefiniteForm, "prepareIndefiniteForm");
  2074. var BaseStringBlock = class extends BaseBlock {
  2075. constructor({ value = EMPTY_STRING, ...parameters } = {}, stringValueBlockType) {
  2076. super(parameters, stringValueBlockType);
  2077. if (value) {
  2078. this.fromString(value);
  2079. }
  2080. }
  2081. getValue() {
  2082. return this.valueBlock.value;
  2083. }
  2084. setValue(value) {
  2085. this.valueBlock.value = value;
  2086. }
  2087. fromBER(inputBuffer, inputOffset, inputLength) {
  2088. const resultOffset = this.valueBlock.fromBER(inputBuffer, inputOffset, this.lenBlock.isIndefiniteForm ? inputLength : this.lenBlock.length);
  2089. if (resultOffset === -1) {
  2090. this.error = this.valueBlock.error;
  2091. return resultOffset;
  2092. }
  2093. this.fromBuffer(this.valueBlock.valueHexView);
  2094. if (!this.idBlock.error.length)
  2095. this.blockLength += this.idBlock.blockLength;
  2096. if (!this.lenBlock.error.length)
  2097. this.blockLength += this.lenBlock.blockLength;
  2098. if (!this.valueBlock.error.length)
  2099. this.blockLength += this.valueBlock.blockLength;
  2100. return resultOffset;
  2101. }
  2102. onAsciiEncoding() {
  2103. return `${this.constructor.NAME} : '${this.valueBlock.value}'`;
  2104. }
  2105. };
  2106. __name(BaseStringBlock, "BaseStringBlock");
  2107. BaseStringBlock.NAME = "BaseStringBlock";
  2108. var LocalPrimitiveValueBlock = class extends HexBlock(ValueBlock) {
  2109. constructor({ isHexOnly = true, ...parameters } = {}) {
  2110. super(parameters);
  2111. this.isHexOnly = isHexOnly;
  2112. }
  2113. };
  2114. __name(LocalPrimitiveValueBlock, "LocalPrimitiveValueBlock");
  2115. LocalPrimitiveValueBlock.NAME = "PrimitiveValueBlock";
  2116. var _a$w;
  2117. var Primitive = class extends BaseBlock {
  2118. constructor(parameters = {}) {
  2119. super(parameters, LocalPrimitiveValueBlock);
  2120. this.idBlock.isConstructed = false;
  2121. }
  2122. };
  2123. __name(Primitive, "Primitive");
  2124. _a$w = Primitive;
  2125. (() => {
  2126. typeStore.Primitive = _a$w;
  2127. })();
  2128. Primitive.NAME = "PRIMITIVE";
  2129. function localChangeType(inputObject, newType) {
  2130. if (inputObject instanceof newType) {
  2131. return inputObject;
  2132. }
  2133. const newObject = new newType();
  2134. newObject.idBlock = inputObject.idBlock;
  2135. newObject.lenBlock = inputObject.lenBlock;
  2136. newObject.warnings = inputObject.warnings;
  2137. newObject.valueBeforeDecodeView = inputObject.valueBeforeDecodeView;
  2138. return newObject;
  2139. }
  2140. __name(localChangeType, "localChangeType");
  2141. function localFromBER(inputBuffer, inputOffset = 0, inputLength = inputBuffer.length) {
  2142. const incomingOffset = inputOffset;
  2143. let returnObject = new BaseBlock({}, ValueBlock);
  2144. const baseBlock = new LocalBaseBlock();
  2145. if (!checkBufferParams(baseBlock, inputBuffer, inputOffset, inputLength)) {
  2146. returnObject.error = baseBlock.error;
  2147. return {
  2148. offset: -1,
  2149. result: returnObject
  2150. };
  2151. }
  2152. const intBuffer = inputBuffer.subarray(inputOffset, inputOffset + inputLength);
  2153. if (!intBuffer.length) {
  2154. returnObject.error = "Zero buffer length";
  2155. return {
  2156. offset: -1,
  2157. result: returnObject
  2158. };
  2159. }
  2160. let resultOffset = returnObject.idBlock.fromBER(inputBuffer, inputOffset, inputLength);
  2161. if (returnObject.idBlock.warnings.length) {
  2162. returnObject.warnings.concat(returnObject.idBlock.warnings);
  2163. }
  2164. if (resultOffset === -1) {
  2165. returnObject.error = returnObject.idBlock.error;
  2166. return {
  2167. offset: -1,
  2168. result: returnObject
  2169. };
  2170. }
  2171. inputOffset = resultOffset;
  2172. inputLength -= returnObject.idBlock.blockLength;
  2173. resultOffset = returnObject.lenBlock.fromBER(inputBuffer, inputOffset, inputLength);
  2174. if (returnObject.lenBlock.warnings.length) {
  2175. returnObject.warnings.concat(returnObject.lenBlock.warnings);
  2176. }
  2177. if (resultOffset === -1) {
  2178. returnObject.error = returnObject.lenBlock.error;
  2179. return {
  2180. offset: -1,
  2181. result: returnObject
  2182. };
  2183. }
  2184. inputOffset = resultOffset;
  2185. inputLength -= returnObject.lenBlock.blockLength;
  2186. if (!returnObject.idBlock.isConstructed && returnObject.lenBlock.isIndefiniteForm) {
  2187. returnObject.error = "Indefinite length form used for primitive encoding form";
  2188. return {
  2189. offset: -1,
  2190. result: returnObject
  2191. };
  2192. }
  2193. let newASN1Type = BaseBlock;
  2194. switch (returnObject.idBlock.tagClass) {
  2195. case 1:
  2196. if (returnObject.idBlock.tagNumber >= 37 && returnObject.idBlock.isHexOnly === false) {
  2197. returnObject.error = "UNIVERSAL 37 and upper tags are reserved by ASN.1 standard";
  2198. return {
  2199. offset: -1,
  2200. result: returnObject
  2201. };
  2202. }
  2203. switch (returnObject.idBlock.tagNumber) {
  2204. case 0:
  2205. if (returnObject.idBlock.isConstructed && returnObject.lenBlock.length > 0) {
  2206. returnObject.error = "Type [UNIVERSAL 0] is reserved";
  2207. return {
  2208. offset: -1,
  2209. result: returnObject
  2210. };
  2211. }
  2212. newASN1Type = typeStore.EndOfContent;
  2213. break;
  2214. case 1:
  2215. newASN1Type = typeStore.Boolean;
  2216. break;
  2217. case 2:
  2218. newASN1Type = typeStore.Integer;
  2219. break;
  2220. case 3:
  2221. newASN1Type = typeStore.BitString;
  2222. break;
  2223. case 4:
  2224. newASN1Type = typeStore.OctetString;
  2225. break;
  2226. case 5:
  2227. newASN1Type = typeStore.Null;
  2228. break;
  2229. case 6:
  2230. newASN1Type = typeStore.ObjectIdentifier;
  2231. break;
  2232. case 10:
  2233. newASN1Type = typeStore.Enumerated;
  2234. break;
  2235. case 12:
  2236. newASN1Type = typeStore.Utf8String;
  2237. break;
  2238. case 13:
  2239. newASN1Type = typeStore.RelativeObjectIdentifier;
  2240. break;
  2241. case 14:
  2242. newASN1Type = typeStore.TIME;
  2243. break;
  2244. case 15:
  2245. returnObject.error = "[UNIVERSAL 15] is reserved by ASN.1 standard";
  2246. return {
  2247. offset: -1,
  2248. result: returnObject
  2249. };
  2250. case 16:
  2251. newASN1Type = typeStore.Sequence;
  2252. break;
  2253. case 17:
  2254. newASN1Type = typeStore.Set;
  2255. break;
  2256. case 18:
  2257. newASN1Type = typeStore.NumericString;
  2258. break;
  2259. case 19:
  2260. newASN1Type = typeStore.PrintableString;
  2261. break;
  2262. case 20:
  2263. newASN1Type = typeStore.TeletexString;
  2264. break;
  2265. case 21:
  2266. newASN1Type = typeStore.VideotexString;
  2267. break;
  2268. case 22:
  2269. newASN1Type = typeStore.IA5String;
  2270. break;
  2271. case 23:
  2272. newASN1Type = typeStore.UTCTime;
  2273. break;
  2274. case 24:
  2275. newASN1Type = typeStore.GeneralizedTime;
  2276. break;
  2277. case 25:
  2278. newASN1Type = typeStore.GraphicString;
  2279. break;
  2280. case 26:
  2281. newASN1Type = typeStore.VisibleString;
  2282. break;
  2283. case 27:
  2284. newASN1Type = typeStore.GeneralString;
  2285. break;
  2286. case 28:
  2287. newASN1Type = typeStore.UniversalString;
  2288. break;
  2289. case 29:
  2290. newASN1Type = typeStore.CharacterString;
  2291. break;
  2292. case 30:
  2293. newASN1Type = typeStore.BmpString;
  2294. break;
  2295. case 31:
  2296. newASN1Type = typeStore.DATE;
  2297. break;
  2298. case 32:
  2299. newASN1Type = typeStore.TimeOfDay;
  2300. break;
  2301. case 33:
  2302. newASN1Type = typeStore.DateTime;
  2303. break;
  2304. case 34:
  2305. newASN1Type = typeStore.Duration;
  2306. break;
  2307. default: {
  2308. const newObject = returnObject.idBlock.isConstructed ? new typeStore.Constructed() : new typeStore.Primitive();
  2309. newObject.idBlock = returnObject.idBlock;
  2310. newObject.lenBlock = returnObject.lenBlock;
  2311. newObject.warnings = returnObject.warnings;
  2312. returnObject = newObject;
  2313. }
  2314. }
  2315. break;
  2316. case 2:
  2317. case 3:
  2318. case 4:
  2319. default: {
  2320. newASN1Type = returnObject.idBlock.isConstructed ? typeStore.Constructed : typeStore.Primitive;
  2321. }
  2322. }
  2323. returnObject = localChangeType(returnObject, newASN1Type);
  2324. resultOffset = returnObject.fromBER(inputBuffer, inputOffset, returnObject.lenBlock.isIndefiniteForm ? inputLength : returnObject.lenBlock.length);
  2325. returnObject.valueBeforeDecodeView = inputBuffer.subarray(incomingOffset, incomingOffset + returnObject.blockLength);
  2326. return {
  2327. offset: resultOffset,
  2328. result: returnObject
  2329. };
  2330. }
  2331. __name(localFromBER, "localFromBER");
  2332. function fromBER(inputBuffer) {
  2333. if (!inputBuffer.byteLength) {
  2334. const result = new BaseBlock({}, ValueBlock);
  2335. result.error = "Input buffer has zero length";
  2336. return {
  2337. offset: -1,
  2338. result
  2339. };
  2340. }
  2341. return localFromBER(BufferSourceConverter.toUint8Array(inputBuffer).slice(), 0, inputBuffer.byteLength);
  2342. }
  2343. __name(fromBER, "fromBER");
  2344. function checkLen(indefiniteLength, length) {
  2345. if (indefiniteLength) {
  2346. return 1;
  2347. }
  2348. return length;
  2349. }
  2350. __name(checkLen, "checkLen");
  2351. var LocalConstructedValueBlock = class extends ValueBlock {
  2352. constructor({ value = [], isIndefiniteForm = false, ...parameters } = {}) {
  2353. super(parameters);
  2354. this.value = value;
  2355. this.isIndefiniteForm = isIndefiniteForm;
  2356. }
  2357. fromBER(inputBuffer, inputOffset, inputLength) {
  2358. const view = BufferSourceConverter.toUint8Array(inputBuffer);
  2359. if (!checkBufferParams(this, view, inputOffset, inputLength)) {
  2360. return -1;
  2361. }
  2362. this.valueBeforeDecodeView = view.subarray(inputOffset, inputOffset + inputLength);
  2363. if (this.valueBeforeDecodeView.length === 0) {
  2364. this.warnings.push("Zero buffer length");
  2365. return inputOffset;
  2366. }
  2367. let currentOffset = inputOffset;
  2368. while (checkLen(this.isIndefiniteForm, inputLength) > 0) {
  2369. const returnObject = localFromBER(view, currentOffset, inputLength);
  2370. if (returnObject.offset === -1) {
  2371. this.error = returnObject.result.error;
  2372. this.warnings.concat(returnObject.result.warnings);
  2373. return -1;
  2374. }
  2375. currentOffset = returnObject.offset;
  2376. this.blockLength += returnObject.result.blockLength;
  2377. inputLength -= returnObject.result.blockLength;
  2378. this.value.push(returnObject.result);
  2379. if (this.isIndefiniteForm && returnObject.result.constructor.NAME === END_OF_CONTENT_NAME) {
  2380. break;
  2381. }
  2382. }
  2383. if (this.isIndefiniteForm) {
  2384. if (this.value[this.value.length - 1].constructor.NAME === END_OF_CONTENT_NAME) {
  2385. this.value.pop();
  2386. } else {
  2387. this.warnings.push("No EndOfContent block encoded");
  2388. }
  2389. }
  2390. return currentOffset;
  2391. }
  2392. toBER(sizeOnly, writer) {
  2393. const _writer = writer || new ViewWriter();
  2394. for (let i = 0; i < this.value.length; i++) {
  2395. this.value[i].toBER(sizeOnly, _writer);
  2396. }
  2397. if (!writer) {
  2398. return _writer.final();
  2399. }
  2400. return EMPTY_BUFFER;
  2401. }
  2402. toJSON() {
  2403. const object = {
  2404. ...super.toJSON(),
  2405. isIndefiniteForm: this.isIndefiniteForm,
  2406. value: []
  2407. };
  2408. for (const value of this.value) {
  2409. object.value.push(value.toJSON());
  2410. }
  2411. return object;
  2412. }
  2413. };
  2414. __name(LocalConstructedValueBlock, "LocalConstructedValueBlock");
  2415. LocalConstructedValueBlock.NAME = "ConstructedValueBlock";
  2416. var _a$v;
  2417. var Constructed = class extends BaseBlock {
  2418. constructor(parameters = {}) {
  2419. super(parameters, LocalConstructedValueBlock);
  2420. this.idBlock.isConstructed = true;
  2421. }
  2422. fromBER(inputBuffer, inputOffset, inputLength) {
  2423. this.valueBlock.isIndefiniteForm = this.lenBlock.isIndefiniteForm;
  2424. const resultOffset = this.valueBlock.fromBER(inputBuffer, inputOffset, this.lenBlock.isIndefiniteForm ? inputLength : this.lenBlock.length);
  2425. if (resultOffset === -1) {
  2426. this.error = this.valueBlock.error;
  2427. return resultOffset;
  2428. }
  2429. if (!this.idBlock.error.length)
  2430. this.blockLength += this.idBlock.blockLength;
  2431. if (!this.lenBlock.error.length)
  2432. this.blockLength += this.lenBlock.blockLength;
  2433. if (!this.valueBlock.error.length)
  2434. this.blockLength += this.valueBlock.blockLength;
  2435. return resultOffset;
  2436. }
  2437. onAsciiEncoding() {
  2438. const values = [];
  2439. for (const value of this.valueBlock.value) {
  2440. values.push(value.toString("ascii").split("\n").map((o) => ` ${o}`).join("\n"));
  2441. }
  2442. const blockName = this.idBlock.tagClass === 3 ? `[${this.idBlock.tagNumber}]` : this.constructor.NAME;
  2443. return values.length ? `${blockName} :
  2444. ${values.join("\n")}` : `${blockName} :`;
  2445. }
  2446. };
  2447. __name(Constructed, "Constructed");
  2448. _a$v = Constructed;
  2449. (() => {
  2450. typeStore.Constructed = _a$v;
  2451. })();
  2452. Constructed.NAME = "CONSTRUCTED";
  2453. var LocalEndOfContentValueBlock = class extends ValueBlock {
  2454. fromBER(inputBuffer, inputOffset, inputLength) {
  2455. return inputOffset;
  2456. }
  2457. toBER(sizeOnly) {
  2458. return EMPTY_BUFFER;
  2459. }
  2460. };
  2461. __name(LocalEndOfContentValueBlock, "LocalEndOfContentValueBlock");
  2462. LocalEndOfContentValueBlock.override = "EndOfContentValueBlock";
  2463. var _a$u;
  2464. var EndOfContent = class extends BaseBlock {
  2465. constructor(parameters = {}) {
  2466. super(parameters, LocalEndOfContentValueBlock);
  2467. this.idBlock.tagClass = 1;
  2468. this.idBlock.tagNumber = 0;
  2469. }
  2470. };
  2471. __name(EndOfContent, "EndOfContent");
  2472. _a$u = EndOfContent;
  2473. (() => {
  2474. typeStore.EndOfContent = _a$u;
  2475. })();
  2476. EndOfContent.NAME = END_OF_CONTENT_NAME;
  2477. var _a$t;
  2478. var Null = class extends BaseBlock {
  2479. constructor(parameters = {}) {
  2480. super(parameters, ValueBlock);
  2481. this.idBlock.tagClass = 1;
  2482. this.idBlock.tagNumber = 5;
  2483. }
  2484. fromBER(inputBuffer, inputOffset, inputLength) {
  2485. if (this.lenBlock.length > 0)
  2486. this.warnings.push("Non-zero length of value block for Null type");
  2487. if (!this.idBlock.error.length)
  2488. this.blockLength += this.idBlock.blockLength;
  2489. if (!this.lenBlock.error.length)
  2490. this.blockLength += this.lenBlock.blockLength;
  2491. this.blockLength += inputLength;
  2492. if (inputOffset + inputLength > inputBuffer.byteLength) {
  2493. this.error = "End of input reached before message was fully decoded (inconsistent offset and length values)";
  2494. return -1;
  2495. }
  2496. return inputOffset + inputLength;
  2497. }
  2498. toBER(sizeOnly, writer) {
  2499. const retBuf = new ArrayBuffer(2);
  2500. if (!sizeOnly) {
  2501. const retView = new Uint8Array(retBuf);
  2502. retView[0] = 5;
  2503. retView[1] = 0;
  2504. }
  2505. if (writer) {
  2506. writer.write(retBuf);
  2507. }
  2508. return retBuf;
  2509. }
  2510. onAsciiEncoding() {
  2511. return `${this.constructor.NAME}`;
  2512. }
  2513. };
  2514. __name(Null, "Null");
  2515. _a$t = Null;
  2516. (() => {
  2517. typeStore.Null = _a$t;
  2518. })();
  2519. Null.NAME = "NULL";
  2520. var LocalBooleanValueBlock = class extends HexBlock(ValueBlock) {
  2521. constructor({ value, ...parameters } = {}) {
  2522. super(parameters);
  2523. if (parameters.valueHex) {
  2524. this.valueHexView = BufferSourceConverter.toUint8Array(parameters.valueHex);
  2525. } else {
  2526. this.valueHexView = new Uint8Array(1);
  2527. }
  2528. if (value) {
  2529. this.value = value;
  2530. }
  2531. }
  2532. get value() {
  2533. for (const octet of this.valueHexView) {
  2534. if (octet > 0) {
  2535. return true;
  2536. }
  2537. }
  2538. return false;
  2539. }
  2540. set value(value) {
  2541. this.valueHexView[0] = value ? 255 : 0;
  2542. }
  2543. fromBER(inputBuffer, inputOffset, inputLength) {
  2544. const inputView = BufferSourceConverter.toUint8Array(inputBuffer);
  2545. if (!checkBufferParams(this, inputView, inputOffset, inputLength)) {
  2546. return -1;
  2547. }
  2548. this.valueHexView = inputView.subarray(inputOffset, inputOffset + inputLength);
  2549. if (inputLength > 1)
  2550. this.warnings.push("Boolean value encoded in more then 1 octet");
  2551. this.isHexOnly = true;
  2552. utilDecodeTC.call(this);
  2553. this.blockLength = inputLength;
  2554. return inputOffset + inputLength;
  2555. }
  2556. toBER() {
  2557. return this.valueHexView.slice();
  2558. }
  2559. toJSON() {
  2560. return {
  2561. ...super.toJSON(),
  2562. value: this.value
  2563. };
  2564. }
  2565. };
  2566. __name(LocalBooleanValueBlock, "LocalBooleanValueBlock");
  2567. LocalBooleanValueBlock.NAME = "BooleanValueBlock";
  2568. var _a$s;
  2569. var Boolean = class extends BaseBlock {
  2570. constructor(parameters = {}) {
  2571. super(parameters, LocalBooleanValueBlock);
  2572. this.idBlock.tagClass = 1;
  2573. this.idBlock.tagNumber = 1;
  2574. }
  2575. getValue() {
  2576. return this.valueBlock.value;
  2577. }
  2578. setValue(value) {
  2579. this.valueBlock.value = value;
  2580. }
  2581. onAsciiEncoding() {
  2582. return `${this.constructor.NAME} : ${this.getValue}`;
  2583. }
  2584. };
  2585. __name(Boolean, "Boolean");
  2586. _a$s = Boolean;
  2587. (() => {
  2588. typeStore.Boolean = _a$s;
  2589. })();
  2590. Boolean.NAME = "BOOLEAN";
  2591. var LocalOctetStringValueBlock = class extends HexBlock(LocalConstructedValueBlock) {
  2592. constructor({ isConstructed = false, ...parameters } = {}) {
  2593. super(parameters);
  2594. this.isConstructed = isConstructed;
  2595. }
  2596. fromBER(inputBuffer, inputOffset, inputLength) {
  2597. let resultOffset = 0;
  2598. if (this.isConstructed) {
  2599. this.isHexOnly = false;
  2600. resultOffset = LocalConstructedValueBlock.prototype.fromBER.call(this, inputBuffer, inputOffset, inputLength);
  2601. if (resultOffset === -1)
  2602. return resultOffset;
  2603. for (let i = 0; i < this.value.length; i++) {
  2604. const currentBlockName = this.value[i].constructor.NAME;
  2605. if (currentBlockName === END_OF_CONTENT_NAME) {
  2606. if (this.isIndefiniteForm)
  2607. break;
  2608. else {
  2609. this.error = "EndOfContent is unexpected, OCTET STRING may consists of OCTET STRINGs only";
  2610. return -1;
  2611. }
  2612. }
  2613. if (currentBlockName !== OCTET_STRING_NAME) {
  2614. this.error = "OCTET STRING may consists of OCTET STRINGs only";
  2615. return -1;
  2616. }
  2617. }
  2618. } else {
  2619. this.isHexOnly = true;
  2620. resultOffset = super.fromBER(inputBuffer, inputOffset, inputLength);
  2621. this.blockLength = inputLength;
  2622. }
  2623. return resultOffset;
  2624. }
  2625. toBER(sizeOnly, writer) {
  2626. if (this.isConstructed)
  2627. return LocalConstructedValueBlock.prototype.toBER.call(this, sizeOnly, writer);
  2628. return sizeOnly ? new ArrayBuffer(this.valueHexView.byteLength) : this.valueHexView.slice().buffer;
  2629. }
  2630. toJSON() {
  2631. return {
  2632. ...super.toJSON(),
  2633. isConstructed: this.isConstructed
  2634. };
  2635. }
  2636. };
  2637. __name(LocalOctetStringValueBlock, "LocalOctetStringValueBlock");
  2638. LocalOctetStringValueBlock.NAME = "OctetStringValueBlock";
  2639. var _a$r;
  2640. var OctetString = class extends BaseBlock {
  2641. constructor({ idBlock = {}, lenBlock = {}, ...parameters } = {}) {
  2642. var _b, _c;
  2643. (_b = parameters.isConstructed) !== null && _b !== void 0 ? _b : parameters.isConstructed = !!((_c = parameters.value) === null || _c === void 0 ? void 0 : _c.length);
  2644. super({
  2645. idBlock: {
  2646. isConstructed: parameters.isConstructed,
  2647. ...idBlock
  2648. },
  2649. lenBlock: {
  2650. ...lenBlock,
  2651. isIndefiniteForm: !!parameters.isIndefiniteForm
  2652. },
  2653. ...parameters
  2654. }, LocalOctetStringValueBlock);
  2655. this.idBlock.tagClass = 1;
  2656. this.idBlock.tagNumber = 4;
  2657. }
  2658. fromBER(inputBuffer, inputOffset, inputLength) {
  2659. this.valueBlock.isConstructed = this.idBlock.isConstructed;
  2660. this.valueBlock.isIndefiniteForm = this.lenBlock.isIndefiniteForm;
  2661. if (inputLength === 0) {
  2662. if (this.idBlock.error.length === 0)
  2663. this.blockLength += this.idBlock.blockLength;
  2664. if (this.lenBlock.error.length === 0)
  2665. this.blockLength += this.lenBlock.blockLength;
  2666. return inputOffset;
  2667. }
  2668. if (!this.valueBlock.isConstructed) {
  2669. const view = inputBuffer instanceof ArrayBuffer ? new Uint8Array(inputBuffer) : inputBuffer;
  2670. const buf = view.subarray(inputOffset, inputOffset + inputLength);
  2671. try {
  2672. if (buf.byteLength) {
  2673. const asn = localFromBER(buf, 0, buf.byteLength);
  2674. if (asn.offset !== -1 && asn.offset === inputLength) {
  2675. this.valueBlock.value = [asn.result];
  2676. }
  2677. }
  2678. } catch (e) {
  2679. }
  2680. }
  2681. return super.fromBER(inputBuffer, inputOffset, inputLength);
  2682. }
  2683. onAsciiEncoding() {
  2684. if (this.valueBlock.isConstructed || this.valueBlock.value && this.valueBlock.value.length) {
  2685. return Constructed.prototype.onAsciiEncoding.call(this);
  2686. }
  2687. return `${this.constructor.NAME} : ${Convert.ToHex(this.valueBlock.valueHexView)}`;
  2688. }
  2689. getValue() {
  2690. if (!this.idBlock.isConstructed) {
  2691. return this.valueBlock.valueHexView.slice().buffer;
  2692. }
  2693. const array = [];
  2694. for (const content of this.valueBlock.value) {
  2695. if (content instanceof OctetString) {
  2696. array.push(content.valueBlock.valueHexView);
  2697. }
  2698. }
  2699. return BufferSourceConverter.concat(array);
  2700. }
  2701. };
  2702. __name(OctetString, "OctetString");
  2703. _a$r = OctetString;
  2704. (() => {
  2705. typeStore.OctetString = _a$r;
  2706. })();
  2707. OctetString.NAME = OCTET_STRING_NAME;
  2708. var LocalBitStringValueBlock = class extends HexBlock(LocalConstructedValueBlock) {
  2709. constructor({ unusedBits = 0, isConstructed = false, ...parameters } = {}) {
  2710. super(parameters);
  2711. this.unusedBits = unusedBits;
  2712. this.isConstructed = isConstructed;
  2713. this.blockLength = this.valueHexView.byteLength;
  2714. }
  2715. fromBER(inputBuffer, inputOffset, inputLength) {
  2716. if (!inputLength) {
  2717. return inputOffset;
  2718. }
  2719. let resultOffset = -1;
  2720. if (this.isConstructed) {
  2721. resultOffset = LocalConstructedValueBlock.prototype.fromBER.call(this, inputBuffer, inputOffset, inputLength);
  2722. if (resultOffset === -1)
  2723. return resultOffset;
  2724. for (const value of this.value) {
  2725. const currentBlockName = value.constructor.NAME;
  2726. if (currentBlockName === END_OF_CONTENT_NAME) {
  2727. if (this.isIndefiniteForm)
  2728. break;
  2729. else {
  2730. this.error = "EndOfContent is unexpected, BIT STRING may consists of BIT STRINGs only";
  2731. return -1;
  2732. }
  2733. }
  2734. if (currentBlockName !== BIT_STRING_NAME) {
  2735. this.error = "BIT STRING may consists of BIT STRINGs only";
  2736. return -1;
  2737. }
  2738. const valueBlock = value.valueBlock;
  2739. if (this.unusedBits > 0 && valueBlock.unusedBits > 0) {
  2740. this.error = 'Using of "unused bits" inside constructive BIT STRING allowed for least one only';
  2741. return -1;
  2742. }
  2743. this.unusedBits = valueBlock.unusedBits;
  2744. }
  2745. return resultOffset;
  2746. }
  2747. const inputView = BufferSourceConverter.toUint8Array(inputBuffer);
  2748. if (!checkBufferParams(this, inputView, inputOffset, inputLength)) {
  2749. return -1;
  2750. }
  2751. const intBuffer = inputView.subarray(inputOffset, inputOffset + inputLength);
  2752. this.unusedBits = intBuffer[0];
  2753. if (this.unusedBits > 7) {
  2754. this.error = "Unused bits for BitString must be in range 0-7";
  2755. return -1;
  2756. }
  2757. if (!this.unusedBits) {
  2758. const buf = intBuffer.subarray(1);
  2759. try {
  2760. if (buf.byteLength) {
  2761. const asn = localFromBER(buf, 0, buf.byteLength);
  2762. if (asn.offset !== -1 && asn.offset === inputLength - 1) {
  2763. this.value = [asn.result];
  2764. }
  2765. }
  2766. } catch (e) {
  2767. }
  2768. }
  2769. this.valueHexView = intBuffer.subarray(1);
  2770. this.blockLength = intBuffer.length;
  2771. return inputOffset + inputLength;
  2772. }
  2773. toBER(sizeOnly, writer) {
  2774. if (this.isConstructed) {
  2775. return LocalConstructedValueBlock.prototype.toBER.call(this, sizeOnly, writer);
  2776. }
  2777. if (sizeOnly) {
  2778. return new ArrayBuffer(this.valueHexView.byteLength + 1);
  2779. }
  2780. if (!this.valueHexView.byteLength) {
  2781. return EMPTY_BUFFER;
  2782. }
  2783. const retView = new Uint8Array(this.valueHexView.length + 1);
  2784. retView[0] = this.unusedBits;
  2785. retView.set(this.valueHexView, 1);
  2786. return retView.buffer;
  2787. }
  2788. toJSON() {
  2789. return {
  2790. ...super.toJSON(),
  2791. unusedBits: this.unusedBits,
  2792. isConstructed: this.isConstructed
  2793. };
  2794. }
  2795. };
  2796. __name(LocalBitStringValueBlock, "LocalBitStringValueBlock");
  2797. LocalBitStringValueBlock.NAME = "BitStringValueBlock";
  2798. var _a$q;
  2799. var BitString = class extends BaseBlock {
  2800. constructor({ idBlock = {}, lenBlock = {}, ...parameters } = {}) {
  2801. var _b, _c;
  2802. (_b = parameters.isConstructed) !== null && _b !== void 0 ? _b : parameters.isConstructed = !!((_c = parameters.value) === null || _c === void 0 ? void 0 : _c.length);
  2803. super({
  2804. idBlock: {
  2805. isConstructed: parameters.isConstructed,
  2806. ...idBlock
  2807. },
  2808. lenBlock: {
  2809. ...lenBlock,
  2810. isIndefiniteForm: !!parameters.isIndefiniteForm
  2811. },
  2812. ...parameters
  2813. }, LocalBitStringValueBlock);
  2814. this.idBlock.tagClass = 1;
  2815. this.idBlock.tagNumber = 3;
  2816. }
  2817. fromBER(inputBuffer, inputOffset, inputLength) {
  2818. this.valueBlock.isConstructed = this.idBlock.isConstructed;
  2819. this.valueBlock.isIndefiniteForm = this.lenBlock.isIndefiniteForm;
  2820. return super.fromBER(inputBuffer, inputOffset, inputLength);
  2821. }
  2822. onAsciiEncoding() {
  2823. if (this.valueBlock.isConstructed || this.valueBlock.value && this.valueBlock.value.length) {
  2824. return Constructed.prototype.onAsciiEncoding.call(this);
  2825. } else {
  2826. const bits = [];
  2827. const valueHex = this.valueBlock.valueHexView;
  2828. for (const byte of valueHex) {
  2829. bits.push(byte.toString(2).padStart(8, "0"));
  2830. }
  2831. const bitsStr = bits.join("");
  2832. return `${this.constructor.NAME} : ${bitsStr.substring(0, bitsStr.length - this.valueBlock.unusedBits)}`;
  2833. }
  2834. }
  2835. };
  2836. __name(BitString, "BitString");
  2837. _a$q = BitString;
  2838. (() => {
  2839. typeStore.BitString = _a$q;
  2840. })();
  2841. BitString.NAME = BIT_STRING_NAME;
  2842. var _a$p;
  2843. function viewAdd(first, second) {
  2844. const c = new Uint8Array([0]);
  2845. const firstView = new Uint8Array(first);
  2846. const secondView = new Uint8Array(second);
  2847. let firstViewCopy = firstView.slice(0);
  2848. const firstViewCopyLength = firstViewCopy.length - 1;
  2849. const secondViewCopy = secondView.slice(0);
  2850. const secondViewCopyLength = secondViewCopy.length - 1;
  2851. let value = 0;
  2852. const max = secondViewCopyLength < firstViewCopyLength ? firstViewCopyLength : secondViewCopyLength;
  2853. let counter = 0;
  2854. for (let i = max; i >= 0; i--, counter++) {
  2855. switch (true) {
  2856. case counter < secondViewCopy.length:
  2857. value = firstViewCopy[firstViewCopyLength - counter] + secondViewCopy[secondViewCopyLength - counter] + c[0];
  2858. break;
  2859. default:
  2860. value = firstViewCopy[firstViewCopyLength - counter] + c[0];
  2861. }
  2862. c[0] = value / 10;
  2863. switch (true) {
  2864. case counter >= firstViewCopy.length:
  2865. firstViewCopy = utilConcatView(new Uint8Array([value % 10]), firstViewCopy);
  2866. break;
  2867. default:
  2868. firstViewCopy[firstViewCopyLength - counter] = value % 10;
  2869. }
  2870. }
  2871. if (c[0] > 0)
  2872. firstViewCopy = utilConcatView(c, firstViewCopy);
  2873. return firstViewCopy;
  2874. }
  2875. __name(viewAdd, "viewAdd");
  2876. function power2(n) {
  2877. if (n >= powers2.length) {
  2878. for (let p = powers2.length; p <= n; p++) {
  2879. const c = new Uint8Array([0]);
  2880. let digits = powers2[p - 1].slice(0);
  2881. for (let i = digits.length - 1; i >= 0; i--) {
  2882. const newValue = new Uint8Array([(digits[i] << 1) + c[0]]);
  2883. c[0] = newValue[0] / 10;
  2884. digits[i] = newValue[0] % 10;
  2885. }
  2886. if (c[0] > 0)
  2887. digits = utilConcatView(c, digits);
  2888. powers2.push(digits);
  2889. }
  2890. }
  2891. return powers2[n];
  2892. }
  2893. __name(power2, "power2");
  2894. function viewSub(first, second) {
  2895. let b = 0;
  2896. const firstView = new Uint8Array(first);
  2897. const secondView = new Uint8Array(second);
  2898. const firstViewCopy = firstView.slice(0);
  2899. const firstViewCopyLength = firstViewCopy.length - 1;
  2900. const secondViewCopy = secondView.slice(0);
  2901. const secondViewCopyLength = secondViewCopy.length - 1;
  2902. let value;
  2903. let counter = 0;
  2904. for (let i = secondViewCopyLength; i >= 0; i--, counter++) {
  2905. value = firstViewCopy[firstViewCopyLength - counter] - secondViewCopy[secondViewCopyLength - counter] - b;
  2906. switch (true) {
  2907. case value < 0:
  2908. b = 1;
  2909. firstViewCopy[firstViewCopyLength - counter] = value + 10;
  2910. break;
  2911. default:
  2912. b = 0;
  2913. firstViewCopy[firstViewCopyLength - counter] = value;
  2914. }
  2915. }
  2916. if (b > 0) {
  2917. for (let i = firstViewCopyLength - secondViewCopyLength + 1; i >= 0; i--, counter++) {
  2918. value = firstViewCopy[firstViewCopyLength - counter] - b;
  2919. if (value < 0) {
  2920. b = 1;
  2921. firstViewCopy[firstViewCopyLength - counter] = value + 10;
  2922. } else {
  2923. b = 0;
  2924. firstViewCopy[firstViewCopyLength - counter] = value;
  2925. break;
  2926. }
  2927. }
  2928. }
  2929. return firstViewCopy.slice();
  2930. }
  2931. __name(viewSub, "viewSub");
  2932. var LocalIntegerValueBlock = class extends HexBlock(ValueBlock) {
  2933. constructor({ value, ...parameters } = {}) {
  2934. super(parameters);
  2935. this._valueDec = 0;
  2936. if (parameters.valueHex) {
  2937. this.setValueHex();
  2938. }
  2939. if (value !== void 0) {
  2940. this.valueDec = value;
  2941. }
  2942. }
  2943. setValueHex() {
  2944. if (this.valueHexView.length >= 4) {
  2945. this.warnings.push("Too big Integer for decoding, hex only");
  2946. this.isHexOnly = true;
  2947. this._valueDec = 0;
  2948. } else {
  2949. this.isHexOnly = false;
  2950. if (this.valueHexView.length > 0) {
  2951. this._valueDec = utilDecodeTC.call(this);
  2952. }
  2953. }
  2954. }
  2955. set valueDec(v) {
  2956. this._valueDec = v;
  2957. this.isHexOnly = false;
  2958. this.valueHexView = new Uint8Array(utilEncodeTC(v));
  2959. }
  2960. get valueDec() {
  2961. return this._valueDec;
  2962. }
  2963. fromDER(inputBuffer, inputOffset, inputLength, expectedLength = 0) {
  2964. const offset = this.fromBER(inputBuffer, inputOffset, inputLength);
  2965. if (offset === -1)
  2966. return offset;
  2967. const view = this.valueHexView;
  2968. if (view[0] === 0 && (view[1] & 128) !== 0) {
  2969. this.valueHexView = view.subarray(1);
  2970. } else {
  2971. if (expectedLength !== 0) {
  2972. if (view.length < expectedLength) {
  2973. if (expectedLength - view.length > 1)
  2974. expectedLength = view.length + 1;
  2975. this.valueHexView = view.subarray(expectedLength - view.length);
  2976. }
  2977. }
  2978. }
  2979. return offset;
  2980. }
  2981. toDER(sizeOnly = false) {
  2982. const view = this.valueHexView;
  2983. switch (true) {
  2984. case (view[0] & 128) !== 0:
  2985. {
  2986. const updatedView = new Uint8Array(this.valueHexView.length + 1);
  2987. updatedView[0] = 0;
  2988. updatedView.set(view, 1);
  2989. this.valueHexView = updatedView;
  2990. }
  2991. break;
  2992. case (view[0] === 0 && (view[1] & 128) === 0):
  2993. {
  2994. this.valueHexView = this.valueHexView.subarray(1);
  2995. }
  2996. break;
  2997. }
  2998. return this.toBER(sizeOnly);
  2999. }
  3000. fromBER(inputBuffer, inputOffset, inputLength) {
  3001. const resultOffset = super.fromBER(inputBuffer, inputOffset, inputLength);
  3002. if (resultOffset === -1) {
  3003. return resultOffset;
  3004. }
  3005. this.setValueHex();
  3006. return resultOffset;
  3007. }
  3008. toBER(sizeOnly) {
  3009. return sizeOnly ? new ArrayBuffer(this.valueHexView.length) : this.valueHexView.slice().buffer;
  3010. }
  3011. toJSON() {
  3012. return {
  3013. ...super.toJSON(),
  3014. valueDec: this.valueDec
  3015. };
  3016. }
  3017. toString() {
  3018. const firstBit = this.valueHexView.length * 8 - 1;
  3019. let digits = new Uint8Array(this.valueHexView.length * 8 / 3);
  3020. let bitNumber = 0;
  3021. let currentByte;
  3022. const asn1View = this.valueHexView;
  3023. let result = "";
  3024. let flag = false;
  3025. for (let byteNumber = asn1View.byteLength - 1; byteNumber >= 0; byteNumber--) {
  3026. currentByte = asn1View[byteNumber];
  3027. for (let i = 0; i < 8; i++) {
  3028. if ((currentByte & 1) === 1) {
  3029. switch (bitNumber) {
  3030. case firstBit:
  3031. digits = viewSub(power2(bitNumber), digits);
  3032. result = "-";
  3033. break;
  3034. default:
  3035. digits = viewAdd(digits, power2(bitNumber));
  3036. }
  3037. }
  3038. bitNumber++;
  3039. currentByte >>= 1;
  3040. }
  3041. }
  3042. for (let i = 0; i < digits.length; i++) {
  3043. if (digits[i])
  3044. flag = true;
  3045. if (flag)
  3046. result += digitsString.charAt(digits[i]);
  3047. }
  3048. if (flag === false)
  3049. result += digitsString.charAt(0);
  3050. return result;
  3051. }
  3052. };
  3053. __name(LocalIntegerValueBlock, "LocalIntegerValueBlock");
  3054. _a$p = LocalIntegerValueBlock;
  3055. LocalIntegerValueBlock.NAME = "IntegerValueBlock";
  3056. (() => {
  3057. Object.defineProperty(_a$p.prototype, "valueHex", {
  3058. set: function(v) {
  3059. this.valueHexView = new Uint8Array(v);
  3060. this.setValueHex();
  3061. },
  3062. get: function() {
  3063. return this.valueHexView.slice().buffer;
  3064. }
  3065. });
  3066. })();
  3067. var _a$o;
  3068. var Integer = class extends BaseBlock {
  3069. constructor(parameters = {}) {
  3070. super(parameters, LocalIntegerValueBlock);
  3071. this.idBlock.tagClass = 1;
  3072. this.idBlock.tagNumber = 2;
  3073. }
  3074. toBigInt() {
  3075. assertBigInt();
  3076. return BigInt(this.valueBlock.toString());
  3077. }
  3078. static fromBigInt(value) {
  3079. assertBigInt();
  3080. const bigIntValue = BigInt(value);
  3081. const writer = new ViewWriter();
  3082. const hex = bigIntValue.toString(16).replace(/^-/, "");
  3083. const view = new Uint8Array(Convert.FromHex(hex));
  3084. if (bigIntValue < 0) {
  3085. const first = new Uint8Array(view.length + (view[0] & 128 ? 1 : 0));
  3086. first[0] |= 128;
  3087. const firstInt = BigInt(`0x${Convert.ToHex(first)}`);
  3088. const secondInt = firstInt + bigIntValue;
  3089. const second = BufferSourceConverter.toUint8Array(Convert.FromHex(secondInt.toString(16)));
  3090. second[0] |= 128;
  3091. writer.write(second);
  3092. } else {
  3093. if (view[0] & 128) {
  3094. writer.write(new Uint8Array([0]));
  3095. }
  3096. writer.write(view);
  3097. }
  3098. const res = new Integer({
  3099. valueHex: writer.final()
  3100. });
  3101. return res;
  3102. }
  3103. convertToDER() {
  3104. const integer = new Integer({ valueHex: this.valueBlock.valueHexView });
  3105. integer.valueBlock.toDER();
  3106. return integer;
  3107. }
  3108. convertFromDER() {
  3109. return new Integer({
  3110. valueHex: this.valueBlock.valueHexView[0] === 0 ? this.valueBlock.valueHexView.subarray(1) : this.valueBlock.valueHexView
  3111. });
  3112. }
  3113. onAsciiEncoding() {
  3114. return `${this.constructor.NAME} : ${this.valueBlock.toString()}`;
  3115. }
  3116. };
  3117. __name(Integer, "Integer");
  3118. _a$o = Integer;
  3119. (() => {
  3120. typeStore.Integer = _a$o;
  3121. })();
  3122. Integer.NAME = "INTEGER";
  3123. var _a$n;
  3124. var Enumerated = class extends Integer {
  3125. constructor(parameters = {}) {
  3126. super(parameters);
  3127. this.idBlock.tagClass = 1;
  3128. this.idBlock.tagNumber = 10;
  3129. }
  3130. };
  3131. __name(Enumerated, "Enumerated");
  3132. _a$n = Enumerated;
  3133. (() => {
  3134. typeStore.Enumerated = _a$n;
  3135. })();
  3136. Enumerated.NAME = "ENUMERATED";
  3137. var LocalSidValueBlock = class extends HexBlock(ValueBlock) {
  3138. constructor({ valueDec = -1, isFirstSid = false, ...parameters } = {}) {
  3139. super(parameters);
  3140. this.valueDec = valueDec;
  3141. this.isFirstSid = isFirstSid;
  3142. }
  3143. fromBER(inputBuffer, inputOffset, inputLength) {
  3144. if (!inputLength) {
  3145. return inputOffset;
  3146. }
  3147. const inputView = BufferSourceConverter.toUint8Array(inputBuffer);
  3148. if (!checkBufferParams(this, inputView, inputOffset, inputLength)) {
  3149. return -1;
  3150. }
  3151. const intBuffer = inputView.subarray(inputOffset, inputOffset + inputLength);
  3152. this.valueHexView = new Uint8Array(inputLength);
  3153. for (let i = 0; i < inputLength; i++) {
  3154. this.valueHexView[i] = intBuffer[i] & 127;
  3155. this.blockLength++;
  3156. if ((intBuffer[i] & 128) === 0)
  3157. break;
  3158. }
  3159. const tempView = new Uint8Array(this.blockLength);
  3160. for (let i = 0; i < this.blockLength; i++) {
  3161. tempView[i] = this.valueHexView[i];
  3162. }
  3163. this.valueHexView = tempView;
  3164. if ((intBuffer[this.blockLength - 1] & 128) !== 0) {
  3165. this.error = "End of input reached before message was fully decoded";
  3166. return -1;
  3167. }
  3168. if (this.valueHexView[0] === 0)
  3169. this.warnings.push("Needlessly long format of SID encoding");
  3170. if (this.blockLength <= 8)
  3171. this.valueDec = utilFromBase(this.valueHexView, 7);
  3172. else {
  3173. this.isHexOnly = true;
  3174. this.warnings.push("Too big SID for decoding, hex only");
  3175. }
  3176. return inputOffset + this.blockLength;
  3177. }
  3178. set valueBigInt(value) {
  3179. assertBigInt();
  3180. let bits = BigInt(value).toString(2);
  3181. while (bits.length % 7) {
  3182. bits = "0" + bits;
  3183. }
  3184. const bytes = new Uint8Array(bits.length / 7);
  3185. for (let i = 0; i < bytes.length; i++) {
  3186. bytes[i] = parseInt(bits.slice(i * 7, i * 7 + 7), 2) + (i + 1 < bytes.length ? 128 : 0);
  3187. }
  3188. this.fromBER(bytes.buffer, 0, bytes.length);
  3189. }
  3190. toBER(sizeOnly) {
  3191. if (this.isHexOnly) {
  3192. if (sizeOnly)
  3193. return new ArrayBuffer(this.valueHexView.byteLength);
  3194. const curView = this.valueHexView;
  3195. const retView2 = new Uint8Array(this.blockLength);
  3196. for (let i = 0; i < this.blockLength - 1; i++)
  3197. retView2[i] = curView[i] | 128;
  3198. retView2[this.blockLength - 1] = curView[this.blockLength - 1];
  3199. return retView2.buffer;
  3200. }
  3201. const encodedBuf = utilToBase(this.valueDec, 7);
  3202. if (encodedBuf.byteLength === 0) {
  3203. this.error = "Error during encoding SID value";
  3204. return EMPTY_BUFFER;
  3205. }
  3206. const retView = new Uint8Array(encodedBuf.byteLength);
  3207. if (!sizeOnly) {
  3208. const encodedView = new Uint8Array(encodedBuf);
  3209. const len = encodedBuf.byteLength - 1;
  3210. for (let i = 0; i < len; i++)
  3211. retView[i] = encodedView[i] | 128;
  3212. retView[len] = encodedView[len];
  3213. }
  3214. return retView;
  3215. }
  3216. toString() {
  3217. let result = "";
  3218. if (this.isHexOnly)
  3219. result = Convert.ToHex(this.valueHexView);
  3220. else {
  3221. if (this.isFirstSid) {
  3222. let sidValue = this.valueDec;
  3223. if (this.valueDec <= 39)
  3224. result = "0.";
  3225. else {
  3226. if (this.valueDec <= 79) {
  3227. result = "1.";
  3228. sidValue -= 40;
  3229. } else {
  3230. result = "2.";
  3231. sidValue -= 80;
  3232. }
  3233. }
  3234. result += sidValue.toString();
  3235. } else
  3236. result = this.valueDec.toString();
  3237. }
  3238. return result;
  3239. }
  3240. toJSON() {
  3241. return {
  3242. ...super.toJSON(),
  3243. valueDec: this.valueDec,
  3244. isFirstSid: this.isFirstSid
  3245. };
  3246. }
  3247. };
  3248. __name(LocalSidValueBlock, "LocalSidValueBlock");
  3249. LocalSidValueBlock.NAME = "sidBlock";
  3250. var LocalObjectIdentifierValueBlock = class extends ValueBlock {
  3251. constructor({ value = EMPTY_STRING, ...parameters } = {}) {
  3252. super(parameters);
  3253. this.value = [];
  3254. if (value) {
  3255. this.fromString(value);
  3256. }
  3257. }
  3258. fromBER(inputBuffer, inputOffset, inputLength) {
  3259. let resultOffset = inputOffset;
  3260. while (inputLength > 0) {
  3261. const sidBlock = new LocalSidValueBlock();
  3262. resultOffset = sidBlock.fromBER(inputBuffer, resultOffset, inputLength);
  3263. if (resultOffset === -1) {
  3264. this.blockLength = 0;
  3265. this.error = sidBlock.error;
  3266. return resultOffset;
  3267. }
  3268. if (this.value.length === 0)
  3269. sidBlock.isFirstSid = true;
  3270. this.blockLength += sidBlock.blockLength;
  3271. inputLength -= sidBlock.blockLength;
  3272. this.value.push(sidBlock);
  3273. }
  3274. return resultOffset;
  3275. }
  3276. toBER(sizeOnly) {
  3277. const retBuffers = [];
  3278. for (let i = 0; i < this.value.length; i++) {
  3279. const valueBuf = this.value[i].toBER(sizeOnly);
  3280. if (valueBuf.byteLength === 0) {
  3281. this.error = this.value[i].error;
  3282. return EMPTY_BUFFER;
  3283. }
  3284. retBuffers.push(valueBuf);
  3285. }
  3286. return concat(retBuffers);
  3287. }
  3288. fromString(string) {
  3289. this.value = [];
  3290. let pos1 = 0;
  3291. let pos2 = 0;
  3292. let sid = "";
  3293. let flag = false;
  3294. do {
  3295. pos2 = string.indexOf(".", pos1);
  3296. if (pos2 === -1)
  3297. sid = string.substring(pos1);
  3298. else
  3299. sid = string.substring(pos1, pos2);
  3300. pos1 = pos2 + 1;
  3301. if (flag) {
  3302. const sidBlock = this.value[0];
  3303. let plus = 0;
  3304. switch (sidBlock.valueDec) {
  3305. case 0:
  3306. break;
  3307. case 1:
  3308. plus = 40;
  3309. break;
  3310. case 2:
  3311. plus = 80;
  3312. break;
  3313. default:
  3314. this.value = [];
  3315. return;
  3316. }
  3317. const parsedSID = parseInt(sid, 10);
  3318. if (isNaN(parsedSID))
  3319. return;
  3320. sidBlock.valueDec = parsedSID + plus;
  3321. flag = false;
  3322. } else {
  3323. const sidBlock = new LocalSidValueBlock();
  3324. if (sid > Number.MAX_SAFE_INTEGER) {
  3325. assertBigInt();
  3326. const sidValue = BigInt(sid);
  3327. sidBlock.valueBigInt = sidValue;
  3328. } else {
  3329. sidBlock.valueDec = parseInt(sid, 10);
  3330. if (isNaN(sidBlock.valueDec))
  3331. return;
  3332. }
  3333. if (!this.value.length) {
  3334. sidBlock.isFirstSid = true;
  3335. flag = true;
  3336. }
  3337. this.value.push(sidBlock);
  3338. }
  3339. } while (pos2 !== -1);
  3340. }
  3341. toString() {
  3342. let result = "";
  3343. let isHexOnly = false;
  3344. for (let i = 0; i < this.value.length; i++) {
  3345. isHexOnly = this.value[i].isHexOnly;
  3346. let sidStr = this.value[i].toString();
  3347. if (i !== 0)
  3348. result = `${result}.`;
  3349. if (isHexOnly) {
  3350. sidStr = `{${sidStr}}`;
  3351. if (this.value[i].isFirstSid)
  3352. result = `2.{${sidStr} - 80}`;
  3353. else
  3354. result += sidStr;
  3355. } else
  3356. result += sidStr;
  3357. }
  3358. return result;
  3359. }
  3360. toJSON() {
  3361. const object = {
  3362. ...super.toJSON(),
  3363. value: this.toString(),
  3364. sidArray: []
  3365. };
  3366. for (let i = 0; i < this.value.length; i++) {
  3367. object.sidArray.push(this.value[i].toJSON());
  3368. }
  3369. return object;
  3370. }
  3371. };
  3372. __name(LocalObjectIdentifierValueBlock, "LocalObjectIdentifierValueBlock");
  3373. LocalObjectIdentifierValueBlock.NAME = "ObjectIdentifierValueBlock";
  3374. var _a$m;
  3375. var ObjectIdentifier = class extends BaseBlock {
  3376. constructor(parameters = {}) {
  3377. super(parameters, LocalObjectIdentifierValueBlock);
  3378. this.idBlock.tagClass = 1;
  3379. this.idBlock.tagNumber = 6;
  3380. }
  3381. getValue() {
  3382. return this.valueBlock.toString();
  3383. }
  3384. setValue(value) {
  3385. this.valueBlock.fromString(value);
  3386. }
  3387. onAsciiEncoding() {
  3388. return `${this.constructor.NAME} : ${this.valueBlock.toString() || "empty"}`;
  3389. }
  3390. toJSON() {
  3391. return {
  3392. ...super.toJSON(),
  3393. value: this.getValue()
  3394. };
  3395. }
  3396. };
  3397. __name(ObjectIdentifier, "ObjectIdentifier");
  3398. _a$m = ObjectIdentifier;
  3399. (() => {
  3400. typeStore.ObjectIdentifier = _a$m;
  3401. })();
  3402. ObjectIdentifier.NAME = "OBJECT IDENTIFIER";
  3403. var LocalRelativeSidValueBlock = class extends HexBlock(LocalBaseBlock) {
  3404. constructor({ valueDec = 0, ...parameters } = {}) {
  3405. super(parameters);
  3406. this.valueDec = valueDec;
  3407. }
  3408. fromBER(inputBuffer, inputOffset, inputLength) {
  3409. if (inputLength === 0)
  3410. return inputOffset;
  3411. const inputView = BufferSourceConverter.toUint8Array(inputBuffer);
  3412. if (!checkBufferParams(this, inputView, inputOffset, inputLength))
  3413. return -1;
  3414. const intBuffer = inputView.subarray(inputOffset, inputOffset + inputLength);
  3415. this.valueHexView = new Uint8Array(inputLength);
  3416. for (let i = 0; i < inputLength; i++) {
  3417. this.valueHexView[i] = intBuffer[i] & 127;
  3418. this.blockLength++;
  3419. if ((intBuffer[i] & 128) === 0)
  3420. break;
  3421. }
  3422. const tempView = new Uint8Array(this.blockLength);
  3423. for (let i = 0; i < this.blockLength; i++)
  3424. tempView[i] = this.valueHexView[i];
  3425. this.valueHexView = tempView;
  3426. if ((intBuffer[this.blockLength - 1] & 128) !== 0) {
  3427. this.error = "End of input reached before message was fully decoded";
  3428. return -1;
  3429. }
  3430. if (this.valueHexView[0] === 0)
  3431. this.warnings.push("Needlessly long format of SID encoding");
  3432. if (this.blockLength <= 8)
  3433. this.valueDec = utilFromBase(this.valueHexView, 7);
  3434. else {
  3435. this.isHexOnly = true;
  3436. this.warnings.push("Too big SID for decoding, hex only");
  3437. }
  3438. return inputOffset + this.blockLength;
  3439. }
  3440. toBER(sizeOnly) {
  3441. if (this.isHexOnly) {
  3442. if (sizeOnly)
  3443. return new ArrayBuffer(this.valueHexView.byteLength);
  3444. const curView = this.valueHexView;
  3445. const retView2 = new Uint8Array(this.blockLength);
  3446. for (let i = 0; i < this.blockLength - 1; i++)
  3447. retView2[i] = curView[i] | 128;
  3448. retView2[this.blockLength - 1] = curView[this.blockLength - 1];
  3449. return retView2.buffer;
  3450. }
  3451. const encodedBuf = utilToBase(this.valueDec, 7);
  3452. if (encodedBuf.byteLength === 0) {
  3453. this.error = "Error during encoding SID value";
  3454. return EMPTY_BUFFER;
  3455. }
  3456. const retView = new Uint8Array(encodedBuf.byteLength);
  3457. if (!sizeOnly) {
  3458. const encodedView = new Uint8Array(encodedBuf);
  3459. const len = encodedBuf.byteLength - 1;
  3460. for (let i = 0; i < len; i++)
  3461. retView[i] = encodedView[i] | 128;
  3462. retView[len] = encodedView[len];
  3463. }
  3464. return retView.buffer;
  3465. }
  3466. toString() {
  3467. let result = "";
  3468. if (this.isHexOnly)
  3469. result = Convert.ToHex(this.valueHexView);
  3470. else {
  3471. result = this.valueDec.toString();
  3472. }
  3473. return result;
  3474. }
  3475. toJSON() {
  3476. return {
  3477. ...super.toJSON(),
  3478. valueDec: this.valueDec
  3479. };
  3480. }
  3481. };
  3482. __name(LocalRelativeSidValueBlock, "LocalRelativeSidValueBlock");
  3483. LocalRelativeSidValueBlock.NAME = "relativeSidBlock";
  3484. var LocalRelativeObjectIdentifierValueBlock = class extends ValueBlock {
  3485. constructor({ value = EMPTY_STRING, ...parameters } = {}) {
  3486. super(parameters);
  3487. this.value = [];
  3488. if (value) {
  3489. this.fromString(value);
  3490. }
  3491. }
  3492. fromBER(inputBuffer, inputOffset, inputLength) {
  3493. let resultOffset = inputOffset;
  3494. while (inputLength > 0) {
  3495. const sidBlock = new LocalRelativeSidValueBlock();
  3496. resultOffset = sidBlock.fromBER(inputBuffer, resultOffset, inputLength);
  3497. if (resultOffset === -1) {
  3498. this.blockLength = 0;
  3499. this.error = sidBlock.error;
  3500. return resultOffset;
  3501. }
  3502. this.blockLength += sidBlock.blockLength;
  3503. inputLength -= sidBlock.blockLength;
  3504. this.value.push(sidBlock);
  3505. }
  3506. return resultOffset;
  3507. }
  3508. toBER(sizeOnly, writer) {
  3509. const retBuffers = [];
  3510. for (let i = 0; i < this.value.length; i++) {
  3511. const valueBuf = this.value[i].toBER(sizeOnly);
  3512. if (valueBuf.byteLength === 0) {
  3513. this.error = this.value[i].error;
  3514. return EMPTY_BUFFER;
  3515. }
  3516. retBuffers.push(valueBuf);
  3517. }
  3518. return concat(retBuffers);
  3519. }
  3520. fromString(string) {
  3521. this.value = [];
  3522. let pos1 = 0;
  3523. let pos2 = 0;
  3524. let sid = "";
  3525. do {
  3526. pos2 = string.indexOf(".", pos1);
  3527. if (pos2 === -1)
  3528. sid = string.substring(pos1);
  3529. else
  3530. sid = string.substring(pos1, pos2);
  3531. pos1 = pos2 + 1;
  3532. const sidBlock = new LocalRelativeSidValueBlock();
  3533. sidBlock.valueDec = parseInt(sid, 10);
  3534. if (isNaN(sidBlock.valueDec))
  3535. return true;
  3536. this.value.push(sidBlock);
  3537. } while (pos2 !== -1);
  3538. return true;
  3539. }
  3540. toString() {
  3541. let result = "";
  3542. let isHexOnly = false;
  3543. for (let i = 0; i < this.value.length; i++) {
  3544. isHexOnly = this.value[i].isHexOnly;
  3545. let sidStr = this.value[i].toString();
  3546. if (i !== 0)
  3547. result = `${result}.`;
  3548. if (isHexOnly) {
  3549. sidStr = `{${sidStr}}`;
  3550. result += sidStr;
  3551. } else
  3552. result += sidStr;
  3553. }
  3554. return result;
  3555. }
  3556. toJSON() {
  3557. const object = {
  3558. ...super.toJSON(),
  3559. value: this.toString(),
  3560. sidArray: []
  3561. };
  3562. for (let i = 0; i < this.value.length; i++)
  3563. object.sidArray.push(this.value[i].toJSON());
  3564. return object;
  3565. }
  3566. };
  3567. __name(LocalRelativeObjectIdentifierValueBlock, "LocalRelativeObjectIdentifierValueBlock");
  3568. LocalRelativeObjectIdentifierValueBlock.NAME = "RelativeObjectIdentifierValueBlock";
  3569. var _a$l;
  3570. var RelativeObjectIdentifier = class extends BaseBlock {
  3571. constructor(parameters = {}) {
  3572. super(parameters, LocalRelativeObjectIdentifierValueBlock);
  3573. this.idBlock.tagClass = 1;
  3574. this.idBlock.tagNumber = 13;
  3575. }
  3576. getValue() {
  3577. return this.valueBlock.toString();
  3578. }
  3579. setValue(value) {
  3580. this.valueBlock.fromString(value);
  3581. }
  3582. onAsciiEncoding() {
  3583. return `${this.constructor.NAME} : ${this.valueBlock.toString() || "empty"}`;
  3584. }
  3585. toJSON() {
  3586. return {
  3587. ...super.toJSON(),
  3588. value: this.getValue()
  3589. };
  3590. }
  3591. };
  3592. __name(RelativeObjectIdentifier, "RelativeObjectIdentifier");
  3593. _a$l = RelativeObjectIdentifier;
  3594. (() => {
  3595. typeStore.RelativeObjectIdentifier = _a$l;
  3596. })();
  3597. RelativeObjectIdentifier.NAME = "RelativeObjectIdentifier";
  3598. var _a$k;
  3599. var Sequence = class extends Constructed {
  3600. constructor(parameters = {}) {
  3601. super(parameters);
  3602. this.idBlock.tagClass = 1;
  3603. this.idBlock.tagNumber = 16;
  3604. }
  3605. };
  3606. __name(Sequence, "Sequence");
  3607. _a$k = Sequence;
  3608. (() => {
  3609. typeStore.Sequence = _a$k;
  3610. })();
  3611. Sequence.NAME = "SEQUENCE";
  3612. var _a$j;
  3613. var Set = class extends Constructed {
  3614. constructor(parameters = {}) {
  3615. super(parameters);
  3616. this.idBlock.tagClass = 1;
  3617. this.idBlock.tagNumber = 17;
  3618. }
  3619. };
  3620. __name(Set, "Set");
  3621. _a$j = Set;
  3622. (() => {
  3623. typeStore.Set = _a$j;
  3624. })();
  3625. Set.NAME = "SET";
  3626. var LocalStringValueBlock = class extends HexBlock(ValueBlock) {
  3627. constructor({ ...parameters } = {}) {
  3628. super(parameters);
  3629. this.isHexOnly = true;
  3630. this.value = EMPTY_STRING;
  3631. }
  3632. toJSON() {
  3633. return {
  3634. ...super.toJSON(),
  3635. value: this.value
  3636. };
  3637. }
  3638. };
  3639. __name(LocalStringValueBlock, "LocalStringValueBlock");
  3640. LocalStringValueBlock.NAME = "StringValueBlock";
  3641. var LocalSimpleStringValueBlock = class extends LocalStringValueBlock {
  3642. };
  3643. __name(LocalSimpleStringValueBlock, "LocalSimpleStringValueBlock");
  3644. LocalSimpleStringValueBlock.NAME = "SimpleStringValueBlock";
  3645. var LocalSimpleStringBlock = class extends BaseStringBlock {
  3646. constructor({ ...parameters } = {}) {
  3647. super(parameters, LocalSimpleStringValueBlock);
  3648. }
  3649. fromBuffer(inputBuffer) {
  3650. this.valueBlock.value = String.fromCharCode.apply(null, BufferSourceConverter.toUint8Array(inputBuffer));
  3651. }
  3652. fromString(inputString) {
  3653. const strLen = inputString.length;
  3654. const view = this.valueBlock.valueHexView = new Uint8Array(strLen);
  3655. for (let i = 0; i < strLen; i++)
  3656. view[i] = inputString.charCodeAt(i);
  3657. this.valueBlock.value = inputString;
  3658. }
  3659. };
  3660. __name(LocalSimpleStringBlock, "LocalSimpleStringBlock");
  3661. LocalSimpleStringBlock.NAME = "SIMPLE STRING";
  3662. var LocalUtf8StringValueBlock = class extends LocalSimpleStringBlock {
  3663. fromBuffer(inputBuffer) {
  3664. this.valueBlock.valueHexView = BufferSourceConverter.toUint8Array(inputBuffer);
  3665. try {
  3666. this.valueBlock.value = Convert.ToUtf8String(inputBuffer);
  3667. } catch (ex) {
  3668. this.warnings.push(`Error during "decodeURIComponent": ${ex}, using raw string`);
  3669. this.valueBlock.value = Convert.ToBinary(inputBuffer);
  3670. }
  3671. }
  3672. fromString(inputString) {
  3673. this.valueBlock.valueHexView = new Uint8Array(Convert.FromUtf8String(inputString));
  3674. this.valueBlock.value = inputString;
  3675. }
  3676. };
  3677. __name(LocalUtf8StringValueBlock, "LocalUtf8StringValueBlock");
  3678. LocalUtf8StringValueBlock.NAME = "Utf8StringValueBlock";
  3679. var _a$i;
  3680. var Utf8String = class extends LocalUtf8StringValueBlock {
  3681. constructor(parameters = {}) {
  3682. super(parameters);
  3683. this.idBlock.tagClass = 1;
  3684. this.idBlock.tagNumber = 12;
  3685. }
  3686. };
  3687. __name(Utf8String, "Utf8String");
  3688. _a$i = Utf8String;
  3689. (() => {
  3690. typeStore.Utf8String = _a$i;
  3691. })();
  3692. Utf8String.NAME = "UTF8String";
  3693. var LocalBmpStringValueBlock = class extends LocalSimpleStringBlock {
  3694. fromBuffer(inputBuffer) {
  3695. this.valueBlock.value = Convert.ToUtf16String(inputBuffer);
  3696. this.valueBlock.valueHexView = BufferSourceConverter.toUint8Array(inputBuffer);
  3697. }
  3698. fromString(inputString) {
  3699. this.valueBlock.value = inputString;
  3700. this.valueBlock.valueHexView = new Uint8Array(Convert.FromUtf16String(inputString));
  3701. }
  3702. };
  3703. __name(LocalBmpStringValueBlock, "LocalBmpStringValueBlock");
  3704. LocalBmpStringValueBlock.NAME = "BmpStringValueBlock";
  3705. var _a$h;
  3706. var BmpString = class extends LocalBmpStringValueBlock {
  3707. constructor({ ...parameters } = {}) {
  3708. super(parameters);
  3709. this.idBlock.tagClass = 1;
  3710. this.idBlock.tagNumber = 30;
  3711. }
  3712. };
  3713. __name(BmpString, "BmpString");
  3714. _a$h = BmpString;
  3715. (() => {
  3716. typeStore.BmpString = _a$h;
  3717. })();
  3718. BmpString.NAME = "BMPString";
  3719. var LocalUniversalStringValueBlock = class extends LocalSimpleStringBlock {
  3720. fromBuffer(inputBuffer) {
  3721. const copyBuffer = ArrayBuffer.isView(inputBuffer) ? inputBuffer.slice().buffer : inputBuffer.slice(0);
  3722. const valueView = new Uint8Array(copyBuffer);
  3723. for (let i = 0; i < valueView.length; i += 4) {
  3724. valueView[i] = valueView[i + 3];
  3725. valueView[i + 1] = valueView[i + 2];
  3726. valueView[i + 2] = 0;
  3727. valueView[i + 3] = 0;
  3728. }
  3729. this.valueBlock.value = String.fromCharCode.apply(null, new Uint32Array(copyBuffer));
  3730. }
  3731. fromString(inputString) {
  3732. const strLength = inputString.length;
  3733. const valueHexView = this.valueBlock.valueHexView = new Uint8Array(strLength * 4);
  3734. for (let i = 0; i < strLength; i++) {
  3735. const codeBuf = utilToBase(inputString.charCodeAt(i), 8);
  3736. const codeView = new Uint8Array(codeBuf);
  3737. if (codeView.length > 4)
  3738. continue;
  3739. const dif = 4 - codeView.length;
  3740. for (let j = codeView.length - 1; j >= 0; j--)
  3741. valueHexView[i * 4 + j + dif] = codeView[j];
  3742. }
  3743. this.valueBlock.value = inputString;
  3744. }
  3745. };
  3746. __name(LocalUniversalStringValueBlock, "LocalUniversalStringValueBlock");
  3747. LocalUniversalStringValueBlock.NAME = "UniversalStringValueBlock";
  3748. var _a$g;
  3749. var UniversalString = class extends LocalUniversalStringValueBlock {
  3750. constructor({ ...parameters } = {}) {
  3751. super(parameters);
  3752. this.idBlock.tagClass = 1;
  3753. this.idBlock.tagNumber = 28;
  3754. }
  3755. };
  3756. __name(UniversalString, "UniversalString");
  3757. _a$g = UniversalString;
  3758. (() => {
  3759. typeStore.UniversalString = _a$g;
  3760. })();
  3761. UniversalString.NAME = "UniversalString";
  3762. var _a$f;
  3763. var NumericString = class extends LocalSimpleStringBlock {
  3764. constructor(parameters = {}) {
  3765. super(parameters);
  3766. this.idBlock.tagClass = 1;
  3767. this.idBlock.tagNumber = 18;
  3768. }
  3769. };
  3770. __name(NumericString, "NumericString");
  3771. _a$f = NumericString;
  3772. (() => {
  3773. typeStore.NumericString = _a$f;
  3774. })();
  3775. NumericString.NAME = "NumericString";
  3776. var _a$e;
  3777. var PrintableString = class extends LocalSimpleStringBlock {
  3778. constructor(parameters = {}) {
  3779. super(parameters);
  3780. this.idBlock.tagClass = 1;
  3781. this.idBlock.tagNumber = 19;
  3782. }
  3783. };
  3784. __name(PrintableString, "PrintableString");
  3785. _a$e = PrintableString;
  3786. (() => {
  3787. typeStore.PrintableString = _a$e;
  3788. })();
  3789. PrintableString.NAME = "PrintableString";
  3790. var _a$d;
  3791. var TeletexString = class extends LocalSimpleStringBlock {
  3792. constructor(parameters = {}) {
  3793. super(parameters);
  3794. this.idBlock.tagClass = 1;
  3795. this.idBlock.tagNumber = 20;
  3796. }
  3797. };
  3798. __name(TeletexString, "TeletexString");
  3799. _a$d = TeletexString;
  3800. (() => {
  3801. typeStore.TeletexString = _a$d;
  3802. })();
  3803. TeletexString.NAME = "TeletexString";
  3804. var _a$c;
  3805. var VideotexString = class extends LocalSimpleStringBlock {
  3806. constructor(parameters = {}) {
  3807. super(parameters);
  3808. this.idBlock.tagClass = 1;
  3809. this.idBlock.tagNumber = 21;
  3810. }
  3811. };
  3812. __name(VideotexString, "VideotexString");
  3813. _a$c = VideotexString;
  3814. (() => {
  3815. typeStore.VideotexString = _a$c;
  3816. })();
  3817. VideotexString.NAME = "VideotexString";
  3818. var _a$b;
  3819. var IA5String = class extends LocalSimpleStringBlock {
  3820. constructor(parameters = {}) {
  3821. super(parameters);
  3822. this.idBlock.tagClass = 1;
  3823. this.idBlock.tagNumber = 22;
  3824. }
  3825. };
  3826. __name(IA5String, "IA5String");
  3827. _a$b = IA5String;
  3828. (() => {
  3829. typeStore.IA5String = _a$b;
  3830. })();
  3831. IA5String.NAME = "IA5String";
  3832. var _a$a;
  3833. var GraphicString = class extends LocalSimpleStringBlock {
  3834. constructor(parameters = {}) {
  3835. super(parameters);
  3836. this.idBlock.tagClass = 1;
  3837. this.idBlock.tagNumber = 25;
  3838. }
  3839. };
  3840. __name(GraphicString, "GraphicString");
  3841. _a$a = GraphicString;
  3842. (() => {
  3843. typeStore.GraphicString = _a$a;
  3844. })();
  3845. GraphicString.NAME = "GraphicString";
  3846. var _a$9;
  3847. var VisibleString = class extends LocalSimpleStringBlock {
  3848. constructor(parameters = {}) {
  3849. super(parameters);
  3850. this.idBlock.tagClass = 1;
  3851. this.idBlock.tagNumber = 26;
  3852. }
  3853. };
  3854. __name(VisibleString, "VisibleString");
  3855. _a$9 = VisibleString;
  3856. (() => {
  3857. typeStore.VisibleString = _a$9;
  3858. })();
  3859. VisibleString.NAME = "VisibleString";
  3860. var _a$8;
  3861. var GeneralString = class extends LocalSimpleStringBlock {
  3862. constructor(parameters = {}) {
  3863. super(parameters);
  3864. this.idBlock.tagClass = 1;
  3865. this.idBlock.tagNumber = 27;
  3866. }
  3867. };
  3868. __name(GeneralString, "GeneralString");
  3869. _a$8 = GeneralString;
  3870. (() => {
  3871. typeStore.GeneralString = _a$8;
  3872. })();
  3873. GeneralString.NAME = "GeneralString";
  3874. var _a$7;
  3875. var CharacterString = class extends LocalSimpleStringBlock {
  3876. constructor(parameters = {}) {
  3877. super(parameters);
  3878. this.idBlock.tagClass = 1;
  3879. this.idBlock.tagNumber = 29;
  3880. }
  3881. };
  3882. __name(CharacterString, "CharacterString");
  3883. _a$7 = CharacterString;
  3884. (() => {
  3885. typeStore.CharacterString = _a$7;
  3886. })();
  3887. CharacterString.NAME = "CharacterString";
  3888. var _a$6;
  3889. var UTCTime = class extends VisibleString {
  3890. constructor({ value, valueDate, ...parameters } = {}) {
  3891. super(parameters);
  3892. this.year = 0;
  3893. this.month = 0;
  3894. this.day = 0;
  3895. this.hour = 0;
  3896. this.minute = 0;
  3897. this.second = 0;
  3898. if (value) {
  3899. this.fromString(value);
  3900. this.valueBlock.valueHexView = new Uint8Array(value.length);
  3901. for (let i = 0; i < value.length; i++)
  3902. this.valueBlock.valueHexView[i] = value.charCodeAt(i);
  3903. }
  3904. if (valueDate) {
  3905. this.fromDate(valueDate);
  3906. this.valueBlock.valueHexView = new Uint8Array(this.toBuffer());
  3907. }
  3908. this.idBlock.tagClass = 1;
  3909. this.idBlock.tagNumber = 23;
  3910. }
  3911. fromBuffer(inputBuffer) {
  3912. this.fromString(String.fromCharCode.apply(null, BufferSourceConverter.toUint8Array(inputBuffer)));
  3913. }
  3914. toBuffer() {
  3915. const str = this.toString();
  3916. const buffer = new ArrayBuffer(str.length);
  3917. const view = new Uint8Array(buffer);
  3918. for (let i = 0; i < str.length; i++)
  3919. view[i] = str.charCodeAt(i);
  3920. return buffer;
  3921. }
  3922. fromDate(inputDate) {
  3923. this.year = inputDate.getUTCFullYear();
  3924. this.month = inputDate.getUTCMonth() + 1;
  3925. this.day = inputDate.getUTCDate();
  3926. this.hour = inputDate.getUTCHours();
  3927. this.minute = inputDate.getUTCMinutes();
  3928. this.second = inputDate.getUTCSeconds();
  3929. }
  3930. toDate() {
  3931. return new Date(Date.UTC(this.year, this.month - 1, this.day, this.hour, this.minute, this.second));
  3932. }
  3933. fromString(inputString) {
  3934. const parser = /(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})Z/ig;
  3935. const parserArray = parser.exec(inputString);
  3936. if (parserArray === null) {
  3937. this.error = "Wrong input string for conversion";
  3938. return;
  3939. }
  3940. const year = parseInt(parserArray[1], 10);
  3941. if (year >= 50)
  3942. this.year = 1900 + year;
  3943. else
  3944. this.year = 2e3 + year;
  3945. this.month = parseInt(parserArray[2], 10);
  3946. this.day = parseInt(parserArray[3], 10);
  3947. this.hour = parseInt(parserArray[4], 10);
  3948. this.minute = parseInt(parserArray[5], 10);
  3949. this.second = parseInt(parserArray[6], 10);
  3950. }
  3951. toString(encoding = "iso") {
  3952. if (encoding === "iso") {
  3953. const outputArray = new Array(7);
  3954. outputArray[0] = padNumber(this.year < 2e3 ? this.year - 1900 : this.year - 2e3, 2);
  3955. outputArray[1] = padNumber(this.month, 2);
  3956. outputArray[2] = padNumber(this.day, 2);
  3957. outputArray[3] = padNumber(this.hour, 2);
  3958. outputArray[4] = padNumber(this.minute, 2);
  3959. outputArray[5] = padNumber(this.second, 2);
  3960. outputArray[6] = "Z";
  3961. return outputArray.join("");
  3962. }
  3963. return super.toString(encoding);
  3964. }
  3965. onAsciiEncoding() {
  3966. return `${this.constructor.NAME} : ${this.toDate().toISOString()}`;
  3967. }
  3968. toJSON() {
  3969. return {
  3970. ...super.toJSON(),
  3971. year: this.year,
  3972. month: this.month,
  3973. day: this.day,
  3974. hour: this.hour,
  3975. minute: this.minute,
  3976. second: this.second
  3977. };
  3978. }
  3979. };
  3980. __name(UTCTime, "UTCTime");
  3981. _a$6 = UTCTime;
  3982. (() => {
  3983. typeStore.UTCTime = _a$6;
  3984. })();
  3985. UTCTime.NAME = "UTCTime";
  3986. var _a$5;
  3987. var GeneralizedTime = class extends UTCTime {
  3988. constructor(parameters = {}) {
  3989. var _b;
  3990. super(parameters);
  3991. (_b = this.millisecond) !== null && _b !== void 0 ? _b : this.millisecond = 0;
  3992. this.idBlock.tagClass = 1;
  3993. this.idBlock.tagNumber = 24;
  3994. }
  3995. fromDate(inputDate) {
  3996. super.fromDate(inputDate);
  3997. this.millisecond = inputDate.getUTCMilliseconds();
  3998. }
  3999. toDate() {
  4000. return new Date(Date.UTC(this.year, this.month - 1, this.day, this.hour, this.minute, this.second, this.millisecond));
  4001. }
  4002. fromString(inputString) {
  4003. let isUTC = false;
  4004. let timeString = "";
  4005. let dateTimeString = "";
  4006. let fractionPart = 0;
  4007. let parser;
  4008. let hourDifference = 0;
  4009. let minuteDifference = 0;
  4010. if (inputString[inputString.length - 1] === "Z") {
  4011. timeString = inputString.substring(0, inputString.length - 1);
  4012. isUTC = true;
  4013. } else {
  4014. const number = new Number(inputString[inputString.length - 1]);
  4015. if (isNaN(number.valueOf()))
  4016. throw new Error("Wrong input string for conversion");
  4017. timeString = inputString;
  4018. }
  4019. if (isUTC) {
  4020. if (timeString.indexOf("+") !== -1)
  4021. throw new Error("Wrong input string for conversion");
  4022. if (timeString.indexOf("-") !== -1)
  4023. throw new Error("Wrong input string for conversion");
  4024. } else {
  4025. let multiplier = 1;
  4026. let differencePosition = timeString.indexOf("+");
  4027. let differenceString = "";
  4028. if (differencePosition === -1) {
  4029. differencePosition = timeString.indexOf("-");
  4030. multiplier = -1;
  4031. }
  4032. if (differencePosition !== -1) {
  4033. differenceString = timeString.substring(differencePosition + 1);
  4034. timeString = timeString.substring(0, differencePosition);
  4035. if (differenceString.length !== 2 && differenceString.length !== 4)
  4036. throw new Error("Wrong input string for conversion");
  4037. let number = parseInt(differenceString.substring(0, 2), 10);
  4038. if (isNaN(number.valueOf()))
  4039. throw new Error("Wrong input string for conversion");
  4040. hourDifference = multiplier * number;
  4041. if (differenceString.length === 4) {
  4042. number = parseInt(differenceString.substring(2, 4), 10);
  4043. if (isNaN(number.valueOf()))
  4044. throw new Error("Wrong input string for conversion");
  4045. minuteDifference = multiplier * number;
  4046. }
  4047. }
  4048. }
  4049. let fractionPointPosition = timeString.indexOf(".");
  4050. if (fractionPointPosition === -1)
  4051. fractionPointPosition = timeString.indexOf(",");
  4052. if (fractionPointPosition !== -1) {
  4053. const fractionPartCheck = new Number(`0${timeString.substring(fractionPointPosition)}`);
  4054. if (isNaN(fractionPartCheck.valueOf()))
  4055. throw new Error("Wrong input string for conversion");
  4056. fractionPart = fractionPartCheck.valueOf();
  4057. dateTimeString = timeString.substring(0, fractionPointPosition);
  4058. } else
  4059. dateTimeString = timeString;
  4060. switch (true) {
  4061. case dateTimeString.length === 8:
  4062. parser = /(\d{4})(\d{2})(\d{2})/ig;
  4063. if (fractionPointPosition !== -1)
  4064. throw new Error("Wrong input string for conversion");
  4065. break;
  4066. case dateTimeString.length === 10:
  4067. parser = /(\d{4})(\d{2})(\d{2})(\d{2})/ig;
  4068. if (fractionPointPosition !== -1) {
  4069. let fractionResult = 60 * fractionPart;
  4070. this.minute = Math.floor(fractionResult);
  4071. fractionResult = 60 * (fractionResult - this.minute);
  4072. this.second = Math.floor(fractionResult);
  4073. fractionResult = 1e3 * (fractionResult - this.second);
  4074. this.millisecond = Math.floor(fractionResult);
  4075. }
  4076. break;
  4077. case dateTimeString.length === 12:
  4078. parser = /(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})/ig;
  4079. if (fractionPointPosition !== -1) {
  4080. let fractionResult = 60 * fractionPart;
  4081. this.second = Math.floor(fractionResult);
  4082. fractionResult = 1e3 * (fractionResult - this.second);
  4083. this.millisecond = Math.floor(fractionResult);
  4084. }
  4085. break;
  4086. case dateTimeString.length === 14:
  4087. parser = /(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/ig;
  4088. if (fractionPointPosition !== -1) {
  4089. const fractionResult = 1e3 * fractionPart;
  4090. this.millisecond = Math.floor(fractionResult);
  4091. }
  4092. break;
  4093. default:
  4094. throw new Error("Wrong input string for conversion");
  4095. }
  4096. const parserArray = parser.exec(dateTimeString);
  4097. if (parserArray === null)
  4098. throw new Error("Wrong input string for conversion");
  4099. for (let j = 1; j < parserArray.length; j++) {
  4100. switch (j) {
  4101. case 1:
  4102. this.year = parseInt(parserArray[j], 10);
  4103. break;
  4104. case 2:
  4105. this.month = parseInt(parserArray[j], 10);
  4106. break;
  4107. case 3:
  4108. this.day = parseInt(parserArray[j], 10);
  4109. break;
  4110. case 4:
  4111. this.hour = parseInt(parserArray[j], 10) + hourDifference;
  4112. break;
  4113. case 5:
  4114. this.minute = parseInt(parserArray[j], 10) + minuteDifference;
  4115. break;
  4116. case 6:
  4117. this.second = parseInt(parserArray[j], 10);
  4118. break;
  4119. default:
  4120. throw new Error("Wrong input string for conversion");
  4121. }
  4122. }
  4123. if (isUTC === false) {
  4124. const tempDate = new Date(this.year, this.month, this.day, this.hour, this.minute, this.second, this.millisecond);
  4125. this.year = tempDate.getUTCFullYear();
  4126. this.month = tempDate.getUTCMonth();
  4127. this.day = tempDate.getUTCDay();
  4128. this.hour = tempDate.getUTCHours();
  4129. this.minute = tempDate.getUTCMinutes();
  4130. this.second = tempDate.getUTCSeconds();
  4131. this.millisecond = tempDate.getUTCMilliseconds();
  4132. }
  4133. }
  4134. toString(encoding = "iso") {
  4135. if (encoding === "iso") {
  4136. const outputArray = [];
  4137. outputArray.push(padNumber(this.year, 4));
  4138. outputArray.push(padNumber(this.month, 2));
  4139. outputArray.push(padNumber(this.day, 2));
  4140. outputArray.push(padNumber(this.hour, 2));
  4141. outputArray.push(padNumber(this.minute, 2));
  4142. outputArray.push(padNumber(this.second, 2));
  4143. if (this.millisecond !== 0) {
  4144. outputArray.push(".");
  4145. outputArray.push(padNumber(this.millisecond, 3));
  4146. }
  4147. outputArray.push("Z");
  4148. return outputArray.join("");
  4149. }
  4150. return super.toString(encoding);
  4151. }
  4152. toJSON() {
  4153. return {
  4154. ...super.toJSON(),
  4155. millisecond: this.millisecond
  4156. };
  4157. }
  4158. };
  4159. __name(GeneralizedTime, "GeneralizedTime");
  4160. _a$5 = GeneralizedTime;
  4161. (() => {
  4162. typeStore.GeneralizedTime = _a$5;
  4163. })();
  4164. GeneralizedTime.NAME = "GeneralizedTime";
  4165. var _a$4;
  4166. var DATE = class extends Utf8String {
  4167. constructor(parameters = {}) {
  4168. super(parameters);
  4169. this.idBlock.tagClass = 1;
  4170. this.idBlock.tagNumber = 31;
  4171. }
  4172. };
  4173. __name(DATE, "DATE");
  4174. _a$4 = DATE;
  4175. (() => {
  4176. typeStore.DATE = _a$4;
  4177. })();
  4178. DATE.NAME = "DATE";
  4179. var _a$3;
  4180. var TimeOfDay = class extends Utf8String {
  4181. constructor(parameters = {}) {
  4182. super(parameters);
  4183. this.idBlock.tagClass = 1;
  4184. this.idBlock.tagNumber = 32;
  4185. }
  4186. };
  4187. __name(TimeOfDay, "TimeOfDay");
  4188. _a$3 = TimeOfDay;
  4189. (() => {
  4190. typeStore.TimeOfDay = _a$3;
  4191. })();
  4192. TimeOfDay.NAME = "TimeOfDay";
  4193. var _a$2;
  4194. var DateTime = class extends Utf8String {
  4195. constructor(parameters = {}) {
  4196. super(parameters);
  4197. this.idBlock.tagClass = 1;
  4198. this.idBlock.tagNumber = 33;
  4199. }
  4200. };
  4201. __name(DateTime, "DateTime");
  4202. _a$2 = DateTime;
  4203. (() => {
  4204. typeStore.DateTime = _a$2;
  4205. })();
  4206. DateTime.NAME = "DateTime";
  4207. var _a$1;
  4208. var Duration = class extends Utf8String {
  4209. constructor(parameters = {}) {
  4210. super(parameters);
  4211. this.idBlock.tagClass = 1;
  4212. this.idBlock.tagNumber = 34;
  4213. }
  4214. };
  4215. __name(Duration, "Duration");
  4216. _a$1 = Duration;
  4217. (() => {
  4218. typeStore.Duration = _a$1;
  4219. })();
  4220. Duration.NAME = "Duration";
  4221. var _a;
  4222. var TIME = class extends Utf8String {
  4223. constructor(parameters = {}) {
  4224. super(parameters);
  4225. this.idBlock.tagClass = 1;
  4226. this.idBlock.tagNumber = 14;
  4227. }
  4228. };
  4229. __name(TIME, "TIME");
  4230. _a = TIME;
  4231. (() => {
  4232. typeStore.TIME = _a;
  4233. })();
  4234. TIME.NAME = "TIME";
  4235. var Any = class {
  4236. constructor({ name = EMPTY_STRING, optional = false } = {}) {
  4237. this.name = name;
  4238. this.optional = optional;
  4239. }
  4240. };
  4241. __name(Any, "Any");
  4242. var Choice = class extends Any {
  4243. constructor({ value = [], ...parameters } = {}) {
  4244. super(parameters);
  4245. this.value = value;
  4246. }
  4247. };
  4248. __name(Choice, "Choice");
  4249. var Repeated = class extends Any {
  4250. constructor({ value = new Any(), local = false, ...parameters } = {}) {
  4251. super(parameters);
  4252. this.value = value;
  4253. this.local = local;
  4254. }
  4255. };
  4256. __name(Repeated, "Repeated");
  4257. var RawData = class {
  4258. constructor({ data = EMPTY_VIEW } = {}) {
  4259. this.dataView = BufferSourceConverter.toUint8Array(data);
  4260. }
  4261. get data() {
  4262. return this.dataView.slice().buffer;
  4263. }
  4264. set data(value) {
  4265. this.dataView = BufferSourceConverter.toUint8Array(value);
  4266. }
  4267. fromBER(inputBuffer, inputOffset, inputLength) {
  4268. const endLength = inputOffset + inputLength;
  4269. this.dataView = BufferSourceConverter.toUint8Array(inputBuffer).subarray(inputOffset, endLength);
  4270. return endLength;
  4271. }
  4272. toBER(sizeOnly) {
  4273. return this.dataView.slice().buffer;
  4274. }
  4275. };
  4276. __name(RawData, "RawData");
  4277. function compareSchema(root, inputData, inputSchema) {
  4278. if (inputSchema instanceof Choice) {
  4279. for (let j = 0; j < inputSchema.value.length; j++) {
  4280. const result = compareSchema(root, inputData, inputSchema.value[j]);
  4281. if (result.verified) {
  4282. return {
  4283. verified: true,
  4284. result: root
  4285. };
  4286. }
  4287. }
  4288. {
  4289. const _result = {
  4290. verified: false,
  4291. result: {
  4292. error: "Wrong values for Choice type"
  4293. }
  4294. };
  4295. if (inputSchema.hasOwnProperty(NAME))
  4296. _result.name = inputSchema.name;
  4297. return _result;
  4298. }
  4299. }
  4300. if (inputSchema instanceof Any) {
  4301. if (inputSchema.hasOwnProperty(NAME))
  4302. root[inputSchema.name] = inputData;
  4303. return {
  4304. verified: true,
  4305. result: root
  4306. };
  4307. }
  4308. if (root instanceof Object === false) {
  4309. return {
  4310. verified: false,
  4311. result: { error: "Wrong root object" }
  4312. };
  4313. }
  4314. if (inputData instanceof Object === false) {
  4315. return {
  4316. verified: false,
  4317. result: { error: "Wrong ASN.1 data" }
  4318. };
  4319. }
  4320. if (inputSchema instanceof Object === false) {
  4321. return {
  4322. verified: false,
  4323. result: { error: "Wrong ASN.1 schema" }
  4324. };
  4325. }
  4326. if (ID_BLOCK in inputSchema === false) {
  4327. return {
  4328. verified: false,
  4329. result: { error: "Wrong ASN.1 schema" }
  4330. };
  4331. }
  4332. if (FROM_BER in inputSchema.idBlock === false) {
  4333. return {
  4334. verified: false,
  4335. result: { error: "Wrong ASN.1 schema" }
  4336. };
  4337. }
  4338. if (TO_BER in inputSchema.idBlock === false) {
  4339. return {
  4340. verified: false,
  4341. result: { error: "Wrong ASN.1 schema" }
  4342. };
  4343. }
  4344. const encodedId = inputSchema.idBlock.toBER(false);
  4345. if (encodedId.byteLength === 0) {
  4346. return {
  4347. verified: false,
  4348. result: { error: "Error encoding idBlock for ASN.1 schema" }
  4349. };
  4350. }
  4351. const decodedOffset = inputSchema.idBlock.fromBER(encodedId, 0, encodedId.byteLength);
  4352. if (decodedOffset === -1) {
  4353. return {
  4354. verified: false,
  4355. result: { error: "Error decoding idBlock for ASN.1 schema" }
  4356. };
  4357. }
  4358. if (inputSchema.idBlock.hasOwnProperty(TAG_CLASS) === false) {
  4359. return {
  4360. verified: false,
  4361. result: { error: "Wrong ASN.1 schema" }
  4362. };
  4363. }
  4364. if (inputSchema.idBlock.tagClass !== inputData.idBlock.tagClass) {
  4365. return {
  4366. verified: false,
  4367. result: root
  4368. };
  4369. }
  4370. if (inputSchema.idBlock.hasOwnProperty(TAG_NUMBER) === false) {
  4371. return {
  4372. verified: false,
  4373. result: { error: "Wrong ASN.1 schema" }
  4374. };
  4375. }
  4376. if (inputSchema.idBlock.tagNumber !== inputData.idBlock.tagNumber) {
  4377. return {
  4378. verified: false,
  4379. result: root
  4380. };
  4381. }
  4382. if (inputSchema.idBlock.hasOwnProperty(IS_CONSTRUCTED) === false) {
  4383. return {
  4384. verified: false,
  4385. result: { error: "Wrong ASN.1 schema" }
  4386. };
  4387. }
  4388. if (inputSchema.idBlock.isConstructed !== inputData.idBlock.isConstructed) {
  4389. return {
  4390. verified: false,
  4391. result: root
  4392. };
  4393. }
  4394. if (!(IS_HEX_ONLY in inputSchema.idBlock)) {
  4395. return {
  4396. verified: false,
  4397. result: { error: "Wrong ASN.1 schema" }
  4398. };
  4399. }
  4400. if (inputSchema.idBlock.isHexOnly !== inputData.idBlock.isHexOnly) {
  4401. return {
  4402. verified: false,
  4403. result: root
  4404. };
  4405. }
  4406. if (inputSchema.idBlock.isHexOnly) {
  4407. if (VALUE_HEX_VIEW in inputSchema.idBlock === false) {
  4408. return {
  4409. verified: false,
  4410. result: { error: "Wrong ASN.1 schema" }
  4411. };
  4412. }
  4413. const schemaView = inputSchema.idBlock.valueHexView;
  4414. const asn1View = inputData.idBlock.valueHexView;
  4415. if (schemaView.length !== asn1View.length) {
  4416. return {
  4417. verified: false,
  4418. result: root
  4419. };
  4420. }
  4421. for (let i = 0; i < schemaView.length; i++) {
  4422. if (schemaView[i] !== asn1View[1]) {
  4423. return {
  4424. verified: false,
  4425. result: root
  4426. };
  4427. }
  4428. }
  4429. }
  4430. if (inputSchema.name) {
  4431. inputSchema.name = inputSchema.name.replace(/^\s+|\s+$/g, EMPTY_STRING);
  4432. if (inputSchema.name)
  4433. root[inputSchema.name] = inputData;
  4434. }
  4435. if (inputSchema instanceof typeStore.Constructed) {
  4436. let admission = 0;
  4437. let result = {
  4438. verified: false,
  4439. result: {
  4440. error: "Unknown error"
  4441. }
  4442. };
  4443. let maxLength = inputSchema.valueBlock.value.length;
  4444. if (maxLength > 0) {
  4445. if (inputSchema.valueBlock.value[0] instanceof Repeated) {
  4446. maxLength = inputData.valueBlock.value.length;
  4447. }
  4448. }
  4449. if (maxLength === 0) {
  4450. return {
  4451. verified: true,
  4452. result: root
  4453. };
  4454. }
  4455. if (inputData.valueBlock.value.length === 0 && inputSchema.valueBlock.value.length !== 0) {
  4456. let _optional = true;
  4457. for (let i = 0; i < inputSchema.valueBlock.value.length; i++)
  4458. _optional = _optional && (inputSchema.valueBlock.value[i].optional || false);
  4459. if (_optional) {
  4460. return {
  4461. verified: true,
  4462. result: root
  4463. };
  4464. }
  4465. if (inputSchema.name) {
  4466. inputSchema.name = inputSchema.name.replace(/^\s+|\s+$/g, EMPTY_STRING);
  4467. if (inputSchema.name)
  4468. delete root[inputSchema.name];
  4469. }
  4470. root.error = "Inconsistent object length";
  4471. return {
  4472. verified: false,
  4473. result: root
  4474. };
  4475. }
  4476. for (let i = 0; i < maxLength; i++) {
  4477. if (i - admission >= inputData.valueBlock.value.length) {
  4478. if (inputSchema.valueBlock.value[i].optional === false) {
  4479. const _result = {
  4480. verified: false,
  4481. result: root
  4482. };
  4483. root.error = "Inconsistent length between ASN.1 data and schema";
  4484. if (inputSchema.name) {
  4485. inputSchema.name = inputSchema.name.replace(/^\s+|\s+$/g, EMPTY_STRING);
  4486. if (inputSchema.name) {
  4487. delete root[inputSchema.name];
  4488. _result.name = inputSchema.name;
  4489. }
  4490. }
  4491. return _result;
  4492. }
  4493. } else {
  4494. if (inputSchema.valueBlock.value[0] instanceof Repeated) {
  4495. result = compareSchema(root, inputData.valueBlock.value[i], inputSchema.valueBlock.value[0].value);
  4496. if (result.verified === false) {
  4497. if (inputSchema.valueBlock.value[0].optional)
  4498. admission++;
  4499. else {
  4500. if (inputSchema.name) {
  4501. inputSchema.name = inputSchema.name.replace(/^\s+|\s+$/g, EMPTY_STRING);
  4502. if (inputSchema.name)
  4503. delete root[inputSchema.name];
  4504. }
  4505. return result;
  4506. }
  4507. }
  4508. if (NAME in inputSchema.valueBlock.value[0] && inputSchema.valueBlock.value[0].name.length > 0) {
  4509. let arrayRoot = {};
  4510. if (LOCAL in inputSchema.valueBlock.value[0] && inputSchema.valueBlock.value[0].local)
  4511. arrayRoot = inputData;
  4512. else
  4513. arrayRoot = root;
  4514. if (typeof arrayRoot[inputSchema.valueBlock.value[0].name] === "undefined")
  4515. arrayRoot[inputSchema.valueBlock.value[0].name] = [];
  4516. arrayRoot[inputSchema.valueBlock.value[0].name].push(inputData.valueBlock.value[i]);
  4517. }
  4518. } else {
  4519. result = compareSchema(root, inputData.valueBlock.value[i - admission], inputSchema.valueBlock.value[i]);
  4520. if (result.verified === false) {
  4521. if (inputSchema.valueBlock.value[i].optional)
  4522. admission++;
  4523. else {
  4524. if (inputSchema.name) {
  4525. inputSchema.name = inputSchema.name.replace(/^\s+|\s+$/g, EMPTY_STRING);
  4526. if (inputSchema.name)
  4527. delete root[inputSchema.name];
  4528. }
  4529. return result;
  4530. }
  4531. }
  4532. }
  4533. }
  4534. }
  4535. if (result.verified === false) {
  4536. const _result = {
  4537. verified: false,
  4538. result: root
  4539. };
  4540. if (inputSchema.name) {
  4541. inputSchema.name = inputSchema.name.replace(/^\s+|\s+$/g, EMPTY_STRING);
  4542. if (inputSchema.name) {
  4543. delete root[inputSchema.name];
  4544. _result.name = inputSchema.name;
  4545. }
  4546. }
  4547. return _result;
  4548. }
  4549. return {
  4550. verified: true,
  4551. result: root
  4552. };
  4553. }
  4554. if (inputSchema.primitiveSchema && VALUE_HEX_VIEW in inputData.valueBlock) {
  4555. const asn1 = localFromBER(inputData.valueBlock.valueHexView);
  4556. if (asn1.offset === -1) {
  4557. const _result = {
  4558. verified: false,
  4559. result: asn1.result
  4560. };
  4561. if (inputSchema.name) {
  4562. inputSchema.name = inputSchema.name.replace(/^\s+|\s+$/g, EMPTY_STRING);
  4563. if (inputSchema.name) {
  4564. delete root[inputSchema.name];
  4565. _result.name = inputSchema.name;
  4566. }
  4567. }
  4568. return _result;
  4569. }
  4570. return compareSchema(root, asn1.result, inputSchema.primitiveSchema);
  4571. }
  4572. return {
  4573. verified: true,
  4574. result: root
  4575. };
  4576. }
  4577. __name(compareSchema, "compareSchema");
  4578. function verifySchema(inputBuffer, inputSchema) {
  4579. if (inputSchema instanceof Object === false) {
  4580. return {
  4581. verified: false,
  4582. result: { error: "Wrong ASN.1 schema type" }
  4583. };
  4584. }
  4585. const asn1 = localFromBER(BufferSourceConverter.toUint8Array(inputBuffer));
  4586. if (asn1.offset === -1) {
  4587. return {
  4588. verified: false,
  4589. result: asn1.result
  4590. };
  4591. }
  4592. return compareSchema(asn1.result, asn1.result, inputSchema);
  4593. }
  4594. __name(verifySchema, "verifySchema");
  4595. // ../../node_modules/.pnpm/@peculiar+asn1-schema@2.3.0/node_modules/@peculiar/asn1-schema/build/es2015/enums.js
  4596. init_define_process();
  4597. var AsnTypeTypes;
  4598. (function(AsnTypeTypes2) {
  4599. AsnTypeTypes2[AsnTypeTypes2["Sequence"] = 0] = "Sequence";
  4600. AsnTypeTypes2[AsnTypeTypes2["Set"] = 1] = "Set";
  4601. AsnTypeTypes2[AsnTypeTypes2["Choice"] = 2] = "Choice";
  4602. })(AsnTypeTypes || (AsnTypeTypes = {}));
  4603. var AsnPropTypes;
  4604. (function(AsnPropTypes2) {
  4605. AsnPropTypes2[AsnPropTypes2["Any"] = 1] = "Any";
  4606. AsnPropTypes2[AsnPropTypes2["Boolean"] = 2] = "Boolean";
  4607. AsnPropTypes2[AsnPropTypes2["OctetString"] = 3] = "OctetString";
  4608. AsnPropTypes2[AsnPropTypes2["BitString"] = 4] = "BitString";
  4609. AsnPropTypes2[AsnPropTypes2["Integer"] = 5] = "Integer";
  4610. AsnPropTypes2[AsnPropTypes2["Enumerated"] = 6] = "Enumerated";
  4611. AsnPropTypes2[AsnPropTypes2["ObjectIdentifier"] = 7] = "ObjectIdentifier";
  4612. AsnPropTypes2[AsnPropTypes2["Utf8String"] = 8] = "Utf8String";
  4613. AsnPropTypes2[AsnPropTypes2["BmpString"] = 9] = "BmpString";
  4614. AsnPropTypes2[AsnPropTypes2["UniversalString"] = 10] = "UniversalString";
  4615. AsnPropTypes2[AsnPropTypes2["NumericString"] = 11] = "NumericString";
  4616. AsnPropTypes2[AsnPropTypes2["PrintableString"] = 12] = "PrintableString";
  4617. AsnPropTypes2[AsnPropTypes2["TeletexString"] = 13] = "TeletexString";
  4618. AsnPropTypes2[AsnPropTypes2["VideotexString"] = 14] = "VideotexString";
  4619. AsnPropTypes2[AsnPropTypes2["IA5String"] = 15] = "IA5String";
  4620. AsnPropTypes2[AsnPropTypes2["GraphicString"] = 16] = "GraphicString";
  4621. AsnPropTypes2[AsnPropTypes2["VisibleString"] = 17] = "VisibleString";
  4622. AsnPropTypes2[AsnPropTypes2["GeneralString"] = 18] = "GeneralString";
  4623. AsnPropTypes2[AsnPropTypes2["CharacterString"] = 19] = "CharacterString";
  4624. AsnPropTypes2[AsnPropTypes2["UTCTime"] = 20] = "UTCTime";
  4625. AsnPropTypes2[AsnPropTypes2["GeneralizedTime"] = 21] = "GeneralizedTime";
  4626. AsnPropTypes2[AsnPropTypes2["DATE"] = 22] = "DATE";
  4627. AsnPropTypes2[AsnPropTypes2["TimeOfDay"] = 23] = "TimeOfDay";
  4628. AsnPropTypes2[AsnPropTypes2["DateTime"] = 24] = "DateTime";
  4629. AsnPropTypes2[AsnPropTypes2["Duration"] = 25] = "Duration";
  4630. AsnPropTypes2[AsnPropTypes2["TIME"] = 26] = "TIME";
  4631. AsnPropTypes2[AsnPropTypes2["Null"] = 27] = "Null";
  4632. })(AsnPropTypes || (AsnPropTypes = {}));
  4633. // ../../node_modules/.pnpm/@peculiar+asn1-schema@2.3.0/node_modules/@peculiar/asn1-schema/build/es2015/converters.js
  4634. var AsnAnyConverter = {
  4635. fromASN: (value) => value instanceof Null ? null : value.valueBeforeDecodeView,
  4636. toASN: (value) => {
  4637. if (value === null) {
  4638. return new Null();
  4639. }
  4640. const schema = fromBER(value);
  4641. if (schema.result.error) {
  4642. throw new Error(schema.result.error);
  4643. }
  4644. return schema.result;
  4645. }
  4646. };
  4647. var AsnIntegerConverter = {
  4648. fromASN: (value) => value.valueBlock.valueHexView.byteLength >= 4 ? value.valueBlock.toString() : value.valueBlock.valueDec,
  4649. toASN: (value) => new Integer({ value: +value })
  4650. };
  4651. var AsnEnumeratedConverter = {
  4652. fromASN: (value) => value.valueBlock.valueDec,
  4653. toASN: (value) => new Enumerated({ value })
  4654. };
  4655. var AsnBitStringConverter = {
  4656. fromASN: (value) => value.valueBlock.valueHexView,
  4657. toASN: (value) => new BitString({ valueHex: value })
  4658. };
  4659. var AsnObjectIdentifierConverter = {
  4660. fromASN: (value) => value.valueBlock.toString(),
  4661. toASN: (value) => new ObjectIdentifier({ value })
  4662. };
  4663. var AsnBooleanConverter = {
  4664. fromASN: (value) => value.valueBlock.value,
  4665. toASN: (value) => new Boolean({ value })
  4666. };
  4667. var AsnOctetStringConverter = {
  4668. fromASN: (value) => value.valueBlock.valueHexView,
  4669. toASN: (value) => new OctetString({ valueHex: value })
  4670. };
  4671. function createStringConverter(Asn1Type) {
  4672. return {
  4673. fromASN: (value) => value.valueBlock.value,
  4674. toASN: (value) => new Asn1Type({ value })
  4675. };
  4676. }
  4677. __name(createStringConverter, "createStringConverter");
  4678. var AsnUtf8StringConverter = createStringConverter(Utf8String);
  4679. var AsnBmpStringConverter = createStringConverter(BmpString);
  4680. var AsnUniversalStringConverter = createStringConverter(UniversalString);
  4681. var AsnNumericStringConverter = createStringConverter(NumericString);
  4682. var AsnPrintableStringConverter = createStringConverter(PrintableString);
  4683. var AsnTeletexStringConverter = createStringConverter(TeletexString);
  4684. var AsnVideotexStringConverter = createStringConverter(VideotexString);
  4685. var AsnIA5StringConverter = createStringConverter(IA5String);
  4686. var AsnGraphicStringConverter = createStringConverter(GraphicString);
  4687. var AsnVisibleStringConverter = createStringConverter(VisibleString);
  4688. var AsnGeneralStringConverter = createStringConverter(GeneralString);
  4689. var AsnCharacterStringConverter = createStringConverter(CharacterString);
  4690. var AsnUTCTimeConverter = {
  4691. fromASN: (value) => value.toDate(),
  4692. toASN: (value) => new UTCTime({ valueDate: value })
  4693. };
  4694. var AsnGeneralizedTimeConverter = {
  4695. fromASN: (value) => value.toDate(),
  4696. toASN: (value) => new GeneralizedTime({ valueDate: value })
  4697. };
  4698. var AsnNullConverter = {
  4699. fromASN: () => null,
  4700. toASN: () => {
  4701. return new Null();
  4702. }
  4703. };
  4704. function defaultConverter(type) {
  4705. switch (type) {
  4706. case AsnPropTypes.Any:
  4707. return AsnAnyConverter;
  4708. case AsnPropTypes.BitString:
  4709. return AsnBitStringConverter;
  4710. case AsnPropTypes.BmpString:
  4711. return AsnBmpStringConverter;
  4712. case AsnPropTypes.Boolean:
  4713. return AsnBooleanConverter;
  4714. case AsnPropTypes.CharacterString:
  4715. return AsnCharacterStringConverter;
  4716. case AsnPropTypes.Enumerated:
  4717. return AsnEnumeratedConverter;
  4718. case AsnPropTypes.GeneralString:
  4719. return AsnGeneralStringConverter;
  4720. case AsnPropTypes.GeneralizedTime:
  4721. return AsnGeneralizedTimeConverter;
  4722. case AsnPropTypes.GraphicString:
  4723. return AsnGraphicStringConverter;
  4724. case AsnPropTypes.IA5String:
  4725. return AsnIA5StringConverter;
  4726. case AsnPropTypes.Integer:
  4727. return AsnIntegerConverter;
  4728. case AsnPropTypes.Null:
  4729. return AsnNullConverter;
  4730. case AsnPropTypes.NumericString:
  4731. return AsnNumericStringConverter;
  4732. case AsnPropTypes.ObjectIdentifier:
  4733. return AsnObjectIdentifierConverter;
  4734. case AsnPropTypes.OctetString:
  4735. return AsnOctetStringConverter;
  4736. case AsnPropTypes.PrintableString:
  4737. return AsnPrintableStringConverter;
  4738. case AsnPropTypes.TeletexString:
  4739. return AsnTeletexStringConverter;
  4740. case AsnPropTypes.UTCTime:
  4741. return AsnUTCTimeConverter;
  4742. case AsnPropTypes.UniversalString:
  4743. return AsnUniversalStringConverter;
  4744. case AsnPropTypes.Utf8String:
  4745. return AsnUtf8StringConverter;
  4746. case AsnPropTypes.VideotexString:
  4747. return AsnVideotexStringConverter;
  4748. case AsnPropTypes.VisibleString:
  4749. return AsnVisibleStringConverter;
  4750. default:
  4751. return null;
  4752. }
  4753. }
  4754. __name(defaultConverter, "defaultConverter");
  4755. // ../../node_modules/.pnpm/@peculiar+asn1-schema@2.3.0/node_modules/@peculiar/asn1-schema/build/es2015/types/index.js
  4756. init_define_process();
  4757. // ../../node_modules/.pnpm/@peculiar+asn1-schema@2.3.0/node_modules/@peculiar/asn1-schema/build/es2015/types/bit_string.js
  4758. init_define_process();
  4759. // ../../node_modules/.pnpm/@peculiar+asn1-schema@2.3.0/node_modules/@peculiar/asn1-schema/build/es2015/types/octet_string.js
  4760. init_define_process();
  4761. // ../../node_modules/.pnpm/@peculiar+asn1-schema@2.3.0/node_modules/@peculiar/asn1-schema/build/es2015/decorators.js
  4762. init_define_process();
  4763. // ../../node_modules/.pnpm/@peculiar+asn1-schema@2.3.0/node_modules/@peculiar/asn1-schema/build/es2015/storage.js
  4764. init_define_process();
  4765. // ../../node_modules/.pnpm/@peculiar+asn1-schema@2.3.0/node_modules/@peculiar/asn1-schema/build/es2015/schema.js
  4766. init_define_process();
  4767. // ../../node_modules/.pnpm/@peculiar+asn1-schema@2.3.0/node_modules/@peculiar/asn1-schema/build/es2015/helper.js
  4768. init_define_process();
  4769. function isConvertible(target) {
  4770. if (typeof target === "function" && target.prototype) {
  4771. if (target.prototype.toASN && target.prototype.fromASN) {
  4772. return true;
  4773. } else {
  4774. return isConvertible(target.prototype);
  4775. }
  4776. } else {
  4777. return !!(target && typeof target === "object" && "toASN" in target && "fromASN" in target);
  4778. }
  4779. }
  4780. __name(isConvertible, "isConvertible");
  4781. function isTypeOfArray(target) {
  4782. var _a2;
  4783. if (target) {
  4784. const proto = Object.getPrototypeOf(target);
  4785. if (((_a2 = proto === null || proto === void 0 ? void 0 : proto.prototype) === null || _a2 === void 0 ? void 0 : _a2.constructor) === Array) {
  4786. return true;
  4787. }
  4788. return isTypeOfArray(proto);
  4789. }
  4790. return false;
  4791. }
  4792. __name(isTypeOfArray, "isTypeOfArray");
  4793. function isArrayEqual(bytes1, bytes2) {
  4794. if (!(bytes1 && bytes2)) {
  4795. return false;
  4796. }
  4797. if (bytes1.byteLength !== bytes2.byteLength) {
  4798. return false;
  4799. }
  4800. const b1 = new Uint8Array(bytes1);
  4801. const b2 = new Uint8Array(bytes2);
  4802. for (let i = 0; i < bytes1.byteLength; i++) {
  4803. if (b1[i] !== b2[i]) {
  4804. return false;
  4805. }
  4806. }
  4807. return true;
  4808. }
  4809. __name(isArrayEqual, "isArrayEqual");
  4810. // ../../node_modules/.pnpm/@peculiar+asn1-schema@2.3.0/node_modules/@peculiar/asn1-schema/build/es2015/schema.js
  4811. var AsnSchemaStorage = class {
  4812. constructor() {
  4813. this.items = /* @__PURE__ */ new WeakMap();
  4814. }
  4815. has(target) {
  4816. return this.items.has(target);
  4817. }
  4818. get(target, checkSchema = false) {
  4819. const schema = this.items.get(target);
  4820. if (!schema) {
  4821. throw new Error(`Cannot get schema for '${target.prototype.constructor.name}' target`);
  4822. }
  4823. if (checkSchema && !schema.schema) {
  4824. throw new Error(`Schema '${target.prototype.constructor.name}' doesn't contain ASN.1 schema. Call 'AsnSchemaStorage.cache'.`);
  4825. }
  4826. return schema;
  4827. }
  4828. cache(target) {
  4829. const schema = this.get(target);
  4830. if (!schema.schema) {
  4831. schema.schema = this.create(target, true);
  4832. }
  4833. }
  4834. createDefault(target) {
  4835. const schema = {
  4836. type: AsnTypeTypes.Sequence,
  4837. items: {}
  4838. };
  4839. const parentSchema = this.findParentSchema(target);
  4840. if (parentSchema) {
  4841. Object.assign(schema, parentSchema);
  4842. schema.items = Object.assign({}, schema.items, parentSchema.items);
  4843. }
  4844. return schema;
  4845. }
  4846. create(target, useNames) {
  4847. const schema = this.items.get(target) || this.createDefault(target);
  4848. const asn1Value = [];
  4849. for (const key in schema.items) {
  4850. const item = schema.items[key];
  4851. const name = useNames ? key : "";
  4852. let asn1Item;
  4853. if (typeof item.type === "number") {
  4854. const Asn1TypeName = AsnPropTypes[item.type];
  4855. const Asn1Type = index_es_exports[Asn1TypeName];
  4856. if (!Asn1Type) {
  4857. throw new Error(`Cannot get ASN1 class by name '${Asn1TypeName}'`);
  4858. }
  4859. asn1Item = new Asn1Type({ name });
  4860. } else if (isConvertible(item.type)) {
  4861. const instance = new item.type();
  4862. asn1Item = instance.toSchema(name);
  4863. } else if (item.optional) {
  4864. const itemSchema = this.get(item.type);
  4865. if (itemSchema.type === AsnTypeTypes.Choice) {
  4866. asn1Item = new Any({ name });
  4867. } else {
  4868. asn1Item = this.create(item.type, false);
  4869. asn1Item.name = name;
  4870. }
  4871. } else {
  4872. asn1Item = new Any({ name });
  4873. }
  4874. const optional = !!item.optional || item.defaultValue !== void 0;
  4875. if (item.repeated) {
  4876. asn1Item.name = "";
  4877. const Container = item.repeated === "set" ? Set : Sequence;
  4878. asn1Item = new Container({
  4879. name: "",
  4880. value: [
  4881. new Repeated({
  4882. name,
  4883. value: asn1Item
  4884. })
  4885. ]
  4886. });
  4887. }
  4888. if (item.context !== null && item.context !== void 0) {
  4889. if (item.implicit) {
  4890. if (typeof item.type === "number" || isConvertible(item.type)) {
  4891. const Container = item.repeated ? Constructed : Primitive;
  4892. asn1Value.push(new Container({
  4893. name,
  4894. optional,
  4895. idBlock: {
  4896. tagClass: 3,
  4897. tagNumber: item.context
  4898. }
  4899. }));
  4900. } else {
  4901. this.cache(item.type);
  4902. const isRepeated = !!item.repeated;
  4903. let value = !isRepeated ? this.get(item.type, true).schema : asn1Item;
  4904. value = "valueBlock" in value ? value.valueBlock.value : value.value;
  4905. asn1Value.push(new Constructed({
  4906. name: !isRepeated ? name : "",
  4907. optional,
  4908. idBlock: {
  4909. tagClass: 3,
  4910. tagNumber: item.context
  4911. },
  4912. value
  4913. }));
  4914. }
  4915. } else {
  4916. asn1Value.push(new Constructed({
  4917. optional,
  4918. idBlock: {
  4919. tagClass: 3,
  4920. tagNumber: item.context
  4921. },
  4922. value: [asn1Item]
  4923. }));
  4924. }
  4925. } else {
  4926. asn1Item.optional = optional;
  4927. asn1Value.push(asn1Item);
  4928. }
  4929. }
  4930. switch (schema.type) {
  4931. case AsnTypeTypes.Sequence:
  4932. return new Sequence({ value: asn1Value, name: "" });
  4933. case AsnTypeTypes.Set:
  4934. return new Set({ value: asn1Value, name: "" });
  4935. case AsnTypeTypes.Choice:
  4936. return new Choice({ value: asn1Value, name: "" });
  4937. default:
  4938. throw new Error(`Unsupported ASN1 type in use`);
  4939. }
  4940. }
  4941. set(target, schema) {
  4942. this.items.set(target, schema);
  4943. return this;
  4944. }
  4945. findParentSchema(target) {
  4946. const parent = target.__proto__;
  4947. if (parent) {
  4948. const schema = this.items.get(parent);
  4949. return schema || this.findParentSchema(parent);
  4950. }
  4951. return null;
  4952. }
  4953. };
  4954. __name(AsnSchemaStorage, "AsnSchemaStorage");
  4955. // ../../node_modules/.pnpm/@peculiar+asn1-schema@2.3.0/node_modules/@peculiar/asn1-schema/build/es2015/storage.js
  4956. var schemaStorage = new AsnSchemaStorage();
  4957. // ../../node_modules/.pnpm/@peculiar+asn1-schema@2.3.0/node_modules/@peculiar/asn1-schema/build/es2015/decorators.js
  4958. var AsnType = /* @__PURE__ */ __name((options) => (target) => {
  4959. let schema;
  4960. if (!schemaStorage.has(target)) {
  4961. schema = schemaStorage.createDefault(target);
  4962. schemaStorage.set(target, schema);
  4963. } else {
  4964. schema = schemaStorage.get(target);
  4965. }
  4966. Object.assign(schema, options);
  4967. }, "AsnType");
  4968. var AsnProp = /* @__PURE__ */ __name((options) => (target, propertyKey) => {
  4969. let schema;
  4970. if (!schemaStorage.has(target.constructor)) {
  4971. schema = schemaStorage.createDefault(target.constructor);
  4972. schemaStorage.set(target.constructor, schema);
  4973. } else {
  4974. schema = schemaStorage.get(target.constructor);
  4975. }
  4976. const copyOptions = Object.assign({}, options);
  4977. if (typeof copyOptions.type === "number" && !copyOptions.converter) {
  4978. const defaultConverter2 = defaultConverter(options.type);
  4979. if (!defaultConverter2) {
  4980. throw new Error(`Cannot get default converter for property '${propertyKey}' of ${target.constructor.name}`);
  4981. }
  4982. copyOptions.converter = defaultConverter2;
  4983. }
  4984. schema.items[propertyKey] = copyOptions;
  4985. }, "AsnProp");
  4986. // ../../node_modules/.pnpm/@peculiar+asn1-schema@2.3.0/node_modules/@peculiar/asn1-schema/build/es2015/parser.js
  4987. init_define_process();
  4988. // ../../node_modules/.pnpm/@peculiar+asn1-schema@2.3.0/node_modules/@peculiar/asn1-schema/build/es2015/errors/index.js
  4989. init_define_process();
  4990. // ../../node_modules/.pnpm/@peculiar+asn1-schema@2.3.0/node_modules/@peculiar/asn1-schema/build/es2015/errors/schema_validation.js
  4991. init_define_process();
  4992. var AsnSchemaValidationError = class extends Error {
  4993. constructor() {
  4994. super(...arguments);
  4995. this.schemas = [];
  4996. }
  4997. };
  4998. __name(AsnSchemaValidationError, "AsnSchemaValidationError");
  4999. // ../../node_modules/.pnpm/@peculiar+asn1-schema@2.3.0/node_modules/@peculiar/asn1-schema/build/es2015/parser.js
  5000. var AsnParser = class {
  5001. static parse(data, target) {
  5002. const asn1Parsed = fromBER(data);
  5003. if (asn1Parsed.result.error) {
  5004. throw new Error(asn1Parsed.result.error);
  5005. }
  5006. const res = this.fromASN(asn1Parsed.result, target);
  5007. return res;
  5008. }
  5009. static fromASN(asn1Schema, target) {
  5010. var _a2;
  5011. try {
  5012. if (isConvertible(target)) {
  5013. const value = new target();
  5014. return value.fromASN(asn1Schema);
  5015. }
  5016. const schema = schemaStorage.get(target);
  5017. schemaStorage.cache(target);
  5018. let targetSchema = schema.schema;
  5019. if (asn1Schema.constructor === Constructed && schema.type !== AsnTypeTypes.Choice) {
  5020. targetSchema = new Constructed({
  5021. idBlock: {
  5022. tagClass: 3,
  5023. tagNumber: asn1Schema.idBlock.tagNumber
  5024. },
  5025. value: schema.schema.valueBlock.value
  5026. });
  5027. for (const key in schema.items) {
  5028. delete asn1Schema[key];
  5029. }
  5030. }
  5031. const asn1ComparedSchema = compareSchema({}, asn1Schema, targetSchema);
  5032. if (!asn1ComparedSchema.verified) {
  5033. throw new AsnSchemaValidationError(`Data does not match to ${target.name} ASN1 schema. ${asn1ComparedSchema.result.error}`);
  5034. }
  5035. const res = new target();
  5036. if (isTypeOfArray(target)) {
  5037. if (!("value" in asn1Schema.valueBlock && Array.isArray(asn1Schema.valueBlock.value))) {
  5038. throw new Error(`Cannot get items from the ASN.1 parsed value. ASN.1 object is not constructed.`);
  5039. }
  5040. const itemType = schema.itemType;
  5041. if (typeof itemType === "number") {
  5042. const converter = defaultConverter(itemType);
  5043. if (!converter) {
  5044. throw new Error(`Cannot get default converter for array item of ${target.name} ASN1 schema`);
  5045. }
  5046. return target.from(asn1Schema.valueBlock.value, (element) => converter.fromASN(element));
  5047. } else {
  5048. return target.from(asn1Schema.valueBlock.value, (element) => this.fromASN(element, itemType));
  5049. }
  5050. }
  5051. for (const key in schema.items) {
  5052. const asn1SchemaValue = asn1ComparedSchema.result[key];
  5053. if (!asn1SchemaValue) {
  5054. continue;
  5055. }
  5056. const schemaItem = schema.items[key];
  5057. const schemaItemType = schemaItem.type;
  5058. if (typeof schemaItemType === "number" || isConvertible(schemaItemType)) {
  5059. const converter = (_a2 = schemaItem.converter) !== null && _a2 !== void 0 ? _a2 : isConvertible(schemaItemType) ? new schemaItemType() : null;
  5060. if (!converter) {
  5061. throw new Error("Converter is empty");
  5062. }
  5063. if (schemaItem.repeated) {
  5064. if (schemaItem.implicit) {
  5065. const Container = schemaItem.repeated === "sequence" ? Sequence : Set;
  5066. const newItem = new Container();
  5067. newItem.valueBlock = asn1SchemaValue.valueBlock;
  5068. const newItemAsn = fromBER(newItem.toBER(false));
  5069. if (newItemAsn.offset === -1) {
  5070. throw new Error(`Cannot parse the child item. ${newItemAsn.result.error}`);
  5071. }
  5072. if (!("value" in newItemAsn.result.valueBlock && Array.isArray(newItemAsn.result.valueBlock.value))) {
  5073. throw new Error("Cannot get items from the ASN.1 parsed value. ASN.1 object is not constructed.");
  5074. }
  5075. const value = newItemAsn.result.valueBlock.value;
  5076. res[key] = Array.from(value, (element) => converter.fromASN(element));
  5077. } else {
  5078. res[key] = Array.from(asn1SchemaValue, (element) => converter.fromASN(element));
  5079. }
  5080. } else {
  5081. let value = asn1SchemaValue;
  5082. if (schemaItem.implicit) {
  5083. let newItem;
  5084. if (isConvertible(schemaItemType)) {
  5085. newItem = new schemaItemType().toSchema("");
  5086. } else {
  5087. const Asn1TypeName = AsnPropTypes[schemaItemType];
  5088. const Asn1Type = index_es_exports[Asn1TypeName];
  5089. if (!Asn1Type) {
  5090. throw new Error(`Cannot get '${Asn1TypeName}' class from asn1js module`);
  5091. }
  5092. newItem = new Asn1Type();
  5093. }
  5094. newItem.valueBlock = value.valueBlock;
  5095. value = fromBER(newItem.toBER(false)).result;
  5096. }
  5097. res[key] = converter.fromASN(value);
  5098. }
  5099. } else {
  5100. if (schemaItem.repeated) {
  5101. if (!Array.isArray(asn1SchemaValue)) {
  5102. throw new Error("Cannot get list of items from the ASN.1 parsed value. ASN.1 value should be iterable.");
  5103. }
  5104. res[key] = Array.from(asn1SchemaValue, (element) => this.fromASN(element, schemaItemType));
  5105. } else {
  5106. res[key] = this.fromASN(asn1SchemaValue, schemaItemType);
  5107. }
  5108. }
  5109. }
  5110. return res;
  5111. } catch (error) {
  5112. if (error instanceof AsnSchemaValidationError) {
  5113. error.schemas.push(target.name);
  5114. }
  5115. throw error;
  5116. }
  5117. }
  5118. };
  5119. __name(AsnParser, "AsnParser");
  5120. // ../../node_modules/.pnpm/@peculiar+asn1-schema@2.3.0/node_modules/@peculiar/asn1-schema/build/es2015/serializer.js
  5121. init_define_process();
  5122. var AsnSerializer = class {
  5123. static serialize(obj) {
  5124. if (obj instanceof BaseBlock) {
  5125. return obj.toBER(false);
  5126. }
  5127. return this.toASN(obj).toBER(false);
  5128. }
  5129. static toASN(obj) {
  5130. if (obj && typeof obj === "object" && isConvertible(obj)) {
  5131. return obj.toASN();
  5132. }
  5133. if (!(obj && typeof obj === "object")) {
  5134. throw new TypeError("Parameter 1 should be type of Object.");
  5135. }
  5136. const target = obj.constructor;
  5137. const schema = schemaStorage.get(target);
  5138. schemaStorage.cache(target);
  5139. let asn1Value = [];
  5140. if (schema.itemType) {
  5141. if (!Array.isArray(obj)) {
  5142. throw new TypeError("Parameter 1 should be type of Array.");
  5143. }
  5144. if (typeof schema.itemType === "number") {
  5145. const converter = defaultConverter(schema.itemType);
  5146. if (!converter) {
  5147. throw new Error(`Cannot get default converter for array item of ${target.name} ASN1 schema`);
  5148. }
  5149. asn1Value = obj.map((o) => converter.toASN(o));
  5150. } else {
  5151. asn1Value = obj.map((o) => this.toAsnItem({ type: schema.itemType }, "[]", target, o));
  5152. }
  5153. } else {
  5154. for (const key in schema.items) {
  5155. const schemaItem = schema.items[key];
  5156. const objProp = obj[key];
  5157. if (objProp === void 0 || schemaItem.defaultValue === objProp || typeof schemaItem.defaultValue === "object" && typeof objProp === "object" && isArrayEqual(this.serialize(schemaItem.defaultValue), this.serialize(objProp))) {
  5158. continue;
  5159. }
  5160. const asn1Item = AsnSerializer.toAsnItem(schemaItem, key, target, objProp);
  5161. if (typeof schemaItem.context === "number") {
  5162. if (schemaItem.implicit) {
  5163. if (!schemaItem.repeated && (typeof schemaItem.type === "number" || isConvertible(schemaItem.type))) {
  5164. const value = {};
  5165. value.valueHex = asn1Item instanceof Null ? asn1Item.valueBeforeDecodeView : asn1Item.valueBlock.toBER();
  5166. asn1Value.push(new Primitive({
  5167. optional: schemaItem.optional,
  5168. idBlock: {
  5169. tagClass: 3,
  5170. tagNumber: schemaItem.context
  5171. },
  5172. ...value
  5173. }));
  5174. } else {
  5175. asn1Value.push(new Constructed({
  5176. optional: schemaItem.optional,
  5177. idBlock: {
  5178. tagClass: 3,
  5179. tagNumber: schemaItem.context
  5180. },
  5181. value: asn1Item.valueBlock.value
  5182. }));
  5183. }
  5184. } else {
  5185. asn1Value.push(new Constructed({
  5186. optional: schemaItem.optional,
  5187. idBlock: {
  5188. tagClass: 3,
  5189. tagNumber: schemaItem.context
  5190. },
  5191. value: [asn1Item]
  5192. }));
  5193. }
  5194. } else if (schemaItem.repeated) {
  5195. asn1Value = asn1Value.concat(asn1Item);
  5196. } else {
  5197. asn1Value.push(asn1Item);
  5198. }
  5199. }
  5200. }
  5201. let asnSchema;
  5202. switch (schema.type) {
  5203. case AsnTypeTypes.Sequence:
  5204. asnSchema = new Sequence({ value: asn1Value });
  5205. break;
  5206. case AsnTypeTypes.Set:
  5207. asnSchema = new Set({ value: asn1Value });
  5208. break;
  5209. case AsnTypeTypes.Choice:
  5210. if (!asn1Value[0]) {
  5211. throw new Error(`Schema '${target.name}' has wrong data. Choice cannot be empty.`);
  5212. }
  5213. asnSchema = asn1Value[0];
  5214. break;
  5215. }
  5216. return asnSchema;
  5217. }
  5218. static toAsnItem(schemaItem, key, target, objProp) {
  5219. let asn1Item;
  5220. if (typeof schemaItem.type === "number") {
  5221. const converter = schemaItem.converter;
  5222. if (!converter) {
  5223. throw new Error(`Property '${key}' doesn't have converter for type ${AsnPropTypes[schemaItem.type]} in schema '${target.name}'`);
  5224. }
  5225. if (schemaItem.repeated) {
  5226. if (!Array.isArray(objProp)) {
  5227. throw new TypeError("Parameter 'objProp' should be type of Array.");
  5228. }
  5229. const items = Array.from(objProp, (element) => converter.toASN(element));
  5230. const Container = schemaItem.repeated === "sequence" ? Sequence : Set;
  5231. asn1Item = new Container({
  5232. value: items
  5233. });
  5234. } else {
  5235. asn1Item = converter.toASN(objProp);
  5236. }
  5237. } else {
  5238. if (schemaItem.repeated) {
  5239. if (!Array.isArray(objProp)) {
  5240. throw new TypeError("Parameter 'objProp' should be type of Array.");
  5241. }
  5242. const items = Array.from(objProp, (element) => this.toASN(element));
  5243. const Container = schemaItem.repeated === "sequence" ? Sequence : Set;
  5244. asn1Item = new Container({
  5245. value: items
  5246. });
  5247. } else {
  5248. asn1Item = this.toASN(objProp);
  5249. }
  5250. }
  5251. return asn1Item;
  5252. }
  5253. };
  5254. __name(AsnSerializer, "AsnSerializer");
  5255. // ../../node_modules/.pnpm/@peculiar+asn1-schema@2.3.0/node_modules/@peculiar/asn1-schema/build/es2015/objects.js
  5256. init_define_process();
  5257. // ../../node_modules/.pnpm/@peculiar+asn1-schema@2.3.0/node_modules/@peculiar/asn1-schema/build/es2015/convert.js
  5258. init_define_process();
  5259. var AsnConvert = class {
  5260. static serialize(obj) {
  5261. return AsnSerializer.serialize(obj);
  5262. }
  5263. static parse(data, target) {
  5264. return AsnParser.parse(data, target);
  5265. }
  5266. static toString(data) {
  5267. const buf = BufferSourceConverter.isBufferSource(data) ? BufferSourceConverter.toArrayBuffer(data) : AsnConvert.serialize(data);
  5268. const asn = fromBER(buf);
  5269. if (asn.offset === -1) {
  5270. throw new Error(`Cannot decode ASN.1 data. ${asn.result.error}`);
  5271. }
  5272. return asn.result.toString();
  5273. }
  5274. };
  5275. __name(AsnConvert, "AsnConvert");
  5276. // ../../node_modules/.pnpm/tslib@2.4.0/node_modules/tslib/modules/index.js
  5277. init_define_process();
  5278. var import_tslib = __toESM(require_tslib(), 1);
  5279. var {
  5280. __extends,
  5281. __assign,
  5282. __rest,
  5283. __decorate,
  5284. __param,
  5285. __metadata,
  5286. __awaiter,
  5287. __generator,
  5288. __exportStar,
  5289. __createBinding,
  5290. __values,
  5291. __read,
  5292. __spread,
  5293. __spreadArrays,
  5294. __spreadArray,
  5295. __await,
  5296. __asyncGenerator,
  5297. __asyncDelegator,
  5298. __asyncValues,
  5299. __makeTemplateObject,
  5300. __importStar,
  5301. __importDefault,
  5302. __classPrivateFieldGet,
  5303. __classPrivateFieldSet,
  5304. __classPrivateFieldIn
  5305. } = import_tslib.default;
  5306. // ../../node_modules/.pnpm/@peculiar+json-schema@1.1.12/node_modules/@peculiar/json-schema/build/index.es.js
  5307. init_define_process();
  5308. var JsonError = class extends Error {
  5309. constructor(message, innerError) {
  5310. super(innerError ? `${message}. See the inner exception for more details.` : message);
  5311. this.message = message;
  5312. this.innerError = innerError;
  5313. }
  5314. };
  5315. __name(JsonError, "JsonError");
  5316. var TransformError = class extends JsonError {
  5317. constructor(schema, message, innerError) {
  5318. super(message, innerError);
  5319. this.schema = schema;
  5320. }
  5321. };
  5322. __name(TransformError, "TransformError");
  5323. var ParserError = class extends TransformError {
  5324. constructor(schema, message, innerError) {
  5325. super(schema, `JSON doesn't match to '${schema.target.name}' schema. ${message}`, innerError);
  5326. }
  5327. };
  5328. __name(ParserError, "ParserError");
  5329. var ValidationError = class extends JsonError {
  5330. };
  5331. __name(ValidationError, "ValidationError");
  5332. var SerializerError = class extends JsonError {
  5333. constructor(schemaName, message, innerError) {
  5334. super(`Cannot serialize by '${schemaName}' schema. ${message}`, innerError);
  5335. this.schemaName = schemaName;
  5336. }
  5337. };
  5338. __name(SerializerError, "SerializerError");
  5339. var KeyError = class extends ParserError {
  5340. constructor(schema, keys, errors = {}) {
  5341. super(schema, "Some keys doesn't match to schema");
  5342. this.keys = keys;
  5343. this.errors = errors;
  5344. }
  5345. };
  5346. __name(KeyError, "KeyError");
  5347. var JsonPropTypes;
  5348. (function(JsonPropTypes2) {
  5349. JsonPropTypes2[JsonPropTypes2["Any"] = 0] = "Any";
  5350. JsonPropTypes2[JsonPropTypes2["Boolean"] = 1] = "Boolean";
  5351. JsonPropTypes2[JsonPropTypes2["Number"] = 2] = "Number";
  5352. JsonPropTypes2[JsonPropTypes2["String"] = 3] = "String";
  5353. })(JsonPropTypes || (JsonPropTypes = {}));
  5354. function checkType(value, type) {
  5355. switch (type) {
  5356. case JsonPropTypes.Boolean:
  5357. return typeof value === "boolean";
  5358. case JsonPropTypes.Number:
  5359. return typeof value === "number";
  5360. case JsonPropTypes.String:
  5361. return typeof value === "string";
  5362. }
  5363. return true;
  5364. }
  5365. __name(checkType, "checkType");
  5366. function throwIfTypeIsWrong(value, type) {
  5367. if (!checkType(value, type)) {
  5368. throw new TypeError(`Value must be ${JsonPropTypes[type]}`);
  5369. }
  5370. }
  5371. __name(throwIfTypeIsWrong, "throwIfTypeIsWrong");
  5372. function isConvertible2(target) {
  5373. if (target && target.prototype) {
  5374. if (target.prototype.toJSON && target.prototype.fromJSON) {
  5375. return true;
  5376. } else {
  5377. return isConvertible2(target.prototype);
  5378. }
  5379. } else {
  5380. return !!(target && target.toJSON && target.fromJSON);
  5381. }
  5382. }
  5383. __name(isConvertible2, "isConvertible");
  5384. var JsonSchemaStorage = class {
  5385. constructor() {
  5386. this.items = /* @__PURE__ */ new Map();
  5387. }
  5388. has(target) {
  5389. return this.items.has(target) || !!this.findParentSchema(target);
  5390. }
  5391. get(target) {
  5392. const schema = this.items.get(target) || this.findParentSchema(target);
  5393. if (!schema) {
  5394. throw new Error("Cannot get schema for current target");
  5395. }
  5396. return schema;
  5397. }
  5398. create(target) {
  5399. const schema = { names: {} };
  5400. const parentSchema = this.findParentSchema(target);
  5401. if (parentSchema) {
  5402. Object.assign(schema, parentSchema);
  5403. schema.names = {};
  5404. for (const name in parentSchema.names) {
  5405. schema.names[name] = Object.assign({}, parentSchema.names[name]);
  5406. }
  5407. }
  5408. schema.target = target;
  5409. return schema;
  5410. }
  5411. set(target, schema) {
  5412. this.items.set(target, schema);
  5413. return this;
  5414. }
  5415. findParentSchema(target) {
  5416. const parent = target.__proto__;
  5417. if (parent) {
  5418. const schema = this.items.get(parent);
  5419. return schema || this.findParentSchema(parent);
  5420. }
  5421. return null;
  5422. }
  5423. };
  5424. __name(JsonSchemaStorage, "JsonSchemaStorage");
  5425. var DEFAULT_SCHEMA = "default";
  5426. var schemaStorage2 = new JsonSchemaStorage();
  5427. var PatternValidation = class {
  5428. constructor(pattern) {
  5429. this.pattern = new RegExp(pattern);
  5430. }
  5431. validate(value) {
  5432. const pattern = new RegExp(this.pattern.source, this.pattern.flags);
  5433. if (typeof value !== "string") {
  5434. throw new ValidationError("Incoming value must be string");
  5435. }
  5436. if (!pattern.exec(value)) {
  5437. throw new ValidationError(`Value doesn't match to pattern '${pattern.toString()}'`);
  5438. }
  5439. }
  5440. };
  5441. __name(PatternValidation, "PatternValidation");
  5442. var InclusiveValidation = class {
  5443. constructor(min = Number.MIN_VALUE, max = Number.MAX_VALUE) {
  5444. this.min = min;
  5445. this.max = max;
  5446. }
  5447. validate(value) {
  5448. throwIfTypeIsWrong(value, JsonPropTypes.Number);
  5449. if (!(this.min <= value && value <= this.max)) {
  5450. const min = this.min === Number.MIN_VALUE ? "MIN" : this.min;
  5451. const max = this.max === Number.MAX_VALUE ? "MAX" : this.max;
  5452. throw new ValidationError(`Value doesn't match to diapason [${min},${max}]`);
  5453. }
  5454. }
  5455. };
  5456. __name(InclusiveValidation, "InclusiveValidation");
  5457. var ExclusiveValidation = class {
  5458. constructor(min = Number.MIN_VALUE, max = Number.MAX_VALUE) {
  5459. this.min = min;
  5460. this.max = max;
  5461. }
  5462. validate(value) {
  5463. throwIfTypeIsWrong(value, JsonPropTypes.Number);
  5464. if (!(this.min < value && value < this.max)) {
  5465. const min = this.min === Number.MIN_VALUE ? "MIN" : this.min;
  5466. const max = this.max === Number.MAX_VALUE ? "MAX" : this.max;
  5467. throw new ValidationError(`Value doesn't match to diapason (${min},${max})`);
  5468. }
  5469. }
  5470. };
  5471. __name(ExclusiveValidation, "ExclusiveValidation");
  5472. var LengthValidation = class {
  5473. constructor(length, minLength, maxLength) {
  5474. this.length = length;
  5475. this.minLength = minLength;
  5476. this.maxLength = maxLength;
  5477. }
  5478. validate(value) {
  5479. if (this.length !== void 0) {
  5480. if (value.length !== this.length) {
  5481. throw new ValidationError(`Value length must be exactly ${this.length}.`);
  5482. }
  5483. return;
  5484. }
  5485. if (this.minLength !== void 0) {
  5486. if (value.length < this.minLength) {
  5487. throw new ValidationError(`Value length must be more than ${this.minLength}.`);
  5488. }
  5489. }
  5490. if (this.maxLength !== void 0) {
  5491. if (value.length > this.maxLength) {
  5492. throw new ValidationError(`Value length must be less than ${this.maxLength}.`);
  5493. }
  5494. }
  5495. }
  5496. };
  5497. __name(LengthValidation, "LengthValidation");
  5498. var EnumerationValidation = class {
  5499. constructor(enumeration) {
  5500. this.enumeration = enumeration;
  5501. }
  5502. validate(value) {
  5503. throwIfTypeIsWrong(value, JsonPropTypes.String);
  5504. if (!this.enumeration.includes(value)) {
  5505. throw new ValidationError(`Value must be one of ${this.enumeration.map((v) => `'${v}'`).join(", ")}`);
  5506. }
  5507. }
  5508. };
  5509. __name(EnumerationValidation, "EnumerationValidation");
  5510. var JsonTransform = class {
  5511. static checkValues(data, schemaItem) {
  5512. const values = Array.isArray(data) ? data : [data];
  5513. for (const value of values) {
  5514. for (const validation of schemaItem.validations) {
  5515. if (validation instanceof LengthValidation && schemaItem.repeated) {
  5516. validation.validate(data);
  5517. } else {
  5518. validation.validate(value);
  5519. }
  5520. }
  5521. }
  5522. }
  5523. static checkTypes(value, schemaItem) {
  5524. if (schemaItem.repeated && !Array.isArray(value)) {
  5525. throw new TypeError("Value must be Array");
  5526. }
  5527. if (typeof schemaItem.type === "number") {
  5528. const values = Array.isArray(value) ? value : [value];
  5529. for (const v of values) {
  5530. throwIfTypeIsWrong(v, schemaItem.type);
  5531. }
  5532. }
  5533. }
  5534. static getSchemaByName(schema, name = DEFAULT_SCHEMA) {
  5535. return { ...schema.names[DEFAULT_SCHEMA], ...schema.names[name] };
  5536. }
  5537. };
  5538. __name(JsonTransform, "JsonTransform");
  5539. var JsonSerializer = class extends JsonTransform {
  5540. static serialize(obj, options, replacer, space) {
  5541. const json = this.toJSON(obj, options);
  5542. return JSON.stringify(json, replacer, space);
  5543. }
  5544. static toJSON(obj, options = {}) {
  5545. let res;
  5546. let targetSchema = options.targetSchema;
  5547. const schemaName = options.schemaName || DEFAULT_SCHEMA;
  5548. if (isConvertible2(obj)) {
  5549. return obj.toJSON();
  5550. }
  5551. if (Array.isArray(obj)) {
  5552. res = [];
  5553. for (const item of obj) {
  5554. res.push(this.toJSON(item, options));
  5555. }
  5556. } else if (typeof obj === "object") {
  5557. if (targetSchema && !schemaStorage2.has(targetSchema)) {
  5558. throw new JsonError("Cannot get schema for `targetSchema` param");
  5559. }
  5560. targetSchema = targetSchema || obj.constructor;
  5561. if (schemaStorage2.has(targetSchema)) {
  5562. const schema = schemaStorage2.get(targetSchema);
  5563. res = {};
  5564. const namedSchema = this.getSchemaByName(schema, schemaName);
  5565. for (const key in namedSchema) {
  5566. try {
  5567. const item = namedSchema[key];
  5568. const objItem = obj[key];
  5569. let value;
  5570. if (item.optional && objItem === void 0 || item.defaultValue !== void 0 && objItem === item.defaultValue) {
  5571. continue;
  5572. }
  5573. if (!item.optional && objItem === void 0) {
  5574. throw new SerializerError(targetSchema.name, `Property '${key}' is required.`);
  5575. }
  5576. if (typeof item.type === "number") {
  5577. if (item.converter) {
  5578. if (item.repeated) {
  5579. value = objItem.map((el) => item.converter.toJSON(el, obj));
  5580. } else {
  5581. value = item.converter.toJSON(objItem, obj);
  5582. }
  5583. } else {
  5584. value = objItem;
  5585. }
  5586. } else {
  5587. if (item.repeated) {
  5588. value = objItem.map((el) => this.toJSON(el, { schemaName }));
  5589. } else {
  5590. value = this.toJSON(objItem, { schemaName });
  5591. }
  5592. }
  5593. this.checkTypes(value, item);
  5594. this.checkValues(value, item);
  5595. res[item.name || key] = value;
  5596. } catch (e) {
  5597. if (e instanceof SerializerError) {
  5598. throw e;
  5599. } else {
  5600. throw new SerializerError(schema.target.name, `Property '${key}' is wrong. ${e.message}`, e);
  5601. }
  5602. }
  5603. }
  5604. } else {
  5605. res = {};
  5606. for (const key in obj) {
  5607. res[key] = this.toJSON(obj[key], { schemaName });
  5608. }
  5609. }
  5610. } else {
  5611. res = obj;
  5612. }
  5613. return res;
  5614. }
  5615. };
  5616. __name(JsonSerializer, "JsonSerializer");
  5617. var JsonParser = class extends JsonTransform {
  5618. static parse(data, options) {
  5619. const obj = JSON.parse(data);
  5620. return this.fromJSON(obj, options);
  5621. }
  5622. static fromJSON(target, options) {
  5623. const targetSchema = options.targetSchema;
  5624. const schemaName = options.schemaName || DEFAULT_SCHEMA;
  5625. const obj = new targetSchema();
  5626. if (isConvertible2(obj)) {
  5627. return obj.fromJSON(target);
  5628. }
  5629. const schema = schemaStorage2.get(targetSchema);
  5630. const namedSchema = this.getSchemaByName(schema, schemaName);
  5631. const keyErrors = {};
  5632. if (options.strictProperty && !Array.isArray(target)) {
  5633. JsonParser.checkStrictProperty(target, namedSchema, schema);
  5634. }
  5635. for (const key in namedSchema) {
  5636. try {
  5637. const item = namedSchema[key];
  5638. const name = item.name || key;
  5639. const value = target[name];
  5640. if (value === void 0 && (item.optional || item.defaultValue !== void 0)) {
  5641. continue;
  5642. }
  5643. if (!item.optional && value === void 0) {
  5644. throw new ParserError(schema, `Property '${name}' is required.`);
  5645. }
  5646. this.checkTypes(value, item);
  5647. this.checkValues(value, item);
  5648. if (typeof item.type === "number") {
  5649. if (item.converter) {
  5650. if (item.repeated) {
  5651. obj[key] = value.map((el) => item.converter.fromJSON(el, obj));
  5652. } else {
  5653. obj[key] = item.converter.fromJSON(value, obj);
  5654. }
  5655. } else {
  5656. obj[key] = value;
  5657. }
  5658. } else {
  5659. const newOptions = {
  5660. ...options,
  5661. targetSchema: item.type,
  5662. schemaName
  5663. };
  5664. if (item.repeated) {
  5665. obj[key] = value.map((el) => this.fromJSON(el, newOptions));
  5666. } else {
  5667. obj[key] = this.fromJSON(value, newOptions);
  5668. }
  5669. }
  5670. } catch (e) {
  5671. if (!(e instanceof ParserError)) {
  5672. e = new ParserError(schema, `Property '${key}' is wrong. ${e.message}`, e);
  5673. }
  5674. if (options.strictAllKeys) {
  5675. keyErrors[key] = e;
  5676. } else {
  5677. throw e;
  5678. }
  5679. }
  5680. }
  5681. const keys = Object.keys(keyErrors);
  5682. if (keys.length) {
  5683. throw new KeyError(schema, keys, keyErrors);
  5684. }
  5685. return obj;
  5686. }
  5687. static checkStrictProperty(target, namedSchema, schema) {
  5688. const jsonProps = Object.keys(target);
  5689. const schemaProps = Object.keys(namedSchema);
  5690. const keys = [];
  5691. for (const key of jsonProps) {
  5692. if (schemaProps.indexOf(key) === -1) {
  5693. keys.push(key);
  5694. }
  5695. }
  5696. if (keys.length) {
  5697. throw new KeyError(schema, keys);
  5698. }
  5699. }
  5700. };
  5701. __name(JsonParser, "JsonParser");
  5702. function getValidations(item) {
  5703. const validations = [];
  5704. if (item.pattern) {
  5705. validations.push(new PatternValidation(item.pattern));
  5706. }
  5707. if (item.type === JsonPropTypes.Number || item.type === JsonPropTypes.Any) {
  5708. if (item.minInclusive !== void 0 || item.maxInclusive !== void 0) {
  5709. validations.push(new InclusiveValidation(item.minInclusive, item.maxInclusive));
  5710. }
  5711. if (item.minExclusive !== void 0 || item.maxExclusive !== void 0) {
  5712. validations.push(new ExclusiveValidation(item.minExclusive, item.maxExclusive));
  5713. }
  5714. if (item.enumeration !== void 0) {
  5715. validations.push(new EnumerationValidation(item.enumeration));
  5716. }
  5717. }
  5718. if (item.type === JsonPropTypes.String || item.repeated || item.type === JsonPropTypes.Any) {
  5719. if (item.length !== void 0 || item.minLength !== void 0 || item.maxLength !== void 0) {
  5720. validations.push(new LengthValidation(item.length, item.minLength, item.maxLength));
  5721. }
  5722. }
  5723. return validations;
  5724. }
  5725. __name(getValidations, "getValidations");
  5726. var JsonProp = /* @__PURE__ */ __name((options = {}) => (target, propertyKey) => {
  5727. const errorMessage = `Cannot set type for ${propertyKey} property of ${target.constructor.name} schema`;
  5728. let schema;
  5729. if (!schemaStorage2.has(target.constructor)) {
  5730. schema = schemaStorage2.create(target.constructor);
  5731. schemaStorage2.set(target.constructor, schema);
  5732. } else {
  5733. schema = schemaStorage2.get(target.constructor);
  5734. if (schema.target !== target.constructor) {
  5735. schema = schemaStorage2.create(target.constructor);
  5736. schemaStorage2.set(target.constructor, schema);
  5737. }
  5738. }
  5739. const defaultSchema = {
  5740. type: JsonPropTypes.Any,
  5741. validations: []
  5742. };
  5743. const copyOptions = Object.assign(defaultSchema, options);
  5744. copyOptions.validations = getValidations(copyOptions);
  5745. if (typeof copyOptions.type !== "number") {
  5746. if (!schemaStorage2.has(copyOptions.type) && !isConvertible2(copyOptions.type)) {
  5747. throw new Error(`${errorMessage}. Assigning type doesn't have schema.`);
  5748. }
  5749. }
  5750. let schemaNames;
  5751. if (Array.isArray(options.schema)) {
  5752. schemaNames = options.schema;
  5753. } else {
  5754. schemaNames = [options.schema || DEFAULT_SCHEMA];
  5755. }
  5756. for (const schemaName of schemaNames) {
  5757. if (!schema.names[schemaName]) {
  5758. schema.names[schemaName] = {};
  5759. }
  5760. const namedSchema = schema.names[schemaName];
  5761. namedSchema[propertyKey] = copyOptions;
  5762. }
  5763. }, "JsonProp");
  5764. // ../../node_modules/.pnpm/webcrypto-core@1.7.5/node_modules/webcrypto-core/build/webcrypto-core.es.js
  5765. var CryptoError = class extends Error {
  5766. };
  5767. __name(CryptoError, "CryptoError");
  5768. var AlgorithmError = class extends CryptoError {
  5769. };
  5770. __name(AlgorithmError, "AlgorithmError");
  5771. var UnsupportedOperationError = class extends CryptoError {
  5772. constructor(methodName) {
  5773. super(`Unsupported operation: ${methodName ? `${methodName}` : ""}`);
  5774. }
  5775. };
  5776. __name(UnsupportedOperationError, "UnsupportedOperationError");
  5777. var OperationError = class extends CryptoError {
  5778. };
  5779. __name(OperationError, "OperationError");
  5780. var RequiredPropertyError = class extends CryptoError {
  5781. constructor(propName) {
  5782. super(`${propName}: Missing required property`);
  5783. }
  5784. };
  5785. __name(RequiredPropertyError, "RequiredPropertyError");
  5786. function isJWK(data) {
  5787. return typeof data === "object" && "kty" in data;
  5788. }
  5789. __name(isJWK, "isJWK");
  5790. var ProviderCrypto = class {
  5791. async digest(...args) {
  5792. this.checkDigest.apply(this, args);
  5793. return this.onDigest.apply(this, args);
  5794. }
  5795. checkDigest(algorithm, data) {
  5796. this.checkAlgorithmName(algorithm);
  5797. }
  5798. async onDigest(algorithm, data) {
  5799. throw new UnsupportedOperationError("digest");
  5800. }
  5801. async generateKey(...args) {
  5802. this.checkGenerateKey.apply(this, args);
  5803. return this.onGenerateKey.apply(this, args);
  5804. }
  5805. checkGenerateKey(algorithm, extractable, keyUsages, ...args) {
  5806. this.checkAlgorithmName(algorithm);
  5807. this.checkGenerateKeyParams(algorithm);
  5808. if (!(keyUsages && keyUsages.length)) {
  5809. throw new TypeError(`Usages cannot be empty when creating a key.`);
  5810. }
  5811. let allowedUsages;
  5812. if (Array.isArray(this.usages)) {
  5813. allowedUsages = this.usages;
  5814. } else {
  5815. allowedUsages = this.usages.privateKey.concat(this.usages.publicKey);
  5816. }
  5817. this.checkKeyUsages(keyUsages, allowedUsages);
  5818. }
  5819. checkGenerateKeyParams(algorithm) {
  5820. }
  5821. async onGenerateKey(algorithm, extractable, keyUsages, ...args) {
  5822. throw new UnsupportedOperationError("generateKey");
  5823. }
  5824. async sign(...args) {
  5825. this.checkSign.apply(this, args);
  5826. return this.onSign.apply(this, args);
  5827. }
  5828. checkSign(algorithm, key, data, ...args) {
  5829. this.checkAlgorithmName(algorithm);
  5830. this.checkAlgorithmParams(algorithm);
  5831. this.checkCryptoKey(key, "sign");
  5832. }
  5833. async onSign(algorithm, key, data, ...args) {
  5834. throw new UnsupportedOperationError("sign");
  5835. }
  5836. async verify(...args) {
  5837. this.checkVerify.apply(this, args);
  5838. return this.onVerify.apply(this, args);
  5839. }
  5840. checkVerify(algorithm, key, signature, data, ...args) {
  5841. this.checkAlgorithmName(algorithm);
  5842. this.checkAlgorithmParams(algorithm);
  5843. this.checkCryptoKey(key, "verify");
  5844. }
  5845. async onVerify(algorithm, key, signature, data, ...args) {
  5846. throw new UnsupportedOperationError("verify");
  5847. }
  5848. async encrypt(...args) {
  5849. this.checkEncrypt.apply(this, args);
  5850. return this.onEncrypt.apply(this, args);
  5851. }
  5852. checkEncrypt(algorithm, key, data, options = {}, ...args) {
  5853. this.checkAlgorithmName(algorithm);
  5854. this.checkAlgorithmParams(algorithm);
  5855. this.checkCryptoKey(key, options.keyUsage ? "encrypt" : void 0);
  5856. }
  5857. async onEncrypt(algorithm, key, data, ...args) {
  5858. throw new UnsupportedOperationError("encrypt");
  5859. }
  5860. async decrypt(...args) {
  5861. this.checkDecrypt.apply(this, args);
  5862. return this.onDecrypt.apply(this, args);
  5863. }
  5864. checkDecrypt(algorithm, key, data, options = {}, ...args) {
  5865. this.checkAlgorithmName(algorithm);
  5866. this.checkAlgorithmParams(algorithm);
  5867. this.checkCryptoKey(key, options.keyUsage ? "decrypt" : void 0);
  5868. }
  5869. async onDecrypt(algorithm, key, data, ...args) {
  5870. throw new UnsupportedOperationError("decrypt");
  5871. }
  5872. async deriveBits(...args) {
  5873. this.checkDeriveBits.apply(this, args);
  5874. return this.onDeriveBits.apply(this, args);
  5875. }
  5876. checkDeriveBits(algorithm, baseKey, length, options = {}, ...args) {
  5877. this.checkAlgorithmName(algorithm);
  5878. this.checkAlgorithmParams(algorithm);
  5879. this.checkCryptoKey(baseKey, options.keyUsage ? "deriveBits" : void 0);
  5880. if (length % 8 !== 0) {
  5881. throw new OperationError("length: Is not multiple of 8");
  5882. }
  5883. }
  5884. async onDeriveBits(algorithm, baseKey, length, ...args) {
  5885. throw new UnsupportedOperationError("deriveBits");
  5886. }
  5887. async exportKey(...args) {
  5888. this.checkExportKey.apply(this, args);
  5889. return this.onExportKey.apply(this, args);
  5890. }
  5891. checkExportKey(format, key, ...args) {
  5892. this.checkKeyFormat(format);
  5893. this.checkCryptoKey(key);
  5894. if (!key.extractable) {
  5895. throw new CryptoError("key: Is not extractable");
  5896. }
  5897. }
  5898. async onExportKey(format, key, ...args) {
  5899. throw new UnsupportedOperationError("exportKey");
  5900. }
  5901. async importKey(...args) {
  5902. this.checkImportKey.apply(this, args);
  5903. return this.onImportKey.apply(this, args);
  5904. }
  5905. checkImportKey(format, keyData, algorithm, extractable, keyUsages, ...args) {
  5906. this.checkKeyFormat(format);
  5907. this.checkKeyData(format, keyData);
  5908. this.checkAlgorithmName(algorithm);
  5909. this.checkImportParams(algorithm);
  5910. if (Array.isArray(this.usages)) {
  5911. this.checkKeyUsages(keyUsages, this.usages);
  5912. }
  5913. }
  5914. async onImportKey(format, keyData, algorithm, extractable, keyUsages, ...args) {
  5915. throw new UnsupportedOperationError("importKey");
  5916. }
  5917. checkAlgorithmName(algorithm) {
  5918. if (algorithm.name.toLowerCase() !== this.name.toLowerCase()) {
  5919. throw new AlgorithmError("Unrecognized name");
  5920. }
  5921. }
  5922. checkAlgorithmParams(algorithm) {
  5923. }
  5924. checkDerivedKeyParams(algorithm) {
  5925. }
  5926. checkKeyUsages(usages, allowed) {
  5927. for (const usage of usages) {
  5928. if (allowed.indexOf(usage) === -1) {
  5929. throw new TypeError("Cannot create a key using the specified key usages");
  5930. }
  5931. }
  5932. }
  5933. checkCryptoKey(key, keyUsage) {
  5934. this.checkAlgorithmName(key.algorithm);
  5935. if (keyUsage && key.usages.indexOf(keyUsage) === -1) {
  5936. throw new CryptoError(`key does not match that of operation`);
  5937. }
  5938. }
  5939. checkRequiredProperty(data, propName) {
  5940. if (!(propName in data)) {
  5941. throw new RequiredPropertyError(propName);
  5942. }
  5943. }
  5944. checkHashAlgorithm(algorithm, hashAlgorithms) {
  5945. for (const item of hashAlgorithms) {
  5946. if (item.toLowerCase() === algorithm.name.toLowerCase()) {
  5947. return;
  5948. }
  5949. }
  5950. throw new OperationError(`hash: Must be one of ${hashAlgorithms.join(", ")}`);
  5951. }
  5952. checkImportParams(algorithm) {
  5953. }
  5954. checkKeyFormat(format) {
  5955. switch (format) {
  5956. case "raw":
  5957. case "pkcs8":
  5958. case "spki":
  5959. case "jwk":
  5960. break;
  5961. default:
  5962. throw new TypeError("format: Is invalid value. Must be 'jwk', 'raw', 'spki', or 'pkcs8'");
  5963. }
  5964. }
  5965. checkKeyData(format, keyData) {
  5966. if (!keyData) {
  5967. throw new TypeError("keyData: Cannot be empty on empty on key importing");
  5968. }
  5969. if (format === "jwk") {
  5970. if (!isJWK(keyData)) {
  5971. throw new TypeError("keyData: Is not JsonWebToken");
  5972. }
  5973. } else if (!BufferSourceConverter.isBufferSource(keyData)) {
  5974. throw new TypeError("keyData: Is not ArrayBufferView or ArrayBuffer");
  5975. }
  5976. }
  5977. prepareData(data) {
  5978. return BufferSourceConverter.toArrayBuffer(data);
  5979. }
  5980. };
  5981. __name(ProviderCrypto, "ProviderCrypto");
  5982. var AesProvider = class extends ProviderCrypto {
  5983. checkGenerateKeyParams(algorithm) {
  5984. this.checkRequiredProperty(algorithm, "length");
  5985. if (typeof algorithm.length !== "number") {
  5986. throw new TypeError("length: Is not of type Number");
  5987. }
  5988. switch (algorithm.length) {
  5989. case 128:
  5990. case 192:
  5991. case 256:
  5992. break;
  5993. default:
  5994. throw new TypeError("length: Must be 128, 192, or 256");
  5995. }
  5996. }
  5997. checkDerivedKeyParams(algorithm) {
  5998. this.checkGenerateKeyParams(algorithm);
  5999. }
  6000. };
  6001. __name(AesProvider, "AesProvider");
  6002. var AesCbcProvider = class extends AesProvider {
  6003. constructor() {
  6004. super(...arguments);
  6005. this.name = "AES-CBC";
  6006. this.usages = ["encrypt", "decrypt", "wrapKey", "unwrapKey"];
  6007. }
  6008. checkAlgorithmParams(algorithm) {
  6009. this.checkRequiredProperty(algorithm, "iv");
  6010. if (!(algorithm.iv instanceof ArrayBuffer || ArrayBuffer.isView(algorithm.iv))) {
  6011. throw new TypeError("iv: Is not of type '(ArrayBuffer or ArrayBufferView)'");
  6012. }
  6013. if (algorithm.iv.byteLength !== 16) {
  6014. throw new TypeError("iv: Must have length 16 bytes");
  6015. }
  6016. }
  6017. };
  6018. __name(AesCbcProvider, "AesCbcProvider");
  6019. var AesCmacProvider = class extends AesProvider {
  6020. constructor() {
  6021. super(...arguments);
  6022. this.name = "AES-CMAC";
  6023. this.usages = ["sign", "verify"];
  6024. }
  6025. checkAlgorithmParams(algorithm) {
  6026. this.checkRequiredProperty(algorithm, "length");
  6027. if (typeof algorithm.length !== "number") {
  6028. throw new TypeError("length: Is not a Number");
  6029. }
  6030. if (algorithm.length < 1) {
  6031. throw new OperationError("length: Must be more than 0");
  6032. }
  6033. }
  6034. };
  6035. __name(AesCmacProvider, "AesCmacProvider");
  6036. var AesCtrProvider = class extends AesProvider {
  6037. constructor() {
  6038. super(...arguments);
  6039. this.name = "AES-CTR";
  6040. this.usages = ["encrypt", "decrypt", "wrapKey", "unwrapKey"];
  6041. }
  6042. checkAlgorithmParams(algorithm) {
  6043. this.checkRequiredProperty(algorithm, "counter");
  6044. if (!(algorithm.counter instanceof ArrayBuffer || ArrayBuffer.isView(algorithm.counter))) {
  6045. throw new TypeError("counter: Is not of type '(ArrayBuffer or ArrayBufferView)'");
  6046. }
  6047. if (algorithm.counter.byteLength !== 16) {
  6048. throw new TypeError("iv: Must have length 16 bytes");
  6049. }
  6050. this.checkRequiredProperty(algorithm, "length");
  6051. if (typeof algorithm.length !== "number") {
  6052. throw new TypeError("length: Is not a Number");
  6053. }
  6054. if (algorithm.length < 1) {
  6055. throw new OperationError("length: Must be more than 0");
  6056. }
  6057. }
  6058. };
  6059. __name(AesCtrProvider, "AesCtrProvider");
  6060. var AesEcbProvider = class extends AesProvider {
  6061. constructor() {
  6062. super(...arguments);
  6063. this.name = "AES-ECB";
  6064. this.usages = ["encrypt", "decrypt", "wrapKey", "unwrapKey"];
  6065. }
  6066. };
  6067. __name(AesEcbProvider, "AesEcbProvider");
  6068. var AesGcmProvider = class extends AesProvider {
  6069. constructor() {
  6070. super(...arguments);
  6071. this.name = "AES-GCM";
  6072. this.usages = ["encrypt", "decrypt", "wrapKey", "unwrapKey"];
  6073. }
  6074. checkAlgorithmParams(algorithm) {
  6075. this.checkRequiredProperty(algorithm, "iv");
  6076. if (!(algorithm.iv instanceof ArrayBuffer || ArrayBuffer.isView(algorithm.iv))) {
  6077. throw new TypeError("iv: Is not of type '(ArrayBuffer or ArrayBufferView)'");
  6078. }
  6079. if (algorithm.iv.byteLength < 1) {
  6080. throw new OperationError("iv: Must have length more than 0 and less than 2^64 - 1");
  6081. }
  6082. if (!("tagLength" in algorithm)) {
  6083. algorithm.tagLength = 128;
  6084. }
  6085. switch (algorithm.tagLength) {
  6086. case 32:
  6087. case 64:
  6088. case 96:
  6089. case 104:
  6090. case 112:
  6091. case 120:
  6092. case 128:
  6093. break;
  6094. default:
  6095. throw new OperationError("tagLength: Must be one of 32, 64, 96, 104, 112, 120 or 128");
  6096. }
  6097. }
  6098. };
  6099. __name(AesGcmProvider, "AesGcmProvider");
  6100. var AesKwProvider = class extends AesProvider {
  6101. constructor() {
  6102. super(...arguments);
  6103. this.name = "AES-KW";
  6104. this.usages = ["wrapKey", "unwrapKey"];
  6105. }
  6106. };
  6107. __name(AesKwProvider, "AesKwProvider");
  6108. var DesProvider = class extends ProviderCrypto {
  6109. constructor() {
  6110. super(...arguments);
  6111. this.usages = ["encrypt", "decrypt", "wrapKey", "unwrapKey"];
  6112. }
  6113. checkAlgorithmParams(algorithm) {
  6114. if (this.ivSize) {
  6115. this.checkRequiredProperty(algorithm, "iv");
  6116. if (!(algorithm.iv instanceof ArrayBuffer || ArrayBuffer.isView(algorithm.iv))) {
  6117. throw new TypeError("iv: Is not of type '(ArrayBuffer or ArrayBufferView)'");
  6118. }
  6119. if (algorithm.iv.byteLength !== this.ivSize) {
  6120. throw new TypeError(`iv: Must have length ${this.ivSize} bytes`);
  6121. }
  6122. }
  6123. }
  6124. checkGenerateKeyParams(algorithm) {
  6125. this.checkRequiredProperty(algorithm, "length");
  6126. if (typeof algorithm.length !== "number") {
  6127. throw new TypeError("length: Is not of type Number");
  6128. }
  6129. if (algorithm.length !== this.keySizeBits) {
  6130. throw new OperationError(`algorithm.length: Must be ${this.keySizeBits}`);
  6131. }
  6132. }
  6133. checkDerivedKeyParams(algorithm) {
  6134. this.checkGenerateKeyParams(algorithm);
  6135. }
  6136. };
  6137. __name(DesProvider, "DesProvider");
  6138. var RsaProvider = class extends ProviderCrypto {
  6139. constructor() {
  6140. super(...arguments);
  6141. this.hashAlgorithms = ["SHA-1", "SHA-256", "SHA-384", "SHA-512"];
  6142. }
  6143. checkGenerateKeyParams(algorithm) {
  6144. this.checkRequiredProperty(algorithm, "hash");
  6145. this.checkHashAlgorithm(algorithm.hash, this.hashAlgorithms);
  6146. this.checkRequiredProperty(algorithm, "publicExponent");
  6147. if (!(algorithm.publicExponent && algorithm.publicExponent instanceof Uint8Array)) {
  6148. throw new TypeError("publicExponent: Missing or not a Uint8Array");
  6149. }
  6150. const publicExponent = Convert.ToBase64(algorithm.publicExponent);
  6151. if (!(publicExponent === "Aw==" || publicExponent === "AQAB")) {
  6152. throw new TypeError("publicExponent: Must be [3] or [1,0,1]");
  6153. }
  6154. this.checkRequiredProperty(algorithm, "modulusLength");
  6155. if (algorithm.modulusLength % 8 || algorithm.modulusLength < 256 || algorithm.modulusLength > 16384) {
  6156. throw new TypeError("The modulus length must be a multiple of 8 bits and >= 256 and <= 16384");
  6157. }
  6158. }
  6159. checkImportParams(algorithm) {
  6160. this.checkRequiredProperty(algorithm, "hash");
  6161. this.checkHashAlgorithm(algorithm.hash, this.hashAlgorithms);
  6162. }
  6163. };
  6164. __name(RsaProvider, "RsaProvider");
  6165. var RsaSsaProvider = class extends RsaProvider {
  6166. constructor() {
  6167. super(...arguments);
  6168. this.name = "RSASSA-PKCS1-v1_5";
  6169. this.usages = {
  6170. privateKey: ["sign"],
  6171. publicKey: ["verify"]
  6172. };
  6173. }
  6174. };
  6175. __name(RsaSsaProvider, "RsaSsaProvider");
  6176. var RsaPssProvider = class extends RsaProvider {
  6177. constructor() {
  6178. super(...arguments);
  6179. this.name = "RSA-PSS";
  6180. this.usages = {
  6181. privateKey: ["sign"],
  6182. publicKey: ["verify"]
  6183. };
  6184. }
  6185. checkAlgorithmParams(algorithm) {
  6186. this.checkRequiredProperty(algorithm, "saltLength");
  6187. if (typeof algorithm.saltLength !== "number") {
  6188. throw new TypeError("saltLength: Is not a Number");
  6189. }
  6190. if (algorithm.saltLength < 0) {
  6191. throw new RangeError("saltLength: Must be positive number");
  6192. }
  6193. }
  6194. };
  6195. __name(RsaPssProvider, "RsaPssProvider");
  6196. var RsaOaepProvider = class extends RsaProvider {
  6197. constructor() {
  6198. super(...arguments);
  6199. this.name = "RSA-OAEP";
  6200. this.usages = {
  6201. privateKey: ["decrypt", "unwrapKey"],
  6202. publicKey: ["encrypt", "wrapKey"]
  6203. };
  6204. }
  6205. checkAlgorithmParams(algorithm) {
  6206. if (algorithm.label && !(algorithm.label instanceof ArrayBuffer || ArrayBuffer.isView(algorithm.label))) {
  6207. throw new TypeError("label: Is not of type '(ArrayBuffer or ArrayBufferView)'");
  6208. }
  6209. }
  6210. };
  6211. __name(RsaOaepProvider, "RsaOaepProvider");
  6212. var EllipticProvider = class extends ProviderCrypto {
  6213. checkGenerateKeyParams(algorithm) {
  6214. this.checkRequiredProperty(algorithm, "namedCurve");
  6215. this.checkNamedCurve(algorithm.namedCurve);
  6216. }
  6217. checkNamedCurve(namedCurve) {
  6218. for (const item of this.namedCurves) {
  6219. if (item.toLowerCase() === namedCurve.toLowerCase()) {
  6220. return;
  6221. }
  6222. }
  6223. throw new OperationError(`namedCurve: Must be one of ${this.namedCurves.join(", ")}`);
  6224. }
  6225. };
  6226. __name(EllipticProvider, "EllipticProvider");
  6227. var EcdsaProvider = class extends EllipticProvider {
  6228. constructor() {
  6229. super(...arguments);
  6230. this.name = "ECDSA";
  6231. this.hashAlgorithms = ["SHA-1", "SHA-256", "SHA-384", "SHA-512"];
  6232. this.usages = {
  6233. privateKey: ["sign"],
  6234. publicKey: ["verify"]
  6235. };
  6236. this.namedCurves = ["P-256", "P-384", "P-521", "K-256"];
  6237. }
  6238. checkAlgorithmParams(algorithm) {
  6239. this.checkRequiredProperty(algorithm, "hash");
  6240. this.checkHashAlgorithm(algorithm.hash, this.hashAlgorithms);
  6241. }
  6242. };
  6243. __name(EcdsaProvider, "EcdsaProvider");
  6244. var KEY_TYPES = ["secret", "private", "public"];
  6245. var CryptoKey = class {
  6246. static create(algorithm, type, extractable, usages) {
  6247. const key = new this();
  6248. key.algorithm = algorithm;
  6249. key.type = type;
  6250. key.extractable = extractable;
  6251. key.usages = usages;
  6252. return key;
  6253. }
  6254. static isKeyType(data) {
  6255. return KEY_TYPES.indexOf(data) !== -1;
  6256. }
  6257. get [Symbol.toStringTag]() {
  6258. return "CryptoKey";
  6259. }
  6260. };
  6261. __name(CryptoKey, "CryptoKey");
  6262. var EcdhProvider = class extends EllipticProvider {
  6263. constructor() {
  6264. super(...arguments);
  6265. this.name = "ECDH";
  6266. this.usages = {
  6267. privateKey: ["deriveBits", "deriveKey"],
  6268. publicKey: []
  6269. };
  6270. this.namedCurves = ["P-256", "P-384", "P-521", "K-256"];
  6271. }
  6272. checkAlgorithmParams(algorithm) {
  6273. this.checkRequiredProperty(algorithm, "public");
  6274. if (!(algorithm.public instanceof CryptoKey)) {
  6275. throw new TypeError("public: Is not a CryptoKey");
  6276. }
  6277. if (algorithm.public.type !== "public") {
  6278. throw new OperationError("public: Is not a public key");
  6279. }
  6280. if (algorithm.public.algorithm.name !== this.name) {
  6281. throw new OperationError(`public: Is not ${this.name} key`);
  6282. }
  6283. }
  6284. };
  6285. __name(EcdhProvider, "EcdhProvider");
  6286. var EcdhEsProvider = class extends EcdhProvider {
  6287. constructor() {
  6288. super(...arguments);
  6289. this.name = "ECDH-ES";
  6290. this.namedCurves = ["X25519", "X448"];
  6291. }
  6292. };
  6293. __name(EcdhEsProvider, "EcdhEsProvider");
  6294. var EdDsaProvider = class extends EllipticProvider {
  6295. constructor() {
  6296. super(...arguments);
  6297. this.name = "EdDSA";
  6298. this.usages = {
  6299. privateKey: ["sign"],
  6300. publicKey: ["verify"]
  6301. };
  6302. this.namedCurves = ["Ed25519", "Ed448"];
  6303. }
  6304. };
  6305. __name(EdDsaProvider, "EdDsaProvider");
  6306. var ObjectIdentifier2 = /* @__PURE__ */ __name(class ObjectIdentifier3 {
  6307. constructor(value) {
  6308. if (value) {
  6309. this.value = value;
  6310. }
  6311. }
  6312. }, "ObjectIdentifier");
  6313. __decorate([
  6314. AsnProp({ type: AsnPropTypes.ObjectIdentifier })
  6315. ], ObjectIdentifier2.prototype, "value", void 0);
  6316. ObjectIdentifier2 = __decorate([
  6317. AsnType({ type: AsnTypeTypes.Choice })
  6318. ], ObjectIdentifier2);
  6319. var AlgorithmIdentifier = class {
  6320. constructor(params) {
  6321. Object.assign(this, params);
  6322. }
  6323. };
  6324. __name(AlgorithmIdentifier, "AlgorithmIdentifier");
  6325. __decorate([
  6326. AsnProp({
  6327. type: AsnPropTypes.ObjectIdentifier
  6328. })
  6329. ], AlgorithmIdentifier.prototype, "algorithm", void 0);
  6330. __decorate([
  6331. AsnProp({
  6332. type: AsnPropTypes.Any,
  6333. optional: true
  6334. })
  6335. ], AlgorithmIdentifier.prototype, "parameters", void 0);
  6336. var PrivateKeyInfo = class {
  6337. constructor() {
  6338. this.version = 0;
  6339. this.privateKeyAlgorithm = new AlgorithmIdentifier();
  6340. this.privateKey = new ArrayBuffer(0);
  6341. }
  6342. };
  6343. __name(PrivateKeyInfo, "PrivateKeyInfo");
  6344. __decorate([
  6345. AsnProp({ type: AsnPropTypes.Integer })
  6346. ], PrivateKeyInfo.prototype, "version", void 0);
  6347. __decorate([
  6348. AsnProp({ type: AlgorithmIdentifier })
  6349. ], PrivateKeyInfo.prototype, "privateKeyAlgorithm", void 0);
  6350. __decorate([
  6351. AsnProp({ type: AsnPropTypes.OctetString })
  6352. ], PrivateKeyInfo.prototype, "privateKey", void 0);
  6353. __decorate([
  6354. AsnProp({ type: AsnPropTypes.Any, optional: true })
  6355. ], PrivateKeyInfo.prototype, "attributes", void 0);
  6356. var PublicKeyInfo = class {
  6357. constructor() {
  6358. this.publicKeyAlgorithm = new AlgorithmIdentifier();
  6359. this.publicKey = new ArrayBuffer(0);
  6360. }
  6361. };
  6362. __name(PublicKeyInfo, "PublicKeyInfo");
  6363. __decorate([
  6364. AsnProp({ type: AlgorithmIdentifier })
  6365. ], PublicKeyInfo.prototype, "publicKeyAlgorithm", void 0);
  6366. __decorate([
  6367. AsnProp({ type: AsnPropTypes.BitString })
  6368. ], PublicKeyInfo.prototype, "publicKey", void 0);
  6369. var JsonBase64UrlArrayBufferConverter = {
  6370. fromJSON: (value) => Convert.FromBase64Url(value),
  6371. toJSON: (value) => Convert.ToBase64Url(new Uint8Array(value))
  6372. };
  6373. var AsnIntegerArrayBufferConverter = {
  6374. fromASN: (value) => {
  6375. const valueHex = value.valueBlock.valueHex;
  6376. return !new Uint8Array(valueHex)[0] ? value.valueBlock.valueHex.slice(1) : value.valueBlock.valueHex;
  6377. },
  6378. toASN: (value) => {
  6379. const valueHex = new Uint8Array(value)[0] > 127 ? combine(new Uint8Array([0]).buffer, value) : value;
  6380. return new Integer({ valueHex });
  6381. }
  6382. };
  6383. var RsaPrivateKey = class {
  6384. constructor() {
  6385. this.version = 0;
  6386. this.modulus = new ArrayBuffer(0);
  6387. this.publicExponent = new ArrayBuffer(0);
  6388. this.privateExponent = new ArrayBuffer(0);
  6389. this.prime1 = new ArrayBuffer(0);
  6390. this.prime2 = new ArrayBuffer(0);
  6391. this.exponent1 = new ArrayBuffer(0);
  6392. this.exponent2 = new ArrayBuffer(0);
  6393. this.coefficient = new ArrayBuffer(0);
  6394. }
  6395. };
  6396. __name(RsaPrivateKey, "RsaPrivateKey");
  6397. __decorate([
  6398. AsnProp({ type: AsnPropTypes.Integer, converter: AsnIntegerConverter })
  6399. ], RsaPrivateKey.prototype, "version", void 0);
  6400. __decorate([
  6401. AsnProp({ type: AsnPropTypes.Integer, converter: AsnIntegerArrayBufferConverter }),
  6402. JsonProp({ name: "n", converter: JsonBase64UrlArrayBufferConverter })
  6403. ], RsaPrivateKey.prototype, "modulus", void 0);
  6404. __decorate([
  6405. AsnProp({ type: AsnPropTypes.Integer, converter: AsnIntegerArrayBufferConverter }),
  6406. JsonProp({ name: "e", converter: JsonBase64UrlArrayBufferConverter })
  6407. ], RsaPrivateKey.prototype, "publicExponent", void 0);
  6408. __decorate([
  6409. AsnProp({ type: AsnPropTypes.Integer, converter: AsnIntegerArrayBufferConverter }),
  6410. JsonProp({ name: "d", converter: JsonBase64UrlArrayBufferConverter })
  6411. ], RsaPrivateKey.prototype, "privateExponent", void 0);
  6412. __decorate([
  6413. AsnProp({ type: AsnPropTypes.Integer, converter: AsnIntegerArrayBufferConverter }),
  6414. JsonProp({ name: "p", converter: JsonBase64UrlArrayBufferConverter })
  6415. ], RsaPrivateKey.prototype, "prime1", void 0);
  6416. __decorate([
  6417. AsnProp({ type: AsnPropTypes.Integer, converter: AsnIntegerArrayBufferConverter }),
  6418. JsonProp({ name: "q", converter: JsonBase64UrlArrayBufferConverter })
  6419. ], RsaPrivateKey.prototype, "prime2", void 0);
  6420. __decorate([
  6421. AsnProp({ type: AsnPropTypes.Integer, converter: AsnIntegerArrayBufferConverter }),
  6422. JsonProp({ name: "dp", converter: JsonBase64UrlArrayBufferConverter })
  6423. ], RsaPrivateKey.prototype, "exponent1", void 0);
  6424. __decorate([
  6425. AsnProp({ type: AsnPropTypes.Integer, converter: AsnIntegerArrayBufferConverter }),
  6426. JsonProp({ name: "dq", converter: JsonBase64UrlArrayBufferConverter })
  6427. ], RsaPrivateKey.prototype, "exponent2", void 0);
  6428. __decorate([
  6429. AsnProp({ type: AsnPropTypes.Integer, converter: AsnIntegerArrayBufferConverter }),
  6430. JsonProp({ name: "qi", converter: JsonBase64UrlArrayBufferConverter })
  6431. ], RsaPrivateKey.prototype, "coefficient", void 0);
  6432. __decorate([
  6433. AsnProp({ type: AsnPropTypes.Any, optional: true })
  6434. ], RsaPrivateKey.prototype, "otherPrimeInfos", void 0);
  6435. var RsaPublicKey = class {
  6436. constructor() {
  6437. this.modulus = new ArrayBuffer(0);
  6438. this.publicExponent = new ArrayBuffer(0);
  6439. }
  6440. };
  6441. __name(RsaPublicKey, "RsaPublicKey");
  6442. __decorate([
  6443. AsnProp({ type: AsnPropTypes.Integer, converter: AsnIntegerArrayBufferConverter }),
  6444. JsonProp({ name: "n", converter: JsonBase64UrlArrayBufferConverter })
  6445. ], RsaPublicKey.prototype, "modulus", void 0);
  6446. __decorate([
  6447. AsnProp({ type: AsnPropTypes.Integer, converter: AsnIntegerArrayBufferConverter }),
  6448. JsonProp({ name: "e", converter: JsonBase64UrlArrayBufferConverter })
  6449. ], RsaPublicKey.prototype, "publicExponent", void 0);
  6450. var EcPublicKey = /* @__PURE__ */ __name(class EcPublicKey2 {
  6451. constructor(value) {
  6452. this.value = new ArrayBuffer(0);
  6453. if (value) {
  6454. this.value = value;
  6455. }
  6456. }
  6457. toJSON() {
  6458. let bytes = new Uint8Array(this.value);
  6459. if (bytes[0] !== 4) {
  6460. throw new CryptoError("Wrong ECPoint. Current version supports only Uncompressed (0x04) point");
  6461. }
  6462. bytes = new Uint8Array(this.value.slice(1));
  6463. const size = bytes.length / 2;
  6464. const offset = 0;
  6465. const json = {
  6466. x: Convert.ToBase64Url(bytes.buffer.slice(offset, offset + size)),
  6467. y: Convert.ToBase64Url(bytes.buffer.slice(offset + size, offset + size + size))
  6468. };
  6469. return json;
  6470. }
  6471. fromJSON(json) {
  6472. if (!("x" in json)) {
  6473. throw new Error("x: Missing required property");
  6474. }
  6475. if (!("y" in json)) {
  6476. throw new Error("y: Missing required property");
  6477. }
  6478. const x = Convert.FromBase64Url(json.x);
  6479. const y = Convert.FromBase64Url(json.y);
  6480. const value = combine(new Uint8Array([4]).buffer, x, y);
  6481. this.value = new Uint8Array(value).buffer;
  6482. return this;
  6483. }
  6484. }, "EcPublicKey");
  6485. __decorate([
  6486. AsnProp({ type: AsnPropTypes.OctetString })
  6487. ], EcPublicKey.prototype, "value", void 0);
  6488. EcPublicKey = __decorate([
  6489. AsnType({ type: AsnTypeTypes.Choice })
  6490. ], EcPublicKey);
  6491. var EcPrivateKey = class {
  6492. constructor() {
  6493. this.version = 1;
  6494. this.privateKey = new ArrayBuffer(0);
  6495. }
  6496. fromJSON(json) {
  6497. if (!("d" in json)) {
  6498. throw new Error("d: Missing required property");
  6499. }
  6500. this.privateKey = Convert.FromBase64Url(json.d);
  6501. if ("x" in json) {
  6502. const publicKey = new EcPublicKey();
  6503. publicKey.fromJSON(json);
  6504. this.publicKey = AsnSerializer.toASN(publicKey).valueBlock.valueHex;
  6505. }
  6506. return this;
  6507. }
  6508. toJSON() {
  6509. const jwk = {};
  6510. jwk.d = Convert.ToBase64Url(this.privateKey);
  6511. if (this.publicKey) {
  6512. Object.assign(jwk, new EcPublicKey(this.publicKey).toJSON());
  6513. }
  6514. return jwk;
  6515. }
  6516. };
  6517. __name(EcPrivateKey, "EcPrivateKey");
  6518. __decorate([
  6519. AsnProp({ type: AsnPropTypes.Integer, converter: AsnIntegerConverter })
  6520. ], EcPrivateKey.prototype, "version", void 0);
  6521. __decorate([
  6522. AsnProp({ type: AsnPropTypes.OctetString })
  6523. ], EcPrivateKey.prototype, "privateKey", void 0);
  6524. __decorate([
  6525. AsnProp({ context: 0, type: AsnPropTypes.Any, optional: true })
  6526. ], EcPrivateKey.prototype, "parameters", void 0);
  6527. __decorate([
  6528. AsnProp({ context: 1, type: AsnPropTypes.BitString, optional: true })
  6529. ], EcPrivateKey.prototype, "publicKey", void 0);
  6530. var AsnIntegerWithoutPaddingConverter = {
  6531. fromASN: (value) => {
  6532. const bytes = new Uint8Array(value.valueBlock.valueHex);
  6533. return bytes[0] === 0 ? bytes.buffer.slice(1) : bytes.buffer;
  6534. },
  6535. toASN: (value) => {
  6536. const bytes = new Uint8Array(value);
  6537. if (bytes[0] > 127) {
  6538. const newValue = new Uint8Array(bytes.length + 1);
  6539. newValue.set(bytes, 1);
  6540. return new Integer({ valueHex: newValue.buffer });
  6541. }
  6542. return new Integer({ valueHex: value });
  6543. }
  6544. };
  6545. var index$2 = /* @__PURE__ */ Object.freeze({
  6546. __proto__: null,
  6547. AsnIntegerWithoutPaddingConverter
  6548. });
  6549. var EcUtils = class {
  6550. static decodePoint(data, pointSize) {
  6551. const view = BufferSourceConverter.toUint8Array(data);
  6552. if (view.length === 0 || view[0] !== 4) {
  6553. throw new Error("Only uncompressed point format supported");
  6554. }
  6555. const n = (view.length - 1) / 2;
  6556. if (n !== Math.ceil(pointSize / 8)) {
  6557. throw new Error("Point does not match field size");
  6558. }
  6559. const xb = view.slice(1, n + 1);
  6560. const yb = view.slice(n + 1, n + 1 + n);
  6561. return { x: xb, y: yb };
  6562. }
  6563. static encodePoint(point, pointSize) {
  6564. const size = Math.ceil(pointSize / 8);
  6565. if (point.x.byteLength !== size || point.y.byteLength !== size) {
  6566. throw new Error("X,Y coordinates don't match point size criteria");
  6567. }
  6568. const x = BufferSourceConverter.toUint8Array(point.x);
  6569. const y = BufferSourceConverter.toUint8Array(point.y);
  6570. const res = new Uint8Array(size * 2 + 1);
  6571. res[0] = 4;
  6572. res.set(x, 1);
  6573. res.set(y, size + 1);
  6574. return res;
  6575. }
  6576. static getSize(pointSize) {
  6577. return Math.ceil(pointSize / 8);
  6578. }
  6579. static encodeSignature(signature, pointSize) {
  6580. const size = this.getSize(pointSize);
  6581. const r = BufferSourceConverter.toUint8Array(signature.r);
  6582. const s = BufferSourceConverter.toUint8Array(signature.s);
  6583. const res = new Uint8Array(size * 2);
  6584. res.set(this.padStart(r, size));
  6585. res.set(this.padStart(s, size), size);
  6586. return res;
  6587. }
  6588. static decodeSignature(data, pointSize) {
  6589. const size = this.getSize(pointSize);
  6590. const view = BufferSourceConverter.toUint8Array(data);
  6591. if (view.length !== size * 2) {
  6592. throw new Error("Incorrect size of the signature");
  6593. }
  6594. const r = view.slice(0, size);
  6595. const s = view.slice(size);
  6596. return {
  6597. r: this.trimStart(r),
  6598. s: this.trimStart(s)
  6599. };
  6600. }
  6601. static trimStart(data) {
  6602. let i = 0;
  6603. while (i < data.length - 1 && data[i] === 0) {
  6604. i++;
  6605. }
  6606. if (i === 0) {
  6607. return data;
  6608. }
  6609. return data.slice(i, data.length);
  6610. }
  6611. static padStart(data, size) {
  6612. if (size === data.length) {
  6613. return data;
  6614. }
  6615. const res = new Uint8Array(size);
  6616. res.set(data, size - data.length);
  6617. return res;
  6618. }
  6619. };
  6620. __name(EcUtils, "EcUtils");
  6621. var EcDsaSignature = class {
  6622. constructor() {
  6623. this.r = new ArrayBuffer(0);
  6624. this.s = new ArrayBuffer(0);
  6625. }
  6626. static fromWebCryptoSignature(value) {
  6627. const pointSize = value.byteLength / 2;
  6628. const point = EcUtils.decodeSignature(value, pointSize * 8);
  6629. const ecSignature = new EcDsaSignature();
  6630. ecSignature.r = BufferSourceConverter.toArrayBuffer(point.r);
  6631. ecSignature.s = BufferSourceConverter.toArrayBuffer(point.s);
  6632. return ecSignature;
  6633. }
  6634. toWebCryptoSignature(pointSize) {
  6635. pointSize !== null && pointSize !== void 0 ? pointSize : pointSize = Math.max(this.r.byteLength, this.s.byteLength) * 8;
  6636. const signature = EcUtils.encodeSignature(this, pointSize);
  6637. return signature.buffer;
  6638. }
  6639. };
  6640. __name(EcDsaSignature, "EcDsaSignature");
  6641. __decorate([
  6642. AsnProp({ type: AsnPropTypes.Integer, converter: AsnIntegerWithoutPaddingConverter })
  6643. ], EcDsaSignature.prototype, "r", void 0);
  6644. __decorate([
  6645. AsnProp({ type: AsnPropTypes.Integer, converter: AsnIntegerWithoutPaddingConverter })
  6646. ], EcDsaSignature.prototype, "s", void 0);
  6647. var OneAsymmetricKey = class extends PrivateKeyInfo {
  6648. };
  6649. __name(OneAsymmetricKey, "OneAsymmetricKey");
  6650. __decorate([
  6651. AsnProp({ context: 1, implicit: true, type: AsnPropTypes.BitString, optional: true })
  6652. ], OneAsymmetricKey.prototype, "publicKey", void 0);
  6653. var EdPrivateKey = /* @__PURE__ */ __name(class EdPrivateKey2 {
  6654. constructor() {
  6655. this.value = new ArrayBuffer(0);
  6656. }
  6657. fromJSON(json) {
  6658. if (!json.d) {
  6659. throw new Error("d: Missing required property");
  6660. }
  6661. this.value = Convert.FromBase64Url(json.d);
  6662. return this;
  6663. }
  6664. toJSON() {
  6665. const jwk = {
  6666. d: Convert.ToBase64Url(this.value)
  6667. };
  6668. return jwk;
  6669. }
  6670. }, "EdPrivateKey");
  6671. __decorate([
  6672. AsnProp({ type: AsnPropTypes.OctetString })
  6673. ], EdPrivateKey.prototype, "value", void 0);
  6674. EdPrivateKey = __decorate([
  6675. AsnType({ type: AsnTypeTypes.Choice })
  6676. ], EdPrivateKey);
  6677. var EdPublicKey = /* @__PURE__ */ __name(class EdPublicKey2 {
  6678. constructor(value) {
  6679. this.value = new ArrayBuffer(0);
  6680. if (value) {
  6681. this.value = value;
  6682. }
  6683. }
  6684. toJSON() {
  6685. const json = {
  6686. x: Convert.ToBase64Url(this.value)
  6687. };
  6688. return json;
  6689. }
  6690. fromJSON(json) {
  6691. if (!("x" in json)) {
  6692. throw new Error("x: Missing required property");
  6693. }
  6694. this.value = Convert.FromBase64Url(json.x);
  6695. return this;
  6696. }
  6697. }, "EdPublicKey");
  6698. __decorate([
  6699. AsnProp({ type: AsnPropTypes.BitString })
  6700. ], EdPublicKey.prototype, "value", void 0);
  6701. EdPublicKey = __decorate([
  6702. AsnType({ type: AsnTypeTypes.Choice })
  6703. ], EdPublicKey);
  6704. var CurvePrivateKey = /* @__PURE__ */ __name(class CurvePrivateKey2 {
  6705. }, "CurvePrivateKey");
  6706. __decorate([
  6707. AsnProp({ type: AsnPropTypes.OctetString }),
  6708. JsonProp({ type: JsonPropTypes.String, converter: JsonBase64UrlArrayBufferConverter })
  6709. ], CurvePrivateKey.prototype, "d", void 0);
  6710. CurvePrivateKey = __decorate([
  6711. AsnType({ type: AsnTypeTypes.Choice })
  6712. ], CurvePrivateKey);
  6713. var idSecp256r1 = "1.2.840.10045.3.1.7";
  6714. var idEllipticCurve = "1.3.132.0";
  6715. var idSecp384r1 = `${idEllipticCurve}.34`;
  6716. var idSecp521r1 = `${idEllipticCurve}.35`;
  6717. var idSecp256k1 = `${idEllipticCurve}.10`;
  6718. var idVersionOne = "1.3.36.3.3.2.8.1.1";
  6719. var idBrainpoolP160r1 = `${idVersionOne}.1`;
  6720. var idBrainpoolP160t1 = `${idVersionOne}.2`;
  6721. var idBrainpoolP192r1 = `${idVersionOne}.3`;
  6722. var idBrainpoolP192t1 = `${idVersionOne}.4`;
  6723. var idBrainpoolP224r1 = `${idVersionOne}.5`;
  6724. var idBrainpoolP224t1 = `${idVersionOne}.6`;
  6725. var idBrainpoolP256r1 = `${idVersionOne}.7`;
  6726. var idBrainpoolP256t1 = `${idVersionOne}.8`;
  6727. var idBrainpoolP320r1 = `${idVersionOne}.9`;
  6728. var idBrainpoolP320t1 = `${idVersionOne}.10`;
  6729. var idBrainpoolP384r1 = `${idVersionOne}.11`;
  6730. var idBrainpoolP384t1 = `${idVersionOne}.12`;
  6731. var idBrainpoolP512r1 = `${idVersionOne}.13`;
  6732. var idBrainpoolP512t1 = `${idVersionOne}.14`;
  6733. var idX25519 = "1.3.101.110";
  6734. var idX448 = "1.3.101.111";
  6735. var idEd25519 = "1.3.101.112";
  6736. var idEd448 = "1.3.101.113";
  6737. var index$1 = /* @__PURE__ */ Object.freeze({
  6738. __proto__: null,
  6739. converters: index$2,
  6740. get ObjectIdentifier() {
  6741. return ObjectIdentifier2;
  6742. },
  6743. AlgorithmIdentifier,
  6744. PrivateKeyInfo,
  6745. PublicKeyInfo,
  6746. RsaPrivateKey,
  6747. RsaPublicKey,
  6748. EcPrivateKey,
  6749. get EcPublicKey() {
  6750. return EcPublicKey;
  6751. },
  6752. EcDsaSignature,
  6753. OneAsymmetricKey,
  6754. get EdPrivateKey() {
  6755. return EdPrivateKey;
  6756. },
  6757. get EdPublicKey() {
  6758. return EdPublicKey;
  6759. },
  6760. get CurvePrivateKey() {
  6761. return CurvePrivateKey;
  6762. },
  6763. idSecp256r1,
  6764. idEllipticCurve,
  6765. idSecp384r1,
  6766. idSecp521r1,
  6767. idSecp256k1,
  6768. idVersionOne,
  6769. idBrainpoolP160r1,
  6770. idBrainpoolP160t1,
  6771. idBrainpoolP192r1,
  6772. idBrainpoolP192t1,
  6773. idBrainpoolP224r1,
  6774. idBrainpoolP224t1,
  6775. idBrainpoolP256r1,
  6776. idBrainpoolP256t1,
  6777. idBrainpoolP320r1,
  6778. idBrainpoolP320t1,
  6779. idBrainpoolP384r1,
  6780. idBrainpoolP384t1,
  6781. idBrainpoolP512r1,
  6782. idBrainpoolP512t1,
  6783. idX25519,
  6784. idX448,
  6785. idEd25519,
  6786. idEd448
  6787. });
  6788. var EcCurves = class {
  6789. constructor() {
  6790. }
  6791. static register(item) {
  6792. const oid = new ObjectIdentifier2();
  6793. oid.value = item.id;
  6794. const raw = AsnConvert.serialize(oid);
  6795. this.items.push({
  6796. ...item,
  6797. raw
  6798. });
  6799. this.names.push(item.name);
  6800. }
  6801. static find(nameOrId) {
  6802. nameOrId = nameOrId.toUpperCase();
  6803. for (const item of this.items) {
  6804. if (item.name.toUpperCase() === nameOrId || item.id.toUpperCase() === nameOrId) {
  6805. return item;
  6806. }
  6807. }
  6808. return null;
  6809. }
  6810. static get(nameOrId) {
  6811. const res = this.find(nameOrId);
  6812. if (!res) {
  6813. throw new Error(`Unsupported EC named curve '${nameOrId}'`);
  6814. }
  6815. return res;
  6816. }
  6817. };
  6818. __name(EcCurves, "EcCurves");
  6819. EcCurves.items = [];
  6820. EcCurves.names = [];
  6821. EcCurves.register({ name: "P-256", id: idSecp256r1, size: 256 });
  6822. EcCurves.register({ name: "P-384", id: idSecp384r1, size: 384 });
  6823. EcCurves.register({ name: "P-521", id: idSecp521r1, size: 521 });
  6824. EcCurves.register({ name: "K-256", id: idSecp256k1, size: 256 });
  6825. EcCurves.register({ name: "brainpoolP160r1", id: idBrainpoolP160r1, size: 160 });
  6826. EcCurves.register({ name: "brainpoolP160t1", id: idBrainpoolP160t1, size: 160 });
  6827. EcCurves.register({ name: "brainpoolP192r1", id: idBrainpoolP192r1, size: 192 });
  6828. EcCurves.register({ name: "brainpoolP192t1", id: idBrainpoolP192t1, size: 192 });
  6829. EcCurves.register({ name: "brainpoolP224r1", id: idBrainpoolP224r1, size: 224 });
  6830. EcCurves.register({ name: "brainpoolP224t1", id: idBrainpoolP224t1, size: 224 });
  6831. EcCurves.register({ name: "brainpoolP256r1", id: idBrainpoolP256r1, size: 256 });
  6832. EcCurves.register({ name: "brainpoolP256t1", id: idBrainpoolP256t1, size: 256 });
  6833. EcCurves.register({ name: "brainpoolP320r1", id: idBrainpoolP320r1, size: 320 });
  6834. EcCurves.register({ name: "brainpoolP320t1", id: idBrainpoolP320t1, size: 320 });
  6835. EcCurves.register({ name: "brainpoolP384r1", id: idBrainpoolP384r1, size: 384 });
  6836. EcCurves.register({ name: "brainpoolP384t1", id: idBrainpoolP384t1, size: 384 });
  6837. EcCurves.register({ name: "brainpoolP512r1", id: idBrainpoolP512r1, size: 512 });
  6838. EcCurves.register({ name: "brainpoolP512t1", id: idBrainpoolP512t1, size: 512 });
  6839. var HmacProvider = class extends ProviderCrypto {
  6840. constructor() {
  6841. super(...arguments);
  6842. this.name = "HMAC";
  6843. this.hashAlgorithms = ["SHA-1", "SHA-256", "SHA-384", "SHA-512"];
  6844. this.usages = ["sign", "verify"];
  6845. }
  6846. getDefaultLength(algName) {
  6847. switch (algName.toUpperCase()) {
  6848. case "SHA-1":
  6849. case "SHA-256":
  6850. case "SHA-384":
  6851. case "SHA-512":
  6852. return 512;
  6853. default:
  6854. throw new Error(`Unknown algorithm name '${algName}'`);
  6855. }
  6856. }
  6857. checkGenerateKeyParams(algorithm) {
  6858. this.checkRequiredProperty(algorithm, "hash");
  6859. this.checkHashAlgorithm(algorithm.hash, this.hashAlgorithms);
  6860. if ("length" in algorithm) {
  6861. if (typeof algorithm.length !== "number") {
  6862. throw new TypeError("length: Is not a Number");
  6863. }
  6864. if (algorithm.length < 1) {
  6865. throw new RangeError("length: Number is out of range");
  6866. }
  6867. }
  6868. }
  6869. checkImportParams(algorithm) {
  6870. this.checkRequiredProperty(algorithm, "hash");
  6871. this.checkHashAlgorithm(algorithm.hash, this.hashAlgorithms);
  6872. }
  6873. };
  6874. __name(HmacProvider, "HmacProvider");
  6875. var Pbkdf2Provider = class extends ProviderCrypto {
  6876. constructor() {
  6877. super(...arguments);
  6878. this.name = "PBKDF2";
  6879. this.hashAlgorithms = ["SHA-1", "SHA-256", "SHA-384", "SHA-512"];
  6880. this.usages = ["deriveBits", "deriveKey"];
  6881. }
  6882. checkAlgorithmParams(algorithm) {
  6883. this.checkRequiredProperty(algorithm, "hash");
  6884. this.checkHashAlgorithm(algorithm.hash, this.hashAlgorithms);
  6885. this.checkRequiredProperty(algorithm, "salt");
  6886. if (!(algorithm.salt instanceof ArrayBuffer || ArrayBuffer.isView(algorithm.salt))) {
  6887. throw new TypeError("salt: Is not of type '(ArrayBuffer or ArrayBufferView)'");
  6888. }
  6889. this.checkRequiredProperty(algorithm, "iterations");
  6890. if (typeof algorithm.iterations !== "number") {
  6891. throw new TypeError("iterations: Is not a Number");
  6892. }
  6893. if (algorithm.iterations < 1) {
  6894. throw new TypeError("iterations: Is less than 1");
  6895. }
  6896. }
  6897. checkImportKey(format, keyData, algorithm, extractable, keyUsages, ...args) {
  6898. super.checkImportKey(format, keyData, algorithm, extractable, keyUsages);
  6899. if (extractable) {
  6900. throw new SyntaxError("extractable: Must be 'false'");
  6901. }
  6902. }
  6903. };
  6904. __name(Pbkdf2Provider, "Pbkdf2Provider");
  6905. var HkdfProvider = class extends ProviderCrypto {
  6906. constructor() {
  6907. super(...arguments);
  6908. this.name = "HKDF";
  6909. this.hashAlgorithms = ["SHA-1", "SHA-256", "SHA-384", "SHA-512"];
  6910. this.usages = ["deriveKey", "deriveBits"];
  6911. }
  6912. checkAlgorithmParams(algorithm) {
  6913. this.checkRequiredProperty(algorithm, "hash");
  6914. this.checkHashAlgorithm(algorithm.hash, this.hashAlgorithms);
  6915. this.checkRequiredProperty(algorithm, "salt");
  6916. if (!BufferSourceConverter.isBufferSource(algorithm.salt)) {
  6917. throw new TypeError("salt: Is not of type '(ArrayBuffer or ArrayBufferView)'");
  6918. }
  6919. this.checkRequiredProperty(algorithm, "info");
  6920. if (!BufferSourceConverter.isBufferSource(algorithm.info)) {
  6921. throw new TypeError("salt: Is not of type '(ArrayBuffer or ArrayBufferView)'");
  6922. }
  6923. }
  6924. checkImportKey(format, keyData, algorithm, extractable, keyUsages, ...args) {
  6925. super.checkImportKey(format, keyData, algorithm, extractable, keyUsages);
  6926. if (extractable) {
  6927. throw new SyntaxError("extractable: Must be 'false'");
  6928. }
  6929. }
  6930. };
  6931. __name(HkdfProvider, "HkdfProvider");
  6932. var ShakeProvider = class extends ProviderCrypto {
  6933. constructor() {
  6934. super(...arguments);
  6935. this.usages = [];
  6936. this.defaultLength = 0;
  6937. }
  6938. digest(...args) {
  6939. args[0] = { length: this.defaultLength, ...args[0] };
  6940. return super.digest.apply(this, args);
  6941. }
  6942. checkDigest(algorithm, data) {
  6943. super.checkDigest(algorithm, data);
  6944. const length = algorithm.length || 0;
  6945. if (typeof length !== "number") {
  6946. throw new TypeError("length: Is not a Number");
  6947. }
  6948. if (length < 0) {
  6949. throw new TypeError("length: Is negative");
  6950. }
  6951. }
  6952. };
  6953. __name(ShakeProvider, "ShakeProvider");
  6954. var Shake128Provider = class extends ShakeProvider {
  6955. constructor() {
  6956. super(...arguments);
  6957. this.name = "shake128";
  6958. this.defaultLength = 16;
  6959. }
  6960. };
  6961. __name(Shake128Provider, "Shake128Provider");
  6962. var Shake256Provider = class extends ShakeProvider {
  6963. constructor() {
  6964. super(...arguments);
  6965. this.name = "shake256";
  6966. this.defaultLength = 32;
  6967. }
  6968. };
  6969. __name(Shake256Provider, "Shake256Provider");
  6970. var Crypto = class {
  6971. get [Symbol.toStringTag]() {
  6972. return "Crypto";
  6973. }
  6974. randomUUID() {
  6975. const b = this.getRandomValues(new Uint8Array(16));
  6976. b[6] = b[6] & 15 | 64;
  6977. b[8] = b[8] & 63 | 128;
  6978. const uuid2 = Convert.ToHex(b).toLowerCase();
  6979. return `${uuid2.substring(0, 8)}-${uuid2.substring(8, 12)}-${uuid2.substring(12, 16)}-${uuid2.substring(16)}`;
  6980. }
  6981. };
  6982. __name(Crypto, "Crypto");
  6983. var ProviderStorage = class {
  6984. constructor() {
  6985. this.items = {};
  6986. }
  6987. get(algorithmName) {
  6988. return this.items[algorithmName.toLowerCase()] || null;
  6989. }
  6990. set(provider) {
  6991. this.items[provider.name.toLowerCase()] = provider;
  6992. }
  6993. removeAt(algorithmName) {
  6994. const provider = this.get(algorithmName.toLowerCase());
  6995. if (provider) {
  6996. delete this.items[algorithmName];
  6997. }
  6998. return provider;
  6999. }
  7000. has(name) {
  7001. return !!this.get(name);
  7002. }
  7003. get length() {
  7004. return Object.keys(this.items).length;
  7005. }
  7006. get algorithms() {
  7007. const algorithms = [];
  7008. for (const key in this.items) {
  7009. const provider = this.items[key];
  7010. algorithms.push(provider.name);
  7011. }
  7012. return algorithms.sort();
  7013. }
  7014. };
  7015. __name(ProviderStorage, "ProviderStorage");
  7016. var SubtleCrypto = class {
  7017. constructor() {
  7018. this.providers = new ProviderStorage();
  7019. }
  7020. static isHashedAlgorithm(data) {
  7021. return data && typeof data === "object" && "name" in data && "hash" in data ? true : false;
  7022. }
  7023. get [Symbol.toStringTag]() {
  7024. return "SubtleCrypto";
  7025. }
  7026. async digest(...args) {
  7027. this.checkRequiredArguments(args, 2, "digest");
  7028. const [algorithm, data, ...params] = args;
  7029. const preparedAlgorithm = this.prepareAlgorithm(algorithm);
  7030. const preparedData = BufferSourceConverter.toArrayBuffer(data);
  7031. const provider = this.getProvider(preparedAlgorithm.name);
  7032. const result = await provider.digest(preparedAlgorithm, preparedData, ...params);
  7033. return result;
  7034. }
  7035. async generateKey(...args) {
  7036. this.checkRequiredArguments(args, 3, "generateKey");
  7037. const [algorithm, extractable, keyUsages, ...params] = args;
  7038. const preparedAlgorithm = this.prepareAlgorithm(algorithm);
  7039. const provider = this.getProvider(preparedAlgorithm.name);
  7040. const result = await provider.generateKey({ ...preparedAlgorithm, name: provider.name }, extractable, keyUsages, ...params);
  7041. return result;
  7042. }
  7043. async sign(...args) {
  7044. this.checkRequiredArguments(args, 3, "sign");
  7045. const [algorithm, key, data, ...params] = args;
  7046. this.checkCryptoKey(key);
  7047. const preparedAlgorithm = this.prepareAlgorithm(algorithm);
  7048. const preparedData = BufferSourceConverter.toArrayBuffer(data);
  7049. const provider = this.getProvider(preparedAlgorithm.name);
  7050. const result = await provider.sign({ ...preparedAlgorithm, name: provider.name }, key, preparedData, ...params);
  7051. return result;
  7052. }
  7053. async verify(...args) {
  7054. this.checkRequiredArguments(args, 4, "verify");
  7055. const [algorithm, key, signature, data, ...params] = args;
  7056. this.checkCryptoKey(key);
  7057. const preparedAlgorithm = this.prepareAlgorithm(algorithm);
  7058. const preparedData = BufferSourceConverter.toArrayBuffer(data);
  7059. const preparedSignature = BufferSourceConverter.toArrayBuffer(signature);
  7060. const provider = this.getProvider(preparedAlgorithm.name);
  7061. const result = await provider.verify({ ...preparedAlgorithm, name: provider.name }, key, preparedSignature, preparedData, ...params);
  7062. return result;
  7063. }
  7064. async encrypt(...args) {
  7065. this.checkRequiredArguments(args, 3, "encrypt");
  7066. const [algorithm, key, data, ...params] = args;
  7067. this.checkCryptoKey(key);
  7068. const preparedAlgorithm = this.prepareAlgorithm(algorithm);
  7069. const preparedData = BufferSourceConverter.toArrayBuffer(data);
  7070. const provider = this.getProvider(preparedAlgorithm.name);
  7071. const result = await provider.encrypt({ ...preparedAlgorithm, name: provider.name }, key, preparedData, { keyUsage: true }, ...params);
  7072. return result;
  7073. }
  7074. async decrypt(...args) {
  7075. this.checkRequiredArguments(args, 3, "decrypt");
  7076. const [algorithm, key, data, ...params] = args;
  7077. this.checkCryptoKey(key);
  7078. const preparedAlgorithm = this.prepareAlgorithm(algorithm);
  7079. const preparedData = BufferSourceConverter.toArrayBuffer(data);
  7080. const provider = this.getProvider(preparedAlgorithm.name);
  7081. const result = await provider.decrypt({ ...preparedAlgorithm, name: provider.name }, key, preparedData, { keyUsage: true }, ...params);
  7082. return result;
  7083. }
  7084. async deriveBits(...args) {
  7085. this.checkRequiredArguments(args, 3, "deriveBits");
  7086. const [algorithm, baseKey, length, ...params] = args;
  7087. this.checkCryptoKey(baseKey);
  7088. const preparedAlgorithm = this.prepareAlgorithm(algorithm);
  7089. const provider = this.getProvider(preparedAlgorithm.name);
  7090. const result = await provider.deriveBits({ ...preparedAlgorithm, name: provider.name }, baseKey, length, { keyUsage: true }, ...params);
  7091. return result;
  7092. }
  7093. async deriveKey(...args) {
  7094. this.checkRequiredArguments(args, 5, "deriveKey");
  7095. const [algorithm, baseKey, derivedKeyType, extractable, keyUsages, ...params] = args;
  7096. const preparedDerivedKeyType = this.prepareAlgorithm(derivedKeyType);
  7097. const importProvider = this.getProvider(preparedDerivedKeyType.name);
  7098. importProvider.checkDerivedKeyParams(preparedDerivedKeyType);
  7099. const preparedAlgorithm = this.prepareAlgorithm(algorithm);
  7100. const provider = this.getProvider(preparedAlgorithm.name);
  7101. provider.checkCryptoKey(baseKey, "deriveKey");
  7102. const derivedBits = await provider.deriveBits({ ...preparedAlgorithm, name: provider.name }, baseKey, derivedKeyType.length || 512, { keyUsage: false }, ...params);
  7103. return this.importKey("raw", derivedBits, derivedKeyType, extractable, keyUsages, ...params);
  7104. }
  7105. async exportKey(...args) {
  7106. this.checkRequiredArguments(args, 2, "exportKey");
  7107. const [format, key, ...params] = args;
  7108. this.checkCryptoKey(key);
  7109. const provider = this.getProvider(key.algorithm.name);
  7110. const result = await provider.exportKey(format, key, ...params);
  7111. return result;
  7112. }
  7113. async importKey(...args) {
  7114. this.checkRequiredArguments(args, 5, "importKey");
  7115. const [format, keyData, algorithm, extractable, keyUsages, ...params] = args;
  7116. const preparedAlgorithm = this.prepareAlgorithm(algorithm);
  7117. const provider = this.getProvider(preparedAlgorithm.name);
  7118. if (["pkcs8", "spki", "raw"].indexOf(format) !== -1) {
  7119. const preparedData = BufferSourceConverter.toArrayBuffer(keyData);
  7120. return provider.importKey(format, preparedData, { ...preparedAlgorithm, name: provider.name }, extractable, keyUsages, ...params);
  7121. } else {
  7122. if (!keyData.kty) {
  7123. throw new TypeError("keyData: Is not JSON");
  7124. }
  7125. }
  7126. return provider.importKey(format, keyData, { ...preparedAlgorithm, name: provider.name }, extractable, keyUsages, ...params);
  7127. }
  7128. async wrapKey(format, key, wrappingKey, wrapAlgorithm, ...args) {
  7129. let keyData = await this.exportKey(format, key, ...args);
  7130. if (format === "jwk") {
  7131. const json = JSON.stringify(keyData);
  7132. keyData = Convert.FromUtf8String(json);
  7133. }
  7134. const preparedAlgorithm = this.prepareAlgorithm(wrapAlgorithm);
  7135. const preparedData = BufferSourceConverter.toArrayBuffer(keyData);
  7136. const provider = this.getProvider(preparedAlgorithm.name);
  7137. return provider.encrypt({ ...preparedAlgorithm, name: provider.name }, wrappingKey, preparedData, { keyUsage: false }, ...args);
  7138. }
  7139. async unwrapKey(format, wrappedKey, unwrappingKey, unwrapAlgorithm, unwrappedKeyAlgorithm, extractable, keyUsages, ...args) {
  7140. const preparedAlgorithm = this.prepareAlgorithm(unwrapAlgorithm);
  7141. const preparedData = BufferSourceConverter.toArrayBuffer(wrappedKey);
  7142. const provider = this.getProvider(preparedAlgorithm.name);
  7143. let keyData = await provider.decrypt({ ...preparedAlgorithm, name: provider.name }, unwrappingKey, preparedData, { keyUsage: false }, ...args);
  7144. if (format === "jwk") {
  7145. try {
  7146. keyData = JSON.parse(Convert.ToUtf8String(keyData));
  7147. } catch (e) {
  7148. const error = new TypeError("wrappedKey: Is not a JSON");
  7149. error.internal = e;
  7150. throw error;
  7151. }
  7152. }
  7153. return this.importKey(format, keyData, unwrappedKeyAlgorithm, extractable, keyUsages, ...args);
  7154. }
  7155. checkRequiredArguments(args, size, methodName) {
  7156. if (args.length < size) {
  7157. throw new TypeError(`Failed to execute '${methodName}' on 'SubtleCrypto': ${size} arguments required, but only ${args.length} present`);
  7158. }
  7159. }
  7160. prepareAlgorithm(algorithm) {
  7161. if (typeof algorithm === "string") {
  7162. return {
  7163. name: algorithm
  7164. };
  7165. }
  7166. if (SubtleCrypto.isHashedAlgorithm(algorithm)) {
  7167. const preparedAlgorithm = { ...algorithm };
  7168. preparedAlgorithm.hash = this.prepareAlgorithm(algorithm.hash);
  7169. return preparedAlgorithm;
  7170. }
  7171. return { ...algorithm };
  7172. }
  7173. getProvider(name) {
  7174. const provider = this.providers.get(name);
  7175. if (!provider) {
  7176. throw new AlgorithmError("Unrecognized name");
  7177. }
  7178. return provider;
  7179. }
  7180. checkCryptoKey(key) {
  7181. if (!(key instanceof CryptoKey)) {
  7182. throw new TypeError(`Key is not of type 'CryptoKey'`);
  7183. }
  7184. }
  7185. };
  7186. __name(SubtleCrypto, "SubtleCrypto");
  7187. // ../../node_modules/.pnpm/@peculiar+webcrypto@1.4.0/node_modules/@peculiar/webcrypto/build/webcrypto.es.js
  7188. var crypto = __toESM(require("crypto"));
  7189. var import_crypto = __toESM(require("crypto"));
  7190. var process = __toESM(require("process"));
  7191. var JsonBase64UrlConverter = {
  7192. fromJSON: (value) => Buffer.from(Convert.FromBase64Url(value)),
  7193. toJSON: (value) => Convert.ToBase64Url(value)
  7194. };
  7195. var CryptoKey2 = class extends CryptoKey {
  7196. constructor() {
  7197. super(...arguments);
  7198. this.data = Buffer.alloc(0);
  7199. this.algorithm = { name: "" };
  7200. this.extractable = false;
  7201. this.type = "secret";
  7202. this.usages = [];
  7203. this.kty = "oct";
  7204. this.alg = "";
  7205. }
  7206. };
  7207. __name(CryptoKey2, "CryptoKey");
  7208. __decorate([
  7209. JsonProp({ name: "ext", type: JsonPropTypes.Boolean, optional: true })
  7210. ], CryptoKey2.prototype, "extractable", void 0);
  7211. __decorate([
  7212. JsonProp({ name: "key_ops", type: JsonPropTypes.String, repeated: true, optional: true })
  7213. ], CryptoKey2.prototype, "usages", void 0);
  7214. __decorate([
  7215. JsonProp({ type: JsonPropTypes.String })
  7216. ], CryptoKey2.prototype, "kty", void 0);
  7217. __decorate([
  7218. JsonProp({ type: JsonPropTypes.String, optional: true })
  7219. ], CryptoKey2.prototype, "alg", void 0);
  7220. var SymmetricKey = class extends CryptoKey2 {
  7221. constructor() {
  7222. super(...arguments);
  7223. this.kty = "oct";
  7224. this.type = "secret";
  7225. }
  7226. };
  7227. __name(SymmetricKey, "SymmetricKey");
  7228. var AsymmetricKey = class extends CryptoKey2 {
  7229. };
  7230. __name(AsymmetricKey, "AsymmetricKey");
  7231. var AesCryptoKey = class extends SymmetricKey {
  7232. get alg() {
  7233. switch (this.algorithm.name.toUpperCase()) {
  7234. case "AES-CBC":
  7235. return `A${this.algorithm.length}CBC`;
  7236. case "AES-CTR":
  7237. return `A${this.algorithm.length}CTR`;
  7238. case "AES-GCM":
  7239. return `A${this.algorithm.length}GCM`;
  7240. case "AES-KW":
  7241. return `A${this.algorithm.length}KW`;
  7242. case "AES-CMAC":
  7243. return `A${this.algorithm.length}CMAC`;
  7244. case "AES-ECB":
  7245. return `A${this.algorithm.length}ECB`;
  7246. default:
  7247. throw new AlgorithmError("Unsupported algorithm name");
  7248. }
  7249. }
  7250. set alg(value) {
  7251. }
  7252. };
  7253. __name(AesCryptoKey, "AesCryptoKey");
  7254. __decorate([
  7255. JsonProp({ name: "k", converter: JsonBase64UrlConverter })
  7256. ], AesCryptoKey.prototype, "data", void 0);
  7257. var keyStorage = /* @__PURE__ */ new WeakMap();
  7258. function getCryptoKey(key) {
  7259. const res = keyStorage.get(key);
  7260. if (!res) {
  7261. throw new OperationError("Cannot get CryptoKey from secure storage");
  7262. }
  7263. return res;
  7264. }
  7265. __name(getCryptoKey, "getCryptoKey");
  7266. function setCryptoKey(value) {
  7267. const key = CryptoKey.create(value.algorithm, value.type, value.extractable, value.usages);
  7268. Object.freeze(key);
  7269. keyStorage.set(key, value);
  7270. return key;
  7271. }
  7272. __name(setCryptoKey, "setCryptoKey");
  7273. var AesCrypto = class {
  7274. static async generateKey(algorithm, extractable, keyUsages) {
  7275. const key = new AesCryptoKey();
  7276. key.algorithm = algorithm;
  7277. key.extractable = extractable;
  7278. key.usages = keyUsages;
  7279. key.data = import_crypto.default.randomBytes(algorithm.length >> 3);
  7280. return key;
  7281. }
  7282. static async exportKey(format, key) {
  7283. if (!(key instanceof AesCryptoKey)) {
  7284. throw new Error("key: Is not AesCryptoKey");
  7285. }
  7286. switch (format.toLowerCase()) {
  7287. case "jwk":
  7288. return JsonSerializer.toJSON(key);
  7289. case "raw":
  7290. return new Uint8Array(key.data).buffer;
  7291. default:
  7292. throw new OperationError("format: Must be 'jwk' or 'raw'");
  7293. }
  7294. }
  7295. static async importKey(format, keyData, algorithm, extractable, keyUsages) {
  7296. let key;
  7297. switch (format.toLowerCase()) {
  7298. case "jwk":
  7299. key = JsonParser.fromJSON(keyData, { targetSchema: AesCryptoKey });
  7300. break;
  7301. case "raw":
  7302. key = new AesCryptoKey();
  7303. key.data = Buffer.from(keyData);
  7304. break;
  7305. default:
  7306. throw new OperationError("format: Must be 'jwk' or 'raw'");
  7307. }
  7308. key.algorithm = algorithm;
  7309. key.algorithm.length = key.data.length << 3;
  7310. key.extractable = extractable;
  7311. key.usages = keyUsages;
  7312. switch (key.algorithm.length) {
  7313. case 128:
  7314. case 192:
  7315. case 256:
  7316. break;
  7317. default:
  7318. throw new OperationError("keyData: Is wrong key length");
  7319. }
  7320. return key;
  7321. }
  7322. static async encrypt(algorithm, key, data) {
  7323. switch (algorithm.name.toUpperCase()) {
  7324. case "AES-CBC":
  7325. return this.encryptAesCBC(algorithm, key, Buffer.from(data));
  7326. case "AES-CTR":
  7327. return this.encryptAesCTR(algorithm, key, Buffer.from(data));
  7328. case "AES-GCM":
  7329. return this.encryptAesGCM(algorithm, key, Buffer.from(data));
  7330. case "AES-KW":
  7331. return this.encryptAesKW(algorithm, key, Buffer.from(data));
  7332. case "AES-ECB":
  7333. return this.encryptAesECB(algorithm, key, Buffer.from(data));
  7334. default:
  7335. throw new OperationError("algorithm: Is not recognized");
  7336. }
  7337. }
  7338. static async decrypt(algorithm, key, data) {
  7339. if (!(key instanceof AesCryptoKey)) {
  7340. throw new Error("key: Is not AesCryptoKey");
  7341. }
  7342. switch (algorithm.name.toUpperCase()) {
  7343. case "AES-CBC":
  7344. return this.decryptAesCBC(algorithm, key, Buffer.from(data));
  7345. case "AES-CTR":
  7346. return this.decryptAesCTR(algorithm, key, Buffer.from(data));
  7347. case "AES-GCM":
  7348. return this.decryptAesGCM(algorithm, key, Buffer.from(data));
  7349. case "AES-KW":
  7350. return this.decryptAesKW(algorithm, key, Buffer.from(data));
  7351. case "AES-ECB":
  7352. return this.decryptAesECB(algorithm, key, Buffer.from(data));
  7353. default:
  7354. throw new OperationError("algorithm: Is not recognized");
  7355. }
  7356. }
  7357. static async encryptAesCBC(algorithm, key, data) {
  7358. const cipher = import_crypto.default.createCipheriv(`aes-${key.algorithm.length}-cbc`, key.data, new Uint8Array(algorithm.iv));
  7359. let enc = cipher.update(data);
  7360. enc = Buffer.concat([enc, cipher.final()]);
  7361. const res = new Uint8Array(enc).buffer;
  7362. return res;
  7363. }
  7364. static async decryptAesCBC(algorithm, key, data) {
  7365. const decipher = import_crypto.default.createDecipheriv(`aes-${key.algorithm.length}-cbc`, key.data, new Uint8Array(algorithm.iv));
  7366. let dec = decipher.update(data);
  7367. dec = Buffer.concat([dec, decipher.final()]);
  7368. return new Uint8Array(dec).buffer;
  7369. }
  7370. static async encryptAesCTR(algorithm, key, data) {
  7371. const cipher = import_crypto.default.createCipheriv(`aes-${key.algorithm.length}-ctr`, key.data, Buffer.from(algorithm.counter));
  7372. let enc = cipher.update(data);
  7373. enc = Buffer.concat([enc, cipher.final()]);
  7374. const res = new Uint8Array(enc).buffer;
  7375. return res;
  7376. }
  7377. static async decryptAesCTR(algorithm, key, data) {
  7378. const decipher = import_crypto.default.createDecipheriv(`aes-${key.algorithm.length}-ctr`, key.data, new Uint8Array(algorithm.counter));
  7379. let dec = decipher.update(data);
  7380. dec = Buffer.concat([dec, decipher.final()]);
  7381. return new Uint8Array(dec).buffer;
  7382. }
  7383. static async encryptAesGCM(algorithm, key, data) {
  7384. const cipher = import_crypto.default.createCipheriv(`aes-${key.algorithm.length}-gcm`, key.data, Buffer.from(algorithm.iv), {
  7385. authTagLength: (algorithm.tagLength || 128) >> 3
  7386. });
  7387. if (algorithm.additionalData) {
  7388. cipher.setAAD(Buffer.from(algorithm.additionalData));
  7389. }
  7390. let enc = cipher.update(data);
  7391. enc = Buffer.concat([enc, cipher.final(), cipher.getAuthTag()]);
  7392. const res = new Uint8Array(enc).buffer;
  7393. return res;
  7394. }
  7395. static async decryptAesGCM(algorithm, key, data) {
  7396. const decipher = import_crypto.default.createDecipheriv(`aes-${key.algorithm.length}-gcm`, key.data, new Uint8Array(algorithm.iv));
  7397. const tagLength = (algorithm.tagLength || 128) >> 3;
  7398. const enc = data.slice(0, data.length - tagLength);
  7399. const tag = data.slice(data.length - tagLength);
  7400. if (algorithm.additionalData) {
  7401. decipher.setAAD(Buffer.from(algorithm.additionalData));
  7402. }
  7403. decipher.setAuthTag(tag);
  7404. let dec = decipher.update(enc);
  7405. dec = Buffer.concat([dec, decipher.final()]);
  7406. return new Uint8Array(dec).buffer;
  7407. }
  7408. static async encryptAesKW(algorithm, key, data) {
  7409. const cipher = import_crypto.default.createCipheriv(`id-aes${key.algorithm.length}-wrap`, key.data, this.AES_KW_IV);
  7410. let enc = cipher.update(data);
  7411. enc = Buffer.concat([enc, cipher.final()]);
  7412. return new Uint8Array(enc).buffer;
  7413. }
  7414. static async decryptAesKW(algorithm, key, data) {
  7415. const decipher = import_crypto.default.createDecipheriv(`id-aes${key.algorithm.length}-wrap`, key.data, this.AES_KW_IV);
  7416. let dec = decipher.update(data);
  7417. dec = Buffer.concat([dec, decipher.final()]);
  7418. return new Uint8Array(dec).buffer;
  7419. }
  7420. static async encryptAesECB(algorithm, key, data) {
  7421. const cipher = import_crypto.default.createCipheriv(`aes-${key.algorithm.length}-ecb`, key.data, new Uint8Array(0));
  7422. let enc = cipher.update(data);
  7423. enc = Buffer.concat([enc, cipher.final()]);
  7424. const res = new Uint8Array(enc).buffer;
  7425. return res;
  7426. }
  7427. static async decryptAesECB(algorithm, key, data) {
  7428. const decipher = import_crypto.default.createDecipheriv(`aes-${key.algorithm.length}-ecb`, key.data, new Uint8Array(0));
  7429. let dec = decipher.update(data);
  7430. dec = Buffer.concat([dec, decipher.final()]);
  7431. return new Uint8Array(dec).buffer;
  7432. }
  7433. };
  7434. __name(AesCrypto, "AesCrypto");
  7435. AesCrypto.AES_KW_IV = Buffer.from("A6A6A6A6A6A6A6A6", "hex");
  7436. var AesCbcProvider2 = class extends AesCbcProvider {
  7437. async onGenerateKey(algorithm, extractable, keyUsages) {
  7438. const key = await AesCrypto.generateKey({
  7439. name: this.name,
  7440. length: algorithm.length
  7441. }, extractable, keyUsages);
  7442. return setCryptoKey(key);
  7443. }
  7444. async onEncrypt(algorithm, key, data) {
  7445. return AesCrypto.encrypt(algorithm, getCryptoKey(key), new Uint8Array(data));
  7446. }
  7447. async onDecrypt(algorithm, key, data) {
  7448. return AesCrypto.decrypt(algorithm, getCryptoKey(key), new Uint8Array(data));
  7449. }
  7450. async onExportKey(format, key) {
  7451. return AesCrypto.exportKey(format, getCryptoKey(key));
  7452. }
  7453. async onImportKey(format, keyData, algorithm, extractable, keyUsages) {
  7454. const key = await AesCrypto.importKey(format, keyData, { name: algorithm.name }, extractable, keyUsages);
  7455. return setCryptoKey(key);
  7456. }
  7457. checkCryptoKey(key, keyUsage) {
  7458. super.checkCryptoKey(key, keyUsage);
  7459. if (!(getCryptoKey(key) instanceof AesCryptoKey)) {
  7460. throw new TypeError("key: Is not a AesCryptoKey");
  7461. }
  7462. }
  7463. };
  7464. __name(AesCbcProvider2, "AesCbcProvider");
  7465. var zero = Buffer.from([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
  7466. var rb = Buffer.from([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 135]);
  7467. var blockSize = 16;
  7468. function bitShiftLeft(buffer) {
  7469. const shifted = Buffer.alloc(buffer.length);
  7470. const last = buffer.length - 1;
  7471. for (let index = 0; index < last; index++) {
  7472. shifted[index] = buffer[index] << 1;
  7473. if (buffer[index + 1] & 128) {
  7474. shifted[index] += 1;
  7475. }
  7476. }
  7477. shifted[last] = buffer[last] << 1;
  7478. return shifted;
  7479. }
  7480. __name(bitShiftLeft, "bitShiftLeft");
  7481. function xor(a, b) {
  7482. const length = Math.min(a.length, b.length);
  7483. const output = Buffer.alloc(length);
  7484. for (let index = 0; index < length; index++) {
  7485. output[index] = a[index] ^ b[index];
  7486. }
  7487. return output;
  7488. }
  7489. __name(xor, "xor");
  7490. function aes(key, message) {
  7491. const cipher = crypto.createCipheriv(`aes${key.length << 3}`, key, zero);
  7492. const result = cipher.update(message);
  7493. cipher.final();
  7494. return result;
  7495. }
  7496. __name(aes, "aes");
  7497. function getMessageBlock(message, blockIndex) {
  7498. const block = Buffer.alloc(blockSize);
  7499. const start = blockIndex * blockSize;
  7500. const end = start + blockSize;
  7501. message.copy(block, 0, start, end);
  7502. return block;
  7503. }
  7504. __name(getMessageBlock, "getMessageBlock");
  7505. function getPaddedMessageBlock(message, blockIndex) {
  7506. const block = Buffer.alloc(blockSize);
  7507. const start = blockIndex * blockSize;
  7508. const end = message.length;
  7509. block.fill(0);
  7510. message.copy(block, 0, start, end);
  7511. block[end - start] = 128;
  7512. return block;
  7513. }
  7514. __name(getPaddedMessageBlock, "getPaddedMessageBlock");
  7515. function generateSubkeys(key) {
  7516. const l = aes(key, zero);
  7517. let subkey1 = bitShiftLeft(l);
  7518. if (l[0] & 128) {
  7519. subkey1 = xor(subkey1, rb);
  7520. }
  7521. let subkey2 = bitShiftLeft(subkey1);
  7522. if (subkey1[0] & 128) {
  7523. subkey2 = xor(subkey2, rb);
  7524. }
  7525. return { subkey1, subkey2 };
  7526. }
  7527. __name(generateSubkeys, "generateSubkeys");
  7528. function aesCmac(key, message) {
  7529. const subkeys = generateSubkeys(key);
  7530. let blockCount = Math.ceil(message.length / blockSize);
  7531. let lastBlockCompleteFlag;
  7532. let lastBlock;
  7533. if (blockCount === 0) {
  7534. blockCount = 1;
  7535. lastBlockCompleteFlag = false;
  7536. } else {
  7537. lastBlockCompleteFlag = message.length % blockSize === 0;
  7538. }
  7539. const lastBlockIndex = blockCount - 1;
  7540. if (lastBlockCompleteFlag) {
  7541. lastBlock = xor(getMessageBlock(message, lastBlockIndex), subkeys.subkey1);
  7542. } else {
  7543. lastBlock = xor(getPaddedMessageBlock(message, lastBlockIndex), subkeys.subkey2);
  7544. }
  7545. let x = zero;
  7546. let y;
  7547. for (let index = 0; index < lastBlockIndex; index++) {
  7548. y = xor(x, getMessageBlock(message, index));
  7549. x = aes(key, y);
  7550. }
  7551. y = xor(lastBlock, x);
  7552. return aes(key, y);
  7553. }
  7554. __name(aesCmac, "aesCmac");
  7555. var AesCmacProvider2 = class extends AesCmacProvider {
  7556. async onGenerateKey(algorithm, extractable, keyUsages) {
  7557. const key = await AesCrypto.generateKey({
  7558. name: this.name,
  7559. length: algorithm.length
  7560. }, extractable, keyUsages);
  7561. return setCryptoKey(key);
  7562. }
  7563. async onSign(algorithm, key, data) {
  7564. const result = aesCmac(getCryptoKey(key).data, Buffer.from(data));
  7565. return new Uint8Array(result).buffer;
  7566. }
  7567. async onVerify(algorithm, key, signature, data) {
  7568. const signature2 = await this.sign(algorithm, key, data);
  7569. return Buffer.from(signature).compare(Buffer.from(signature2)) === 0;
  7570. }
  7571. async onExportKey(format, key) {
  7572. return AesCrypto.exportKey(format, getCryptoKey(key));
  7573. }
  7574. async onImportKey(format, keyData, algorithm, extractable, keyUsages) {
  7575. const res = await AesCrypto.importKey(format, keyData, { name: algorithm.name }, extractable, keyUsages);
  7576. return setCryptoKey(res);
  7577. }
  7578. checkCryptoKey(key, keyUsage) {
  7579. super.checkCryptoKey(key, keyUsage);
  7580. if (!(getCryptoKey(key) instanceof AesCryptoKey)) {
  7581. throw new TypeError("key: Is not a AesCryptoKey");
  7582. }
  7583. }
  7584. };
  7585. __name(AesCmacProvider2, "AesCmacProvider");
  7586. var AesCtrProvider2 = class extends AesCtrProvider {
  7587. async onGenerateKey(algorithm, extractable, keyUsages) {
  7588. const key = await AesCrypto.generateKey({
  7589. name: this.name,
  7590. length: algorithm.length
  7591. }, extractable, keyUsages);
  7592. return setCryptoKey(key);
  7593. }
  7594. async onEncrypt(algorithm, key, data) {
  7595. return AesCrypto.encrypt(algorithm, getCryptoKey(key), new Uint8Array(data));
  7596. }
  7597. async onDecrypt(algorithm, key, data) {
  7598. return AesCrypto.decrypt(algorithm, getCryptoKey(key), new Uint8Array(data));
  7599. }
  7600. async onExportKey(format, key) {
  7601. return AesCrypto.exportKey(format, getCryptoKey(key));
  7602. }
  7603. async onImportKey(format, keyData, algorithm, extractable, keyUsages) {
  7604. const res = await AesCrypto.importKey(format, keyData, { name: algorithm.name }, extractable, keyUsages);
  7605. return setCryptoKey(res);
  7606. }
  7607. checkCryptoKey(key, keyUsage) {
  7608. super.checkCryptoKey(key, keyUsage);
  7609. if (!(getCryptoKey(key) instanceof AesCryptoKey)) {
  7610. throw new TypeError("key: Is not a AesCryptoKey");
  7611. }
  7612. }
  7613. };
  7614. __name(AesCtrProvider2, "AesCtrProvider");
  7615. var AesGcmProvider2 = class extends AesGcmProvider {
  7616. async onGenerateKey(algorithm, extractable, keyUsages) {
  7617. const key = await AesCrypto.generateKey({
  7618. name: this.name,
  7619. length: algorithm.length
  7620. }, extractable, keyUsages);
  7621. return setCryptoKey(key);
  7622. }
  7623. async onEncrypt(algorithm, key, data) {
  7624. return AesCrypto.encrypt(algorithm, getCryptoKey(key), new Uint8Array(data));
  7625. }
  7626. async onDecrypt(algorithm, key, data) {
  7627. return AesCrypto.decrypt(algorithm, getCryptoKey(key), new Uint8Array(data));
  7628. }
  7629. async onExportKey(format, key) {
  7630. return AesCrypto.exportKey(format, getCryptoKey(key));
  7631. }
  7632. async onImportKey(format, keyData, algorithm, extractable, keyUsages) {
  7633. const res = await AesCrypto.importKey(format, keyData, { name: algorithm.name }, extractable, keyUsages);
  7634. return setCryptoKey(res);
  7635. }
  7636. checkCryptoKey(key, keyUsage) {
  7637. super.checkCryptoKey(key, keyUsage);
  7638. if (!(getCryptoKey(key) instanceof AesCryptoKey)) {
  7639. throw new TypeError("key: Is not a AesCryptoKey");
  7640. }
  7641. }
  7642. };
  7643. __name(AesGcmProvider2, "AesGcmProvider");
  7644. var AesKwProvider2 = class extends AesKwProvider {
  7645. async onGenerateKey(algorithm, extractable, keyUsages) {
  7646. const res = await AesCrypto.generateKey({
  7647. name: this.name,
  7648. length: algorithm.length
  7649. }, extractable, keyUsages);
  7650. return setCryptoKey(res);
  7651. }
  7652. async onExportKey(format, key) {
  7653. return AesCrypto.exportKey(format, getCryptoKey(key));
  7654. }
  7655. async onImportKey(format, keyData, algorithm, extractable, keyUsages) {
  7656. const res = await AesCrypto.importKey(format, keyData, { name: algorithm.name }, extractable, keyUsages);
  7657. return setCryptoKey(res);
  7658. }
  7659. async onEncrypt(algorithm, key, data) {
  7660. return AesCrypto.encrypt(algorithm, getCryptoKey(key), new Uint8Array(data));
  7661. }
  7662. async onDecrypt(algorithm, key, data) {
  7663. return AesCrypto.decrypt(algorithm, getCryptoKey(key), new Uint8Array(data));
  7664. }
  7665. checkCryptoKey(key, keyUsage) {
  7666. super.checkCryptoKey(key, keyUsage);
  7667. if (!(getCryptoKey(key) instanceof AesCryptoKey)) {
  7668. throw new TypeError("key: Is not a AesCryptoKey");
  7669. }
  7670. }
  7671. };
  7672. __name(AesKwProvider2, "AesKwProvider");
  7673. var AesEcbProvider2 = class extends AesEcbProvider {
  7674. async onGenerateKey(algorithm, extractable, keyUsages) {
  7675. const key = await AesCrypto.generateKey({
  7676. name: this.name,
  7677. length: algorithm.length
  7678. }, extractable, keyUsages);
  7679. return setCryptoKey(key);
  7680. }
  7681. async onEncrypt(algorithm, key, data) {
  7682. return AesCrypto.encrypt(algorithm, getCryptoKey(key), new Uint8Array(data));
  7683. }
  7684. async onDecrypt(algorithm, key, data) {
  7685. return AesCrypto.decrypt(algorithm, getCryptoKey(key), new Uint8Array(data));
  7686. }
  7687. async onExportKey(format, key) {
  7688. return AesCrypto.exportKey(format, getCryptoKey(key));
  7689. }
  7690. async onImportKey(format, keyData, algorithm, extractable, keyUsages) {
  7691. const res = await AesCrypto.importKey(format, keyData, { name: algorithm.name }, extractable, keyUsages);
  7692. return setCryptoKey(res);
  7693. }
  7694. checkCryptoKey(key, keyUsage) {
  7695. super.checkCryptoKey(key, keyUsage);
  7696. if (!(getCryptoKey(key) instanceof AesCryptoKey)) {
  7697. throw new TypeError("key: Is not a AesCryptoKey");
  7698. }
  7699. }
  7700. };
  7701. __name(AesEcbProvider2, "AesEcbProvider");
  7702. var DesCryptoKey = class extends SymmetricKey {
  7703. get alg() {
  7704. switch (this.algorithm.name.toUpperCase()) {
  7705. case "DES-CBC":
  7706. return `DES-CBC`;
  7707. case "DES-EDE3-CBC":
  7708. return `3DES-CBC`;
  7709. default:
  7710. throw new AlgorithmError("Unsupported algorithm name");
  7711. }
  7712. }
  7713. set alg(value) {
  7714. }
  7715. };
  7716. __name(DesCryptoKey, "DesCryptoKey");
  7717. __decorate([
  7718. JsonProp({ name: "k", converter: JsonBase64UrlConverter })
  7719. ], DesCryptoKey.prototype, "data", void 0);
  7720. var DesCrypto = class {
  7721. static async generateKey(algorithm, extractable, keyUsages) {
  7722. const key = new DesCryptoKey();
  7723. key.algorithm = algorithm;
  7724. key.extractable = extractable;
  7725. key.usages = keyUsages;
  7726. key.data = import_crypto.default.randomBytes(algorithm.length >> 3);
  7727. return key;
  7728. }
  7729. static async exportKey(format, key) {
  7730. switch (format.toLowerCase()) {
  7731. case "jwk":
  7732. return JsonSerializer.toJSON(key);
  7733. case "raw":
  7734. return new Uint8Array(key.data).buffer;
  7735. default:
  7736. throw new OperationError("format: Must be 'jwk' or 'raw'");
  7737. }
  7738. }
  7739. static async importKey(format, keyData, algorithm, extractable, keyUsages) {
  7740. let key;
  7741. switch (format.toLowerCase()) {
  7742. case "jwk":
  7743. key = JsonParser.fromJSON(keyData, { targetSchema: DesCryptoKey });
  7744. break;
  7745. case "raw":
  7746. key = new DesCryptoKey();
  7747. key.data = Buffer.from(keyData);
  7748. break;
  7749. default:
  7750. throw new OperationError("format: Must be 'jwk' or 'raw'");
  7751. }
  7752. key.algorithm = algorithm;
  7753. key.extractable = extractable;
  7754. key.usages = keyUsages;
  7755. return key;
  7756. }
  7757. static async encrypt(algorithm, key, data) {
  7758. switch (algorithm.name.toUpperCase()) {
  7759. case "DES-CBC":
  7760. return this.encryptDesCBC(algorithm, key, Buffer.from(data));
  7761. case "DES-EDE3-CBC":
  7762. return this.encryptDesEDE3CBC(algorithm, key, Buffer.from(data));
  7763. default:
  7764. throw new OperationError("algorithm: Is not recognized");
  7765. }
  7766. }
  7767. static async decrypt(algorithm, key, data) {
  7768. if (!(key instanceof DesCryptoKey)) {
  7769. throw new Error("key: Is not DesCryptoKey");
  7770. }
  7771. switch (algorithm.name.toUpperCase()) {
  7772. case "DES-CBC":
  7773. return this.decryptDesCBC(algorithm, key, Buffer.from(data));
  7774. case "DES-EDE3-CBC":
  7775. return this.decryptDesEDE3CBC(algorithm, key, Buffer.from(data));
  7776. default:
  7777. throw new OperationError("algorithm: Is not recognized");
  7778. }
  7779. }
  7780. static async encryptDesCBC(algorithm, key, data) {
  7781. const cipher = import_crypto.default.createCipheriv(`des-cbc`, key.data, new Uint8Array(algorithm.iv));
  7782. let enc = cipher.update(data);
  7783. enc = Buffer.concat([enc, cipher.final()]);
  7784. const res = new Uint8Array(enc).buffer;
  7785. return res;
  7786. }
  7787. static async decryptDesCBC(algorithm, key, data) {
  7788. const decipher = import_crypto.default.createDecipheriv(`des-cbc`, key.data, new Uint8Array(algorithm.iv));
  7789. let dec = decipher.update(data);
  7790. dec = Buffer.concat([dec, decipher.final()]);
  7791. return new Uint8Array(dec).buffer;
  7792. }
  7793. static async encryptDesEDE3CBC(algorithm, key, data) {
  7794. const cipher = import_crypto.default.createCipheriv(`des-ede3-cbc`, key.data, Buffer.from(algorithm.iv));
  7795. let enc = cipher.update(data);
  7796. enc = Buffer.concat([enc, cipher.final()]);
  7797. const res = new Uint8Array(enc).buffer;
  7798. return res;
  7799. }
  7800. static async decryptDesEDE3CBC(algorithm, key, data) {
  7801. const decipher = import_crypto.default.createDecipheriv(`des-ede3-cbc`, key.data, new Uint8Array(algorithm.iv));
  7802. let dec = decipher.update(data);
  7803. dec = Buffer.concat([dec, decipher.final()]);
  7804. return new Uint8Array(dec).buffer;
  7805. }
  7806. };
  7807. __name(DesCrypto, "DesCrypto");
  7808. var DesCbcProvider = class extends DesProvider {
  7809. constructor() {
  7810. super(...arguments);
  7811. this.keySizeBits = 64;
  7812. this.ivSize = 8;
  7813. this.name = "DES-CBC";
  7814. }
  7815. async onGenerateKey(algorithm, extractable, keyUsages) {
  7816. const key = await DesCrypto.generateKey({
  7817. name: this.name,
  7818. length: this.keySizeBits
  7819. }, extractable, keyUsages);
  7820. return setCryptoKey(key);
  7821. }
  7822. async onEncrypt(algorithm, key, data) {
  7823. return DesCrypto.encrypt(algorithm, getCryptoKey(key), new Uint8Array(data));
  7824. }
  7825. async onDecrypt(algorithm, key, data) {
  7826. return DesCrypto.decrypt(algorithm, getCryptoKey(key), new Uint8Array(data));
  7827. }
  7828. async onExportKey(format, key) {
  7829. return DesCrypto.exportKey(format, getCryptoKey(key));
  7830. }
  7831. async onImportKey(format, keyData, algorithm, extractable, keyUsages) {
  7832. const key = await DesCrypto.importKey(format, keyData, { name: this.name, length: this.keySizeBits }, extractable, keyUsages);
  7833. if (key.data.length !== this.keySizeBits >> 3) {
  7834. throw new OperationError("keyData: Wrong key size");
  7835. }
  7836. return setCryptoKey(key);
  7837. }
  7838. checkCryptoKey(key, keyUsage) {
  7839. super.checkCryptoKey(key, keyUsage);
  7840. if (!(getCryptoKey(key) instanceof DesCryptoKey)) {
  7841. throw new TypeError("key: Is not a DesCryptoKey");
  7842. }
  7843. }
  7844. };
  7845. __name(DesCbcProvider, "DesCbcProvider");
  7846. var DesEde3CbcProvider = class extends DesProvider {
  7847. constructor() {
  7848. super(...arguments);
  7849. this.keySizeBits = 192;
  7850. this.ivSize = 8;
  7851. this.name = "DES-EDE3-CBC";
  7852. }
  7853. async onGenerateKey(algorithm, extractable, keyUsages) {
  7854. const key = await DesCrypto.generateKey({
  7855. name: this.name,
  7856. length: this.keySizeBits
  7857. }, extractable, keyUsages);
  7858. return setCryptoKey(key);
  7859. }
  7860. async onEncrypt(algorithm, key, data) {
  7861. return DesCrypto.encrypt(algorithm, getCryptoKey(key), new Uint8Array(data));
  7862. }
  7863. async onDecrypt(algorithm, key, data) {
  7864. return DesCrypto.decrypt(algorithm, getCryptoKey(key), new Uint8Array(data));
  7865. }
  7866. async onExportKey(format, key) {
  7867. return DesCrypto.exportKey(format, getCryptoKey(key));
  7868. }
  7869. async onImportKey(format, keyData, algorithm, extractable, keyUsages) {
  7870. const key = await DesCrypto.importKey(format, keyData, { name: this.name, length: this.keySizeBits }, extractable, keyUsages);
  7871. if (key.data.length !== this.keySizeBits >> 3) {
  7872. throw new OperationError("keyData: Wrong key size");
  7873. }
  7874. return setCryptoKey(key);
  7875. }
  7876. checkCryptoKey(key, keyUsage) {
  7877. super.checkCryptoKey(key, keyUsage);
  7878. if (!(getCryptoKey(key) instanceof DesCryptoKey)) {
  7879. throw new TypeError("key: Is not a DesCryptoKey");
  7880. }
  7881. }
  7882. };
  7883. __name(DesEde3CbcProvider, "DesEde3CbcProvider");
  7884. function getJwkAlgorithm(algorithm) {
  7885. switch (algorithm.name.toUpperCase()) {
  7886. case "RSA-OAEP": {
  7887. const mdSize = /(\d+)$/.exec(algorithm.hash.name)[1];
  7888. return `RSA-OAEP${mdSize !== "1" ? `-${mdSize}` : ""}`;
  7889. }
  7890. case "RSASSA-PKCS1-V1_5":
  7891. return `RS${/(\d+)$/.exec(algorithm.hash.name)[1]}`;
  7892. case "RSA-PSS":
  7893. return `PS${/(\d+)$/.exec(algorithm.hash.name)[1]}`;
  7894. case "RSA-PKCS1":
  7895. return `RS1`;
  7896. default:
  7897. throw new OperationError("algorithm: Is not recognized");
  7898. }
  7899. }
  7900. __name(getJwkAlgorithm, "getJwkAlgorithm");
  7901. var RsaPrivateKey2 = class extends AsymmetricKey {
  7902. constructor() {
  7903. super(...arguments);
  7904. this.type = "private";
  7905. }
  7906. getKey() {
  7907. const keyInfo = AsnParser.parse(this.data, index$1.PrivateKeyInfo);
  7908. return AsnParser.parse(keyInfo.privateKey, index$1.RsaPrivateKey);
  7909. }
  7910. toJSON() {
  7911. const key = this.getKey();
  7912. const json = {
  7913. kty: "RSA",
  7914. alg: getJwkAlgorithm(this.algorithm),
  7915. key_ops: this.usages,
  7916. ext: this.extractable
  7917. };
  7918. return Object.assign(json, JsonSerializer.toJSON(key));
  7919. }
  7920. fromJSON(json) {
  7921. const key = JsonParser.fromJSON(json, { targetSchema: index$1.RsaPrivateKey });
  7922. const keyInfo = new index$1.PrivateKeyInfo();
  7923. keyInfo.privateKeyAlgorithm.algorithm = "1.2.840.113549.1.1.1";
  7924. keyInfo.privateKeyAlgorithm.parameters = null;
  7925. keyInfo.privateKey = AsnSerializer.serialize(key);
  7926. this.data = Buffer.from(AsnSerializer.serialize(keyInfo));
  7927. }
  7928. };
  7929. __name(RsaPrivateKey2, "RsaPrivateKey");
  7930. var RsaPublicKey2 = class extends AsymmetricKey {
  7931. constructor() {
  7932. super(...arguments);
  7933. this.type = "public";
  7934. }
  7935. getKey() {
  7936. const keyInfo = AsnParser.parse(this.data, index$1.PublicKeyInfo);
  7937. return AsnParser.parse(keyInfo.publicKey, index$1.RsaPublicKey);
  7938. }
  7939. toJSON() {
  7940. const key = this.getKey();
  7941. const json = {
  7942. kty: "RSA",
  7943. alg: getJwkAlgorithm(this.algorithm),
  7944. key_ops: this.usages,
  7945. ext: this.extractable
  7946. };
  7947. return Object.assign(json, JsonSerializer.toJSON(key));
  7948. }
  7949. fromJSON(json) {
  7950. const key = JsonParser.fromJSON(json, { targetSchema: index$1.RsaPublicKey });
  7951. const keyInfo = new index$1.PublicKeyInfo();
  7952. keyInfo.publicKeyAlgorithm.algorithm = "1.2.840.113549.1.1.1";
  7953. keyInfo.publicKeyAlgorithm.parameters = null;
  7954. keyInfo.publicKey = AsnSerializer.serialize(key);
  7955. this.data = Buffer.from(AsnSerializer.serialize(keyInfo));
  7956. }
  7957. };
  7958. __name(RsaPublicKey2, "RsaPublicKey");
  7959. var RsaCrypto = class {
  7960. static async generateKey(algorithm, extractable, keyUsages) {
  7961. const privateKey = new RsaPrivateKey2();
  7962. privateKey.algorithm = algorithm;
  7963. privateKey.extractable = extractable;
  7964. privateKey.usages = keyUsages.filter((usage) => this.privateKeyUsages.indexOf(usage) !== -1);
  7965. const publicKey = new RsaPublicKey2();
  7966. publicKey.algorithm = algorithm;
  7967. publicKey.extractable = true;
  7968. publicKey.usages = keyUsages.filter((usage) => this.publicKeyUsages.indexOf(usage) !== -1);
  7969. const publicExponent = Buffer.concat([
  7970. Buffer.alloc(4 - algorithm.publicExponent.byteLength, 0),
  7971. Buffer.from(algorithm.publicExponent)
  7972. ]).readInt32BE(0);
  7973. const keys = import_crypto.default.generateKeyPairSync("rsa", {
  7974. modulusLength: algorithm.modulusLength,
  7975. publicExponent,
  7976. publicKeyEncoding: {
  7977. format: "der",
  7978. type: "spki"
  7979. },
  7980. privateKeyEncoding: {
  7981. format: "der",
  7982. type: "pkcs8"
  7983. }
  7984. });
  7985. privateKey.data = keys.privateKey;
  7986. publicKey.data = keys.publicKey;
  7987. const res = {
  7988. privateKey,
  7989. publicKey
  7990. };
  7991. return res;
  7992. }
  7993. static async exportKey(format, key) {
  7994. switch (format.toLowerCase()) {
  7995. case "jwk":
  7996. return JsonSerializer.toJSON(key);
  7997. case "pkcs8":
  7998. case "spki":
  7999. return new Uint8Array(key.data).buffer;
  8000. default:
  8001. throw new OperationError("format: Must be 'jwk', 'pkcs8' or 'spki'");
  8002. }
  8003. }
  8004. static async importKey(format, keyData, algorithm, extractable, keyUsages) {
  8005. switch (format.toLowerCase()) {
  8006. case "jwk": {
  8007. const jwk = keyData;
  8008. if (jwk.d) {
  8009. const asnKey = JsonParser.fromJSON(keyData, { targetSchema: index$1.RsaPrivateKey });
  8010. return this.importPrivateKey(asnKey, algorithm, extractable, keyUsages);
  8011. } else {
  8012. const asnKey = JsonParser.fromJSON(keyData, { targetSchema: index$1.RsaPublicKey });
  8013. return this.importPublicKey(asnKey, algorithm, extractable, keyUsages);
  8014. }
  8015. }
  8016. case "spki": {
  8017. const keyInfo = AsnParser.parse(new Uint8Array(keyData), index$1.PublicKeyInfo);
  8018. const asnKey = AsnParser.parse(keyInfo.publicKey, index$1.RsaPublicKey);
  8019. return this.importPublicKey(asnKey, algorithm, extractable, keyUsages);
  8020. }
  8021. case "pkcs8": {
  8022. const keyInfo = AsnParser.parse(new Uint8Array(keyData), index$1.PrivateKeyInfo);
  8023. const asnKey = AsnParser.parse(keyInfo.privateKey, index$1.RsaPrivateKey);
  8024. return this.importPrivateKey(asnKey, algorithm, extractable, keyUsages);
  8025. }
  8026. default:
  8027. throw new OperationError("format: Must be 'jwk', 'pkcs8' or 'spki'");
  8028. }
  8029. }
  8030. static async sign(algorithm, key, data) {
  8031. switch (algorithm.name.toUpperCase()) {
  8032. case "RSA-PSS":
  8033. case "RSASSA-PKCS1-V1_5":
  8034. return this.signRsa(algorithm, key, data);
  8035. default:
  8036. throw new OperationError("algorithm: Is not recognized");
  8037. }
  8038. }
  8039. static async verify(algorithm, key, signature, data) {
  8040. switch (algorithm.name.toUpperCase()) {
  8041. case "RSA-PSS":
  8042. case "RSASSA-PKCS1-V1_5":
  8043. return this.verifySSA(algorithm, key, data, signature);
  8044. default:
  8045. throw new OperationError("algorithm: Is not recognized");
  8046. }
  8047. }
  8048. static async encrypt(algorithm, key, data) {
  8049. switch (algorithm.name.toUpperCase()) {
  8050. case "RSA-OAEP":
  8051. return this.encryptOAEP(algorithm, key, data);
  8052. default:
  8053. throw new OperationError("algorithm: Is not recognized");
  8054. }
  8055. }
  8056. static async decrypt(algorithm, key, data) {
  8057. switch (algorithm.name.toUpperCase()) {
  8058. case "RSA-OAEP":
  8059. return this.decryptOAEP(algorithm, key, data);
  8060. default:
  8061. throw new OperationError("algorithm: Is not recognized");
  8062. }
  8063. }
  8064. static importPrivateKey(asnKey, algorithm, extractable, keyUsages) {
  8065. const keyInfo = new index$1.PrivateKeyInfo();
  8066. keyInfo.privateKeyAlgorithm.algorithm = "1.2.840.113549.1.1.1";
  8067. keyInfo.privateKeyAlgorithm.parameters = null;
  8068. keyInfo.privateKey = AsnSerializer.serialize(asnKey);
  8069. const key = new RsaPrivateKey2();
  8070. key.data = Buffer.from(AsnSerializer.serialize(keyInfo));
  8071. key.algorithm = Object.assign({}, algorithm);
  8072. key.algorithm.publicExponent = new Uint8Array(asnKey.publicExponent);
  8073. key.algorithm.modulusLength = asnKey.modulus.byteLength << 3;
  8074. key.extractable = extractable;
  8075. key.usages = keyUsages;
  8076. return key;
  8077. }
  8078. static importPublicKey(asnKey, algorithm, extractable, keyUsages) {
  8079. const keyInfo = new index$1.PublicKeyInfo();
  8080. keyInfo.publicKeyAlgorithm.algorithm = "1.2.840.113549.1.1.1";
  8081. keyInfo.publicKeyAlgorithm.parameters = null;
  8082. keyInfo.publicKey = AsnSerializer.serialize(asnKey);
  8083. const key = new RsaPublicKey2();
  8084. key.data = Buffer.from(AsnSerializer.serialize(keyInfo));
  8085. key.algorithm = Object.assign({}, algorithm);
  8086. key.algorithm.publicExponent = new Uint8Array(asnKey.publicExponent);
  8087. key.algorithm.modulusLength = asnKey.modulus.byteLength << 3;
  8088. key.extractable = extractable;
  8089. key.usages = keyUsages;
  8090. return key;
  8091. }
  8092. static getCryptoAlgorithm(alg) {
  8093. switch (alg.hash.name.toUpperCase()) {
  8094. case "SHA-1":
  8095. return "RSA-SHA1";
  8096. case "SHA-256":
  8097. return "RSA-SHA256";
  8098. case "SHA-384":
  8099. return "RSA-SHA384";
  8100. case "SHA-512":
  8101. return "RSA-SHA512";
  8102. case "SHA3-256":
  8103. return "RSA-SHA3-256";
  8104. case "SHA3-384":
  8105. return "RSA-SHA3-384";
  8106. case "SHA3-512":
  8107. return "RSA-SHA3-512";
  8108. default:
  8109. throw new OperationError("algorithm.hash: Is not recognized");
  8110. }
  8111. }
  8112. static signRsa(algorithm, key, data) {
  8113. const cryptoAlg = this.getCryptoAlgorithm(key.algorithm);
  8114. const signer = import_crypto.default.createSign(cryptoAlg);
  8115. signer.update(Buffer.from(data));
  8116. if (!key.pem) {
  8117. key.pem = `-----BEGIN PRIVATE KEY-----
  8118. ${key.data.toString("base64")}
  8119. -----END PRIVATE KEY-----`;
  8120. }
  8121. const options = {
  8122. key: key.pem
  8123. };
  8124. if (algorithm.name.toUpperCase() === "RSA-PSS") {
  8125. options.padding = import_crypto.default.constants.RSA_PKCS1_PSS_PADDING;
  8126. options.saltLength = algorithm.saltLength;
  8127. }
  8128. const signature = signer.sign(options);
  8129. return new Uint8Array(signature).buffer;
  8130. }
  8131. static verifySSA(algorithm, key, data, signature) {
  8132. const cryptoAlg = this.getCryptoAlgorithm(key.algorithm);
  8133. const signer = import_crypto.default.createVerify(cryptoAlg);
  8134. signer.update(Buffer.from(data));
  8135. if (!key.pem) {
  8136. key.pem = `-----BEGIN PUBLIC KEY-----
  8137. ${key.data.toString("base64")}
  8138. -----END PUBLIC KEY-----`;
  8139. }
  8140. const options = {
  8141. key: key.pem
  8142. };
  8143. if (algorithm.name.toUpperCase() === "RSA-PSS") {
  8144. options.padding = import_crypto.default.constants.RSA_PKCS1_PSS_PADDING;
  8145. options.saltLength = algorithm.saltLength;
  8146. }
  8147. const ok = signer.verify(options, signature);
  8148. return ok;
  8149. }
  8150. static encryptOAEP(algorithm, key, data) {
  8151. const options = {
  8152. key: `-----BEGIN PUBLIC KEY-----
  8153. ${key.data.toString("base64")}
  8154. -----END PUBLIC KEY-----`,
  8155. padding: import_crypto.default.constants.RSA_PKCS1_OAEP_PADDING
  8156. };
  8157. if (algorithm.label)
  8158. ;
  8159. return new Uint8Array(import_crypto.default.publicEncrypt(options, data)).buffer;
  8160. }
  8161. static decryptOAEP(algorithm, key, data) {
  8162. const options = {
  8163. key: `-----BEGIN PRIVATE KEY-----
  8164. ${key.data.toString("base64")}
  8165. -----END PRIVATE KEY-----`,
  8166. padding: import_crypto.default.constants.RSA_PKCS1_OAEP_PADDING
  8167. };
  8168. if (algorithm.label)
  8169. ;
  8170. return new Uint8Array(import_crypto.default.privateDecrypt(options, data)).buffer;
  8171. }
  8172. };
  8173. __name(RsaCrypto, "RsaCrypto");
  8174. RsaCrypto.publicKeyUsages = ["verify", "encrypt", "wrapKey"];
  8175. RsaCrypto.privateKeyUsages = ["sign", "decrypt", "unwrapKey"];
  8176. var RsaSsaProvider2 = class extends RsaSsaProvider {
  8177. constructor() {
  8178. super(...arguments);
  8179. this.hashAlgorithms = [
  8180. "SHA-1",
  8181. "SHA-256",
  8182. "SHA-384",
  8183. "SHA-512",
  8184. "shake128",
  8185. "shake256",
  8186. "SHA3-256",
  8187. "SHA3-384",
  8188. "SHA3-512"
  8189. ];
  8190. }
  8191. async onGenerateKey(algorithm, extractable, keyUsages) {
  8192. const keys = await RsaCrypto.generateKey({
  8193. ...algorithm,
  8194. name: this.name
  8195. }, extractable, keyUsages);
  8196. return {
  8197. privateKey: setCryptoKey(keys.privateKey),
  8198. publicKey: setCryptoKey(keys.publicKey)
  8199. };
  8200. }
  8201. async onSign(algorithm, key, data) {
  8202. return RsaCrypto.sign(algorithm, getCryptoKey(key), new Uint8Array(data));
  8203. }
  8204. async onVerify(algorithm, key, signature, data) {
  8205. return RsaCrypto.verify(algorithm, getCryptoKey(key), new Uint8Array(signature), new Uint8Array(data));
  8206. }
  8207. async onExportKey(format, key) {
  8208. return RsaCrypto.exportKey(format, getCryptoKey(key));
  8209. }
  8210. async onImportKey(format, keyData, algorithm, extractable, keyUsages) {
  8211. const key = await RsaCrypto.importKey(format, keyData, { ...algorithm, name: this.name }, extractable, keyUsages);
  8212. return setCryptoKey(key);
  8213. }
  8214. checkCryptoKey(key, keyUsage) {
  8215. super.checkCryptoKey(key, keyUsage);
  8216. const internalKey = getCryptoKey(key);
  8217. if (!(internalKey instanceof RsaPrivateKey2 || internalKey instanceof RsaPublicKey2)) {
  8218. throw new TypeError("key: Is not RSA CryptoKey");
  8219. }
  8220. }
  8221. };
  8222. __name(RsaSsaProvider2, "RsaSsaProvider");
  8223. var RsaPssProvider2 = class extends RsaPssProvider {
  8224. constructor() {
  8225. super(...arguments);
  8226. this.hashAlgorithms = [
  8227. "SHA-1",
  8228. "SHA-256",
  8229. "SHA-384",
  8230. "SHA-512",
  8231. "shake128",
  8232. "shake256",
  8233. "SHA3-256",
  8234. "SHA3-384",
  8235. "SHA3-512"
  8236. ];
  8237. }
  8238. async onGenerateKey(algorithm, extractable, keyUsages) {
  8239. const keys = await RsaCrypto.generateKey({
  8240. ...algorithm,
  8241. name: this.name
  8242. }, extractable, keyUsages);
  8243. return {
  8244. privateKey: setCryptoKey(keys.privateKey),
  8245. publicKey: setCryptoKey(keys.publicKey)
  8246. };
  8247. }
  8248. async onSign(algorithm, key, data) {
  8249. return RsaCrypto.sign(algorithm, getCryptoKey(key), new Uint8Array(data));
  8250. }
  8251. async onVerify(algorithm, key, signature, data) {
  8252. return RsaCrypto.verify(algorithm, getCryptoKey(key), new Uint8Array(signature), new Uint8Array(data));
  8253. }
  8254. async onExportKey(format, key) {
  8255. return RsaCrypto.exportKey(format, getCryptoKey(key));
  8256. }
  8257. async onImportKey(format, keyData, algorithm, extractable, keyUsages) {
  8258. const key = await RsaCrypto.importKey(format, keyData, { ...algorithm, name: this.name }, extractable, keyUsages);
  8259. return setCryptoKey(key);
  8260. }
  8261. checkCryptoKey(key, keyUsage) {
  8262. super.checkCryptoKey(key, keyUsage);
  8263. const internalKey = getCryptoKey(key);
  8264. if (!(internalKey instanceof RsaPrivateKey2 || internalKey instanceof RsaPublicKey2)) {
  8265. throw new TypeError("key: Is not RSA CryptoKey");
  8266. }
  8267. }
  8268. };
  8269. __name(RsaPssProvider2, "RsaPssProvider");
  8270. var ShaCrypto = class {
  8271. static size(algorithm) {
  8272. switch (algorithm.name.toUpperCase()) {
  8273. case "SHA-1":
  8274. return 160;
  8275. case "SHA-256":
  8276. case "SHA3-256":
  8277. return 256;
  8278. case "SHA-384":
  8279. case "SHA3-384":
  8280. return 384;
  8281. case "SHA-512":
  8282. case "SHA3-512":
  8283. return 512;
  8284. default:
  8285. throw new Error("Unrecognized name");
  8286. }
  8287. }
  8288. static getAlgorithmName(algorithm) {
  8289. switch (algorithm.name.toUpperCase()) {
  8290. case "SHA-1":
  8291. return "sha1";
  8292. case "SHA-256":
  8293. return "sha256";
  8294. case "SHA-384":
  8295. return "sha384";
  8296. case "SHA-512":
  8297. return "sha512";
  8298. case "SHA3-256":
  8299. return "sha3-256";
  8300. case "SHA3-384":
  8301. return "sha3-384";
  8302. case "SHA3-512":
  8303. return "sha3-512";
  8304. default:
  8305. throw new Error("Unrecognized name");
  8306. }
  8307. }
  8308. static digest(algorithm, data) {
  8309. const hashAlg = this.getAlgorithmName(algorithm);
  8310. const hash = import_crypto.default.createHash(hashAlg).update(Buffer.from(data)).digest();
  8311. return new Uint8Array(hash).buffer;
  8312. }
  8313. };
  8314. __name(ShaCrypto, "ShaCrypto");
  8315. var RsaOaepProvider2 = class extends RsaOaepProvider {
  8316. async onGenerateKey(algorithm, extractable, keyUsages) {
  8317. const keys = await RsaCrypto.generateKey({
  8318. ...algorithm,
  8319. name: this.name
  8320. }, extractable, keyUsages);
  8321. return {
  8322. privateKey: setCryptoKey(keys.privateKey),
  8323. publicKey: setCryptoKey(keys.publicKey)
  8324. };
  8325. }
  8326. async onEncrypt(algorithm, key, data) {
  8327. const internalKey = getCryptoKey(key);
  8328. const dataView = new Uint8Array(data);
  8329. const keySize = Math.ceil(internalKey.algorithm.modulusLength >> 3);
  8330. const hashSize = ShaCrypto.size(internalKey.algorithm.hash) >> 3;
  8331. const dataLength = dataView.byteLength;
  8332. const psLength = keySize - dataLength - 2 * hashSize - 2;
  8333. if (dataLength > keySize - 2 * hashSize - 2) {
  8334. throw new Error("Data too large");
  8335. }
  8336. const message = new Uint8Array(keySize);
  8337. const seed = message.subarray(1, hashSize + 1);
  8338. const dataBlock = message.subarray(hashSize + 1);
  8339. dataBlock.set(dataView, hashSize + psLength + 1);
  8340. const labelHash = import_crypto.default.createHash(internalKey.algorithm.hash.name.replace("-", "")).update(BufferSourceConverter.toUint8Array(algorithm.label || new Uint8Array(0))).digest();
  8341. dataBlock.set(labelHash, 0);
  8342. dataBlock[hashSize + psLength] = 1;
  8343. import_crypto.default.randomFillSync(seed);
  8344. const dataBlockMask = this.mgf1(internalKey.algorithm.hash, seed, dataBlock.length);
  8345. for (let i = 0; i < dataBlock.length; i++) {
  8346. dataBlock[i] ^= dataBlockMask[i];
  8347. }
  8348. const seedMask = this.mgf1(internalKey.algorithm.hash, dataBlock, seed.length);
  8349. for (let i = 0; i < seed.length; i++) {
  8350. seed[i] ^= seedMask[i];
  8351. }
  8352. if (!internalKey.pem) {
  8353. internalKey.pem = `-----BEGIN PUBLIC KEY-----
  8354. ${internalKey.data.toString("base64")}
  8355. -----END PUBLIC KEY-----`;
  8356. }
  8357. const pkcs0 = import_crypto.default.publicEncrypt({
  8358. key: internalKey.pem,
  8359. padding: import_crypto.default.constants.RSA_NO_PADDING
  8360. }, Buffer.from(message));
  8361. return new Uint8Array(pkcs0).buffer;
  8362. }
  8363. async onDecrypt(algorithm, key, data) {
  8364. const internalKey = getCryptoKey(key);
  8365. const keySize = Math.ceil(internalKey.algorithm.modulusLength >> 3);
  8366. const hashSize = ShaCrypto.size(internalKey.algorithm.hash) >> 3;
  8367. const dataLength = data.byteLength;
  8368. if (dataLength !== keySize) {
  8369. throw new Error("Bad data");
  8370. }
  8371. if (!internalKey.pem) {
  8372. internalKey.pem = `-----BEGIN PRIVATE KEY-----
  8373. ${internalKey.data.toString("base64")}
  8374. -----END PRIVATE KEY-----`;
  8375. }
  8376. let pkcs0 = import_crypto.default.privateDecrypt({
  8377. key: internalKey.pem,
  8378. padding: import_crypto.default.constants.RSA_NO_PADDING
  8379. }, Buffer.from(data));
  8380. const z = pkcs0[0];
  8381. const seed = pkcs0.subarray(1, hashSize + 1);
  8382. const dataBlock = pkcs0.subarray(hashSize + 1);
  8383. if (z !== 0) {
  8384. throw new Error("Decryption failed");
  8385. }
  8386. const seedMask = this.mgf1(internalKey.algorithm.hash, dataBlock, seed.length);
  8387. for (let i = 0; i < seed.length; i++) {
  8388. seed[i] ^= seedMask[i];
  8389. }
  8390. const dataBlockMask = this.mgf1(internalKey.algorithm.hash, seed, dataBlock.length);
  8391. for (let i = 0; i < dataBlock.length; i++) {
  8392. dataBlock[i] ^= dataBlockMask[i];
  8393. }
  8394. const labelHash = import_crypto.default.createHash(internalKey.algorithm.hash.name.replace("-", "")).update(BufferSourceConverter.toUint8Array(algorithm.label || new Uint8Array(0))).digest();
  8395. for (let i = 0; i < hashSize; i++) {
  8396. if (labelHash[i] !== dataBlock[i]) {
  8397. throw new Error("Decryption failed");
  8398. }
  8399. }
  8400. let psEnd = hashSize;
  8401. for (; psEnd < dataBlock.length; psEnd++) {
  8402. const psz = dataBlock[psEnd];
  8403. if (psz === 1) {
  8404. break;
  8405. }
  8406. if (psz !== 0) {
  8407. throw new Error("Decryption failed");
  8408. }
  8409. }
  8410. if (psEnd === dataBlock.length) {
  8411. throw new Error("Decryption failed");
  8412. }
  8413. pkcs0 = dataBlock.subarray(psEnd + 1);
  8414. return new Uint8Array(pkcs0).buffer;
  8415. }
  8416. async onExportKey(format, key) {
  8417. return RsaCrypto.exportKey(format, getCryptoKey(key));
  8418. }
  8419. async onImportKey(format, keyData, algorithm, extractable, keyUsages) {
  8420. const key = await RsaCrypto.importKey(format, keyData, { ...algorithm, name: this.name }, extractable, keyUsages);
  8421. return setCryptoKey(key);
  8422. }
  8423. checkCryptoKey(key, keyUsage) {
  8424. super.checkCryptoKey(key, keyUsage);
  8425. const internalKey = getCryptoKey(key);
  8426. if (!(internalKey instanceof RsaPrivateKey2 || internalKey instanceof RsaPublicKey2)) {
  8427. throw new TypeError("key: Is not RSA CryptoKey");
  8428. }
  8429. }
  8430. mgf1(algorithm, seed, length = 0) {
  8431. const hashSize = ShaCrypto.size(algorithm) >> 3;
  8432. const mask = new Uint8Array(length);
  8433. const counter = new Uint8Array(4);
  8434. const chunks = Math.ceil(length / hashSize);
  8435. for (let i = 0; i < chunks; i++) {
  8436. counter[0] = i >>> 24;
  8437. counter[1] = i >>> 16 & 255;
  8438. counter[2] = i >>> 8 & 255;
  8439. counter[3] = i & 255;
  8440. const submask = mask.subarray(i * hashSize);
  8441. let chunk = import_crypto.default.createHash(algorithm.name.replace("-", "")).update(seed).update(counter).digest();
  8442. if (chunk.length > submask.length) {
  8443. chunk = chunk.subarray(0, submask.length);
  8444. }
  8445. submask.set(chunk);
  8446. }
  8447. return mask;
  8448. }
  8449. };
  8450. __name(RsaOaepProvider2, "RsaOaepProvider");
  8451. var RsaEsProvider = class extends ProviderCrypto {
  8452. constructor() {
  8453. super(...arguments);
  8454. this.name = "RSAES-PKCS1-v1_5";
  8455. this.usages = {
  8456. publicKey: ["encrypt", "wrapKey"],
  8457. privateKey: ["decrypt", "unwrapKey"]
  8458. };
  8459. }
  8460. async onGenerateKey(algorithm, extractable, keyUsages) {
  8461. const keys = await RsaCrypto.generateKey({
  8462. ...algorithm,
  8463. name: this.name
  8464. }, extractable, keyUsages);
  8465. return {
  8466. privateKey: setCryptoKey(keys.privateKey),
  8467. publicKey: setCryptoKey(keys.publicKey)
  8468. };
  8469. }
  8470. checkGenerateKeyParams(algorithm) {
  8471. this.checkRequiredProperty(algorithm, "publicExponent");
  8472. if (!(algorithm.publicExponent && algorithm.publicExponent instanceof Uint8Array)) {
  8473. throw new TypeError("publicExponent: Missing or not a Uint8Array");
  8474. }
  8475. const publicExponent = Convert.ToBase64(algorithm.publicExponent);
  8476. if (!(publicExponent === "Aw==" || publicExponent === "AQAB")) {
  8477. throw new TypeError("publicExponent: Must be [3] or [1,0,1]");
  8478. }
  8479. this.checkRequiredProperty(algorithm, "modulusLength");
  8480. switch (algorithm.modulusLength) {
  8481. case 1024:
  8482. case 2048:
  8483. case 4096:
  8484. break;
  8485. default:
  8486. throw new TypeError("modulusLength: Must be 1024, 2048, or 4096");
  8487. }
  8488. }
  8489. async onEncrypt(algorithm, key, data) {
  8490. const options = this.toCryptoOptions(key);
  8491. const enc = crypto.publicEncrypt(options, new Uint8Array(data));
  8492. return new Uint8Array(enc).buffer;
  8493. }
  8494. async onDecrypt(algorithm, key, data) {
  8495. const options = this.toCryptoOptions(key);
  8496. const dec = crypto.privateDecrypt(options, new Uint8Array(data));
  8497. return new Uint8Array(dec).buffer;
  8498. }
  8499. async onExportKey(format, key) {
  8500. return RsaCrypto.exportKey(format, getCryptoKey(key));
  8501. }
  8502. async onImportKey(format, keyData, algorithm, extractable, keyUsages) {
  8503. const key = await RsaCrypto.importKey(format, keyData, { ...algorithm, name: this.name }, extractable, keyUsages);
  8504. return setCryptoKey(key);
  8505. }
  8506. checkCryptoKey(key, keyUsage) {
  8507. super.checkCryptoKey(key, keyUsage);
  8508. const internalKey = getCryptoKey(key);
  8509. if (!(internalKey instanceof RsaPrivateKey2 || internalKey instanceof RsaPublicKey2)) {
  8510. throw new TypeError("key: Is not RSA CryptoKey");
  8511. }
  8512. }
  8513. toCryptoOptions(key) {
  8514. const type = key.type.toUpperCase();
  8515. return {
  8516. key: `-----BEGIN ${type} KEY-----
  8517. ${getCryptoKey(key).data.toString("base64")}
  8518. -----END ${type} KEY-----`,
  8519. padding: crypto.constants.RSA_PKCS1_PADDING
  8520. };
  8521. }
  8522. };
  8523. __name(RsaEsProvider, "RsaEsProvider");
  8524. var namedOIDs = {
  8525. "1.2.840.10045.3.1.7": "P-256",
  8526. "P-256": "1.2.840.10045.3.1.7",
  8527. "1.3.132.0.34": "P-384",
  8528. "P-384": "1.3.132.0.34",
  8529. "1.3.132.0.35": "P-521",
  8530. "P-521": "1.3.132.0.35",
  8531. "1.3.132.0.10": "K-256",
  8532. "K-256": "1.3.132.0.10",
  8533. "brainpoolP160r1": "1.3.36.3.3.2.8.1.1.1",
  8534. "1.3.36.3.3.2.8.1.1.1": "brainpoolP160r1",
  8535. "brainpoolP160t1": "1.3.36.3.3.2.8.1.1.2",
  8536. "1.3.36.3.3.2.8.1.1.2": "brainpoolP160t1",
  8537. "brainpoolP192r1": "1.3.36.3.3.2.8.1.1.3",
  8538. "1.3.36.3.3.2.8.1.1.3": "brainpoolP192r1",
  8539. "brainpoolP192t1": "1.3.36.3.3.2.8.1.1.4",
  8540. "1.3.36.3.3.2.8.1.1.4": "brainpoolP192t1",
  8541. "brainpoolP224r1": "1.3.36.3.3.2.8.1.1.5",
  8542. "1.3.36.3.3.2.8.1.1.5": "brainpoolP224r1",
  8543. "brainpoolP224t1": "1.3.36.3.3.2.8.1.1.6",
  8544. "1.3.36.3.3.2.8.1.1.6": "brainpoolP224t1",
  8545. "brainpoolP256r1": "1.3.36.3.3.2.8.1.1.7",
  8546. "1.3.36.3.3.2.8.1.1.7": "brainpoolP256r1",
  8547. "brainpoolP256t1": "1.3.36.3.3.2.8.1.1.8",
  8548. "1.3.36.3.3.2.8.1.1.8": "brainpoolP256t1",
  8549. "brainpoolP320r1": "1.3.36.3.3.2.8.1.1.9",
  8550. "1.3.36.3.3.2.8.1.1.9": "brainpoolP320r1",
  8551. "brainpoolP320t1": "1.3.36.3.3.2.8.1.1.10",
  8552. "1.3.36.3.3.2.8.1.1.10": "brainpoolP320t1",
  8553. "brainpoolP384r1": "1.3.36.3.3.2.8.1.1.11",
  8554. "1.3.36.3.3.2.8.1.1.11": "brainpoolP384r1",
  8555. "brainpoolP384t1": "1.3.36.3.3.2.8.1.1.12",
  8556. "1.3.36.3.3.2.8.1.1.12": "brainpoolP384t1",
  8557. "brainpoolP512r1": "1.3.36.3.3.2.8.1.1.13",
  8558. "1.3.36.3.3.2.8.1.1.13": "brainpoolP512r1",
  8559. "brainpoolP512t1": "1.3.36.3.3.2.8.1.1.14",
  8560. "1.3.36.3.3.2.8.1.1.14": "brainpoolP512t1"
  8561. };
  8562. function getOidByNamedCurve$1(namedCurve) {
  8563. const oid = namedOIDs[namedCurve];
  8564. if (!oid) {
  8565. throw new OperationError(`Cannot convert WebCrypto named curve '${namedCurve}' to OID`);
  8566. }
  8567. return oid;
  8568. }
  8569. __name(getOidByNamedCurve$1, "getOidByNamedCurve$1");
  8570. var EcPrivateKey2 = class extends AsymmetricKey {
  8571. constructor() {
  8572. super(...arguments);
  8573. this.type = "private";
  8574. }
  8575. getKey() {
  8576. const keyInfo = AsnParser.parse(this.data, index$1.PrivateKeyInfo);
  8577. return AsnParser.parse(keyInfo.privateKey, index$1.EcPrivateKey);
  8578. }
  8579. toJSON() {
  8580. const key = this.getKey();
  8581. const json = {
  8582. kty: "EC",
  8583. crv: this.algorithm.namedCurve,
  8584. key_ops: this.usages,
  8585. ext: this.extractable
  8586. };
  8587. return Object.assign(json, JsonSerializer.toJSON(key));
  8588. }
  8589. fromJSON(json) {
  8590. if (!json.crv) {
  8591. throw new OperationError(`Cannot get named curve from JWK. Property 'crv' is required`);
  8592. }
  8593. const keyInfo = new index$1.PrivateKeyInfo();
  8594. keyInfo.privateKeyAlgorithm.algorithm = "1.2.840.10045.2.1";
  8595. keyInfo.privateKeyAlgorithm.parameters = AsnSerializer.serialize(new index$1.ObjectIdentifier(getOidByNamedCurve$1(json.crv)));
  8596. const key = JsonParser.fromJSON(json, { targetSchema: index$1.EcPrivateKey });
  8597. keyInfo.privateKey = AsnSerializer.serialize(key);
  8598. this.data = Buffer.from(AsnSerializer.serialize(keyInfo));
  8599. return this;
  8600. }
  8601. };
  8602. __name(EcPrivateKey2, "EcPrivateKey");
  8603. var EcPublicKey3 = class extends AsymmetricKey {
  8604. constructor() {
  8605. super(...arguments);
  8606. this.type = "public";
  8607. }
  8608. getKey() {
  8609. const keyInfo = AsnParser.parse(this.data, index$1.PublicKeyInfo);
  8610. return new index$1.EcPublicKey(keyInfo.publicKey);
  8611. }
  8612. toJSON() {
  8613. const key = this.getKey();
  8614. const json = {
  8615. kty: "EC",
  8616. crv: this.algorithm.namedCurve,
  8617. key_ops: this.usages,
  8618. ext: this.extractable
  8619. };
  8620. return Object.assign(json, JsonSerializer.toJSON(key));
  8621. }
  8622. fromJSON(json) {
  8623. if (!json.crv) {
  8624. throw new OperationError(`Cannot get named curve from JWK. Property 'crv' is required`);
  8625. }
  8626. const key = JsonParser.fromJSON(json, { targetSchema: index$1.EcPublicKey });
  8627. const keyInfo = new index$1.PublicKeyInfo();
  8628. keyInfo.publicKeyAlgorithm.algorithm = "1.2.840.10045.2.1";
  8629. keyInfo.publicKeyAlgorithm.parameters = AsnSerializer.serialize(new index$1.ObjectIdentifier(getOidByNamedCurve$1(json.crv)));
  8630. keyInfo.publicKey = AsnSerializer.toASN(key).valueHex;
  8631. this.data = Buffer.from(AsnSerializer.serialize(keyInfo));
  8632. return this;
  8633. }
  8634. };
  8635. __name(EcPublicKey3, "EcPublicKey");
  8636. var Sha1Provider = class extends ProviderCrypto {
  8637. constructor() {
  8638. super(...arguments);
  8639. this.name = "SHA-1";
  8640. this.usages = [];
  8641. }
  8642. async onDigest(algorithm, data) {
  8643. return ShaCrypto.digest(algorithm, data);
  8644. }
  8645. };
  8646. __name(Sha1Provider, "Sha1Provider");
  8647. var Sha256Provider = class extends ProviderCrypto {
  8648. constructor() {
  8649. super(...arguments);
  8650. this.name = "SHA-256";
  8651. this.usages = [];
  8652. }
  8653. async onDigest(algorithm, data) {
  8654. return ShaCrypto.digest(algorithm, data);
  8655. }
  8656. };
  8657. __name(Sha256Provider, "Sha256Provider");
  8658. var Sha384Provider = class extends ProviderCrypto {
  8659. constructor() {
  8660. super(...arguments);
  8661. this.name = "SHA-384";
  8662. this.usages = [];
  8663. }
  8664. async onDigest(algorithm, data) {
  8665. return ShaCrypto.digest(algorithm, data);
  8666. }
  8667. };
  8668. __name(Sha384Provider, "Sha384Provider");
  8669. var Sha512Provider = class extends ProviderCrypto {
  8670. constructor() {
  8671. super(...arguments);
  8672. this.name = "SHA-512";
  8673. this.usages = [];
  8674. }
  8675. async onDigest(algorithm, data) {
  8676. return ShaCrypto.digest(algorithm, data);
  8677. }
  8678. };
  8679. __name(Sha512Provider, "Sha512Provider");
  8680. var Sha3256Provider = class extends ProviderCrypto {
  8681. constructor() {
  8682. super(...arguments);
  8683. this.name = "SHA3-256";
  8684. this.usages = [];
  8685. }
  8686. async onDigest(algorithm, data) {
  8687. return ShaCrypto.digest(algorithm, data);
  8688. }
  8689. };
  8690. __name(Sha3256Provider, "Sha3256Provider");
  8691. var Sha3384Provider = class extends ProviderCrypto {
  8692. constructor() {
  8693. super(...arguments);
  8694. this.name = "SHA3-384";
  8695. this.usages = [];
  8696. }
  8697. async onDigest(algorithm, data) {
  8698. return ShaCrypto.digest(algorithm, data);
  8699. }
  8700. };
  8701. __name(Sha3384Provider, "Sha3384Provider");
  8702. var Sha3512Provider = class extends ProviderCrypto {
  8703. constructor() {
  8704. super(...arguments);
  8705. this.name = "SHA3-512";
  8706. this.usages = [];
  8707. }
  8708. async onDigest(algorithm, data) {
  8709. return ShaCrypto.digest(algorithm, data);
  8710. }
  8711. };
  8712. __name(Sha3512Provider, "Sha3512Provider");
  8713. var EcCrypto = class {
  8714. static async generateKey(algorithm, extractable, keyUsages) {
  8715. const privateKey = new EcPrivateKey2();
  8716. privateKey.algorithm = algorithm;
  8717. privateKey.extractable = extractable;
  8718. privateKey.usages = keyUsages.filter((usage) => this.privateKeyUsages.indexOf(usage) !== -1);
  8719. const publicKey = new EcPublicKey3();
  8720. publicKey.algorithm = algorithm;
  8721. publicKey.extractable = true;
  8722. publicKey.usages = keyUsages.filter((usage) => this.publicKeyUsages.indexOf(usage) !== -1);
  8723. const keys = import_crypto.default.generateKeyPairSync("ec", {
  8724. namedCurve: this.getOpenSSLNamedCurve(algorithm.namedCurve),
  8725. publicKeyEncoding: {
  8726. format: "der",
  8727. type: "spki"
  8728. },
  8729. privateKeyEncoding: {
  8730. format: "der",
  8731. type: "pkcs8"
  8732. }
  8733. });
  8734. privateKey.data = keys.privateKey;
  8735. publicKey.data = keys.publicKey;
  8736. const res = {
  8737. privateKey,
  8738. publicKey
  8739. };
  8740. return res;
  8741. }
  8742. static async sign(algorithm, key, data) {
  8743. const cryptoAlg = ShaCrypto.getAlgorithmName(algorithm.hash);
  8744. const signer = import_crypto.default.createSign(cryptoAlg);
  8745. signer.update(Buffer.from(data));
  8746. if (!key.pem) {
  8747. key.pem = `-----BEGIN PRIVATE KEY-----
  8748. ${key.data.toString("base64")}
  8749. -----END PRIVATE KEY-----`;
  8750. }
  8751. const options = {
  8752. key: key.pem
  8753. };
  8754. const signature = signer.sign(options);
  8755. const ecSignature = AsnParser.parse(signature, index$1.EcDsaSignature);
  8756. const signatureRaw = EcUtils.encodeSignature(ecSignature, EcCurves.get(key.algorithm.namedCurve).size);
  8757. return signatureRaw.buffer;
  8758. }
  8759. static async verify(algorithm, key, signature, data) {
  8760. const cryptoAlg = ShaCrypto.getAlgorithmName(algorithm.hash);
  8761. const signer = import_crypto.default.createVerify(cryptoAlg);
  8762. signer.update(Buffer.from(data));
  8763. if (!key.pem) {
  8764. key.pem = `-----BEGIN PUBLIC KEY-----
  8765. ${key.data.toString("base64")}
  8766. -----END PUBLIC KEY-----`;
  8767. }
  8768. const options = {
  8769. key: key.pem
  8770. };
  8771. const ecSignature = new index$1.EcDsaSignature();
  8772. const namedCurve = EcCurves.get(key.algorithm.namedCurve);
  8773. const signaturePoint = EcUtils.decodeSignature(signature, namedCurve.size);
  8774. ecSignature.r = BufferSourceConverter.toArrayBuffer(signaturePoint.r);
  8775. ecSignature.s = BufferSourceConverter.toArrayBuffer(signaturePoint.s);
  8776. const ecSignatureRaw = Buffer.from(AsnSerializer.serialize(ecSignature));
  8777. const ok = signer.verify(options, ecSignatureRaw);
  8778. return ok;
  8779. }
  8780. static async deriveBits(algorithm, baseKey, length) {
  8781. const cryptoAlg = this.getOpenSSLNamedCurve(baseKey.algorithm.namedCurve);
  8782. const ecdh = import_crypto.default.createECDH(cryptoAlg);
  8783. const asnPrivateKey = AsnParser.parse(baseKey.data, index$1.PrivateKeyInfo);
  8784. const asnEcPrivateKey = AsnParser.parse(asnPrivateKey.privateKey, index$1.EcPrivateKey);
  8785. ecdh.setPrivateKey(Buffer.from(asnEcPrivateKey.privateKey));
  8786. const asnPublicKey = AsnParser.parse(algorithm.public.data, index$1.PublicKeyInfo);
  8787. const bits = ecdh.computeSecret(Buffer.from(asnPublicKey.publicKey));
  8788. return new Uint8Array(bits).buffer.slice(0, length >> 3);
  8789. }
  8790. static async exportKey(format, key) {
  8791. switch (format.toLowerCase()) {
  8792. case "jwk":
  8793. return JsonSerializer.toJSON(key);
  8794. case "pkcs8":
  8795. case "spki":
  8796. return new Uint8Array(key.data).buffer;
  8797. case "raw": {
  8798. const publicKeyInfo = AsnParser.parse(key.data, index$1.PublicKeyInfo);
  8799. return publicKeyInfo.publicKey;
  8800. }
  8801. default:
  8802. throw new OperationError("format: Must be 'jwk', 'raw', pkcs8' or 'spki'");
  8803. }
  8804. }
  8805. static async importKey(format, keyData, algorithm, extractable, keyUsages) {
  8806. switch (format.toLowerCase()) {
  8807. case "jwk": {
  8808. const jwk = keyData;
  8809. if (jwk.d) {
  8810. const asnKey = JsonParser.fromJSON(keyData, { targetSchema: index$1.EcPrivateKey });
  8811. return this.importPrivateKey(asnKey, algorithm, extractable, keyUsages);
  8812. } else {
  8813. const asnKey = JsonParser.fromJSON(keyData, { targetSchema: index$1.EcPublicKey });
  8814. return this.importPublicKey(asnKey, algorithm, extractable, keyUsages);
  8815. }
  8816. }
  8817. case "raw": {
  8818. const asnKey = new index$1.EcPublicKey(keyData);
  8819. return this.importPublicKey(asnKey, algorithm, extractable, keyUsages);
  8820. }
  8821. case "spki": {
  8822. const keyInfo = AsnParser.parse(new Uint8Array(keyData), index$1.PublicKeyInfo);
  8823. const asnKey = new index$1.EcPublicKey(keyInfo.publicKey);
  8824. this.assertKeyParameters(keyInfo.publicKeyAlgorithm.parameters, algorithm.namedCurve);
  8825. return this.importPublicKey(asnKey, algorithm, extractable, keyUsages);
  8826. }
  8827. case "pkcs8": {
  8828. const keyInfo = AsnParser.parse(new Uint8Array(keyData), index$1.PrivateKeyInfo);
  8829. const asnKey = AsnParser.parse(keyInfo.privateKey, index$1.EcPrivateKey);
  8830. this.assertKeyParameters(keyInfo.privateKeyAlgorithm.parameters, algorithm.namedCurve);
  8831. return this.importPrivateKey(asnKey, algorithm, extractable, keyUsages);
  8832. }
  8833. default:
  8834. throw new OperationError("format: Must be 'jwk', 'raw', 'pkcs8' or 'spki'");
  8835. }
  8836. }
  8837. static assertKeyParameters(parameters, namedCurve) {
  8838. if (!parameters) {
  8839. throw new CryptoError("Key info doesn't have required parameters");
  8840. }
  8841. let namedCurveIdentifier = "";
  8842. try {
  8843. namedCurveIdentifier = AsnParser.parse(parameters, index$1.ObjectIdentifier).value;
  8844. } catch (e) {
  8845. throw new CryptoError("Cannot read key info parameters");
  8846. }
  8847. if (getOidByNamedCurve$1(namedCurve) !== namedCurveIdentifier) {
  8848. throw new CryptoError("Key info parameter doesn't match to named curve");
  8849. }
  8850. }
  8851. static async importPrivateKey(asnKey, algorithm, extractable, keyUsages) {
  8852. const keyInfo = new index$1.PrivateKeyInfo();
  8853. keyInfo.privateKeyAlgorithm.algorithm = "1.2.840.10045.2.1";
  8854. keyInfo.privateKeyAlgorithm.parameters = AsnSerializer.serialize(new index$1.ObjectIdentifier(getOidByNamedCurve$1(algorithm.namedCurve)));
  8855. keyInfo.privateKey = AsnSerializer.serialize(asnKey);
  8856. const key = new EcPrivateKey2();
  8857. key.data = Buffer.from(AsnSerializer.serialize(keyInfo));
  8858. key.algorithm = Object.assign({}, algorithm);
  8859. key.extractable = extractable;
  8860. key.usages = keyUsages;
  8861. return key;
  8862. }
  8863. static async importPublicKey(asnKey, algorithm, extractable, keyUsages) {
  8864. const keyInfo = new index$1.PublicKeyInfo();
  8865. keyInfo.publicKeyAlgorithm.algorithm = "1.2.840.10045.2.1";
  8866. const namedCurve = getOidByNamedCurve$1(algorithm.namedCurve);
  8867. keyInfo.publicKeyAlgorithm.parameters = AsnSerializer.serialize(new index$1.ObjectIdentifier(namedCurve));
  8868. keyInfo.publicKey = asnKey.value;
  8869. const key = new EcPublicKey3();
  8870. key.data = Buffer.from(AsnSerializer.serialize(keyInfo));
  8871. key.algorithm = Object.assign({}, algorithm);
  8872. key.extractable = extractable;
  8873. key.usages = keyUsages;
  8874. return key;
  8875. }
  8876. static getOpenSSLNamedCurve(curve) {
  8877. switch (curve.toUpperCase()) {
  8878. case "P-256":
  8879. return "prime256v1";
  8880. case "K-256":
  8881. return "secp256k1";
  8882. case "P-384":
  8883. return "secp384r1";
  8884. case "P-521":
  8885. return "secp521r1";
  8886. default:
  8887. return curve;
  8888. }
  8889. }
  8890. };
  8891. __name(EcCrypto, "EcCrypto");
  8892. EcCrypto.publicKeyUsages = ["verify"];
  8893. EcCrypto.privateKeyUsages = ["sign", "deriveKey", "deriveBits"];
  8894. var EcdsaProvider2 = class extends EcdsaProvider {
  8895. constructor() {
  8896. super(...arguments);
  8897. this.namedCurves = EcCurves.names;
  8898. this.hashAlgorithms = [
  8899. "SHA-1",
  8900. "SHA-256",
  8901. "SHA-384",
  8902. "SHA-512",
  8903. "shake128",
  8904. "shake256",
  8905. "SHA3-256",
  8906. "SHA3-384",
  8907. "SHA3-512"
  8908. ];
  8909. }
  8910. async onGenerateKey(algorithm, extractable, keyUsages) {
  8911. const keys = await EcCrypto.generateKey({
  8912. ...algorithm,
  8913. name: this.name
  8914. }, extractable, keyUsages);
  8915. return {
  8916. privateKey: setCryptoKey(keys.privateKey),
  8917. publicKey: setCryptoKey(keys.publicKey)
  8918. };
  8919. }
  8920. async onSign(algorithm, key, data) {
  8921. return EcCrypto.sign(algorithm, getCryptoKey(key), new Uint8Array(data));
  8922. }
  8923. async onVerify(algorithm, key, signature, data) {
  8924. return EcCrypto.verify(algorithm, getCryptoKey(key), new Uint8Array(signature), new Uint8Array(data));
  8925. }
  8926. async onExportKey(format, key) {
  8927. return EcCrypto.exportKey(format, getCryptoKey(key));
  8928. }
  8929. async onImportKey(format, keyData, algorithm, extractable, keyUsages) {
  8930. const key = await EcCrypto.importKey(format, keyData, { ...algorithm, name: this.name }, extractable, keyUsages);
  8931. return setCryptoKey(key);
  8932. }
  8933. checkCryptoKey(key, keyUsage) {
  8934. super.checkCryptoKey(key, keyUsage);
  8935. const internalKey = getCryptoKey(key);
  8936. if (!(internalKey instanceof EcPrivateKey2 || internalKey instanceof EcPublicKey3)) {
  8937. throw new TypeError("key: Is not EC CryptoKey");
  8938. }
  8939. }
  8940. };
  8941. __name(EcdsaProvider2, "EcdsaProvider");
  8942. var EcdhProvider2 = class extends EcdhProvider {
  8943. constructor() {
  8944. super(...arguments);
  8945. this.namedCurves = EcCurves.names;
  8946. }
  8947. async onGenerateKey(algorithm, extractable, keyUsages) {
  8948. const keys = await EcCrypto.generateKey({
  8949. ...algorithm,
  8950. name: this.name
  8951. }, extractable, keyUsages);
  8952. return {
  8953. privateKey: setCryptoKey(keys.privateKey),
  8954. publicKey: setCryptoKey(keys.publicKey)
  8955. };
  8956. }
  8957. async onExportKey(format, key) {
  8958. return EcCrypto.exportKey(format, getCryptoKey(key));
  8959. }
  8960. async onImportKey(format, keyData, algorithm, extractable, keyUsages) {
  8961. const key = await EcCrypto.importKey(format, keyData, { ...algorithm, name: this.name }, extractable, keyUsages);
  8962. return setCryptoKey(key);
  8963. }
  8964. checkCryptoKey(key, keyUsage) {
  8965. super.checkCryptoKey(key, keyUsage);
  8966. const internalKey = getCryptoKey(key);
  8967. if (!(internalKey instanceof EcPrivateKey2 || internalKey instanceof EcPublicKey3)) {
  8968. throw new TypeError("key: Is not EC CryptoKey");
  8969. }
  8970. }
  8971. async onDeriveBits(algorithm, baseKey, length) {
  8972. const bits = await EcCrypto.deriveBits({ ...algorithm, public: getCryptoKey(algorithm.public) }, getCryptoKey(baseKey), length);
  8973. return bits;
  8974. }
  8975. };
  8976. __name(EcdhProvider2, "EcdhProvider");
  8977. var edOIDs = {
  8978. [index$1.idEd448]: "Ed448",
  8979. "ed448": index$1.idEd448,
  8980. [index$1.idX448]: "X448",
  8981. "x448": index$1.idX448,
  8982. [index$1.idEd25519]: "Ed25519",
  8983. "ed25519": index$1.idEd25519,
  8984. [index$1.idX25519]: "X25519",
  8985. "x25519": index$1.idX25519
  8986. };
  8987. function getOidByNamedCurve(namedCurve) {
  8988. const oid = edOIDs[namedCurve.toLowerCase()];
  8989. if (!oid) {
  8990. throw new OperationError(`Cannot convert WebCrypto named curve '${namedCurve}' to OID`);
  8991. }
  8992. return oid;
  8993. }
  8994. __name(getOidByNamedCurve, "getOidByNamedCurve");
  8995. var EdPrivateKey3 = class extends AsymmetricKey {
  8996. constructor() {
  8997. super(...arguments);
  8998. this.type = "private";
  8999. }
  9000. getKey() {
  9001. const keyInfo = AsnParser.parse(this.data, index$1.PrivateKeyInfo);
  9002. return AsnParser.parse(keyInfo.privateKey, index$1.CurvePrivateKey);
  9003. }
  9004. toJSON() {
  9005. const key = this.getKey();
  9006. const json = {
  9007. kty: "OKP",
  9008. crv: this.algorithm.namedCurve,
  9009. key_ops: this.usages,
  9010. ext: this.extractable
  9011. };
  9012. return Object.assign(json, JsonSerializer.toJSON(key));
  9013. }
  9014. fromJSON(json) {
  9015. if (!json.crv) {
  9016. throw new OperationError(`Cannot get named curve from JWK. Property 'crv' is required`);
  9017. }
  9018. const keyInfo = new index$1.PrivateKeyInfo();
  9019. keyInfo.privateKeyAlgorithm.algorithm = getOidByNamedCurve(json.crv);
  9020. const key = JsonParser.fromJSON(json, { targetSchema: index$1.CurvePrivateKey });
  9021. keyInfo.privateKey = AsnSerializer.serialize(key);
  9022. this.data = Buffer.from(AsnSerializer.serialize(keyInfo));
  9023. return this;
  9024. }
  9025. };
  9026. __name(EdPrivateKey3, "EdPrivateKey");
  9027. var EdPublicKey3 = class extends AsymmetricKey {
  9028. constructor() {
  9029. super(...arguments);
  9030. this.type = "public";
  9031. }
  9032. getKey() {
  9033. const keyInfo = AsnParser.parse(this.data, index$1.PublicKeyInfo);
  9034. return keyInfo.publicKey;
  9035. }
  9036. toJSON() {
  9037. const key = this.getKey();
  9038. const json = {
  9039. kty: "OKP",
  9040. crv: this.algorithm.namedCurve,
  9041. key_ops: this.usages,
  9042. ext: this.extractable
  9043. };
  9044. return Object.assign(json, {
  9045. x: Convert.ToBase64Url(key)
  9046. });
  9047. }
  9048. fromJSON(json) {
  9049. if (!json.crv) {
  9050. throw new OperationError(`Cannot get named curve from JWK. Property 'crv' is required`);
  9051. }
  9052. if (!json.x) {
  9053. throw new OperationError(`Cannot get property from JWK. Property 'x' is required`);
  9054. }
  9055. const keyInfo = new index$1.PublicKeyInfo();
  9056. keyInfo.publicKeyAlgorithm.algorithm = getOidByNamedCurve(json.crv);
  9057. keyInfo.publicKey = Convert.FromBase64Url(json.x);
  9058. this.data = Buffer.from(AsnSerializer.serialize(keyInfo));
  9059. return this;
  9060. }
  9061. };
  9062. __name(EdPublicKey3, "EdPublicKey");
  9063. var EdCrypto = class {
  9064. static async generateKey(algorithm, extractable, keyUsages) {
  9065. const privateKey = new EdPrivateKey3();
  9066. privateKey.algorithm = algorithm;
  9067. privateKey.extractable = extractable;
  9068. privateKey.usages = keyUsages.filter((usage) => this.privateKeyUsages.indexOf(usage) !== -1);
  9069. const publicKey = new EdPublicKey3();
  9070. publicKey.algorithm = algorithm;
  9071. publicKey.extractable = true;
  9072. publicKey.usages = keyUsages.filter((usage) => this.publicKeyUsages.indexOf(usage) !== -1);
  9073. const type = algorithm.namedCurve.toLowerCase();
  9074. const keys = import_crypto.default.generateKeyPairSync(type, {
  9075. publicKeyEncoding: {
  9076. format: "der",
  9077. type: "spki"
  9078. },
  9079. privateKeyEncoding: {
  9080. format: "der",
  9081. type: "pkcs8"
  9082. }
  9083. });
  9084. privateKey.data = keys.privateKey;
  9085. publicKey.data = keys.publicKey;
  9086. const res = {
  9087. privateKey,
  9088. publicKey
  9089. };
  9090. return res;
  9091. }
  9092. static async sign(algorithm, key, data) {
  9093. if (!key.pem) {
  9094. key.pem = `-----BEGIN PRIVATE KEY-----
  9095. ${key.data.toString("base64")}
  9096. -----END PRIVATE KEY-----`;
  9097. }
  9098. const options = {
  9099. key: key.pem
  9100. };
  9101. const signature = import_crypto.default.sign(null, Buffer.from(data), options);
  9102. return BufferSourceConverter.toArrayBuffer(signature);
  9103. }
  9104. static async verify(algorithm, key, signature, data) {
  9105. if (!key.pem) {
  9106. key.pem = `-----BEGIN PUBLIC KEY-----
  9107. ${key.data.toString("base64")}
  9108. -----END PUBLIC KEY-----`;
  9109. }
  9110. const options = {
  9111. key: key.pem
  9112. };
  9113. const ok = import_crypto.default.verify(null, Buffer.from(data), options, Buffer.from(signature));
  9114. return ok;
  9115. }
  9116. static async deriveBits(algorithm, baseKey, length) {
  9117. const publicKey = import_crypto.default.createPublicKey({
  9118. key: algorithm.public.data,
  9119. format: "der",
  9120. type: "spki"
  9121. });
  9122. const privateKey = import_crypto.default.createPrivateKey({
  9123. key: baseKey.data,
  9124. format: "der",
  9125. type: "pkcs8"
  9126. });
  9127. const bits = import_crypto.default.diffieHellman({
  9128. publicKey,
  9129. privateKey
  9130. });
  9131. return new Uint8Array(bits).buffer.slice(0, length >> 3);
  9132. }
  9133. static async exportKey(format, key) {
  9134. switch (format.toLowerCase()) {
  9135. case "jwk":
  9136. return JsonSerializer.toJSON(key);
  9137. case "pkcs8":
  9138. case "spki":
  9139. return new Uint8Array(key.data).buffer;
  9140. case "raw": {
  9141. const publicKeyInfo = AsnParser.parse(key.data, index$1.PublicKeyInfo);
  9142. return publicKeyInfo.publicKey;
  9143. }
  9144. default:
  9145. throw new OperationError("format: Must be 'jwk', 'raw', pkcs8' or 'spki'");
  9146. }
  9147. }
  9148. static async importKey(format, keyData, algorithm, extractable, keyUsages) {
  9149. switch (format.toLowerCase()) {
  9150. case "jwk": {
  9151. const jwk = keyData;
  9152. if (jwk.d) {
  9153. const asnKey = JsonParser.fromJSON(keyData, { targetSchema: index$1.CurvePrivateKey });
  9154. return this.importPrivateKey(asnKey, algorithm, extractable, keyUsages);
  9155. } else {
  9156. if (!jwk.x) {
  9157. throw new TypeError("keyData: Cannot get required 'x' filed");
  9158. }
  9159. return this.importPublicKey(Convert.FromBase64Url(jwk.x), algorithm, extractable, keyUsages);
  9160. }
  9161. }
  9162. case "raw": {
  9163. return this.importPublicKey(keyData, algorithm, extractable, keyUsages);
  9164. }
  9165. case "spki": {
  9166. const keyInfo = AsnParser.parse(new Uint8Array(keyData), index$1.PublicKeyInfo);
  9167. return this.importPublicKey(keyInfo.publicKey, algorithm, extractable, keyUsages);
  9168. }
  9169. case "pkcs8": {
  9170. const keyInfo = AsnParser.parse(new Uint8Array(keyData), index$1.PrivateKeyInfo);
  9171. const asnKey = AsnParser.parse(keyInfo.privateKey, index$1.CurvePrivateKey);
  9172. return this.importPrivateKey(asnKey, algorithm, extractable, keyUsages);
  9173. }
  9174. default:
  9175. throw new OperationError("format: Must be 'jwk', 'raw', 'pkcs8' or 'spki'");
  9176. }
  9177. }
  9178. static importPrivateKey(asnKey, algorithm, extractable, keyUsages) {
  9179. const key = new EdPrivateKey3();
  9180. key.fromJSON({
  9181. crv: algorithm.namedCurve,
  9182. d: Convert.ToBase64Url(asnKey.d)
  9183. });
  9184. key.algorithm = Object.assign({}, algorithm);
  9185. key.extractable = extractable;
  9186. key.usages = keyUsages;
  9187. return key;
  9188. }
  9189. static async importPublicKey(asnKey, algorithm, extractable, keyUsages) {
  9190. const key = new EdPublicKey3();
  9191. key.fromJSON({
  9192. crv: algorithm.namedCurve,
  9193. x: Convert.ToBase64Url(asnKey)
  9194. });
  9195. key.algorithm = Object.assign({}, algorithm);
  9196. key.extractable = extractable;
  9197. key.usages = keyUsages;
  9198. return key;
  9199. }
  9200. };
  9201. __name(EdCrypto, "EdCrypto");
  9202. EdCrypto.publicKeyUsages = ["verify"];
  9203. EdCrypto.privateKeyUsages = ["sign", "deriveKey", "deriveBits"];
  9204. var EdDsaProvider2 = class extends EdDsaProvider {
  9205. async onGenerateKey(algorithm, extractable, keyUsages) {
  9206. const keys = await EdCrypto.generateKey({
  9207. name: this.name,
  9208. namedCurve: algorithm.namedCurve.replace(/^ed/i, "Ed")
  9209. }, extractable, keyUsages);
  9210. return {
  9211. privateKey: setCryptoKey(keys.privateKey),
  9212. publicKey: setCryptoKey(keys.publicKey)
  9213. };
  9214. }
  9215. async onSign(algorithm, key, data) {
  9216. return EdCrypto.sign(algorithm, getCryptoKey(key), new Uint8Array(data));
  9217. }
  9218. async onVerify(algorithm, key, signature, data) {
  9219. return EdCrypto.verify(algorithm, getCryptoKey(key), new Uint8Array(signature), new Uint8Array(data));
  9220. }
  9221. async onExportKey(format, key) {
  9222. return EdCrypto.exportKey(format, getCryptoKey(key));
  9223. }
  9224. async onImportKey(format, keyData, algorithm, extractable, keyUsages) {
  9225. const key = await EdCrypto.importKey(format, keyData, { ...algorithm, name: this.name }, extractable, keyUsages);
  9226. return setCryptoKey(key);
  9227. }
  9228. };
  9229. __name(EdDsaProvider2, "EdDsaProvider");
  9230. var EcdhEsProvider2 = class extends EcdhEsProvider {
  9231. async onGenerateKey(algorithm, extractable, keyUsages) {
  9232. const keys = await EdCrypto.generateKey({
  9233. name: this.name,
  9234. namedCurve: algorithm.namedCurve.toUpperCase()
  9235. }, extractable, keyUsages);
  9236. return {
  9237. privateKey: setCryptoKey(keys.privateKey),
  9238. publicKey: setCryptoKey(keys.publicKey)
  9239. };
  9240. }
  9241. async onDeriveBits(algorithm, baseKey, length) {
  9242. const bits = await EdCrypto.deriveBits({ ...algorithm, public: getCryptoKey(algorithm.public) }, getCryptoKey(baseKey), length);
  9243. return bits;
  9244. }
  9245. async onExportKey(format, key) {
  9246. return EdCrypto.exportKey(format, getCryptoKey(key));
  9247. }
  9248. async onImportKey(format, keyData, algorithm, extractable, keyUsages) {
  9249. const key = await EdCrypto.importKey(format, keyData, { ...algorithm, name: this.name }, extractable, keyUsages);
  9250. return setCryptoKey(key);
  9251. }
  9252. };
  9253. __name(EcdhEsProvider2, "EcdhEsProvider");
  9254. var PbkdfCryptoKey = class extends CryptoKey2 {
  9255. };
  9256. __name(PbkdfCryptoKey, "PbkdfCryptoKey");
  9257. var Pbkdf2Provider2 = class extends Pbkdf2Provider {
  9258. async onDeriveBits(algorithm, baseKey, length) {
  9259. return new Promise((resolve, reject) => {
  9260. const salt = BufferSourceConverter.toArrayBuffer(algorithm.salt);
  9261. const hash = algorithm.hash.name.replace("-", "");
  9262. import_crypto.default.pbkdf2(getCryptoKey(baseKey).data, Buffer.from(salt), algorithm.iterations, length >> 3, hash, (err, derivedBits) => {
  9263. if (err) {
  9264. reject(err);
  9265. } else {
  9266. resolve(new Uint8Array(derivedBits).buffer);
  9267. }
  9268. });
  9269. });
  9270. }
  9271. async onImportKey(format, keyData, algorithm, extractable, keyUsages) {
  9272. if (format === "raw") {
  9273. const key = new PbkdfCryptoKey();
  9274. key.data = Buffer.from(keyData);
  9275. key.algorithm = { name: this.name };
  9276. key.extractable = false;
  9277. key.usages = keyUsages;
  9278. return setCryptoKey(key);
  9279. }
  9280. throw new OperationError("format: Must be 'raw'");
  9281. }
  9282. checkCryptoKey(key, keyUsage) {
  9283. super.checkCryptoKey(key, keyUsage);
  9284. if (!(getCryptoKey(key) instanceof PbkdfCryptoKey)) {
  9285. throw new TypeError("key: Is not PBKDF CryptoKey");
  9286. }
  9287. }
  9288. };
  9289. __name(Pbkdf2Provider2, "Pbkdf2Provider");
  9290. var HmacCryptoKey = class extends CryptoKey2 {
  9291. get alg() {
  9292. const hash = this.algorithm.hash.name.toUpperCase();
  9293. return `HS${hash.replace("SHA-", "")}`;
  9294. }
  9295. set alg(value) {
  9296. }
  9297. };
  9298. __name(HmacCryptoKey, "HmacCryptoKey");
  9299. __decorate([
  9300. JsonProp({ name: "k", converter: JsonBase64UrlConverter })
  9301. ], HmacCryptoKey.prototype, "data", void 0);
  9302. var HmacProvider2 = class extends HmacProvider {
  9303. async onGenerateKey(algorithm, extractable, keyUsages) {
  9304. const length = (algorithm.length || this.getDefaultLength(algorithm.hash.name)) >> 3 << 3;
  9305. const key = new HmacCryptoKey();
  9306. key.algorithm = {
  9307. ...algorithm,
  9308. length,
  9309. name: this.name
  9310. };
  9311. key.extractable = extractable;
  9312. key.usages = keyUsages;
  9313. key.data = import_crypto.default.randomBytes(length >> 3);
  9314. return setCryptoKey(key);
  9315. }
  9316. async onSign(algorithm, key, data) {
  9317. const cryptoAlg = ShaCrypto.getAlgorithmName(key.algorithm.hash);
  9318. const hmac = import_crypto.default.createHmac(cryptoAlg, getCryptoKey(key).data).update(Buffer.from(data)).digest();
  9319. return new Uint8Array(hmac).buffer;
  9320. }
  9321. async onVerify(algorithm, key, signature, data) {
  9322. const cryptoAlg = ShaCrypto.getAlgorithmName(key.algorithm.hash);
  9323. const hmac = import_crypto.default.createHmac(cryptoAlg, getCryptoKey(key).data).update(Buffer.from(data)).digest();
  9324. return hmac.compare(Buffer.from(signature)) === 0;
  9325. }
  9326. async onImportKey(format, keyData, algorithm, extractable, keyUsages) {
  9327. let key;
  9328. switch (format.toLowerCase()) {
  9329. case "jwk":
  9330. key = JsonParser.fromJSON(keyData, { targetSchema: HmacCryptoKey });
  9331. break;
  9332. case "raw":
  9333. key = new HmacCryptoKey();
  9334. key.data = Buffer.from(keyData);
  9335. break;
  9336. default:
  9337. throw new OperationError("format: Must be 'jwk' or 'raw'");
  9338. }
  9339. key.algorithm = {
  9340. hash: { name: algorithm.hash.name },
  9341. name: this.name,
  9342. length: key.data.length << 3
  9343. };
  9344. key.extractable = extractable;
  9345. key.usages = keyUsages;
  9346. return setCryptoKey(key);
  9347. }
  9348. async onExportKey(format, key) {
  9349. switch (format.toLowerCase()) {
  9350. case "jwk":
  9351. return JsonSerializer.toJSON(getCryptoKey(key));
  9352. case "raw":
  9353. return new Uint8Array(getCryptoKey(key).data).buffer;
  9354. default:
  9355. throw new OperationError("format: Must be 'jwk' or 'raw'");
  9356. }
  9357. }
  9358. checkCryptoKey(key, keyUsage) {
  9359. super.checkCryptoKey(key, keyUsage);
  9360. if (!(getCryptoKey(key) instanceof HmacCryptoKey)) {
  9361. throw new TypeError("key: Is not HMAC CryptoKey");
  9362. }
  9363. }
  9364. };
  9365. __name(HmacProvider2, "HmacProvider");
  9366. var HkdfCryptoKey = class extends CryptoKey2 {
  9367. };
  9368. __name(HkdfCryptoKey, "HkdfCryptoKey");
  9369. var HkdfProvider2 = class extends HkdfProvider {
  9370. async onImportKey(format, keyData, algorithm, extractable, keyUsages) {
  9371. if (format.toLowerCase() !== "raw") {
  9372. throw new OperationError("Operation not supported");
  9373. }
  9374. const key = new HkdfCryptoKey();
  9375. key.data = Buffer.from(keyData);
  9376. key.algorithm = { name: this.name };
  9377. key.extractable = extractable;
  9378. key.usages = keyUsages;
  9379. return setCryptoKey(key);
  9380. }
  9381. async onDeriveBits(params, baseKey, length) {
  9382. const hash = params.hash.name.replace("-", "");
  9383. const hashLength = import_crypto.default.createHash(hash).digest().length;
  9384. const byteLength = length / 8;
  9385. const info = BufferSourceConverter.toUint8Array(params.info);
  9386. const PRK = import_crypto.default.createHmac(hash, BufferSourceConverter.toUint8Array(params.salt)).update(BufferSourceConverter.toUint8Array(getCryptoKey(baseKey).data)).digest();
  9387. const blocks = [Buffer.alloc(0)];
  9388. const blockCount = Math.ceil(byteLength / hashLength) + 1;
  9389. for (let i = 1; i < blockCount; ++i) {
  9390. blocks.push(import_crypto.default.createHmac(hash, PRK).update(Buffer.concat([blocks[i - 1], info, Buffer.from([i])])).digest());
  9391. }
  9392. return Buffer.concat(blocks).slice(0, byteLength);
  9393. }
  9394. checkCryptoKey(key, keyUsage) {
  9395. super.checkCryptoKey(key, keyUsage);
  9396. if (!(getCryptoKey(key) instanceof HkdfCryptoKey)) {
  9397. throw new TypeError("key: Is not HKDF CryptoKey");
  9398. }
  9399. }
  9400. };
  9401. __name(HkdfProvider2, "HkdfProvider");
  9402. var ShakeCrypto = class {
  9403. static digest(algorithm, data) {
  9404. const hash = import_crypto.default.createHash(algorithm.name.toLowerCase(), { outputLength: algorithm.length }).update(Buffer.from(data)).digest();
  9405. return new Uint8Array(hash).buffer;
  9406. }
  9407. };
  9408. __name(ShakeCrypto, "ShakeCrypto");
  9409. var Shake128Provider2 = class extends Shake128Provider {
  9410. async onDigest(algorithm, data) {
  9411. return ShakeCrypto.digest(algorithm, data);
  9412. }
  9413. };
  9414. __name(Shake128Provider2, "Shake128Provider");
  9415. var Shake256Provider2 = class extends Shake256Provider {
  9416. async onDigest(algorithm, data) {
  9417. return ShakeCrypto.digest(algorithm, data);
  9418. }
  9419. };
  9420. __name(Shake256Provider2, "Shake256Provider");
  9421. var SubtleCrypto2 = class extends SubtleCrypto {
  9422. constructor() {
  9423. var _a2;
  9424. super();
  9425. this.providers.set(new AesCbcProvider2());
  9426. this.providers.set(new AesCtrProvider2());
  9427. this.providers.set(new AesGcmProvider2());
  9428. this.providers.set(new AesCmacProvider2());
  9429. this.providers.set(new AesKwProvider2());
  9430. this.providers.set(new AesEcbProvider2());
  9431. this.providers.set(new DesCbcProvider());
  9432. this.providers.set(new DesEde3CbcProvider());
  9433. this.providers.set(new RsaSsaProvider2());
  9434. this.providers.set(new RsaPssProvider2());
  9435. this.providers.set(new RsaOaepProvider2());
  9436. this.providers.set(new RsaEsProvider());
  9437. this.providers.set(new EcdsaProvider2());
  9438. this.providers.set(new EcdhProvider2());
  9439. this.providers.set(new Sha1Provider());
  9440. this.providers.set(new Sha256Provider());
  9441. this.providers.set(new Sha384Provider());
  9442. this.providers.set(new Sha512Provider());
  9443. this.providers.set(new Pbkdf2Provider2());
  9444. this.providers.set(new HmacProvider2());
  9445. this.providers.set(new HkdfProvider2());
  9446. const nodeMajorVersion = (_a2 = /^v(\d+)/.exec(process.version)) === null || _a2 === void 0 ? void 0 : _a2[1];
  9447. if (nodeMajorVersion && parseInt(nodeMajorVersion, 10) >= 12) {
  9448. this.providers.set(new Shake128Provider2());
  9449. this.providers.set(new Shake256Provider2());
  9450. }
  9451. const hashes = crypto.getHashes();
  9452. if (hashes.includes("sha3-256")) {
  9453. this.providers.set(new Sha3256Provider());
  9454. }
  9455. if (hashes.includes("sha3-384")) {
  9456. this.providers.set(new Sha3384Provider());
  9457. }
  9458. if (hashes.includes("sha3-512")) {
  9459. this.providers.set(new Sha3512Provider());
  9460. }
  9461. if (nodeMajorVersion && parseInt(nodeMajorVersion, 10) >= 14) {
  9462. this.providers.set(new EdDsaProvider2());
  9463. this.providers.set(new EcdhEsProvider2());
  9464. }
  9465. }
  9466. };
  9467. __name(SubtleCrypto2, "SubtleCrypto");
  9468. var Crypto2 = class extends Crypto {
  9469. constructor() {
  9470. super(...arguments);
  9471. this.subtle = new SubtleCrypto2();
  9472. }
  9473. getRandomValues(array) {
  9474. if (!ArrayBuffer.isView(array)) {
  9475. throw new TypeError("Failed to execute 'getRandomValues' on 'Crypto': parameter 1 is not of type 'ArrayBufferView'");
  9476. }
  9477. const buffer = Buffer.from(array.buffer, array.byteOffset, array.byteLength);
  9478. import_crypto.default.randomFillSync(buffer);
  9479. return array;
  9480. }
  9481. };
  9482. __name(Crypto2, "Crypto");
  9483. // ../../node_modules/.pnpm/uuid@8.3.2/node_modules/uuid/wrapper.mjs
  9484. init_define_process();
  9485. var import_dist = __toESM(require_dist(), 1);
  9486. var v1 = import_dist.default.v1;
  9487. var v3 = import_dist.default.v3;
  9488. var v4 = import_dist.default.v4;
  9489. var v5 = import_dist.default.v5;
  9490. var NIL = import_dist.default.NIL;
  9491. var version2 = import_dist.default.version;
  9492. var validate = import_dist.default.validate;
  9493. var stringify = import_dist.default.stringify;
  9494. var parse = import_dist.default.parse;
  9495. // src/primitives/crypto.js
  9496. var _randomUUID;
  9497. var Crypto3 = class extends Crypto2 {
  9498. constructor() {
  9499. super(...arguments);
  9500. __privateAdd(this, _randomUUID, v4);
  9501. }
  9502. };
  9503. __name(Crypto3, "Crypto");
  9504. _randomUUID = new WeakMap();
  9505. function SubtleCrypto3() {
  9506. if (!(this instanceof SubtleCrypto3))
  9507. return new SubtleCrypto3();
  9508. throw TypeError("Illegal constructor");
  9509. }
  9510. __name(SubtleCrypto3, "SubtleCrypto");
  9511. var crypto2 = new Crypto3();
  9512. // Annotate the CommonJS export names for ESM import in node:
  9513. 0 && (module.exports = {
  9514. Crypto,
  9515. CryptoKey,
  9516. SubtleCrypto,
  9517. crypto
  9518. });