web3.js 394 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686
  1. require=(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
  2. module.exports=[
  3. {
  4. "constant": true,
  5. "inputs": [
  6. {
  7. "name": "_owner",
  8. "type": "address"
  9. }
  10. ],
  11. "name": "name",
  12. "outputs": [
  13. {
  14. "name": "o_name",
  15. "type": "bytes32"
  16. }
  17. ],
  18. "type": "function"
  19. },
  20. {
  21. "constant": true,
  22. "inputs": [
  23. {
  24. "name": "_name",
  25. "type": "bytes32"
  26. }
  27. ],
  28. "name": "owner",
  29. "outputs": [
  30. {
  31. "name": "",
  32. "type": "address"
  33. }
  34. ],
  35. "type": "function"
  36. },
  37. {
  38. "constant": true,
  39. "inputs": [
  40. {
  41. "name": "_name",
  42. "type": "bytes32"
  43. }
  44. ],
  45. "name": "content",
  46. "outputs": [
  47. {
  48. "name": "",
  49. "type": "bytes32"
  50. }
  51. ],
  52. "type": "function"
  53. },
  54. {
  55. "constant": true,
  56. "inputs": [
  57. {
  58. "name": "_name",
  59. "type": "bytes32"
  60. }
  61. ],
  62. "name": "addr",
  63. "outputs": [
  64. {
  65. "name": "",
  66. "type": "address"
  67. }
  68. ],
  69. "type": "function"
  70. },
  71. {
  72. "constant": false,
  73. "inputs": [
  74. {
  75. "name": "_name",
  76. "type": "bytes32"
  77. }
  78. ],
  79. "name": "reserve",
  80. "outputs": [],
  81. "type": "function"
  82. },
  83. {
  84. "constant": true,
  85. "inputs": [
  86. {
  87. "name": "_name",
  88. "type": "bytes32"
  89. }
  90. ],
  91. "name": "subRegistrar",
  92. "outputs": [
  93. {
  94. "name": "",
  95. "type": "address"
  96. }
  97. ],
  98. "type": "function"
  99. },
  100. {
  101. "constant": false,
  102. "inputs": [
  103. {
  104. "name": "_name",
  105. "type": "bytes32"
  106. },
  107. {
  108. "name": "_newOwner",
  109. "type": "address"
  110. }
  111. ],
  112. "name": "transfer",
  113. "outputs": [],
  114. "type": "function"
  115. },
  116. {
  117. "constant": false,
  118. "inputs": [
  119. {
  120. "name": "_name",
  121. "type": "bytes32"
  122. },
  123. {
  124. "name": "_registrar",
  125. "type": "address"
  126. }
  127. ],
  128. "name": "setSubRegistrar",
  129. "outputs": [],
  130. "type": "function"
  131. },
  132. {
  133. "constant": false,
  134. "inputs": [],
  135. "name": "Registrar",
  136. "outputs": [],
  137. "type": "function"
  138. },
  139. {
  140. "constant": false,
  141. "inputs": [
  142. {
  143. "name": "_name",
  144. "type": "bytes32"
  145. },
  146. {
  147. "name": "_a",
  148. "type": "address"
  149. },
  150. {
  151. "name": "_primary",
  152. "type": "bool"
  153. }
  154. ],
  155. "name": "setAddress",
  156. "outputs": [],
  157. "type": "function"
  158. },
  159. {
  160. "constant": false,
  161. "inputs": [
  162. {
  163. "name": "_name",
  164. "type": "bytes32"
  165. },
  166. {
  167. "name": "_content",
  168. "type": "bytes32"
  169. }
  170. ],
  171. "name": "setContent",
  172. "outputs": [],
  173. "type": "function"
  174. },
  175. {
  176. "constant": false,
  177. "inputs": [
  178. {
  179. "name": "_name",
  180. "type": "bytes32"
  181. }
  182. ],
  183. "name": "disown",
  184. "outputs": [],
  185. "type": "function"
  186. },
  187. {
  188. "anonymous": false,
  189. "inputs": [
  190. {
  191. "indexed": true,
  192. "name": "_name",
  193. "type": "bytes32"
  194. },
  195. {
  196. "indexed": false,
  197. "name": "_winner",
  198. "type": "address"
  199. }
  200. ],
  201. "name": "AuctionEnded",
  202. "type": "event"
  203. },
  204. {
  205. "anonymous": false,
  206. "inputs": [
  207. {
  208. "indexed": true,
  209. "name": "_name",
  210. "type": "bytes32"
  211. },
  212. {
  213. "indexed": false,
  214. "name": "_bidder",
  215. "type": "address"
  216. },
  217. {
  218. "indexed": false,
  219. "name": "_value",
  220. "type": "uint256"
  221. }
  222. ],
  223. "name": "NewBid",
  224. "type": "event"
  225. },
  226. {
  227. "anonymous": false,
  228. "inputs": [
  229. {
  230. "indexed": true,
  231. "name": "name",
  232. "type": "bytes32"
  233. }
  234. ],
  235. "name": "Changed",
  236. "type": "event"
  237. },
  238. {
  239. "anonymous": false,
  240. "inputs": [
  241. {
  242. "indexed": true,
  243. "name": "name",
  244. "type": "bytes32"
  245. },
  246. {
  247. "indexed": true,
  248. "name": "addr",
  249. "type": "address"
  250. }
  251. ],
  252. "name": "PrimaryChanged",
  253. "type": "event"
  254. }
  255. ]
  256. },{}],2:[function(require,module,exports){
  257. module.exports=[
  258. {
  259. "constant": true,
  260. "inputs": [
  261. {
  262. "name": "_name",
  263. "type": "bytes32"
  264. }
  265. ],
  266. "name": "owner",
  267. "outputs": [
  268. {
  269. "name": "",
  270. "type": "address"
  271. }
  272. ],
  273. "type": "function"
  274. },
  275. {
  276. "constant": false,
  277. "inputs": [
  278. {
  279. "name": "_name",
  280. "type": "bytes32"
  281. },
  282. {
  283. "name": "_refund",
  284. "type": "address"
  285. }
  286. ],
  287. "name": "disown",
  288. "outputs": [],
  289. "type": "function"
  290. },
  291. {
  292. "constant": true,
  293. "inputs": [
  294. {
  295. "name": "_name",
  296. "type": "bytes32"
  297. }
  298. ],
  299. "name": "addr",
  300. "outputs": [
  301. {
  302. "name": "",
  303. "type": "address"
  304. }
  305. ],
  306. "type": "function"
  307. },
  308. {
  309. "constant": false,
  310. "inputs": [
  311. {
  312. "name": "_name",
  313. "type": "bytes32"
  314. }
  315. ],
  316. "name": "reserve",
  317. "outputs": [],
  318. "type": "function"
  319. },
  320. {
  321. "constant": false,
  322. "inputs": [
  323. {
  324. "name": "_name",
  325. "type": "bytes32"
  326. },
  327. {
  328. "name": "_newOwner",
  329. "type": "address"
  330. }
  331. ],
  332. "name": "transfer",
  333. "outputs": [],
  334. "type": "function"
  335. },
  336. {
  337. "constant": false,
  338. "inputs": [
  339. {
  340. "name": "_name",
  341. "type": "bytes32"
  342. },
  343. {
  344. "name": "_a",
  345. "type": "address"
  346. }
  347. ],
  348. "name": "setAddr",
  349. "outputs": [],
  350. "type": "function"
  351. },
  352. {
  353. "anonymous": false,
  354. "inputs": [
  355. {
  356. "indexed": true,
  357. "name": "name",
  358. "type": "bytes32"
  359. }
  360. ],
  361. "name": "Changed",
  362. "type": "event"
  363. }
  364. ]
  365. },{}],3:[function(require,module,exports){
  366. module.exports=[
  367. {
  368. "constant": false,
  369. "inputs": [
  370. {
  371. "name": "from",
  372. "type": "bytes32"
  373. },
  374. {
  375. "name": "to",
  376. "type": "address"
  377. },
  378. {
  379. "name": "value",
  380. "type": "uint256"
  381. }
  382. ],
  383. "name": "transfer",
  384. "outputs": [],
  385. "type": "function"
  386. },
  387. {
  388. "constant": false,
  389. "inputs": [
  390. {
  391. "name": "from",
  392. "type": "bytes32"
  393. },
  394. {
  395. "name": "to",
  396. "type": "address"
  397. },
  398. {
  399. "name": "indirectId",
  400. "type": "bytes32"
  401. },
  402. {
  403. "name": "value",
  404. "type": "uint256"
  405. }
  406. ],
  407. "name": "icapTransfer",
  408. "outputs": [],
  409. "type": "function"
  410. },
  411. {
  412. "constant": false,
  413. "inputs": [
  414. {
  415. "name": "to",
  416. "type": "bytes32"
  417. }
  418. ],
  419. "name": "deposit",
  420. "outputs": [],
  421. "payable": true,
  422. "type": "function"
  423. },
  424. {
  425. "anonymous": false,
  426. "inputs": [
  427. {
  428. "indexed": true,
  429. "name": "from",
  430. "type": "address"
  431. },
  432. {
  433. "indexed": false,
  434. "name": "value",
  435. "type": "uint256"
  436. }
  437. ],
  438. "name": "AnonymousDeposit",
  439. "type": "event"
  440. },
  441. {
  442. "anonymous": false,
  443. "inputs": [
  444. {
  445. "indexed": true,
  446. "name": "from",
  447. "type": "address"
  448. },
  449. {
  450. "indexed": true,
  451. "name": "to",
  452. "type": "bytes32"
  453. },
  454. {
  455. "indexed": false,
  456. "name": "value",
  457. "type": "uint256"
  458. }
  459. ],
  460. "name": "Deposit",
  461. "type": "event"
  462. },
  463. {
  464. "anonymous": false,
  465. "inputs": [
  466. {
  467. "indexed": true,
  468. "name": "from",
  469. "type": "bytes32"
  470. },
  471. {
  472. "indexed": true,
  473. "name": "to",
  474. "type": "address"
  475. },
  476. {
  477. "indexed": false,
  478. "name": "value",
  479. "type": "uint256"
  480. }
  481. ],
  482. "name": "Transfer",
  483. "type": "event"
  484. },
  485. {
  486. "anonymous": false,
  487. "inputs": [
  488. {
  489. "indexed": true,
  490. "name": "from",
  491. "type": "bytes32"
  492. },
  493. {
  494. "indexed": true,
  495. "name": "to",
  496. "type": "address"
  497. },
  498. {
  499. "indexed": false,
  500. "name": "indirectId",
  501. "type": "bytes32"
  502. },
  503. {
  504. "indexed": false,
  505. "name": "value",
  506. "type": "uint256"
  507. }
  508. ],
  509. "name": "IcapTransfer",
  510. "type": "event"
  511. }
  512. ]
  513. },{}],4:[function(require,module,exports){
  514. var f = require('./formatters');
  515. var SolidityType = require('./type');
  516. /**
  517. * SolidityTypeAddress is a prootype that represents address type
  518. * It matches:
  519. * address
  520. * address[]
  521. * address[4]
  522. * address[][]
  523. * address[3][]
  524. * address[][6][], ...
  525. */
  526. var SolidityTypeAddress = function () {
  527. this._inputFormatter = f.formatInputInt;
  528. this._outputFormatter = f.formatOutputAddress;
  529. };
  530. SolidityTypeAddress.prototype = new SolidityType({});
  531. SolidityTypeAddress.prototype.constructor = SolidityTypeAddress;
  532. SolidityTypeAddress.prototype.isType = function (name) {
  533. return !!name.match(/address(\[([0-9]*)\])?/);
  534. };
  535. module.exports = SolidityTypeAddress;
  536. },{"./formatters":9,"./type":14}],5:[function(require,module,exports){
  537. var f = require('./formatters');
  538. var SolidityType = require('./type');
  539. /**
  540. * SolidityTypeBool is a prootype that represents bool type
  541. * It matches:
  542. * bool
  543. * bool[]
  544. * bool[4]
  545. * bool[][]
  546. * bool[3][]
  547. * bool[][6][], ...
  548. */
  549. var SolidityTypeBool = function () {
  550. this._inputFormatter = f.formatInputBool;
  551. this._outputFormatter = f.formatOutputBool;
  552. };
  553. SolidityTypeBool.prototype = new SolidityType({});
  554. SolidityTypeBool.prototype.constructor = SolidityTypeBool;
  555. SolidityTypeBool.prototype.isType = function (name) {
  556. return !!name.match(/^bool(\[([0-9]*)\])*$/);
  557. };
  558. module.exports = SolidityTypeBool;
  559. },{"./formatters":9,"./type":14}],6:[function(require,module,exports){
  560. var f = require('./formatters');
  561. var SolidityType = require('./type');
  562. /**
  563. * SolidityTypeBytes is a prototype that represents the bytes type.
  564. * It matches:
  565. * bytes
  566. * bytes[]
  567. * bytes[4]
  568. * bytes[][]
  569. * bytes[3][]
  570. * bytes[][6][], ...
  571. * bytes32
  572. * bytes8[4]
  573. * bytes[3][]
  574. */
  575. var SolidityTypeBytes = function () {
  576. this._inputFormatter = f.formatInputBytes;
  577. this._outputFormatter = f.formatOutputBytes;
  578. };
  579. SolidityTypeBytes.prototype = new SolidityType({});
  580. SolidityTypeBytes.prototype.constructor = SolidityTypeBytes;
  581. SolidityTypeBytes.prototype.isType = function (name) {
  582. return !!name.match(/^bytes([0-9]{1,})(\[([0-9]*)\])*$/);
  583. };
  584. module.exports = SolidityTypeBytes;
  585. },{"./formatters":9,"./type":14}],7:[function(require,module,exports){
  586. /*
  587. This file is part of web3.js.
  588. web3.js is free software: you can redistribute it and/or modify
  589. it under the terms of the GNU Lesser General Public License as published by
  590. the Free Software Foundation, either version 3 of the License, or
  591. (at your option) any later version.
  592. web3.js is distributed in the hope that it will be useful,
  593. but WITHOUT ANY WARRANTY; without even the implied warranty of
  594. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  595. GNU Lesser General Public License for more details.
  596. You should have received a copy of the GNU Lesser General Public License
  597. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  598. */
  599. /**
  600. * @file coder.js
  601. * @author Marek Kotewicz <marek@ethdev.com>
  602. * @date 2015
  603. */
  604. var f = require('./formatters');
  605. var SolidityTypeAddress = require('./address');
  606. var SolidityTypeBool = require('./bool');
  607. var SolidityTypeInt = require('./int');
  608. var SolidityTypeUInt = require('./uint');
  609. var SolidityTypeDynamicBytes = require('./dynamicbytes');
  610. var SolidityTypeString = require('./string');
  611. var SolidityTypeReal = require('./real');
  612. var SolidityTypeUReal = require('./ureal');
  613. var SolidityTypeBytes = require('./bytes');
  614. var isDynamic = function (solidityType, type) {
  615. return solidityType.isDynamicType(type) ||
  616. solidityType.isDynamicArray(type);
  617. };
  618. /**
  619. * SolidityCoder prototype should be used to encode/decode solidity params of any type
  620. */
  621. var SolidityCoder = function (types) {
  622. this._types = types;
  623. };
  624. /**
  625. * This method should be used to transform type to SolidityType
  626. *
  627. * @method _requireType
  628. * @param {String} type
  629. * @returns {SolidityType}
  630. * @throws {Error} throws if no matching type is found
  631. */
  632. SolidityCoder.prototype._requireType = function (type) {
  633. var solidityType = this._types.filter(function (t) {
  634. return t.isType(type);
  635. })[0];
  636. if (!solidityType) {
  637. throw Error('invalid solidity type!: ' + type);
  638. }
  639. return solidityType;
  640. };
  641. /**
  642. * Should be used to encode plain param
  643. *
  644. * @method encodeParam
  645. * @param {String} type
  646. * @param {Object} plain param
  647. * @return {String} encoded plain param
  648. */
  649. SolidityCoder.prototype.encodeParam = function (type, param) {
  650. return this.encodeParams([type], [param]);
  651. };
  652. /**
  653. * Should be used to encode list of params
  654. *
  655. * @method encodeParams
  656. * @param {Array} types
  657. * @param {Array} params
  658. * @return {String} encoded list of params
  659. */
  660. SolidityCoder.prototype.encodeParams = function (types, params) {
  661. var solidityTypes = this.getSolidityTypes(types);
  662. var encodeds = solidityTypes.map(function (solidityType, index) {
  663. return solidityType.encode(params[index], types[index]);
  664. });
  665. var dynamicOffset = solidityTypes.reduce(function (acc, solidityType, index) {
  666. var staticPartLength = solidityType.staticPartLength(types[index]);
  667. var roundedStaticPartLength = Math.floor((staticPartLength + 31) / 32) * 32;
  668. return acc + (isDynamic(solidityTypes[index], types[index]) ?
  669. 32 :
  670. roundedStaticPartLength);
  671. }, 0);
  672. var result = this.encodeMultiWithOffset(types, solidityTypes, encodeds, dynamicOffset);
  673. return result;
  674. };
  675. SolidityCoder.prototype.encodeMultiWithOffset = function (types, solidityTypes, encodeds, dynamicOffset) {
  676. var result = "";
  677. var self = this;
  678. types.forEach(function (type, i) {
  679. if (isDynamic(solidityTypes[i], types[i])) {
  680. result += f.formatInputInt(dynamicOffset).encode();
  681. var e = self.encodeWithOffset(types[i], solidityTypes[i], encodeds[i], dynamicOffset);
  682. dynamicOffset += e.length / 2;
  683. } else {
  684. // don't add length to dynamicOffset. it's already counted
  685. result += self.encodeWithOffset(types[i], solidityTypes[i], encodeds[i], dynamicOffset);
  686. }
  687. // TODO: figure out nested arrays
  688. });
  689. types.forEach(function (type, i) {
  690. if (isDynamic(solidityTypes[i], types[i])) {
  691. var e = self.encodeWithOffset(types[i], solidityTypes[i], encodeds[i], dynamicOffset);
  692. dynamicOffset += e.length / 2;
  693. result += e;
  694. }
  695. });
  696. return result;
  697. };
  698. // TODO: refactor whole encoding!
  699. SolidityCoder.prototype.encodeWithOffset = function (type, solidityType, encoded, offset) {
  700. var self = this;
  701. if (solidityType.isDynamicArray(type)) {
  702. return (function () {
  703. // offset was already set
  704. var nestedName = solidityType.nestedName(type);
  705. var nestedStaticPartLength = solidityType.staticPartLength(nestedName);
  706. var result = encoded[0];
  707. (function () {
  708. var previousLength = 2; // in int
  709. if (solidityType.isDynamicArray(nestedName)) {
  710. for (var i = 1; i < encoded.length; i++) {
  711. previousLength += +(encoded[i - 1])[0] || 0;
  712. result += f.formatInputInt(offset + i * nestedStaticPartLength + previousLength * 32).encode();
  713. }
  714. }
  715. })();
  716. // first element is length, skip it
  717. (function () {
  718. for (var i = 0; i < encoded.length - 1; i++) {
  719. var additionalOffset = result / 2;
  720. result += self.encodeWithOffset(nestedName, solidityType, encoded[i + 1], offset + additionalOffset);
  721. }
  722. })();
  723. return result;
  724. })();
  725. } else if (solidityType.isStaticArray(type)) {
  726. return (function () {
  727. var nestedName = solidityType.nestedName(type);
  728. var nestedStaticPartLength = solidityType.staticPartLength(nestedName);
  729. var result = "";
  730. if (solidityType.isDynamicArray(nestedName)) {
  731. (function () {
  732. var previousLength = 0; // in int
  733. for (var i = 0; i < encoded.length; i++) {
  734. // calculate length of previous item
  735. previousLength += +(encoded[i - 1] || [])[0] || 0;
  736. result += f.formatInputInt(offset + i * nestedStaticPartLength + previousLength * 32).encode();
  737. }
  738. })();
  739. }
  740. (function () {
  741. for (var i = 0; i < encoded.length; i++) {
  742. var additionalOffset = result / 2;
  743. result += self.encodeWithOffset(nestedName, solidityType, encoded[i], offset + additionalOffset);
  744. }
  745. })();
  746. return result;
  747. })();
  748. }
  749. return encoded;
  750. };
  751. /**
  752. * Should be used to decode bytes to plain param
  753. *
  754. * @method decodeParam
  755. * @param {String} type
  756. * @param {String} bytes
  757. * @return {Object} plain param
  758. */
  759. SolidityCoder.prototype.decodeParam = function (type, bytes) {
  760. return this.decodeParams([type], bytes)[0];
  761. };
  762. /**
  763. * Should be used to decode list of params
  764. *
  765. * @method decodeParam
  766. * @param {Array} types
  767. * @param {String} bytes
  768. * @return {Array} array of plain params
  769. */
  770. SolidityCoder.prototype.decodeParams = function (types, bytes) {
  771. var solidityTypes = this.getSolidityTypes(types);
  772. var offsets = this.getOffsets(types, solidityTypes);
  773. return solidityTypes.map(function (solidityType, index) {
  774. return solidityType.decode(bytes, offsets[index], types[index], index);
  775. });
  776. };
  777. SolidityCoder.prototype.getOffsets = function (types, solidityTypes) {
  778. var lengths = solidityTypes.map(function (solidityType, index) {
  779. return solidityType.staticPartLength(types[index]);
  780. });
  781. for (var i = 1; i < lengths.length; i++) {
  782. // sum with length of previous element
  783. lengths[i] += lengths[i - 1];
  784. }
  785. return lengths.map(function (length, index) {
  786. // remove the current length, so the length is sum of previous elements
  787. var staticPartLength = solidityTypes[index].staticPartLength(types[index]);
  788. return length - staticPartLength;
  789. });
  790. };
  791. SolidityCoder.prototype.getSolidityTypes = function (types) {
  792. var self = this;
  793. return types.map(function (type) {
  794. return self._requireType(type);
  795. });
  796. };
  797. var coder = new SolidityCoder([
  798. new SolidityTypeAddress(),
  799. new SolidityTypeBool(),
  800. new SolidityTypeInt(),
  801. new SolidityTypeUInt(),
  802. new SolidityTypeDynamicBytes(),
  803. new SolidityTypeBytes(),
  804. new SolidityTypeString(),
  805. new SolidityTypeReal(),
  806. new SolidityTypeUReal()
  807. ]);
  808. module.exports = coder;
  809. },{"./address":4,"./bool":5,"./bytes":6,"./dynamicbytes":8,"./formatters":9,"./int":10,"./real":12,"./string":13,"./uint":15,"./ureal":16}],8:[function(require,module,exports){
  810. var f = require('./formatters');
  811. var SolidityType = require('./type');
  812. var SolidityTypeDynamicBytes = function () {
  813. this._inputFormatter = f.formatInputDynamicBytes;
  814. this._outputFormatter = f.formatOutputDynamicBytes;
  815. };
  816. SolidityTypeDynamicBytes.prototype = new SolidityType({});
  817. SolidityTypeDynamicBytes.prototype.constructor = SolidityTypeDynamicBytes;
  818. SolidityTypeDynamicBytes.prototype.isType = function (name) {
  819. return !!name.match(/^bytes(\[([0-9]*)\])*$/);
  820. };
  821. SolidityTypeDynamicBytes.prototype.isDynamicType = function () {
  822. return true;
  823. };
  824. module.exports = SolidityTypeDynamicBytes;
  825. },{"./formatters":9,"./type":14}],9:[function(require,module,exports){
  826. /*
  827. This file is part of web3.js.
  828. web3.js is free software: you can redistribute it and/or modify
  829. it under the terms of the GNU Lesser General Public License as published by
  830. the Free Software Foundation, either version 3 of the License, or
  831. (at your option) any later version.
  832. web3.js is distributed in the hope that it will be useful,
  833. but WITHOUT ANY WARRANTY; without even the implied warranty of
  834. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  835. GNU Lesser General Public License for more details.
  836. You should have received a copy of the GNU Lesser General Public License
  837. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  838. */
  839. /**
  840. * @file formatters.js
  841. * @author Marek Kotewicz <marek@ethdev.com>
  842. * @date 2015
  843. */
  844. var BigNumber = require('bignumber.js');
  845. var utils = require('../utils/utils');
  846. var c = require('../utils/config');
  847. var SolidityParam = require('./param');
  848. /**
  849. * Formats input value to byte representation of int
  850. * If value is negative, return it's two's complement
  851. * If the value is floating point, round it down
  852. *
  853. * @method formatInputInt
  854. * @param {String|Number|BigNumber} value that needs to be formatted
  855. * @returns {SolidityParam}
  856. */
  857. var formatInputInt = function (value) {
  858. BigNumber.config(c.ETH_BIGNUMBER_ROUNDING_MODE);
  859. var result = utils.padLeft(utils.toTwosComplement(value).toString(16), 64);
  860. return new SolidityParam(result);
  861. };
  862. /**
  863. * Formats input bytes
  864. *
  865. * @method formatInputBytes
  866. * @param {String}
  867. * @returns {SolidityParam}
  868. */
  869. var formatInputBytes = function (value) {
  870. var result = utils.toHex(value).substr(2);
  871. var l = Math.floor((result.length + 63) / 64);
  872. result = utils.padRight(result, l * 64);
  873. return new SolidityParam(result);
  874. };
  875. /**
  876. * Formats input bytes
  877. *
  878. * @method formatDynamicInputBytes
  879. * @param {String}
  880. * @returns {SolidityParam}
  881. */
  882. var formatInputDynamicBytes = function (value) {
  883. var result = utils.toHex(value).substr(2);
  884. var length = result.length / 2;
  885. var l = Math.floor((result.length + 63) / 64);
  886. result = utils.padRight(result, l * 64);
  887. return new SolidityParam(formatInputInt(length).value + result);
  888. };
  889. /**
  890. * Formats input value to byte representation of string
  891. *
  892. * @method formatInputString
  893. * @param {String}
  894. * @returns {SolidityParam}
  895. */
  896. var formatInputString = function (value) {
  897. var result = utils.fromUtf8(value).substr(2);
  898. var length = result.length / 2;
  899. var l = Math.floor((result.length + 63) / 64);
  900. result = utils.padRight(result, l * 64);
  901. return new SolidityParam(formatInputInt(length).value + result);
  902. };
  903. /**
  904. * Formats input value to byte representation of bool
  905. *
  906. * @method formatInputBool
  907. * @param {Boolean}
  908. * @returns {SolidityParam}
  909. */
  910. var formatInputBool = function (value) {
  911. var result = '000000000000000000000000000000000000000000000000000000000000000' + (value ? '1' : '0');
  912. return new SolidityParam(result);
  913. };
  914. /**
  915. * Formats input value to byte representation of real
  916. * Values are multiplied by 2^m and encoded as integers
  917. *
  918. * @method formatInputReal
  919. * @param {String|Number|BigNumber}
  920. * @returns {SolidityParam}
  921. */
  922. var formatInputReal = function (value) {
  923. return formatInputInt(new BigNumber(value).times(new BigNumber(2).pow(128)));
  924. };
  925. /**
  926. * Check if input value is negative
  927. *
  928. * @method signedIsNegative
  929. * @param {String} value is hex format
  930. * @returns {Boolean} true if it is negative, otherwise false
  931. */
  932. var signedIsNegative = function (value) {
  933. return (new BigNumber(value.substr(0, 1), 16).toString(2).substr(0, 1)) === '1';
  934. };
  935. /**
  936. * Formats right-aligned output bytes to int
  937. *
  938. * @method formatOutputInt
  939. * @param {SolidityParam} param
  940. * @returns {BigNumber} right-aligned output bytes formatted to big number
  941. */
  942. var formatOutputInt = function (param) {
  943. var value = param.staticPart() || "0";
  944. // check if it's negative number
  945. // it is, return two's complement
  946. if (signedIsNegative(value)) {
  947. return new BigNumber(value, 16).minus(new BigNumber('ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', 16)).minus(1);
  948. }
  949. return new BigNumber(value, 16);
  950. };
  951. /**
  952. * Formats right-aligned output bytes to uint
  953. *
  954. * @method formatOutputUInt
  955. * @param {SolidityParam}
  956. * @returns {BigNumeber} right-aligned output bytes formatted to uint
  957. */
  958. var formatOutputUInt = function (param) {
  959. var value = param.staticPart() || "0";
  960. return new BigNumber(value, 16);
  961. };
  962. /**
  963. * Formats right-aligned output bytes to real
  964. *
  965. * @method formatOutputReal
  966. * @param {SolidityParam}
  967. * @returns {BigNumber} input bytes formatted to real
  968. */
  969. var formatOutputReal = function (param) {
  970. return formatOutputInt(param).dividedBy(new BigNumber(2).pow(128));
  971. };
  972. /**
  973. * Formats right-aligned output bytes to ureal
  974. *
  975. * @method formatOutputUReal
  976. * @param {SolidityParam}
  977. * @returns {BigNumber} input bytes formatted to ureal
  978. */
  979. var formatOutputUReal = function (param) {
  980. return formatOutputUInt(param).dividedBy(new BigNumber(2).pow(128));
  981. };
  982. /**
  983. * Should be used to format output bool
  984. *
  985. * @method formatOutputBool
  986. * @param {SolidityParam}
  987. * @returns {Boolean} right-aligned input bytes formatted to bool
  988. */
  989. var formatOutputBool = function (param) {
  990. return param.staticPart() === '0000000000000000000000000000000000000000000000000000000000000001' ? true : false;
  991. };
  992. /**
  993. * Should be used to format output bytes
  994. *
  995. * @method formatOutputBytes
  996. * @param {SolidityParam} left-aligned hex representation of string
  997. * @param {String} name type name
  998. * @returns {String} hex string
  999. */
  1000. var formatOutputBytes = function (param, name) {
  1001. var matches = name.match(/^bytes([0-9]*)/);
  1002. var size = parseInt(matches[1]);
  1003. return '0x' + param.staticPart().slice(0, 2 * size);
  1004. };
  1005. /**
  1006. * Should be used to format output bytes
  1007. *
  1008. * @method formatOutputDynamicBytes
  1009. * @param {SolidityParam} left-aligned hex representation of string
  1010. * @returns {String} hex string
  1011. */
  1012. var formatOutputDynamicBytes = function (param) {
  1013. var length = (new BigNumber(param.dynamicPart().slice(0, 64), 16)).toNumber() * 2;
  1014. return '0x' + param.dynamicPart().substr(64, length);
  1015. };
  1016. /**
  1017. * Should be used to format output string
  1018. *
  1019. * @method formatOutputString
  1020. * @param {SolidityParam} left-aligned hex representation of string
  1021. * @returns {String} ascii string
  1022. */
  1023. var formatOutputString = function (param) {
  1024. var length = (new BigNumber(param.dynamicPart().slice(0, 64), 16)).toNumber() * 2;
  1025. return utils.toUtf8(param.dynamicPart().substr(64, length));
  1026. };
  1027. /**
  1028. * Should be used to format output address
  1029. *
  1030. * @method formatOutputAddress
  1031. * @param {SolidityParam} right-aligned input bytes
  1032. * @returns {String} address
  1033. */
  1034. var formatOutputAddress = function (param) {
  1035. var value = param.staticPart();
  1036. return "0x" + value.slice(value.length - 40, value.length);
  1037. };
  1038. module.exports = {
  1039. formatInputInt: formatInputInt,
  1040. formatInputBytes: formatInputBytes,
  1041. formatInputDynamicBytes: formatInputDynamicBytes,
  1042. formatInputString: formatInputString,
  1043. formatInputBool: formatInputBool,
  1044. formatInputReal: formatInputReal,
  1045. formatOutputInt: formatOutputInt,
  1046. formatOutputUInt: formatOutputUInt,
  1047. formatOutputReal: formatOutputReal,
  1048. formatOutputUReal: formatOutputUReal,
  1049. formatOutputBool: formatOutputBool,
  1050. formatOutputBytes: formatOutputBytes,
  1051. formatOutputDynamicBytes: formatOutputDynamicBytes,
  1052. formatOutputString: formatOutputString,
  1053. formatOutputAddress: formatOutputAddress
  1054. };
  1055. },{"../utils/config":18,"../utils/utils":20,"./param":11,"bignumber.js":"bignumber.js"}],10:[function(require,module,exports){
  1056. var f = require('./formatters');
  1057. var SolidityType = require('./type');
  1058. /**
  1059. * SolidityTypeInt is a prootype that represents int type
  1060. * It matches:
  1061. * int
  1062. * int[]
  1063. * int[4]
  1064. * int[][]
  1065. * int[3][]
  1066. * int[][6][], ...
  1067. * int32
  1068. * int64[]
  1069. * int8[4]
  1070. * int256[][]
  1071. * int[3][]
  1072. * int64[][6][], ...
  1073. */
  1074. var SolidityTypeInt = function () {
  1075. this._inputFormatter = f.formatInputInt;
  1076. this._outputFormatter = f.formatOutputInt;
  1077. };
  1078. SolidityTypeInt.prototype = new SolidityType({});
  1079. SolidityTypeInt.prototype.constructor = SolidityTypeInt;
  1080. SolidityTypeInt.prototype.isType = function (name) {
  1081. return !!name.match(/^int([0-9]*)?(\[([0-9]*)\])*$/);
  1082. };
  1083. module.exports = SolidityTypeInt;
  1084. },{"./formatters":9,"./type":14}],11:[function(require,module,exports){
  1085. /*
  1086. This file is part of web3.js.
  1087. web3.js is free software: you can redistribute it and/or modify
  1088. it under the terms of the GNU Lesser General Public License as published by
  1089. the Free Software Foundation, either version 3 of the License, or
  1090. (at your option) any later version.
  1091. web3.js is distributed in the hope that it will be useful,
  1092. but WITHOUT ANY WARRANTY; without even the implied warranty of
  1093. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  1094. GNU Lesser General Public License for more details.
  1095. You should have received a copy of the GNU Lesser General Public License
  1096. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  1097. */
  1098. /**
  1099. * @file param.js
  1100. * @author Marek Kotewicz <marek@ethdev.com>
  1101. * @date 2015
  1102. */
  1103. var utils = require('../utils/utils');
  1104. /**
  1105. * SolidityParam object prototype.
  1106. * Should be used when encoding, decoding solidity bytes
  1107. */
  1108. var SolidityParam = function (value, offset) {
  1109. this.value = value || '';
  1110. this.offset = offset; // offset in bytes
  1111. };
  1112. /**
  1113. * This method should be used to get length of params's dynamic part
  1114. *
  1115. * @method dynamicPartLength
  1116. * @returns {Number} length of dynamic part (in bytes)
  1117. */
  1118. SolidityParam.prototype.dynamicPartLength = function () {
  1119. return this.dynamicPart().length / 2;
  1120. };
  1121. /**
  1122. * This method should be used to create copy of solidity param with different offset
  1123. *
  1124. * @method withOffset
  1125. * @param {Number} offset length in bytes
  1126. * @returns {SolidityParam} new solidity param with applied offset
  1127. */
  1128. SolidityParam.prototype.withOffset = function (offset) {
  1129. return new SolidityParam(this.value, offset);
  1130. };
  1131. /**
  1132. * This method should be used to combine solidity params together
  1133. * eg. when appending an array
  1134. *
  1135. * @method combine
  1136. * @param {SolidityParam} param with which we should combine
  1137. * @param {SolidityParam} result of combination
  1138. */
  1139. SolidityParam.prototype.combine = function (param) {
  1140. return new SolidityParam(this.value + param.value);
  1141. };
  1142. /**
  1143. * This method should be called to check if param has dynamic size.
  1144. * If it has, it returns true, otherwise false
  1145. *
  1146. * @method isDynamic
  1147. * @returns {Boolean}
  1148. */
  1149. SolidityParam.prototype.isDynamic = function () {
  1150. return this.offset !== undefined;
  1151. };
  1152. /**
  1153. * This method should be called to transform offset to bytes
  1154. *
  1155. * @method offsetAsBytes
  1156. * @returns {String} bytes representation of offset
  1157. */
  1158. SolidityParam.prototype.offsetAsBytes = function () {
  1159. return !this.isDynamic() ? '' : utils.padLeft(utils.toTwosComplement(this.offset).toString(16), 64);
  1160. };
  1161. /**
  1162. * This method should be called to get static part of param
  1163. *
  1164. * @method staticPart
  1165. * @returns {String} offset if it is a dynamic param, otherwise value
  1166. */
  1167. SolidityParam.prototype.staticPart = function () {
  1168. if (!this.isDynamic()) {
  1169. return this.value;
  1170. }
  1171. return this.offsetAsBytes();
  1172. };
  1173. /**
  1174. * This method should be called to get dynamic part of param
  1175. *
  1176. * @method dynamicPart
  1177. * @returns {String} returns a value if it is a dynamic param, otherwise empty string
  1178. */
  1179. SolidityParam.prototype.dynamicPart = function () {
  1180. return this.isDynamic() ? this.value : '';
  1181. };
  1182. /**
  1183. * This method should be called to encode param
  1184. *
  1185. * @method encode
  1186. * @returns {String}
  1187. */
  1188. SolidityParam.prototype.encode = function () {
  1189. return this.staticPart() + this.dynamicPart();
  1190. };
  1191. /**
  1192. * This method should be called to encode array of params
  1193. *
  1194. * @method encodeList
  1195. * @param {Array[SolidityParam]} params
  1196. * @returns {String}
  1197. */
  1198. SolidityParam.encodeList = function (params) {
  1199. // updating offsets
  1200. var totalOffset = params.length * 32;
  1201. var offsetParams = params.map(function (param) {
  1202. if (!param.isDynamic()) {
  1203. return param;
  1204. }
  1205. var offset = totalOffset;
  1206. totalOffset += param.dynamicPartLength();
  1207. return param.withOffset(offset);
  1208. });
  1209. // encode everything!
  1210. return offsetParams.reduce(function (result, param) {
  1211. return result + param.dynamicPart();
  1212. }, offsetParams.reduce(function (result, param) {
  1213. return result + param.staticPart();
  1214. }, ''));
  1215. };
  1216. module.exports = SolidityParam;
  1217. },{"../utils/utils":20}],12:[function(require,module,exports){
  1218. var f = require('./formatters');
  1219. var SolidityType = require('./type');
  1220. /**
  1221. * SolidityTypeReal is a prootype that represents real type
  1222. * It matches:
  1223. * real
  1224. * real[]
  1225. * real[4]
  1226. * real[][]
  1227. * real[3][]
  1228. * real[][6][], ...
  1229. * real32
  1230. * real64[]
  1231. * real8[4]
  1232. * real256[][]
  1233. * real[3][]
  1234. * real64[][6][], ...
  1235. */
  1236. var SolidityTypeReal = function () {
  1237. this._inputFormatter = f.formatInputReal;
  1238. this._outputFormatter = f.formatOutputReal;
  1239. };
  1240. SolidityTypeReal.prototype = new SolidityType({});
  1241. SolidityTypeReal.prototype.constructor = SolidityTypeReal;
  1242. SolidityTypeReal.prototype.isType = function (name) {
  1243. return !!name.match(/real([0-9]*)?(\[([0-9]*)\])?/);
  1244. };
  1245. module.exports = SolidityTypeReal;
  1246. },{"./formatters":9,"./type":14}],13:[function(require,module,exports){
  1247. var f = require('./formatters');
  1248. var SolidityType = require('./type');
  1249. var SolidityTypeString = function () {
  1250. this._inputFormatter = f.formatInputString;
  1251. this._outputFormatter = f.formatOutputString;
  1252. };
  1253. SolidityTypeString.prototype = new SolidityType({});
  1254. SolidityTypeString.prototype.constructor = SolidityTypeString;
  1255. SolidityTypeString.prototype.isType = function (name) {
  1256. return !!name.match(/^string(\[([0-9]*)\])*$/);
  1257. };
  1258. SolidityTypeString.prototype.isDynamicType = function () {
  1259. return true;
  1260. };
  1261. module.exports = SolidityTypeString;
  1262. },{"./formatters":9,"./type":14}],14:[function(require,module,exports){
  1263. var f = require('./formatters');
  1264. var SolidityParam = require('./param');
  1265. /**
  1266. * SolidityType prototype is used to encode/decode solidity params of certain type
  1267. */
  1268. var SolidityType = function (config) {
  1269. this._inputFormatter = config.inputFormatter;
  1270. this._outputFormatter = config.outputFormatter;
  1271. };
  1272. /**
  1273. * Should be used to determine if this SolidityType do match given name
  1274. *
  1275. * @method isType
  1276. * @param {String} name
  1277. * @return {Bool} true if type match this SolidityType, otherwise false
  1278. */
  1279. SolidityType.prototype.isType = function (name) {
  1280. throw "this method should be overrwritten for type " + name;
  1281. };
  1282. /**
  1283. * Should be used to determine what is the length of static part in given type
  1284. *
  1285. * @method staticPartLength
  1286. * @param {String} name
  1287. * @return {Number} length of static part in bytes
  1288. */
  1289. SolidityType.prototype.staticPartLength = function (name) {
  1290. // If name isn't an array then treat it like a single element array.
  1291. return (this.nestedTypes(name) || ['[1]'])
  1292. .map(function (type) {
  1293. // the length of the nested array
  1294. return parseInt(type.slice(1, -1), 10) || 1;
  1295. })
  1296. .reduce(function (previous, current) {
  1297. return previous * current;
  1298. // all basic types are 32 bytes long
  1299. }, 32);
  1300. };
  1301. /**
  1302. * Should be used to determine if type is dynamic array
  1303. * eg:
  1304. * "type[]" => true
  1305. * "type[4]" => false
  1306. *
  1307. * @method isDynamicArray
  1308. * @param {String} name
  1309. * @return {Bool} true if the type is dynamic array
  1310. */
  1311. SolidityType.prototype.isDynamicArray = function (name) {
  1312. var nestedTypes = this.nestedTypes(name);
  1313. return !!nestedTypes && !nestedTypes[nestedTypes.length - 1].match(/[0-9]{1,}/g);
  1314. };
  1315. /**
  1316. * Should be used to determine if type is static array
  1317. * eg:
  1318. * "type[]" => false
  1319. * "type[4]" => true
  1320. *
  1321. * @method isStaticArray
  1322. * @param {String} name
  1323. * @return {Bool} true if the type is static array
  1324. */
  1325. SolidityType.prototype.isStaticArray = function (name) {
  1326. var nestedTypes = this.nestedTypes(name);
  1327. return !!nestedTypes && !!nestedTypes[nestedTypes.length - 1].match(/[0-9]{1,}/g);
  1328. };
  1329. /**
  1330. * Should return length of static array
  1331. * eg.
  1332. * "int[32]" => 32
  1333. * "int256[14]" => 14
  1334. * "int[2][3]" => 3
  1335. * "int" => 1
  1336. * "int[1]" => 1
  1337. * "int[]" => 1
  1338. *
  1339. * @method staticArrayLength
  1340. * @param {String} name
  1341. * @return {Number} static array length
  1342. */
  1343. SolidityType.prototype.staticArrayLength = function (name) {
  1344. var nestedTypes = this.nestedTypes(name);
  1345. if (nestedTypes) {
  1346. return parseInt(nestedTypes[nestedTypes.length - 1].match(/[0-9]{1,}/g) || 1);
  1347. }
  1348. return 1;
  1349. };
  1350. /**
  1351. * Should return nested type
  1352. * eg.
  1353. * "int[32]" => "int"
  1354. * "int256[14]" => "int256"
  1355. * "int[2][3]" => "int[2]"
  1356. * "int" => "int"
  1357. * "int[]" => "int"
  1358. *
  1359. * @method nestedName
  1360. * @param {String} name
  1361. * @return {String} nested name
  1362. */
  1363. SolidityType.prototype.nestedName = function (name) {
  1364. // remove last [] in name
  1365. var nestedTypes = this.nestedTypes(name);
  1366. if (!nestedTypes) {
  1367. return name;
  1368. }
  1369. return name.substr(0, name.length - nestedTypes[nestedTypes.length - 1].length);
  1370. };
  1371. /**
  1372. * Should return true if type has dynamic size by default
  1373. * such types are "string", "bytes"
  1374. *
  1375. * @method isDynamicType
  1376. * @param {String} name
  1377. * @return {Bool} true if is dynamic, otherwise false
  1378. */
  1379. SolidityType.prototype.isDynamicType = function () {
  1380. return false;
  1381. };
  1382. /**
  1383. * Should return array of nested types
  1384. * eg.
  1385. * "int[2][3][]" => ["[2]", "[3]", "[]"]
  1386. * "int[] => ["[]"]
  1387. * "int" => null
  1388. *
  1389. * @method nestedTypes
  1390. * @param {String} name
  1391. * @return {Array} array of nested types
  1392. */
  1393. SolidityType.prototype.nestedTypes = function (name) {
  1394. // return list of strings eg. "[]", "[3]", "[]", "[2]"
  1395. return name.match(/(\[[0-9]*\])/g);
  1396. };
  1397. /**
  1398. * Should be used to encode the value
  1399. *
  1400. * @method encode
  1401. * @param {Object} value
  1402. * @param {String} name
  1403. * @return {String} encoded value
  1404. */
  1405. SolidityType.prototype.encode = function (value, name) {
  1406. var self = this;
  1407. if (this.isDynamicArray(name)) {
  1408. return (function () {
  1409. var length = value.length; // in int
  1410. var nestedName = self.nestedName(name);
  1411. var result = [];
  1412. result.push(f.formatInputInt(length).encode());
  1413. value.forEach(function (v) {
  1414. result.push(self.encode(v, nestedName));
  1415. });
  1416. return result;
  1417. })();
  1418. } else if (this.isStaticArray(name)) {
  1419. return (function () {
  1420. var length = self.staticArrayLength(name); // in int
  1421. var nestedName = self.nestedName(name);
  1422. var result = [];
  1423. for (var i = 0; i < length; i++) {
  1424. result.push(self.encode(value[i], nestedName));
  1425. }
  1426. return result;
  1427. })();
  1428. }
  1429. return this._inputFormatter(value, name).encode();
  1430. };
  1431. /**
  1432. * Should be used to decode value from bytes
  1433. *
  1434. * @method decode
  1435. * @param {String} bytes
  1436. * @param {Number} offset in bytes
  1437. * @param {String} name type name
  1438. * @returns {Object} decoded value
  1439. */
  1440. SolidityType.prototype.decode = function (bytes, offset, name) {
  1441. var self = this;
  1442. if (this.isDynamicArray(name)) {
  1443. return (function () {
  1444. var arrayOffset = parseInt('0x' + bytes.substr(offset * 2, 64)); // in bytes
  1445. var length = parseInt('0x' + bytes.substr(arrayOffset * 2, 64)); // in int
  1446. var arrayStart = arrayOffset + 32; // array starts after length; // in bytes
  1447. var nestedName = self.nestedName(name);
  1448. var nestedStaticPartLength = self.staticPartLength(nestedName); // in bytes
  1449. var roundedNestedStaticPartLength = Math.floor((nestedStaticPartLength + 31) / 32) * 32;
  1450. var result = [];
  1451. for (var i = 0; i < length * roundedNestedStaticPartLength; i += roundedNestedStaticPartLength) {
  1452. result.push(self.decode(bytes, arrayStart + i, nestedName));
  1453. }
  1454. return result;
  1455. })();
  1456. } else if (this.isStaticArray(name)) {
  1457. return (function () {
  1458. var length = self.staticArrayLength(name); // in int
  1459. var arrayStart = offset; // in bytes
  1460. var nestedName = self.nestedName(name);
  1461. var nestedStaticPartLength = self.staticPartLength(nestedName); // in bytes
  1462. var roundedNestedStaticPartLength = Math.floor((nestedStaticPartLength + 31) / 32) * 32;
  1463. var result = [];
  1464. for (var i = 0; i < length * roundedNestedStaticPartLength; i += roundedNestedStaticPartLength) {
  1465. result.push(self.decode(bytes, arrayStart + i, nestedName));
  1466. }
  1467. return result;
  1468. })();
  1469. } else if (this.isDynamicType(name)) {
  1470. return (function () {
  1471. var dynamicOffset = parseInt('0x' + bytes.substr(offset * 2, 64)); // in bytes
  1472. var length = parseInt('0x' + bytes.substr(dynamicOffset * 2, 64)); // in bytes
  1473. var roundedLength = Math.floor((length + 31) / 32); // in int
  1474. var param = new SolidityParam(bytes.substr(dynamicOffset * 2, ( 1 + roundedLength) * 64), 0);
  1475. return self._outputFormatter(param, name);
  1476. })();
  1477. }
  1478. var length = this.staticPartLength(name);
  1479. var param = new SolidityParam(bytes.substr(offset * 2, length * 2));
  1480. return this._outputFormatter(param, name);
  1481. };
  1482. module.exports = SolidityType;
  1483. },{"./formatters":9,"./param":11}],15:[function(require,module,exports){
  1484. var f = require('./formatters');
  1485. var SolidityType = require('./type');
  1486. /**
  1487. * SolidityTypeUInt is a prootype that represents uint type
  1488. * It matches:
  1489. * uint
  1490. * uint[]
  1491. * uint[4]
  1492. * uint[][]
  1493. * uint[3][]
  1494. * uint[][6][], ...
  1495. * uint32
  1496. * uint64[]
  1497. * uint8[4]
  1498. * uint256[][]
  1499. * uint[3][]
  1500. * uint64[][6][], ...
  1501. */
  1502. var SolidityTypeUInt = function () {
  1503. this._inputFormatter = f.formatInputInt;
  1504. this._outputFormatter = f.formatOutputUInt;
  1505. };
  1506. SolidityTypeUInt.prototype = new SolidityType({});
  1507. SolidityTypeUInt.prototype.constructor = SolidityTypeUInt;
  1508. SolidityTypeUInt.prototype.isType = function (name) {
  1509. return !!name.match(/^uint([0-9]*)?(\[([0-9]*)\])*$/);
  1510. };
  1511. module.exports = SolidityTypeUInt;
  1512. },{"./formatters":9,"./type":14}],16:[function(require,module,exports){
  1513. var f = require('./formatters');
  1514. var SolidityType = require('./type');
  1515. /**
  1516. * SolidityTypeUReal is a prootype that represents ureal type
  1517. * It matches:
  1518. * ureal
  1519. * ureal[]
  1520. * ureal[4]
  1521. * ureal[][]
  1522. * ureal[3][]
  1523. * ureal[][6][], ...
  1524. * ureal32
  1525. * ureal64[]
  1526. * ureal8[4]
  1527. * ureal256[][]
  1528. * ureal[3][]
  1529. * ureal64[][6][], ...
  1530. */
  1531. var SolidityTypeUReal = function () {
  1532. this._inputFormatter = f.formatInputReal;
  1533. this._outputFormatter = f.formatOutputUReal;
  1534. };
  1535. SolidityTypeUReal.prototype = new SolidityType({});
  1536. SolidityTypeUReal.prototype.constructor = SolidityTypeUReal;
  1537. SolidityTypeUReal.prototype.isType = function (name) {
  1538. return !!name.match(/^ureal([0-9]*)?(\[([0-9]*)\])*$/);
  1539. };
  1540. module.exports = SolidityTypeUReal;
  1541. },{"./formatters":9,"./type":14}],17:[function(require,module,exports){
  1542. 'use strict';
  1543. // go env doesn't have and need XMLHttpRequest
  1544. if (typeof XMLHttpRequest === 'undefined') {
  1545. exports.XMLHttpRequest = {};
  1546. } else {
  1547. exports.XMLHttpRequest = XMLHttpRequest; // jshint ignore:line
  1548. }
  1549. },{}],18:[function(require,module,exports){
  1550. /*
  1551. This file is part of web3.js.
  1552. web3.js is free software: you can redistribute it and/or modify
  1553. it under the terms of the GNU Lesser General Public License as published by
  1554. the Free Software Foundation, either version 3 of the License, or
  1555. (at your option) any later version.
  1556. web3.js is distributed in the hope that it will be useful,
  1557. but WITHOUT ANY WARRANTY; without even the implied warranty of
  1558. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  1559. GNU Lesser General Public License for more details.
  1560. You should have received a copy of the GNU Lesser General Public License
  1561. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  1562. */
  1563. /** @file config.js
  1564. * @authors:
  1565. * Marek Kotewicz <marek@ethdev.com>
  1566. * @date 2015
  1567. */
  1568. /**
  1569. * Utils
  1570. *
  1571. * @module utils
  1572. */
  1573. /**
  1574. * Utility functions
  1575. *
  1576. * @class [utils] config
  1577. * @constructor
  1578. */
  1579. /// required to define ETH_BIGNUMBER_ROUNDING_MODE
  1580. var BigNumber = require('bignumber.js');
  1581. var ETH_UNITS = [
  1582. 'wei',
  1583. 'kwei',
  1584. 'Mwei',
  1585. 'Gwei',
  1586. 'szabo',
  1587. 'finney',
  1588. 'femtoether',
  1589. 'picoether',
  1590. 'nanoether',
  1591. 'microether',
  1592. 'milliether',
  1593. 'nano',
  1594. 'micro',
  1595. 'milli',
  1596. 'ether',
  1597. 'grand',
  1598. 'Mether',
  1599. 'Gether',
  1600. 'Tether',
  1601. 'Pether',
  1602. 'Eether',
  1603. 'Zether',
  1604. 'Yether',
  1605. 'Nether',
  1606. 'Dether',
  1607. 'Vether',
  1608. 'Uether'
  1609. ];
  1610. module.exports = {
  1611. ETH_PADDING: 32,
  1612. ETH_SIGNATURE_LENGTH: 4,
  1613. ETH_UNITS: ETH_UNITS,
  1614. ETH_BIGNUMBER_ROUNDING_MODE: { ROUNDING_MODE: BigNumber.ROUND_DOWN },
  1615. ETH_POLLING_TIMEOUT: 1000/2,
  1616. defaultBlock: 'latest',
  1617. defaultAccount: undefined
  1618. };
  1619. },{"bignumber.js":"bignumber.js"}],19:[function(require,module,exports){
  1620. /*
  1621. This file is part of web3.js.
  1622. web3.js is free software: you can redistribute it and/or modify
  1623. it under the terms of the GNU Lesser General Public License as published by
  1624. the Free Software Foundation, either version 3 of the License, or
  1625. (at your option) any later version.
  1626. web3.js is distributed in the hope that it will be useful,
  1627. but WITHOUT ANY WARRANTY; without even the implied warranty of
  1628. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  1629. GNU Lesser General Public License for more details.
  1630. You should have received a copy of the GNU Lesser General Public License
  1631. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  1632. */
  1633. /**
  1634. * @file sha3.js
  1635. * @author Marek Kotewicz <marek@ethdev.com>
  1636. * @date 2015
  1637. */
  1638. var CryptoJS = require('crypto-js');
  1639. var sha3 = require('crypto-js/sha3');
  1640. module.exports = function (value, options) {
  1641. if (options && options.encoding === 'hex') {
  1642. if (value.length > 2 && value.substr(0, 2) === '0x') {
  1643. value = value.substr(2);
  1644. }
  1645. value = CryptoJS.enc.Hex.parse(value);
  1646. }
  1647. return sha3(value, {
  1648. outputLength: 256
  1649. }).toString();
  1650. };
  1651. },{"crypto-js":59,"crypto-js/sha3":80}],20:[function(require,module,exports){
  1652. /*
  1653. This file is part of web3.js.
  1654. web3.js is free software: you can redistribute it and/or modify
  1655. it under the terms of the GNU Lesser General Public License as published by
  1656. the Free Software Foundation, either version 3 of the License, or
  1657. (at your option) any later version.
  1658. web3.js is distributed in the hope that it will be useful,
  1659. but WITHOUT ANY WARRANTY; without even the implied warranty of
  1660. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  1661. GNU Lesser General Public License for more details.
  1662. You should have received a copy of the GNU Lesser General Public License
  1663. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  1664. */
  1665. /**
  1666. * @file utils.js
  1667. * @author Marek Kotewicz <marek@ethdev.com>
  1668. * @date 2015
  1669. */
  1670. /**
  1671. * Utils
  1672. *
  1673. * @module utils
  1674. */
  1675. /**
  1676. * Utility functions
  1677. *
  1678. * @class [utils] utils
  1679. * @constructor
  1680. */
  1681. var BigNumber = require('bignumber.js');
  1682. var sha3 = require('./sha3.js');
  1683. var utf8 = require('utf8');
  1684. var unitMap = {
  1685. 'noether': '0',
  1686. 'wei': '1',
  1687. 'kwei': '1000',
  1688. 'Kwei': '1000',
  1689. 'babbage': '1000',
  1690. 'femtoether': '1000',
  1691. 'mwei': '1000000',
  1692. 'Mwei': '1000000',
  1693. 'lovelace': '1000000',
  1694. 'picoether': '1000000',
  1695. 'gwei': '1000000000',
  1696. 'Gwei': '1000000000',
  1697. 'shannon': '1000000000',
  1698. 'nanoether': '1000000000',
  1699. 'nano': '1000000000',
  1700. 'szabo': '1000000000000',
  1701. 'microether': '1000000000000',
  1702. 'micro': '1000000000000',
  1703. 'finney': '1000000000000000',
  1704. 'milliether': '1000000000000000',
  1705. 'milli': '1000000000000000',
  1706. 'ether': '1000000000000000000',
  1707. 'kether': '1000000000000000000000',
  1708. 'grand': '1000000000000000000000',
  1709. 'mether': '1000000000000000000000000',
  1710. 'gether': '1000000000000000000000000000',
  1711. 'tether': '1000000000000000000000000000000'
  1712. };
  1713. /**
  1714. * Should be called to pad string to expected length
  1715. *
  1716. * @method padLeft
  1717. * @param {String} string to be padded
  1718. * @param {Number} characters that result string should have
  1719. * @param {String} sign, by default 0
  1720. * @returns {String} right aligned string
  1721. */
  1722. var padLeft = function (string, chars, sign) {
  1723. return new Array(chars - string.length + 1).join(sign ? sign : "0") + string;
  1724. };
  1725. /**
  1726. * Should be called to pad string to expected length
  1727. *
  1728. * @method padRight
  1729. * @param {String} string to be padded
  1730. * @param {Number} characters that result string should have
  1731. * @param {String} sign, by default 0
  1732. * @returns {String} right aligned string
  1733. */
  1734. var padRight = function (string, chars, sign) {
  1735. return string + (new Array(chars - string.length + 1).join(sign ? sign : "0"));
  1736. };
  1737. /**
  1738. * Should be called to get utf8 from it's hex representation
  1739. *
  1740. * @method toUtf8
  1741. * @param {String} string in hex
  1742. * @returns {String} ascii string representation of hex value
  1743. */
  1744. var toUtf8 = function(hex) {
  1745. // Find termination
  1746. var str = "";
  1747. var i = 0, l = hex.length;
  1748. if (hex.substring(0, 2) === '0x') {
  1749. i = 2;
  1750. }
  1751. for (; i < l; i+=2) {
  1752. var code = parseInt(hex.substr(i, 2), 16);
  1753. if (code === 0)
  1754. break;
  1755. str += String.fromCharCode(code);
  1756. }
  1757. return utf8.decode(str);
  1758. };
  1759. /**
  1760. * Should be called to get ascii from it's hex representation
  1761. *
  1762. * @method toAscii
  1763. * @param {String} string in hex
  1764. * @returns {String} ascii string representation of hex value
  1765. */
  1766. var toAscii = function(hex) {
  1767. // Find termination
  1768. var str = "";
  1769. var i = 0, l = hex.length;
  1770. if (hex.substring(0, 2) === '0x') {
  1771. i = 2;
  1772. }
  1773. for (; i < l; i+=2) {
  1774. var code = parseInt(hex.substr(i, 2), 16);
  1775. str += String.fromCharCode(code);
  1776. }
  1777. return str;
  1778. };
  1779. /**
  1780. * Should be called to get hex representation (prefixed by 0x) of utf8 string
  1781. *
  1782. * @method fromUtf8
  1783. * @param {String} string
  1784. * @param {Number} optional padding
  1785. * @returns {String} hex representation of input string
  1786. */
  1787. var fromUtf8 = function(str) {
  1788. str = utf8.encode(str);
  1789. var hex = "";
  1790. for(var i = 0; i < str.length; i++) {
  1791. var code = str.charCodeAt(i);
  1792. if (code === 0)
  1793. break;
  1794. var n = code.toString(16);
  1795. hex += n.length < 2 ? '0' + n : n;
  1796. }
  1797. return "0x" + hex;
  1798. };
  1799. /**
  1800. * Should be called to get hex representation (prefixed by 0x) of ascii string
  1801. *
  1802. * @method fromAscii
  1803. * @param {String} string
  1804. * @param {Number} optional padding
  1805. * @returns {String} hex representation of input string
  1806. */
  1807. var fromAscii = function(str) {
  1808. var hex = "";
  1809. for(var i = 0; i < str.length; i++) {
  1810. var code = str.charCodeAt(i);
  1811. var n = code.toString(16);
  1812. hex += n.length < 2 ? '0' + n : n;
  1813. }
  1814. return "0x" + hex;
  1815. };
  1816. /**
  1817. * Should be used to create full function/event name from json abi
  1818. *
  1819. * @method transformToFullName
  1820. * @param {Object} json-abi
  1821. * @return {String} full fnction/event name
  1822. */
  1823. var transformToFullName = function (json) {
  1824. if (json.name.indexOf('(') !== -1) {
  1825. return json.name;
  1826. }
  1827. var typeName = json.inputs.map(function(i){return i.type; }).join();
  1828. return json.name + '(' + typeName + ')';
  1829. };
  1830. /**
  1831. * Should be called to get display name of contract function
  1832. *
  1833. * @method extractDisplayName
  1834. * @param {String} name of function/event
  1835. * @returns {String} display name for function/event eg. multiply(uint256) -> multiply
  1836. */
  1837. var extractDisplayName = function (name) {
  1838. var length = name.indexOf('(');
  1839. return length !== -1 ? name.substr(0, length) : name;
  1840. };
  1841. /// @returns overloaded part of function/event name
  1842. var extractTypeName = function (name) {
  1843. /// TODO: make it invulnerable
  1844. var length = name.indexOf('(');
  1845. return length !== -1 ? name.substr(length + 1, name.length - 1 - (length + 1)).replace(' ', '') : "";
  1846. };
  1847. /**
  1848. * Converts value to it's decimal representation in string
  1849. *
  1850. * @method toDecimal
  1851. * @param {String|Number|BigNumber}
  1852. * @return {String}
  1853. */
  1854. var toDecimal = function (value) {
  1855. return toBigNumber(value).toNumber();
  1856. };
  1857. /**
  1858. * Converts value to it's hex representation
  1859. *
  1860. * @method fromDecimal
  1861. * @param {String|Number|BigNumber}
  1862. * @return {String}
  1863. */
  1864. var fromDecimal = function (value) {
  1865. var number = toBigNumber(value);
  1866. var result = number.toString(16);
  1867. return number.lessThan(0) ? '-0x' + result.substr(1) : '0x' + result;
  1868. };
  1869. /**
  1870. * Auto converts any given value into it's hex representation.
  1871. *
  1872. * And even stringifys objects before.
  1873. *
  1874. * @method toHex
  1875. * @param {String|Number|BigNumber|Object}
  1876. * @return {String}
  1877. */
  1878. var toHex = function (val) {
  1879. /*jshint maxcomplexity: 8 */
  1880. if (isBoolean(val))
  1881. return fromDecimal(+val);
  1882. if (isBigNumber(val))
  1883. return fromDecimal(val);
  1884. if (typeof val === 'object')
  1885. return fromUtf8(JSON.stringify(val));
  1886. // if its a negative number, pass it through fromDecimal
  1887. if (isString(val)) {
  1888. if (val.indexOf('-0x') === 0)
  1889. return fromDecimal(val);
  1890. else if(val.indexOf('0x') === 0)
  1891. return val;
  1892. else if (!isFinite(val))
  1893. return fromAscii(val);
  1894. }
  1895. return fromDecimal(val);
  1896. };
  1897. /**
  1898. * Returns value of unit in Wei
  1899. *
  1900. * @method getValueOfUnit
  1901. * @param {String} unit the unit to convert to, default ether
  1902. * @returns {BigNumber} value of the unit (in Wei)
  1903. * @throws error if the unit is not correct:w
  1904. */
  1905. var getValueOfUnit = function (unit) {
  1906. unit = unit ? unit.toLowerCase() : 'ether';
  1907. var unitValue = unitMap[unit];
  1908. if (unitValue === undefined) {
  1909. throw new Error('This unit doesn\'t exists, please use the one of the following units' + JSON.stringify(unitMap, null, 2));
  1910. }
  1911. return new BigNumber(unitValue, 10);
  1912. };
  1913. /**
  1914. * Takes a number of wei and converts it to any other ether unit.
  1915. *
  1916. * Possible units are:
  1917. * SI Short SI Full Effigy Other
  1918. * - kwei femtoether babbage
  1919. * - mwei picoether lovelace
  1920. * - gwei nanoether shannon nano
  1921. * - -- microether szabo micro
  1922. * - -- milliether finney milli
  1923. * - ether -- --
  1924. * - kether -- grand
  1925. * - mether
  1926. * - gether
  1927. * - tether
  1928. *
  1929. * @method fromWei
  1930. * @param {Number|String} number can be a number, number string or a HEX of a decimal
  1931. * @param {String} unit the unit to convert to, default ether
  1932. * @return {String|Object} When given a BigNumber object it returns one as well, otherwise a number
  1933. */
  1934. var fromWei = function(number, unit) {
  1935. var returnValue = toBigNumber(number).dividedBy(getValueOfUnit(unit));
  1936. return isBigNumber(number) ? returnValue : returnValue.toString(10);
  1937. };
  1938. /**
  1939. * Takes a number of a unit and converts it to wei.
  1940. *
  1941. * Possible units are:
  1942. * SI Short SI Full Effigy Other
  1943. * - kwei femtoether babbage
  1944. * - mwei picoether lovelace
  1945. * - gwei nanoether shannon nano
  1946. * - -- microether szabo micro
  1947. * - -- microether szabo micro
  1948. * - -- milliether finney milli
  1949. * - ether -- --
  1950. * - kether -- grand
  1951. * - mether
  1952. * - gether
  1953. * - tether
  1954. *
  1955. * @method toWei
  1956. * @param {Number|String|BigNumber} number can be a number, number string or a HEX of a decimal
  1957. * @param {String} unit the unit to convert from, default ether
  1958. * @return {String|Object} When given a BigNumber object it returns one as well, otherwise a number
  1959. */
  1960. var toWei = function(number, unit) {
  1961. var returnValue = toBigNumber(number).times(getValueOfUnit(unit));
  1962. return isBigNumber(number) ? returnValue : returnValue.toString(10);
  1963. };
  1964. /**
  1965. * Takes an input and transforms it into a bignumber
  1966. *
  1967. * @method toBigNumber
  1968. * @param {Number|String|BigNumber} a number, string, HEX string or BigNumber
  1969. * @return {BigNumber} BigNumber
  1970. */
  1971. var toBigNumber = function(number) {
  1972. /*jshint maxcomplexity:5 */
  1973. number = number || 0;
  1974. if (isBigNumber(number))
  1975. return number;
  1976. if (isString(number) && (number.indexOf('0x') === 0 || number.indexOf('-0x') === 0)) {
  1977. return new BigNumber(number.replace('0x',''), 16);
  1978. }
  1979. return new BigNumber(number.toString(10), 10);
  1980. };
  1981. /**
  1982. * Takes and input transforms it into bignumber and if it is negative value, into two's complement
  1983. *
  1984. * @method toTwosComplement
  1985. * @param {Number|String|BigNumber}
  1986. * @return {BigNumber}
  1987. */
  1988. var toTwosComplement = function (number) {
  1989. var bigNumber = toBigNumber(number).round();
  1990. if (bigNumber.lessThan(0)) {
  1991. return new BigNumber("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 16).plus(bigNumber).plus(1);
  1992. }
  1993. return bigNumber;
  1994. };
  1995. /**
  1996. * Checks if the given string is strictly an address
  1997. *
  1998. * @method isStrictAddress
  1999. * @param {String} address the given HEX address
  2000. * @return {Boolean}
  2001. */
  2002. var isStrictAddress = function (address) {
  2003. return /^0x[0-9a-f]{40}$/i.test(address);
  2004. };
  2005. /**
  2006. * Checks if the given string is an address
  2007. *
  2008. * @method isAddress
  2009. * @param {String} address the given HEX address
  2010. * @return {Boolean}
  2011. */
  2012. var isAddress = function (address) {
  2013. if (!/^(0x)?[0-9a-f]{40}$/i.test(address)) {
  2014. // check if it has the basic requirements of an address
  2015. return false;
  2016. } else if (/^(0x)?[0-9a-f]{40}$/.test(address) || /^(0x)?[0-9A-F]{40}$/.test(address)) {
  2017. // If it's all small caps or all caps, return true
  2018. return true;
  2019. } else {
  2020. // Otherwise check each case
  2021. return isChecksumAddress(address);
  2022. }
  2023. };
  2024. /**
  2025. * Checks if the given string is a checksummed address
  2026. *
  2027. * @method isChecksumAddress
  2028. * @param {String} address the given HEX address
  2029. * @return {Boolean}
  2030. */
  2031. var isChecksumAddress = function (address) {
  2032. // Check each case
  2033. address = address.replace('0x','');
  2034. var addressHash = sha3(address.toLowerCase());
  2035. for (var i = 0; i < 40; i++ ) {
  2036. // the nth letter should be uppercase if the nth digit of casemap is 1
  2037. if ((parseInt(addressHash[i], 16) > 7 && address[i].toUpperCase() !== address[i]) || (parseInt(addressHash[i], 16) <= 7 && address[i].toLowerCase() !== address[i])) {
  2038. return false;
  2039. }
  2040. }
  2041. return true;
  2042. };
  2043. /**
  2044. * Makes a checksum address
  2045. *
  2046. * @method toChecksumAddress
  2047. * @param {String} address the given HEX address
  2048. * @return {String}
  2049. */
  2050. var toChecksumAddress = function (address) {
  2051. if (typeof address === 'undefined') return '';
  2052. address = address.toLowerCase().replace('0x','');
  2053. var addressHash = sha3(address);
  2054. var checksumAddress = '0x';
  2055. for (var i = 0; i < address.length; i++ ) {
  2056. // If ith character is 9 to f then make it uppercase
  2057. if (parseInt(addressHash[i], 16) > 7) {
  2058. checksumAddress += address[i].toUpperCase();
  2059. } else {
  2060. checksumAddress += address[i];
  2061. }
  2062. }
  2063. return checksumAddress;
  2064. };
  2065. /**
  2066. * Transforms given string to valid 20 bytes-length addres with 0x prefix
  2067. *
  2068. * @method toAddress
  2069. * @param {String} address
  2070. * @return {String} formatted address
  2071. */
  2072. var toAddress = function (address) {
  2073. if (isStrictAddress(address)) {
  2074. return address;
  2075. }
  2076. if (/^[0-9a-f]{40}$/.test(address)) {
  2077. return '0x' + address;
  2078. }
  2079. return '0x' + padLeft(toHex(address).substr(2), 40);
  2080. };
  2081. /**
  2082. * Returns true if object is BigNumber, otherwise false
  2083. *
  2084. * @method isBigNumber
  2085. * @param {Object}
  2086. * @return {Boolean}
  2087. */
  2088. var isBigNumber = function (object) {
  2089. return object instanceof BigNumber ||
  2090. (object && object.constructor && object.constructor.name === 'BigNumber');
  2091. };
  2092. /**
  2093. * Returns true if object is string, otherwise false
  2094. *
  2095. * @method isString
  2096. * @param {Object}
  2097. * @return {Boolean}
  2098. */
  2099. var isString = function (object) {
  2100. return typeof object === 'string' ||
  2101. (object && object.constructor && object.constructor.name === 'String');
  2102. };
  2103. /**
  2104. * Returns true if object is function, otherwise false
  2105. *
  2106. * @method isFunction
  2107. * @param {Object}
  2108. * @return {Boolean}
  2109. */
  2110. var isFunction = function (object) {
  2111. return typeof object === 'function';
  2112. };
  2113. /**
  2114. * Returns true if object is Objet, otherwise false
  2115. *
  2116. * @method isObject
  2117. * @param {Object}
  2118. * @return {Boolean}
  2119. */
  2120. var isObject = function (object) {
  2121. return object !== null && !(object instanceof Array) && typeof object === 'object';
  2122. };
  2123. /**
  2124. * Returns true if object is boolean, otherwise false
  2125. *
  2126. * @method isBoolean
  2127. * @param {Object}
  2128. * @return {Boolean}
  2129. */
  2130. var isBoolean = function (object) {
  2131. return typeof object === 'boolean';
  2132. };
  2133. /**
  2134. * Returns true if object is array, otherwise false
  2135. *
  2136. * @method isArray
  2137. * @param {Object}
  2138. * @return {Boolean}
  2139. */
  2140. var isArray = function (object) {
  2141. return object instanceof Array;
  2142. };
  2143. /**
  2144. * Returns true if given string is valid json object
  2145. *
  2146. * @method isJson
  2147. * @param {String}
  2148. * @return {Boolean}
  2149. */
  2150. var isJson = function (str) {
  2151. try {
  2152. return !!JSON.parse(str);
  2153. } catch (e) {
  2154. return false;
  2155. }
  2156. };
  2157. /**
  2158. * Returns true if given string is a valid Ethereum block header bloom.
  2159. *
  2160. * @method isBloom
  2161. * @param {String} hex encoded bloom filter
  2162. * @return {Boolean}
  2163. */
  2164. var isBloom = function (bloom) {
  2165. if (!/^(0x)?[0-9a-f]{512}$/i.test(bloom)) {
  2166. return false;
  2167. } else if (/^(0x)?[0-9a-f]{512}$/.test(bloom) || /^(0x)?[0-9A-F]{512}$/.test(bloom)) {
  2168. return true;
  2169. }
  2170. return false;
  2171. };
  2172. /**
  2173. * Returns true if given string is a valid log topic.
  2174. *
  2175. * @method isTopic
  2176. * @param {String} hex encoded topic
  2177. * @return {Boolean}
  2178. */
  2179. var isTopic = function (topic) {
  2180. if (!/^(0x)?[0-9a-f]{64}$/i.test(topic)) {
  2181. return false;
  2182. } else if (/^(0x)?[0-9a-f]{64}$/.test(topic) || /^(0x)?[0-9A-F]{64}$/.test(topic)) {
  2183. return true;
  2184. }
  2185. return false;
  2186. };
  2187. module.exports = {
  2188. padLeft: padLeft,
  2189. padRight: padRight,
  2190. toHex: toHex,
  2191. toDecimal: toDecimal,
  2192. fromDecimal: fromDecimal,
  2193. toUtf8: toUtf8,
  2194. toAscii: toAscii,
  2195. fromUtf8: fromUtf8,
  2196. fromAscii: fromAscii,
  2197. transformToFullName: transformToFullName,
  2198. extractDisplayName: extractDisplayName,
  2199. extractTypeName: extractTypeName,
  2200. toWei: toWei,
  2201. fromWei: fromWei,
  2202. toBigNumber: toBigNumber,
  2203. toTwosComplement: toTwosComplement,
  2204. toAddress: toAddress,
  2205. isBigNumber: isBigNumber,
  2206. isStrictAddress: isStrictAddress,
  2207. isAddress: isAddress,
  2208. isChecksumAddress: isChecksumAddress,
  2209. toChecksumAddress: toChecksumAddress,
  2210. isFunction: isFunction,
  2211. isString: isString,
  2212. isObject: isObject,
  2213. isBoolean: isBoolean,
  2214. isArray: isArray,
  2215. isJson: isJson,
  2216. isBloom: isBloom,
  2217. isTopic: isTopic,
  2218. };
  2219. },{"./sha3.js":19,"bignumber.js":"bignumber.js","utf8":85}],21:[function(require,module,exports){
  2220. module.exports={
  2221. "version": "0.20.1"
  2222. }
  2223. },{}],22:[function(require,module,exports){
  2224. /*
  2225. This file is part of web3.js.
  2226. web3.js is free software: you can redistribute it and/or modify
  2227. it under the terms of the GNU Lesser General Public License as published by
  2228. the Free Software Foundation, either version 3 of the License, or
  2229. (at your option) any later version.
  2230. web3.js is distributed in the hope that it will be useful,
  2231. but WITHOUT ANY WARRANTY; without even the implied warranty of
  2232. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  2233. GNU Lesser General Public License for more details.
  2234. You should have received a copy of the GNU Lesser General Public License
  2235. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  2236. */
  2237. /**
  2238. * @file web3.js
  2239. * @authors:
  2240. * Jeffrey Wilcke <jeff@ethdev.com>
  2241. * Marek Kotewicz <marek@ethdev.com>
  2242. * Marian Oancea <marian@ethdev.com>
  2243. * Fabian Vogelsteller <fabian@ethdev.com>
  2244. * Gav Wood <g@ethdev.com>
  2245. * @date 2014
  2246. */
  2247. var RequestManager = require('./web3/requestmanager');
  2248. var Iban = require('./web3/iban');
  2249. var Eth = require('./web3/methods/eth');
  2250. var DB = require('./web3/methods/db');
  2251. var Shh = require('./web3/methods/shh');
  2252. var Net = require('./web3/methods/net');
  2253. var Personal = require('./web3/methods/personal');
  2254. var Swarm = require('./web3/methods/swarm');
  2255. var Settings = require('./web3/settings');
  2256. var version = require('./version.json');
  2257. var utils = require('./utils/utils');
  2258. var sha3 = require('./utils/sha3');
  2259. var extend = require('./web3/extend');
  2260. var Batch = require('./web3/batch');
  2261. var Property = require('./web3/property');
  2262. var HttpProvider = require('./web3/httpprovider');
  2263. var IpcProvider = require('./web3/ipcprovider');
  2264. var BigNumber = require('bignumber.js');
  2265. function Web3 (provider) {
  2266. this._requestManager = new RequestManager(provider);
  2267. this.currentProvider = provider;
  2268. this.eth = new Eth(this);
  2269. this.db = new DB(this);
  2270. this.shh = new Shh(this);
  2271. this.net = new Net(this);
  2272. this.personal = new Personal(this);
  2273. this.bzz = new Swarm(this);
  2274. this.settings = new Settings();
  2275. this.version = {
  2276. api: version.version
  2277. };
  2278. this.providers = {
  2279. HttpProvider: HttpProvider,
  2280. IpcProvider: IpcProvider
  2281. };
  2282. this._extend = extend(this);
  2283. this._extend({
  2284. properties: properties()
  2285. });
  2286. }
  2287. // expose providers on the class
  2288. Web3.providers = {
  2289. HttpProvider: HttpProvider,
  2290. IpcProvider: IpcProvider
  2291. };
  2292. Web3.prototype.setProvider = function (provider) {
  2293. this._requestManager.setProvider(provider);
  2294. this.currentProvider = provider;
  2295. };
  2296. Web3.prototype.reset = function (keepIsSyncing) {
  2297. this._requestManager.reset(keepIsSyncing);
  2298. this.settings = new Settings();
  2299. };
  2300. Web3.prototype.BigNumber = BigNumber;
  2301. Web3.prototype.toHex = utils.toHex;
  2302. Web3.prototype.toAscii = utils.toAscii;
  2303. Web3.prototype.toUtf8 = utils.toUtf8;
  2304. Web3.prototype.fromAscii = utils.fromAscii;
  2305. Web3.prototype.fromUtf8 = utils.fromUtf8;
  2306. Web3.prototype.toDecimal = utils.toDecimal;
  2307. Web3.prototype.fromDecimal = utils.fromDecimal;
  2308. Web3.prototype.toBigNumber = utils.toBigNumber;
  2309. Web3.prototype.toWei = utils.toWei;
  2310. Web3.prototype.fromWei = utils.fromWei;
  2311. Web3.prototype.isAddress = utils.isAddress;
  2312. Web3.prototype.isChecksumAddress = utils.isChecksumAddress;
  2313. Web3.prototype.toChecksumAddress = utils.toChecksumAddress;
  2314. Web3.prototype.isIBAN = utils.isIBAN;
  2315. Web3.prototype.padLeft = utils.padLeft;
  2316. Web3.prototype.padRight = utils.padRight;
  2317. Web3.prototype.sha3 = function(string, options) {
  2318. return '0x' + sha3(string, options);
  2319. };
  2320. /**
  2321. * Transforms direct icap to address
  2322. */
  2323. Web3.prototype.fromICAP = function (icap) {
  2324. var iban = new Iban(icap);
  2325. return iban.address();
  2326. };
  2327. var properties = function () {
  2328. return [
  2329. new Property({
  2330. name: 'version.node',
  2331. getter: 'web3_clientVersion'
  2332. }),
  2333. new Property({
  2334. name: 'version.network',
  2335. getter: 'net_version',
  2336. inputFormatter: utils.toDecimal
  2337. }),
  2338. new Property({
  2339. name: 'version.ethereum',
  2340. getter: 'eth_protocolVersion',
  2341. inputFormatter: utils.toDecimal
  2342. }),
  2343. new Property({
  2344. name: 'version.whisper',
  2345. getter: 'shh_version',
  2346. inputFormatter: utils.toDecimal
  2347. })
  2348. ];
  2349. };
  2350. Web3.prototype.isConnected = function(){
  2351. return (this.currentProvider && this.currentProvider.isConnected());
  2352. };
  2353. Web3.prototype.createBatch = function () {
  2354. return new Batch(this);
  2355. };
  2356. module.exports = Web3;
  2357. },{"./utils/sha3":19,"./utils/utils":20,"./version.json":21,"./web3/batch":24,"./web3/extend":28,"./web3/httpprovider":32,"./web3/iban":33,"./web3/ipcprovider":34,"./web3/methods/db":37,"./web3/methods/eth":38,"./web3/methods/net":39,"./web3/methods/personal":40,"./web3/methods/shh":41,"./web3/methods/swarm":42,"./web3/property":45,"./web3/requestmanager":46,"./web3/settings":47,"bignumber.js":"bignumber.js"}],23:[function(require,module,exports){
  2358. /*
  2359. This file is part of web3.js.
  2360. web3.js is free software: you can redistribute it and/or modify
  2361. it under the terms of the GNU Lesser General Public License as published by
  2362. the Free Software Foundation, either version 3 of the License, or
  2363. (at your option) any later version.
  2364. web3.js is distributed in the hope that it will be useful,
  2365. but WITHOUT ANY WARRANTY; without even the implied warranty of
  2366. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  2367. GNU Lesser General Public License for more details.
  2368. You should have received a copy of the GNU Lesser General Public License
  2369. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  2370. */
  2371. /**
  2372. * @file allevents.js
  2373. * @author Marek Kotewicz <marek@ethdev.com>
  2374. * @date 2014
  2375. */
  2376. var sha3 = require('../utils/sha3');
  2377. var SolidityEvent = require('./event');
  2378. var formatters = require('./formatters');
  2379. var utils = require('../utils/utils');
  2380. var Filter = require('./filter');
  2381. var watches = require('./methods/watches');
  2382. var AllSolidityEvents = function (requestManager, json, address) {
  2383. this._requestManager = requestManager;
  2384. this._json = json;
  2385. this._address = address;
  2386. };
  2387. AllSolidityEvents.prototype.encode = function (options) {
  2388. options = options || {};
  2389. var result = {};
  2390. ['fromBlock', 'toBlock'].filter(function (f) {
  2391. return options[f] !== undefined;
  2392. }).forEach(function (f) {
  2393. result[f] = formatters.inputBlockNumberFormatter(options[f]);
  2394. });
  2395. result.address = this._address;
  2396. return result;
  2397. };
  2398. AllSolidityEvents.prototype.decode = function (data) {
  2399. data.data = data.data || '';
  2400. data.topics = data.topics || [];
  2401. var eventTopic = data.topics[0].slice(2);
  2402. var match = this._json.filter(function (j) {
  2403. return eventTopic === sha3(utils.transformToFullName(j));
  2404. })[0];
  2405. if (!match) { // cannot find matching event?
  2406. console.warn('cannot find event for log');
  2407. return data;
  2408. }
  2409. var event = new SolidityEvent(this._requestManager, match, this._address);
  2410. return event.decode(data);
  2411. };
  2412. AllSolidityEvents.prototype.execute = function (options, callback) {
  2413. if (utils.isFunction(arguments[arguments.length - 1])) {
  2414. callback = arguments[arguments.length - 1];
  2415. if(arguments.length === 1)
  2416. options = null;
  2417. }
  2418. var o = this.encode(options);
  2419. var formatter = this.decode.bind(this);
  2420. return new Filter(o, 'eth', this._requestManager, watches.eth(), formatter, callback);
  2421. };
  2422. AllSolidityEvents.prototype.attachToContract = function (contract) {
  2423. var execute = this.execute.bind(this);
  2424. contract.allEvents = execute;
  2425. };
  2426. module.exports = AllSolidityEvents;
  2427. },{"../utils/sha3":19,"../utils/utils":20,"./event":27,"./filter":29,"./formatters":30,"./methods/watches":43}],24:[function(require,module,exports){
  2428. /*
  2429. This file is part of web3.js.
  2430. web3.js is free software: you can redistribute it and/or modify
  2431. it under the terms of the GNU Lesser General Public License as published by
  2432. the Free Software Foundation, either version 3 of the License, or
  2433. (at your option) any later version.
  2434. web3.js is distributed in the hope that it will be useful,
  2435. but WITHOUT ANY WARRANTY; without even the implied warranty of
  2436. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  2437. GNU Lesser General Public License for more details.
  2438. You should have received a copy of the GNU Lesser General Public License
  2439. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  2440. */
  2441. /**
  2442. * @file batch.js
  2443. * @author Marek Kotewicz <marek@ethdev.com>
  2444. * @date 2015
  2445. */
  2446. var Jsonrpc = require('./jsonrpc');
  2447. var errors = require('./errors');
  2448. var Batch = function (web3) {
  2449. this.requestManager = web3._requestManager;
  2450. this.requests = [];
  2451. };
  2452. /**
  2453. * Should be called to add create new request to batch request
  2454. *
  2455. * @method add
  2456. * @param {Object} jsonrpc requet object
  2457. */
  2458. Batch.prototype.add = function (request) {
  2459. this.requests.push(request);
  2460. };
  2461. /**
  2462. * Should be called to execute batch request
  2463. *
  2464. * @method execute
  2465. */
  2466. Batch.prototype.execute = function () {
  2467. var requests = this.requests;
  2468. this.requestManager.sendBatch(requests, function (err, results) {
  2469. results = results || [];
  2470. requests.map(function (request, index) {
  2471. return results[index] || {};
  2472. }).forEach(function (result, index) {
  2473. if (requests[index].callback) {
  2474. if (!Jsonrpc.isValidResponse(result)) {
  2475. return requests[index].callback(errors.InvalidResponse(result));
  2476. }
  2477. requests[index].callback(null, (requests[index].format ? requests[index].format(result.result) : result.result));
  2478. }
  2479. });
  2480. });
  2481. };
  2482. module.exports = Batch;
  2483. },{"./errors":26,"./jsonrpc":35}],25:[function(require,module,exports){
  2484. /*
  2485. This file is part of web3.js.
  2486. web3.js is free software: you can redistribute it and/or modify
  2487. it under the terms of the GNU Lesser General Public License as published by
  2488. the Free Software Foundation, either version 3 of the License, or
  2489. (at your option) any later version.
  2490. web3.js is distributed in the hope that it will be useful,
  2491. but WITHOUT ANY WARRANTY; without even the implied warranty of
  2492. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  2493. GNU Lesser General Public License for more details.
  2494. You should have received a copy of the GNU Lesser General Public License
  2495. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  2496. */
  2497. /**
  2498. * @file contract.js
  2499. * @author Marek Kotewicz <marek@ethdev.com>
  2500. * @date 2014
  2501. */
  2502. var utils = require('../utils/utils');
  2503. var coder = require('../solidity/coder');
  2504. var SolidityEvent = require('./event');
  2505. var SolidityFunction = require('./function');
  2506. var AllEvents = require('./allevents');
  2507. /**
  2508. * Should be called to encode constructor params
  2509. *
  2510. * @method encodeConstructorParams
  2511. * @param {Array} abi
  2512. * @param {Array} constructor params
  2513. */
  2514. var encodeConstructorParams = function (abi, params) {
  2515. return abi.filter(function (json) {
  2516. return json.type === 'constructor' && json.inputs.length === params.length;
  2517. }).map(function (json) {
  2518. return json.inputs.map(function (input) {
  2519. return input.type;
  2520. });
  2521. }).map(function (types) {
  2522. return coder.encodeParams(types, params);
  2523. })[0] || '';
  2524. };
  2525. /**
  2526. * Should be called to add functions to contract object
  2527. *
  2528. * @method addFunctionsToContract
  2529. * @param {Contract} contract
  2530. * @param {Array} abi
  2531. */
  2532. var addFunctionsToContract = function (contract) {
  2533. contract.abi.filter(function (json) {
  2534. return json.type === 'function';
  2535. }).map(function (json) {
  2536. return new SolidityFunction(contract._eth, json, contract.address);
  2537. }).forEach(function (f) {
  2538. f.attachToContract(contract);
  2539. });
  2540. };
  2541. /**
  2542. * Should be called to add events to contract object
  2543. *
  2544. * @method addEventsToContract
  2545. * @param {Contract} contract
  2546. * @param {Array} abi
  2547. */
  2548. var addEventsToContract = function (contract) {
  2549. var events = contract.abi.filter(function (json) {
  2550. return json.type === 'event';
  2551. });
  2552. var All = new AllEvents(contract._eth._requestManager, events, contract.address);
  2553. All.attachToContract(contract);
  2554. events.map(function (json) {
  2555. return new SolidityEvent(contract._eth._requestManager, json, contract.address);
  2556. }).forEach(function (e) {
  2557. e.attachToContract(contract);
  2558. });
  2559. };
  2560. /**
  2561. * Should be called to check if the contract gets properly deployed on the blockchain.
  2562. *
  2563. * @method checkForContractAddress
  2564. * @param {Object} contract
  2565. * @param {Function} callback
  2566. * @returns {Undefined}
  2567. */
  2568. var checkForContractAddress = function(contract, callback){
  2569. var count = 0,
  2570. callbackFired = false;
  2571. // wait for receipt
  2572. var filter = contract._eth.filter('latest', function(e){
  2573. if (!e && !callbackFired) {
  2574. count++;
  2575. // stop watching after 50 blocks (timeout)
  2576. if (count > 50) {
  2577. filter.stopWatching(function() {});
  2578. callbackFired = true;
  2579. if (callback)
  2580. callback(new Error('Contract transaction couldn\'t be found after 50 blocks'));
  2581. else
  2582. throw new Error('Contract transaction couldn\'t be found after 50 blocks');
  2583. } else {
  2584. contract._eth.getTransactionReceipt(contract.transactionHash, function(e, receipt){
  2585. if(receipt && !callbackFired) {
  2586. contract._eth.getCode(receipt.contractAddress, function(e, code){
  2587. /*jshint maxcomplexity: 6 */
  2588. if(callbackFired || !code)
  2589. return;
  2590. filter.stopWatching(function() {});
  2591. callbackFired = true;
  2592. if(code.length > 3) {
  2593. // console.log('Contract code deployed!');
  2594. contract.address = receipt.contractAddress;
  2595. // attach events and methods again after we have
  2596. addFunctionsToContract(contract);
  2597. addEventsToContract(contract);
  2598. // call callback for the second time
  2599. if(callback)
  2600. callback(null, contract);
  2601. } else {
  2602. if(callback)
  2603. callback(new Error('The contract code couldn\'t be stored, please check your gas amount.'));
  2604. else
  2605. throw new Error('The contract code couldn\'t be stored, please check your gas amount.');
  2606. }
  2607. });
  2608. }
  2609. });
  2610. }
  2611. }
  2612. });
  2613. };
  2614. /**
  2615. * Should be called to create new ContractFactory instance
  2616. *
  2617. * @method ContractFactory
  2618. * @param {Array} abi
  2619. */
  2620. var ContractFactory = function (eth, abi) {
  2621. this.eth = eth;
  2622. this.abi = abi;
  2623. /**
  2624. * Should be called to create new contract on a blockchain
  2625. *
  2626. * @method new
  2627. * @param {Any} contract constructor param1 (optional)
  2628. * @param {Any} contract constructor param2 (optional)
  2629. * @param {Object} contract transaction object (required)
  2630. * @param {Function} callback
  2631. * @returns {Contract} returns contract instance
  2632. */
  2633. this.new = function () {
  2634. /*jshint maxcomplexity: 7 */
  2635. var contract = new Contract(this.eth, this.abi);
  2636. // parse arguments
  2637. var options = {}; // required!
  2638. var callback;
  2639. var args = Array.prototype.slice.call(arguments);
  2640. if (utils.isFunction(args[args.length - 1])) {
  2641. callback = args.pop();
  2642. }
  2643. var last = args[args.length - 1];
  2644. if (utils.isObject(last) && !utils.isArray(last)) {
  2645. options = args.pop();
  2646. }
  2647. if (options.value > 0) {
  2648. var constructorAbi = abi.filter(function (json) {
  2649. return json.type === 'constructor' && json.inputs.length === args.length;
  2650. })[0] || {};
  2651. if (!constructorAbi.payable) {
  2652. throw new Error('Cannot send value to non-payable constructor');
  2653. }
  2654. }
  2655. var bytes = encodeConstructorParams(this.abi, args);
  2656. options.data += bytes;
  2657. if (callback) {
  2658. // wait for the contract address and check if the code was deployed
  2659. this.eth.sendTransaction(options, function (err, hash) {
  2660. if (err) {
  2661. callback(err);
  2662. } else {
  2663. // add the transaction hash
  2664. contract.transactionHash = hash;
  2665. // call callback for the first time
  2666. callback(null, contract);
  2667. checkForContractAddress(contract, callback);
  2668. }
  2669. });
  2670. } else {
  2671. var hash = this.eth.sendTransaction(options);
  2672. // add the transaction hash
  2673. contract.transactionHash = hash;
  2674. checkForContractAddress(contract);
  2675. }
  2676. return contract;
  2677. };
  2678. this.new.getData = this.getData.bind(this);
  2679. };
  2680. /**
  2681. * Should be called to create new ContractFactory
  2682. *
  2683. * @method contract
  2684. * @param {Array} abi
  2685. * @returns {ContractFactory} new contract factory
  2686. */
  2687. //var contract = function (abi) {
  2688. //return new ContractFactory(abi);
  2689. //};
  2690. /**
  2691. * Should be called to get access to existing contract on a blockchain
  2692. *
  2693. * @method at
  2694. * @param {Address} contract address (required)
  2695. * @param {Function} callback {optional)
  2696. * @returns {Contract} returns contract if no callback was passed,
  2697. * otherwise calls callback function (err, contract)
  2698. */
  2699. ContractFactory.prototype.at = function (address, callback) {
  2700. var contract = new Contract(this.eth, this.abi, address);
  2701. // this functions are not part of prototype,
  2702. // because we dont want to spoil the interface
  2703. addFunctionsToContract(contract);
  2704. addEventsToContract(contract);
  2705. if (callback) {
  2706. callback(null, contract);
  2707. }
  2708. return contract;
  2709. };
  2710. /**
  2711. * Gets the data, which is data to deploy plus constructor params
  2712. *
  2713. * @method getData
  2714. */
  2715. ContractFactory.prototype.getData = function () {
  2716. var options = {}; // required!
  2717. var args = Array.prototype.slice.call(arguments);
  2718. var last = args[args.length - 1];
  2719. if (utils.isObject(last) && !utils.isArray(last)) {
  2720. options = args.pop();
  2721. }
  2722. var bytes = encodeConstructorParams(this.abi, args);
  2723. options.data += bytes;
  2724. return options.data;
  2725. };
  2726. /**
  2727. * Should be called to create new contract instance
  2728. *
  2729. * @method Contract
  2730. * @param {Array} abi
  2731. * @param {Address} contract address
  2732. */
  2733. var Contract = function (eth, abi, address) {
  2734. this._eth = eth;
  2735. this.transactionHash = null;
  2736. this.address = address;
  2737. this.abi = abi;
  2738. };
  2739. module.exports = ContractFactory;
  2740. },{"../solidity/coder":7,"../utils/utils":20,"./allevents":23,"./event":27,"./function":31}],26:[function(require,module,exports){
  2741. /*
  2742. This file is part of web3.js.
  2743. web3.js is free software: you can redistribute it and/or modify
  2744. it under the terms of the GNU Lesser General Public License as published by
  2745. the Free Software Foundation, either version 3 of the License, or
  2746. (at your option) any later version.
  2747. web3.js is distributed in the hope that it will be useful,
  2748. but WITHOUT ANY WARRANTY; without even the implied warranty of
  2749. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  2750. GNU Lesser General Public License for more details.
  2751. You should have received a copy of the GNU Lesser General Public License
  2752. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  2753. */
  2754. /**
  2755. * @file errors.js
  2756. * @author Marek Kotewicz <marek@ethdev.com>
  2757. * @date 2015
  2758. */
  2759. module.exports = {
  2760. InvalidNumberOfSolidityArgs: function () {
  2761. return new Error('Invalid number of arguments to Solidity function');
  2762. },
  2763. InvalidNumberOfRPCParams: function () {
  2764. return new Error('Invalid number of input parameters to RPC method');
  2765. },
  2766. InvalidConnection: function (host){
  2767. return new Error('CONNECTION ERROR: Couldn\'t connect to node '+ host +'.');
  2768. },
  2769. InvalidProvider: function () {
  2770. return new Error('Provider not set or invalid');
  2771. },
  2772. InvalidResponse: function (result){
  2773. var message = !!result && !!result.error && !!result.error.message ? result.error.message : 'Invalid JSON RPC response: ' + JSON.stringify(result);
  2774. return new Error(message);
  2775. },
  2776. ConnectionTimeout: function (ms){
  2777. return new Error('CONNECTION TIMEOUT: timeout of ' + ms + ' ms achived');
  2778. }
  2779. };
  2780. },{}],27:[function(require,module,exports){
  2781. /*
  2782. This file is part of web3.js.
  2783. web3.js is free software: you can redistribute it and/or modify
  2784. it under the terms of the GNU Lesser General Public License as published by
  2785. the Free Software Foundation, either version 3 of the License, or
  2786. (at your option) any later version.
  2787. web3.js is distributed in the hope that it will be useful,
  2788. but WITHOUT ANY WARRANTY; without even the implied warranty of
  2789. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  2790. GNU Lesser General Public License for more details.
  2791. You should have received a copy of the GNU Lesser General Public License
  2792. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  2793. */
  2794. /**
  2795. * @file event.js
  2796. * @author Marek Kotewicz <marek@ethdev.com>
  2797. * @date 2014
  2798. */
  2799. var utils = require('../utils/utils');
  2800. var coder = require('../solidity/coder');
  2801. var formatters = require('./formatters');
  2802. var sha3 = require('../utils/sha3');
  2803. var Filter = require('./filter');
  2804. var watches = require('./methods/watches');
  2805. /**
  2806. * This prototype should be used to create event filters
  2807. */
  2808. var SolidityEvent = function (requestManager, json, address) {
  2809. this._requestManager = requestManager;
  2810. this._params = json.inputs;
  2811. this._name = utils.transformToFullName(json);
  2812. this._address = address;
  2813. this._anonymous = json.anonymous;
  2814. };
  2815. /**
  2816. * Should be used to get filtered param types
  2817. *
  2818. * @method types
  2819. * @param {Bool} decide if returned typed should be indexed
  2820. * @return {Array} array of types
  2821. */
  2822. SolidityEvent.prototype.types = function (indexed) {
  2823. return this._params.filter(function (i) {
  2824. return i.indexed === indexed;
  2825. }).map(function (i) {
  2826. return i.type;
  2827. });
  2828. };
  2829. /**
  2830. * Should be used to get event display name
  2831. *
  2832. * @method displayName
  2833. * @return {String} event display name
  2834. */
  2835. SolidityEvent.prototype.displayName = function () {
  2836. return utils.extractDisplayName(this._name);
  2837. };
  2838. /**
  2839. * Should be used to get event type name
  2840. *
  2841. * @method typeName
  2842. * @return {String} event type name
  2843. */
  2844. SolidityEvent.prototype.typeName = function () {
  2845. return utils.extractTypeName(this._name);
  2846. };
  2847. /**
  2848. * Should be used to get event signature
  2849. *
  2850. * @method signature
  2851. * @return {String} event signature
  2852. */
  2853. SolidityEvent.prototype.signature = function () {
  2854. return sha3(this._name);
  2855. };
  2856. /**
  2857. * Should be used to encode indexed params and options to one final object
  2858. *
  2859. * @method encode
  2860. * @param {Object} indexed
  2861. * @param {Object} options
  2862. * @return {Object} everything combined together and encoded
  2863. */
  2864. SolidityEvent.prototype.encode = function (indexed, options) {
  2865. indexed = indexed || {};
  2866. options = options || {};
  2867. var result = {};
  2868. ['fromBlock', 'toBlock'].filter(function (f) {
  2869. return options[f] !== undefined;
  2870. }).forEach(function (f) {
  2871. result[f] = formatters.inputBlockNumberFormatter(options[f]);
  2872. });
  2873. result.topics = [];
  2874. result.address = this._address;
  2875. if (!this._anonymous) {
  2876. result.topics.push('0x' + this.signature());
  2877. }
  2878. var indexedTopics = this._params.filter(function (i) {
  2879. return i.indexed === true;
  2880. }).map(function (i) {
  2881. var value = indexed[i.name];
  2882. if (value === undefined || value === null) {
  2883. return null;
  2884. }
  2885. if (utils.isArray(value)) {
  2886. return value.map(function (v) {
  2887. return '0x' + coder.encodeParam(i.type, v);
  2888. });
  2889. }
  2890. return '0x' + coder.encodeParam(i.type, value);
  2891. });
  2892. result.topics = result.topics.concat(indexedTopics);
  2893. return result;
  2894. };
  2895. /**
  2896. * Should be used to decode indexed params and options
  2897. *
  2898. * @method decode
  2899. * @param {Object} data
  2900. * @return {Object} result object with decoded indexed && not indexed params
  2901. */
  2902. SolidityEvent.prototype.decode = function (data) {
  2903. data.data = data.data || '';
  2904. data.topics = data.topics || [];
  2905. var argTopics = this._anonymous ? data.topics : data.topics.slice(1);
  2906. var indexedData = argTopics.map(function (topics) { return topics.slice(2); }).join("");
  2907. var indexedParams = coder.decodeParams(this.types(true), indexedData);
  2908. var notIndexedData = data.data.slice(2);
  2909. var notIndexedParams = coder.decodeParams(this.types(false), notIndexedData);
  2910. var result = formatters.outputLogFormatter(data);
  2911. result.event = this.displayName();
  2912. result.address = data.address;
  2913. result.args = this._params.reduce(function (acc, current) {
  2914. acc[current.name] = current.indexed ? indexedParams.shift() : notIndexedParams.shift();
  2915. return acc;
  2916. }, {});
  2917. delete result.data;
  2918. delete result.topics;
  2919. return result;
  2920. };
  2921. /**
  2922. * Should be used to create new filter object from event
  2923. *
  2924. * @method execute
  2925. * @param {Object} indexed
  2926. * @param {Object} options
  2927. * @return {Object} filter object
  2928. */
  2929. SolidityEvent.prototype.execute = function (indexed, options, callback) {
  2930. if (utils.isFunction(arguments[arguments.length - 1])) {
  2931. callback = arguments[arguments.length - 1];
  2932. if(arguments.length === 2)
  2933. options = null;
  2934. if(arguments.length === 1) {
  2935. options = null;
  2936. indexed = {};
  2937. }
  2938. }
  2939. var o = this.encode(indexed, options);
  2940. var formatter = this.decode.bind(this);
  2941. return new Filter(o, 'eth', this._requestManager, watches.eth(), formatter, callback);
  2942. };
  2943. /**
  2944. * Should be used to attach event to contract object
  2945. *
  2946. * @method attachToContract
  2947. * @param {Contract}
  2948. */
  2949. SolidityEvent.prototype.attachToContract = function (contract) {
  2950. var execute = this.execute.bind(this);
  2951. var displayName = this.displayName();
  2952. if (!contract[displayName]) {
  2953. contract[displayName] = execute;
  2954. }
  2955. contract[displayName][this.typeName()] = this.execute.bind(this, contract);
  2956. };
  2957. module.exports = SolidityEvent;
  2958. },{"../solidity/coder":7,"../utils/sha3":19,"../utils/utils":20,"./filter":29,"./formatters":30,"./methods/watches":43}],28:[function(require,module,exports){
  2959. var formatters = require('./formatters');
  2960. var utils = require('./../utils/utils');
  2961. var Method = require('./method');
  2962. var Property = require('./property');
  2963. // TODO: refactor, so the input params are not altered.
  2964. // it's necessary to make same 'extension' work with multiple providers
  2965. var extend = function (web3) {
  2966. /* jshint maxcomplexity:5 */
  2967. var ex = function (extension) {
  2968. var extendedObject;
  2969. if (extension.property) {
  2970. if (!web3[extension.property]) {
  2971. web3[extension.property] = {};
  2972. }
  2973. extendedObject = web3[extension.property];
  2974. } else {
  2975. extendedObject = web3;
  2976. }
  2977. if (extension.methods) {
  2978. extension.methods.forEach(function (method) {
  2979. method.attachToObject(extendedObject);
  2980. method.setRequestManager(web3._requestManager);
  2981. });
  2982. }
  2983. if (extension.properties) {
  2984. extension.properties.forEach(function (property) {
  2985. property.attachToObject(extendedObject);
  2986. property.setRequestManager(web3._requestManager);
  2987. });
  2988. }
  2989. };
  2990. ex.formatters = formatters;
  2991. ex.utils = utils;
  2992. ex.Method = Method;
  2993. ex.Property = Property;
  2994. return ex;
  2995. };
  2996. module.exports = extend;
  2997. },{"./../utils/utils":20,"./formatters":30,"./method":36,"./property":45}],29:[function(require,module,exports){
  2998. /*
  2999. This file is part of web3.js.
  3000. web3.js is free software: you can redistribute it and/or modify
  3001. it under the terms of the GNU Lesser General Public License as published by
  3002. the Free Software Foundation, either version 3 of the License, or
  3003. (at your option) any later version.
  3004. web3.js is distributed in the hope that it will be useful,
  3005. but WITHOUT ANY WARRANTY; without even the implied warranty of
  3006. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  3007. GNU Lesser General Public License for more details.
  3008. You should have received a copy of the GNU Lesser General Public License
  3009. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  3010. */
  3011. /** @file filter.js
  3012. * @authors:
  3013. * Jeffrey Wilcke <jeff@ethdev.com>
  3014. * Marek Kotewicz <marek@ethdev.com>
  3015. * Marian Oancea <marian@ethdev.com>
  3016. * Fabian Vogelsteller <fabian@ethdev.com>
  3017. * Gav Wood <g@ethdev.com>
  3018. * @date 2014
  3019. */
  3020. var formatters = require('./formatters');
  3021. var utils = require('../utils/utils');
  3022. /**
  3023. * Converts a given topic to a hex string, but also allows null values.
  3024. *
  3025. * @param {Mixed} value
  3026. * @return {String}
  3027. */
  3028. var toTopic = function(value){
  3029. if(value === null || typeof value === 'undefined')
  3030. return null;
  3031. value = String(value);
  3032. if(value.indexOf('0x') === 0)
  3033. return value;
  3034. else
  3035. return utils.fromUtf8(value);
  3036. };
  3037. /// This method should be called on options object, to verify deprecated properties && lazy load dynamic ones
  3038. /// @param should be string or object
  3039. /// @returns options string or object
  3040. var getOptions = function (options, type) {
  3041. /*jshint maxcomplexity: 6 */
  3042. if (utils.isString(options)) {
  3043. return options;
  3044. }
  3045. options = options || {};
  3046. switch(type) {
  3047. case 'eth':
  3048. // make sure topics, get converted to hex
  3049. options.topics = options.topics || [];
  3050. options.topics = options.topics.map(function(topic){
  3051. return (utils.isArray(topic)) ? topic.map(toTopic) : toTopic(topic);
  3052. });
  3053. return {
  3054. topics: options.topics,
  3055. from: options.from,
  3056. to: options.to,
  3057. address: options.address,
  3058. fromBlock: formatters.inputBlockNumberFormatter(options.fromBlock),
  3059. toBlock: formatters.inputBlockNumberFormatter(options.toBlock)
  3060. };
  3061. case 'shh':
  3062. return options;
  3063. }
  3064. };
  3065. /**
  3066. Adds the callback and sets up the methods, to iterate over the results.
  3067. @method getLogsAtStart
  3068. @param {Object} self
  3069. @param {function} callback
  3070. */
  3071. var getLogsAtStart = function(self, callback){
  3072. // call getFilterLogs for the first watch callback start
  3073. if (!utils.isString(self.options)) {
  3074. self.get(function (err, messages) {
  3075. // don't send all the responses to all the watches again... just to self one
  3076. if (err) {
  3077. callback(err);
  3078. }
  3079. if(utils.isArray(messages)) {
  3080. messages.forEach(function (message) {
  3081. callback(null, message);
  3082. });
  3083. }
  3084. });
  3085. }
  3086. };
  3087. /**
  3088. Adds the callback and sets up the methods, to iterate over the results.
  3089. @method pollFilter
  3090. @param {Object} self
  3091. */
  3092. var pollFilter = function(self) {
  3093. var onMessage = function (error, messages) {
  3094. if (error) {
  3095. return self.callbacks.forEach(function (callback) {
  3096. callback(error);
  3097. });
  3098. }
  3099. if(utils.isArray(messages)) {
  3100. messages.forEach(function (message) {
  3101. message = self.formatter ? self.formatter(message) : message;
  3102. self.callbacks.forEach(function (callback) {
  3103. callback(null, message);
  3104. });
  3105. });
  3106. }
  3107. };
  3108. self.requestManager.startPolling({
  3109. method: self.implementation.poll.call,
  3110. params: [self.filterId],
  3111. }, self.filterId, onMessage, self.stopWatching.bind(self));
  3112. };
  3113. var Filter = function (options, type, requestManager, methods, formatter, callback, filterCreationErrorCallback) {
  3114. var self = this;
  3115. var implementation = {};
  3116. methods.forEach(function (method) {
  3117. method.setRequestManager(requestManager);
  3118. method.attachToObject(implementation);
  3119. });
  3120. this.requestManager = requestManager;
  3121. this.options = getOptions(options, type);
  3122. this.implementation = implementation;
  3123. this.filterId = null;
  3124. this.callbacks = [];
  3125. this.getLogsCallbacks = [];
  3126. this.pollFilters = [];
  3127. this.formatter = formatter;
  3128. this.implementation.newFilter(this.options, function(error, id){
  3129. if(error) {
  3130. self.callbacks.forEach(function(cb){
  3131. cb(error);
  3132. });
  3133. if (typeof filterCreationErrorCallback === 'function') {
  3134. filterCreationErrorCallback(error);
  3135. }
  3136. } else {
  3137. self.filterId = id;
  3138. // check if there are get pending callbacks as a consequence
  3139. // of calling get() with filterId unassigned.
  3140. self.getLogsCallbacks.forEach(function (cb){
  3141. self.get(cb);
  3142. });
  3143. self.getLogsCallbacks = [];
  3144. // get filter logs for the already existing watch calls
  3145. self.callbacks.forEach(function(cb){
  3146. getLogsAtStart(self, cb);
  3147. });
  3148. if(self.callbacks.length > 0)
  3149. pollFilter(self);
  3150. // start to watch immediately
  3151. if(typeof callback === 'function') {
  3152. return self.watch(callback);
  3153. }
  3154. }
  3155. });
  3156. return this;
  3157. };
  3158. Filter.prototype.watch = function (callback) {
  3159. this.callbacks.push(callback);
  3160. if(this.filterId) {
  3161. getLogsAtStart(this, callback);
  3162. pollFilter(this);
  3163. }
  3164. return this;
  3165. };
  3166. Filter.prototype.stopWatching = function (callback) {
  3167. this.requestManager.stopPolling(this.filterId);
  3168. this.callbacks = [];
  3169. // remove filter async
  3170. if (callback) {
  3171. this.implementation.uninstallFilter(this.filterId, callback);
  3172. } else {
  3173. return this.implementation.uninstallFilter(this.filterId);
  3174. }
  3175. };
  3176. Filter.prototype.get = function (callback) {
  3177. var self = this;
  3178. if (utils.isFunction(callback)) {
  3179. if (this.filterId === null) {
  3180. // If filterId is not set yet, call it back
  3181. // when newFilter() assigns it.
  3182. this.getLogsCallbacks.push(callback);
  3183. } else {
  3184. this.implementation.getLogs(this.filterId, function(err, res){
  3185. if (err) {
  3186. callback(err);
  3187. } else {
  3188. callback(null, res.map(function (log) {
  3189. return self.formatter ? self.formatter(log) : log;
  3190. }));
  3191. }
  3192. });
  3193. }
  3194. } else {
  3195. if (this.filterId === null) {
  3196. throw new Error('Filter ID Error: filter().get() can\'t be chained synchronous, please provide a callback for the get() method.');
  3197. }
  3198. var logs = this.implementation.getLogs(this.filterId);
  3199. return logs.map(function (log) {
  3200. return self.formatter ? self.formatter(log) : log;
  3201. });
  3202. }
  3203. return this;
  3204. };
  3205. module.exports = Filter;
  3206. },{"../utils/utils":20,"./formatters":30}],30:[function(require,module,exports){
  3207. 'use strict'
  3208. /*
  3209. This file is part of web3.js.
  3210. web3.js is free software: you can redistribute it and/or modify
  3211. it under the terms of the GNU Lesser General Public License as published by
  3212. the Free Software Foundation, either version 3 of the License, or
  3213. (at your option) any later version.
  3214. web3.js is distributed in the hope that it will be useful,
  3215. but WITHOUT ANY WARRANTY; without even the implied warranty of
  3216. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  3217. GNU Lesser General Public License for more details.
  3218. You should have received a copy of the GNU Lesser General Public License
  3219. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  3220. */
  3221. /**
  3222. * @file formatters.js
  3223. * @author Marek Kotewicz <marek@ethdev.com>
  3224. * @author Fabian Vogelsteller <fabian@ethdev.com>
  3225. * @date 2015
  3226. */
  3227. var utils = require('../utils/utils');
  3228. var config = require('../utils/config');
  3229. var Iban = require('./iban');
  3230. /**
  3231. * Should the format output to a big number
  3232. *
  3233. * @method outputBigNumberFormatter
  3234. * @param {String|Number|BigNumber}
  3235. * @returns {BigNumber} object
  3236. */
  3237. var outputBigNumberFormatter = function (number) {
  3238. return utils.toBigNumber(number);
  3239. };
  3240. var isPredefinedBlockNumber = function (blockNumber) {
  3241. return blockNumber === 'latest' || blockNumber === 'pending' || blockNumber === 'earliest';
  3242. };
  3243. var inputDefaultBlockNumberFormatter = function (blockNumber) {
  3244. if (blockNumber === undefined) {
  3245. return config.defaultBlock;
  3246. }
  3247. return inputBlockNumberFormatter(blockNumber);
  3248. };
  3249. var inputBlockNumberFormatter = function (blockNumber) {
  3250. if (blockNumber === undefined) {
  3251. return undefined;
  3252. } else if (isPredefinedBlockNumber(blockNumber)) {
  3253. return blockNumber;
  3254. }
  3255. return utils.toHex(blockNumber);
  3256. };
  3257. /**
  3258. * Formats the input of a transaction and converts all values to HEX
  3259. *
  3260. * @method inputCallFormatter
  3261. * @param {Object} transaction options
  3262. * @returns object
  3263. */
  3264. var inputCallFormatter = function (options){
  3265. options.from = options.from || config.defaultAccount;
  3266. if (options.from) {
  3267. options.from = inputAddressFormatter(options.from);
  3268. }
  3269. if (options.to) { // it might be contract creation
  3270. options.to = inputAddressFormatter(options.to);
  3271. }
  3272. ['gasPrice', 'gas', 'value', 'nonce'].filter(function (key) {
  3273. return options[key] !== undefined;
  3274. }).forEach(function(key){
  3275. options[key] = utils.fromDecimal(options[key]);
  3276. });
  3277. return options;
  3278. };
  3279. /**
  3280. * Formats the input of a transaction and converts all values to HEX
  3281. *
  3282. * @method inputTransactionFormatter
  3283. * @param {Object} transaction options
  3284. * @returns object
  3285. */
  3286. var inputTransactionFormatter = function (options){
  3287. options.from = options.from || config.defaultAccount;
  3288. options.from = inputAddressFormatter(options.from);
  3289. if (options.to) { // it might be contract creation
  3290. options.to = inputAddressFormatter(options.to);
  3291. }
  3292. ['gasPrice', 'gas', 'value', 'nonce'].filter(function (key) {
  3293. return options[key] !== undefined;
  3294. }).forEach(function(key){
  3295. options[key] = utils.fromDecimal(options[key]);
  3296. });
  3297. return options;
  3298. };
  3299. /**
  3300. * Formats the output of a transaction to its proper values
  3301. *
  3302. * @method outputTransactionFormatter
  3303. * @param {Object} tx
  3304. * @returns {Object}
  3305. */
  3306. var outputTransactionFormatter = function (tx){
  3307. if(tx.blockNumber !== null)
  3308. tx.blockNumber = utils.toDecimal(tx.blockNumber);
  3309. if(tx.transactionIndex !== null)
  3310. tx.transactionIndex = utils.toDecimal(tx.transactionIndex);
  3311. tx.nonce = utils.toDecimal(tx.nonce);
  3312. tx.gas = utils.toDecimal(tx.gas);
  3313. tx.gasPrice = utils.toBigNumber(tx.gasPrice);
  3314. tx.value = utils.toBigNumber(tx.value);
  3315. return tx;
  3316. };
  3317. /**
  3318. * Formats the output of a transaction receipt to its proper values
  3319. *
  3320. * @method outputTransactionReceiptFormatter
  3321. * @param {Object} receipt
  3322. * @returns {Object}
  3323. */
  3324. var outputTransactionReceiptFormatter = function (receipt){
  3325. if(receipt.blockNumber !== null)
  3326. receipt.blockNumber = utils.toDecimal(receipt.blockNumber);
  3327. if(receipt.transactionIndex !== null)
  3328. receipt.transactionIndex = utils.toDecimal(receipt.transactionIndex);
  3329. receipt.cumulativeGasUsed = utils.toDecimal(receipt.cumulativeGasUsed);
  3330. receipt.gasUsed = utils.toDecimal(receipt.gasUsed);
  3331. if(utils.isArray(receipt.logs)) {
  3332. receipt.logs = receipt.logs.map(function(log){
  3333. return outputLogFormatter(log);
  3334. });
  3335. }
  3336. return receipt;
  3337. };
  3338. /**
  3339. * Formats the output of a transaction original data and receipt to its proper values
  3340. *
  3341. * @method outputTransactionDataAndReceiptFormatter
  3342. * @param {Object} dataAndReceipt
  3343. * @returns {Object}
  3344. */
  3345. var outputTransactionDataAndReceiptFormatter = function (dataAndReceipt){
  3346. if(dataAndReceipt.receipt.blockNumber !== null)
  3347. dataAndReceipt.receipt.blockNumber = utils.toDecimal(dataAndReceipt.receipt.blockNumber);
  3348. if(dataAndReceipt.receipt.transactionIndex !== null)
  3349. dataAndReceipt.receipt.transactionIndex = utils.toDecimal(dataAndReceipt.receipt.transactionIndex);
  3350. dataAndReceipt.receipt.cumulativeGasUsed = utils.toDecimal(dataAndReceipt.receipt.cumulativeGasUsed);
  3351. dataAndReceipt.receipt.gasUsed = utils.toDecimal(dataAndReceipt.receipt.gasUsed);
  3352. if(utils.isArray(dataAndReceipt.receipt.logs)) {
  3353. dataAndReceipt.receipt.logs = dataAndReceipt.receipt.logs.map(function(log){
  3354. return outputLogFormatter(log);
  3355. });
  3356. }
  3357. if(dataAndReceipt.txData.blockNumber !== null)
  3358. dataAndReceipt.txData.blockNumber = utils.toDecimal(dataAndReceipt.txData.blockNumber);
  3359. if(dataAndReceipt.txData.transactionIndex !== null)
  3360. dataAndReceipt.txData.transactionIndex = utils.toDecimal(dataAndReceipt.txData.transactionIndex);
  3361. dataAndReceipt.txData.nonce = utils.toDecimal(dataAndReceipt.txData.nonce);
  3362. dataAndReceipt.txData.gas = utils.toDecimal(dataAndReceipt.txData.gas);
  3363. dataAndReceipt.txData.gasPrice = utils.toBigNumber(dataAndReceipt.txData.gasPrice);
  3364. dataAndReceipt.txData.value = utils.toBigNumber(dataAndReceipt.txData.value);
  3365. return dataAndReceipt;
  3366. };
  3367. /**
  3368. * Formats the output of a block to its proper values
  3369. *
  3370. * @method outputBlockFormatter
  3371. * @param {Object} block
  3372. * @returns {Object}
  3373. */
  3374. var outputBlockFormatter = function(block) {
  3375. // transform to number
  3376. block.gasLimit = utils.toDecimal(block.gasLimit);
  3377. block.gasUsed = utils.toDecimal(block.gasUsed);
  3378. block.size = utils.toDecimal(block.size);
  3379. block.timestamp = utils.toDecimal(block.timestamp);
  3380. if(block.number !== null)
  3381. block.number = utils.toDecimal(block.number);
  3382. block.difficulty = utils.toBigNumber(block.difficulty);
  3383. block.totalDifficulty = utils.toBigNumber(block.totalDifficulty);
  3384. if (utils.isArray(block.transactions)) {
  3385. block.transactions.forEach(function(item){
  3386. if(!utils.isString(item))
  3387. return outputTransactionFormatter(item);
  3388. });
  3389. }
  3390. return block;
  3391. };
  3392. /**
  3393. * Formats the output of a log
  3394. *
  3395. * @method outputLogFormatter
  3396. * @param {Object} log object
  3397. * @returns {Object} log
  3398. */
  3399. var outputLogFormatter = function(log) {
  3400. if(log.blockNumber)
  3401. log.blockNumber = utils.toDecimal(log.blockNumber);
  3402. if(log.transactionIndex)
  3403. log.transactionIndex = utils.toDecimal(log.transactionIndex);
  3404. if(log.logIndex)
  3405. log.logIndex = utils.toDecimal(log.logIndex);
  3406. return log;
  3407. };
  3408. /**
  3409. * Formats the input of a whisper post and converts all values to HEX
  3410. *
  3411. * @method inputPostFormatter
  3412. * @param {Object} transaction object
  3413. * @returns {Object}
  3414. */
  3415. var inputPostFormatter = function(post) {
  3416. // post.payload = utils.toHex(post.payload);
  3417. post.ttl = utils.fromDecimal(post.ttl);
  3418. post.workToProve = utils.fromDecimal(post.workToProve);
  3419. post.priority = utils.fromDecimal(post.priority);
  3420. // fallback
  3421. if (!utils.isArray(post.topics)) {
  3422. post.topics = post.topics ? [post.topics] : [];
  3423. }
  3424. // format the following options
  3425. post.topics = post.topics.map(function(topic){
  3426. // convert only if not hex
  3427. return (topic.indexOf('0x') === 0) ? topic : utils.fromUtf8(topic);
  3428. });
  3429. return post;
  3430. };
  3431. /**
  3432. * Formats the output of a received post message
  3433. *
  3434. * @method outputPostFormatter
  3435. * @param {Object}
  3436. * @returns {Object}
  3437. */
  3438. var outputPostFormatter = function(post){
  3439. post.expiry = utils.toDecimal(post.expiry);
  3440. post.sent = utils.toDecimal(post.sent);
  3441. post.ttl = utils.toDecimal(post.ttl);
  3442. post.workProved = utils.toDecimal(post.workProved);
  3443. // post.payloadRaw = post.payload;
  3444. // post.payload = utils.toAscii(post.payload);
  3445. // if (utils.isJson(post.payload)) {
  3446. // post.payload = JSON.parse(post.payload);
  3447. // }
  3448. // format the following options
  3449. if (!post.topics) {
  3450. post.topics = [];
  3451. }
  3452. post.topics = post.topics.map(function(topic){
  3453. return utils.toAscii(topic);
  3454. });
  3455. return post;
  3456. };
  3457. var inputAddressFormatter = function (address) {
  3458. var iban = new Iban(address);
  3459. if (iban.isValid() && iban.isDirect()) {
  3460. return '0x' + iban.address();
  3461. } else if (utils.isStrictAddress(address)) {
  3462. return address;
  3463. } else if (utils.isAddress(address)) {
  3464. return '0x' + address;
  3465. }
  3466. throw new Error('invalid address');
  3467. };
  3468. var outputSyncingFormatter = function(result) {
  3469. if (!result) {
  3470. return result;
  3471. }
  3472. result.startingBlock = utils.toDecimal(result.startingBlock);
  3473. result.currentBlock = utils.toDecimal(result.currentBlock);
  3474. result.highestBlock = utils.toDecimal(result.highestBlock);
  3475. if (result.knownStates) {
  3476. result.knownStates = utils.toDecimal(result.knownStates);
  3477. result.pulledStates = utils.toDecimal(result.pulledStates);
  3478. }
  3479. return result;
  3480. };
  3481. module.exports = {
  3482. inputDefaultBlockNumberFormatter: inputDefaultBlockNumberFormatter,
  3483. inputBlockNumberFormatter: inputBlockNumberFormatter,
  3484. inputCallFormatter: inputCallFormatter,
  3485. inputTransactionFormatter: inputTransactionFormatter,
  3486. inputAddressFormatter: inputAddressFormatter,
  3487. inputPostFormatter: inputPostFormatter,
  3488. outputBigNumberFormatter: outputBigNumberFormatter,
  3489. outputTransactionFormatter: outputTransactionFormatter,
  3490. outputTransactionReceiptFormatter: outputTransactionReceiptFormatter,
  3491. outputTransactionDataAndReceiptFormatter: outputTransactionDataAndReceiptFormatter,
  3492. outputBlockFormatter: outputBlockFormatter,
  3493. outputLogFormatter: outputLogFormatter,
  3494. outputPostFormatter: outputPostFormatter,
  3495. outputSyncingFormatter: outputSyncingFormatter
  3496. };
  3497. },{"../utils/config":18,"../utils/utils":20,"./iban":33}],31:[function(require,module,exports){
  3498. /*
  3499. This file is part of web3.js.
  3500. web3.js is free software: you can redistribute it and/or modify
  3501. it under the terms of the GNU Lesser General Public License as published by
  3502. the Free Software Foundation, either version 3 of the License, or
  3503. (at your option) any later version.
  3504. web3.js is distributed in the hope that it will be useful,
  3505. but WITHOUT ANY WARRANTY; without even the implied warranty of
  3506. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  3507. GNU Lesser General Public License for more details.
  3508. You should have received a copy of the GNU Lesser General Public License
  3509. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  3510. */
  3511. /**
  3512. * @file function.js
  3513. * @author Marek Kotewicz <marek@ethdev.com>
  3514. * @date 2015
  3515. */
  3516. var coder = require('../solidity/coder');
  3517. var utils = require('../utils/utils');
  3518. var errors = require('./errors');
  3519. var formatters = require('./formatters');
  3520. var sha3 = require('../utils/sha3');
  3521. /**
  3522. * This prototype should be used to call/sendTransaction to solidity functions
  3523. */
  3524. var SolidityFunction = function (eth, json, address) {
  3525. this._eth = eth;
  3526. this._inputTypes = json.inputs.map(function (i) {
  3527. return i.type;
  3528. });
  3529. this._outputTypes = json.outputs.map(function (i) {
  3530. return i.type;
  3531. });
  3532. this._constant = json.constant;
  3533. this._payable = json.payable;
  3534. this._name = utils.transformToFullName(json);
  3535. this._address = address;
  3536. };
  3537. SolidityFunction.prototype.extractCallback = function (args) {
  3538. if (utils.isFunction(args[args.length - 1])) {
  3539. return args.pop(); // modify the args array!
  3540. }
  3541. };
  3542. SolidityFunction.prototype.extractDefaultBlock = function (args) {
  3543. if (args.length > this._inputTypes.length && !utils.isObject(args[args.length -1])) {
  3544. return formatters.inputDefaultBlockNumberFormatter(args.pop()); // modify the args array!
  3545. }
  3546. };
  3547. /**
  3548. * Should be called to check if the number of arguments is correct
  3549. *
  3550. * @method validateArgs
  3551. * @param {Array} arguments
  3552. * @throws {Error} if it is not
  3553. */
  3554. SolidityFunction.prototype.validateArgs = function (args) {
  3555. var inputArgs = args.filter(function (a) {
  3556. // filter the options object but not arguments that are arrays
  3557. return !( (utils.isObject(a) === true) &&
  3558. (utils.isArray(a) === false) &&
  3559. (utils.isBigNumber(a) === false)
  3560. );
  3561. });
  3562. if (inputArgs.length !== this._inputTypes.length) {
  3563. throw errors.InvalidNumberOfSolidityArgs();
  3564. }
  3565. };
  3566. /**
  3567. * Should be used to create payload from arguments
  3568. *
  3569. * @method toPayload
  3570. * @param {Array} solidity function params
  3571. * @param {Object} optional payload options
  3572. */
  3573. SolidityFunction.prototype.toPayload = function (args) {
  3574. var options = {};
  3575. if (args.length > this._inputTypes.length && utils.isObject(args[args.length -1])) {
  3576. options = args[args.length - 1];
  3577. }
  3578. this.validateArgs(args);
  3579. options.to = this._address;
  3580. options.data = '0x' + this.signature() + coder.encodeParams(this._inputTypes, args);
  3581. return options;
  3582. };
  3583. /**
  3584. * Should be used to get function signature
  3585. *
  3586. * @method signature
  3587. * @return {String} function signature
  3588. */
  3589. SolidityFunction.prototype.signature = function () {
  3590. return sha3(this._name).slice(0, 8);
  3591. };
  3592. SolidityFunction.prototype.unpackOutput = function (output) {
  3593. if (!output) {
  3594. return;
  3595. }
  3596. output = output.length >= 2 ? output.slice(2) : output;
  3597. var result = coder.decodeParams(this._outputTypes, output);
  3598. return result.length === 1 ? result[0] : result;
  3599. };
  3600. /**
  3601. * Calls a contract function.
  3602. *
  3603. * @method call
  3604. * @param {...Object} Contract function arguments
  3605. * @param {function} If the last argument is a function, the contract function
  3606. * call will be asynchronous, and the callback will be passed the
  3607. * error and result.
  3608. * @return {String} output bytes
  3609. */
  3610. SolidityFunction.prototype.call = function () {
  3611. var args = Array.prototype.slice.call(arguments).filter(function (a) {return a !== undefined; });
  3612. var callback = this.extractCallback(args);
  3613. var defaultBlock = this.extractDefaultBlock(args);
  3614. var payload = this.toPayload(args);
  3615. if (!callback) {
  3616. var output = this._eth.call(payload, defaultBlock);
  3617. return this.unpackOutput(output);
  3618. }
  3619. var self = this;
  3620. this._eth.call(payload, defaultBlock, function (error, output) {
  3621. if (error) return callback(error, null);
  3622. var unpacked = null;
  3623. try {
  3624. unpacked = self.unpackOutput(output);
  3625. }
  3626. catch (e) {
  3627. error = e;
  3628. }
  3629. callback(error, unpacked);
  3630. });
  3631. };
  3632. /**
  3633. * Should be used to sendTransaction to solidity function
  3634. *
  3635. * @method sendTransaction
  3636. */
  3637. SolidityFunction.prototype.sendTransaction = function () {
  3638. var args = Array.prototype.slice.call(arguments).filter(function (a) {return a !== undefined; });
  3639. var callback = this.extractCallback(args);
  3640. var payload = this.toPayload(args);
  3641. if (payload.value > 0 && !this._payable) {
  3642. throw new Error('Cannot send value to non-payable function');
  3643. }
  3644. if (!callback) {
  3645. return this._eth.sendTransaction(payload);
  3646. }
  3647. this._eth.sendTransaction(payload, callback);
  3648. };
  3649. /**
  3650. * Should be used to estimateGas of solidity function
  3651. *
  3652. * @method estimateGas
  3653. */
  3654. SolidityFunction.prototype.estimateGas = function () {
  3655. var args = Array.prototype.slice.call(arguments);
  3656. var callback = this.extractCallback(args);
  3657. var payload = this.toPayload(args);
  3658. if (!callback) {
  3659. return this._eth.estimateGas(payload);
  3660. }
  3661. this._eth.estimateGas(payload, callback);
  3662. };
  3663. /**
  3664. * Return the encoded data of the call
  3665. *
  3666. * @method getData
  3667. * @return {String} the encoded data
  3668. */
  3669. SolidityFunction.prototype.getData = function () {
  3670. var args = Array.prototype.slice.call(arguments);
  3671. var payload = this.toPayload(args);
  3672. return payload.data;
  3673. };
  3674. /**
  3675. * Should be used to get function display name
  3676. *
  3677. * @method displayName
  3678. * @return {String} display name of the function
  3679. */
  3680. SolidityFunction.prototype.displayName = function () {
  3681. return utils.extractDisplayName(this._name);
  3682. };
  3683. /**
  3684. * Should be used to get function type name
  3685. *
  3686. * @method typeName
  3687. * @return {String} type name of the function
  3688. */
  3689. SolidityFunction.prototype.typeName = function () {
  3690. return utils.extractTypeName(this._name);
  3691. };
  3692. /**
  3693. * Should be called to get rpc requests from solidity function
  3694. *
  3695. * @method request
  3696. * @returns {Object}
  3697. */
  3698. SolidityFunction.prototype.request = function () {
  3699. var args = Array.prototype.slice.call(arguments);
  3700. var callback = this.extractCallback(args);
  3701. var payload = this.toPayload(args);
  3702. var format = this.unpackOutput.bind(this);
  3703. return {
  3704. method: this._constant ? 'eth_call' : 'eth_sendTransaction',
  3705. callback: callback,
  3706. params: [payload],
  3707. format: format
  3708. };
  3709. };
  3710. /**
  3711. * Should be called to execute function
  3712. *
  3713. * @method execute
  3714. */
  3715. SolidityFunction.prototype.execute = function () {
  3716. var transaction = !this._constant;
  3717. // send transaction
  3718. if (transaction) {
  3719. return this.sendTransaction.apply(this, Array.prototype.slice.call(arguments));
  3720. }
  3721. // call
  3722. return this.call.apply(this, Array.prototype.slice.call(arguments));
  3723. };
  3724. /**
  3725. * Should be called to attach function to contract
  3726. *
  3727. * @method attachToContract
  3728. * @param {Contract}
  3729. */
  3730. SolidityFunction.prototype.attachToContract = function (contract) {
  3731. var execute = this.execute.bind(this);
  3732. execute.request = this.request.bind(this);
  3733. execute.call = this.call.bind(this);
  3734. execute.sendTransaction = this.sendTransaction.bind(this);
  3735. execute.estimateGas = this.estimateGas.bind(this);
  3736. execute.getData = this.getData.bind(this);
  3737. var displayName = this.displayName();
  3738. if (!contract[displayName]) {
  3739. contract[displayName] = execute;
  3740. }
  3741. contract[displayName][this.typeName()] = execute; // circular!!!!
  3742. };
  3743. module.exports = SolidityFunction;
  3744. },{"../solidity/coder":7,"../utils/sha3":19,"../utils/utils":20,"./errors":26,"./formatters":30}],32:[function(require,module,exports){
  3745. /*
  3746. This file is part of web3.js.
  3747. web3.js is free software: you can redistribute it and/or modify
  3748. it under the terms of the GNU Lesser General Public License as published by
  3749. the Free Software Foundation, either version 3 of the License, or
  3750. (at your option) any later version.
  3751. web3.js is distributed in the hope that it will be useful,
  3752. but WITHOUT ANY WARRANTY; without even the implied warranty of
  3753. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  3754. GNU Lesser General Public License for more details.
  3755. You should have received a copy of the GNU Lesser General Public License
  3756. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  3757. */
  3758. /** @file httpprovider.js
  3759. * @authors:
  3760. * Marek Kotewicz <marek@ethdev.com>
  3761. * Marian Oancea <marian@ethdev.com>
  3762. * Fabian Vogelsteller <fabian@ethdev.com>
  3763. * @date 2015
  3764. */
  3765. var errors = require('./errors');
  3766. // workaround to use httpprovider in different envs
  3767. // browser
  3768. if (typeof window !== 'undefined' && window.XMLHttpRequest) {
  3769. XMLHttpRequest = window.XMLHttpRequest; // jshint ignore: line
  3770. // node
  3771. } else {
  3772. XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest; // jshint ignore: line
  3773. }
  3774. var XHR2 = require('xhr2'); // jshint ignore: line
  3775. /**
  3776. * HttpProvider should be used to send rpc calls over http
  3777. */
  3778. var HttpProvider = function (host, timeout, user, password) {
  3779. this.host = host || 'http://localhost:8545';
  3780. this.timeout = timeout || 0;
  3781. this.user = user;
  3782. this.password = password;
  3783. };
  3784. /**
  3785. * Should be called to prepare new XMLHttpRequest
  3786. *
  3787. * @method prepareRequest
  3788. * @param {Boolean} true if request should be async
  3789. * @return {XMLHttpRequest} object
  3790. */
  3791. HttpProvider.prototype.prepareRequest = function (async) {
  3792. var request;
  3793. if (async) {
  3794. request = new XHR2();
  3795. request.timeout = this.timeout;
  3796. } else {
  3797. request = new XMLHttpRequest();
  3798. }
  3799. request.open('POST', this.host, async);
  3800. if (this.user && this.password) {
  3801. var auth = 'Basic ' + new Buffer(this.user + ':' + this.password).toString('base64');
  3802. request.setRequestHeader('Authorization', auth);
  3803. } request.setRequestHeader('Content-Type', 'application/json');
  3804. return request;
  3805. };
  3806. /**
  3807. * Should be called to make sync request
  3808. *
  3809. * @method send
  3810. * @param {Object} payload
  3811. * @return {Object} result
  3812. */
  3813. HttpProvider.prototype.send = function (payload) {
  3814. var request = this.prepareRequest(false);
  3815. try {
  3816. request.send(JSON.stringify(payload));
  3817. } catch (error) {
  3818. throw errors.InvalidConnection(this.host);
  3819. }
  3820. var result = request.responseText;
  3821. try {
  3822. result = JSON.parse(result);
  3823. } catch (e) {
  3824. throw errors.InvalidResponse(request.responseText);
  3825. }
  3826. return result;
  3827. };
  3828. /**
  3829. * Should be used to make async request
  3830. *
  3831. * @method sendAsync
  3832. * @param {Object} payload
  3833. * @param {Function} callback triggered on end with (err, result)
  3834. */
  3835. HttpProvider.prototype.sendAsync = function (payload, callback) {
  3836. var request = this.prepareRequest(true);
  3837. request.onreadystatechange = function () {
  3838. if (request.readyState === 4 && request.timeout !== 1) {
  3839. var result = request.responseText;
  3840. var error = null;
  3841. try {
  3842. result = JSON.parse(result);
  3843. } catch (e) {
  3844. error = errors.InvalidResponse(request.responseText);
  3845. }
  3846. callback(error, result);
  3847. }
  3848. };
  3849. request.ontimeout = function () {
  3850. callback(errors.ConnectionTimeout(this.timeout));
  3851. };
  3852. try {
  3853. request.send(JSON.stringify(payload));
  3854. } catch (error) {
  3855. callback(errors.InvalidConnection(this.host));
  3856. }
  3857. };
  3858. /**
  3859. * Synchronously tries to make Http request
  3860. *
  3861. * @method isConnected
  3862. * @return {Boolean} returns true if request haven't failed. Otherwise false
  3863. */
  3864. HttpProvider.prototype.isConnected = function () {
  3865. try {
  3866. this.send({
  3867. id: 9999999999,
  3868. jsonrpc: '2.0',
  3869. method: 'net_listening',
  3870. params: []
  3871. });
  3872. return true;
  3873. } catch (e) {
  3874. return false;
  3875. }
  3876. };
  3877. module.exports = HttpProvider;
  3878. },{"./errors":26,"xhr2":86,"xmlhttprequest":17}],33:[function(require,module,exports){
  3879. /*
  3880. This file is part of web3.js.
  3881. web3.js is free software: you can redistribute it and/or modify
  3882. it under the terms of the GNU Lesser General Public License as published by
  3883. the Free Software Foundation, either version 3 of the License, or
  3884. (at your option) any later version.
  3885. web3.js is distributed in the hope that it will be useful,
  3886. but WITHOUT ANY WARRANTY; without even the implied warranty of
  3887. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  3888. GNU Lesser General Public License for more details.
  3889. You should have received a copy of the GNU Lesser General Public License
  3890. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  3891. */
  3892. /**
  3893. * @file iban.js
  3894. * @author Marek Kotewicz <marek@ethdev.com>
  3895. * @date 2015
  3896. */
  3897. var BigNumber = require('bignumber.js');
  3898. var padLeft = function (string, bytes) {
  3899. var result = string;
  3900. while (result.length < bytes * 2) {
  3901. result = '0' + result;
  3902. }
  3903. return result;
  3904. };
  3905. /**
  3906. * Prepare an IBAN for mod 97 computation by moving the first 4 chars to the end and transforming the letters to
  3907. * numbers (A = 10, B = 11, ..., Z = 35), as specified in ISO13616.
  3908. *
  3909. * @method iso13616Prepare
  3910. * @param {String} iban the IBAN
  3911. * @returns {String} the prepared IBAN
  3912. */
  3913. var iso13616Prepare = function (iban) {
  3914. var A = 'A'.charCodeAt(0);
  3915. var Z = 'Z'.charCodeAt(0);
  3916. iban = iban.toUpperCase();
  3917. iban = iban.substr(4) + iban.substr(0,4);
  3918. return iban.split('').map(function(n){
  3919. var code = n.charCodeAt(0);
  3920. if (code >= A && code <= Z){
  3921. // A = 10, B = 11, ... Z = 35
  3922. return code - A + 10;
  3923. } else {
  3924. return n;
  3925. }
  3926. }).join('');
  3927. };
  3928. /**
  3929. * Calculates the MOD 97 10 of the passed IBAN as specified in ISO7064.
  3930. *
  3931. * @method mod9710
  3932. * @param {String} iban
  3933. * @returns {Number}
  3934. */
  3935. var mod9710 = function (iban) {
  3936. var remainder = iban,
  3937. block;
  3938. while (remainder.length > 2){
  3939. block = remainder.slice(0, 9);
  3940. remainder = parseInt(block, 10) % 97 + remainder.slice(block.length);
  3941. }
  3942. return parseInt(remainder, 10) % 97;
  3943. };
  3944. /**
  3945. * This prototype should be used to create iban object from iban correct string
  3946. *
  3947. * @param {String} iban
  3948. */
  3949. var Iban = function (iban) {
  3950. this._iban = iban;
  3951. };
  3952. /**
  3953. * This method should be used to create iban object from ethereum address
  3954. *
  3955. * @method fromAddress
  3956. * @param {String} address
  3957. * @return {Iban} the IBAN object
  3958. */
  3959. Iban.fromAddress = function (address) {
  3960. var asBn = new BigNumber(address, 16);
  3961. var base36 = asBn.toString(36);
  3962. var padded = padLeft(base36, 15);
  3963. return Iban.fromBban(padded.toUpperCase());
  3964. };
  3965. /**
  3966. * Convert the passed BBAN to an IBAN for this country specification.
  3967. * Please note that <i>"generation of the IBAN shall be the exclusive responsibility of the bank/branch servicing the account"</i>.
  3968. * This method implements the preferred algorithm described in http://en.wikipedia.org/wiki/International_Bank_Account_Number#Generating_IBAN_check_digits
  3969. *
  3970. * @method fromBban
  3971. * @param {String} bban the BBAN to convert to IBAN
  3972. * @returns {Iban} the IBAN object
  3973. */
  3974. Iban.fromBban = function (bban) {
  3975. var countryCode = 'XE';
  3976. var remainder = mod9710(iso13616Prepare(countryCode + '00' + bban));
  3977. var checkDigit = ('0' + (98 - remainder)).slice(-2);
  3978. return new Iban(countryCode + checkDigit + bban);
  3979. };
  3980. /**
  3981. * Should be used to create IBAN object for given institution and identifier
  3982. *
  3983. * @method createIndirect
  3984. * @param {Object} options, required options are "institution" and "identifier"
  3985. * @return {Iban} the IBAN object
  3986. */
  3987. Iban.createIndirect = function (options) {
  3988. return Iban.fromBban('ETH' + options.institution + options.identifier);
  3989. };
  3990. /**
  3991. * Thos method should be used to check if given string is valid iban object
  3992. *
  3993. * @method isValid
  3994. * @param {String} iban string
  3995. * @return {Boolean} true if it is valid IBAN
  3996. */
  3997. Iban.isValid = function (iban) {
  3998. var i = new Iban(iban);
  3999. return i.isValid();
  4000. };
  4001. /**
  4002. * Should be called to check if iban is correct
  4003. *
  4004. * @method isValid
  4005. * @returns {Boolean} true if it is, otherwise false
  4006. */
  4007. Iban.prototype.isValid = function () {
  4008. return /^XE[0-9]{2}(ETH[0-9A-Z]{13}|[0-9A-Z]{30,31})$/.test(this._iban) &&
  4009. mod9710(iso13616Prepare(this._iban)) === 1;
  4010. };
  4011. /**
  4012. * Should be called to check if iban number is direct
  4013. *
  4014. * @method isDirect
  4015. * @returns {Boolean} true if it is, otherwise false
  4016. */
  4017. Iban.prototype.isDirect = function () {
  4018. return this._iban.length === 34 || this._iban.length === 35;
  4019. };
  4020. /**
  4021. * Should be called to check if iban number if indirect
  4022. *
  4023. * @method isIndirect
  4024. * @returns {Boolean} true if it is, otherwise false
  4025. */
  4026. Iban.prototype.isIndirect = function () {
  4027. return this._iban.length === 20;
  4028. };
  4029. /**
  4030. * Should be called to get iban checksum
  4031. * Uses the mod-97-10 checksumming protocol (ISO/IEC 7064:2003)
  4032. *
  4033. * @method checksum
  4034. * @returns {String} checksum
  4035. */
  4036. Iban.prototype.checksum = function () {
  4037. return this._iban.substr(2, 2);
  4038. };
  4039. /**
  4040. * Should be called to get institution identifier
  4041. * eg. XREG
  4042. *
  4043. * @method institution
  4044. * @returns {String} institution identifier
  4045. */
  4046. Iban.prototype.institution = function () {
  4047. return this.isIndirect() ? this._iban.substr(7, 4) : '';
  4048. };
  4049. /**
  4050. * Should be called to get client identifier within institution
  4051. * eg. GAVOFYORK
  4052. *
  4053. * @method client
  4054. * @returns {String} client identifier
  4055. */
  4056. Iban.prototype.client = function () {
  4057. return this.isIndirect() ? this._iban.substr(11) : '';
  4058. };
  4059. /**
  4060. * Should be called to get client direct address
  4061. *
  4062. * @method address
  4063. * @returns {String} client direct address
  4064. */
  4065. Iban.prototype.address = function () {
  4066. if (this.isDirect()) {
  4067. var base36 = this._iban.substr(4);
  4068. var asBn = new BigNumber(base36, 36);
  4069. return padLeft(asBn.toString(16), 20);
  4070. }
  4071. return '';
  4072. };
  4073. Iban.prototype.toString = function () {
  4074. return this._iban;
  4075. };
  4076. module.exports = Iban;
  4077. },{"bignumber.js":"bignumber.js"}],34:[function(require,module,exports){
  4078. /*
  4079. This file is part of web3.js.
  4080. web3.js is free software: you can redistribute it and/or modify
  4081. it under the terms of the GNU Lesser General Public License as published by
  4082. the Free Software Foundation, either version 3 of the License, or
  4083. (at your option) any later version.
  4084. web3.js is distributed in the hope that it will be useful,
  4085. but WITHOUT ANY WARRANTY; without even the implied warranty of
  4086. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  4087. GNU Lesser General Public License for more details.
  4088. You should have received a copy of the GNU Lesser General Public License
  4089. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  4090. */
  4091. /** @file ipcprovider.js
  4092. * @authors:
  4093. * Fabian Vogelsteller <fabian@ethdev.com>
  4094. * @date 2015
  4095. */
  4096. "use strict";
  4097. var utils = require('../utils/utils');
  4098. var errors = require('./errors');
  4099. var IpcProvider = function (path, net) {
  4100. var _this = this;
  4101. this.responseCallbacks = {};
  4102. this.path = path;
  4103. this.connection = net.connect({path: this.path});
  4104. this.connection.on('error', function(e){
  4105. console.error('IPC Connection Error', e);
  4106. _this._timeout();
  4107. });
  4108. this.connection.on('end', function(){
  4109. _this._timeout();
  4110. });
  4111. // LISTEN FOR CONNECTION RESPONSES
  4112. this.connection.on('data', function(data) {
  4113. /*jshint maxcomplexity: 6 */
  4114. _this._parseResponse(data.toString()).forEach(function(result){
  4115. var id = null;
  4116. // get the id which matches the returned id
  4117. if(utils.isArray(result)) {
  4118. result.forEach(function(load){
  4119. if(_this.responseCallbacks[load.id])
  4120. id = load.id;
  4121. });
  4122. } else {
  4123. id = result.id;
  4124. }
  4125. // fire the callback
  4126. if(_this.responseCallbacks[id]) {
  4127. _this.responseCallbacks[id](null, result);
  4128. delete _this.responseCallbacks[id];
  4129. }
  4130. });
  4131. });
  4132. };
  4133. /**
  4134. Will parse the response and make an array out of it.
  4135. @method _parseResponse
  4136. @param {String} data
  4137. */
  4138. IpcProvider.prototype._parseResponse = function(data) {
  4139. var _this = this,
  4140. returnValues = [];
  4141. // DE-CHUNKER
  4142. var dechunkedData = data
  4143. .replace(/\}[\n\r]?\{/g,'}|--|{') // }{
  4144. .replace(/\}\][\n\r]?\[\{/g,'}]|--|[{') // }][{
  4145. .replace(/\}[\n\r]?\[\{/g,'}|--|[{') // }[{
  4146. .replace(/\}\][\n\r]?\{/g,'}]|--|{') // }]{
  4147. .split('|--|');
  4148. dechunkedData.forEach(function(data){
  4149. // prepend the last chunk
  4150. if(_this.lastChunk)
  4151. data = _this.lastChunk + data;
  4152. var result = null;
  4153. try {
  4154. result = JSON.parse(data);
  4155. } catch(e) {
  4156. _this.lastChunk = data;
  4157. // start timeout to cancel all requests
  4158. clearTimeout(_this.lastChunkTimeout);
  4159. _this.lastChunkTimeout = setTimeout(function(){
  4160. _this._timeout();
  4161. throw errors.InvalidResponse(data);
  4162. }, 1000 * 15);
  4163. return;
  4164. }
  4165. // cancel timeout and set chunk to null
  4166. clearTimeout(_this.lastChunkTimeout);
  4167. _this.lastChunk = null;
  4168. if(result)
  4169. returnValues.push(result);
  4170. });
  4171. return returnValues;
  4172. };
  4173. /**
  4174. Get the adds a callback to the responseCallbacks object,
  4175. which will be called if a response matching the response Id will arrive.
  4176. @method _addResponseCallback
  4177. */
  4178. IpcProvider.prototype._addResponseCallback = function(payload, callback) {
  4179. var id = payload.id || payload[0].id;
  4180. var method = payload.method || payload[0].method;
  4181. this.responseCallbacks[id] = callback;
  4182. this.responseCallbacks[id].method = method;
  4183. };
  4184. /**
  4185. Timeout all requests when the end/error event is fired
  4186. @method _timeout
  4187. */
  4188. IpcProvider.prototype._timeout = function() {
  4189. for(var key in this.responseCallbacks) {
  4190. if(this.responseCallbacks.hasOwnProperty(key)){
  4191. this.responseCallbacks[key](errors.InvalidConnection('on IPC'));
  4192. delete this.responseCallbacks[key];
  4193. }
  4194. }
  4195. };
  4196. /**
  4197. Check if the current connection is still valid.
  4198. @method isConnected
  4199. */
  4200. IpcProvider.prototype.isConnected = function() {
  4201. var _this = this;
  4202. // try reconnect, when connection is gone
  4203. if(!_this.connection.writable)
  4204. _this.connection.connect({path: _this.path});
  4205. return !!this.connection.writable;
  4206. };
  4207. IpcProvider.prototype.send = function (payload) {
  4208. if(this.connection.writeSync) {
  4209. var result;
  4210. // try reconnect, when connection is gone
  4211. if(!this.connection.writable)
  4212. this.connection.connect({path: this.path});
  4213. var data = this.connection.writeSync(JSON.stringify(payload));
  4214. try {
  4215. result = JSON.parse(data);
  4216. } catch(e) {
  4217. throw errors.InvalidResponse(data);
  4218. }
  4219. return result;
  4220. } else {
  4221. throw new Error('You tried to send "'+ payload.method +'" synchronously. Synchronous requests are not supported by the IPC provider.');
  4222. }
  4223. };
  4224. IpcProvider.prototype.sendAsync = function (payload, callback) {
  4225. // try reconnect, when connection is gone
  4226. if(!this.connection.writable)
  4227. this.connection.connect({path: this.path});
  4228. this.connection.write(JSON.stringify(payload));
  4229. this._addResponseCallback(payload, callback);
  4230. };
  4231. module.exports = IpcProvider;
  4232. },{"../utils/utils":20,"./errors":26}],35:[function(require,module,exports){
  4233. /*
  4234. This file is part of web3.js.
  4235. web3.js is free software: you can redistribute it and/or modify
  4236. it under the terms of the GNU Lesser General Public License as published by
  4237. the Free Software Foundation, either version 3 of the License, or
  4238. (at your option) any later version.
  4239. web3.js is distributed in the hope that it will be useful,
  4240. but WITHOUT ANY WARRANTY; without even the implied warranty of
  4241. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  4242. GNU Lesser General Public License for more details.
  4243. You should have received a copy of the GNU Lesser General Public License
  4244. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  4245. */
  4246. /** @file jsonrpc.js
  4247. * @authors:
  4248. * Marek Kotewicz <marek@ethdev.com>
  4249. * Aaron Kumavis <aaron@kumavis.me>
  4250. * @date 2015
  4251. */
  4252. // Initialize Jsonrpc as a simple object with utility functions.
  4253. var Jsonrpc = {
  4254. messageId: 0
  4255. };
  4256. /**
  4257. * Should be called to valid json create payload object
  4258. *
  4259. * @method toPayload
  4260. * @param {Function} method of jsonrpc call, required
  4261. * @param {Array} params, an array of method params, optional
  4262. * @returns {Object} valid jsonrpc payload object
  4263. */
  4264. Jsonrpc.toPayload = function (method, params) {
  4265. if (!method)
  4266. console.error('jsonrpc method should be specified!');
  4267. // advance message ID
  4268. Jsonrpc.messageId++;
  4269. return {
  4270. jsonrpc: '2.0',
  4271. id: Jsonrpc.messageId,
  4272. method: method,
  4273. params: params || []
  4274. };
  4275. };
  4276. /**
  4277. * Should be called to check if jsonrpc response is valid
  4278. *
  4279. * @method isValidResponse
  4280. * @param {Object}
  4281. * @returns {Boolean} true if response is valid, otherwise false
  4282. */
  4283. Jsonrpc.isValidResponse = function (response) {
  4284. return Array.isArray(response) ? response.every(validateSingleMessage) : validateSingleMessage(response);
  4285. function validateSingleMessage(message){
  4286. return !!message &&
  4287. !message.error &&
  4288. message.jsonrpc === '2.0' &&
  4289. typeof message.id === 'number' &&
  4290. message.result !== undefined; // only undefined is not valid json object
  4291. }
  4292. };
  4293. /**
  4294. * Should be called to create batch payload object
  4295. *
  4296. * @method toBatchPayload
  4297. * @param {Array} messages, an array of objects with method (required) and params (optional) fields
  4298. * @returns {Array} batch payload
  4299. */
  4300. Jsonrpc.toBatchPayload = function (messages) {
  4301. return messages.map(function (message) {
  4302. return Jsonrpc.toPayload(message.method, message.params);
  4303. });
  4304. };
  4305. module.exports = Jsonrpc;
  4306. },{}],36:[function(require,module,exports){
  4307. /*
  4308. This file is part of web3.js.
  4309. web3.js is free software: you can redistribute it and/or modify
  4310. it under the terms of the GNU Lesser General Public License as published by
  4311. the Free Software Foundation, either version 3 of the License, or
  4312. (at your option) any later version.
  4313. web3.js is distributed in the hope that it will be useful,
  4314. but WITHOUT ANY WARRANTY; without even the implied warranty of
  4315. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  4316. GNU Lesser General Public License for more details.
  4317. You should have received a copy of the GNU Lesser General Public License
  4318. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  4319. */
  4320. /**
  4321. * @file method.js
  4322. * @author Marek Kotewicz <marek@ethdev.com>
  4323. * @date 2015
  4324. */
  4325. var utils = require('../utils/utils');
  4326. var errors = require('./errors');
  4327. var Method = function (options) {
  4328. this.name = options.name;
  4329. this.call = options.call;
  4330. this.params = options.params || 0;
  4331. this.inputFormatter = options.inputFormatter;
  4332. this.outputFormatter = options.outputFormatter;
  4333. this.requestManager = null;
  4334. };
  4335. Method.prototype.setRequestManager = function (rm) {
  4336. this.requestManager = rm;
  4337. };
  4338. /**
  4339. * Should be used to determine name of the jsonrpc method based on arguments
  4340. *
  4341. * @method getCall
  4342. * @param {Array} arguments
  4343. * @return {String} name of jsonrpc method
  4344. */
  4345. Method.prototype.getCall = function (args) {
  4346. return utils.isFunction(this.call) ? this.call(args) : this.call;
  4347. };
  4348. /**
  4349. * Should be used to extract callback from array of arguments. Modifies input param
  4350. *
  4351. * @method extractCallback
  4352. * @param {Array} arguments
  4353. * @return {Function|Null} callback, if exists
  4354. */
  4355. Method.prototype.extractCallback = function (args) {
  4356. if (utils.isFunction(args[args.length - 1])) {
  4357. return args.pop(); // modify the args array!
  4358. }
  4359. };
  4360. /**
  4361. * Should be called to check if the number of arguments is correct
  4362. *
  4363. * @method validateArgs
  4364. * @param {Array} arguments
  4365. * @throws {Error} if it is not
  4366. */
  4367. Method.prototype.validateArgs = function (args) {
  4368. if (args.length !== this.params) {
  4369. throw errors.InvalidNumberOfRPCParams();
  4370. }
  4371. };
  4372. /**
  4373. * Should be called to format input args of method
  4374. *
  4375. * @method formatInput
  4376. * @param {Array}
  4377. * @return {Array}
  4378. */
  4379. Method.prototype.formatInput = function (args) {
  4380. if (!this.inputFormatter) {
  4381. return args;
  4382. }
  4383. return this.inputFormatter.map(function (formatter, index) {
  4384. return formatter ? formatter(args[index]) : args[index];
  4385. });
  4386. };
  4387. /**
  4388. * Should be called to format output(result) of method
  4389. *
  4390. * @method formatOutput
  4391. * @param {Object}
  4392. * @return {Object}
  4393. */
  4394. Method.prototype.formatOutput = function (result) {
  4395. return this.outputFormatter && result ? this.outputFormatter(result) : result;
  4396. };
  4397. /**
  4398. * Should create payload from given input args
  4399. *
  4400. * @method toPayload
  4401. * @param {Array} args
  4402. * @return {Object}
  4403. */
  4404. Method.prototype.toPayload = function (args) {
  4405. var call = this.getCall(args);
  4406. var callback = this.extractCallback(args);
  4407. var params = this.formatInput(args);
  4408. this.validateArgs(params);
  4409. return {
  4410. method: call,
  4411. params: params,
  4412. callback: callback
  4413. };
  4414. };
  4415. Method.prototype.attachToObject = function (obj) {
  4416. var func = this.buildCall();
  4417. func.call = this.call; // TODO!!! that's ugly. filter.js uses it
  4418. var name = this.name.split('.');
  4419. if (name.length > 1) {
  4420. obj[name[0]] = obj[name[0]] || {};
  4421. obj[name[0]][name[1]] = func;
  4422. } else {
  4423. obj[name[0]] = func;
  4424. }
  4425. };
  4426. Method.prototype.buildCall = function() {
  4427. var method = this;
  4428. var send = function () {
  4429. var payload = method.toPayload(Array.prototype.slice.call(arguments));
  4430. if (payload.callback) {
  4431. return method.requestManager.sendAsync(payload, function (err, result) {
  4432. payload.callback(err, method.formatOutput(result));
  4433. });
  4434. }
  4435. return method.formatOutput(method.requestManager.send(payload));
  4436. };
  4437. send.request = this.request.bind(this);
  4438. return send;
  4439. };
  4440. /**
  4441. * Should be called to create pure JSONRPC request which can be used in batch request
  4442. *
  4443. * @method request
  4444. * @param {...} params
  4445. * @return {Object} jsonrpc request
  4446. */
  4447. Method.prototype.request = function () {
  4448. var payload = this.toPayload(Array.prototype.slice.call(arguments));
  4449. payload.format = this.formatOutput.bind(this);
  4450. return payload;
  4451. };
  4452. module.exports = Method;
  4453. },{"../utils/utils":20,"./errors":26}],37:[function(require,module,exports){
  4454. /*
  4455. This file is part of web3.js.
  4456. web3.js is free software: you can redistribute it and/or modify
  4457. it under the terms of the GNU Lesser General Public License as published by
  4458. the Free Software Foundation, either version 3 of the License, or
  4459. (at your option) any later version.
  4460. web3.js is distributed in the hope that it will be useful,
  4461. but WITHOUT ANY WARRANTY; without even the implied warranty of
  4462. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  4463. GNU Lesser General Public License for more details.
  4464. You should have received a copy of the GNU Lesser General Public License
  4465. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  4466. */
  4467. /** @file db.js
  4468. * @authors:
  4469. * Marek Kotewicz <marek@ethdev.com>
  4470. * @date 2015
  4471. */
  4472. var Method = require('../method');
  4473. var DB = function (web3) {
  4474. this._requestManager = web3._requestManager;
  4475. var self = this;
  4476. methods().forEach(function(method) {
  4477. method.attachToObject(self);
  4478. method.setRequestManager(web3._requestManager);
  4479. });
  4480. };
  4481. var methods = function () {
  4482. var putString = new Method({
  4483. name: 'putString',
  4484. call: 'db_putString',
  4485. params: 3
  4486. });
  4487. var getString = new Method({
  4488. name: 'getString',
  4489. call: 'db_getString',
  4490. params: 2
  4491. });
  4492. var putHex = new Method({
  4493. name: 'putHex',
  4494. call: 'db_putHex',
  4495. params: 3
  4496. });
  4497. var getHex = new Method({
  4498. name: 'getHex',
  4499. call: 'db_getHex',
  4500. params: 2
  4501. });
  4502. return [
  4503. putString, getString, putHex, getHex
  4504. ];
  4505. };
  4506. module.exports = DB;
  4507. },{"../method":36}],38:[function(require,module,exports){
  4508. /*
  4509. This file is part of web3.js.
  4510. web3.js is free software: you can redistribute it and/or modify
  4511. it under the terms of the GNU Lesser General Public License as published by
  4512. the Free Software Foundation, either version 3 of the License, or
  4513. (at your option) any later version.
  4514. web3.js is distributed in the hope that it will be useful,
  4515. but WITHOUT ANY WARRANTY; without even the implied warranty of
  4516. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  4517. GNU Lesser General Public License for more details.
  4518. You should have received a copy of the GNU Lesser General Public License
  4519. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  4520. */
  4521. /**
  4522. * @file eth.js
  4523. * @author Marek Kotewicz <marek@ethdev.com>
  4524. * @author Fabian Vogelsteller <fabian@ethdev.com>
  4525. * @date 2015
  4526. */
  4527. "use strict";
  4528. var formatters = require('../formatters');
  4529. var utils = require('../../utils/utils');
  4530. var Method = require('../method');
  4531. var Property = require('../property');
  4532. var c = require('../../utils/config');
  4533. var Contract = require('../contract');
  4534. var watches = require('./watches');
  4535. var Filter = require('../filter');
  4536. var IsSyncing = require('../syncing');
  4537. var namereg = require('../namereg');
  4538. var Iban = require('../iban');
  4539. var transfer = require('../transfer');
  4540. var blockCall = function (args) {
  4541. return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? "eth_getBlockByHash" : "eth_getBlockByNumber";
  4542. };
  4543. var transactionFromBlockCall = function (args) {
  4544. return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getTransactionByBlockHashAndIndex' : 'eth_getTransactionByBlockNumberAndIndex';
  4545. };
  4546. var uncleCall = function (args) {
  4547. return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getUncleByBlockHashAndIndex' : 'eth_getUncleByBlockNumberAndIndex';
  4548. };
  4549. var getBlockTransactionCountCall = function (args) {
  4550. return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getBlockTransactionCountByHash' : 'eth_getBlockTransactionCountByNumber';
  4551. };
  4552. var uncleCountCall = function (args) {
  4553. return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getUncleCountByBlockHash' : 'eth_getUncleCountByBlockNumber';
  4554. };
  4555. function Eth(web3) {
  4556. this._requestManager = web3._requestManager;
  4557. var self = this;
  4558. methods().forEach(function(method) {
  4559. method.attachToObject(self);
  4560. method.setRequestManager(self._requestManager);
  4561. });
  4562. properties().forEach(function(p) {
  4563. p.attachToObject(self);
  4564. p.setRequestManager(self._requestManager);
  4565. });
  4566. this.iban = Iban;
  4567. this.sendIBANTransaction = transfer.bind(null, this);
  4568. }
  4569. Object.defineProperty(Eth.prototype, 'defaultBlock', {
  4570. get: function () {
  4571. return c.defaultBlock;
  4572. },
  4573. set: function (val) {
  4574. c.defaultBlock = val;
  4575. return val;
  4576. }
  4577. });
  4578. Object.defineProperty(Eth.prototype, 'defaultAccount', {
  4579. get: function () {
  4580. return c.defaultAccount;
  4581. },
  4582. set: function (val) {
  4583. c.defaultAccount = val;
  4584. return val;
  4585. }
  4586. });
  4587. var methods = function () {
  4588. var getBalance = new Method({
  4589. name: 'getBalance',
  4590. call: 'eth_getBalance',
  4591. params: 2,
  4592. inputFormatter: [formatters.inputAddressFormatter, formatters.inputDefaultBlockNumberFormatter],
  4593. outputFormatter: formatters.outputBigNumberFormatter
  4594. });
  4595. var getStorageAt = new Method({
  4596. name: 'getStorageAt',
  4597. call: 'eth_getStorageAt',
  4598. params: 3,
  4599. inputFormatter: [null, utils.toHex, formatters.inputDefaultBlockNumberFormatter]
  4600. });
  4601. var getCode = new Method({
  4602. name: 'getCode',
  4603. call: 'eth_getCode',
  4604. params: 2,
  4605. inputFormatter: [formatters.inputAddressFormatter, formatters.inputDefaultBlockNumberFormatter]
  4606. });
  4607. var getBlock = new Method({
  4608. name: 'getBlock',
  4609. call: blockCall,
  4610. params: 2,
  4611. inputFormatter: [formatters.inputBlockNumberFormatter, function (val) { return !!val; }],
  4612. outputFormatter: formatters.outputBlockFormatter
  4613. });
  4614. var getUncle = new Method({
  4615. name: 'getUncle',
  4616. call: uncleCall,
  4617. params: 2,
  4618. inputFormatter: [formatters.inputBlockNumberFormatter, utils.toHex],
  4619. outputFormatter: formatters.outputBlockFormatter,
  4620. });
  4621. var getCompilers = new Method({
  4622. name: 'getCompilers',
  4623. call: 'eth_getCompilers',
  4624. params: 0
  4625. });
  4626. var getBlockTransactionCount = new Method({
  4627. name: 'getBlockTransactionCount',
  4628. call: getBlockTransactionCountCall,
  4629. params: 1,
  4630. inputFormatter: [formatters.inputBlockNumberFormatter],
  4631. outputFormatter: utils.toDecimal
  4632. });
  4633. var getBlockUncleCount = new Method({
  4634. name: 'getBlockUncleCount',
  4635. call: uncleCountCall,
  4636. params: 1,
  4637. inputFormatter: [formatters.inputBlockNumberFormatter],
  4638. outputFormatter: utils.toDecimal
  4639. });
  4640. var getTransaction = new Method({
  4641. name: 'getTransaction',
  4642. call: 'eth_getTransactionByHash',
  4643. params: 1,
  4644. outputFormatter: formatters.outputTransactionFormatter
  4645. });
  4646. var getTransactionFromBlock = new Method({
  4647. name: 'getTransactionFromBlock',
  4648. call: transactionFromBlockCall,
  4649. params: 2,
  4650. inputFormatter: [formatters.inputBlockNumberFormatter, utils.toHex],
  4651. outputFormatter: formatters.outputTransactionFormatter
  4652. });
  4653. var getTransactionDataAndReceipt = new Method({
  4654. name: 'getTransactionDataAndReceipt',
  4655. call: 'eth_getTransactionDataAndReceipt',
  4656. params: 1,
  4657. outputFormatter: formatters.outputTransactionDataAndReceiptFormatter
  4658. });
  4659. var getTransactionsByBlockNumber = new Method({
  4660. name: 'getTransactionsByBlockNumber',
  4661. call: 'eth_getTransactionsByBlockNumber',
  4662. params: 1,
  4663. outputFormatter: formatters.outputTransactionFormatter
  4664. });
  4665. var getTransactionReceiptsByBlockNumber = new Method({
  4666. name: 'getTransactionReceiptsByBlockNumber',
  4667. call: 'eth_getTransactionReceiptsByBlockNumber',
  4668. params: 1,
  4669. outputFormatter: formatters.outputTransactionReceiptFormatter
  4670. });
  4671. var getTransactionReceipt = new Method({
  4672. name: 'getTransactionReceipt',
  4673. call: 'eth_getTransactionReceipt',
  4674. params: 1,
  4675. outputFormatter: formatters.outputTransactionReceiptFormatter
  4676. });
  4677. var getTransactionCount = new Method({
  4678. name: 'getTransactionCount',
  4679. call: 'eth_getTransactionCount',
  4680. params: 2,
  4681. inputFormatter: [null, formatters.inputDefaultBlockNumberFormatter],
  4682. outputFormatter: utils.toDecimal
  4683. });
  4684. var sendRawTransaction = new Method({
  4685. name: 'sendRawTransaction',
  4686. call: 'eth_sendRawTransaction',
  4687. params: 1,
  4688. inputFormatter: [null]
  4689. });
  4690. var sendTransaction = new Method({
  4691. name: 'sendTransaction',
  4692. call: 'eth_sendTransaction',
  4693. params: 1,
  4694. inputFormatter: [formatters.inputTransactionFormatter]
  4695. });
  4696. var signTransaction = new Method({
  4697. name: 'signTransaction',
  4698. call: 'eth_signTransaction',
  4699. params: 1,
  4700. inputFormatter: [formatters.inputTransactionFormatter]
  4701. });
  4702. var sign = new Method({
  4703. name: 'sign',
  4704. call: 'eth_sign',
  4705. params: 2,
  4706. inputFormatter: [formatters.inputAddressFormatter, null]
  4707. });
  4708. var call = new Method({
  4709. name: 'call',
  4710. call: 'eth_call',
  4711. params: 2,
  4712. inputFormatter: [formatters.inputCallFormatter, formatters.inputDefaultBlockNumberFormatter]
  4713. });
  4714. var estimateGas = new Method({
  4715. name: 'estimateGas',
  4716. call: 'eth_estimateGas',
  4717. params: 1,
  4718. inputFormatter: [formatters.inputCallFormatter],
  4719. outputFormatter: utils.toDecimal
  4720. });
  4721. var compileSolidity = new Method({
  4722. name: 'compile.solidity',
  4723. call: 'eth_compileSolidity',
  4724. params: 1
  4725. });
  4726. var compileLLL = new Method({
  4727. name: 'compile.lll',
  4728. call: 'eth_compileLLL',
  4729. params: 1
  4730. });
  4731. var compileSerpent = new Method({
  4732. name: 'compile.serpent',
  4733. call: 'eth_compileSerpent',
  4734. params: 1
  4735. });
  4736. var submitWork = new Method({
  4737. name: 'submitWork',
  4738. call: 'eth_submitWork',
  4739. params: 3
  4740. });
  4741. var getWork = new Method({
  4742. name: 'getWork',
  4743. call: 'eth_getWork',
  4744. params: 0
  4745. });
  4746. return [
  4747. getBalance,
  4748. getStorageAt,
  4749. getCode,
  4750. getBlock,
  4751. getUncle,
  4752. getCompilers,
  4753. getBlockTransactionCount,
  4754. getBlockUncleCount,
  4755. getTransaction,
  4756. getTransactionFromBlock,
  4757. getTransactionsByBlockNumber,
  4758. getTransactionReceiptsByBlockNumber,
  4759. getTransactionDataAndReceipt,
  4760. getTransactionReceipt,
  4761. getTransactionCount,
  4762. call,
  4763. estimateGas,
  4764. sendRawTransaction,
  4765. signTransaction,
  4766. sendTransaction,
  4767. sign,
  4768. compileSolidity,
  4769. compileLLL,
  4770. compileSerpent,
  4771. submitWork,
  4772. getWork
  4773. ];
  4774. };
  4775. var properties = function () {
  4776. return [
  4777. new Property({
  4778. name: 'coinbase',
  4779. getter: 'eth_coinbase'
  4780. }),
  4781. new Property({
  4782. name: 'mining',
  4783. getter: 'eth_mining'
  4784. }),
  4785. new Property({
  4786. name: 'hashrate',
  4787. getter: 'eth_hashrate',
  4788. outputFormatter: utils.toDecimal
  4789. }),
  4790. new Property({
  4791. name: 'syncing',
  4792. getter: 'eth_syncing',
  4793. outputFormatter: formatters.outputSyncingFormatter
  4794. }),
  4795. new Property({
  4796. name: 'gasPrice',
  4797. getter: 'eth_gasPrice',
  4798. outputFormatter: formatters.outputBigNumberFormatter
  4799. }),
  4800. new Property({
  4801. name: 'accounts',
  4802. getter: 'eth_accounts'
  4803. }),
  4804. new Property({
  4805. name: 'blockNumber',
  4806. getter: 'eth_blockNumber',
  4807. outputFormatter: utils.toDecimal
  4808. }),
  4809. new Property({
  4810. name: 'protocolVersion',
  4811. getter: 'eth_protocolVersion'
  4812. })
  4813. ];
  4814. };
  4815. Eth.prototype.contract = function (abi) {
  4816. var factory = new Contract(this, abi);
  4817. return factory;
  4818. };
  4819. Eth.prototype.filter = function (options, callback, filterCreationErrorCallback) {
  4820. return new Filter(options, 'eth', this._requestManager, watches.eth(), formatters.outputLogFormatter, callback, filterCreationErrorCallback);
  4821. };
  4822. Eth.prototype.namereg = function () {
  4823. return this.contract(namereg.global.abi).at(namereg.global.address);
  4824. };
  4825. Eth.prototype.icapNamereg = function () {
  4826. return this.contract(namereg.icap.abi).at(namereg.icap.address);
  4827. };
  4828. Eth.prototype.isSyncing = function (callback) {
  4829. return new IsSyncing(this._requestManager, callback);
  4830. };
  4831. module.exports = Eth;
  4832. },{"../../utils/config":18,"../../utils/utils":20,"../contract":25,"../filter":29,"../formatters":30,"../iban":33,"../method":36,"../namereg":44,"../property":45,"../syncing":48,"../transfer":49,"./watches":43}],39:[function(require,module,exports){
  4833. /*
  4834. This file is part of web3.js.
  4835. web3.js is free software: you can redistribute it and/or modify
  4836. it under the terms of the GNU Lesser General Public License as published by
  4837. the Free Software Foundation, either version 3 of the License, or
  4838. (at your option) any later version.
  4839. web3.js is distributed in the hope that it will be useful,
  4840. but WITHOUT ANY WARRANTY; without even the implied warranty of
  4841. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  4842. GNU Lesser General Public License for more details.
  4843. You should have received a copy of the GNU Lesser General Public License
  4844. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  4845. */
  4846. /** @file eth.js
  4847. * @authors:
  4848. * Marek Kotewicz <marek@ethdev.com>
  4849. * @date 2015
  4850. */
  4851. var utils = require('../../utils/utils');
  4852. var Property = require('../property');
  4853. var Net = function (web3) {
  4854. this._requestManager = web3._requestManager;
  4855. var self = this;
  4856. properties().forEach(function(p) {
  4857. p.attachToObject(self);
  4858. p.setRequestManager(web3._requestManager);
  4859. });
  4860. };
  4861. /// @returns an array of objects describing web3.eth api properties
  4862. var properties = function () {
  4863. return [
  4864. new Property({
  4865. name: 'listening',
  4866. getter: 'net_listening'
  4867. }),
  4868. new Property({
  4869. name: 'peerCount',
  4870. getter: 'net_peerCount',
  4871. outputFormatter: utils.toDecimal
  4872. })
  4873. ];
  4874. };
  4875. module.exports = Net;
  4876. },{"../../utils/utils":20,"../property":45}],40:[function(require,module,exports){
  4877. /*
  4878. This file is part of web3.js.
  4879. web3.js is free software: you can redistribute it and/or modify
  4880. it under the terms of the GNU Lesser General Public License as published by
  4881. the Free Software Foundation, either version 3 of the License, or
  4882. (at your option) any later version.
  4883. web3.js is distributed in the hope that it will be useful,
  4884. but WITHOUT ANY WARRANTY; without even the implied warranty of
  4885. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  4886. GNU Lesser General Public License for more details.
  4887. You should have received a copy of the GNU Lesser General Public License
  4888. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  4889. */
  4890. /**
  4891. * @file eth.js
  4892. * @author Marek Kotewicz <marek@ethdev.com>
  4893. * @author Fabian Vogelsteller <fabian@ethdev.com>
  4894. * @date 2015
  4895. */
  4896. "use strict";
  4897. var Method = require('../method');
  4898. var Property = require('../property');
  4899. var formatters = require('../formatters');
  4900. function Personal(web3) {
  4901. this._requestManager = web3._requestManager;
  4902. var self = this;
  4903. methods().forEach(function(method) {
  4904. method.attachToObject(self);
  4905. method.setRequestManager(self._requestManager);
  4906. });
  4907. properties().forEach(function(p) {
  4908. p.attachToObject(self);
  4909. p.setRequestManager(self._requestManager);
  4910. });
  4911. }
  4912. var methods = function () {
  4913. var newAccount = new Method({
  4914. name: 'newAccount',
  4915. call: 'personal_newAccount',
  4916. params: 1,
  4917. inputFormatter: [null]
  4918. });
  4919. var importRawKey = new Method({
  4920. name: 'importRawKey',
  4921. call: 'personal_importRawKey',
  4922. params: 2
  4923. });
  4924. var sign = new Method({
  4925. name: 'sign',
  4926. call: 'personal_sign',
  4927. params: 3,
  4928. inputFormatter: [null, formatters.inputAddressFormatter, null]
  4929. });
  4930. var ecRecover = new Method({
  4931. name: 'ecRecover',
  4932. call: 'personal_ecRecover',
  4933. params: 2
  4934. });
  4935. var unlockAccount = new Method({
  4936. name: 'unlockAccount',
  4937. call: 'personal_unlockAccount',
  4938. params: 3,
  4939. inputFormatter: [formatters.inputAddressFormatter, null, null]
  4940. });
  4941. var sendTransaction = new Method({
  4942. name: 'sendTransaction',
  4943. call: 'personal_sendTransaction',
  4944. params: 2,
  4945. inputFormatter: [formatters.inputTransactionFormatter, null]
  4946. });
  4947. var lockAccount = new Method({
  4948. name: 'lockAccount',
  4949. call: 'personal_lockAccount',
  4950. params: 1,
  4951. inputFormatter: [formatters.inputAddressFormatter]
  4952. });
  4953. return [
  4954. newAccount,
  4955. importRawKey,
  4956. unlockAccount,
  4957. ecRecover,
  4958. sign,
  4959. sendTransaction,
  4960. lockAccount
  4961. ];
  4962. };
  4963. var properties = function () {
  4964. return [
  4965. new Property({
  4966. name: 'listAccounts',
  4967. getter: 'personal_listAccounts'
  4968. })
  4969. ];
  4970. };
  4971. module.exports = Personal;
  4972. },{"../formatters":30,"../method":36,"../property":45}],41:[function(require,module,exports){
  4973. /*
  4974. This file is part of web3.js.
  4975. web3.js is free software: you can redistribute it and/or modify
  4976. it under the terms of the GNU Lesser General Public License as published by
  4977. the Free Software Foundation, either version 3 of the License, or
  4978. (at your option) any later version.
  4979. web3.js is distributed in the hope that it will be useful,
  4980. but WITHOUT ANY WARRANTY; without even the implied warranty of
  4981. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  4982. GNU Lesser General Public License for more details.
  4983. You should have received a copy of the GNU Lesser General Public License
  4984. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  4985. */
  4986. /** @file shh.js
  4987. * @authors:
  4988. * Fabian Vogelsteller <fabian@ethereum.org>
  4989. * Marek Kotewicz <marek@ethcore.io>
  4990. * @date 2017
  4991. */
  4992. var Method = require('../method');
  4993. var Filter = require('../filter');
  4994. var watches = require('./watches');
  4995. var Shh = function (web3) {
  4996. this._requestManager = web3._requestManager;
  4997. var self = this;
  4998. methods().forEach(function(method) {
  4999. method.attachToObject(self);
  5000. method.setRequestManager(self._requestManager);
  5001. });
  5002. };
  5003. Shh.prototype.newMessageFilter = function (options, callback, filterCreationErrorCallback) {
  5004. return new Filter(options, 'shh', this._requestManager, watches.shh(), null, callback, filterCreationErrorCallback);
  5005. };
  5006. var methods = function () {
  5007. return [
  5008. new Method({
  5009. name: 'version',
  5010. call: 'shh_version',
  5011. params: 0
  5012. }),
  5013. new Method({
  5014. name: 'info',
  5015. call: 'shh_info',
  5016. params: 0
  5017. }),
  5018. new Method({
  5019. name: 'setMaxMessageSize',
  5020. call: 'shh_setMaxMessageSize',
  5021. params: 1
  5022. }),
  5023. new Method({
  5024. name: 'setMinPoW',
  5025. call: 'shh_setMinPoW',
  5026. params: 1
  5027. }),
  5028. new Method({
  5029. name: 'markTrustedPeer',
  5030. call: 'shh_markTrustedPeer',
  5031. params: 1
  5032. }),
  5033. new Method({
  5034. name: 'newKeyPair',
  5035. call: 'shh_newKeyPair',
  5036. params: 0
  5037. }),
  5038. new Method({
  5039. name: 'addPrivateKey',
  5040. call: 'shh_addPrivateKey',
  5041. params: 1
  5042. }),
  5043. new Method({
  5044. name: 'deleteKeyPair',
  5045. call: 'shh_deleteKeyPair',
  5046. params: 1
  5047. }),
  5048. new Method({
  5049. name: 'hasKeyPair',
  5050. call: 'shh_hasKeyPair',
  5051. params: 1
  5052. }),
  5053. new Method({
  5054. name: 'getPublicKey',
  5055. call: 'shh_getPublicKey',
  5056. params: 1
  5057. }),
  5058. new Method({
  5059. name: 'getPrivateKey',
  5060. call: 'shh_getPrivateKey',
  5061. params: 1
  5062. }),
  5063. new Method({
  5064. name: 'newSymKey',
  5065. call: 'shh_newSymKey',
  5066. params: 0
  5067. }),
  5068. new Method({
  5069. name: 'addSymKey',
  5070. call: 'shh_addSymKey',
  5071. params: 1
  5072. }),
  5073. new Method({
  5074. name: 'generateSymKeyFromPassword',
  5075. call: 'shh_generateSymKeyFromPassword',
  5076. params: 1
  5077. }),
  5078. new Method({
  5079. name: 'hasSymKey',
  5080. call: 'shh_hasSymKey',
  5081. params: 1
  5082. }),
  5083. new Method({
  5084. name: 'getSymKey',
  5085. call: 'shh_getSymKey',
  5086. params: 1
  5087. }),
  5088. new Method({
  5089. name: 'deleteSymKey',
  5090. call: 'shh_deleteSymKey',
  5091. params: 1
  5092. }),
  5093. // subscribe and unsubscribe missing
  5094. new Method({
  5095. name: 'post',
  5096. call: 'shh_post',
  5097. params: 1,
  5098. inputFormatter: [null]
  5099. })
  5100. ];
  5101. };
  5102. module.exports = Shh;
  5103. },{"../filter":29,"../method":36,"./watches":43}],42:[function(require,module,exports){
  5104. /*
  5105. This file is part of web3.js.
  5106. web3.js is free software: you can redistribute it and/or modify
  5107. it under the terms of the GNU Lesser General Public License as published by
  5108. the Free Software Foundation, either version 3 of the License, or
  5109. (at your option) any later version.
  5110. web3.js is distributed in the hope that it will be useful,
  5111. but WITHOUT ANY WARRANTY; without even the implied warranty of
  5112. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  5113. GNU Lesser General Public License for more details.
  5114. You should have received a copy of the GNU Lesser General Public License
  5115. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  5116. */
  5117. /**
  5118. * @file bzz.js
  5119. * @author Alex Beregszaszi <alex@rtfs.hu>
  5120. * @date 2016
  5121. *
  5122. * Reference: https://github.com/ethereum/go-ethereum/blob/swarm/internal/web3ext/web3ext.go#L33
  5123. */
  5124. "use strict";
  5125. var Method = require('../method');
  5126. var Property = require('../property');
  5127. function Swarm(web3) {
  5128. this._requestManager = web3._requestManager;
  5129. var self = this;
  5130. methods().forEach(function(method) {
  5131. method.attachToObject(self);
  5132. method.setRequestManager(self._requestManager);
  5133. });
  5134. properties().forEach(function(p) {
  5135. p.attachToObject(self);
  5136. p.setRequestManager(self._requestManager);
  5137. });
  5138. }
  5139. var methods = function () {
  5140. var blockNetworkRead = new Method({
  5141. name: 'blockNetworkRead',
  5142. call: 'bzz_blockNetworkRead',
  5143. params: 1,
  5144. inputFormatter: [null]
  5145. });
  5146. var syncEnabled = new Method({
  5147. name: 'syncEnabled',
  5148. call: 'bzz_syncEnabled',
  5149. params: 1,
  5150. inputFormatter: [null]
  5151. });
  5152. var swapEnabled = new Method({
  5153. name: 'swapEnabled',
  5154. call: 'bzz_swapEnabled',
  5155. params: 1,
  5156. inputFormatter: [null]
  5157. });
  5158. var download = new Method({
  5159. name: 'download',
  5160. call: 'bzz_download',
  5161. params: 2,
  5162. inputFormatter: [null, null]
  5163. });
  5164. var upload = new Method({
  5165. name: 'upload',
  5166. call: 'bzz_upload',
  5167. params: 2,
  5168. inputFormatter: [null, null]
  5169. });
  5170. var retrieve = new Method({
  5171. name: 'retrieve',
  5172. call: 'bzz_retrieve',
  5173. params: 1,
  5174. inputFormatter: [null]
  5175. });
  5176. var store = new Method({
  5177. name: 'store',
  5178. call: 'bzz_store',
  5179. params: 2,
  5180. inputFormatter: [null, null]
  5181. });
  5182. var get = new Method({
  5183. name: 'get',
  5184. call: 'bzz_get',
  5185. params: 1,
  5186. inputFormatter: [null]
  5187. });
  5188. var put = new Method({
  5189. name: 'put',
  5190. call: 'bzz_put',
  5191. params: 2,
  5192. inputFormatter: [null, null]
  5193. });
  5194. var modify = new Method({
  5195. name: 'modify',
  5196. call: 'bzz_modify',
  5197. params: 4,
  5198. inputFormatter: [null, null, null, null]
  5199. });
  5200. return [
  5201. blockNetworkRead,
  5202. syncEnabled,
  5203. swapEnabled,
  5204. download,
  5205. upload,
  5206. retrieve,
  5207. store,
  5208. get,
  5209. put,
  5210. modify
  5211. ];
  5212. };
  5213. var properties = function () {
  5214. return [
  5215. new Property({
  5216. name: 'hive',
  5217. getter: 'bzz_hive'
  5218. }),
  5219. new Property({
  5220. name: 'info',
  5221. getter: 'bzz_info'
  5222. })
  5223. ];
  5224. };
  5225. module.exports = Swarm;
  5226. },{"../method":36,"../property":45}],43:[function(require,module,exports){
  5227. /*
  5228. This file is part of web3.js.
  5229. web3.js is free software: you can redistribute it and/or modify
  5230. it under the terms of the GNU Lesser General Public License as published by
  5231. the Free Software Foundation, either version 3 of the License, or
  5232. (at your option) any later version.
  5233. web3.js is distributed in the hope that it will be useful,
  5234. but WITHOUT ANY WARRANTY; without even the implied warranty of
  5235. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  5236. GNU Lesser General Public License for more details.
  5237. You should have received a copy of the GNU Lesser General Public License
  5238. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  5239. */
  5240. /** @file watches.js
  5241. * @authors:
  5242. * Marek Kotewicz <marek@ethdev.com>
  5243. * @date 2015
  5244. */
  5245. var Method = require('../method');
  5246. /// @returns an array of objects describing web3.eth.filter api methods
  5247. var eth = function () {
  5248. var newFilterCall = function (args) {
  5249. var type = args[0];
  5250. switch(type) {
  5251. case 'latest':
  5252. args.shift();
  5253. this.params = 0;
  5254. return 'eth_newBlockFilter';
  5255. case 'pending':
  5256. args.shift();
  5257. this.params = 0;
  5258. return 'eth_newPendingTransactionFilter';
  5259. default:
  5260. return 'eth_newFilter';
  5261. }
  5262. };
  5263. var newFilter = new Method({
  5264. name: 'newFilter',
  5265. call: newFilterCall,
  5266. params: 1
  5267. });
  5268. var uninstallFilter = new Method({
  5269. name: 'uninstallFilter',
  5270. call: 'eth_uninstallFilter',
  5271. params: 1
  5272. });
  5273. var getLogs = new Method({
  5274. name: 'getLogs',
  5275. call: 'eth_getFilterLogs',
  5276. params: 1
  5277. });
  5278. var poll = new Method({
  5279. name: 'poll',
  5280. call: 'eth_getFilterChanges',
  5281. params: 1
  5282. });
  5283. return [
  5284. newFilter,
  5285. uninstallFilter,
  5286. getLogs,
  5287. poll
  5288. ];
  5289. };
  5290. /// @returns an array of objects describing web3.shh.watch api methods
  5291. var shh = function () {
  5292. return [
  5293. new Method({
  5294. name: 'newFilter',
  5295. call: 'shh_newMessageFilter',
  5296. params: 1
  5297. }),
  5298. new Method({
  5299. name: 'uninstallFilter',
  5300. call: 'shh_deleteMessageFilter',
  5301. params: 1
  5302. }),
  5303. new Method({
  5304. name: 'getLogs',
  5305. call: 'shh_getFilterMessages',
  5306. params: 1
  5307. }),
  5308. new Method({
  5309. name: 'poll',
  5310. call: 'shh_getFilterMessages',
  5311. params: 1
  5312. })
  5313. ];
  5314. };
  5315. module.exports = {
  5316. eth: eth,
  5317. shh: shh
  5318. };
  5319. },{"../method":36}],44:[function(require,module,exports){
  5320. /*
  5321. This file is part of web3.js.
  5322. web3.js is free software: you can redistribute it and/or modify
  5323. it under the terms of the GNU Lesser General Public License as published by
  5324. the Free Software Foundation, either version 3 of the License, or
  5325. (at your option) any later version.
  5326. web3.js is distributed in the hope that it will be useful,
  5327. but WITHOUT ANY WARRANTY; without even the implied warranty of
  5328. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  5329. GNU Lesser General Public License for more details.
  5330. You should have received a copy of the GNU Lesser General Public License
  5331. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  5332. */
  5333. /**
  5334. * @file namereg.js
  5335. * @author Marek Kotewicz <marek@ethdev.com>
  5336. * @date 2015
  5337. */
  5338. var globalRegistrarAbi = require('../contracts/GlobalRegistrar.json');
  5339. var icapRegistrarAbi= require('../contracts/ICAPRegistrar.json');
  5340. var globalNameregAddress = '0xc6d9d2cd449a754c494264e1809c50e34d64562b';
  5341. var icapNameregAddress = '0xa1a111bc074c9cfa781f0c38e63bd51c91b8af00';
  5342. module.exports = {
  5343. global: {
  5344. abi: globalRegistrarAbi,
  5345. address: globalNameregAddress
  5346. },
  5347. icap: {
  5348. abi: icapRegistrarAbi,
  5349. address: icapNameregAddress
  5350. }
  5351. };
  5352. },{"../contracts/GlobalRegistrar.json":1,"../contracts/ICAPRegistrar.json":2}],45:[function(require,module,exports){
  5353. /*
  5354. This file is part of web3.js.
  5355. web3.js is free software: you can redistribute it and/or modify
  5356. it under the terms of the GNU Lesser General Public License as published by
  5357. the Free Software Foundation, either version 3 of the License, or
  5358. (at your option) any later version.
  5359. web3.js is distributed in the hope that it will be useful,
  5360. but WITHOUT ANY WARRANTY; without even the implied warranty of
  5361. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  5362. GNU Lesser General Public License for more details.
  5363. You should have received a copy of the GNU Lesser General Public License
  5364. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  5365. */
  5366. /**
  5367. * @file property.js
  5368. * @author Fabian Vogelsteller <fabian@frozeman.de>
  5369. * @author Marek Kotewicz <marek@ethdev.com>
  5370. * @date 2015
  5371. */
  5372. var utils = require('../utils/utils');
  5373. var Property = function (options) {
  5374. this.name = options.name;
  5375. this.getter = options.getter;
  5376. this.setter = options.setter;
  5377. this.outputFormatter = options.outputFormatter;
  5378. this.inputFormatter = options.inputFormatter;
  5379. this.requestManager = null;
  5380. };
  5381. Property.prototype.setRequestManager = function (rm) {
  5382. this.requestManager = rm;
  5383. };
  5384. /**
  5385. * Should be called to format input args of method
  5386. *
  5387. * @method formatInput
  5388. * @param {Array}
  5389. * @return {Array}
  5390. */
  5391. Property.prototype.formatInput = function (arg) {
  5392. return this.inputFormatter ? this.inputFormatter(arg) : arg;
  5393. };
  5394. /**
  5395. * Should be called to format output(result) of method
  5396. *
  5397. * @method formatOutput
  5398. * @param {Object}
  5399. * @return {Object}
  5400. */
  5401. Property.prototype.formatOutput = function (result) {
  5402. return this.outputFormatter && result !== null && result !== undefined ? this.outputFormatter(result) : result;
  5403. };
  5404. /**
  5405. * Should be used to extract callback from array of arguments. Modifies input param
  5406. *
  5407. * @method extractCallback
  5408. * @param {Array} arguments
  5409. * @return {Function|Null} callback, if exists
  5410. */
  5411. Property.prototype.extractCallback = function (args) {
  5412. if (utils.isFunction(args[args.length - 1])) {
  5413. return args.pop(); // modify the args array!
  5414. }
  5415. };
  5416. /**
  5417. * Should attach function to method
  5418. *
  5419. * @method attachToObject
  5420. * @param {Object}
  5421. * @param {Function}
  5422. */
  5423. Property.prototype.attachToObject = function (obj) {
  5424. var proto = {
  5425. get: this.buildGet(),
  5426. enumerable: true
  5427. };
  5428. var names = this.name.split('.');
  5429. var name = names[0];
  5430. if (names.length > 1) {
  5431. obj[names[0]] = obj[names[0]] || {};
  5432. obj = obj[names[0]];
  5433. name = names[1];
  5434. }
  5435. Object.defineProperty(obj, name, proto);
  5436. obj[asyncGetterName(name)] = this.buildAsyncGet();
  5437. };
  5438. var asyncGetterName = function (name) {
  5439. return 'get' + name.charAt(0).toUpperCase() + name.slice(1);
  5440. };
  5441. Property.prototype.buildGet = function () {
  5442. var property = this;
  5443. return function get() {
  5444. return property.formatOutput(property.requestManager.send({
  5445. method: property.getter
  5446. }));
  5447. };
  5448. };
  5449. Property.prototype.buildAsyncGet = function () {
  5450. var property = this;
  5451. var get = function (callback) {
  5452. property.requestManager.sendAsync({
  5453. method: property.getter
  5454. }, function (err, result) {
  5455. callback(err, property.formatOutput(result));
  5456. });
  5457. };
  5458. get.request = this.request.bind(this);
  5459. return get;
  5460. };
  5461. /**
  5462. * Should be called to create pure JSONRPC request which can be used in batch request
  5463. *
  5464. * @method request
  5465. * @param {...} params
  5466. * @return {Object} jsonrpc request
  5467. */
  5468. Property.prototype.request = function () {
  5469. var payload = {
  5470. method: this.getter,
  5471. params: [],
  5472. callback: this.extractCallback(Array.prototype.slice.call(arguments))
  5473. };
  5474. payload.format = this.formatOutput.bind(this);
  5475. return payload;
  5476. };
  5477. module.exports = Property;
  5478. },{"../utils/utils":20}],46:[function(require,module,exports){
  5479. /*
  5480. This file is part of web3.js.
  5481. web3.js is free software: you can redistribute it and/or modify
  5482. it under the terms of the GNU Lesser General Public License as published by
  5483. the Free Software Foundation, either version 3 of the License, or
  5484. (at your option) any later version.
  5485. web3.js is distributed in the hope that it will be useful,
  5486. but WITHOUT ANY WARRANTY; without even the implied warranty of
  5487. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  5488. GNU Lesser General Public License for more details.
  5489. You should have received a copy of the GNU Lesser General Public License
  5490. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  5491. */
  5492. /**
  5493. * @file requestmanager.js
  5494. * @author Jeffrey Wilcke <jeff@ethdev.com>
  5495. * @author Marek Kotewicz <marek@ethdev.com>
  5496. * @author Marian Oancea <marian@ethdev.com>
  5497. * @author Fabian Vogelsteller <fabian@ethdev.com>
  5498. * @author Gav Wood <g@ethdev.com>
  5499. * @date 2014
  5500. */
  5501. var Jsonrpc = require('./jsonrpc');
  5502. var utils = require('../utils/utils');
  5503. var c = require('../utils/config');
  5504. var errors = require('./errors');
  5505. /**
  5506. * It's responsible for passing messages to providers
  5507. * It's also responsible for polling the ethereum node for incoming messages
  5508. * Default poll timeout is 1 second
  5509. * Singleton
  5510. */
  5511. var RequestManager = function (provider) {
  5512. this.provider = provider;
  5513. this.polls = {};
  5514. this.timeout = null;
  5515. };
  5516. /**
  5517. * Should be used to synchronously send request
  5518. *
  5519. * @method send
  5520. * @param {Object} data
  5521. * @return {Object}
  5522. */
  5523. RequestManager.prototype.send = function (data) {
  5524. if (!this.provider) {
  5525. console.error(errors.InvalidProvider());
  5526. return null;
  5527. }
  5528. var payload = Jsonrpc.toPayload(data.method, data.params);
  5529. var result = this.provider.send(payload);
  5530. if (!Jsonrpc.isValidResponse(result)) {
  5531. throw errors.InvalidResponse(result);
  5532. }
  5533. return result.result;
  5534. };
  5535. /**
  5536. * Should be used to asynchronously send request
  5537. *
  5538. * @method sendAsync
  5539. * @param {Object} data
  5540. * @param {Function} callback
  5541. */
  5542. RequestManager.prototype.sendAsync = function (data, callback) {
  5543. if (!this.provider) {
  5544. return callback(errors.InvalidProvider());
  5545. }
  5546. var payload = Jsonrpc.toPayload(data.method, data.params);
  5547. this.provider.sendAsync(payload, function (err, result) {
  5548. if (err) {
  5549. return callback(err);
  5550. }
  5551. if (!Jsonrpc.isValidResponse(result)) {
  5552. return callback(errors.InvalidResponse(result));
  5553. }
  5554. callback(null, result.result);
  5555. });
  5556. };
  5557. /**
  5558. * Should be called to asynchronously send batch request
  5559. *
  5560. * @method sendBatch
  5561. * @param {Array} batch data
  5562. * @param {Function} callback
  5563. */
  5564. RequestManager.prototype.sendBatch = function (data, callback) {
  5565. if (!this.provider) {
  5566. return callback(errors.InvalidProvider());
  5567. }
  5568. var payload = Jsonrpc.toBatchPayload(data);
  5569. this.provider.sendAsync(payload, function (err, results) {
  5570. if (err) {
  5571. return callback(err);
  5572. }
  5573. if (!utils.isArray(results)) {
  5574. return callback(errors.InvalidResponse(results));
  5575. }
  5576. callback(err, results);
  5577. });
  5578. };
  5579. /**
  5580. * Should be used to set provider of request manager
  5581. *
  5582. * @method setProvider
  5583. * @param {Object}
  5584. */
  5585. RequestManager.prototype.setProvider = function (p) {
  5586. this.provider = p;
  5587. };
  5588. /**
  5589. * Should be used to start polling
  5590. *
  5591. * @method startPolling
  5592. * @param {Object} data
  5593. * @param {Number} pollId
  5594. * @param {Function} callback
  5595. * @param {Function} uninstall
  5596. *
  5597. * @todo cleanup number of params
  5598. */
  5599. RequestManager.prototype.startPolling = function (data, pollId, callback, uninstall) {
  5600. this.polls[pollId] = {data: data, id: pollId, callback: callback, uninstall: uninstall};
  5601. // start polling
  5602. if (!this.timeout) {
  5603. this.poll();
  5604. }
  5605. };
  5606. /**
  5607. * Should be used to stop polling for filter with given id
  5608. *
  5609. * @method stopPolling
  5610. * @param {Number} pollId
  5611. */
  5612. RequestManager.prototype.stopPolling = function (pollId) {
  5613. delete this.polls[pollId];
  5614. // stop polling
  5615. if(Object.keys(this.polls).length === 0 && this.timeout) {
  5616. clearTimeout(this.timeout);
  5617. this.timeout = null;
  5618. }
  5619. };
  5620. /**
  5621. * Should be called to reset the polling mechanism of the request manager
  5622. *
  5623. * @method reset
  5624. */
  5625. RequestManager.prototype.reset = function (keepIsSyncing) {
  5626. /*jshint maxcomplexity:5 */
  5627. for (var key in this.polls) {
  5628. // remove all polls, except sync polls,
  5629. // they need to be removed manually by calling syncing.stopWatching()
  5630. if(!keepIsSyncing || key.indexOf('syncPoll_') === -1) {
  5631. this.polls[key].uninstall();
  5632. delete this.polls[key];
  5633. }
  5634. }
  5635. // stop polling
  5636. if(Object.keys(this.polls).length === 0 && this.timeout) {
  5637. clearTimeout(this.timeout);
  5638. this.timeout = null;
  5639. }
  5640. };
  5641. /**
  5642. * Should be called to poll for changes on filter with given id
  5643. *
  5644. * @method poll
  5645. */
  5646. RequestManager.prototype.poll = function () {
  5647. /*jshint maxcomplexity: 6 */
  5648. this.timeout = setTimeout(this.poll.bind(this), c.ETH_POLLING_TIMEOUT);
  5649. if (Object.keys(this.polls).length === 0) {
  5650. return;
  5651. }
  5652. if (!this.provider) {
  5653. console.error(errors.InvalidProvider());
  5654. return;
  5655. }
  5656. var pollsData = [];
  5657. var pollsIds = [];
  5658. for (var key in this.polls) {
  5659. pollsData.push(this.polls[key].data);
  5660. pollsIds.push(key);
  5661. }
  5662. if (pollsData.length === 0) {
  5663. return;
  5664. }
  5665. var payload = Jsonrpc.toBatchPayload(pollsData);
  5666. // map the request id to they poll id
  5667. var pollsIdMap = {};
  5668. payload.forEach(function(load, index){
  5669. pollsIdMap[load.id] = pollsIds[index];
  5670. });
  5671. var self = this;
  5672. this.provider.sendAsync(payload, function (error, results) {
  5673. // TODO: console log?
  5674. if (error) {
  5675. return;
  5676. }
  5677. if (!utils.isArray(results)) {
  5678. throw errors.InvalidResponse(results);
  5679. }
  5680. results.map(function (result) {
  5681. var id = pollsIdMap[result.id];
  5682. // make sure the filter is still installed after arrival of the request
  5683. if (self.polls[id]) {
  5684. result.callback = self.polls[id].callback;
  5685. return result;
  5686. } else
  5687. return false;
  5688. }).filter(function (result) {
  5689. return !!result;
  5690. }).filter(function (result) {
  5691. var valid = Jsonrpc.isValidResponse(result);
  5692. if (!valid) {
  5693. result.callback(errors.InvalidResponse(result));
  5694. }
  5695. return valid;
  5696. }).forEach(function (result) {
  5697. result.callback(null, result.result);
  5698. });
  5699. });
  5700. };
  5701. module.exports = RequestManager;
  5702. },{"../utils/config":18,"../utils/utils":20,"./errors":26,"./jsonrpc":35}],47:[function(require,module,exports){
  5703. var Settings = function () {
  5704. this.defaultBlock = 'latest';
  5705. this.defaultAccount = undefined;
  5706. };
  5707. module.exports = Settings;
  5708. },{}],48:[function(require,module,exports){
  5709. /*
  5710. This file is part of web3.js.
  5711. web3.js is free software: you can redistribute it and/or modify
  5712. it under the terms of the GNU Lesser General Public License as published by
  5713. the Free Software Foundation, either version 3 of the License, or
  5714. (at your option) any later version.
  5715. web3.js is distributed in the hope that it will be useful,
  5716. but WITHOUT ANY WARRANTY; without even the implied warranty of
  5717. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  5718. GNU Lesser General Public License for more details.
  5719. You should have received a copy of the GNU Lesser General Public License
  5720. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  5721. */
  5722. /** @file syncing.js
  5723. * @authors:
  5724. * Fabian Vogelsteller <fabian@ethdev.com>
  5725. * @date 2015
  5726. */
  5727. var formatters = require('./formatters');
  5728. var utils = require('../utils/utils');
  5729. var count = 1;
  5730. /**
  5731. Adds the callback and sets up the methods, to iterate over the results.
  5732. @method pollSyncing
  5733. @param {Object} self
  5734. */
  5735. var pollSyncing = function(self) {
  5736. var onMessage = function (error, sync) {
  5737. if (error) {
  5738. return self.callbacks.forEach(function (callback) {
  5739. callback(error);
  5740. });
  5741. }
  5742. if(utils.isObject(sync) && sync.startingBlock)
  5743. sync = formatters.outputSyncingFormatter(sync);
  5744. self.callbacks.forEach(function (callback) {
  5745. if (self.lastSyncState !== sync) {
  5746. // call the callback with true first so the app can stop anything, before receiving the sync data
  5747. if(!self.lastSyncState && utils.isObject(sync))
  5748. callback(null, true);
  5749. // call on the next CPU cycle, so the actions of the sync stop can be processes first
  5750. setTimeout(function() {
  5751. callback(null, sync);
  5752. }, 0);
  5753. self.lastSyncState = sync;
  5754. }
  5755. });
  5756. };
  5757. self.requestManager.startPolling({
  5758. method: 'eth_syncing',
  5759. params: [],
  5760. }, self.pollId, onMessage, self.stopWatching.bind(self));
  5761. };
  5762. var IsSyncing = function (requestManager, callback) {
  5763. this.requestManager = requestManager;
  5764. this.pollId = 'syncPoll_'+ count++;
  5765. this.callbacks = [];
  5766. this.addCallback(callback);
  5767. this.lastSyncState = false;
  5768. pollSyncing(this);
  5769. return this;
  5770. };
  5771. IsSyncing.prototype.addCallback = function (callback) {
  5772. if(callback)
  5773. this.callbacks.push(callback);
  5774. return this;
  5775. };
  5776. IsSyncing.prototype.stopWatching = function () {
  5777. this.requestManager.stopPolling(this.pollId);
  5778. this.callbacks = [];
  5779. };
  5780. module.exports = IsSyncing;
  5781. },{"../utils/utils":20,"./formatters":30}],49:[function(require,module,exports){
  5782. /*
  5783. This file is part of web3.js.
  5784. web3.js is free software: you can redistribute it and/or modify
  5785. it under the terms of the GNU Lesser General Public License as published by
  5786. the Free Software Foundation, either version 3 of the License, or
  5787. (at your option) any later version.
  5788. web3.js is distributed in the hope that it will be useful,
  5789. but WITHOUT ANY WARRANTY; without even the implied warranty of
  5790. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  5791. GNU Lesser General Public License for more details.
  5792. You should have received a copy of the GNU Lesser General Public License
  5793. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  5794. */
  5795. /**
  5796. * @file transfer.js
  5797. * @author Marek Kotewicz <marek@ethdev.com>
  5798. * @date 2015
  5799. */
  5800. var Iban = require('./iban');
  5801. var exchangeAbi = require('../contracts/SmartExchange.json');
  5802. /**
  5803. * Should be used to make Iban transfer
  5804. *
  5805. * @method transfer
  5806. * @param {String} from
  5807. * @param {String} to iban
  5808. * @param {Value} value to be tranfered
  5809. * @param {Function} callback, callback
  5810. */
  5811. var transfer = function (eth, from, to, value, callback) {
  5812. var iban = new Iban(to);
  5813. if (!iban.isValid()) {
  5814. throw new Error('invalid iban address');
  5815. }
  5816. if (iban.isDirect()) {
  5817. return transferToAddress(eth, from, iban.address(), value, callback);
  5818. }
  5819. if (!callback) {
  5820. var address = eth.icapNamereg().addr(iban.institution());
  5821. return deposit(eth, from, address, value, iban.client());
  5822. }
  5823. eth.icapNamereg().addr(iban.institution(), function (err, address) {
  5824. return deposit(eth, from, address, value, iban.client(), callback);
  5825. });
  5826. };
  5827. /**
  5828. * Should be used to transfer funds to certain address
  5829. *
  5830. * @method transferToAddress
  5831. * @param {String} from
  5832. * @param {String} to
  5833. * @param {Value} value to be tranfered
  5834. * @param {Function} callback, callback
  5835. */
  5836. var transferToAddress = function (eth, from, to, value, callback) {
  5837. return eth.sendTransaction({
  5838. address: to,
  5839. from: from,
  5840. value: value
  5841. }, callback);
  5842. };
  5843. /**
  5844. * Should be used to deposit funds to generic Exchange contract (must implement deposit(bytes32) method!)
  5845. *
  5846. * @method deposit
  5847. * @param {String} from
  5848. * @param {String} to
  5849. * @param {Value} value to be transferred
  5850. * @param {String} client unique identifier
  5851. * @param {Function} callback, callback
  5852. */
  5853. var deposit = function (eth, from, to, value, client, callback) {
  5854. var abi = exchangeAbi;
  5855. return eth.contract(abi).at(to).deposit(client, {
  5856. from: from,
  5857. value: value
  5858. }, callback);
  5859. };
  5860. module.exports = transfer;
  5861. },{"../contracts/SmartExchange.json":3,"./iban":33}],50:[function(require,module,exports){
  5862. },{}],51:[function(require,module,exports){
  5863. ;(function (root, factory, undef) {
  5864. if (typeof exports === "object") {
  5865. // CommonJS
  5866. module.exports = exports = factory(require("./core"), require("./enc-base64"), require("./md5"), require("./evpkdf"), require("./cipher-core"));
  5867. }
  5868. else if (typeof define === "function" && define.amd) {
  5869. // AMD
  5870. define(["./core", "./enc-base64", "./md5", "./evpkdf", "./cipher-core"], factory);
  5871. }
  5872. else {
  5873. // Global (browser)
  5874. factory(root.CryptoJS);
  5875. }
  5876. }(this, function (CryptoJS) {
  5877. (function () {
  5878. // Shortcuts
  5879. var C = CryptoJS;
  5880. var C_lib = C.lib;
  5881. var BlockCipher = C_lib.BlockCipher;
  5882. var C_algo = C.algo;
  5883. // Lookup tables
  5884. var SBOX = [];
  5885. var INV_SBOX = [];
  5886. var SUB_MIX_0 = [];
  5887. var SUB_MIX_1 = [];
  5888. var SUB_MIX_2 = [];
  5889. var SUB_MIX_3 = [];
  5890. var INV_SUB_MIX_0 = [];
  5891. var INV_SUB_MIX_1 = [];
  5892. var INV_SUB_MIX_2 = [];
  5893. var INV_SUB_MIX_3 = [];
  5894. // Compute lookup tables
  5895. (function () {
  5896. // Compute double table
  5897. var d = [];
  5898. for (var i = 0; i < 256; i++) {
  5899. if (i < 128) {
  5900. d[i] = i << 1;
  5901. } else {
  5902. d[i] = (i << 1) ^ 0x11b;
  5903. }
  5904. }
  5905. // Walk GF(2^8)
  5906. var x = 0;
  5907. var xi = 0;
  5908. for (var i = 0; i < 256; i++) {
  5909. // Compute sbox
  5910. var sx = xi ^ (xi << 1) ^ (xi << 2) ^ (xi << 3) ^ (xi << 4);
  5911. sx = (sx >>> 8) ^ (sx & 0xff) ^ 0x63;
  5912. SBOX[x] = sx;
  5913. INV_SBOX[sx] = x;
  5914. // Compute multiplication
  5915. var x2 = d[x];
  5916. var x4 = d[x2];
  5917. var x8 = d[x4];
  5918. // Compute sub bytes, mix columns tables
  5919. var t = (d[sx] * 0x101) ^ (sx * 0x1010100);
  5920. SUB_MIX_0[x] = (t << 24) | (t >>> 8);
  5921. SUB_MIX_1[x] = (t << 16) | (t >>> 16);
  5922. SUB_MIX_2[x] = (t << 8) | (t >>> 24);
  5923. SUB_MIX_3[x] = t;
  5924. // Compute inv sub bytes, inv mix columns tables
  5925. var t = (x8 * 0x1010101) ^ (x4 * 0x10001) ^ (x2 * 0x101) ^ (x * 0x1010100);
  5926. INV_SUB_MIX_0[sx] = (t << 24) | (t >>> 8);
  5927. INV_SUB_MIX_1[sx] = (t << 16) | (t >>> 16);
  5928. INV_SUB_MIX_2[sx] = (t << 8) | (t >>> 24);
  5929. INV_SUB_MIX_3[sx] = t;
  5930. // Compute next counter
  5931. if (!x) {
  5932. x = xi = 1;
  5933. } else {
  5934. x = x2 ^ d[d[d[x8 ^ x2]]];
  5935. xi ^= d[d[xi]];
  5936. }
  5937. }
  5938. }());
  5939. // Precomputed Rcon lookup
  5940. var RCON = [0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36];
  5941. /**
  5942. * AES block cipher algorithm.
  5943. */
  5944. var AES = C_algo.AES = BlockCipher.extend({
  5945. _doReset: function () {
  5946. // Skip reset of nRounds has been set before and key did not change
  5947. if (this._nRounds && this._keyPriorReset === this._key) {
  5948. return;
  5949. }
  5950. // Shortcuts
  5951. var key = this._keyPriorReset = this._key;
  5952. var keyWords = key.words;
  5953. var keySize = key.sigBytes / 4;
  5954. // Compute number of rounds
  5955. var nRounds = this._nRounds = keySize + 6;
  5956. // Compute number of key schedule rows
  5957. var ksRows = (nRounds + 1) * 4;
  5958. // Compute key schedule
  5959. var keySchedule = this._keySchedule = [];
  5960. for (var ksRow = 0; ksRow < ksRows; ksRow++) {
  5961. if (ksRow < keySize) {
  5962. keySchedule[ksRow] = keyWords[ksRow];
  5963. } else {
  5964. var t = keySchedule[ksRow - 1];
  5965. if (!(ksRow % keySize)) {
  5966. // Rot word
  5967. t = (t << 8) | (t >>> 24);
  5968. // Sub word
  5969. t = (SBOX[t >>> 24] << 24) | (SBOX[(t >>> 16) & 0xff] << 16) | (SBOX[(t >>> 8) & 0xff] << 8) | SBOX[t & 0xff];
  5970. // Mix Rcon
  5971. t ^= RCON[(ksRow / keySize) | 0] << 24;
  5972. } else if (keySize > 6 && ksRow % keySize == 4) {
  5973. // Sub word
  5974. t = (SBOX[t >>> 24] << 24) | (SBOX[(t >>> 16) & 0xff] << 16) | (SBOX[(t >>> 8) & 0xff] << 8) | SBOX[t & 0xff];
  5975. }
  5976. keySchedule[ksRow] = keySchedule[ksRow - keySize] ^ t;
  5977. }
  5978. }
  5979. // Compute inv key schedule
  5980. var invKeySchedule = this._invKeySchedule = [];
  5981. for (var invKsRow = 0; invKsRow < ksRows; invKsRow++) {
  5982. var ksRow = ksRows - invKsRow;
  5983. if (invKsRow % 4) {
  5984. var t = keySchedule[ksRow];
  5985. } else {
  5986. var t = keySchedule[ksRow - 4];
  5987. }
  5988. if (invKsRow < 4 || ksRow <= 4) {
  5989. invKeySchedule[invKsRow] = t;
  5990. } else {
  5991. invKeySchedule[invKsRow] = INV_SUB_MIX_0[SBOX[t >>> 24]] ^ INV_SUB_MIX_1[SBOX[(t >>> 16) & 0xff]] ^
  5992. INV_SUB_MIX_2[SBOX[(t >>> 8) & 0xff]] ^ INV_SUB_MIX_3[SBOX[t & 0xff]];
  5993. }
  5994. }
  5995. },
  5996. encryptBlock: function (M, offset) {
  5997. this._doCryptBlock(M, offset, this._keySchedule, SUB_MIX_0, SUB_MIX_1, SUB_MIX_2, SUB_MIX_3, SBOX);
  5998. },
  5999. decryptBlock: function (M, offset) {
  6000. // Swap 2nd and 4th rows
  6001. var t = M[offset + 1];
  6002. M[offset + 1] = M[offset + 3];
  6003. M[offset + 3] = t;
  6004. this._doCryptBlock(M, offset, this._invKeySchedule, INV_SUB_MIX_0, INV_SUB_MIX_1, INV_SUB_MIX_2, INV_SUB_MIX_3, INV_SBOX);
  6005. // Inv swap 2nd and 4th rows
  6006. var t = M[offset + 1];
  6007. M[offset + 1] = M[offset + 3];
  6008. M[offset + 3] = t;
  6009. },
  6010. _doCryptBlock: function (M, offset, keySchedule, SUB_MIX_0, SUB_MIX_1, SUB_MIX_2, SUB_MIX_3, SBOX) {
  6011. // Shortcut
  6012. var nRounds = this._nRounds;
  6013. // Get input, add round key
  6014. var s0 = M[offset] ^ keySchedule[0];
  6015. var s1 = M[offset + 1] ^ keySchedule[1];
  6016. var s2 = M[offset + 2] ^ keySchedule[2];
  6017. var s3 = M[offset + 3] ^ keySchedule[3];
  6018. // Key schedule row counter
  6019. var ksRow = 4;
  6020. // Rounds
  6021. for (var round = 1; round < nRounds; round++) {
  6022. // Shift rows, sub bytes, mix columns, add round key
  6023. var t0 = SUB_MIX_0[s0 >>> 24] ^ SUB_MIX_1[(s1 >>> 16) & 0xff] ^ SUB_MIX_2[(s2 >>> 8) & 0xff] ^ SUB_MIX_3[s3 & 0xff] ^ keySchedule[ksRow++];
  6024. var t1 = SUB_MIX_0[s1 >>> 24] ^ SUB_MIX_1[(s2 >>> 16) & 0xff] ^ SUB_MIX_2[(s3 >>> 8) & 0xff] ^ SUB_MIX_3[s0 & 0xff] ^ keySchedule[ksRow++];
  6025. var t2 = SUB_MIX_0[s2 >>> 24] ^ SUB_MIX_1[(s3 >>> 16) & 0xff] ^ SUB_MIX_2[(s0 >>> 8) & 0xff] ^ SUB_MIX_3[s1 & 0xff] ^ keySchedule[ksRow++];
  6026. var t3 = SUB_MIX_0[s3 >>> 24] ^ SUB_MIX_1[(s0 >>> 16) & 0xff] ^ SUB_MIX_2[(s1 >>> 8) & 0xff] ^ SUB_MIX_3[s2 & 0xff] ^ keySchedule[ksRow++];
  6027. // Update state
  6028. s0 = t0;
  6029. s1 = t1;
  6030. s2 = t2;
  6031. s3 = t3;
  6032. }
  6033. // Shift rows, sub bytes, add round key
  6034. var t0 = ((SBOX[s0 >>> 24] << 24) | (SBOX[(s1 >>> 16) & 0xff] << 16) | (SBOX[(s2 >>> 8) & 0xff] << 8) | SBOX[s3 & 0xff]) ^ keySchedule[ksRow++];
  6035. var t1 = ((SBOX[s1 >>> 24] << 24) | (SBOX[(s2 >>> 16) & 0xff] << 16) | (SBOX[(s3 >>> 8) & 0xff] << 8) | SBOX[s0 & 0xff]) ^ keySchedule[ksRow++];
  6036. var t2 = ((SBOX[s2 >>> 24] << 24) | (SBOX[(s3 >>> 16) & 0xff] << 16) | (SBOX[(s0 >>> 8) & 0xff] << 8) | SBOX[s1 & 0xff]) ^ keySchedule[ksRow++];
  6037. var t3 = ((SBOX[s3 >>> 24] << 24) | (SBOX[(s0 >>> 16) & 0xff] << 16) | (SBOX[(s1 >>> 8) & 0xff] << 8) | SBOX[s2 & 0xff]) ^ keySchedule[ksRow++];
  6038. // Set output
  6039. M[offset] = t0;
  6040. M[offset + 1] = t1;
  6041. M[offset + 2] = t2;
  6042. M[offset + 3] = t3;
  6043. },
  6044. keySize: 256/32
  6045. });
  6046. /**
  6047. * Shortcut functions to the cipher's object interface.
  6048. *
  6049. * @example
  6050. *
  6051. * var ciphertext = CryptoJS.AES.encrypt(message, key, cfg);
  6052. * var plaintext = CryptoJS.AES.decrypt(ciphertext, key, cfg);
  6053. */
  6054. C.AES = BlockCipher._createHelper(AES);
  6055. }());
  6056. return CryptoJS.AES;
  6057. }));
  6058. },{"./cipher-core":52,"./core":53,"./enc-base64":54,"./evpkdf":56,"./md5":61}],52:[function(require,module,exports){
  6059. ;(function (root, factory) {
  6060. if (typeof exports === "object") {
  6061. // CommonJS
  6062. module.exports = exports = factory(require("./core"));
  6063. }
  6064. else if (typeof define === "function" && define.amd) {
  6065. // AMD
  6066. define(["./core"], factory);
  6067. }
  6068. else {
  6069. // Global (browser)
  6070. factory(root.CryptoJS);
  6071. }
  6072. }(this, function (CryptoJS) {
  6073. /**
  6074. * Cipher core components.
  6075. */
  6076. CryptoJS.lib.Cipher || (function (undefined) {
  6077. // Shortcuts
  6078. var C = CryptoJS;
  6079. var C_lib = C.lib;
  6080. var Base = C_lib.Base;
  6081. var WordArray = C_lib.WordArray;
  6082. var BufferedBlockAlgorithm = C_lib.BufferedBlockAlgorithm;
  6083. var C_enc = C.enc;
  6084. var Utf8 = C_enc.Utf8;
  6085. var Base64 = C_enc.Base64;
  6086. var C_algo = C.algo;
  6087. var EvpKDF = C_algo.EvpKDF;
  6088. /**
  6089. * Abstract base cipher template.
  6090. *
  6091. * @property {number} keySize This cipher's key size. Default: 4 (128 bits)
  6092. * @property {number} ivSize This cipher's IV size. Default: 4 (128 bits)
  6093. * @property {number} _ENC_XFORM_MODE A constant representing encryption mode.
  6094. * @property {number} _DEC_XFORM_MODE A constant representing decryption mode.
  6095. */
  6096. var Cipher = C_lib.Cipher = BufferedBlockAlgorithm.extend({
  6097. /**
  6098. * Configuration options.
  6099. *
  6100. * @property {WordArray} iv The IV to use for this operation.
  6101. */
  6102. cfg: Base.extend(),
  6103. /**
  6104. * Creates this cipher in encryption mode.
  6105. *
  6106. * @param {WordArray} key The key.
  6107. * @param {Object} cfg (Optional) The configuration options to use for this operation.
  6108. *
  6109. * @return {Cipher} A cipher instance.
  6110. *
  6111. * @static
  6112. *
  6113. * @example
  6114. *
  6115. * var cipher = CryptoJS.algo.AES.createEncryptor(keyWordArray, { iv: ivWordArray });
  6116. */
  6117. createEncryptor: function (key, cfg) {
  6118. return this.create(this._ENC_XFORM_MODE, key, cfg);
  6119. },
  6120. /**
  6121. * Creates this cipher in decryption mode.
  6122. *
  6123. * @param {WordArray} key The key.
  6124. * @param {Object} cfg (Optional) The configuration options to use for this operation.
  6125. *
  6126. * @return {Cipher} A cipher instance.
  6127. *
  6128. * @static
  6129. *
  6130. * @example
  6131. *
  6132. * var cipher = CryptoJS.algo.AES.createDecryptor(keyWordArray, { iv: ivWordArray });
  6133. */
  6134. createDecryptor: function (key, cfg) {
  6135. return this.create(this._DEC_XFORM_MODE, key, cfg);
  6136. },
  6137. /**
  6138. * Initializes a newly created cipher.
  6139. *
  6140. * @param {number} xformMode Either the encryption or decryption transormation mode constant.
  6141. * @param {WordArray} key The key.
  6142. * @param {Object} cfg (Optional) The configuration options to use for this operation.
  6143. *
  6144. * @example
  6145. *
  6146. * var cipher = CryptoJS.algo.AES.create(CryptoJS.algo.AES._ENC_XFORM_MODE, keyWordArray, { iv: ivWordArray });
  6147. */
  6148. init: function (xformMode, key, cfg) {
  6149. // Apply config defaults
  6150. this.cfg = this.cfg.extend(cfg);
  6151. // Store transform mode and key
  6152. this._xformMode = xformMode;
  6153. this._key = key;
  6154. // Set initial values
  6155. this.reset();
  6156. },
  6157. /**
  6158. * Resets this cipher to its initial state.
  6159. *
  6160. * @example
  6161. *
  6162. * cipher.reset();
  6163. */
  6164. reset: function () {
  6165. // Reset data buffer
  6166. BufferedBlockAlgorithm.reset.call(this);
  6167. // Perform concrete-cipher logic
  6168. this._doReset();
  6169. },
  6170. /**
  6171. * Adds data to be encrypted or decrypted.
  6172. *
  6173. * @param {WordArray|string} dataUpdate The data to encrypt or decrypt.
  6174. *
  6175. * @return {WordArray} The data after processing.
  6176. *
  6177. * @example
  6178. *
  6179. * var encrypted = cipher.process('data');
  6180. * var encrypted = cipher.process(wordArray);
  6181. */
  6182. process: function (dataUpdate) {
  6183. // Append
  6184. this._append(dataUpdate);
  6185. // Process available blocks
  6186. return this._process();
  6187. },
  6188. /**
  6189. * Finalizes the encryption or decryption process.
  6190. * Note that the finalize operation is effectively a destructive, read-once operation.
  6191. *
  6192. * @param {WordArray|string} dataUpdate The final data to encrypt or decrypt.
  6193. *
  6194. * @return {WordArray} The data after final processing.
  6195. *
  6196. * @example
  6197. *
  6198. * var encrypted = cipher.finalize();
  6199. * var encrypted = cipher.finalize('data');
  6200. * var encrypted = cipher.finalize(wordArray);
  6201. */
  6202. finalize: function (dataUpdate) {
  6203. // Final data update
  6204. if (dataUpdate) {
  6205. this._append(dataUpdate);
  6206. }
  6207. // Perform concrete-cipher logic
  6208. var finalProcessedData = this._doFinalize();
  6209. return finalProcessedData;
  6210. },
  6211. keySize: 128/32,
  6212. ivSize: 128/32,
  6213. _ENC_XFORM_MODE: 1,
  6214. _DEC_XFORM_MODE: 2,
  6215. /**
  6216. * Creates shortcut functions to a cipher's object interface.
  6217. *
  6218. * @param {Cipher} cipher The cipher to create a helper for.
  6219. *
  6220. * @return {Object} An object with encrypt and decrypt shortcut functions.
  6221. *
  6222. * @static
  6223. *
  6224. * @example
  6225. *
  6226. * var AES = CryptoJS.lib.Cipher._createHelper(CryptoJS.algo.AES);
  6227. */
  6228. _createHelper: (function () {
  6229. function selectCipherStrategy(key) {
  6230. if (typeof key == 'string') {
  6231. return PasswordBasedCipher;
  6232. } else {
  6233. return SerializableCipher;
  6234. }
  6235. }
  6236. return function (cipher) {
  6237. return {
  6238. encrypt: function (message, key, cfg) {
  6239. return selectCipherStrategy(key).encrypt(cipher, message, key, cfg);
  6240. },
  6241. decrypt: function (ciphertext, key, cfg) {
  6242. return selectCipherStrategy(key).decrypt(cipher, ciphertext, key, cfg);
  6243. }
  6244. };
  6245. };
  6246. }())
  6247. });
  6248. /**
  6249. * Abstract base stream cipher template.
  6250. *
  6251. * @property {number} blockSize The number of 32-bit words this cipher operates on. Default: 1 (32 bits)
  6252. */
  6253. var StreamCipher = C_lib.StreamCipher = Cipher.extend({
  6254. _doFinalize: function () {
  6255. // Process partial blocks
  6256. var finalProcessedBlocks = this._process(!!'flush');
  6257. return finalProcessedBlocks;
  6258. },
  6259. blockSize: 1
  6260. });
  6261. /**
  6262. * Mode namespace.
  6263. */
  6264. var C_mode = C.mode = {};
  6265. /**
  6266. * Abstract base block cipher mode template.
  6267. */
  6268. var BlockCipherMode = C_lib.BlockCipherMode = Base.extend({
  6269. /**
  6270. * Creates this mode for encryption.
  6271. *
  6272. * @param {Cipher} cipher A block cipher instance.
  6273. * @param {Array} iv The IV words.
  6274. *
  6275. * @static
  6276. *
  6277. * @example
  6278. *
  6279. * var mode = CryptoJS.mode.CBC.createEncryptor(cipher, iv.words);
  6280. */
  6281. createEncryptor: function (cipher, iv) {
  6282. return this.Encryptor.create(cipher, iv);
  6283. },
  6284. /**
  6285. * Creates this mode for decryption.
  6286. *
  6287. * @param {Cipher} cipher A block cipher instance.
  6288. * @param {Array} iv The IV words.
  6289. *
  6290. * @static
  6291. *
  6292. * @example
  6293. *
  6294. * var mode = CryptoJS.mode.CBC.createDecryptor(cipher, iv.words);
  6295. */
  6296. createDecryptor: function (cipher, iv) {
  6297. return this.Decryptor.create(cipher, iv);
  6298. },
  6299. /**
  6300. * Initializes a newly created mode.
  6301. *
  6302. * @param {Cipher} cipher A block cipher instance.
  6303. * @param {Array} iv The IV words.
  6304. *
  6305. * @example
  6306. *
  6307. * var mode = CryptoJS.mode.CBC.Encryptor.create(cipher, iv.words);
  6308. */
  6309. init: function (cipher, iv) {
  6310. this._cipher = cipher;
  6311. this._iv = iv;
  6312. }
  6313. });
  6314. /**
  6315. * Cipher Block Chaining mode.
  6316. */
  6317. var CBC = C_mode.CBC = (function () {
  6318. /**
  6319. * Abstract base CBC mode.
  6320. */
  6321. var CBC = BlockCipherMode.extend();
  6322. /**
  6323. * CBC encryptor.
  6324. */
  6325. CBC.Encryptor = CBC.extend({
  6326. /**
  6327. * Processes the data block at offset.
  6328. *
  6329. * @param {Array} words The data words to operate on.
  6330. * @param {number} offset The offset where the block starts.
  6331. *
  6332. * @example
  6333. *
  6334. * mode.processBlock(data.words, offset);
  6335. */
  6336. processBlock: function (words, offset) {
  6337. // Shortcuts
  6338. var cipher = this._cipher;
  6339. var blockSize = cipher.blockSize;
  6340. // XOR and encrypt
  6341. xorBlock.call(this, words, offset, blockSize);
  6342. cipher.encryptBlock(words, offset);
  6343. // Remember this block to use with next block
  6344. this._prevBlock = words.slice(offset, offset + blockSize);
  6345. }
  6346. });
  6347. /**
  6348. * CBC decryptor.
  6349. */
  6350. CBC.Decryptor = CBC.extend({
  6351. /**
  6352. * Processes the data block at offset.
  6353. *
  6354. * @param {Array} words The data words to operate on.
  6355. * @param {number} offset The offset where the block starts.
  6356. *
  6357. * @example
  6358. *
  6359. * mode.processBlock(data.words, offset);
  6360. */
  6361. processBlock: function (words, offset) {
  6362. // Shortcuts
  6363. var cipher = this._cipher;
  6364. var blockSize = cipher.blockSize;
  6365. // Remember this block to use with next block
  6366. var thisBlock = words.slice(offset, offset + blockSize);
  6367. // Decrypt and XOR
  6368. cipher.decryptBlock(words, offset);
  6369. xorBlock.call(this, words, offset, blockSize);
  6370. // This block becomes the previous block
  6371. this._prevBlock = thisBlock;
  6372. }
  6373. });
  6374. function xorBlock(words, offset, blockSize) {
  6375. // Shortcut
  6376. var iv = this._iv;
  6377. // Choose mixing block
  6378. if (iv) {
  6379. var block = iv;
  6380. // Remove IV for subsequent blocks
  6381. this._iv = undefined;
  6382. } else {
  6383. var block = this._prevBlock;
  6384. }
  6385. // XOR blocks
  6386. for (var i = 0; i < blockSize; i++) {
  6387. words[offset + i] ^= block[i];
  6388. }
  6389. }
  6390. return CBC;
  6391. }());
  6392. /**
  6393. * Padding namespace.
  6394. */
  6395. var C_pad = C.pad = {};
  6396. /**
  6397. * PKCS #5/7 padding strategy.
  6398. */
  6399. var Pkcs7 = C_pad.Pkcs7 = {
  6400. /**
  6401. * Pads data using the algorithm defined in PKCS #5/7.
  6402. *
  6403. * @param {WordArray} data The data to pad.
  6404. * @param {number} blockSize The multiple that the data should be padded to.
  6405. *
  6406. * @static
  6407. *
  6408. * @example
  6409. *
  6410. * CryptoJS.pad.Pkcs7.pad(wordArray, 4);
  6411. */
  6412. pad: function (data, blockSize) {
  6413. // Shortcut
  6414. var blockSizeBytes = blockSize * 4;
  6415. // Count padding bytes
  6416. var nPaddingBytes = blockSizeBytes - data.sigBytes % blockSizeBytes;
  6417. // Create padding word
  6418. var paddingWord = (nPaddingBytes << 24) | (nPaddingBytes << 16) | (nPaddingBytes << 8) | nPaddingBytes;
  6419. // Create padding
  6420. var paddingWords = [];
  6421. for (var i = 0; i < nPaddingBytes; i += 4) {
  6422. paddingWords.push(paddingWord);
  6423. }
  6424. var padding = WordArray.create(paddingWords, nPaddingBytes);
  6425. // Add padding
  6426. data.concat(padding);
  6427. },
  6428. /**
  6429. * Unpads data that had been padded using the algorithm defined in PKCS #5/7.
  6430. *
  6431. * @param {WordArray} data The data to unpad.
  6432. *
  6433. * @static
  6434. *
  6435. * @example
  6436. *
  6437. * CryptoJS.pad.Pkcs7.unpad(wordArray);
  6438. */
  6439. unpad: function (data) {
  6440. // Get number of padding bytes from last byte
  6441. var nPaddingBytes = data.words[(data.sigBytes - 1) >>> 2] & 0xff;
  6442. // Remove padding
  6443. data.sigBytes -= nPaddingBytes;
  6444. }
  6445. };
  6446. /**
  6447. * Abstract base block cipher template.
  6448. *
  6449. * @property {number} blockSize The number of 32-bit words this cipher operates on. Default: 4 (128 bits)
  6450. */
  6451. var BlockCipher = C_lib.BlockCipher = Cipher.extend({
  6452. /**
  6453. * Configuration options.
  6454. *
  6455. * @property {Mode} mode The block mode to use. Default: CBC
  6456. * @property {Padding} padding The padding strategy to use. Default: Pkcs7
  6457. */
  6458. cfg: Cipher.cfg.extend({
  6459. mode: CBC,
  6460. padding: Pkcs7
  6461. }),
  6462. reset: function () {
  6463. // Reset cipher
  6464. Cipher.reset.call(this);
  6465. // Shortcuts
  6466. var cfg = this.cfg;
  6467. var iv = cfg.iv;
  6468. var mode = cfg.mode;
  6469. // Reset block mode
  6470. if (this._xformMode == this._ENC_XFORM_MODE) {
  6471. var modeCreator = mode.createEncryptor;
  6472. } else /* if (this._xformMode == this._DEC_XFORM_MODE) */ {
  6473. var modeCreator = mode.createDecryptor;
  6474. // Keep at least one block in the buffer for unpadding
  6475. this._minBufferSize = 1;
  6476. }
  6477. this._mode = modeCreator.call(mode, this, iv && iv.words);
  6478. },
  6479. _doProcessBlock: function (words, offset) {
  6480. this._mode.processBlock(words, offset);
  6481. },
  6482. _doFinalize: function () {
  6483. // Shortcut
  6484. var padding = this.cfg.padding;
  6485. // Finalize
  6486. if (this._xformMode == this._ENC_XFORM_MODE) {
  6487. // Pad data
  6488. padding.pad(this._data, this.blockSize);
  6489. // Process final blocks
  6490. var finalProcessedBlocks = this._process(!!'flush');
  6491. } else /* if (this._xformMode == this._DEC_XFORM_MODE) */ {
  6492. // Process final blocks
  6493. var finalProcessedBlocks = this._process(!!'flush');
  6494. // Unpad data
  6495. padding.unpad(finalProcessedBlocks);
  6496. }
  6497. return finalProcessedBlocks;
  6498. },
  6499. blockSize: 128/32
  6500. });
  6501. /**
  6502. * A collection of cipher parameters.
  6503. *
  6504. * @property {WordArray} ciphertext The raw ciphertext.
  6505. * @property {WordArray} key The key to this ciphertext.
  6506. * @property {WordArray} iv The IV used in the ciphering operation.
  6507. * @property {WordArray} salt The salt used with a key derivation function.
  6508. * @property {Cipher} algorithm The cipher algorithm.
  6509. * @property {Mode} mode The block mode used in the ciphering operation.
  6510. * @property {Padding} padding The padding scheme used in the ciphering operation.
  6511. * @property {number} blockSize The block size of the cipher.
  6512. * @property {Format} formatter The default formatting strategy to convert this cipher params object to a string.
  6513. */
  6514. var CipherParams = C_lib.CipherParams = Base.extend({
  6515. /**
  6516. * Initializes a newly created cipher params object.
  6517. *
  6518. * @param {Object} cipherParams An object with any of the possible cipher parameters.
  6519. *
  6520. * @example
  6521. *
  6522. * var cipherParams = CryptoJS.lib.CipherParams.create({
  6523. * ciphertext: ciphertextWordArray,
  6524. * key: keyWordArray,
  6525. * iv: ivWordArray,
  6526. * salt: saltWordArray,
  6527. * algorithm: CryptoJS.algo.AES,
  6528. * mode: CryptoJS.mode.CBC,
  6529. * padding: CryptoJS.pad.PKCS7,
  6530. * blockSize: 4,
  6531. * formatter: CryptoJS.format.OpenSSL
  6532. * });
  6533. */
  6534. init: function (cipherParams) {
  6535. this.mixIn(cipherParams);
  6536. },
  6537. /**
  6538. * Converts this cipher params object to a string.
  6539. *
  6540. * @param {Format} formatter (Optional) The formatting strategy to use.
  6541. *
  6542. * @return {string} The stringified cipher params.
  6543. *
  6544. * @throws Error If neither the formatter nor the default formatter is set.
  6545. *
  6546. * @example
  6547. *
  6548. * var string = cipherParams + '';
  6549. * var string = cipherParams.toString();
  6550. * var string = cipherParams.toString(CryptoJS.format.OpenSSL);
  6551. */
  6552. toString: function (formatter) {
  6553. return (formatter || this.formatter).stringify(this);
  6554. }
  6555. });
  6556. /**
  6557. * Format namespace.
  6558. */
  6559. var C_format = C.format = {};
  6560. /**
  6561. * OpenSSL formatting strategy.
  6562. */
  6563. var OpenSSLFormatter = C_format.OpenSSL = {
  6564. /**
  6565. * Converts a cipher params object to an OpenSSL-compatible string.
  6566. *
  6567. * @param {CipherParams} cipherParams The cipher params object.
  6568. *
  6569. * @return {string} The OpenSSL-compatible string.
  6570. *
  6571. * @static
  6572. *
  6573. * @example
  6574. *
  6575. * var openSSLString = CryptoJS.format.OpenSSL.stringify(cipherParams);
  6576. */
  6577. stringify: function (cipherParams) {
  6578. // Shortcuts
  6579. var ciphertext = cipherParams.ciphertext;
  6580. var salt = cipherParams.salt;
  6581. // Format
  6582. if (salt) {
  6583. var wordArray = WordArray.create([0x53616c74, 0x65645f5f]).concat(salt).concat(ciphertext);
  6584. } else {
  6585. var wordArray = ciphertext;
  6586. }
  6587. return wordArray.toString(Base64);
  6588. },
  6589. /**
  6590. * Converts an OpenSSL-compatible string to a cipher params object.
  6591. *
  6592. * @param {string} openSSLStr The OpenSSL-compatible string.
  6593. *
  6594. * @return {CipherParams} The cipher params object.
  6595. *
  6596. * @static
  6597. *
  6598. * @example
  6599. *
  6600. * var cipherParams = CryptoJS.format.OpenSSL.parse(openSSLString);
  6601. */
  6602. parse: function (openSSLStr) {
  6603. // Parse base64
  6604. var ciphertext = Base64.parse(openSSLStr);
  6605. // Shortcut
  6606. var ciphertextWords = ciphertext.words;
  6607. // Test for salt
  6608. if (ciphertextWords[0] == 0x53616c74 && ciphertextWords[1] == 0x65645f5f) {
  6609. // Extract salt
  6610. var salt = WordArray.create(ciphertextWords.slice(2, 4));
  6611. // Remove salt from ciphertext
  6612. ciphertextWords.splice(0, 4);
  6613. ciphertext.sigBytes -= 16;
  6614. }
  6615. return CipherParams.create({ ciphertext: ciphertext, salt: salt });
  6616. }
  6617. };
  6618. /**
  6619. * A cipher wrapper that returns ciphertext as a serializable cipher params object.
  6620. */
  6621. var SerializableCipher = C_lib.SerializableCipher = Base.extend({
  6622. /**
  6623. * Configuration options.
  6624. *
  6625. * @property {Formatter} format The formatting strategy to convert cipher param objects to and from a string. Default: OpenSSL
  6626. */
  6627. cfg: Base.extend({
  6628. format: OpenSSLFormatter
  6629. }),
  6630. /**
  6631. * Encrypts a message.
  6632. *
  6633. * @param {Cipher} cipher The cipher algorithm to use.
  6634. * @param {WordArray|string} message The message to encrypt.
  6635. * @param {WordArray} key The key.
  6636. * @param {Object} cfg (Optional) The configuration options to use for this operation.
  6637. *
  6638. * @return {CipherParams} A cipher params object.
  6639. *
  6640. * @static
  6641. *
  6642. * @example
  6643. *
  6644. * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key);
  6645. * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key, { iv: iv });
  6646. * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key, { iv: iv, format: CryptoJS.format.OpenSSL });
  6647. */
  6648. encrypt: function (cipher, message, key, cfg) {
  6649. // Apply config defaults
  6650. cfg = this.cfg.extend(cfg);
  6651. // Encrypt
  6652. var encryptor = cipher.createEncryptor(key, cfg);
  6653. var ciphertext = encryptor.finalize(message);
  6654. // Shortcut
  6655. var cipherCfg = encryptor.cfg;
  6656. // Create and return serializable cipher params
  6657. return CipherParams.create({
  6658. ciphertext: ciphertext,
  6659. key: key,
  6660. iv: cipherCfg.iv,
  6661. algorithm: cipher,
  6662. mode: cipherCfg.mode,
  6663. padding: cipherCfg.padding,
  6664. blockSize: cipher.blockSize,
  6665. formatter: cfg.format
  6666. });
  6667. },
  6668. /**
  6669. * Decrypts serialized ciphertext.
  6670. *
  6671. * @param {Cipher} cipher The cipher algorithm to use.
  6672. * @param {CipherParams|string} ciphertext The ciphertext to decrypt.
  6673. * @param {WordArray} key The key.
  6674. * @param {Object} cfg (Optional) The configuration options to use for this operation.
  6675. *
  6676. * @return {WordArray} The plaintext.
  6677. *
  6678. * @static
  6679. *
  6680. * @example
  6681. *
  6682. * var plaintext = CryptoJS.lib.SerializableCipher.decrypt(CryptoJS.algo.AES, formattedCiphertext, key, { iv: iv, format: CryptoJS.format.OpenSSL });
  6683. * var plaintext = CryptoJS.lib.SerializableCipher.decrypt(CryptoJS.algo.AES, ciphertextParams, key, { iv: iv, format: CryptoJS.format.OpenSSL });
  6684. */
  6685. decrypt: function (cipher, ciphertext, key, cfg) {
  6686. // Apply config defaults
  6687. cfg = this.cfg.extend(cfg);
  6688. // Convert string to CipherParams
  6689. ciphertext = this._parse(ciphertext, cfg.format);
  6690. // Decrypt
  6691. var plaintext = cipher.createDecryptor(key, cfg).finalize(ciphertext.ciphertext);
  6692. return plaintext;
  6693. },
  6694. /**
  6695. * Converts serialized ciphertext to CipherParams,
  6696. * else assumed CipherParams already and returns ciphertext unchanged.
  6697. *
  6698. * @param {CipherParams|string} ciphertext The ciphertext.
  6699. * @param {Formatter} format The formatting strategy to use to parse serialized ciphertext.
  6700. *
  6701. * @return {CipherParams} The unserialized ciphertext.
  6702. *
  6703. * @static
  6704. *
  6705. * @example
  6706. *
  6707. * var ciphertextParams = CryptoJS.lib.SerializableCipher._parse(ciphertextStringOrParams, format);
  6708. */
  6709. _parse: function (ciphertext, format) {
  6710. if (typeof ciphertext == 'string') {
  6711. return format.parse(ciphertext, this);
  6712. } else {
  6713. return ciphertext;
  6714. }
  6715. }
  6716. });
  6717. /**
  6718. * Key derivation function namespace.
  6719. */
  6720. var C_kdf = C.kdf = {};
  6721. /**
  6722. * OpenSSL key derivation function.
  6723. */
  6724. var OpenSSLKdf = C_kdf.OpenSSL = {
  6725. /**
  6726. * Derives a key and IV from a password.
  6727. *
  6728. * @param {string} password The password to derive from.
  6729. * @param {number} keySize The size in words of the key to generate.
  6730. * @param {number} ivSize The size in words of the IV to generate.
  6731. * @param {WordArray|string} salt (Optional) A 64-bit salt to use. If omitted, a salt will be generated randomly.
  6732. *
  6733. * @return {CipherParams} A cipher params object with the key, IV, and salt.
  6734. *
  6735. * @static
  6736. *
  6737. * @example
  6738. *
  6739. * var derivedParams = CryptoJS.kdf.OpenSSL.execute('Password', 256/32, 128/32);
  6740. * var derivedParams = CryptoJS.kdf.OpenSSL.execute('Password', 256/32, 128/32, 'saltsalt');
  6741. */
  6742. execute: function (password, keySize, ivSize, salt) {
  6743. // Generate random salt
  6744. if (!salt) {
  6745. salt = WordArray.random(64/8);
  6746. }
  6747. // Derive key and IV
  6748. var key = EvpKDF.create({ keySize: keySize + ivSize }).compute(password, salt);
  6749. // Separate key and IV
  6750. var iv = WordArray.create(key.words.slice(keySize), ivSize * 4);
  6751. key.sigBytes = keySize * 4;
  6752. // Return params
  6753. return CipherParams.create({ key: key, iv: iv, salt: salt });
  6754. }
  6755. };
  6756. /**
  6757. * A serializable cipher wrapper that derives the key from a password,
  6758. * and returns ciphertext as a serializable cipher params object.
  6759. */
  6760. var PasswordBasedCipher = C_lib.PasswordBasedCipher = SerializableCipher.extend({
  6761. /**
  6762. * Configuration options.
  6763. *
  6764. * @property {KDF} kdf The key derivation function to use to generate a key and IV from a password. Default: OpenSSL
  6765. */
  6766. cfg: SerializableCipher.cfg.extend({
  6767. kdf: OpenSSLKdf
  6768. }),
  6769. /**
  6770. * Encrypts a message using a password.
  6771. *
  6772. * @param {Cipher} cipher The cipher algorithm to use.
  6773. * @param {WordArray|string} message The message to encrypt.
  6774. * @param {string} password The password.
  6775. * @param {Object} cfg (Optional) The configuration options to use for this operation.
  6776. *
  6777. * @return {CipherParams} A cipher params object.
  6778. *
  6779. * @static
  6780. *
  6781. * @example
  6782. *
  6783. * var ciphertextParams = CryptoJS.lib.PasswordBasedCipher.encrypt(CryptoJS.algo.AES, message, 'password');
  6784. * var ciphertextParams = CryptoJS.lib.PasswordBasedCipher.encrypt(CryptoJS.algo.AES, message, 'password', { format: CryptoJS.format.OpenSSL });
  6785. */
  6786. encrypt: function (cipher, message, password, cfg) {
  6787. // Apply config defaults
  6788. cfg = this.cfg.extend(cfg);
  6789. // Derive key and other params
  6790. var derivedParams = cfg.kdf.execute(password, cipher.keySize, cipher.ivSize);
  6791. // Add IV to config
  6792. cfg.iv = derivedParams.iv;
  6793. // Encrypt
  6794. var ciphertext = SerializableCipher.encrypt.call(this, cipher, message, derivedParams.key, cfg);
  6795. // Mix in derived params
  6796. ciphertext.mixIn(derivedParams);
  6797. return ciphertext;
  6798. },
  6799. /**
  6800. * Decrypts serialized ciphertext using a password.
  6801. *
  6802. * @param {Cipher} cipher The cipher algorithm to use.
  6803. * @param {CipherParams|string} ciphertext The ciphertext to decrypt.
  6804. * @param {string} password The password.
  6805. * @param {Object} cfg (Optional) The configuration options to use for this operation.
  6806. *
  6807. * @return {WordArray} The plaintext.
  6808. *
  6809. * @static
  6810. *
  6811. * @example
  6812. *
  6813. * var plaintext = CryptoJS.lib.PasswordBasedCipher.decrypt(CryptoJS.algo.AES, formattedCiphertext, 'password', { format: CryptoJS.format.OpenSSL });
  6814. * var plaintext = CryptoJS.lib.PasswordBasedCipher.decrypt(CryptoJS.algo.AES, ciphertextParams, 'password', { format: CryptoJS.format.OpenSSL });
  6815. */
  6816. decrypt: function (cipher, ciphertext, password, cfg) {
  6817. // Apply config defaults
  6818. cfg = this.cfg.extend(cfg);
  6819. // Convert string to CipherParams
  6820. ciphertext = this._parse(ciphertext, cfg.format);
  6821. // Derive key and other params
  6822. var derivedParams = cfg.kdf.execute(password, cipher.keySize, cipher.ivSize, ciphertext.salt);
  6823. // Add IV to config
  6824. cfg.iv = derivedParams.iv;
  6825. // Decrypt
  6826. var plaintext = SerializableCipher.decrypt.call(this, cipher, ciphertext, derivedParams.key, cfg);
  6827. return plaintext;
  6828. }
  6829. });
  6830. }());
  6831. }));
  6832. },{"./core":53}],53:[function(require,module,exports){
  6833. ;(function (root, factory) {
  6834. if (typeof exports === "object") {
  6835. // CommonJS
  6836. module.exports = exports = factory();
  6837. }
  6838. else if (typeof define === "function" && define.amd) {
  6839. // AMD
  6840. define([], factory);
  6841. }
  6842. else {
  6843. // Global (browser)
  6844. root.CryptoJS = factory();
  6845. }
  6846. }(this, function () {
  6847. /**
  6848. * CryptoJS core components.
  6849. */
  6850. var CryptoJS = CryptoJS || (function (Math, undefined) {
  6851. /*
  6852. * Local polyfil of Object.create
  6853. */
  6854. var create = Object.create || (function () {
  6855. function F() {};
  6856. return function (obj) {
  6857. var subtype;
  6858. F.prototype = obj;
  6859. subtype = new F();
  6860. F.prototype = null;
  6861. return subtype;
  6862. };
  6863. }())
  6864. /**
  6865. * CryptoJS namespace.
  6866. */
  6867. var C = {};
  6868. /**
  6869. * Library namespace.
  6870. */
  6871. var C_lib = C.lib = {};
  6872. /**
  6873. * Base object for prototypal inheritance.
  6874. */
  6875. var Base = C_lib.Base = (function () {
  6876. return {
  6877. /**
  6878. * Creates a new object that inherits from this object.
  6879. *
  6880. * @param {Object} overrides Properties to copy into the new object.
  6881. *
  6882. * @return {Object} The new object.
  6883. *
  6884. * @static
  6885. *
  6886. * @example
  6887. *
  6888. * var MyType = CryptoJS.lib.Base.extend({
  6889. * field: 'value',
  6890. *
  6891. * method: function () {
  6892. * }
  6893. * });
  6894. */
  6895. extend: function (overrides) {
  6896. // Spawn
  6897. var subtype = create(this);
  6898. // Augment
  6899. if (overrides) {
  6900. subtype.mixIn(overrides);
  6901. }
  6902. // Create default initializer
  6903. if (!subtype.hasOwnProperty('init') || this.init === subtype.init) {
  6904. subtype.init = function () {
  6905. subtype.$super.init.apply(this, arguments);
  6906. };
  6907. }
  6908. // Initializer's prototype is the subtype object
  6909. subtype.init.prototype = subtype;
  6910. // Reference supertype
  6911. subtype.$super = this;
  6912. return subtype;
  6913. },
  6914. /**
  6915. * Extends this object and runs the init method.
  6916. * Arguments to create() will be passed to init().
  6917. *
  6918. * @return {Object} The new object.
  6919. *
  6920. * @static
  6921. *
  6922. * @example
  6923. *
  6924. * var instance = MyType.create();
  6925. */
  6926. create: function () {
  6927. var instance = this.extend();
  6928. instance.init.apply(instance, arguments);
  6929. return instance;
  6930. },
  6931. /**
  6932. * Initializes a newly created object.
  6933. * Override this method to add some logic when your objects are created.
  6934. *
  6935. * @example
  6936. *
  6937. * var MyType = CryptoJS.lib.Base.extend({
  6938. * init: function () {
  6939. * // ...
  6940. * }
  6941. * });
  6942. */
  6943. init: function () {
  6944. },
  6945. /**
  6946. * Copies properties into this object.
  6947. *
  6948. * @param {Object} properties The properties to mix in.
  6949. *
  6950. * @example
  6951. *
  6952. * MyType.mixIn({
  6953. * field: 'value'
  6954. * });
  6955. */
  6956. mixIn: function (properties) {
  6957. for (var propertyName in properties) {
  6958. if (properties.hasOwnProperty(propertyName)) {
  6959. this[propertyName] = properties[propertyName];
  6960. }
  6961. }
  6962. // IE won't copy toString using the loop above
  6963. if (properties.hasOwnProperty('toString')) {
  6964. this.toString = properties.toString;
  6965. }
  6966. },
  6967. /**
  6968. * Creates a copy of this object.
  6969. *
  6970. * @return {Object} The clone.
  6971. *
  6972. * @example
  6973. *
  6974. * var clone = instance.clone();
  6975. */
  6976. clone: function () {
  6977. return this.init.prototype.extend(this);
  6978. }
  6979. };
  6980. }());
  6981. /**
  6982. * An array of 32-bit words.
  6983. *
  6984. * @property {Array} words The array of 32-bit words.
  6985. * @property {number} sigBytes The number of significant bytes in this word array.
  6986. */
  6987. var WordArray = C_lib.WordArray = Base.extend({
  6988. /**
  6989. * Initializes a newly created word array.
  6990. *
  6991. * @param {Array} words (Optional) An array of 32-bit words.
  6992. * @param {number} sigBytes (Optional) The number of significant bytes in the words.
  6993. *
  6994. * @example
  6995. *
  6996. * var wordArray = CryptoJS.lib.WordArray.create();
  6997. * var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607]);
  6998. * var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607], 6);
  6999. */
  7000. init: function (words, sigBytes) {
  7001. words = this.words = words || [];
  7002. if (sigBytes != undefined) {
  7003. this.sigBytes = sigBytes;
  7004. } else {
  7005. this.sigBytes = words.length * 4;
  7006. }
  7007. },
  7008. /**
  7009. * Converts this word array to a string.
  7010. *
  7011. * @param {Encoder} encoder (Optional) The encoding strategy to use. Default: CryptoJS.enc.Hex
  7012. *
  7013. * @return {string} The stringified word array.
  7014. *
  7015. * @example
  7016. *
  7017. * var string = wordArray + '';
  7018. * var string = wordArray.toString();
  7019. * var string = wordArray.toString(CryptoJS.enc.Utf8);
  7020. */
  7021. toString: function (encoder) {
  7022. return (encoder || Hex).stringify(this);
  7023. },
  7024. /**
  7025. * Concatenates a word array to this word array.
  7026. *
  7027. * @param {WordArray} wordArray The word array to append.
  7028. *
  7029. * @return {WordArray} This word array.
  7030. *
  7031. * @example
  7032. *
  7033. * wordArray1.concat(wordArray2);
  7034. */
  7035. concat: function (wordArray) {
  7036. // Shortcuts
  7037. var thisWords = this.words;
  7038. var thatWords = wordArray.words;
  7039. var thisSigBytes = this.sigBytes;
  7040. var thatSigBytes = wordArray.sigBytes;
  7041. // Clamp excess bits
  7042. this.clamp();
  7043. // Concat
  7044. if (thisSigBytes % 4) {
  7045. // Copy one byte at a time
  7046. for (var i = 0; i < thatSigBytes; i++) {
  7047. var thatByte = (thatWords[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff;
  7048. thisWords[(thisSigBytes + i) >>> 2] |= thatByte << (24 - ((thisSigBytes + i) % 4) * 8);
  7049. }
  7050. } else {
  7051. // Copy one word at a time
  7052. for (var i = 0; i < thatSigBytes; i += 4) {
  7053. thisWords[(thisSigBytes + i) >>> 2] = thatWords[i >>> 2];
  7054. }
  7055. }
  7056. this.sigBytes += thatSigBytes;
  7057. // Chainable
  7058. return this;
  7059. },
  7060. /**
  7061. * Removes insignificant bits.
  7062. *
  7063. * @example
  7064. *
  7065. * wordArray.clamp();
  7066. */
  7067. clamp: function () {
  7068. // Shortcuts
  7069. var words = this.words;
  7070. var sigBytes = this.sigBytes;
  7071. // Clamp
  7072. words[sigBytes >>> 2] &= 0xffffffff << (32 - (sigBytes % 4) * 8);
  7073. words.length = Math.ceil(sigBytes / 4);
  7074. },
  7075. /**
  7076. * Creates a copy of this word array.
  7077. *
  7078. * @return {WordArray} The clone.
  7079. *
  7080. * @example
  7081. *
  7082. * var clone = wordArray.clone();
  7083. */
  7084. clone: function () {
  7085. var clone = Base.clone.call(this);
  7086. clone.words = this.words.slice(0);
  7087. return clone;
  7088. },
  7089. /**
  7090. * Creates a word array filled with random bytes.
  7091. *
  7092. * @param {number} nBytes The number of random bytes to generate.
  7093. *
  7094. * @return {WordArray} The random word array.
  7095. *
  7096. * @static
  7097. *
  7098. * @example
  7099. *
  7100. * var wordArray = CryptoJS.lib.WordArray.random(16);
  7101. */
  7102. random: function (nBytes) {
  7103. var words = [];
  7104. var r = (function (m_w) {
  7105. var m_w = m_w;
  7106. var m_z = 0x3ade68b1;
  7107. var mask = 0xffffffff;
  7108. return function () {
  7109. m_z = (0x9069 * (m_z & 0xFFFF) + (m_z >> 0x10)) & mask;
  7110. m_w = (0x4650 * (m_w & 0xFFFF) + (m_w >> 0x10)) & mask;
  7111. var result = ((m_z << 0x10) + m_w) & mask;
  7112. result /= 0x100000000;
  7113. result += 0.5;
  7114. return result * (Math.random() > .5 ? 1 : -1);
  7115. }
  7116. });
  7117. for (var i = 0, rcache; i < nBytes; i += 4) {
  7118. var _r = r((rcache || Math.random()) * 0x100000000);
  7119. rcache = _r() * 0x3ade67b7;
  7120. words.push((_r() * 0x100000000) | 0);
  7121. }
  7122. return new WordArray.init(words, nBytes);
  7123. }
  7124. });
  7125. /**
  7126. * Encoder namespace.
  7127. */
  7128. var C_enc = C.enc = {};
  7129. /**
  7130. * Hex encoding strategy.
  7131. */
  7132. var Hex = C_enc.Hex = {
  7133. /**
  7134. * Converts a word array to a hex string.
  7135. *
  7136. * @param {WordArray} wordArray The word array.
  7137. *
  7138. * @return {string} The hex string.
  7139. *
  7140. * @static
  7141. *
  7142. * @example
  7143. *
  7144. * var hexString = CryptoJS.enc.Hex.stringify(wordArray);
  7145. */
  7146. stringify: function (wordArray) {
  7147. // Shortcuts
  7148. var words = wordArray.words;
  7149. var sigBytes = wordArray.sigBytes;
  7150. // Convert
  7151. var hexChars = [];
  7152. for (var i = 0; i < sigBytes; i++) {
  7153. var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff;
  7154. hexChars.push((bite >>> 4).toString(16));
  7155. hexChars.push((bite & 0x0f).toString(16));
  7156. }
  7157. return hexChars.join('');
  7158. },
  7159. /**
  7160. * Converts a hex string to a word array.
  7161. *
  7162. * @param {string} hexStr The hex string.
  7163. *
  7164. * @return {WordArray} The word array.
  7165. *
  7166. * @static
  7167. *
  7168. * @example
  7169. *
  7170. * var wordArray = CryptoJS.enc.Hex.parse(hexString);
  7171. */
  7172. parse: function (hexStr) {
  7173. // Shortcut
  7174. var hexStrLength = hexStr.length;
  7175. // Convert
  7176. var words = [];
  7177. for (var i = 0; i < hexStrLength; i += 2) {
  7178. words[i >>> 3] |= parseInt(hexStr.substr(i, 2), 16) << (24 - (i % 8) * 4);
  7179. }
  7180. return new WordArray.init(words, hexStrLength / 2);
  7181. }
  7182. };
  7183. /**
  7184. * Latin1 encoding strategy.
  7185. */
  7186. var Latin1 = C_enc.Latin1 = {
  7187. /**
  7188. * Converts a word array to a Latin1 string.
  7189. *
  7190. * @param {WordArray} wordArray The word array.
  7191. *
  7192. * @return {string} The Latin1 string.
  7193. *
  7194. * @static
  7195. *
  7196. * @example
  7197. *
  7198. * var latin1String = CryptoJS.enc.Latin1.stringify(wordArray);
  7199. */
  7200. stringify: function (wordArray) {
  7201. // Shortcuts
  7202. var words = wordArray.words;
  7203. var sigBytes = wordArray.sigBytes;
  7204. // Convert
  7205. var latin1Chars = [];
  7206. for (var i = 0; i < sigBytes; i++) {
  7207. var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff;
  7208. latin1Chars.push(String.fromCharCode(bite));
  7209. }
  7210. return latin1Chars.join('');
  7211. },
  7212. /**
  7213. * Converts a Latin1 string to a word array.
  7214. *
  7215. * @param {string} latin1Str The Latin1 string.
  7216. *
  7217. * @return {WordArray} The word array.
  7218. *
  7219. * @static
  7220. *
  7221. * @example
  7222. *
  7223. * var wordArray = CryptoJS.enc.Latin1.parse(latin1String);
  7224. */
  7225. parse: function (latin1Str) {
  7226. // Shortcut
  7227. var latin1StrLength = latin1Str.length;
  7228. // Convert
  7229. var words = [];
  7230. for (var i = 0; i < latin1StrLength; i++) {
  7231. words[i >>> 2] |= (latin1Str.charCodeAt(i) & 0xff) << (24 - (i % 4) * 8);
  7232. }
  7233. return new WordArray.init(words, latin1StrLength);
  7234. }
  7235. };
  7236. /**
  7237. * UTF-8 encoding strategy.
  7238. */
  7239. var Utf8 = C_enc.Utf8 = {
  7240. /**
  7241. * Converts a word array to a UTF-8 string.
  7242. *
  7243. * @param {WordArray} wordArray The word array.
  7244. *
  7245. * @return {string} The UTF-8 string.
  7246. *
  7247. * @static
  7248. *
  7249. * @example
  7250. *
  7251. * var utf8String = CryptoJS.enc.Utf8.stringify(wordArray);
  7252. */
  7253. stringify: function (wordArray) {
  7254. try {
  7255. return decodeURIComponent(escape(Latin1.stringify(wordArray)));
  7256. } catch (e) {
  7257. throw new Error('Malformed UTF-8 data');
  7258. }
  7259. },
  7260. /**
  7261. * Converts a UTF-8 string to a word array.
  7262. *
  7263. * @param {string} utf8Str The UTF-8 string.
  7264. *
  7265. * @return {WordArray} The word array.
  7266. *
  7267. * @static
  7268. *
  7269. * @example
  7270. *
  7271. * var wordArray = CryptoJS.enc.Utf8.parse(utf8String);
  7272. */
  7273. parse: function (utf8Str) {
  7274. return Latin1.parse(unescape(encodeURIComponent(utf8Str)));
  7275. }
  7276. };
  7277. /**
  7278. * Abstract buffered block algorithm template.
  7279. *
  7280. * The property blockSize must be implemented in a concrete subtype.
  7281. *
  7282. * @property {number} _minBufferSize The number of blocks that should be kept unprocessed in the buffer. Default: 0
  7283. */
  7284. var BufferedBlockAlgorithm = C_lib.BufferedBlockAlgorithm = Base.extend({
  7285. /**
  7286. * Resets this block algorithm's data buffer to its initial state.
  7287. *
  7288. * @example
  7289. *
  7290. * bufferedBlockAlgorithm.reset();
  7291. */
  7292. reset: function () {
  7293. // Initial values
  7294. this._data = new WordArray.init();
  7295. this._nDataBytes = 0;
  7296. },
  7297. /**
  7298. * Adds new data to this block algorithm's buffer.
  7299. *
  7300. * @param {WordArray|string} data The data to append. Strings are converted to a WordArray using UTF-8.
  7301. *
  7302. * @example
  7303. *
  7304. * bufferedBlockAlgorithm._append('data');
  7305. * bufferedBlockAlgorithm._append(wordArray);
  7306. */
  7307. _append: function (data) {
  7308. // Convert string to WordArray, else assume WordArray already
  7309. if (typeof data == 'string') {
  7310. data = Utf8.parse(data);
  7311. }
  7312. // Append
  7313. this._data.concat(data);
  7314. this._nDataBytes += data.sigBytes;
  7315. },
  7316. /**
  7317. * Processes available data blocks.
  7318. *
  7319. * This method invokes _doProcessBlock(offset), which must be implemented by a concrete subtype.
  7320. *
  7321. * @param {boolean} doFlush Whether all blocks and partial blocks should be processed.
  7322. *
  7323. * @return {WordArray} The processed data.
  7324. *
  7325. * @example
  7326. *
  7327. * var processedData = bufferedBlockAlgorithm._process();
  7328. * var processedData = bufferedBlockAlgorithm._process(!!'flush');
  7329. */
  7330. _process: function (doFlush) {
  7331. // Shortcuts
  7332. var data = this._data;
  7333. var dataWords = data.words;
  7334. var dataSigBytes = data.sigBytes;
  7335. var blockSize = this.blockSize;
  7336. var blockSizeBytes = blockSize * 4;
  7337. // Count blocks ready
  7338. var nBlocksReady = dataSigBytes / blockSizeBytes;
  7339. if (doFlush) {
  7340. // Round up to include partial blocks
  7341. nBlocksReady = Math.ceil(nBlocksReady);
  7342. } else {
  7343. // Round down to include only full blocks,
  7344. // less the number of blocks that must remain in the buffer
  7345. nBlocksReady = Math.max((nBlocksReady | 0) - this._minBufferSize, 0);
  7346. }
  7347. // Count words ready
  7348. var nWordsReady = nBlocksReady * blockSize;
  7349. // Count bytes ready
  7350. var nBytesReady = Math.min(nWordsReady * 4, dataSigBytes);
  7351. // Process blocks
  7352. if (nWordsReady) {
  7353. for (var offset = 0; offset < nWordsReady; offset += blockSize) {
  7354. // Perform concrete-algorithm logic
  7355. this._doProcessBlock(dataWords, offset);
  7356. }
  7357. // Remove processed words
  7358. var processedWords = dataWords.splice(0, nWordsReady);
  7359. data.sigBytes -= nBytesReady;
  7360. }
  7361. // Return processed words
  7362. return new WordArray.init(processedWords, nBytesReady);
  7363. },
  7364. /**
  7365. * Creates a copy of this object.
  7366. *
  7367. * @return {Object} The clone.
  7368. *
  7369. * @example
  7370. *
  7371. * var clone = bufferedBlockAlgorithm.clone();
  7372. */
  7373. clone: function () {
  7374. var clone = Base.clone.call(this);
  7375. clone._data = this._data.clone();
  7376. return clone;
  7377. },
  7378. _minBufferSize: 0
  7379. });
  7380. /**
  7381. * Abstract hasher template.
  7382. *
  7383. * @property {number} blockSize The number of 32-bit words this hasher operates on. Default: 16 (512 bits)
  7384. */
  7385. var Hasher = C_lib.Hasher = BufferedBlockAlgorithm.extend({
  7386. /**
  7387. * Configuration options.
  7388. */
  7389. cfg: Base.extend(),
  7390. /**
  7391. * Initializes a newly created hasher.
  7392. *
  7393. * @param {Object} cfg (Optional) The configuration options to use for this hash computation.
  7394. *
  7395. * @example
  7396. *
  7397. * var hasher = CryptoJS.algo.SHA256.create();
  7398. */
  7399. init: function (cfg) {
  7400. // Apply config defaults
  7401. this.cfg = this.cfg.extend(cfg);
  7402. // Set initial values
  7403. this.reset();
  7404. },
  7405. /**
  7406. * Resets this hasher to its initial state.
  7407. *
  7408. * @example
  7409. *
  7410. * hasher.reset();
  7411. */
  7412. reset: function () {
  7413. // Reset data buffer
  7414. BufferedBlockAlgorithm.reset.call(this);
  7415. // Perform concrete-hasher logic
  7416. this._doReset();
  7417. },
  7418. /**
  7419. * Updates this hasher with a message.
  7420. *
  7421. * @param {WordArray|string} messageUpdate The message to append.
  7422. *
  7423. * @return {Hasher} This hasher.
  7424. *
  7425. * @example
  7426. *
  7427. * hasher.update('message');
  7428. * hasher.update(wordArray);
  7429. */
  7430. update: function (messageUpdate) {
  7431. // Append
  7432. this._append(messageUpdate);
  7433. // Update the hash
  7434. this._process();
  7435. // Chainable
  7436. return this;
  7437. },
  7438. /**
  7439. * Finalizes the hash computation.
  7440. * Note that the finalize operation is effectively a destructive, read-once operation.
  7441. *
  7442. * @param {WordArray|string} messageUpdate (Optional) A final message update.
  7443. *
  7444. * @return {WordArray} The hash.
  7445. *
  7446. * @example
  7447. *
  7448. * var hash = hasher.finalize();
  7449. * var hash = hasher.finalize('message');
  7450. * var hash = hasher.finalize(wordArray);
  7451. */
  7452. finalize: function (messageUpdate) {
  7453. // Final message update
  7454. if (messageUpdate) {
  7455. this._append(messageUpdate);
  7456. }
  7457. // Perform concrete-hasher logic
  7458. var hash = this._doFinalize();
  7459. return hash;
  7460. },
  7461. blockSize: 512/32,
  7462. /**
  7463. * Creates a shortcut function to a hasher's object interface.
  7464. *
  7465. * @param {Hasher} hasher The hasher to create a helper for.
  7466. *
  7467. * @return {Function} The shortcut function.
  7468. *
  7469. * @static
  7470. *
  7471. * @example
  7472. *
  7473. * var SHA256 = CryptoJS.lib.Hasher._createHelper(CryptoJS.algo.SHA256);
  7474. */
  7475. _createHelper: function (hasher) {
  7476. return function (message, cfg) {
  7477. return new hasher.init(cfg).finalize(message);
  7478. };
  7479. },
  7480. /**
  7481. * Creates a shortcut function to the HMAC's object interface.
  7482. *
  7483. * @param {Hasher} hasher The hasher to use in this HMAC helper.
  7484. *
  7485. * @return {Function} The shortcut function.
  7486. *
  7487. * @static
  7488. *
  7489. * @example
  7490. *
  7491. * var HmacSHA256 = CryptoJS.lib.Hasher._createHmacHelper(CryptoJS.algo.SHA256);
  7492. */
  7493. _createHmacHelper: function (hasher) {
  7494. return function (message, key) {
  7495. return new C_algo.HMAC.init(hasher, key).finalize(message);
  7496. };
  7497. }
  7498. });
  7499. /**
  7500. * Algorithm namespace.
  7501. */
  7502. var C_algo = C.algo = {};
  7503. return C;
  7504. }(Math));
  7505. return CryptoJS;
  7506. }));
  7507. },{}],54:[function(require,module,exports){
  7508. ;(function (root, factory) {
  7509. if (typeof exports === "object") {
  7510. // CommonJS
  7511. module.exports = exports = factory(require("./core"));
  7512. }
  7513. else if (typeof define === "function" && define.amd) {
  7514. // AMD
  7515. define(["./core"], factory);
  7516. }
  7517. else {
  7518. // Global (browser)
  7519. factory(root.CryptoJS);
  7520. }
  7521. }(this, function (CryptoJS) {
  7522. (function () {
  7523. // Shortcuts
  7524. var C = CryptoJS;
  7525. var C_lib = C.lib;
  7526. var WordArray = C_lib.WordArray;
  7527. var C_enc = C.enc;
  7528. /**
  7529. * Base64 encoding strategy.
  7530. */
  7531. var Base64 = C_enc.Base64 = {
  7532. /**
  7533. * Converts a word array to a Base64 string.
  7534. *
  7535. * @param {WordArray} wordArray The word array.
  7536. *
  7537. * @return {string} The Base64 string.
  7538. *
  7539. * @static
  7540. *
  7541. * @example
  7542. *
  7543. * var base64String = CryptoJS.enc.Base64.stringify(wordArray);
  7544. */
  7545. stringify: function (wordArray) {
  7546. // Shortcuts
  7547. var words = wordArray.words;
  7548. var sigBytes = wordArray.sigBytes;
  7549. var map = this._map;
  7550. // Clamp excess bits
  7551. wordArray.clamp();
  7552. // Convert
  7553. var base64Chars = [];
  7554. for (var i = 0; i < sigBytes; i += 3) {
  7555. var byte1 = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff;
  7556. var byte2 = (words[(i + 1) >>> 2] >>> (24 - ((i + 1) % 4) * 8)) & 0xff;
  7557. var byte3 = (words[(i + 2) >>> 2] >>> (24 - ((i + 2) % 4) * 8)) & 0xff;
  7558. var triplet = (byte1 << 16) | (byte2 << 8) | byte3;
  7559. for (var j = 0; (j < 4) && (i + j * 0.75 < sigBytes); j++) {
  7560. base64Chars.push(map.charAt((triplet >>> (6 * (3 - j))) & 0x3f));
  7561. }
  7562. }
  7563. // Add padding
  7564. var paddingChar = map.charAt(64);
  7565. if (paddingChar) {
  7566. while (base64Chars.length % 4) {
  7567. base64Chars.push(paddingChar);
  7568. }
  7569. }
  7570. return base64Chars.join('');
  7571. },
  7572. /**
  7573. * Converts a Base64 string to a word array.
  7574. *
  7575. * @param {string} base64Str The Base64 string.
  7576. *
  7577. * @return {WordArray} The word array.
  7578. *
  7579. * @static
  7580. *
  7581. * @example
  7582. *
  7583. * var wordArray = CryptoJS.enc.Base64.parse(base64String);
  7584. */
  7585. parse: function (base64Str) {
  7586. // Shortcuts
  7587. var base64StrLength = base64Str.length;
  7588. var map = this._map;
  7589. var reverseMap = this._reverseMap;
  7590. if (!reverseMap) {
  7591. reverseMap = this._reverseMap = [];
  7592. for (var j = 0; j < map.length; j++) {
  7593. reverseMap[map.charCodeAt(j)] = j;
  7594. }
  7595. }
  7596. // Ignore padding
  7597. var paddingChar = map.charAt(64);
  7598. if (paddingChar) {
  7599. var paddingIndex = base64Str.indexOf(paddingChar);
  7600. if (paddingIndex !== -1) {
  7601. base64StrLength = paddingIndex;
  7602. }
  7603. }
  7604. // Convert
  7605. return parseLoop(base64Str, base64StrLength, reverseMap);
  7606. },
  7607. _map: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='
  7608. };
  7609. function parseLoop(base64Str, base64StrLength, reverseMap) {
  7610. var words = [];
  7611. var nBytes = 0;
  7612. for (var i = 0; i < base64StrLength; i++) {
  7613. if (i % 4) {
  7614. var bits1 = reverseMap[base64Str.charCodeAt(i - 1)] << ((i % 4) * 2);
  7615. var bits2 = reverseMap[base64Str.charCodeAt(i)] >>> (6 - (i % 4) * 2);
  7616. words[nBytes >>> 2] |= (bits1 | bits2) << (24 - (nBytes % 4) * 8);
  7617. nBytes++;
  7618. }
  7619. }
  7620. return WordArray.create(words, nBytes);
  7621. }
  7622. }());
  7623. return CryptoJS.enc.Base64;
  7624. }));
  7625. },{"./core":53}],55:[function(require,module,exports){
  7626. ;(function (root, factory) {
  7627. if (typeof exports === "object") {
  7628. // CommonJS
  7629. module.exports = exports = factory(require("./core"));
  7630. }
  7631. else if (typeof define === "function" && define.amd) {
  7632. // AMD
  7633. define(["./core"], factory);
  7634. }
  7635. else {
  7636. // Global (browser)
  7637. factory(root.CryptoJS);
  7638. }
  7639. }(this, function (CryptoJS) {
  7640. (function () {
  7641. // Shortcuts
  7642. var C = CryptoJS;
  7643. var C_lib = C.lib;
  7644. var WordArray = C_lib.WordArray;
  7645. var C_enc = C.enc;
  7646. /**
  7647. * UTF-16 BE encoding strategy.
  7648. */
  7649. var Utf16BE = C_enc.Utf16 = C_enc.Utf16BE = {
  7650. /**
  7651. * Converts a word array to a UTF-16 BE string.
  7652. *
  7653. * @param {WordArray} wordArray The word array.
  7654. *
  7655. * @return {string} The UTF-16 BE string.
  7656. *
  7657. * @static
  7658. *
  7659. * @example
  7660. *
  7661. * var utf16String = CryptoJS.enc.Utf16.stringify(wordArray);
  7662. */
  7663. stringify: function (wordArray) {
  7664. // Shortcuts
  7665. var words = wordArray.words;
  7666. var sigBytes = wordArray.sigBytes;
  7667. // Convert
  7668. var utf16Chars = [];
  7669. for (var i = 0; i < sigBytes; i += 2) {
  7670. var codePoint = (words[i >>> 2] >>> (16 - (i % 4) * 8)) & 0xffff;
  7671. utf16Chars.push(String.fromCharCode(codePoint));
  7672. }
  7673. return utf16Chars.join('');
  7674. },
  7675. /**
  7676. * Converts a UTF-16 BE string to a word array.
  7677. *
  7678. * @param {string} utf16Str The UTF-16 BE string.
  7679. *
  7680. * @return {WordArray} The word array.
  7681. *
  7682. * @static
  7683. *
  7684. * @example
  7685. *
  7686. * var wordArray = CryptoJS.enc.Utf16.parse(utf16String);
  7687. */
  7688. parse: function (utf16Str) {
  7689. // Shortcut
  7690. var utf16StrLength = utf16Str.length;
  7691. // Convert
  7692. var words = [];
  7693. for (var i = 0; i < utf16StrLength; i++) {
  7694. words[i >>> 1] |= utf16Str.charCodeAt(i) << (16 - (i % 2) * 16);
  7695. }
  7696. return WordArray.create(words, utf16StrLength * 2);
  7697. }
  7698. };
  7699. /**
  7700. * UTF-16 LE encoding strategy.
  7701. */
  7702. C_enc.Utf16LE = {
  7703. /**
  7704. * Converts a word array to a UTF-16 LE string.
  7705. *
  7706. * @param {WordArray} wordArray The word array.
  7707. *
  7708. * @return {string} The UTF-16 LE string.
  7709. *
  7710. * @static
  7711. *
  7712. * @example
  7713. *
  7714. * var utf16Str = CryptoJS.enc.Utf16LE.stringify(wordArray);
  7715. */
  7716. stringify: function (wordArray) {
  7717. // Shortcuts
  7718. var words = wordArray.words;
  7719. var sigBytes = wordArray.sigBytes;
  7720. // Convert
  7721. var utf16Chars = [];
  7722. for (var i = 0; i < sigBytes; i += 2) {
  7723. var codePoint = swapEndian((words[i >>> 2] >>> (16 - (i % 4) * 8)) & 0xffff);
  7724. utf16Chars.push(String.fromCharCode(codePoint));
  7725. }
  7726. return utf16Chars.join('');
  7727. },
  7728. /**
  7729. * Converts a UTF-16 LE string to a word array.
  7730. *
  7731. * @param {string} utf16Str The UTF-16 LE string.
  7732. *
  7733. * @return {WordArray} The word array.
  7734. *
  7735. * @static
  7736. *
  7737. * @example
  7738. *
  7739. * var wordArray = CryptoJS.enc.Utf16LE.parse(utf16Str);
  7740. */
  7741. parse: function (utf16Str) {
  7742. // Shortcut
  7743. var utf16StrLength = utf16Str.length;
  7744. // Convert
  7745. var words = [];
  7746. for (var i = 0; i < utf16StrLength; i++) {
  7747. words[i >>> 1] |= swapEndian(utf16Str.charCodeAt(i) << (16 - (i % 2) * 16));
  7748. }
  7749. return WordArray.create(words, utf16StrLength * 2);
  7750. }
  7751. };
  7752. function swapEndian(word) {
  7753. return ((word << 8) & 0xff00ff00) | ((word >>> 8) & 0x00ff00ff);
  7754. }
  7755. }());
  7756. return CryptoJS.enc.Utf16;
  7757. }));
  7758. },{"./core":53}],56:[function(require,module,exports){
  7759. ;(function (root, factory, undef) {
  7760. if (typeof exports === "object") {
  7761. // CommonJS
  7762. module.exports = exports = factory(require("./core"), require("./sha1"), require("./hmac"));
  7763. }
  7764. else if (typeof define === "function" && define.amd) {
  7765. // AMD
  7766. define(["./core", "./sha1", "./hmac"], factory);
  7767. }
  7768. else {
  7769. // Global (browser)
  7770. factory(root.CryptoJS);
  7771. }
  7772. }(this, function (CryptoJS) {
  7773. (function () {
  7774. // Shortcuts
  7775. var C = CryptoJS;
  7776. var C_lib = C.lib;
  7777. var Base = C_lib.Base;
  7778. var WordArray = C_lib.WordArray;
  7779. var C_algo = C.algo;
  7780. var MD5 = C_algo.MD5;
  7781. /**
  7782. * This key derivation function is meant to conform with EVP_BytesToKey.
  7783. * www.openssl.org/docs/crypto/EVP_BytesToKey.html
  7784. */
  7785. var EvpKDF = C_algo.EvpKDF = Base.extend({
  7786. /**
  7787. * Configuration options.
  7788. *
  7789. * @property {number} keySize The key size in words to generate. Default: 4 (128 bits)
  7790. * @property {Hasher} hasher The hash algorithm to use. Default: MD5
  7791. * @property {number} iterations The number of iterations to perform. Default: 1
  7792. */
  7793. cfg: Base.extend({
  7794. keySize: 128/32,
  7795. hasher: MD5,
  7796. iterations: 1
  7797. }),
  7798. /**
  7799. * Initializes a newly created key derivation function.
  7800. *
  7801. * @param {Object} cfg (Optional) The configuration options to use for the derivation.
  7802. *
  7803. * @example
  7804. *
  7805. * var kdf = CryptoJS.algo.EvpKDF.create();
  7806. * var kdf = CryptoJS.algo.EvpKDF.create({ keySize: 8 });
  7807. * var kdf = CryptoJS.algo.EvpKDF.create({ keySize: 8, iterations: 1000 });
  7808. */
  7809. init: function (cfg) {
  7810. this.cfg = this.cfg.extend(cfg);
  7811. },
  7812. /**
  7813. * Derives a key from a password.
  7814. *
  7815. * @param {WordArray|string} password The password.
  7816. * @param {WordArray|string} salt A salt.
  7817. *
  7818. * @return {WordArray} The derived key.
  7819. *
  7820. * @example
  7821. *
  7822. * var key = kdf.compute(password, salt);
  7823. */
  7824. compute: function (password, salt) {
  7825. // Shortcut
  7826. var cfg = this.cfg;
  7827. // Init hasher
  7828. var hasher = cfg.hasher.create();
  7829. // Initial values
  7830. var derivedKey = WordArray.create();
  7831. // Shortcuts
  7832. var derivedKeyWords = derivedKey.words;
  7833. var keySize = cfg.keySize;
  7834. var iterations = cfg.iterations;
  7835. // Generate key
  7836. while (derivedKeyWords.length < keySize) {
  7837. if (block) {
  7838. hasher.update(block);
  7839. }
  7840. var block = hasher.update(password).finalize(salt);
  7841. hasher.reset();
  7842. // Iterations
  7843. for (var i = 1; i < iterations; i++) {
  7844. block = hasher.finalize(block);
  7845. hasher.reset();
  7846. }
  7847. derivedKey.concat(block);
  7848. }
  7849. derivedKey.sigBytes = keySize * 4;
  7850. return derivedKey;
  7851. }
  7852. });
  7853. /**
  7854. * Derives a key from a password.
  7855. *
  7856. * @param {WordArray|string} password The password.
  7857. * @param {WordArray|string} salt A salt.
  7858. * @param {Object} cfg (Optional) The configuration options to use for this computation.
  7859. *
  7860. * @return {WordArray} The derived key.
  7861. *
  7862. * @static
  7863. *
  7864. * @example
  7865. *
  7866. * var key = CryptoJS.EvpKDF(password, salt);
  7867. * var key = CryptoJS.EvpKDF(password, salt, { keySize: 8 });
  7868. * var key = CryptoJS.EvpKDF(password, salt, { keySize: 8, iterations: 1000 });
  7869. */
  7870. C.EvpKDF = function (password, salt, cfg) {
  7871. return EvpKDF.create(cfg).compute(password, salt);
  7872. };
  7873. }());
  7874. return CryptoJS.EvpKDF;
  7875. }));
  7876. },{"./core":53,"./hmac":58,"./sha1":77}],57:[function(require,module,exports){
  7877. ;(function (root, factory, undef) {
  7878. if (typeof exports === "object") {
  7879. // CommonJS
  7880. module.exports = exports = factory(require("./core"), require("./cipher-core"));
  7881. }
  7882. else if (typeof define === "function" && define.amd) {
  7883. // AMD
  7884. define(["./core", "./cipher-core"], factory);
  7885. }
  7886. else {
  7887. // Global (browser)
  7888. factory(root.CryptoJS);
  7889. }
  7890. }(this, function (CryptoJS) {
  7891. (function (undefined) {
  7892. // Shortcuts
  7893. var C = CryptoJS;
  7894. var C_lib = C.lib;
  7895. var CipherParams = C_lib.CipherParams;
  7896. var C_enc = C.enc;
  7897. var Hex = C_enc.Hex;
  7898. var C_format = C.format;
  7899. var HexFormatter = C_format.Hex = {
  7900. /**
  7901. * Converts the ciphertext of a cipher params object to a hexadecimally encoded string.
  7902. *
  7903. * @param {CipherParams} cipherParams The cipher params object.
  7904. *
  7905. * @return {string} The hexadecimally encoded string.
  7906. *
  7907. * @static
  7908. *
  7909. * @example
  7910. *
  7911. * var hexString = CryptoJS.format.Hex.stringify(cipherParams);
  7912. */
  7913. stringify: function (cipherParams) {
  7914. return cipherParams.ciphertext.toString(Hex);
  7915. },
  7916. /**
  7917. * Converts a hexadecimally encoded ciphertext string to a cipher params object.
  7918. *
  7919. * @param {string} input The hexadecimally encoded string.
  7920. *
  7921. * @return {CipherParams} The cipher params object.
  7922. *
  7923. * @static
  7924. *
  7925. * @example
  7926. *
  7927. * var cipherParams = CryptoJS.format.Hex.parse(hexString);
  7928. */
  7929. parse: function (input) {
  7930. var ciphertext = Hex.parse(input);
  7931. return CipherParams.create({ ciphertext: ciphertext });
  7932. }
  7933. };
  7934. }());
  7935. return CryptoJS.format.Hex;
  7936. }));
  7937. },{"./cipher-core":52,"./core":53}],58:[function(require,module,exports){
  7938. ;(function (root, factory) {
  7939. if (typeof exports === "object") {
  7940. // CommonJS
  7941. module.exports = exports = factory(require("./core"));
  7942. }
  7943. else if (typeof define === "function" && define.amd) {
  7944. // AMD
  7945. define(["./core"], factory);
  7946. }
  7947. else {
  7948. // Global (browser)
  7949. factory(root.CryptoJS);
  7950. }
  7951. }(this, function (CryptoJS) {
  7952. (function () {
  7953. // Shortcuts
  7954. var C = CryptoJS;
  7955. var C_lib = C.lib;
  7956. var Base = C_lib.Base;
  7957. var C_enc = C.enc;
  7958. var Utf8 = C_enc.Utf8;
  7959. var C_algo = C.algo;
  7960. /**
  7961. * HMAC algorithm.
  7962. */
  7963. var HMAC = C_algo.HMAC = Base.extend({
  7964. /**
  7965. * Initializes a newly created HMAC.
  7966. *
  7967. * @param {Hasher} hasher The hash algorithm to use.
  7968. * @param {WordArray|string} key The secret key.
  7969. *
  7970. * @example
  7971. *
  7972. * var hmacHasher = CryptoJS.algo.HMAC.create(CryptoJS.algo.SHA256, key);
  7973. */
  7974. init: function (hasher, key) {
  7975. // Init hasher
  7976. hasher = this._hasher = new hasher.init();
  7977. // Convert string to WordArray, else assume WordArray already
  7978. if (typeof key == 'string') {
  7979. key = Utf8.parse(key);
  7980. }
  7981. // Shortcuts
  7982. var hasherBlockSize = hasher.blockSize;
  7983. var hasherBlockSizeBytes = hasherBlockSize * 4;
  7984. // Allow arbitrary length keys
  7985. if (key.sigBytes > hasherBlockSizeBytes) {
  7986. key = hasher.finalize(key);
  7987. }
  7988. // Clamp excess bits
  7989. key.clamp();
  7990. // Clone key for inner and outer pads
  7991. var oKey = this._oKey = key.clone();
  7992. var iKey = this._iKey = key.clone();
  7993. // Shortcuts
  7994. var oKeyWords = oKey.words;
  7995. var iKeyWords = iKey.words;
  7996. // XOR keys with pad constants
  7997. for (var i = 0; i < hasherBlockSize; i++) {
  7998. oKeyWords[i] ^= 0x5c5c5c5c;
  7999. iKeyWords[i] ^= 0x36363636;
  8000. }
  8001. oKey.sigBytes = iKey.sigBytes = hasherBlockSizeBytes;
  8002. // Set initial values
  8003. this.reset();
  8004. },
  8005. /**
  8006. * Resets this HMAC to its initial state.
  8007. *
  8008. * @example
  8009. *
  8010. * hmacHasher.reset();
  8011. */
  8012. reset: function () {
  8013. // Shortcut
  8014. var hasher = this._hasher;
  8015. // Reset
  8016. hasher.reset();
  8017. hasher.update(this._iKey);
  8018. },
  8019. /**
  8020. * Updates this HMAC with a message.
  8021. *
  8022. * @param {WordArray|string} messageUpdate The message to append.
  8023. *
  8024. * @return {HMAC} This HMAC instance.
  8025. *
  8026. * @example
  8027. *
  8028. * hmacHasher.update('message');
  8029. * hmacHasher.update(wordArray);
  8030. */
  8031. update: function (messageUpdate) {
  8032. this._hasher.update(messageUpdate);
  8033. // Chainable
  8034. return this;
  8035. },
  8036. /**
  8037. * Finalizes the HMAC computation.
  8038. * Note that the finalize operation is effectively a destructive, read-once operation.
  8039. *
  8040. * @param {WordArray|string} messageUpdate (Optional) A final message update.
  8041. *
  8042. * @return {WordArray} The HMAC.
  8043. *
  8044. * @example
  8045. *
  8046. * var hmac = hmacHasher.finalize();
  8047. * var hmac = hmacHasher.finalize('message');
  8048. * var hmac = hmacHasher.finalize(wordArray);
  8049. */
  8050. finalize: function (messageUpdate) {
  8051. // Shortcut
  8052. var hasher = this._hasher;
  8053. // Compute HMAC
  8054. var innerHash = hasher.finalize(messageUpdate);
  8055. hasher.reset();
  8056. var hmac = hasher.finalize(this._oKey.clone().concat(innerHash));
  8057. return hmac;
  8058. }
  8059. });
  8060. }());
  8061. }));
  8062. },{"./core":53}],59:[function(require,module,exports){
  8063. ;(function (root, factory, undef) {
  8064. if (typeof exports === "object") {
  8065. // CommonJS
  8066. module.exports = exports = factory(require("./core"), require("./x64-core"), require("./lib-typedarrays"), require("./enc-utf16"), require("./enc-base64"), require("./md5"), require("./sha1"), require("./sha256"), require("./sha224"), require("./sha512"), require("./sha384"), require("./sha3"), require("./ripemd160"), require("./hmac"), require("./pbkdf2"), require("./evpkdf"), require("./cipher-core"), require("./mode-cfb"), require("./mode-ctr"), require("./mode-ctr-gladman"), require("./mode-ofb"), require("./mode-ecb"), require("./pad-ansix923"), require("./pad-iso10126"), require("./pad-iso97971"), require("./pad-zeropadding"), require("./pad-nopadding"), require("./format-hex"), require("./aes"), require("./tripledes"), require("./rc4"), require("./rabbit"), require("./rabbit-legacy"));
  8067. }
  8068. else if (typeof define === "function" && define.amd) {
  8069. // AMD
  8070. define(["./core", "./x64-core", "./lib-typedarrays", "./enc-utf16", "./enc-base64", "./md5", "./sha1", "./sha256", "./sha224", "./sha512", "./sha384", "./sha3", "./ripemd160", "./hmac", "./pbkdf2", "./evpkdf", "./cipher-core", "./mode-cfb", "./mode-ctr", "./mode-ctr-gladman", "./mode-ofb", "./mode-ecb", "./pad-ansix923", "./pad-iso10126", "./pad-iso97971", "./pad-zeropadding", "./pad-nopadding", "./format-hex", "./aes", "./tripledes", "./rc4", "./rabbit", "./rabbit-legacy"], factory);
  8071. }
  8072. else {
  8073. // Global (browser)
  8074. root.CryptoJS = factory(root.CryptoJS);
  8075. }
  8076. }(this, function (CryptoJS) {
  8077. return CryptoJS;
  8078. }));
  8079. },{"./aes":51,"./cipher-core":52,"./core":53,"./enc-base64":54,"./enc-utf16":55,"./evpkdf":56,"./format-hex":57,"./hmac":58,"./lib-typedarrays":60,"./md5":61,"./mode-cfb":62,"./mode-ctr":64,"./mode-ctr-gladman":63,"./mode-ecb":65,"./mode-ofb":66,"./pad-ansix923":67,"./pad-iso10126":68,"./pad-iso97971":69,"./pad-nopadding":70,"./pad-zeropadding":71,"./pbkdf2":72,"./rabbit":74,"./rabbit-legacy":73,"./rc4":75,"./ripemd160":76,"./sha1":77,"./sha224":78,"./sha256":79,"./sha3":80,"./sha384":81,"./sha512":82,"./tripledes":83,"./x64-core":84}],60:[function(require,module,exports){
  8080. ;(function (root, factory) {
  8081. if (typeof exports === "object") {
  8082. // CommonJS
  8083. module.exports = exports = factory(require("./core"));
  8084. }
  8085. else if (typeof define === "function" && define.amd) {
  8086. // AMD
  8087. define(["./core"], factory);
  8088. }
  8089. else {
  8090. // Global (browser)
  8091. factory(root.CryptoJS);
  8092. }
  8093. }(this, function (CryptoJS) {
  8094. (function () {
  8095. // Check if typed arrays are supported
  8096. if (typeof ArrayBuffer != 'function') {
  8097. return;
  8098. }
  8099. // Shortcuts
  8100. var C = CryptoJS;
  8101. var C_lib = C.lib;
  8102. var WordArray = C_lib.WordArray;
  8103. // Reference original init
  8104. var superInit = WordArray.init;
  8105. // Augment WordArray.init to handle typed arrays
  8106. var subInit = WordArray.init = function (typedArray) {
  8107. // Convert buffers to uint8
  8108. if (typedArray instanceof ArrayBuffer) {
  8109. typedArray = new Uint8Array(typedArray);
  8110. }
  8111. // Convert other array views to uint8
  8112. if (
  8113. typedArray instanceof Int8Array ||
  8114. (typeof Uint8ClampedArray !== "undefined" && typedArray instanceof Uint8ClampedArray) ||
  8115. typedArray instanceof Int16Array ||
  8116. typedArray instanceof Uint16Array ||
  8117. typedArray instanceof Int32Array ||
  8118. typedArray instanceof Uint32Array ||
  8119. typedArray instanceof Float32Array ||
  8120. typedArray instanceof Float64Array
  8121. ) {
  8122. typedArray = new Uint8Array(typedArray.buffer, typedArray.byteOffset, typedArray.byteLength);
  8123. }
  8124. // Handle Uint8Array
  8125. if (typedArray instanceof Uint8Array) {
  8126. // Shortcut
  8127. var typedArrayByteLength = typedArray.byteLength;
  8128. // Extract bytes
  8129. var words = [];
  8130. for (var i = 0; i < typedArrayByteLength; i++) {
  8131. words[i >>> 2] |= typedArray[i] << (24 - (i % 4) * 8);
  8132. }
  8133. // Initialize this word array
  8134. superInit.call(this, words, typedArrayByteLength);
  8135. } else {
  8136. // Else call normal init
  8137. superInit.apply(this, arguments);
  8138. }
  8139. };
  8140. subInit.prototype = WordArray;
  8141. }());
  8142. return CryptoJS.lib.WordArray;
  8143. }));
  8144. },{"./core":53}],61:[function(require,module,exports){
  8145. ;(function (root, factory) {
  8146. if (typeof exports === "object") {
  8147. // CommonJS
  8148. module.exports = exports = factory(require("./core"));
  8149. }
  8150. else if (typeof define === "function" && define.amd) {
  8151. // AMD
  8152. define(["./core"], factory);
  8153. }
  8154. else {
  8155. // Global (browser)
  8156. factory(root.CryptoJS);
  8157. }
  8158. }(this, function (CryptoJS) {
  8159. (function (Math) {
  8160. // Shortcuts
  8161. var C = CryptoJS;
  8162. var C_lib = C.lib;
  8163. var WordArray = C_lib.WordArray;
  8164. var Hasher = C_lib.Hasher;
  8165. var C_algo = C.algo;
  8166. // Constants table
  8167. var T = [];
  8168. // Compute constants
  8169. (function () {
  8170. for (var i = 0; i < 64; i++) {
  8171. T[i] = (Math.abs(Math.sin(i + 1)) * 0x100000000) | 0;
  8172. }
  8173. }());
  8174. /**
  8175. * MD5 hash algorithm.
  8176. */
  8177. var MD5 = C_algo.MD5 = Hasher.extend({
  8178. _doReset: function () {
  8179. this._hash = new WordArray.init([
  8180. 0x67452301, 0xefcdab89,
  8181. 0x98badcfe, 0x10325476
  8182. ]);
  8183. },
  8184. _doProcessBlock: function (M, offset) {
  8185. // Swap endian
  8186. for (var i = 0; i < 16; i++) {
  8187. // Shortcuts
  8188. var offset_i = offset + i;
  8189. var M_offset_i = M[offset_i];
  8190. M[offset_i] = (
  8191. (((M_offset_i << 8) | (M_offset_i >>> 24)) & 0x00ff00ff) |
  8192. (((M_offset_i << 24) | (M_offset_i >>> 8)) & 0xff00ff00)
  8193. );
  8194. }
  8195. // Shortcuts
  8196. var H = this._hash.words;
  8197. var M_offset_0 = M[offset + 0];
  8198. var M_offset_1 = M[offset + 1];
  8199. var M_offset_2 = M[offset + 2];
  8200. var M_offset_3 = M[offset + 3];
  8201. var M_offset_4 = M[offset + 4];
  8202. var M_offset_5 = M[offset + 5];
  8203. var M_offset_6 = M[offset + 6];
  8204. var M_offset_7 = M[offset + 7];
  8205. var M_offset_8 = M[offset + 8];
  8206. var M_offset_9 = M[offset + 9];
  8207. var M_offset_10 = M[offset + 10];
  8208. var M_offset_11 = M[offset + 11];
  8209. var M_offset_12 = M[offset + 12];
  8210. var M_offset_13 = M[offset + 13];
  8211. var M_offset_14 = M[offset + 14];
  8212. var M_offset_15 = M[offset + 15];
  8213. // Working varialbes
  8214. var a = H[0];
  8215. var b = H[1];
  8216. var c = H[2];
  8217. var d = H[3];
  8218. // Computation
  8219. a = FF(a, b, c, d, M_offset_0, 7, T[0]);
  8220. d = FF(d, a, b, c, M_offset_1, 12, T[1]);
  8221. c = FF(c, d, a, b, M_offset_2, 17, T[2]);
  8222. b = FF(b, c, d, a, M_offset_3, 22, T[3]);
  8223. a = FF(a, b, c, d, M_offset_4, 7, T[4]);
  8224. d = FF(d, a, b, c, M_offset_5, 12, T[5]);
  8225. c = FF(c, d, a, b, M_offset_6, 17, T[6]);
  8226. b = FF(b, c, d, a, M_offset_7, 22, T[7]);
  8227. a = FF(a, b, c, d, M_offset_8, 7, T[8]);
  8228. d = FF(d, a, b, c, M_offset_9, 12, T[9]);
  8229. c = FF(c, d, a, b, M_offset_10, 17, T[10]);
  8230. b = FF(b, c, d, a, M_offset_11, 22, T[11]);
  8231. a = FF(a, b, c, d, M_offset_12, 7, T[12]);
  8232. d = FF(d, a, b, c, M_offset_13, 12, T[13]);
  8233. c = FF(c, d, a, b, M_offset_14, 17, T[14]);
  8234. b = FF(b, c, d, a, M_offset_15, 22, T[15]);
  8235. a = GG(a, b, c, d, M_offset_1, 5, T[16]);
  8236. d = GG(d, a, b, c, M_offset_6, 9, T[17]);
  8237. c = GG(c, d, a, b, M_offset_11, 14, T[18]);
  8238. b = GG(b, c, d, a, M_offset_0, 20, T[19]);
  8239. a = GG(a, b, c, d, M_offset_5, 5, T[20]);
  8240. d = GG(d, a, b, c, M_offset_10, 9, T[21]);
  8241. c = GG(c, d, a, b, M_offset_15, 14, T[22]);
  8242. b = GG(b, c, d, a, M_offset_4, 20, T[23]);
  8243. a = GG(a, b, c, d, M_offset_9, 5, T[24]);
  8244. d = GG(d, a, b, c, M_offset_14, 9, T[25]);
  8245. c = GG(c, d, a, b, M_offset_3, 14, T[26]);
  8246. b = GG(b, c, d, a, M_offset_8, 20, T[27]);
  8247. a = GG(a, b, c, d, M_offset_13, 5, T[28]);
  8248. d = GG(d, a, b, c, M_offset_2, 9, T[29]);
  8249. c = GG(c, d, a, b, M_offset_7, 14, T[30]);
  8250. b = GG(b, c, d, a, M_offset_12, 20, T[31]);
  8251. a = HH(a, b, c, d, M_offset_5, 4, T[32]);
  8252. d = HH(d, a, b, c, M_offset_8, 11, T[33]);
  8253. c = HH(c, d, a, b, M_offset_11, 16, T[34]);
  8254. b = HH(b, c, d, a, M_offset_14, 23, T[35]);
  8255. a = HH(a, b, c, d, M_offset_1, 4, T[36]);
  8256. d = HH(d, a, b, c, M_offset_4, 11, T[37]);
  8257. c = HH(c, d, a, b, M_offset_7, 16, T[38]);
  8258. b = HH(b, c, d, a, M_offset_10, 23, T[39]);
  8259. a = HH(a, b, c, d, M_offset_13, 4, T[40]);
  8260. d = HH(d, a, b, c, M_offset_0, 11, T[41]);
  8261. c = HH(c, d, a, b, M_offset_3, 16, T[42]);
  8262. b = HH(b, c, d, a, M_offset_6, 23, T[43]);
  8263. a = HH(a, b, c, d, M_offset_9, 4, T[44]);
  8264. d = HH(d, a, b, c, M_offset_12, 11, T[45]);
  8265. c = HH(c, d, a, b, M_offset_15, 16, T[46]);
  8266. b = HH(b, c, d, a, M_offset_2, 23, T[47]);
  8267. a = II(a, b, c, d, M_offset_0, 6, T[48]);
  8268. d = II(d, a, b, c, M_offset_7, 10, T[49]);
  8269. c = II(c, d, a, b, M_offset_14, 15, T[50]);
  8270. b = II(b, c, d, a, M_offset_5, 21, T[51]);
  8271. a = II(a, b, c, d, M_offset_12, 6, T[52]);
  8272. d = II(d, a, b, c, M_offset_3, 10, T[53]);
  8273. c = II(c, d, a, b, M_offset_10, 15, T[54]);
  8274. b = II(b, c, d, a, M_offset_1, 21, T[55]);
  8275. a = II(a, b, c, d, M_offset_8, 6, T[56]);
  8276. d = II(d, a, b, c, M_offset_15, 10, T[57]);
  8277. c = II(c, d, a, b, M_offset_6, 15, T[58]);
  8278. b = II(b, c, d, a, M_offset_13, 21, T[59]);
  8279. a = II(a, b, c, d, M_offset_4, 6, T[60]);
  8280. d = II(d, a, b, c, M_offset_11, 10, T[61]);
  8281. c = II(c, d, a, b, M_offset_2, 15, T[62]);
  8282. b = II(b, c, d, a, M_offset_9, 21, T[63]);
  8283. // Intermediate hash value
  8284. H[0] = (H[0] + a) | 0;
  8285. H[1] = (H[1] + b) | 0;
  8286. H[2] = (H[2] + c) | 0;
  8287. H[3] = (H[3] + d) | 0;
  8288. },
  8289. _doFinalize: function () {
  8290. // Shortcuts
  8291. var data = this._data;
  8292. var dataWords = data.words;
  8293. var nBitsTotal = this._nDataBytes * 8;
  8294. var nBitsLeft = data.sigBytes * 8;
  8295. // Add padding
  8296. dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32);
  8297. var nBitsTotalH = Math.floor(nBitsTotal / 0x100000000);
  8298. var nBitsTotalL = nBitsTotal;
  8299. dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = (
  8300. (((nBitsTotalH << 8) | (nBitsTotalH >>> 24)) & 0x00ff00ff) |
  8301. (((nBitsTotalH << 24) | (nBitsTotalH >>> 8)) & 0xff00ff00)
  8302. );
  8303. dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = (
  8304. (((nBitsTotalL << 8) | (nBitsTotalL >>> 24)) & 0x00ff00ff) |
  8305. (((nBitsTotalL << 24) | (nBitsTotalL >>> 8)) & 0xff00ff00)
  8306. );
  8307. data.sigBytes = (dataWords.length + 1) * 4;
  8308. // Hash final blocks
  8309. this._process();
  8310. // Shortcuts
  8311. var hash = this._hash;
  8312. var H = hash.words;
  8313. // Swap endian
  8314. for (var i = 0; i < 4; i++) {
  8315. // Shortcut
  8316. var H_i = H[i];
  8317. H[i] = (((H_i << 8) | (H_i >>> 24)) & 0x00ff00ff) |
  8318. (((H_i << 24) | (H_i >>> 8)) & 0xff00ff00);
  8319. }
  8320. // Return final computed hash
  8321. return hash;
  8322. },
  8323. clone: function () {
  8324. var clone = Hasher.clone.call(this);
  8325. clone._hash = this._hash.clone();
  8326. return clone;
  8327. }
  8328. });
  8329. function FF(a, b, c, d, x, s, t) {
  8330. var n = a + ((b & c) | (~b & d)) + x + t;
  8331. return ((n << s) | (n >>> (32 - s))) + b;
  8332. }
  8333. function GG(a, b, c, d, x, s, t) {
  8334. var n = a + ((b & d) | (c & ~d)) + x + t;
  8335. return ((n << s) | (n >>> (32 - s))) + b;
  8336. }
  8337. function HH(a, b, c, d, x, s, t) {
  8338. var n = a + (b ^ c ^ d) + x + t;
  8339. return ((n << s) | (n >>> (32 - s))) + b;
  8340. }
  8341. function II(a, b, c, d, x, s, t) {
  8342. var n = a + (c ^ (b | ~d)) + x + t;
  8343. return ((n << s) | (n >>> (32 - s))) + b;
  8344. }
  8345. /**
  8346. * Shortcut function to the hasher's object interface.
  8347. *
  8348. * @param {WordArray|string} message The message to hash.
  8349. *
  8350. * @return {WordArray} The hash.
  8351. *
  8352. * @static
  8353. *
  8354. * @example
  8355. *
  8356. * var hash = CryptoJS.MD5('message');
  8357. * var hash = CryptoJS.MD5(wordArray);
  8358. */
  8359. C.MD5 = Hasher._createHelper(MD5);
  8360. /**
  8361. * Shortcut function to the HMAC's object interface.
  8362. *
  8363. * @param {WordArray|string} message The message to hash.
  8364. * @param {WordArray|string} key The secret key.
  8365. *
  8366. * @return {WordArray} The HMAC.
  8367. *
  8368. * @static
  8369. *
  8370. * @example
  8371. *
  8372. * var hmac = CryptoJS.HmacMD5(message, key);
  8373. */
  8374. C.HmacMD5 = Hasher._createHmacHelper(MD5);
  8375. }(Math));
  8376. return CryptoJS.MD5;
  8377. }));
  8378. },{"./core":53}],62:[function(require,module,exports){
  8379. ;(function (root, factory, undef) {
  8380. if (typeof exports === "object") {
  8381. // CommonJS
  8382. module.exports = exports = factory(require("./core"), require("./cipher-core"));
  8383. }
  8384. else if (typeof define === "function" && define.amd) {
  8385. // AMD
  8386. define(["./core", "./cipher-core"], factory);
  8387. }
  8388. else {
  8389. // Global (browser)
  8390. factory(root.CryptoJS);
  8391. }
  8392. }(this, function (CryptoJS) {
  8393. /**
  8394. * Cipher Feedback block mode.
  8395. */
  8396. CryptoJS.mode.CFB = (function () {
  8397. var CFB = CryptoJS.lib.BlockCipherMode.extend();
  8398. CFB.Encryptor = CFB.extend({
  8399. processBlock: function (words, offset) {
  8400. // Shortcuts
  8401. var cipher = this._cipher;
  8402. var blockSize = cipher.blockSize;
  8403. generateKeystreamAndEncrypt.call(this, words, offset, blockSize, cipher);
  8404. // Remember this block to use with next block
  8405. this._prevBlock = words.slice(offset, offset + blockSize);
  8406. }
  8407. });
  8408. CFB.Decryptor = CFB.extend({
  8409. processBlock: function (words, offset) {
  8410. // Shortcuts
  8411. var cipher = this._cipher;
  8412. var blockSize = cipher.blockSize;
  8413. // Remember this block to use with next block
  8414. var thisBlock = words.slice(offset, offset + blockSize);
  8415. generateKeystreamAndEncrypt.call(this, words, offset, blockSize, cipher);
  8416. // This block becomes the previous block
  8417. this._prevBlock = thisBlock;
  8418. }
  8419. });
  8420. function generateKeystreamAndEncrypt(words, offset, blockSize, cipher) {
  8421. // Shortcut
  8422. var iv = this._iv;
  8423. // Generate keystream
  8424. if (iv) {
  8425. var keystream = iv.slice(0);
  8426. // Remove IV for subsequent blocks
  8427. this._iv = undefined;
  8428. } else {
  8429. var keystream = this._prevBlock;
  8430. }
  8431. cipher.encryptBlock(keystream, 0);
  8432. // Encrypt
  8433. for (var i = 0; i < blockSize; i++) {
  8434. words[offset + i] ^= keystream[i];
  8435. }
  8436. }
  8437. return CFB;
  8438. }());
  8439. return CryptoJS.mode.CFB;
  8440. }));
  8441. },{"./cipher-core":52,"./core":53}],63:[function(require,module,exports){
  8442. ;(function (root, factory, undef) {
  8443. if (typeof exports === "object") {
  8444. // CommonJS
  8445. module.exports = exports = factory(require("./core"), require("./cipher-core"));
  8446. }
  8447. else if (typeof define === "function" && define.amd) {
  8448. // AMD
  8449. define(["./core", "./cipher-core"], factory);
  8450. }
  8451. else {
  8452. // Global (browser)
  8453. factory(root.CryptoJS);
  8454. }
  8455. }(this, function (CryptoJS) {
  8456. /** @preserve
  8457. * Counter block mode compatible with Dr Brian Gladman fileenc.c
  8458. * derived from CryptoJS.mode.CTR
  8459. * Jan Hruby jhruby.web@gmail.com
  8460. */
  8461. CryptoJS.mode.CTRGladman = (function () {
  8462. var CTRGladman = CryptoJS.lib.BlockCipherMode.extend();
  8463. function incWord(word)
  8464. {
  8465. if (((word >> 24) & 0xff) === 0xff) { //overflow
  8466. var b1 = (word >> 16)&0xff;
  8467. var b2 = (word >> 8)&0xff;
  8468. var b3 = word & 0xff;
  8469. if (b1 === 0xff) // overflow b1
  8470. {
  8471. b1 = 0;
  8472. if (b2 === 0xff)
  8473. {
  8474. b2 = 0;
  8475. if (b3 === 0xff)
  8476. {
  8477. b3 = 0;
  8478. }
  8479. else
  8480. {
  8481. ++b3;
  8482. }
  8483. }
  8484. else
  8485. {
  8486. ++b2;
  8487. }
  8488. }
  8489. else
  8490. {
  8491. ++b1;
  8492. }
  8493. word = 0;
  8494. word += (b1 << 16);
  8495. word += (b2 << 8);
  8496. word += b3;
  8497. }
  8498. else
  8499. {
  8500. word += (0x01 << 24);
  8501. }
  8502. return word;
  8503. }
  8504. function incCounter(counter)
  8505. {
  8506. if ((counter[0] = incWord(counter[0])) === 0)
  8507. {
  8508. // encr_data in fileenc.c from Dr Brian Gladman's counts only with DWORD j < 8
  8509. counter[1] = incWord(counter[1]);
  8510. }
  8511. return counter;
  8512. }
  8513. var Encryptor = CTRGladman.Encryptor = CTRGladman.extend({
  8514. processBlock: function (words, offset) {
  8515. // Shortcuts
  8516. var cipher = this._cipher
  8517. var blockSize = cipher.blockSize;
  8518. var iv = this._iv;
  8519. var counter = this._counter;
  8520. // Generate keystream
  8521. if (iv) {
  8522. counter = this._counter = iv.slice(0);
  8523. // Remove IV for subsequent blocks
  8524. this._iv = undefined;
  8525. }
  8526. incCounter(counter);
  8527. var keystream = counter.slice(0);
  8528. cipher.encryptBlock(keystream, 0);
  8529. // Encrypt
  8530. for (var i = 0; i < blockSize; i++) {
  8531. words[offset + i] ^= keystream[i];
  8532. }
  8533. }
  8534. });
  8535. CTRGladman.Decryptor = Encryptor;
  8536. return CTRGladman;
  8537. }());
  8538. return CryptoJS.mode.CTRGladman;
  8539. }));
  8540. },{"./cipher-core":52,"./core":53}],64:[function(require,module,exports){
  8541. ;(function (root, factory, undef) {
  8542. if (typeof exports === "object") {
  8543. // CommonJS
  8544. module.exports = exports = factory(require("./core"), require("./cipher-core"));
  8545. }
  8546. else if (typeof define === "function" && define.amd) {
  8547. // AMD
  8548. define(["./core", "./cipher-core"], factory);
  8549. }
  8550. else {
  8551. // Global (browser)
  8552. factory(root.CryptoJS);
  8553. }
  8554. }(this, function (CryptoJS) {
  8555. /**
  8556. * Counter block mode.
  8557. */
  8558. CryptoJS.mode.CTR = (function () {
  8559. var CTR = CryptoJS.lib.BlockCipherMode.extend();
  8560. var Encryptor = CTR.Encryptor = CTR.extend({
  8561. processBlock: function (words, offset) {
  8562. // Shortcuts
  8563. var cipher = this._cipher
  8564. var blockSize = cipher.blockSize;
  8565. var iv = this._iv;
  8566. var counter = this._counter;
  8567. // Generate keystream
  8568. if (iv) {
  8569. counter = this._counter = iv.slice(0);
  8570. // Remove IV for subsequent blocks
  8571. this._iv = undefined;
  8572. }
  8573. var keystream = counter.slice(0);
  8574. cipher.encryptBlock(keystream, 0);
  8575. // Increment counter
  8576. counter[blockSize - 1] = (counter[blockSize - 1] + 1) | 0
  8577. // Encrypt
  8578. for (var i = 0; i < blockSize; i++) {
  8579. words[offset + i] ^= keystream[i];
  8580. }
  8581. }
  8582. });
  8583. CTR.Decryptor = Encryptor;
  8584. return CTR;
  8585. }());
  8586. return CryptoJS.mode.CTR;
  8587. }));
  8588. },{"./cipher-core":52,"./core":53}],65:[function(require,module,exports){
  8589. ;(function (root, factory, undef) {
  8590. if (typeof exports === "object") {
  8591. // CommonJS
  8592. module.exports = exports = factory(require("./core"), require("./cipher-core"));
  8593. }
  8594. else if (typeof define === "function" && define.amd) {
  8595. // AMD
  8596. define(["./core", "./cipher-core"], factory);
  8597. }
  8598. else {
  8599. // Global (browser)
  8600. factory(root.CryptoJS);
  8601. }
  8602. }(this, function (CryptoJS) {
  8603. /**
  8604. * Electronic Codebook block mode.
  8605. */
  8606. CryptoJS.mode.ECB = (function () {
  8607. var ECB = CryptoJS.lib.BlockCipherMode.extend();
  8608. ECB.Encryptor = ECB.extend({
  8609. processBlock: function (words, offset) {
  8610. this._cipher.encryptBlock(words, offset);
  8611. }
  8612. });
  8613. ECB.Decryptor = ECB.extend({
  8614. processBlock: function (words, offset) {
  8615. this._cipher.decryptBlock(words, offset);
  8616. }
  8617. });
  8618. return ECB;
  8619. }());
  8620. return CryptoJS.mode.ECB;
  8621. }));
  8622. },{"./cipher-core":52,"./core":53}],66:[function(require,module,exports){
  8623. ;(function (root, factory, undef) {
  8624. if (typeof exports === "object") {
  8625. // CommonJS
  8626. module.exports = exports = factory(require("./core"), require("./cipher-core"));
  8627. }
  8628. else if (typeof define === "function" && define.amd) {
  8629. // AMD
  8630. define(["./core", "./cipher-core"], factory);
  8631. }
  8632. else {
  8633. // Global (browser)
  8634. factory(root.CryptoJS);
  8635. }
  8636. }(this, function (CryptoJS) {
  8637. /**
  8638. * Output Feedback block mode.
  8639. */
  8640. CryptoJS.mode.OFB = (function () {
  8641. var OFB = CryptoJS.lib.BlockCipherMode.extend();
  8642. var Encryptor = OFB.Encryptor = OFB.extend({
  8643. processBlock: function (words, offset) {
  8644. // Shortcuts
  8645. var cipher = this._cipher
  8646. var blockSize = cipher.blockSize;
  8647. var iv = this._iv;
  8648. var keystream = this._keystream;
  8649. // Generate keystream
  8650. if (iv) {
  8651. keystream = this._keystream = iv.slice(0);
  8652. // Remove IV for subsequent blocks
  8653. this._iv = undefined;
  8654. }
  8655. cipher.encryptBlock(keystream, 0);
  8656. // Encrypt
  8657. for (var i = 0; i < blockSize; i++) {
  8658. words[offset + i] ^= keystream[i];
  8659. }
  8660. }
  8661. });
  8662. OFB.Decryptor = Encryptor;
  8663. return OFB;
  8664. }());
  8665. return CryptoJS.mode.OFB;
  8666. }));
  8667. },{"./cipher-core":52,"./core":53}],67:[function(require,module,exports){
  8668. ;(function (root, factory, undef) {
  8669. if (typeof exports === "object") {
  8670. // CommonJS
  8671. module.exports = exports = factory(require("./core"), require("./cipher-core"));
  8672. }
  8673. else if (typeof define === "function" && define.amd) {
  8674. // AMD
  8675. define(["./core", "./cipher-core"], factory);
  8676. }
  8677. else {
  8678. // Global (browser)
  8679. factory(root.CryptoJS);
  8680. }
  8681. }(this, function (CryptoJS) {
  8682. /**
  8683. * ANSI X.923 padding strategy.
  8684. */
  8685. CryptoJS.pad.AnsiX923 = {
  8686. pad: function (data, blockSize) {
  8687. // Shortcuts
  8688. var dataSigBytes = data.sigBytes;
  8689. var blockSizeBytes = blockSize * 4;
  8690. // Count padding bytes
  8691. var nPaddingBytes = blockSizeBytes - dataSigBytes % blockSizeBytes;
  8692. // Compute last byte position
  8693. var lastBytePos = dataSigBytes + nPaddingBytes - 1;
  8694. // Pad
  8695. data.clamp();
  8696. data.words[lastBytePos >>> 2] |= nPaddingBytes << (24 - (lastBytePos % 4) * 8);
  8697. data.sigBytes += nPaddingBytes;
  8698. },
  8699. unpad: function (data) {
  8700. // Get number of padding bytes from last byte
  8701. var nPaddingBytes = data.words[(data.sigBytes - 1) >>> 2] & 0xff;
  8702. // Remove padding
  8703. data.sigBytes -= nPaddingBytes;
  8704. }
  8705. };
  8706. return CryptoJS.pad.Ansix923;
  8707. }));
  8708. },{"./cipher-core":52,"./core":53}],68:[function(require,module,exports){
  8709. ;(function (root, factory, undef) {
  8710. if (typeof exports === "object") {
  8711. // CommonJS
  8712. module.exports = exports = factory(require("./core"), require("./cipher-core"));
  8713. }
  8714. else if (typeof define === "function" && define.amd) {
  8715. // AMD
  8716. define(["./core", "./cipher-core"], factory);
  8717. }
  8718. else {
  8719. // Global (browser)
  8720. factory(root.CryptoJS);
  8721. }
  8722. }(this, function (CryptoJS) {
  8723. /**
  8724. * ISO 10126 padding strategy.
  8725. */
  8726. CryptoJS.pad.Iso10126 = {
  8727. pad: function (data, blockSize) {
  8728. // Shortcut
  8729. var blockSizeBytes = blockSize * 4;
  8730. // Count padding bytes
  8731. var nPaddingBytes = blockSizeBytes - data.sigBytes % blockSizeBytes;
  8732. // Pad
  8733. data.concat(CryptoJS.lib.WordArray.random(nPaddingBytes - 1)).
  8734. concat(CryptoJS.lib.WordArray.create([nPaddingBytes << 24], 1));
  8735. },
  8736. unpad: function (data) {
  8737. // Get number of padding bytes from last byte
  8738. var nPaddingBytes = data.words[(data.sigBytes - 1) >>> 2] & 0xff;
  8739. // Remove padding
  8740. data.sigBytes -= nPaddingBytes;
  8741. }
  8742. };
  8743. return CryptoJS.pad.Iso10126;
  8744. }));
  8745. },{"./cipher-core":52,"./core":53}],69:[function(require,module,exports){
  8746. ;(function (root, factory, undef) {
  8747. if (typeof exports === "object") {
  8748. // CommonJS
  8749. module.exports = exports = factory(require("./core"), require("./cipher-core"));
  8750. }
  8751. else if (typeof define === "function" && define.amd) {
  8752. // AMD
  8753. define(["./core", "./cipher-core"], factory);
  8754. }
  8755. else {
  8756. // Global (browser)
  8757. factory(root.CryptoJS);
  8758. }
  8759. }(this, function (CryptoJS) {
  8760. /**
  8761. * ISO/IEC 9797-1 Padding Method 2.
  8762. */
  8763. CryptoJS.pad.Iso97971 = {
  8764. pad: function (data, blockSize) {
  8765. // Add 0x80 byte
  8766. data.concat(CryptoJS.lib.WordArray.create([0x80000000], 1));
  8767. // Zero pad the rest
  8768. CryptoJS.pad.ZeroPadding.pad(data, blockSize);
  8769. },
  8770. unpad: function (data) {
  8771. // Remove zero padding
  8772. CryptoJS.pad.ZeroPadding.unpad(data);
  8773. // Remove one more byte -- the 0x80 byte
  8774. data.sigBytes--;
  8775. }
  8776. };
  8777. return CryptoJS.pad.Iso97971;
  8778. }));
  8779. },{"./cipher-core":52,"./core":53}],70:[function(require,module,exports){
  8780. ;(function (root, factory, undef) {
  8781. if (typeof exports === "object") {
  8782. // CommonJS
  8783. module.exports = exports = factory(require("./core"), require("./cipher-core"));
  8784. }
  8785. else if (typeof define === "function" && define.amd) {
  8786. // AMD
  8787. define(["./core", "./cipher-core"], factory);
  8788. }
  8789. else {
  8790. // Global (browser)
  8791. factory(root.CryptoJS);
  8792. }
  8793. }(this, function (CryptoJS) {
  8794. /**
  8795. * A noop padding strategy.
  8796. */
  8797. CryptoJS.pad.NoPadding = {
  8798. pad: function () {
  8799. },
  8800. unpad: function () {
  8801. }
  8802. };
  8803. return CryptoJS.pad.NoPadding;
  8804. }));
  8805. },{"./cipher-core":52,"./core":53}],71:[function(require,module,exports){
  8806. ;(function (root, factory, undef) {
  8807. if (typeof exports === "object") {
  8808. // CommonJS
  8809. module.exports = exports = factory(require("./core"), require("./cipher-core"));
  8810. }
  8811. else if (typeof define === "function" && define.amd) {
  8812. // AMD
  8813. define(["./core", "./cipher-core"], factory);
  8814. }
  8815. else {
  8816. // Global (browser)
  8817. factory(root.CryptoJS);
  8818. }
  8819. }(this, function (CryptoJS) {
  8820. /**
  8821. * Zero padding strategy.
  8822. */
  8823. CryptoJS.pad.ZeroPadding = {
  8824. pad: function (data, blockSize) {
  8825. // Shortcut
  8826. var blockSizeBytes = blockSize * 4;
  8827. // Pad
  8828. data.clamp();
  8829. data.sigBytes += blockSizeBytes - ((data.sigBytes % blockSizeBytes) || blockSizeBytes);
  8830. },
  8831. unpad: function (data) {
  8832. // Shortcut
  8833. var dataWords = data.words;
  8834. // Unpad
  8835. var i = data.sigBytes - 1;
  8836. while (!((dataWords[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff)) {
  8837. i--;
  8838. }
  8839. data.sigBytes = i + 1;
  8840. }
  8841. };
  8842. return CryptoJS.pad.ZeroPadding;
  8843. }));
  8844. },{"./cipher-core":52,"./core":53}],72:[function(require,module,exports){
  8845. ;(function (root, factory, undef) {
  8846. if (typeof exports === "object") {
  8847. // CommonJS
  8848. module.exports = exports = factory(require("./core"), require("./sha1"), require("./hmac"));
  8849. }
  8850. else if (typeof define === "function" && define.amd) {
  8851. // AMD
  8852. define(["./core", "./sha1", "./hmac"], factory);
  8853. }
  8854. else {
  8855. // Global (browser)
  8856. factory(root.CryptoJS);
  8857. }
  8858. }(this, function (CryptoJS) {
  8859. (function () {
  8860. // Shortcuts
  8861. var C = CryptoJS;
  8862. var C_lib = C.lib;
  8863. var Base = C_lib.Base;
  8864. var WordArray = C_lib.WordArray;
  8865. var C_algo = C.algo;
  8866. var SHA1 = C_algo.SHA1;
  8867. var HMAC = C_algo.HMAC;
  8868. /**
  8869. * Password-Based Key Derivation Function 2 algorithm.
  8870. */
  8871. var PBKDF2 = C_algo.PBKDF2 = Base.extend({
  8872. /**
  8873. * Configuration options.
  8874. *
  8875. * @property {number} keySize The key size in words to generate. Default: 4 (128 bits)
  8876. * @property {Hasher} hasher The hasher to use. Default: SHA1
  8877. * @property {number} iterations The number of iterations to perform. Default: 1
  8878. */
  8879. cfg: Base.extend({
  8880. keySize: 128/32,
  8881. hasher: SHA1,
  8882. iterations: 1
  8883. }),
  8884. /**
  8885. * Initializes a newly created key derivation function.
  8886. *
  8887. * @param {Object} cfg (Optional) The configuration options to use for the derivation.
  8888. *
  8889. * @example
  8890. *
  8891. * var kdf = CryptoJS.algo.PBKDF2.create();
  8892. * var kdf = CryptoJS.algo.PBKDF2.create({ keySize: 8 });
  8893. * var kdf = CryptoJS.algo.PBKDF2.create({ keySize: 8, iterations: 1000 });
  8894. */
  8895. init: function (cfg) {
  8896. this.cfg = this.cfg.extend(cfg);
  8897. },
  8898. /**
  8899. * Computes the Password-Based Key Derivation Function 2.
  8900. *
  8901. * @param {WordArray|string} password The password.
  8902. * @param {WordArray|string} salt A salt.
  8903. *
  8904. * @return {WordArray} The derived key.
  8905. *
  8906. * @example
  8907. *
  8908. * var key = kdf.compute(password, salt);
  8909. */
  8910. compute: function (password, salt) {
  8911. // Shortcut
  8912. var cfg = this.cfg;
  8913. // Init HMAC
  8914. var hmac = HMAC.create(cfg.hasher, password);
  8915. // Initial values
  8916. var derivedKey = WordArray.create();
  8917. var blockIndex = WordArray.create([0x00000001]);
  8918. // Shortcuts
  8919. var derivedKeyWords = derivedKey.words;
  8920. var blockIndexWords = blockIndex.words;
  8921. var keySize = cfg.keySize;
  8922. var iterations = cfg.iterations;
  8923. // Generate key
  8924. while (derivedKeyWords.length < keySize) {
  8925. var block = hmac.update(salt).finalize(blockIndex);
  8926. hmac.reset();
  8927. // Shortcuts
  8928. var blockWords = block.words;
  8929. var blockWordsLength = blockWords.length;
  8930. // Iterations
  8931. var intermediate = block;
  8932. for (var i = 1; i < iterations; i++) {
  8933. intermediate = hmac.finalize(intermediate);
  8934. hmac.reset();
  8935. // Shortcut
  8936. var intermediateWords = intermediate.words;
  8937. // XOR intermediate with block
  8938. for (var j = 0; j < blockWordsLength; j++) {
  8939. blockWords[j] ^= intermediateWords[j];
  8940. }
  8941. }
  8942. derivedKey.concat(block);
  8943. blockIndexWords[0]++;
  8944. }
  8945. derivedKey.sigBytes = keySize * 4;
  8946. return derivedKey;
  8947. }
  8948. });
  8949. /**
  8950. * Computes the Password-Based Key Derivation Function 2.
  8951. *
  8952. * @param {WordArray|string} password The password.
  8953. * @param {WordArray|string} salt A salt.
  8954. * @param {Object} cfg (Optional) The configuration options to use for this computation.
  8955. *
  8956. * @return {WordArray} The derived key.
  8957. *
  8958. * @static
  8959. *
  8960. * @example
  8961. *
  8962. * var key = CryptoJS.PBKDF2(password, salt);
  8963. * var key = CryptoJS.PBKDF2(password, salt, { keySize: 8 });
  8964. * var key = CryptoJS.PBKDF2(password, salt, { keySize: 8, iterations: 1000 });
  8965. */
  8966. C.PBKDF2 = function (password, salt, cfg) {
  8967. return PBKDF2.create(cfg).compute(password, salt);
  8968. };
  8969. }());
  8970. return CryptoJS.PBKDF2;
  8971. }));
  8972. },{"./core":53,"./hmac":58,"./sha1":77}],73:[function(require,module,exports){
  8973. ;(function (root, factory, undef) {
  8974. if (typeof exports === "object") {
  8975. // CommonJS
  8976. module.exports = exports = factory(require("./core"), require("./enc-base64"), require("./md5"), require("./evpkdf"), require("./cipher-core"));
  8977. }
  8978. else if (typeof define === "function" && define.amd) {
  8979. // AMD
  8980. define(["./core", "./enc-base64", "./md5", "./evpkdf", "./cipher-core"], factory);
  8981. }
  8982. else {
  8983. // Global (browser)
  8984. factory(root.CryptoJS);
  8985. }
  8986. }(this, function (CryptoJS) {
  8987. (function () {
  8988. // Shortcuts
  8989. var C = CryptoJS;
  8990. var C_lib = C.lib;
  8991. var StreamCipher = C_lib.StreamCipher;
  8992. var C_algo = C.algo;
  8993. // Reusable objects
  8994. var S = [];
  8995. var C_ = [];
  8996. var G = [];
  8997. /**
  8998. * Rabbit stream cipher algorithm.
  8999. *
  9000. * This is a legacy version that neglected to convert the key to little-endian.
  9001. * This error doesn't affect the cipher's security,
  9002. * but it does affect its compatibility with other implementations.
  9003. */
  9004. var RabbitLegacy = C_algo.RabbitLegacy = StreamCipher.extend({
  9005. _doReset: function () {
  9006. // Shortcuts
  9007. var K = this._key.words;
  9008. var iv = this.cfg.iv;
  9009. // Generate initial state values
  9010. var X = this._X = [
  9011. K[0], (K[3] << 16) | (K[2] >>> 16),
  9012. K[1], (K[0] << 16) | (K[3] >>> 16),
  9013. K[2], (K[1] << 16) | (K[0] >>> 16),
  9014. K[3], (K[2] << 16) | (K[1] >>> 16)
  9015. ];
  9016. // Generate initial counter values
  9017. var C = this._C = [
  9018. (K[2] << 16) | (K[2] >>> 16), (K[0] & 0xffff0000) | (K[1] & 0x0000ffff),
  9019. (K[3] << 16) | (K[3] >>> 16), (K[1] & 0xffff0000) | (K[2] & 0x0000ffff),
  9020. (K[0] << 16) | (K[0] >>> 16), (K[2] & 0xffff0000) | (K[3] & 0x0000ffff),
  9021. (K[1] << 16) | (K[1] >>> 16), (K[3] & 0xffff0000) | (K[0] & 0x0000ffff)
  9022. ];
  9023. // Carry bit
  9024. this._b = 0;
  9025. // Iterate the system four times
  9026. for (var i = 0; i < 4; i++) {
  9027. nextState.call(this);
  9028. }
  9029. // Modify the counters
  9030. for (var i = 0; i < 8; i++) {
  9031. C[i] ^= X[(i + 4) & 7];
  9032. }
  9033. // IV setup
  9034. if (iv) {
  9035. // Shortcuts
  9036. var IV = iv.words;
  9037. var IV_0 = IV[0];
  9038. var IV_1 = IV[1];
  9039. // Generate four subvectors
  9040. var i0 = (((IV_0 << 8) | (IV_0 >>> 24)) & 0x00ff00ff) | (((IV_0 << 24) | (IV_0 >>> 8)) & 0xff00ff00);
  9041. var i2 = (((IV_1 << 8) | (IV_1 >>> 24)) & 0x00ff00ff) | (((IV_1 << 24) | (IV_1 >>> 8)) & 0xff00ff00);
  9042. var i1 = (i0 >>> 16) | (i2 & 0xffff0000);
  9043. var i3 = (i2 << 16) | (i0 & 0x0000ffff);
  9044. // Modify counter values
  9045. C[0] ^= i0;
  9046. C[1] ^= i1;
  9047. C[2] ^= i2;
  9048. C[3] ^= i3;
  9049. C[4] ^= i0;
  9050. C[5] ^= i1;
  9051. C[6] ^= i2;
  9052. C[7] ^= i3;
  9053. // Iterate the system four times
  9054. for (var i = 0; i < 4; i++) {
  9055. nextState.call(this);
  9056. }
  9057. }
  9058. },
  9059. _doProcessBlock: function (M, offset) {
  9060. // Shortcut
  9061. var X = this._X;
  9062. // Iterate the system
  9063. nextState.call(this);
  9064. // Generate four keystream words
  9065. S[0] = X[0] ^ (X[5] >>> 16) ^ (X[3] << 16);
  9066. S[1] = X[2] ^ (X[7] >>> 16) ^ (X[5] << 16);
  9067. S[2] = X[4] ^ (X[1] >>> 16) ^ (X[7] << 16);
  9068. S[3] = X[6] ^ (X[3] >>> 16) ^ (X[1] << 16);
  9069. for (var i = 0; i < 4; i++) {
  9070. // Swap endian
  9071. S[i] = (((S[i] << 8) | (S[i] >>> 24)) & 0x00ff00ff) |
  9072. (((S[i] << 24) | (S[i] >>> 8)) & 0xff00ff00);
  9073. // Encrypt
  9074. M[offset + i] ^= S[i];
  9075. }
  9076. },
  9077. blockSize: 128/32,
  9078. ivSize: 64/32
  9079. });
  9080. function nextState() {
  9081. // Shortcuts
  9082. var X = this._X;
  9083. var C = this._C;
  9084. // Save old counter values
  9085. for (var i = 0; i < 8; i++) {
  9086. C_[i] = C[i];
  9087. }
  9088. // Calculate new counter values
  9089. C[0] = (C[0] + 0x4d34d34d + this._b) | 0;
  9090. C[1] = (C[1] + 0xd34d34d3 + ((C[0] >>> 0) < (C_[0] >>> 0) ? 1 : 0)) | 0;
  9091. C[2] = (C[2] + 0x34d34d34 + ((C[1] >>> 0) < (C_[1] >>> 0) ? 1 : 0)) | 0;
  9092. C[3] = (C[3] + 0x4d34d34d + ((C[2] >>> 0) < (C_[2] >>> 0) ? 1 : 0)) | 0;
  9093. C[4] = (C[4] + 0xd34d34d3 + ((C[3] >>> 0) < (C_[3] >>> 0) ? 1 : 0)) | 0;
  9094. C[5] = (C[5] + 0x34d34d34 + ((C[4] >>> 0) < (C_[4] >>> 0) ? 1 : 0)) | 0;
  9095. C[6] = (C[6] + 0x4d34d34d + ((C[5] >>> 0) < (C_[5] >>> 0) ? 1 : 0)) | 0;
  9096. C[7] = (C[7] + 0xd34d34d3 + ((C[6] >>> 0) < (C_[6] >>> 0) ? 1 : 0)) | 0;
  9097. this._b = (C[7] >>> 0) < (C_[7] >>> 0) ? 1 : 0;
  9098. // Calculate the g-values
  9099. for (var i = 0; i < 8; i++) {
  9100. var gx = X[i] + C[i];
  9101. // Construct high and low argument for squaring
  9102. var ga = gx & 0xffff;
  9103. var gb = gx >>> 16;
  9104. // Calculate high and low result of squaring
  9105. var gh = ((((ga * ga) >>> 17) + ga * gb) >>> 15) + gb * gb;
  9106. var gl = (((gx & 0xffff0000) * gx) | 0) + (((gx & 0x0000ffff) * gx) | 0);
  9107. // High XOR low
  9108. G[i] = gh ^ gl;
  9109. }
  9110. // Calculate new state values
  9111. X[0] = (G[0] + ((G[7] << 16) | (G[7] >>> 16)) + ((G[6] << 16) | (G[6] >>> 16))) | 0;
  9112. X[1] = (G[1] + ((G[0] << 8) | (G[0] >>> 24)) + G[7]) | 0;
  9113. X[2] = (G[2] + ((G[1] << 16) | (G[1] >>> 16)) + ((G[0] << 16) | (G[0] >>> 16))) | 0;
  9114. X[3] = (G[3] + ((G[2] << 8) | (G[2] >>> 24)) + G[1]) | 0;
  9115. X[4] = (G[4] + ((G[3] << 16) | (G[3] >>> 16)) + ((G[2] << 16) | (G[2] >>> 16))) | 0;
  9116. X[5] = (G[5] + ((G[4] << 8) | (G[4] >>> 24)) + G[3]) | 0;
  9117. X[6] = (G[6] + ((G[5] << 16) | (G[5] >>> 16)) + ((G[4] << 16) | (G[4] >>> 16))) | 0;
  9118. X[7] = (G[7] + ((G[6] << 8) | (G[6] >>> 24)) + G[5]) | 0;
  9119. }
  9120. /**
  9121. * Shortcut functions to the cipher's object interface.
  9122. *
  9123. * @example
  9124. *
  9125. * var ciphertext = CryptoJS.RabbitLegacy.encrypt(message, key, cfg);
  9126. * var plaintext = CryptoJS.RabbitLegacy.decrypt(ciphertext, key, cfg);
  9127. */
  9128. C.RabbitLegacy = StreamCipher._createHelper(RabbitLegacy);
  9129. }());
  9130. return CryptoJS.RabbitLegacy;
  9131. }));
  9132. },{"./cipher-core":52,"./core":53,"./enc-base64":54,"./evpkdf":56,"./md5":61}],74:[function(require,module,exports){
  9133. ;(function (root, factory, undef) {
  9134. if (typeof exports === "object") {
  9135. // CommonJS
  9136. module.exports = exports = factory(require("./core"), require("./enc-base64"), require("./md5"), require("./evpkdf"), require("./cipher-core"));
  9137. }
  9138. else if (typeof define === "function" && define.amd) {
  9139. // AMD
  9140. define(["./core", "./enc-base64", "./md5", "./evpkdf", "./cipher-core"], factory);
  9141. }
  9142. else {
  9143. // Global (browser)
  9144. factory(root.CryptoJS);
  9145. }
  9146. }(this, function (CryptoJS) {
  9147. (function () {
  9148. // Shortcuts
  9149. var C = CryptoJS;
  9150. var C_lib = C.lib;
  9151. var StreamCipher = C_lib.StreamCipher;
  9152. var C_algo = C.algo;
  9153. // Reusable objects
  9154. var S = [];
  9155. var C_ = [];
  9156. var G = [];
  9157. /**
  9158. * Rabbit stream cipher algorithm
  9159. */
  9160. var Rabbit = C_algo.Rabbit = StreamCipher.extend({
  9161. _doReset: function () {
  9162. // Shortcuts
  9163. var K = this._key.words;
  9164. var iv = this.cfg.iv;
  9165. // Swap endian
  9166. for (var i = 0; i < 4; i++) {
  9167. K[i] = (((K[i] << 8) | (K[i] >>> 24)) & 0x00ff00ff) |
  9168. (((K[i] << 24) | (K[i] >>> 8)) & 0xff00ff00);
  9169. }
  9170. // Generate initial state values
  9171. var X = this._X = [
  9172. K[0], (K[3] << 16) | (K[2] >>> 16),
  9173. K[1], (K[0] << 16) | (K[3] >>> 16),
  9174. K[2], (K[1] << 16) | (K[0] >>> 16),
  9175. K[3], (K[2] << 16) | (K[1] >>> 16)
  9176. ];
  9177. // Generate initial counter values
  9178. var C = this._C = [
  9179. (K[2] << 16) | (K[2] >>> 16), (K[0] & 0xffff0000) | (K[1] & 0x0000ffff),
  9180. (K[3] << 16) | (K[3] >>> 16), (K[1] & 0xffff0000) | (K[2] & 0x0000ffff),
  9181. (K[0] << 16) | (K[0] >>> 16), (K[2] & 0xffff0000) | (K[3] & 0x0000ffff),
  9182. (K[1] << 16) | (K[1] >>> 16), (K[3] & 0xffff0000) | (K[0] & 0x0000ffff)
  9183. ];
  9184. // Carry bit
  9185. this._b = 0;
  9186. // Iterate the system four times
  9187. for (var i = 0; i < 4; i++) {
  9188. nextState.call(this);
  9189. }
  9190. // Modify the counters
  9191. for (var i = 0; i < 8; i++) {
  9192. C[i] ^= X[(i + 4) & 7];
  9193. }
  9194. // IV setup
  9195. if (iv) {
  9196. // Shortcuts
  9197. var IV = iv.words;
  9198. var IV_0 = IV[0];
  9199. var IV_1 = IV[1];
  9200. // Generate four subvectors
  9201. var i0 = (((IV_0 << 8) | (IV_0 >>> 24)) & 0x00ff00ff) | (((IV_0 << 24) | (IV_0 >>> 8)) & 0xff00ff00);
  9202. var i2 = (((IV_1 << 8) | (IV_1 >>> 24)) & 0x00ff00ff) | (((IV_1 << 24) | (IV_1 >>> 8)) & 0xff00ff00);
  9203. var i1 = (i0 >>> 16) | (i2 & 0xffff0000);
  9204. var i3 = (i2 << 16) | (i0 & 0x0000ffff);
  9205. // Modify counter values
  9206. C[0] ^= i0;
  9207. C[1] ^= i1;
  9208. C[2] ^= i2;
  9209. C[3] ^= i3;
  9210. C[4] ^= i0;
  9211. C[5] ^= i1;
  9212. C[6] ^= i2;
  9213. C[7] ^= i3;
  9214. // Iterate the system four times
  9215. for (var i = 0; i < 4; i++) {
  9216. nextState.call(this);
  9217. }
  9218. }
  9219. },
  9220. _doProcessBlock: function (M, offset) {
  9221. // Shortcut
  9222. var X = this._X;
  9223. // Iterate the system
  9224. nextState.call(this);
  9225. // Generate four keystream words
  9226. S[0] = X[0] ^ (X[5] >>> 16) ^ (X[3] << 16);
  9227. S[1] = X[2] ^ (X[7] >>> 16) ^ (X[5] << 16);
  9228. S[2] = X[4] ^ (X[1] >>> 16) ^ (X[7] << 16);
  9229. S[3] = X[6] ^ (X[3] >>> 16) ^ (X[1] << 16);
  9230. for (var i = 0; i < 4; i++) {
  9231. // Swap endian
  9232. S[i] = (((S[i] << 8) | (S[i] >>> 24)) & 0x00ff00ff) |
  9233. (((S[i] << 24) | (S[i] >>> 8)) & 0xff00ff00);
  9234. // Encrypt
  9235. M[offset + i] ^= S[i];
  9236. }
  9237. },
  9238. blockSize: 128/32,
  9239. ivSize: 64/32
  9240. });
  9241. function nextState() {
  9242. // Shortcuts
  9243. var X = this._X;
  9244. var C = this._C;
  9245. // Save old counter values
  9246. for (var i = 0; i < 8; i++) {
  9247. C_[i] = C[i];
  9248. }
  9249. // Calculate new counter values
  9250. C[0] = (C[0] + 0x4d34d34d + this._b) | 0;
  9251. C[1] = (C[1] + 0xd34d34d3 + ((C[0] >>> 0) < (C_[0] >>> 0) ? 1 : 0)) | 0;
  9252. C[2] = (C[2] + 0x34d34d34 + ((C[1] >>> 0) < (C_[1] >>> 0) ? 1 : 0)) | 0;
  9253. C[3] = (C[3] + 0x4d34d34d + ((C[2] >>> 0) < (C_[2] >>> 0) ? 1 : 0)) | 0;
  9254. C[4] = (C[4] + 0xd34d34d3 + ((C[3] >>> 0) < (C_[3] >>> 0) ? 1 : 0)) | 0;
  9255. C[5] = (C[5] + 0x34d34d34 + ((C[4] >>> 0) < (C_[4] >>> 0) ? 1 : 0)) | 0;
  9256. C[6] = (C[6] + 0x4d34d34d + ((C[5] >>> 0) < (C_[5] >>> 0) ? 1 : 0)) | 0;
  9257. C[7] = (C[7] + 0xd34d34d3 + ((C[6] >>> 0) < (C_[6] >>> 0) ? 1 : 0)) | 0;
  9258. this._b = (C[7] >>> 0) < (C_[7] >>> 0) ? 1 : 0;
  9259. // Calculate the g-values
  9260. for (var i = 0; i < 8; i++) {
  9261. var gx = X[i] + C[i];
  9262. // Construct high and low argument for squaring
  9263. var ga = gx & 0xffff;
  9264. var gb = gx >>> 16;
  9265. // Calculate high and low result of squaring
  9266. var gh = ((((ga * ga) >>> 17) + ga * gb) >>> 15) + gb * gb;
  9267. var gl = (((gx & 0xffff0000) * gx) | 0) + (((gx & 0x0000ffff) * gx) | 0);
  9268. // High XOR low
  9269. G[i] = gh ^ gl;
  9270. }
  9271. // Calculate new state values
  9272. X[0] = (G[0] + ((G[7] << 16) | (G[7] >>> 16)) + ((G[6] << 16) | (G[6] >>> 16))) | 0;
  9273. X[1] = (G[1] + ((G[0] << 8) | (G[0] >>> 24)) + G[7]) | 0;
  9274. X[2] = (G[2] + ((G[1] << 16) | (G[1] >>> 16)) + ((G[0] << 16) | (G[0] >>> 16))) | 0;
  9275. X[3] = (G[3] + ((G[2] << 8) | (G[2] >>> 24)) + G[1]) | 0;
  9276. X[4] = (G[4] + ((G[3] << 16) | (G[3] >>> 16)) + ((G[2] << 16) | (G[2] >>> 16))) | 0;
  9277. X[5] = (G[5] + ((G[4] << 8) | (G[4] >>> 24)) + G[3]) | 0;
  9278. X[6] = (G[6] + ((G[5] << 16) | (G[5] >>> 16)) + ((G[4] << 16) | (G[4] >>> 16))) | 0;
  9279. X[7] = (G[7] + ((G[6] << 8) | (G[6] >>> 24)) + G[5]) | 0;
  9280. }
  9281. /**
  9282. * Shortcut functions to the cipher's object interface.
  9283. *
  9284. * @example
  9285. *
  9286. * var ciphertext = CryptoJS.Rabbit.encrypt(message, key, cfg);
  9287. * var plaintext = CryptoJS.Rabbit.decrypt(ciphertext, key, cfg);
  9288. */
  9289. C.Rabbit = StreamCipher._createHelper(Rabbit);
  9290. }());
  9291. return CryptoJS.Rabbit;
  9292. }));
  9293. },{"./cipher-core":52,"./core":53,"./enc-base64":54,"./evpkdf":56,"./md5":61}],75:[function(require,module,exports){
  9294. ;(function (root, factory, undef) {
  9295. if (typeof exports === "object") {
  9296. // CommonJS
  9297. module.exports = exports = factory(require("./core"), require("./enc-base64"), require("./md5"), require("./evpkdf"), require("./cipher-core"));
  9298. }
  9299. else if (typeof define === "function" && define.amd) {
  9300. // AMD
  9301. define(["./core", "./enc-base64", "./md5", "./evpkdf", "./cipher-core"], factory);
  9302. }
  9303. else {
  9304. // Global (browser)
  9305. factory(root.CryptoJS);
  9306. }
  9307. }(this, function (CryptoJS) {
  9308. (function () {
  9309. // Shortcuts
  9310. var C = CryptoJS;
  9311. var C_lib = C.lib;
  9312. var StreamCipher = C_lib.StreamCipher;
  9313. var C_algo = C.algo;
  9314. /**
  9315. * RC4 stream cipher algorithm.
  9316. */
  9317. var RC4 = C_algo.RC4 = StreamCipher.extend({
  9318. _doReset: function () {
  9319. // Shortcuts
  9320. var key = this._key;
  9321. var keyWords = key.words;
  9322. var keySigBytes = key.sigBytes;
  9323. // Init sbox
  9324. var S = this._S = [];
  9325. for (var i = 0; i < 256; i++) {
  9326. S[i] = i;
  9327. }
  9328. // Key setup
  9329. for (var i = 0, j = 0; i < 256; i++) {
  9330. var keyByteIndex = i % keySigBytes;
  9331. var keyByte = (keyWords[keyByteIndex >>> 2] >>> (24 - (keyByteIndex % 4) * 8)) & 0xff;
  9332. j = (j + S[i] + keyByte) % 256;
  9333. // Swap
  9334. var t = S[i];
  9335. S[i] = S[j];
  9336. S[j] = t;
  9337. }
  9338. // Counters
  9339. this._i = this._j = 0;
  9340. },
  9341. _doProcessBlock: function (M, offset) {
  9342. M[offset] ^= generateKeystreamWord.call(this);
  9343. },
  9344. keySize: 256/32,
  9345. ivSize: 0
  9346. });
  9347. function generateKeystreamWord() {
  9348. // Shortcuts
  9349. var S = this._S;
  9350. var i = this._i;
  9351. var j = this._j;
  9352. // Generate keystream word
  9353. var keystreamWord = 0;
  9354. for (var n = 0; n < 4; n++) {
  9355. i = (i + 1) % 256;
  9356. j = (j + S[i]) % 256;
  9357. // Swap
  9358. var t = S[i];
  9359. S[i] = S[j];
  9360. S[j] = t;
  9361. keystreamWord |= S[(S[i] + S[j]) % 256] << (24 - n * 8);
  9362. }
  9363. // Update counters
  9364. this._i = i;
  9365. this._j = j;
  9366. return keystreamWord;
  9367. }
  9368. /**
  9369. * Shortcut functions to the cipher's object interface.
  9370. *
  9371. * @example
  9372. *
  9373. * var ciphertext = CryptoJS.RC4.encrypt(message, key, cfg);
  9374. * var plaintext = CryptoJS.RC4.decrypt(ciphertext, key, cfg);
  9375. */
  9376. C.RC4 = StreamCipher._createHelper(RC4);
  9377. /**
  9378. * Modified RC4 stream cipher algorithm.
  9379. */
  9380. var RC4Drop = C_algo.RC4Drop = RC4.extend({
  9381. /**
  9382. * Configuration options.
  9383. *
  9384. * @property {number} drop The number of keystream words to drop. Default 192
  9385. */
  9386. cfg: RC4.cfg.extend({
  9387. drop: 192
  9388. }),
  9389. _doReset: function () {
  9390. RC4._doReset.call(this);
  9391. // Drop
  9392. for (var i = this.cfg.drop; i > 0; i--) {
  9393. generateKeystreamWord.call(this);
  9394. }
  9395. }
  9396. });
  9397. /**
  9398. * Shortcut functions to the cipher's object interface.
  9399. *
  9400. * @example
  9401. *
  9402. * var ciphertext = CryptoJS.RC4Drop.encrypt(message, key, cfg);
  9403. * var plaintext = CryptoJS.RC4Drop.decrypt(ciphertext, key, cfg);
  9404. */
  9405. C.RC4Drop = StreamCipher._createHelper(RC4Drop);
  9406. }());
  9407. return CryptoJS.RC4;
  9408. }));
  9409. },{"./cipher-core":52,"./core":53,"./enc-base64":54,"./evpkdf":56,"./md5":61}],76:[function(require,module,exports){
  9410. ;(function (root, factory) {
  9411. if (typeof exports === "object") {
  9412. // CommonJS
  9413. module.exports = exports = factory(require("./core"));
  9414. }
  9415. else if (typeof define === "function" && define.amd) {
  9416. // AMD
  9417. define(["./core"], factory);
  9418. }
  9419. else {
  9420. // Global (browser)
  9421. factory(root.CryptoJS);
  9422. }
  9423. }(this, function (CryptoJS) {
  9424. /** @preserve
  9425. (c) 2012 by Cédric Mesnil. All rights reserved.
  9426. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
  9427. - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  9428. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  9429. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  9430. */
  9431. (function (Math) {
  9432. // Shortcuts
  9433. var C = CryptoJS;
  9434. var C_lib = C.lib;
  9435. var WordArray = C_lib.WordArray;
  9436. var Hasher = C_lib.Hasher;
  9437. var C_algo = C.algo;
  9438. // Constants table
  9439. var _zl = WordArray.create([
  9440. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
  9441. 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8,
  9442. 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12,
  9443. 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2,
  9444. 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13]);
  9445. var _zr = WordArray.create([
  9446. 5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12,
  9447. 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2,
  9448. 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13,
  9449. 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14,
  9450. 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11]);
  9451. var _sl = WordArray.create([
  9452. 11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8,
  9453. 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12,
  9454. 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5,
  9455. 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12,
  9456. 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6 ]);
  9457. var _sr = WordArray.create([
  9458. 8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6,
  9459. 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11,
  9460. 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5,
  9461. 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8,
  9462. 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11 ]);
  9463. var _hl = WordArray.create([ 0x00000000, 0x5A827999, 0x6ED9EBA1, 0x8F1BBCDC, 0xA953FD4E]);
  9464. var _hr = WordArray.create([ 0x50A28BE6, 0x5C4DD124, 0x6D703EF3, 0x7A6D76E9, 0x00000000]);
  9465. /**
  9466. * RIPEMD160 hash algorithm.
  9467. */
  9468. var RIPEMD160 = C_algo.RIPEMD160 = Hasher.extend({
  9469. _doReset: function () {
  9470. this._hash = WordArray.create([0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0]);
  9471. },
  9472. _doProcessBlock: function (M, offset) {
  9473. // Swap endian
  9474. for (var i = 0; i < 16; i++) {
  9475. // Shortcuts
  9476. var offset_i = offset + i;
  9477. var M_offset_i = M[offset_i];
  9478. // Swap
  9479. M[offset_i] = (
  9480. (((M_offset_i << 8) | (M_offset_i >>> 24)) & 0x00ff00ff) |
  9481. (((M_offset_i << 24) | (M_offset_i >>> 8)) & 0xff00ff00)
  9482. );
  9483. }
  9484. // Shortcut
  9485. var H = this._hash.words;
  9486. var hl = _hl.words;
  9487. var hr = _hr.words;
  9488. var zl = _zl.words;
  9489. var zr = _zr.words;
  9490. var sl = _sl.words;
  9491. var sr = _sr.words;
  9492. // Working variables
  9493. var al, bl, cl, dl, el;
  9494. var ar, br, cr, dr, er;
  9495. ar = al = H[0];
  9496. br = bl = H[1];
  9497. cr = cl = H[2];
  9498. dr = dl = H[3];
  9499. er = el = H[4];
  9500. // Computation
  9501. var t;
  9502. for (var i = 0; i < 80; i += 1) {
  9503. t = (al + M[offset+zl[i]])|0;
  9504. if (i<16){
  9505. t += f1(bl,cl,dl) + hl[0];
  9506. } else if (i<32) {
  9507. t += f2(bl,cl,dl) + hl[1];
  9508. } else if (i<48) {
  9509. t += f3(bl,cl,dl) + hl[2];
  9510. } else if (i<64) {
  9511. t += f4(bl,cl,dl) + hl[3];
  9512. } else {// if (i<80) {
  9513. t += f5(bl,cl,dl) + hl[4];
  9514. }
  9515. t = t|0;
  9516. t = rotl(t,sl[i]);
  9517. t = (t+el)|0;
  9518. al = el;
  9519. el = dl;
  9520. dl = rotl(cl, 10);
  9521. cl = bl;
  9522. bl = t;
  9523. t = (ar + M[offset+zr[i]])|0;
  9524. if (i<16){
  9525. t += f5(br,cr,dr) + hr[0];
  9526. } else if (i<32) {
  9527. t += f4(br,cr,dr) + hr[1];
  9528. } else if (i<48) {
  9529. t += f3(br,cr,dr) + hr[2];
  9530. } else if (i<64) {
  9531. t += f2(br,cr,dr) + hr[3];
  9532. } else {// if (i<80) {
  9533. t += f1(br,cr,dr) + hr[4];
  9534. }
  9535. t = t|0;
  9536. t = rotl(t,sr[i]) ;
  9537. t = (t+er)|0;
  9538. ar = er;
  9539. er = dr;
  9540. dr = rotl(cr, 10);
  9541. cr = br;
  9542. br = t;
  9543. }
  9544. // Intermediate hash value
  9545. t = (H[1] + cl + dr)|0;
  9546. H[1] = (H[2] + dl + er)|0;
  9547. H[2] = (H[3] + el + ar)|0;
  9548. H[3] = (H[4] + al + br)|0;
  9549. H[4] = (H[0] + bl + cr)|0;
  9550. H[0] = t;
  9551. },
  9552. _doFinalize: function () {
  9553. // Shortcuts
  9554. var data = this._data;
  9555. var dataWords = data.words;
  9556. var nBitsTotal = this._nDataBytes * 8;
  9557. var nBitsLeft = data.sigBytes * 8;
  9558. // Add padding
  9559. dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32);
  9560. dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = (
  9561. (((nBitsTotal << 8) | (nBitsTotal >>> 24)) & 0x00ff00ff) |
  9562. (((nBitsTotal << 24) | (nBitsTotal >>> 8)) & 0xff00ff00)
  9563. );
  9564. data.sigBytes = (dataWords.length + 1) * 4;
  9565. // Hash final blocks
  9566. this._process();
  9567. // Shortcuts
  9568. var hash = this._hash;
  9569. var H = hash.words;
  9570. // Swap endian
  9571. for (var i = 0; i < 5; i++) {
  9572. // Shortcut
  9573. var H_i = H[i];
  9574. // Swap
  9575. H[i] = (((H_i << 8) | (H_i >>> 24)) & 0x00ff00ff) |
  9576. (((H_i << 24) | (H_i >>> 8)) & 0xff00ff00);
  9577. }
  9578. // Return final computed hash
  9579. return hash;
  9580. },
  9581. clone: function () {
  9582. var clone = Hasher.clone.call(this);
  9583. clone._hash = this._hash.clone();
  9584. return clone;
  9585. }
  9586. });
  9587. function f1(x, y, z) {
  9588. return ((x) ^ (y) ^ (z));
  9589. }
  9590. function f2(x, y, z) {
  9591. return (((x)&(y)) | ((~x)&(z)));
  9592. }
  9593. function f3(x, y, z) {
  9594. return (((x) | (~(y))) ^ (z));
  9595. }
  9596. function f4(x, y, z) {
  9597. return (((x) & (z)) | ((y)&(~(z))));
  9598. }
  9599. function f5(x, y, z) {
  9600. return ((x) ^ ((y) |(~(z))));
  9601. }
  9602. function rotl(x,n) {
  9603. return (x<<n) | (x>>>(32-n));
  9604. }
  9605. /**
  9606. * Shortcut function to the hasher's object interface.
  9607. *
  9608. * @param {WordArray|string} message The message to hash.
  9609. *
  9610. * @return {WordArray} The hash.
  9611. *
  9612. * @static
  9613. *
  9614. * @example
  9615. *
  9616. * var hash = CryptoJS.RIPEMD160('message');
  9617. * var hash = CryptoJS.RIPEMD160(wordArray);
  9618. */
  9619. C.RIPEMD160 = Hasher._createHelper(RIPEMD160);
  9620. /**
  9621. * Shortcut function to the HMAC's object interface.
  9622. *
  9623. * @param {WordArray|string} message The message to hash.
  9624. * @param {WordArray|string} key The secret key.
  9625. *
  9626. * @return {WordArray} The HMAC.
  9627. *
  9628. * @static
  9629. *
  9630. * @example
  9631. *
  9632. * var hmac = CryptoJS.HmacRIPEMD160(message, key);
  9633. */
  9634. C.HmacRIPEMD160 = Hasher._createHmacHelper(RIPEMD160);
  9635. }(Math));
  9636. return CryptoJS.RIPEMD160;
  9637. }));
  9638. },{"./core":53}],77:[function(require,module,exports){
  9639. ;(function (root, factory) {
  9640. if (typeof exports === "object") {
  9641. // CommonJS
  9642. module.exports = exports = factory(require("./core"));
  9643. }
  9644. else if (typeof define === "function" && define.amd) {
  9645. // AMD
  9646. define(["./core"], factory);
  9647. }
  9648. else {
  9649. // Global (browser)
  9650. factory(root.CryptoJS);
  9651. }
  9652. }(this, function (CryptoJS) {
  9653. (function () {
  9654. // Shortcuts
  9655. var C = CryptoJS;
  9656. var C_lib = C.lib;
  9657. var WordArray = C_lib.WordArray;
  9658. var Hasher = C_lib.Hasher;
  9659. var C_algo = C.algo;
  9660. // Reusable object
  9661. var W = [];
  9662. /**
  9663. * SHA-1 hash algorithm.
  9664. */
  9665. var SHA1 = C_algo.SHA1 = Hasher.extend({
  9666. _doReset: function () {
  9667. this._hash = new WordArray.init([
  9668. 0x67452301, 0xefcdab89,
  9669. 0x98badcfe, 0x10325476,
  9670. 0xc3d2e1f0
  9671. ]);
  9672. },
  9673. _doProcessBlock: function (M, offset) {
  9674. // Shortcut
  9675. var H = this._hash.words;
  9676. // Working variables
  9677. var a = H[0];
  9678. var b = H[1];
  9679. var c = H[2];
  9680. var d = H[3];
  9681. var e = H[4];
  9682. // Computation
  9683. for (var i = 0; i < 80; i++) {
  9684. if (i < 16) {
  9685. W[i] = M[offset + i] | 0;
  9686. } else {
  9687. var n = W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16];
  9688. W[i] = (n << 1) | (n >>> 31);
  9689. }
  9690. var t = ((a << 5) | (a >>> 27)) + e + W[i];
  9691. if (i < 20) {
  9692. t += ((b & c) | (~b & d)) + 0x5a827999;
  9693. } else if (i < 40) {
  9694. t += (b ^ c ^ d) + 0x6ed9eba1;
  9695. } else if (i < 60) {
  9696. t += ((b & c) | (b & d) | (c & d)) - 0x70e44324;
  9697. } else /* if (i < 80) */ {
  9698. t += (b ^ c ^ d) - 0x359d3e2a;
  9699. }
  9700. e = d;
  9701. d = c;
  9702. c = (b << 30) | (b >>> 2);
  9703. b = a;
  9704. a = t;
  9705. }
  9706. // Intermediate hash value
  9707. H[0] = (H[0] + a) | 0;
  9708. H[1] = (H[1] + b) | 0;
  9709. H[2] = (H[2] + c) | 0;
  9710. H[3] = (H[3] + d) | 0;
  9711. H[4] = (H[4] + e) | 0;
  9712. },
  9713. _doFinalize: function () {
  9714. // Shortcuts
  9715. var data = this._data;
  9716. var dataWords = data.words;
  9717. var nBitsTotal = this._nDataBytes * 8;
  9718. var nBitsLeft = data.sigBytes * 8;
  9719. // Add padding
  9720. dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32);
  9721. dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = Math.floor(nBitsTotal / 0x100000000);
  9722. dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = nBitsTotal;
  9723. data.sigBytes = dataWords.length * 4;
  9724. // Hash final blocks
  9725. this._process();
  9726. // Return final computed hash
  9727. return this._hash;
  9728. },
  9729. clone: function () {
  9730. var clone = Hasher.clone.call(this);
  9731. clone._hash = this._hash.clone();
  9732. return clone;
  9733. }
  9734. });
  9735. /**
  9736. * Shortcut function to the hasher's object interface.
  9737. *
  9738. * @param {WordArray|string} message The message to hash.
  9739. *
  9740. * @return {WordArray} The hash.
  9741. *
  9742. * @static
  9743. *
  9744. * @example
  9745. *
  9746. * var hash = CryptoJS.SHA1('message');
  9747. * var hash = CryptoJS.SHA1(wordArray);
  9748. */
  9749. C.SHA1 = Hasher._createHelper(SHA1);
  9750. /**
  9751. * Shortcut function to the HMAC's object interface.
  9752. *
  9753. * @param {WordArray|string} message The message to hash.
  9754. * @param {WordArray|string} key The secret key.
  9755. *
  9756. * @return {WordArray} The HMAC.
  9757. *
  9758. * @static
  9759. *
  9760. * @example
  9761. *
  9762. * var hmac = CryptoJS.HmacSHA1(message, key);
  9763. */
  9764. C.HmacSHA1 = Hasher._createHmacHelper(SHA1);
  9765. }());
  9766. return CryptoJS.SHA1;
  9767. }));
  9768. },{"./core":53}],78:[function(require,module,exports){
  9769. ;(function (root, factory, undef) {
  9770. if (typeof exports === "object") {
  9771. // CommonJS
  9772. module.exports = exports = factory(require("./core"), require("./sha256"));
  9773. }
  9774. else if (typeof define === "function" && define.amd) {
  9775. // AMD
  9776. define(["./core", "./sha256"], factory);
  9777. }
  9778. else {
  9779. // Global (browser)
  9780. factory(root.CryptoJS);
  9781. }
  9782. }(this, function (CryptoJS) {
  9783. (function () {
  9784. // Shortcuts
  9785. var C = CryptoJS;
  9786. var C_lib = C.lib;
  9787. var WordArray = C_lib.WordArray;
  9788. var C_algo = C.algo;
  9789. var SHA256 = C_algo.SHA256;
  9790. /**
  9791. * SHA-224 hash algorithm.
  9792. */
  9793. var SHA224 = C_algo.SHA224 = SHA256.extend({
  9794. _doReset: function () {
  9795. this._hash = new WordArray.init([
  9796. 0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939,
  9797. 0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4
  9798. ]);
  9799. },
  9800. _doFinalize: function () {
  9801. var hash = SHA256._doFinalize.call(this);
  9802. hash.sigBytes -= 4;
  9803. return hash;
  9804. }
  9805. });
  9806. /**
  9807. * Shortcut function to the hasher's object interface.
  9808. *
  9809. * @param {WordArray|string} message The message to hash.
  9810. *
  9811. * @return {WordArray} The hash.
  9812. *
  9813. * @static
  9814. *
  9815. * @example
  9816. *
  9817. * var hash = CryptoJS.SHA224('message');
  9818. * var hash = CryptoJS.SHA224(wordArray);
  9819. */
  9820. C.SHA224 = SHA256._createHelper(SHA224);
  9821. /**
  9822. * Shortcut function to the HMAC's object interface.
  9823. *
  9824. * @param {WordArray|string} message The message to hash.
  9825. * @param {WordArray|string} key The secret key.
  9826. *
  9827. * @return {WordArray} The HMAC.
  9828. *
  9829. * @static
  9830. *
  9831. * @example
  9832. *
  9833. * var hmac = CryptoJS.HmacSHA224(message, key);
  9834. */
  9835. C.HmacSHA224 = SHA256._createHmacHelper(SHA224);
  9836. }());
  9837. return CryptoJS.SHA224;
  9838. }));
  9839. },{"./core":53,"./sha256":79}],79:[function(require,module,exports){
  9840. ;(function (root, factory) {
  9841. if (typeof exports === "object") {
  9842. // CommonJS
  9843. module.exports = exports = factory(require("./core"));
  9844. }
  9845. else if (typeof define === "function" && define.amd) {
  9846. // AMD
  9847. define(["./core"], factory);
  9848. }
  9849. else {
  9850. // Global (browser)
  9851. factory(root.CryptoJS);
  9852. }
  9853. }(this, function (CryptoJS) {
  9854. (function (Math) {
  9855. // Shortcuts
  9856. var C = CryptoJS;
  9857. var C_lib = C.lib;
  9858. var WordArray = C_lib.WordArray;
  9859. var Hasher = C_lib.Hasher;
  9860. var C_algo = C.algo;
  9861. // Initialization and round constants tables
  9862. var H = [];
  9863. var K = [];
  9864. // Compute constants
  9865. (function () {
  9866. function isPrime(n) {
  9867. var sqrtN = Math.sqrt(n);
  9868. for (var factor = 2; factor <= sqrtN; factor++) {
  9869. if (!(n % factor)) {
  9870. return false;
  9871. }
  9872. }
  9873. return true;
  9874. }
  9875. function getFractionalBits(n) {
  9876. return ((n - (n | 0)) * 0x100000000) | 0;
  9877. }
  9878. var n = 2;
  9879. var nPrime = 0;
  9880. while (nPrime < 64) {
  9881. if (isPrime(n)) {
  9882. if (nPrime < 8) {
  9883. H[nPrime] = getFractionalBits(Math.pow(n, 1 / 2));
  9884. }
  9885. K[nPrime] = getFractionalBits(Math.pow(n, 1 / 3));
  9886. nPrime++;
  9887. }
  9888. n++;
  9889. }
  9890. }());
  9891. // Reusable object
  9892. var W = [];
  9893. /**
  9894. * SHA-256 hash algorithm.
  9895. */
  9896. var SHA256 = C_algo.SHA256 = Hasher.extend({
  9897. _doReset: function () {
  9898. this._hash = new WordArray.init(H.slice(0));
  9899. },
  9900. _doProcessBlock: function (M, offset) {
  9901. // Shortcut
  9902. var H = this._hash.words;
  9903. // Working variables
  9904. var a = H[0];
  9905. var b = H[1];
  9906. var c = H[2];
  9907. var d = H[3];
  9908. var e = H[4];
  9909. var f = H[5];
  9910. var g = H[6];
  9911. var h = H[7];
  9912. // Computation
  9913. for (var i = 0; i < 64; i++) {
  9914. if (i < 16) {
  9915. W[i] = M[offset + i] | 0;
  9916. } else {
  9917. var gamma0x = W[i - 15];
  9918. var gamma0 = ((gamma0x << 25) | (gamma0x >>> 7)) ^
  9919. ((gamma0x << 14) | (gamma0x >>> 18)) ^
  9920. (gamma0x >>> 3);
  9921. var gamma1x = W[i - 2];
  9922. var gamma1 = ((gamma1x << 15) | (gamma1x >>> 17)) ^
  9923. ((gamma1x << 13) | (gamma1x >>> 19)) ^
  9924. (gamma1x >>> 10);
  9925. W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16];
  9926. }
  9927. var ch = (e & f) ^ (~e & g);
  9928. var maj = (a & b) ^ (a & c) ^ (b & c);
  9929. var sigma0 = ((a << 30) | (a >>> 2)) ^ ((a << 19) | (a >>> 13)) ^ ((a << 10) | (a >>> 22));
  9930. var sigma1 = ((e << 26) | (e >>> 6)) ^ ((e << 21) | (e >>> 11)) ^ ((e << 7) | (e >>> 25));
  9931. var t1 = h + sigma1 + ch + K[i] + W[i];
  9932. var t2 = sigma0 + maj;
  9933. h = g;
  9934. g = f;
  9935. f = e;
  9936. e = (d + t1) | 0;
  9937. d = c;
  9938. c = b;
  9939. b = a;
  9940. a = (t1 + t2) | 0;
  9941. }
  9942. // Intermediate hash value
  9943. H[0] = (H[0] + a) | 0;
  9944. H[1] = (H[1] + b) | 0;
  9945. H[2] = (H[2] + c) | 0;
  9946. H[3] = (H[3] + d) | 0;
  9947. H[4] = (H[4] + e) | 0;
  9948. H[5] = (H[5] + f) | 0;
  9949. H[6] = (H[6] + g) | 0;
  9950. H[7] = (H[7] + h) | 0;
  9951. },
  9952. _doFinalize: function () {
  9953. // Shortcuts
  9954. var data = this._data;
  9955. var dataWords = data.words;
  9956. var nBitsTotal = this._nDataBytes * 8;
  9957. var nBitsLeft = data.sigBytes * 8;
  9958. // Add padding
  9959. dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32);
  9960. dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = Math.floor(nBitsTotal / 0x100000000);
  9961. dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = nBitsTotal;
  9962. data.sigBytes = dataWords.length * 4;
  9963. // Hash final blocks
  9964. this._process();
  9965. // Return final computed hash
  9966. return this._hash;
  9967. },
  9968. clone: function () {
  9969. var clone = Hasher.clone.call(this);
  9970. clone._hash = this._hash.clone();
  9971. return clone;
  9972. }
  9973. });
  9974. /**
  9975. * Shortcut function to the hasher's object interface.
  9976. *
  9977. * @param {WordArray|string} message The message to hash.
  9978. *
  9979. * @return {WordArray} The hash.
  9980. *
  9981. * @static
  9982. *
  9983. * @example
  9984. *
  9985. * var hash = CryptoJS.SHA256('message');
  9986. * var hash = CryptoJS.SHA256(wordArray);
  9987. */
  9988. C.SHA256 = Hasher._createHelper(SHA256);
  9989. /**
  9990. * Shortcut function to the HMAC's object interface.
  9991. *
  9992. * @param {WordArray|string} message The message to hash.
  9993. * @param {WordArray|string} key The secret key.
  9994. *
  9995. * @return {WordArray} The HMAC.
  9996. *
  9997. * @static
  9998. *
  9999. * @example
  10000. *
  10001. * var hmac = CryptoJS.HmacSHA256(message, key);
  10002. */
  10003. C.HmacSHA256 = Hasher._createHmacHelper(SHA256);
  10004. }(Math));
  10005. return CryptoJS.SHA256;
  10006. }));
  10007. },{"./core":53}],80:[function(require,module,exports){
  10008. ;(function (root, factory, undef) {
  10009. if (typeof exports === "object") {
  10010. // CommonJS
  10011. module.exports = exports = factory(require("./core"), require("./x64-core"));
  10012. }
  10013. else if (typeof define === "function" && define.amd) {
  10014. // AMD
  10015. define(["./core", "./x64-core"], factory);
  10016. }
  10017. else {
  10018. // Global (browser)
  10019. factory(root.CryptoJS);
  10020. }
  10021. }(this, function (CryptoJS) {
  10022. (function (Math) {
  10023. // Shortcuts
  10024. var C = CryptoJS;
  10025. var C_lib = C.lib;
  10026. var WordArray = C_lib.WordArray;
  10027. var Hasher = C_lib.Hasher;
  10028. var C_x64 = C.x64;
  10029. var X64Word = C_x64.Word;
  10030. var C_algo = C.algo;
  10031. // Constants tables
  10032. var RHO_OFFSETS = [];
  10033. var PI_INDEXES = [];
  10034. var ROUND_CONSTANTS = [];
  10035. // Compute Constants
  10036. (function () {
  10037. // Compute rho offset constants
  10038. var x = 1, y = 0;
  10039. for (var t = 0; t < 24; t++) {
  10040. RHO_OFFSETS[x + 5 * y] = ((t + 1) * (t + 2) / 2) % 64;
  10041. var newX = y % 5;
  10042. var newY = (2 * x + 3 * y) % 5;
  10043. x = newX;
  10044. y = newY;
  10045. }
  10046. // Compute pi index constants
  10047. for (var x = 0; x < 5; x++) {
  10048. for (var y = 0; y < 5; y++) {
  10049. PI_INDEXES[x + 5 * y] = y + ((2 * x + 3 * y) % 5) * 5;
  10050. }
  10051. }
  10052. // Compute round constants
  10053. var LFSR = 0x01;
  10054. for (var i = 0; i < 24; i++) {
  10055. var roundConstantMsw = 0;
  10056. var roundConstantLsw = 0;
  10057. for (var j = 0; j < 7; j++) {
  10058. if (LFSR & 0x01) {
  10059. var bitPosition = (1 << j) - 1;
  10060. if (bitPosition < 32) {
  10061. roundConstantLsw ^= 1 << bitPosition;
  10062. } else /* if (bitPosition >= 32) */ {
  10063. roundConstantMsw ^= 1 << (bitPosition - 32);
  10064. }
  10065. }
  10066. // Compute next LFSR
  10067. if (LFSR & 0x80) {
  10068. // Primitive polynomial over GF(2): x^8 + x^6 + x^5 + x^4 + 1
  10069. LFSR = (LFSR << 1) ^ 0x71;
  10070. } else {
  10071. LFSR <<= 1;
  10072. }
  10073. }
  10074. ROUND_CONSTANTS[i] = X64Word.create(roundConstantMsw, roundConstantLsw);
  10075. }
  10076. }());
  10077. // Reusable objects for temporary values
  10078. var T = [];
  10079. (function () {
  10080. for (var i = 0; i < 25; i++) {
  10081. T[i] = X64Word.create();
  10082. }
  10083. }());
  10084. /**
  10085. * SHA-3 hash algorithm.
  10086. */
  10087. var SHA3 = C_algo.SHA3 = Hasher.extend({
  10088. /**
  10089. * Configuration options.
  10090. *
  10091. * @property {number} outputLength
  10092. * The desired number of bits in the output hash.
  10093. * Only values permitted are: 224, 256, 384, 512.
  10094. * Default: 512
  10095. */
  10096. cfg: Hasher.cfg.extend({
  10097. outputLength: 512
  10098. }),
  10099. _doReset: function () {
  10100. var state = this._state = []
  10101. for (var i = 0; i < 25; i++) {
  10102. state[i] = new X64Word.init();
  10103. }
  10104. this.blockSize = (1600 - 2 * this.cfg.outputLength) / 32;
  10105. },
  10106. _doProcessBlock: function (M, offset) {
  10107. // Shortcuts
  10108. var state = this._state;
  10109. var nBlockSizeLanes = this.blockSize / 2;
  10110. // Absorb
  10111. for (var i = 0; i < nBlockSizeLanes; i++) {
  10112. // Shortcuts
  10113. var M2i = M[offset + 2 * i];
  10114. var M2i1 = M[offset + 2 * i + 1];
  10115. // Swap endian
  10116. M2i = (
  10117. (((M2i << 8) | (M2i >>> 24)) & 0x00ff00ff) |
  10118. (((M2i << 24) | (M2i >>> 8)) & 0xff00ff00)
  10119. );
  10120. M2i1 = (
  10121. (((M2i1 << 8) | (M2i1 >>> 24)) & 0x00ff00ff) |
  10122. (((M2i1 << 24) | (M2i1 >>> 8)) & 0xff00ff00)
  10123. );
  10124. // Absorb message into state
  10125. var lane = state[i];
  10126. lane.high ^= M2i1;
  10127. lane.low ^= M2i;
  10128. }
  10129. // Rounds
  10130. for (var round = 0; round < 24; round++) {
  10131. // Theta
  10132. for (var x = 0; x < 5; x++) {
  10133. // Mix column lanes
  10134. var tMsw = 0, tLsw = 0;
  10135. for (var y = 0; y < 5; y++) {
  10136. var lane = state[x + 5 * y];
  10137. tMsw ^= lane.high;
  10138. tLsw ^= lane.low;
  10139. }
  10140. // Temporary values
  10141. var Tx = T[x];
  10142. Tx.high = tMsw;
  10143. Tx.low = tLsw;
  10144. }
  10145. for (var x = 0; x < 5; x++) {
  10146. // Shortcuts
  10147. var Tx4 = T[(x + 4) % 5];
  10148. var Tx1 = T[(x + 1) % 5];
  10149. var Tx1Msw = Tx1.high;
  10150. var Tx1Lsw = Tx1.low;
  10151. // Mix surrounding columns
  10152. var tMsw = Tx4.high ^ ((Tx1Msw << 1) | (Tx1Lsw >>> 31));
  10153. var tLsw = Tx4.low ^ ((Tx1Lsw << 1) | (Tx1Msw >>> 31));
  10154. for (var y = 0; y < 5; y++) {
  10155. var lane = state[x + 5 * y];
  10156. lane.high ^= tMsw;
  10157. lane.low ^= tLsw;
  10158. }
  10159. }
  10160. // Rho Pi
  10161. for (var laneIndex = 1; laneIndex < 25; laneIndex++) {
  10162. // Shortcuts
  10163. var lane = state[laneIndex];
  10164. var laneMsw = lane.high;
  10165. var laneLsw = lane.low;
  10166. var rhoOffset = RHO_OFFSETS[laneIndex];
  10167. // Rotate lanes
  10168. if (rhoOffset < 32) {
  10169. var tMsw = (laneMsw << rhoOffset) | (laneLsw >>> (32 - rhoOffset));
  10170. var tLsw = (laneLsw << rhoOffset) | (laneMsw >>> (32 - rhoOffset));
  10171. } else /* if (rhoOffset >= 32) */ {
  10172. var tMsw = (laneLsw << (rhoOffset - 32)) | (laneMsw >>> (64 - rhoOffset));
  10173. var tLsw = (laneMsw << (rhoOffset - 32)) | (laneLsw >>> (64 - rhoOffset));
  10174. }
  10175. // Transpose lanes
  10176. var TPiLane = T[PI_INDEXES[laneIndex]];
  10177. TPiLane.high = tMsw;
  10178. TPiLane.low = tLsw;
  10179. }
  10180. // Rho pi at x = y = 0
  10181. var T0 = T[0];
  10182. var state0 = state[0];
  10183. T0.high = state0.high;
  10184. T0.low = state0.low;
  10185. // Chi
  10186. for (var x = 0; x < 5; x++) {
  10187. for (var y = 0; y < 5; y++) {
  10188. // Shortcuts
  10189. var laneIndex = x + 5 * y;
  10190. var lane = state[laneIndex];
  10191. var TLane = T[laneIndex];
  10192. var Tx1Lane = T[((x + 1) % 5) + 5 * y];
  10193. var Tx2Lane = T[((x + 2) % 5) + 5 * y];
  10194. // Mix rows
  10195. lane.high = TLane.high ^ (~Tx1Lane.high & Tx2Lane.high);
  10196. lane.low = TLane.low ^ (~Tx1Lane.low & Tx2Lane.low);
  10197. }
  10198. }
  10199. // Iota
  10200. var lane = state[0];
  10201. var roundConstant = ROUND_CONSTANTS[round];
  10202. lane.high ^= roundConstant.high;
  10203. lane.low ^= roundConstant.low;;
  10204. }
  10205. },
  10206. _doFinalize: function () {
  10207. // Shortcuts
  10208. var data = this._data;
  10209. var dataWords = data.words;
  10210. var nBitsTotal = this._nDataBytes * 8;
  10211. var nBitsLeft = data.sigBytes * 8;
  10212. var blockSizeBits = this.blockSize * 32;
  10213. // Add padding
  10214. dataWords[nBitsLeft >>> 5] |= 0x1 << (24 - nBitsLeft % 32);
  10215. dataWords[((Math.ceil((nBitsLeft + 1) / blockSizeBits) * blockSizeBits) >>> 5) - 1] |= 0x80;
  10216. data.sigBytes = dataWords.length * 4;
  10217. // Hash final blocks
  10218. this._process();
  10219. // Shortcuts
  10220. var state = this._state;
  10221. var outputLengthBytes = this.cfg.outputLength / 8;
  10222. var outputLengthLanes = outputLengthBytes / 8;
  10223. // Squeeze
  10224. var hashWords = [];
  10225. for (var i = 0; i < outputLengthLanes; i++) {
  10226. // Shortcuts
  10227. var lane = state[i];
  10228. var laneMsw = lane.high;
  10229. var laneLsw = lane.low;
  10230. // Swap endian
  10231. laneMsw = (
  10232. (((laneMsw << 8) | (laneMsw >>> 24)) & 0x00ff00ff) |
  10233. (((laneMsw << 24) | (laneMsw >>> 8)) & 0xff00ff00)
  10234. );
  10235. laneLsw = (
  10236. (((laneLsw << 8) | (laneLsw >>> 24)) & 0x00ff00ff) |
  10237. (((laneLsw << 24) | (laneLsw >>> 8)) & 0xff00ff00)
  10238. );
  10239. // Squeeze state to retrieve hash
  10240. hashWords.push(laneLsw);
  10241. hashWords.push(laneMsw);
  10242. }
  10243. // Return final computed hash
  10244. return new WordArray.init(hashWords, outputLengthBytes);
  10245. },
  10246. clone: function () {
  10247. var clone = Hasher.clone.call(this);
  10248. var state = clone._state = this._state.slice(0);
  10249. for (var i = 0; i < 25; i++) {
  10250. state[i] = state[i].clone();
  10251. }
  10252. return clone;
  10253. }
  10254. });
  10255. /**
  10256. * Shortcut function to the hasher's object interface.
  10257. *
  10258. * @param {WordArray|string} message The message to hash.
  10259. *
  10260. * @return {WordArray} The hash.
  10261. *
  10262. * @static
  10263. *
  10264. * @example
  10265. *
  10266. * var hash = CryptoJS.SHA3('message');
  10267. * var hash = CryptoJS.SHA3(wordArray);
  10268. */
  10269. C.SHA3 = Hasher._createHelper(SHA3);
  10270. /**
  10271. * Shortcut function to the HMAC's object interface.
  10272. *
  10273. * @param {WordArray|string} message The message to hash.
  10274. * @param {WordArray|string} key The secret key.
  10275. *
  10276. * @return {WordArray} The HMAC.
  10277. *
  10278. * @static
  10279. *
  10280. * @example
  10281. *
  10282. * var hmac = CryptoJS.HmacSHA3(message, key);
  10283. */
  10284. C.HmacSHA3 = Hasher._createHmacHelper(SHA3);
  10285. }(Math));
  10286. return CryptoJS.SHA3;
  10287. }));
  10288. },{"./core":53,"./x64-core":84}],81:[function(require,module,exports){
  10289. ;(function (root, factory, undef) {
  10290. if (typeof exports === "object") {
  10291. // CommonJS
  10292. module.exports = exports = factory(require("./core"), require("./x64-core"), require("./sha512"));
  10293. }
  10294. else if (typeof define === "function" && define.amd) {
  10295. // AMD
  10296. define(["./core", "./x64-core", "./sha512"], factory);
  10297. }
  10298. else {
  10299. // Global (browser)
  10300. factory(root.CryptoJS);
  10301. }
  10302. }(this, function (CryptoJS) {
  10303. (function () {
  10304. // Shortcuts
  10305. var C = CryptoJS;
  10306. var C_x64 = C.x64;
  10307. var X64Word = C_x64.Word;
  10308. var X64WordArray = C_x64.WordArray;
  10309. var C_algo = C.algo;
  10310. var SHA512 = C_algo.SHA512;
  10311. /**
  10312. * SHA-384 hash algorithm.
  10313. */
  10314. var SHA384 = C_algo.SHA384 = SHA512.extend({
  10315. _doReset: function () {
  10316. this._hash = new X64WordArray.init([
  10317. new X64Word.init(0xcbbb9d5d, 0xc1059ed8), new X64Word.init(0x629a292a, 0x367cd507),
  10318. new X64Word.init(0x9159015a, 0x3070dd17), new X64Word.init(0x152fecd8, 0xf70e5939),
  10319. new X64Word.init(0x67332667, 0xffc00b31), new X64Word.init(0x8eb44a87, 0x68581511),
  10320. new X64Word.init(0xdb0c2e0d, 0x64f98fa7), new X64Word.init(0x47b5481d, 0xbefa4fa4)
  10321. ]);
  10322. },
  10323. _doFinalize: function () {
  10324. var hash = SHA512._doFinalize.call(this);
  10325. hash.sigBytes -= 16;
  10326. return hash;
  10327. }
  10328. });
  10329. /**
  10330. * Shortcut function to the hasher's object interface.
  10331. *
  10332. * @param {WordArray|string} message The message to hash.
  10333. *
  10334. * @return {WordArray} The hash.
  10335. *
  10336. * @static
  10337. *
  10338. * @example
  10339. *
  10340. * var hash = CryptoJS.SHA384('message');
  10341. * var hash = CryptoJS.SHA384(wordArray);
  10342. */
  10343. C.SHA384 = SHA512._createHelper(SHA384);
  10344. /**
  10345. * Shortcut function to the HMAC's object interface.
  10346. *
  10347. * @param {WordArray|string} message The message to hash.
  10348. * @param {WordArray|string} key The secret key.
  10349. *
  10350. * @return {WordArray} The HMAC.
  10351. *
  10352. * @static
  10353. *
  10354. * @example
  10355. *
  10356. * var hmac = CryptoJS.HmacSHA384(message, key);
  10357. */
  10358. C.HmacSHA384 = SHA512._createHmacHelper(SHA384);
  10359. }());
  10360. return CryptoJS.SHA384;
  10361. }));
  10362. },{"./core":53,"./sha512":82,"./x64-core":84}],82:[function(require,module,exports){
  10363. ;(function (root, factory, undef) {
  10364. if (typeof exports === "object") {
  10365. // CommonJS
  10366. module.exports = exports = factory(require("./core"), require("./x64-core"));
  10367. }
  10368. else if (typeof define === "function" && define.amd) {
  10369. // AMD
  10370. define(["./core", "./x64-core"], factory);
  10371. }
  10372. else {
  10373. // Global (browser)
  10374. factory(root.CryptoJS);
  10375. }
  10376. }(this, function (CryptoJS) {
  10377. (function () {
  10378. // Shortcuts
  10379. var C = CryptoJS;
  10380. var C_lib = C.lib;
  10381. var Hasher = C_lib.Hasher;
  10382. var C_x64 = C.x64;
  10383. var X64Word = C_x64.Word;
  10384. var X64WordArray = C_x64.WordArray;
  10385. var C_algo = C.algo;
  10386. function X64Word_create() {
  10387. return X64Word.create.apply(X64Word, arguments);
  10388. }
  10389. // Constants
  10390. var K = [
  10391. X64Word_create(0x428a2f98, 0xd728ae22), X64Word_create(0x71374491, 0x23ef65cd),
  10392. X64Word_create(0xb5c0fbcf, 0xec4d3b2f), X64Word_create(0xe9b5dba5, 0x8189dbbc),
  10393. X64Word_create(0x3956c25b, 0xf348b538), X64Word_create(0x59f111f1, 0xb605d019),
  10394. X64Word_create(0x923f82a4, 0xaf194f9b), X64Word_create(0xab1c5ed5, 0xda6d8118),
  10395. X64Word_create(0xd807aa98, 0xa3030242), X64Word_create(0x12835b01, 0x45706fbe),
  10396. X64Word_create(0x243185be, 0x4ee4b28c), X64Word_create(0x550c7dc3, 0xd5ffb4e2),
  10397. X64Word_create(0x72be5d74, 0xf27b896f), X64Word_create(0x80deb1fe, 0x3b1696b1),
  10398. X64Word_create(0x9bdc06a7, 0x25c71235), X64Word_create(0xc19bf174, 0xcf692694),
  10399. X64Word_create(0xe49b69c1, 0x9ef14ad2), X64Word_create(0xefbe4786, 0x384f25e3),
  10400. X64Word_create(0x0fc19dc6, 0x8b8cd5b5), X64Word_create(0x240ca1cc, 0x77ac9c65),
  10401. X64Word_create(0x2de92c6f, 0x592b0275), X64Word_create(0x4a7484aa, 0x6ea6e483),
  10402. X64Word_create(0x5cb0a9dc, 0xbd41fbd4), X64Word_create(0x76f988da, 0x831153b5),
  10403. X64Word_create(0x983e5152, 0xee66dfab), X64Word_create(0xa831c66d, 0x2db43210),
  10404. X64Word_create(0xb00327c8, 0x98fb213f), X64Word_create(0xbf597fc7, 0xbeef0ee4),
  10405. X64Word_create(0xc6e00bf3, 0x3da88fc2), X64Word_create(0xd5a79147, 0x930aa725),
  10406. X64Word_create(0x06ca6351, 0xe003826f), X64Word_create(0x14292967, 0x0a0e6e70),
  10407. X64Word_create(0x27b70a85, 0x46d22ffc), X64Word_create(0x2e1b2138, 0x5c26c926),
  10408. X64Word_create(0x4d2c6dfc, 0x5ac42aed), X64Word_create(0x53380d13, 0x9d95b3df),
  10409. X64Word_create(0x650a7354, 0x8baf63de), X64Word_create(0x766a0abb, 0x3c77b2a8),
  10410. X64Word_create(0x81c2c92e, 0x47edaee6), X64Word_create(0x92722c85, 0x1482353b),
  10411. X64Word_create(0xa2bfe8a1, 0x4cf10364), X64Word_create(0xa81a664b, 0xbc423001),
  10412. X64Word_create(0xc24b8b70, 0xd0f89791), X64Word_create(0xc76c51a3, 0x0654be30),
  10413. X64Word_create(0xd192e819, 0xd6ef5218), X64Word_create(0xd6990624, 0x5565a910),
  10414. X64Word_create(0xf40e3585, 0x5771202a), X64Word_create(0x106aa070, 0x32bbd1b8),
  10415. X64Word_create(0x19a4c116, 0xb8d2d0c8), X64Word_create(0x1e376c08, 0x5141ab53),
  10416. X64Word_create(0x2748774c, 0xdf8eeb99), X64Word_create(0x34b0bcb5, 0xe19b48a8),
  10417. X64Word_create(0x391c0cb3, 0xc5c95a63), X64Word_create(0x4ed8aa4a, 0xe3418acb),
  10418. X64Word_create(0x5b9cca4f, 0x7763e373), X64Word_create(0x682e6ff3, 0xd6b2b8a3),
  10419. X64Word_create(0x748f82ee, 0x5defb2fc), X64Word_create(0x78a5636f, 0x43172f60),
  10420. X64Word_create(0x84c87814, 0xa1f0ab72), X64Word_create(0x8cc70208, 0x1a6439ec),
  10421. X64Word_create(0x90befffa, 0x23631e28), X64Word_create(0xa4506ceb, 0xde82bde9),
  10422. X64Word_create(0xbef9a3f7, 0xb2c67915), X64Word_create(0xc67178f2, 0xe372532b),
  10423. X64Word_create(0xca273ece, 0xea26619c), X64Word_create(0xd186b8c7, 0x21c0c207),
  10424. X64Word_create(0xeada7dd6, 0xcde0eb1e), X64Word_create(0xf57d4f7f, 0xee6ed178),
  10425. X64Word_create(0x06f067aa, 0x72176fba), X64Word_create(0x0a637dc5, 0xa2c898a6),
  10426. X64Word_create(0x113f9804, 0xbef90dae), X64Word_create(0x1b710b35, 0x131c471b),
  10427. X64Word_create(0x28db77f5, 0x23047d84), X64Word_create(0x32caab7b, 0x40c72493),
  10428. X64Word_create(0x3c9ebe0a, 0x15c9bebc), X64Word_create(0x431d67c4, 0x9c100d4c),
  10429. X64Word_create(0x4cc5d4be, 0xcb3e42b6), X64Word_create(0x597f299c, 0xfc657e2a),
  10430. X64Word_create(0x5fcb6fab, 0x3ad6faec), X64Word_create(0x6c44198c, 0x4a475817)
  10431. ];
  10432. // Reusable objects
  10433. var W = [];
  10434. (function () {
  10435. for (var i = 0; i < 80; i++) {
  10436. W[i] = X64Word_create();
  10437. }
  10438. }());
  10439. /**
  10440. * SHA-512 hash algorithm.
  10441. */
  10442. var SHA512 = C_algo.SHA512 = Hasher.extend({
  10443. _doReset: function () {
  10444. this._hash = new X64WordArray.init([
  10445. new X64Word.init(0x6a09e667, 0xf3bcc908), new X64Word.init(0xbb67ae85, 0x84caa73b),
  10446. new X64Word.init(0x3c6ef372, 0xfe94f82b), new X64Word.init(0xa54ff53a, 0x5f1d36f1),
  10447. new X64Word.init(0x510e527f, 0xade682d1), new X64Word.init(0x9b05688c, 0x2b3e6c1f),
  10448. new X64Word.init(0x1f83d9ab, 0xfb41bd6b), new X64Word.init(0x5be0cd19, 0x137e2179)
  10449. ]);
  10450. },
  10451. _doProcessBlock: function (M, offset) {
  10452. // Shortcuts
  10453. var H = this._hash.words;
  10454. var H0 = H[0];
  10455. var H1 = H[1];
  10456. var H2 = H[2];
  10457. var H3 = H[3];
  10458. var H4 = H[4];
  10459. var H5 = H[5];
  10460. var H6 = H[6];
  10461. var H7 = H[7];
  10462. var H0h = H0.high;
  10463. var H0l = H0.low;
  10464. var H1h = H1.high;
  10465. var H1l = H1.low;
  10466. var H2h = H2.high;
  10467. var H2l = H2.low;
  10468. var H3h = H3.high;
  10469. var H3l = H3.low;
  10470. var H4h = H4.high;
  10471. var H4l = H4.low;
  10472. var H5h = H5.high;
  10473. var H5l = H5.low;
  10474. var H6h = H6.high;
  10475. var H6l = H6.low;
  10476. var H7h = H7.high;
  10477. var H7l = H7.low;
  10478. // Working variables
  10479. var ah = H0h;
  10480. var al = H0l;
  10481. var bh = H1h;
  10482. var bl = H1l;
  10483. var ch = H2h;
  10484. var cl = H2l;
  10485. var dh = H3h;
  10486. var dl = H3l;
  10487. var eh = H4h;
  10488. var el = H4l;
  10489. var fh = H5h;
  10490. var fl = H5l;
  10491. var gh = H6h;
  10492. var gl = H6l;
  10493. var hh = H7h;
  10494. var hl = H7l;
  10495. // Rounds
  10496. for (var i = 0; i < 80; i++) {
  10497. // Shortcut
  10498. var Wi = W[i];
  10499. // Extend message
  10500. if (i < 16) {
  10501. var Wih = Wi.high = M[offset + i * 2] | 0;
  10502. var Wil = Wi.low = M[offset + i * 2 + 1] | 0;
  10503. } else {
  10504. // Gamma0
  10505. var gamma0x = W[i - 15];
  10506. var gamma0xh = gamma0x.high;
  10507. var gamma0xl = gamma0x.low;
  10508. var gamma0h = ((gamma0xh >>> 1) | (gamma0xl << 31)) ^ ((gamma0xh >>> 8) | (gamma0xl << 24)) ^ (gamma0xh >>> 7);
  10509. var gamma0l = ((gamma0xl >>> 1) | (gamma0xh << 31)) ^ ((gamma0xl >>> 8) | (gamma0xh << 24)) ^ ((gamma0xl >>> 7) | (gamma0xh << 25));
  10510. // Gamma1
  10511. var gamma1x = W[i - 2];
  10512. var gamma1xh = gamma1x.high;
  10513. var gamma1xl = gamma1x.low;
  10514. var gamma1h = ((gamma1xh >>> 19) | (gamma1xl << 13)) ^ ((gamma1xh << 3) | (gamma1xl >>> 29)) ^ (gamma1xh >>> 6);
  10515. var gamma1l = ((gamma1xl >>> 19) | (gamma1xh << 13)) ^ ((gamma1xl << 3) | (gamma1xh >>> 29)) ^ ((gamma1xl >>> 6) | (gamma1xh << 26));
  10516. // W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16]
  10517. var Wi7 = W[i - 7];
  10518. var Wi7h = Wi7.high;
  10519. var Wi7l = Wi7.low;
  10520. var Wi16 = W[i - 16];
  10521. var Wi16h = Wi16.high;
  10522. var Wi16l = Wi16.low;
  10523. var Wil = gamma0l + Wi7l;
  10524. var Wih = gamma0h + Wi7h + ((Wil >>> 0) < (gamma0l >>> 0) ? 1 : 0);
  10525. var Wil = Wil + gamma1l;
  10526. var Wih = Wih + gamma1h + ((Wil >>> 0) < (gamma1l >>> 0) ? 1 : 0);
  10527. var Wil = Wil + Wi16l;
  10528. var Wih = Wih + Wi16h + ((Wil >>> 0) < (Wi16l >>> 0) ? 1 : 0);
  10529. Wi.high = Wih;
  10530. Wi.low = Wil;
  10531. }
  10532. var chh = (eh & fh) ^ (~eh & gh);
  10533. var chl = (el & fl) ^ (~el & gl);
  10534. var majh = (ah & bh) ^ (ah & ch) ^ (bh & ch);
  10535. var majl = (al & bl) ^ (al & cl) ^ (bl & cl);
  10536. var sigma0h = ((ah >>> 28) | (al << 4)) ^ ((ah << 30) | (al >>> 2)) ^ ((ah << 25) | (al >>> 7));
  10537. var sigma0l = ((al >>> 28) | (ah << 4)) ^ ((al << 30) | (ah >>> 2)) ^ ((al << 25) | (ah >>> 7));
  10538. var sigma1h = ((eh >>> 14) | (el << 18)) ^ ((eh >>> 18) | (el << 14)) ^ ((eh << 23) | (el >>> 9));
  10539. var sigma1l = ((el >>> 14) | (eh << 18)) ^ ((el >>> 18) | (eh << 14)) ^ ((el << 23) | (eh >>> 9));
  10540. // t1 = h + sigma1 + ch + K[i] + W[i]
  10541. var Ki = K[i];
  10542. var Kih = Ki.high;
  10543. var Kil = Ki.low;
  10544. var t1l = hl + sigma1l;
  10545. var t1h = hh + sigma1h + ((t1l >>> 0) < (hl >>> 0) ? 1 : 0);
  10546. var t1l = t1l + chl;
  10547. var t1h = t1h + chh + ((t1l >>> 0) < (chl >>> 0) ? 1 : 0);
  10548. var t1l = t1l + Kil;
  10549. var t1h = t1h + Kih + ((t1l >>> 0) < (Kil >>> 0) ? 1 : 0);
  10550. var t1l = t1l + Wil;
  10551. var t1h = t1h + Wih + ((t1l >>> 0) < (Wil >>> 0) ? 1 : 0);
  10552. // t2 = sigma0 + maj
  10553. var t2l = sigma0l + majl;
  10554. var t2h = sigma0h + majh + ((t2l >>> 0) < (sigma0l >>> 0) ? 1 : 0);
  10555. // Update working variables
  10556. hh = gh;
  10557. hl = gl;
  10558. gh = fh;
  10559. gl = fl;
  10560. fh = eh;
  10561. fl = el;
  10562. el = (dl + t1l) | 0;
  10563. eh = (dh + t1h + ((el >>> 0) < (dl >>> 0) ? 1 : 0)) | 0;
  10564. dh = ch;
  10565. dl = cl;
  10566. ch = bh;
  10567. cl = bl;
  10568. bh = ah;
  10569. bl = al;
  10570. al = (t1l + t2l) | 0;
  10571. ah = (t1h + t2h + ((al >>> 0) < (t1l >>> 0) ? 1 : 0)) | 0;
  10572. }
  10573. // Intermediate hash value
  10574. H0l = H0.low = (H0l + al);
  10575. H0.high = (H0h + ah + ((H0l >>> 0) < (al >>> 0) ? 1 : 0));
  10576. H1l = H1.low = (H1l + bl);
  10577. H1.high = (H1h + bh + ((H1l >>> 0) < (bl >>> 0) ? 1 : 0));
  10578. H2l = H2.low = (H2l + cl);
  10579. H2.high = (H2h + ch + ((H2l >>> 0) < (cl >>> 0) ? 1 : 0));
  10580. H3l = H3.low = (H3l + dl);
  10581. H3.high = (H3h + dh + ((H3l >>> 0) < (dl >>> 0) ? 1 : 0));
  10582. H4l = H4.low = (H4l + el);
  10583. H4.high = (H4h + eh + ((H4l >>> 0) < (el >>> 0) ? 1 : 0));
  10584. H5l = H5.low = (H5l + fl);
  10585. H5.high = (H5h + fh + ((H5l >>> 0) < (fl >>> 0) ? 1 : 0));
  10586. H6l = H6.low = (H6l + gl);
  10587. H6.high = (H6h + gh + ((H6l >>> 0) < (gl >>> 0) ? 1 : 0));
  10588. H7l = H7.low = (H7l + hl);
  10589. H7.high = (H7h + hh + ((H7l >>> 0) < (hl >>> 0) ? 1 : 0));
  10590. },
  10591. _doFinalize: function () {
  10592. // Shortcuts
  10593. var data = this._data;
  10594. var dataWords = data.words;
  10595. var nBitsTotal = this._nDataBytes * 8;
  10596. var nBitsLeft = data.sigBytes * 8;
  10597. // Add padding
  10598. dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32);
  10599. dataWords[(((nBitsLeft + 128) >>> 10) << 5) + 30] = Math.floor(nBitsTotal / 0x100000000);
  10600. dataWords[(((nBitsLeft + 128) >>> 10) << 5) + 31] = nBitsTotal;
  10601. data.sigBytes = dataWords.length * 4;
  10602. // Hash final blocks
  10603. this._process();
  10604. // Convert hash to 32-bit word array before returning
  10605. var hash = this._hash.toX32();
  10606. // Return final computed hash
  10607. return hash;
  10608. },
  10609. clone: function () {
  10610. var clone = Hasher.clone.call(this);
  10611. clone._hash = this._hash.clone();
  10612. return clone;
  10613. },
  10614. blockSize: 1024/32
  10615. });
  10616. /**
  10617. * Shortcut function to the hasher's object interface.
  10618. *
  10619. * @param {WordArray|string} message The message to hash.
  10620. *
  10621. * @return {WordArray} The hash.
  10622. *
  10623. * @static
  10624. *
  10625. * @example
  10626. *
  10627. * var hash = CryptoJS.SHA512('message');
  10628. * var hash = CryptoJS.SHA512(wordArray);
  10629. */
  10630. C.SHA512 = Hasher._createHelper(SHA512);
  10631. /**
  10632. * Shortcut function to the HMAC's object interface.
  10633. *
  10634. * @param {WordArray|string} message The message to hash.
  10635. * @param {WordArray|string} key The secret key.
  10636. *
  10637. * @return {WordArray} The HMAC.
  10638. *
  10639. * @static
  10640. *
  10641. * @example
  10642. *
  10643. * var hmac = CryptoJS.HmacSHA512(message, key);
  10644. */
  10645. C.HmacSHA512 = Hasher._createHmacHelper(SHA512);
  10646. }());
  10647. return CryptoJS.SHA512;
  10648. }));
  10649. },{"./core":53,"./x64-core":84}],83:[function(require,module,exports){
  10650. ;(function (root, factory, undef) {
  10651. if (typeof exports === "object") {
  10652. // CommonJS
  10653. module.exports = exports = factory(require("./core"), require("./enc-base64"), require("./md5"), require("./evpkdf"), require("./cipher-core"));
  10654. }
  10655. else if (typeof define === "function" && define.amd) {
  10656. // AMD
  10657. define(["./core", "./enc-base64", "./md5", "./evpkdf", "./cipher-core"], factory);
  10658. }
  10659. else {
  10660. // Global (browser)
  10661. factory(root.CryptoJS);
  10662. }
  10663. }(this, function (CryptoJS) {
  10664. (function () {
  10665. // Shortcuts
  10666. var C = CryptoJS;
  10667. var C_lib = C.lib;
  10668. var WordArray = C_lib.WordArray;
  10669. var BlockCipher = C_lib.BlockCipher;
  10670. var C_algo = C.algo;
  10671. // Permuted Choice 1 constants
  10672. var PC1 = [
  10673. 57, 49, 41, 33, 25, 17, 9, 1,
  10674. 58, 50, 42, 34, 26, 18, 10, 2,
  10675. 59, 51, 43, 35, 27, 19, 11, 3,
  10676. 60, 52, 44, 36, 63, 55, 47, 39,
  10677. 31, 23, 15, 7, 62, 54, 46, 38,
  10678. 30, 22, 14, 6, 61, 53, 45, 37,
  10679. 29, 21, 13, 5, 28, 20, 12, 4
  10680. ];
  10681. // Permuted Choice 2 constants
  10682. var PC2 = [
  10683. 14, 17, 11, 24, 1, 5,
  10684. 3, 28, 15, 6, 21, 10,
  10685. 23, 19, 12, 4, 26, 8,
  10686. 16, 7, 27, 20, 13, 2,
  10687. 41, 52, 31, 37, 47, 55,
  10688. 30, 40, 51, 45, 33, 48,
  10689. 44, 49, 39, 56, 34, 53,
  10690. 46, 42, 50, 36, 29, 32
  10691. ];
  10692. // Cumulative bit shift constants
  10693. var BIT_SHIFTS = [1, 2, 4, 6, 8, 10, 12, 14, 15, 17, 19, 21, 23, 25, 27, 28];
  10694. // SBOXes and round permutation constants
  10695. var SBOX_P = [
  10696. {
  10697. 0x0: 0x808200,
  10698. 0x10000000: 0x8000,
  10699. 0x20000000: 0x808002,
  10700. 0x30000000: 0x2,
  10701. 0x40000000: 0x200,
  10702. 0x50000000: 0x808202,
  10703. 0x60000000: 0x800202,
  10704. 0x70000000: 0x800000,
  10705. 0x80000000: 0x202,
  10706. 0x90000000: 0x800200,
  10707. 0xa0000000: 0x8200,
  10708. 0xb0000000: 0x808000,
  10709. 0xc0000000: 0x8002,
  10710. 0xd0000000: 0x800002,
  10711. 0xe0000000: 0x0,
  10712. 0xf0000000: 0x8202,
  10713. 0x8000000: 0x0,
  10714. 0x18000000: 0x808202,
  10715. 0x28000000: 0x8202,
  10716. 0x38000000: 0x8000,
  10717. 0x48000000: 0x808200,
  10718. 0x58000000: 0x200,
  10719. 0x68000000: 0x808002,
  10720. 0x78000000: 0x2,
  10721. 0x88000000: 0x800200,
  10722. 0x98000000: 0x8200,
  10723. 0xa8000000: 0x808000,
  10724. 0xb8000000: 0x800202,
  10725. 0xc8000000: 0x800002,
  10726. 0xd8000000: 0x8002,
  10727. 0xe8000000: 0x202,
  10728. 0xf8000000: 0x800000,
  10729. 0x1: 0x8000,
  10730. 0x10000001: 0x2,
  10731. 0x20000001: 0x808200,
  10732. 0x30000001: 0x800000,
  10733. 0x40000001: 0x808002,
  10734. 0x50000001: 0x8200,
  10735. 0x60000001: 0x200,
  10736. 0x70000001: 0x800202,
  10737. 0x80000001: 0x808202,
  10738. 0x90000001: 0x808000,
  10739. 0xa0000001: 0x800002,
  10740. 0xb0000001: 0x8202,
  10741. 0xc0000001: 0x202,
  10742. 0xd0000001: 0x800200,
  10743. 0xe0000001: 0x8002,
  10744. 0xf0000001: 0x0,
  10745. 0x8000001: 0x808202,
  10746. 0x18000001: 0x808000,
  10747. 0x28000001: 0x800000,
  10748. 0x38000001: 0x200,
  10749. 0x48000001: 0x8000,
  10750. 0x58000001: 0x800002,
  10751. 0x68000001: 0x2,
  10752. 0x78000001: 0x8202,
  10753. 0x88000001: 0x8002,
  10754. 0x98000001: 0x800202,
  10755. 0xa8000001: 0x202,
  10756. 0xb8000001: 0x808200,
  10757. 0xc8000001: 0x800200,
  10758. 0xd8000001: 0x0,
  10759. 0xe8000001: 0x8200,
  10760. 0xf8000001: 0x808002
  10761. },
  10762. {
  10763. 0x0: 0x40084010,
  10764. 0x1000000: 0x4000,
  10765. 0x2000000: 0x80000,
  10766. 0x3000000: 0x40080010,
  10767. 0x4000000: 0x40000010,
  10768. 0x5000000: 0x40084000,
  10769. 0x6000000: 0x40004000,
  10770. 0x7000000: 0x10,
  10771. 0x8000000: 0x84000,
  10772. 0x9000000: 0x40004010,
  10773. 0xa000000: 0x40000000,
  10774. 0xb000000: 0x84010,
  10775. 0xc000000: 0x80010,
  10776. 0xd000000: 0x0,
  10777. 0xe000000: 0x4010,
  10778. 0xf000000: 0x40080000,
  10779. 0x800000: 0x40004000,
  10780. 0x1800000: 0x84010,
  10781. 0x2800000: 0x10,
  10782. 0x3800000: 0x40004010,
  10783. 0x4800000: 0x40084010,
  10784. 0x5800000: 0x40000000,
  10785. 0x6800000: 0x80000,
  10786. 0x7800000: 0x40080010,
  10787. 0x8800000: 0x80010,
  10788. 0x9800000: 0x0,
  10789. 0xa800000: 0x4000,
  10790. 0xb800000: 0x40080000,
  10791. 0xc800000: 0x40000010,
  10792. 0xd800000: 0x84000,
  10793. 0xe800000: 0x40084000,
  10794. 0xf800000: 0x4010,
  10795. 0x10000000: 0x0,
  10796. 0x11000000: 0x40080010,
  10797. 0x12000000: 0x40004010,
  10798. 0x13000000: 0x40084000,
  10799. 0x14000000: 0x40080000,
  10800. 0x15000000: 0x10,
  10801. 0x16000000: 0x84010,
  10802. 0x17000000: 0x4000,
  10803. 0x18000000: 0x4010,
  10804. 0x19000000: 0x80000,
  10805. 0x1a000000: 0x80010,
  10806. 0x1b000000: 0x40000010,
  10807. 0x1c000000: 0x84000,
  10808. 0x1d000000: 0x40004000,
  10809. 0x1e000000: 0x40000000,
  10810. 0x1f000000: 0x40084010,
  10811. 0x10800000: 0x84010,
  10812. 0x11800000: 0x80000,
  10813. 0x12800000: 0x40080000,
  10814. 0x13800000: 0x4000,
  10815. 0x14800000: 0x40004000,
  10816. 0x15800000: 0x40084010,
  10817. 0x16800000: 0x10,
  10818. 0x17800000: 0x40000000,
  10819. 0x18800000: 0x40084000,
  10820. 0x19800000: 0x40000010,
  10821. 0x1a800000: 0x40004010,
  10822. 0x1b800000: 0x80010,
  10823. 0x1c800000: 0x0,
  10824. 0x1d800000: 0x4010,
  10825. 0x1e800000: 0x40080010,
  10826. 0x1f800000: 0x84000
  10827. },
  10828. {
  10829. 0x0: 0x104,
  10830. 0x100000: 0x0,
  10831. 0x200000: 0x4000100,
  10832. 0x300000: 0x10104,
  10833. 0x400000: 0x10004,
  10834. 0x500000: 0x4000004,
  10835. 0x600000: 0x4010104,
  10836. 0x700000: 0x4010000,
  10837. 0x800000: 0x4000000,
  10838. 0x900000: 0x4010100,
  10839. 0xa00000: 0x10100,
  10840. 0xb00000: 0x4010004,
  10841. 0xc00000: 0x4000104,
  10842. 0xd00000: 0x10000,
  10843. 0xe00000: 0x4,
  10844. 0xf00000: 0x100,
  10845. 0x80000: 0x4010100,
  10846. 0x180000: 0x4010004,
  10847. 0x280000: 0x0,
  10848. 0x380000: 0x4000100,
  10849. 0x480000: 0x4000004,
  10850. 0x580000: 0x10000,
  10851. 0x680000: 0x10004,
  10852. 0x780000: 0x104,
  10853. 0x880000: 0x4,
  10854. 0x980000: 0x100,
  10855. 0xa80000: 0x4010000,
  10856. 0xb80000: 0x10104,
  10857. 0xc80000: 0x10100,
  10858. 0xd80000: 0x4000104,
  10859. 0xe80000: 0x4010104,
  10860. 0xf80000: 0x4000000,
  10861. 0x1000000: 0x4010100,
  10862. 0x1100000: 0x10004,
  10863. 0x1200000: 0x10000,
  10864. 0x1300000: 0x4000100,
  10865. 0x1400000: 0x100,
  10866. 0x1500000: 0x4010104,
  10867. 0x1600000: 0x4000004,
  10868. 0x1700000: 0x0,
  10869. 0x1800000: 0x4000104,
  10870. 0x1900000: 0x4000000,
  10871. 0x1a00000: 0x4,
  10872. 0x1b00000: 0x10100,
  10873. 0x1c00000: 0x4010000,
  10874. 0x1d00000: 0x104,
  10875. 0x1e00000: 0x10104,
  10876. 0x1f00000: 0x4010004,
  10877. 0x1080000: 0x4000000,
  10878. 0x1180000: 0x104,
  10879. 0x1280000: 0x4010100,
  10880. 0x1380000: 0x0,
  10881. 0x1480000: 0x10004,
  10882. 0x1580000: 0x4000100,
  10883. 0x1680000: 0x100,
  10884. 0x1780000: 0x4010004,
  10885. 0x1880000: 0x10000,
  10886. 0x1980000: 0x4010104,
  10887. 0x1a80000: 0x10104,
  10888. 0x1b80000: 0x4000004,
  10889. 0x1c80000: 0x4000104,
  10890. 0x1d80000: 0x4010000,
  10891. 0x1e80000: 0x4,
  10892. 0x1f80000: 0x10100
  10893. },
  10894. {
  10895. 0x0: 0x80401000,
  10896. 0x10000: 0x80001040,
  10897. 0x20000: 0x401040,
  10898. 0x30000: 0x80400000,
  10899. 0x40000: 0x0,
  10900. 0x50000: 0x401000,
  10901. 0x60000: 0x80000040,
  10902. 0x70000: 0x400040,
  10903. 0x80000: 0x80000000,
  10904. 0x90000: 0x400000,
  10905. 0xa0000: 0x40,
  10906. 0xb0000: 0x80001000,
  10907. 0xc0000: 0x80400040,
  10908. 0xd0000: 0x1040,
  10909. 0xe0000: 0x1000,
  10910. 0xf0000: 0x80401040,
  10911. 0x8000: 0x80001040,
  10912. 0x18000: 0x40,
  10913. 0x28000: 0x80400040,
  10914. 0x38000: 0x80001000,
  10915. 0x48000: 0x401000,
  10916. 0x58000: 0x80401040,
  10917. 0x68000: 0x0,
  10918. 0x78000: 0x80400000,
  10919. 0x88000: 0x1000,
  10920. 0x98000: 0x80401000,
  10921. 0xa8000: 0x400000,
  10922. 0xb8000: 0x1040,
  10923. 0xc8000: 0x80000000,
  10924. 0xd8000: 0x400040,
  10925. 0xe8000: 0x401040,
  10926. 0xf8000: 0x80000040,
  10927. 0x100000: 0x400040,
  10928. 0x110000: 0x401000,
  10929. 0x120000: 0x80000040,
  10930. 0x130000: 0x0,
  10931. 0x140000: 0x1040,
  10932. 0x150000: 0x80400040,
  10933. 0x160000: 0x80401000,
  10934. 0x170000: 0x80001040,
  10935. 0x180000: 0x80401040,
  10936. 0x190000: 0x80000000,
  10937. 0x1a0000: 0x80400000,
  10938. 0x1b0000: 0x401040,
  10939. 0x1c0000: 0x80001000,
  10940. 0x1d0000: 0x400000,
  10941. 0x1e0000: 0x40,
  10942. 0x1f0000: 0x1000,
  10943. 0x108000: 0x80400000,
  10944. 0x118000: 0x80401040,
  10945. 0x128000: 0x0,
  10946. 0x138000: 0x401000,
  10947. 0x148000: 0x400040,
  10948. 0x158000: 0x80000000,
  10949. 0x168000: 0x80001040,
  10950. 0x178000: 0x40,
  10951. 0x188000: 0x80000040,
  10952. 0x198000: 0x1000,
  10953. 0x1a8000: 0x80001000,
  10954. 0x1b8000: 0x80400040,
  10955. 0x1c8000: 0x1040,
  10956. 0x1d8000: 0x80401000,
  10957. 0x1e8000: 0x400000,
  10958. 0x1f8000: 0x401040
  10959. },
  10960. {
  10961. 0x0: 0x80,
  10962. 0x1000: 0x1040000,
  10963. 0x2000: 0x40000,
  10964. 0x3000: 0x20000000,
  10965. 0x4000: 0x20040080,
  10966. 0x5000: 0x1000080,
  10967. 0x6000: 0x21000080,
  10968. 0x7000: 0x40080,
  10969. 0x8000: 0x1000000,
  10970. 0x9000: 0x20040000,
  10971. 0xa000: 0x20000080,
  10972. 0xb000: 0x21040080,
  10973. 0xc000: 0x21040000,
  10974. 0xd000: 0x0,
  10975. 0xe000: 0x1040080,
  10976. 0xf000: 0x21000000,
  10977. 0x800: 0x1040080,
  10978. 0x1800: 0x21000080,
  10979. 0x2800: 0x80,
  10980. 0x3800: 0x1040000,
  10981. 0x4800: 0x40000,
  10982. 0x5800: 0x20040080,
  10983. 0x6800: 0x21040000,
  10984. 0x7800: 0x20000000,
  10985. 0x8800: 0x20040000,
  10986. 0x9800: 0x0,
  10987. 0xa800: 0x21040080,
  10988. 0xb800: 0x1000080,
  10989. 0xc800: 0x20000080,
  10990. 0xd800: 0x21000000,
  10991. 0xe800: 0x1000000,
  10992. 0xf800: 0x40080,
  10993. 0x10000: 0x40000,
  10994. 0x11000: 0x80,
  10995. 0x12000: 0x20000000,
  10996. 0x13000: 0x21000080,
  10997. 0x14000: 0x1000080,
  10998. 0x15000: 0x21040000,
  10999. 0x16000: 0x20040080,
  11000. 0x17000: 0x1000000,
  11001. 0x18000: 0x21040080,
  11002. 0x19000: 0x21000000,
  11003. 0x1a000: 0x1040000,
  11004. 0x1b000: 0x20040000,
  11005. 0x1c000: 0x40080,
  11006. 0x1d000: 0x20000080,
  11007. 0x1e000: 0x0,
  11008. 0x1f000: 0x1040080,
  11009. 0x10800: 0x21000080,
  11010. 0x11800: 0x1000000,
  11011. 0x12800: 0x1040000,
  11012. 0x13800: 0x20040080,
  11013. 0x14800: 0x20000000,
  11014. 0x15800: 0x1040080,
  11015. 0x16800: 0x80,
  11016. 0x17800: 0x21040000,
  11017. 0x18800: 0x40080,
  11018. 0x19800: 0x21040080,
  11019. 0x1a800: 0x0,
  11020. 0x1b800: 0x21000000,
  11021. 0x1c800: 0x1000080,
  11022. 0x1d800: 0x40000,
  11023. 0x1e800: 0x20040000,
  11024. 0x1f800: 0x20000080
  11025. },
  11026. {
  11027. 0x0: 0x10000008,
  11028. 0x100: 0x2000,
  11029. 0x200: 0x10200000,
  11030. 0x300: 0x10202008,
  11031. 0x400: 0x10002000,
  11032. 0x500: 0x200000,
  11033. 0x600: 0x200008,
  11034. 0x700: 0x10000000,
  11035. 0x800: 0x0,
  11036. 0x900: 0x10002008,
  11037. 0xa00: 0x202000,
  11038. 0xb00: 0x8,
  11039. 0xc00: 0x10200008,
  11040. 0xd00: 0x202008,
  11041. 0xe00: 0x2008,
  11042. 0xf00: 0x10202000,
  11043. 0x80: 0x10200000,
  11044. 0x180: 0x10202008,
  11045. 0x280: 0x8,
  11046. 0x380: 0x200000,
  11047. 0x480: 0x202008,
  11048. 0x580: 0x10000008,
  11049. 0x680: 0x10002000,
  11050. 0x780: 0x2008,
  11051. 0x880: 0x200008,
  11052. 0x980: 0x2000,
  11053. 0xa80: 0x10002008,
  11054. 0xb80: 0x10200008,
  11055. 0xc80: 0x0,
  11056. 0xd80: 0x10202000,
  11057. 0xe80: 0x202000,
  11058. 0xf80: 0x10000000,
  11059. 0x1000: 0x10002000,
  11060. 0x1100: 0x10200008,
  11061. 0x1200: 0x10202008,
  11062. 0x1300: 0x2008,
  11063. 0x1400: 0x200000,
  11064. 0x1500: 0x10000000,
  11065. 0x1600: 0x10000008,
  11066. 0x1700: 0x202000,
  11067. 0x1800: 0x202008,
  11068. 0x1900: 0x0,
  11069. 0x1a00: 0x8,
  11070. 0x1b00: 0x10200000,
  11071. 0x1c00: 0x2000,
  11072. 0x1d00: 0x10002008,
  11073. 0x1e00: 0x10202000,
  11074. 0x1f00: 0x200008,
  11075. 0x1080: 0x8,
  11076. 0x1180: 0x202000,
  11077. 0x1280: 0x200000,
  11078. 0x1380: 0x10000008,
  11079. 0x1480: 0x10002000,
  11080. 0x1580: 0x2008,
  11081. 0x1680: 0x10202008,
  11082. 0x1780: 0x10200000,
  11083. 0x1880: 0x10202000,
  11084. 0x1980: 0x10200008,
  11085. 0x1a80: 0x2000,
  11086. 0x1b80: 0x202008,
  11087. 0x1c80: 0x200008,
  11088. 0x1d80: 0x0,
  11089. 0x1e80: 0x10000000,
  11090. 0x1f80: 0x10002008
  11091. },
  11092. {
  11093. 0x0: 0x100000,
  11094. 0x10: 0x2000401,
  11095. 0x20: 0x400,
  11096. 0x30: 0x100401,
  11097. 0x40: 0x2100401,
  11098. 0x50: 0x0,
  11099. 0x60: 0x1,
  11100. 0x70: 0x2100001,
  11101. 0x80: 0x2000400,
  11102. 0x90: 0x100001,
  11103. 0xa0: 0x2000001,
  11104. 0xb0: 0x2100400,
  11105. 0xc0: 0x2100000,
  11106. 0xd0: 0x401,
  11107. 0xe0: 0x100400,
  11108. 0xf0: 0x2000000,
  11109. 0x8: 0x2100001,
  11110. 0x18: 0x0,
  11111. 0x28: 0x2000401,
  11112. 0x38: 0x2100400,
  11113. 0x48: 0x100000,
  11114. 0x58: 0x2000001,
  11115. 0x68: 0x2000000,
  11116. 0x78: 0x401,
  11117. 0x88: 0x100401,
  11118. 0x98: 0x2000400,
  11119. 0xa8: 0x2100000,
  11120. 0xb8: 0x100001,
  11121. 0xc8: 0x400,
  11122. 0xd8: 0x2100401,
  11123. 0xe8: 0x1,
  11124. 0xf8: 0x100400,
  11125. 0x100: 0x2000000,
  11126. 0x110: 0x100000,
  11127. 0x120: 0x2000401,
  11128. 0x130: 0x2100001,
  11129. 0x140: 0x100001,
  11130. 0x150: 0x2000400,
  11131. 0x160: 0x2100400,
  11132. 0x170: 0x100401,
  11133. 0x180: 0x401,
  11134. 0x190: 0x2100401,
  11135. 0x1a0: 0x100400,
  11136. 0x1b0: 0x1,
  11137. 0x1c0: 0x0,
  11138. 0x1d0: 0x2100000,
  11139. 0x1e0: 0x2000001,
  11140. 0x1f0: 0x400,
  11141. 0x108: 0x100400,
  11142. 0x118: 0x2000401,
  11143. 0x128: 0x2100001,
  11144. 0x138: 0x1,
  11145. 0x148: 0x2000000,
  11146. 0x158: 0x100000,
  11147. 0x168: 0x401,
  11148. 0x178: 0x2100400,
  11149. 0x188: 0x2000001,
  11150. 0x198: 0x2100000,
  11151. 0x1a8: 0x0,
  11152. 0x1b8: 0x2100401,
  11153. 0x1c8: 0x100401,
  11154. 0x1d8: 0x400,
  11155. 0x1e8: 0x2000400,
  11156. 0x1f8: 0x100001
  11157. },
  11158. {
  11159. 0x0: 0x8000820,
  11160. 0x1: 0x20000,
  11161. 0x2: 0x8000000,
  11162. 0x3: 0x20,
  11163. 0x4: 0x20020,
  11164. 0x5: 0x8020820,
  11165. 0x6: 0x8020800,
  11166. 0x7: 0x800,
  11167. 0x8: 0x8020000,
  11168. 0x9: 0x8000800,
  11169. 0xa: 0x20800,
  11170. 0xb: 0x8020020,
  11171. 0xc: 0x820,
  11172. 0xd: 0x0,
  11173. 0xe: 0x8000020,
  11174. 0xf: 0x20820,
  11175. 0x80000000: 0x800,
  11176. 0x80000001: 0x8020820,
  11177. 0x80000002: 0x8000820,
  11178. 0x80000003: 0x8000000,
  11179. 0x80000004: 0x8020000,
  11180. 0x80000005: 0x20800,
  11181. 0x80000006: 0x20820,
  11182. 0x80000007: 0x20,
  11183. 0x80000008: 0x8000020,
  11184. 0x80000009: 0x820,
  11185. 0x8000000a: 0x20020,
  11186. 0x8000000b: 0x8020800,
  11187. 0x8000000c: 0x0,
  11188. 0x8000000d: 0x8020020,
  11189. 0x8000000e: 0x8000800,
  11190. 0x8000000f: 0x20000,
  11191. 0x10: 0x20820,
  11192. 0x11: 0x8020800,
  11193. 0x12: 0x20,
  11194. 0x13: 0x800,
  11195. 0x14: 0x8000800,
  11196. 0x15: 0x8000020,
  11197. 0x16: 0x8020020,
  11198. 0x17: 0x20000,
  11199. 0x18: 0x0,
  11200. 0x19: 0x20020,
  11201. 0x1a: 0x8020000,
  11202. 0x1b: 0x8000820,
  11203. 0x1c: 0x8020820,
  11204. 0x1d: 0x20800,
  11205. 0x1e: 0x820,
  11206. 0x1f: 0x8000000,
  11207. 0x80000010: 0x20000,
  11208. 0x80000011: 0x800,
  11209. 0x80000012: 0x8020020,
  11210. 0x80000013: 0x20820,
  11211. 0x80000014: 0x20,
  11212. 0x80000015: 0x8020000,
  11213. 0x80000016: 0x8000000,
  11214. 0x80000017: 0x8000820,
  11215. 0x80000018: 0x8020820,
  11216. 0x80000019: 0x8000020,
  11217. 0x8000001a: 0x8000800,
  11218. 0x8000001b: 0x0,
  11219. 0x8000001c: 0x20800,
  11220. 0x8000001d: 0x820,
  11221. 0x8000001e: 0x20020,
  11222. 0x8000001f: 0x8020800
  11223. }
  11224. ];
  11225. // Masks that select the SBOX input
  11226. var SBOX_MASK = [
  11227. 0xf8000001, 0x1f800000, 0x01f80000, 0x001f8000,
  11228. 0x0001f800, 0x00001f80, 0x000001f8, 0x8000001f
  11229. ];
  11230. /**
  11231. * DES block cipher algorithm.
  11232. */
  11233. var DES = C_algo.DES = BlockCipher.extend({
  11234. _doReset: function () {
  11235. // Shortcuts
  11236. var key = this._key;
  11237. var keyWords = key.words;
  11238. // Select 56 bits according to PC1
  11239. var keyBits = [];
  11240. for (var i = 0; i < 56; i++) {
  11241. var keyBitPos = PC1[i] - 1;
  11242. keyBits[i] = (keyWords[keyBitPos >>> 5] >>> (31 - keyBitPos % 32)) & 1;
  11243. }
  11244. // Assemble 16 subkeys
  11245. var subKeys = this._subKeys = [];
  11246. for (var nSubKey = 0; nSubKey < 16; nSubKey++) {
  11247. // Create subkey
  11248. var subKey = subKeys[nSubKey] = [];
  11249. // Shortcut
  11250. var bitShift = BIT_SHIFTS[nSubKey];
  11251. // Select 48 bits according to PC2
  11252. for (var i = 0; i < 24; i++) {
  11253. // Select from the left 28 key bits
  11254. subKey[(i / 6) | 0] |= keyBits[((PC2[i] - 1) + bitShift) % 28] << (31 - i % 6);
  11255. // Select from the right 28 key bits
  11256. subKey[4 + ((i / 6) | 0)] |= keyBits[28 + (((PC2[i + 24] - 1) + bitShift) % 28)] << (31 - i % 6);
  11257. }
  11258. // Since each subkey is applied to an expanded 32-bit input,
  11259. // the subkey can be broken into 8 values scaled to 32-bits,
  11260. // which allows the key to be used without expansion
  11261. subKey[0] = (subKey[0] << 1) | (subKey[0] >>> 31);
  11262. for (var i = 1; i < 7; i++) {
  11263. subKey[i] = subKey[i] >>> ((i - 1) * 4 + 3);
  11264. }
  11265. subKey[7] = (subKey[7] << 5) | (subKey[7] >>> 27);
  11266. }
  11267. // Compute inverse subkeys
  11268. var invSubKeys = this._invSubKeys = [];
  11269. for (var i = 0; i < 16; i++) {
  11270. invSubKeys[i] = subKeys[15 - i];
  11271. }
  11272. },
  11273. encryptBlock: function (M, offset) {
  11274. this._doCryptBlock(M, offset, this._subKeys);
  11275. },
  11276. decryptBlock: function (M, offset) {
  11277. this._doCryptBlock(M, offset, this._invSubKeys);
  11278. },
  11279. _doCryptBlock: function (M, offset, subKeys) {
  11280. // Get input
  11281. this._lBlock = M[offset];
  11282. this._rBlock = M[offset + 1];
  11283. // Initial permutation
  11284. exchangeLR.call(this, 4, 0x0f0f0f0f);
  11285. exchangeLR.call(this, 16, 0x0000ffff);
  11286. exchangeRL.call(this, 2, 0x33333333);
  11287. exchangeRL.call(this, 8, 0x00ff00ff);
  11288. exchangeLR.call(this, 1, 0x55555555);
  11289. // Rounds
  11290. for (var round = 0; round < 16; round++) {
  11291. // Shortcuts
  11292. var subKey = subKeys[round];
  11293. var lBlock = this._lBlock;
  11294. var rBlock = this._rBlock;
  11295. // Feistel function
  11296. var f = 0;
  11297. for (var i = 0; i < 8; i++) {
  11298. f |= SBOX_P[i][((rBlock ^ subKey[i]) & SBOX_MASK[i]) >>> 0];
  11299. }
  11300. this._lBlock = rBlock;
  11301. this._rBlock = lBlock ^ f;
  11302. }
  11303. // Undo swap from last round
  11304. var t = this._lBlock;
  11305. this._lBlock = this._rBlock;
  11306. this._rBlock = t;
  11307. // Final permutation
  11308. exchangeLR.call(this, 1, 0x55555555);
  11309. exchangeRL.call(this, 8, 0x00ff00ff);
  11310. exchangeRL.call(this, 2, 0x33333333);
  11311. exchangeLR.call(this, 16, 0x0000ffff);
  11312. exchangeLR.call(this, 4, 0x0f0f0f0f);
  11313. // Set output
  11314. M[offset] = this._lBlock;
  11315. M[offset + 1] = this._rBlock;
  11316. },
  11317. keySize: 64/32,
  11318. ivSize: 64/32,
  11319. blockSize: 64/32
  11320. });
  11321. // Swap bits across the left and right words
  11322. function exchangeLR(offset, mask) {
  11323. var t = ((this._lBlock >>> offset) ^ this._rBlock) & mask;
  11324. this._rBlock ^= t;
  11325. this._lBlock ^= t << offset;
  11326. }
  11327. function exchangeRL(offset, mask) {
  11328. var t = ((this._rBlock >>> offset) ^ this._lBlock) & mask;
  11329. this._lBlock ^= t;
  11330. this._rBlock ^= t << offset;
  11331. }
  11332. /**
  11333. * Shortcut functions to the cipher's object interface.
  11334. *
  11335. * @example
  11336. *
  11337. * var ciphertext = CryptoJS.DES.encrypt(message, key, cfg);
  11338. * var plaintext = CryptoJS.DES.decrypt(ciphertext, key, cfg);
  11339. */
  11340. C.DES = BlockCipher._createHelper(DES);
  11341. /**
  11342. * Triple-DES block cipher algorithm.
  11343. */
  11344. var TripleDES = C_algo.TripleDES = BlockCipher.extend({
  11345. _doReset: function () {
  11346. // Shortcuts
  11347. var key = this._key;
  11348. var keyWords = key.words;
  11349. // Create DES instances
  11350. this._des1 = DES.createEncryptor(WordArray.create(keyWords.slice(0, 2)));
  11351. this._des2 = DES.createEncryptor(WordArray.create(keyWords.slice(2, 4)));
  11352. this._des3 = DES.createEncryptor(WordArray.create(keyWords.slice(4, 6)));
  11353. },
  11354. encryptBlock: function (M, offset) {
  11355. this._des1.encryptBlock(M, offset);
  11356. this._des2.decryptBlock(M, offset);
  11357. this._des3.encryptBlock(M, offset);
  11358. },
  11359. decryptBlock: function (M, offset) {
  11360. this._des3.decryptBlock(M, offset);
  11361. this._des2.encryptBlock(M, offset);
  11362. this._des1.decryptBlock(M, offset);
  11363. },
  11364. keySize: 192/32,
  11365. ivSize: 64/32,
  11366. blockSize: 64/32
  11367. });
  11368. /**
  11369. * Shortcut functions to the cipher's object interface.
  11370. *
  11371. * @example
  11372. *
  11373. * var ciphertext = CryptoJS.TripleDES.encrypt(message, key, cfg);
  11374. * var plaintext = CryptoJS.TripleDES.decrypt(ciphertext, key, cfg);
  11375. */
  11376. C.TripleDES = BlockCipher._createHelper(TripleDES);
  11377. }());
  11378. return CryptoJS.TripleDES;
  11379. }));
  11380. },{"./cipher-core":52,"./core":53,"./enc-base64":54,"./evpkdf":56,"./md5":61}],84:[function(require,module,exports){
  11381. ;(function (root, factory) {
  11382. if (typeof exports === "object") {
  11383. // CommonJS
  11384. module.exports = exports = factory(require("./core"));
  11385. }
  11386. else if (typeof define === "function" && define.amd) {
  11387. // AMD
  11388. define(["./core"], factory);
  11389. }
  11390. else {
  11391. // Global (browser)
  11392. factory(root.CryptoJS);
  11393. }
  11394. }(this, function (CryptoJS) {
  11395. (function (undefined) {
  11396. // Shortcuts
  11397. var C = CryptoJS;
  11398. var C_lib = C.lib;
  11399. var Base = C_lib.Base;
  11400. var X32WordArray = C_lib.WordArray;
  11401. /**
  11402. * x64 namespace.
  11403. */
  11404. var C_x64 = C.x64 = {};
  11405. /**
  11406. * A 64-bit word.
  11407. */
  11408. var X64Word = C_x64.Word = Base.extend({
  11409. /**
  11410. * Initializes a newly created 64-bit word.
  11411. *
  11412. * @param {number} high The high 32 bits.
  11413. * @param {number} low The low 32 bits.
  11414. *
  11415. * @example
  11416. *
  11417. * var x64Word = CryptoJS.x64.Word.create(0x00010203, 0x04050607);
  11418. */
  11419. init: function (high, low) {
  11420. this.high = high;
  11421. this.low = low;
  11422. }
  11423. /**
  11424. * Bitwise NOTs this word.
  11425. *
  11426. * @return {X64Word} A new x64-Word object after negating.
  11427. *
  11428. * @example
  11429. *
  11430. * var negated = x64Word.not();
  11431. */
  11432. // not: function () {
  11433. // var high = ~this.high;
  11434. // var low = ~this.low;
  11435. // return X64Word.create(high, low);
  11436. // },
  11437. /**
  11438. * Bitwise ANDs this word with the passed word.
  11439. *
  11440. * @param {X64Word} word The x64-Word to AND with this word.
  11441. *
  11442. * @return {X64Word} A new x64-Word object after ANDing.
  11443. *
  11444. * @example
  11445. *
  11446. * var anded = x64Word.and(anotherX64Word);
  11447. */
  11448. // and: function (word) {
  11449. // var high = this.high & word.high;
  11450. // var low = this.low & word.low;
  11451. // return X64Word.create(high, low);
  11452. // },
  11453. /**
  11454. * Bitwise ORs this word with the passed word.
  11455. *
  11456. * @param {X64Word} word The x64-Word to OR with this word.
  11457. *
  11458. * @return {X64Word} A new x64-Word object after ORing.
  11459. *
  11460. * @example
  11461. *
  11462. * var ored = x64Word.or(anotherX64Word);
  11463. */
  11464. // or: function (word) {
  11465. // var high = this.high | word.high;
  11466. // var low = this.low | word.low;
  11467. // return X64Word.create(high, low);
  11468. // },
  11469. /**
  11470. * Bitwise XORs this word with the passed word.
  11471. *
  11472. * @param {X64Word} word The x64-Word to XOR with this word.
  11473. *
  11474. * @return {X64Word} A new x64-Word object after XORing.
  11475. *
  11476. * @example
  11477. *
  11478. * var xored = x64Word.xor(anotherX64Word);
  11479. */
  11480. // xor: function (word) {
  11481. // var high = this.high ^ word.high;
  11482. // var low = this.low ^ word.low;
  11483. // return X64Word.create(high, low);
  11484. // },
  11485. /**
  11486. * Shifts this word n bits to the left.
  11487. *
  11488. * @param {number} n The number of bits to shift.
  11489. *
  11490. * @return {X64Word} A new x64-Word object after shifting.
  11491. *
  11492. * @example
  11493. *
  11494. * var shifted = x64Word.shiftL(25);
  11495. */
  11496. // shiftL: function (n) {
  11497. // if (n < 32) {
  11498. // var high = (this.high << n) | (this.low >>> (32 - n));
  11499. // var low = this.low << n;
  11500. // } else {
  11501. // var high = this.low << (n - 32);
  11502. // var low = 0;
  11503. // }
  11504. // return X64Word.create(high, low);
  11505. // },
  11506. /**
  11507. * Shifts this word n bits to the right.
  11508. *
  11509. * @param {number} n The number of bits to shift.
  11510. *
  11511. * @return {X64Word} A new x64-Word object after shifting.
  11512. *
  11513. * @example
  11514. *
  11515. * var shifted = x64Word.shiftR(7);
  11516. */
  11517. // shiftR: function (n) {
  11518. // if (n < 32) {
  11519. // var low = (this.low >>> n) | (this.high << (32 - n));
  11520. // var high = this.high >>> n;
  11521. // } else {
  11522. // var low = this.high >>> (n - 32);
  11523. // var high = 0;
  11524. // }
  11525. // return X64Word.create(high, low);
  11526. // },
  11527. /**
  11528. * Rotates this word n bits to the left.
  11529. *
  11530. * @param {number} n The number of bits to rotate.
  11531. *
  11532. * @return {X64Word} A new x64-Word object after rotating.
  11533. *
  11534. * @example
  11535. *
  11536. * var rotated = x64Word.rotL(25);
  11537. */
  11538. // rotL: function (n) {
  11539. // return this.shiftL(n).or(this.shiftR(64 - n));
  11540. // },
  11541. /**
  11542. * Rotates this word n bits to the right.
  11543. *
  11544. * @param {number} n The number of bits to rotate.
  11545. *
  11546. * @return {X64Word} A new x64-Word object after rotating.
  11547. *
  11548. * @example
  11549. *
  11550. * var rotated = x64Word.rotR(7);
  11551. */
  11552. // rotR: function (n) {
  11553. // return this.shiftR(n).or(this.shiftL(64 - n));
  11554. // },
  11555. /**
  11556. * Adds this word with the passed word.
  11557. *
  11558. * @param {X64Word} word The x64-Word to add with this word.
  11559. *
  11560. * @return {X64Word} A new x64-Word object after adding.
  11561. *
  11562. * @example
  11563. *
  11564. * var added = x64Word.add(anotherX64Word);
  11565. */
  11566. // add: function (word) {
  11567. // var low = (this.low + word.low) | 0;
  11568. // var carry = (low >>> 0) < (this.low >>> 0) ? 1 : 0;
  11569. // var high = (this.high + word.high + carry) | 0;
  11570. // return X64Word.create(high, low);
  11571. // }
  11572. });
  11573. /**
  11574. * An array of 64-bit words.
  11575. *
  11576. * @property {Array} words The array of CryptoJS.x64.Word objects.
  11577. * @property {number} sigBytes The number of significant bytes in this word array.
  11578. */
  11579. var X64WordArray = C_x64.WordArray = Base.extend({
  11580. /**
  11581. * Initializes a newly created word array.
  11582. *
  11583. * @param {Array} words (Optional) An array of CryptoJS.x64.Word objects.
  11584. * @param {number} sigBytes (Optional) The number of significant bytes in the words.
  11585. *
  11586. * @example
  11587. *
  11588. * var wordArray = CryptoJS.x64.WordArray.create();
  11589. *
  11590. * var wordArray = CryptoJS.x64.WordArray.create([
  11591. * CryptoJS.x64.Word.create(0x00010203, 0x04050607),
  11592. * CryptoJS.x64.Word.create(0x18191a1b, 0x1c1d1e1f)
  11593. * ]);
  11594. *
  11595. * var wordArray = CryptoJS.x64.WordArray.create([
  11596. * CryptoJS.x64.Word.create(0x00010203, 0x04050607),
  11597. * CryptoJS.x64.Word.create(0x18191a1b, 0x1c1d1e1f)
  11598. * ], 10);
  11599. */
  11600. init: function (words, sigBytes) {
  11601. words = this.words = words || [];
  11602. if (sigBytes != undefined) {
  11603. this.sigBytes = sigBytes;
  11604. } else {
  11605. this.sigBytes = words.length * 8;
  11606. }
  11607. },
  11608. /**
  11609. * Converts this 64-bit word array to a 32-bit word array.
  11610. *
  11611. * @return {CryptoJS.lib.WordArray} This word array's data as a 32-bit word array.
  11612. *
  11613. * @example
  11614. *
  11615. * var x32WordArray = x64WordArray.toX32();
  11616. */
  11617. toX32: function () {
  11618. // Shortcuts
  11619. var x64Words = this.words;
  11620. var x64WordsLength = x64Words.length;
  11621. // Convert
  11622. var x32Words = [];
  11623. for (var i = 0; i < x64WordsLength; i++) {
  11624. var x64Word = x64Words[i];
  11625. x32Words.push(x64Word.high);
  11626. x32Words.push(x64Word.low);
  11627. }
  11628. return X32WordArray.create(x32Words, this.sigBytes);
  11629. },
  11630. /**
  11631. * Creates a copy of this word array.
  11632. *
  11633. * @return {X64WordArray} The clone.
  11634. *
  11635. * @example
  11636. *
  11637. * var clone = x64WordArray.clone();
  11638. */
  11639. clone: function () {
  11640. var clone = Base.clone.call(this);
  11641. // Clone "words" array
  11642. var words = clone.words = this.words.slice(0);
  11643. // Clone each X64Word object
  11644. var wordsLength = words.length;
  11645. for (var i = 0; i < wordsLength; i++) {
  11646. words[i] = words[i].clone();
  11647. }
  11648. return clone;
  11649. }
  11650. });
  11651. }());
  11652. return CryptoJS;
  11653. }));
  11654. },{"./core":53}],85:[function(require,module,exports){
  11655. /*! https://mths.be/utf8js v2.1.2 by @mathias */
  11656. ;(function(root) {
  11657. // Detect free variables `exports`
  11658. var freeExports = typeof exports == 'object' && exports;
  11659. // Detect free variable `module`
  11660. var freeModule = typeof module == 'object' && module &&
  11661. module.exports == freeExports && module;
  11662. // Detect free variable `global`, from Node.js or Browserified code,
  11663. // and use it as `root`
  11664. var freeGlobal = typeof global == 'object' && global;
  11665. if (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal) {
  11666. root = freeGlobal;
  11667. }
  11668. /*--------------------------------------------------------------------------*/
  11669. var stringFromCharCode = String.fromCharCode;
  11670. // Taken from https://mths.be/punycode
  11671. function ucs2decode(string) {
  11672. var output = [];
  11673. var counter = 0;
  11674. var length = string.length;
  11675. var value;
  11676. var extra;
  11677. while (counter < length) {
  11678. value = string.charCodeAt(counter++);
  11679. if (value >= 0xD800 && value <= 0xDBFF && counter < length) {
  11680. // high surrogate, and there is a next character
  11681. extra = string.charCodeAt(counter++);
  11682. if ((extra & 0xFC00) == 0xDC00) { // low surrogate
  11683. output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000);
  11684. } else {
  11685. // unmatched surrogate; only append this code unit, in case the next
  11686. // code unit is the high surrogate of a surrogate pair
  11687. output.push(value);
  11688. counter--;
  11689. }
  11690. } else {
  11691. output.push(value);
  11692. }
  11693. }
  11694. return output;
  11695. }
  11696. // Taken from https://mths.be/punycode
  11697. function ucs2encode(array) {
  11698. var length = array.length;
  11699. var index = -1;
  11700. var value;
  11701. var output = '';
  11702. while (++index < length) {
  11703. value = array[index];
  11704. if (value > 0xFFFF) {
  11705. value -= 0x10000;
  11706. output += stringFromCharCode(value >>> 10 & 0x3FF | 0xD800);
  11707. value = 0xDC00 | value & 0x3FF;
  11708. }
  11709. output += stringFromCharCode(value);
  11710. }
  11711. return output;
  11712. }
  11713. function checkScalarValue(codePoint) {
  11714. if (codePoint >= 0xD800 && codePoint <= 0xDFFF) {
  11715. throw Error(
  11716. 'Lone surrogate U+' + codePoint.toString(16).toUpperCase() +
  11717. ' is not a scalar value'
  11718. );
  11719. }
  11720. }
  11721. /*--------------------------------------------------------------------------*/
  11722. function createByte(codePoint, shift) {
  11723. return stringFromCharCode(((codePoint >> shift) & 0x3F) | 0x80);
  11724. }
  11725. function encodeCodePoint(codePoint) {
  11726. if ((codePoint & 0xFFFFFF80) == 0) { // 1-byte sequence
  11727. return stringFromCharCode(codePoint);
  11728. }
  11729. var symbol = '';
  11730. if ((codePoint & 0xFFFFF800) == 0) { // 2-byte sequence
  11731. symbol = stringFromCharCode(((codePoint >> 6) & 0x1F) | 0xC0);
  11732. }
  11733. else if ((codePoint & 0xFFFF0000) == 0) { // 3-byte sequence
  11734. checkScalarValue(codePoint);
  11735. symbol = stringFromCharCode(((codePoint >> 12) & 0x0F) | 0xE0);
  11736. symbol += createByte(codePoint, 6);
  11737. }
  11738. else if ((codePoint & 0xFFE00000) == 0) { // 4-byte sequence
  11739. symbol = stringFromCharCode(((codePoint >> 18) & 0x07) | 0xF0);
  11740. symbol += createByte(codePoint, 12);
  11741. symbol += createByte(codePoint, 6);
  11742. }
  11743. symbol += stringFromCharCode((codePoint & 0x3F) | 0x80);
  11744. return symbol;
  11745. }
  11746. function utf8encode(string) {
  11747. var codePoints = ucs2decode(string);
  11748. var length = codePoints.length;
  11749. var index = -1;
  11750. var codePoint;
  11751. var byteString = '';
  11752. while (++index < length) {
  11753. codePoint = codePoints[index];
  11754. byteString += encodeCodePoint(codePoint);
  11755. }
  11756. return byteString;
  11757. }
  11758. /*--------------------------------------------------------------------------*/
  11759. function readContinuationByte() {
  11760. if (byteIndex >= byteCount) {
  11761. throw Error('Invalid byte index');
  11762. }
  11763. var continuationByte = byteArray[byteIndex] & 0xFF;
  11764. byteIndex++;
  11765. if ((continuationByte & 0xC0) == 0x80) {
  11766. return continuationByte & 0x3F;
  11767. }
  11768. // If we end up here, it’s not a continuation byte
  11769. throw Error('Invalid continuation byte');
  11770. }
  11771. function decodeSymbol() {
  11772. var byte1;
  11773. var byte2;
  11774. var byte3;
  11775. var byte4;
  11776. var codePoint;
  11777. if (byteIndex > byteCount) {
  11778. throw Error('Invalid byte index');
  11779. }
  11780. if (byteIndex == byteCount) {
  11781. return false;
  11782. }
  11783. // Read first byte
  11784. byte1 = byteArray[byteIndex] & 0xFF;
  11785. byteIndex++;
  11786. // 1-byte sequence (no continuation bytes)
  11787. if ((byte1 & 0x80) == 0) {
  11788. return byte1;
  11789. }
  11790. // 2-byte sequence
  11791. if ((byte1 & 0xE0) == 0xC0) {
  11792. byte2 = readContinuationByte();
  11793. codePoint = ((byte1 & 0x1F) << 6) | byte2;
  11794. if (codePoint >= 0x80) {
  11795. return codePoint;
  11796. } else {
  11797. throw Error('Invalid continuation byte');
  11798. }
  11799. }
  11800. // 3-byte sequence (may include unpaired surrogates)
  11801. if ((byte1 & 0xF0) == 0xE0) {
  11802. byte2 = readContinuationByte();
  11803. byte3 = readContinuationByte();
  11804. codePoint = ((byte1 & 0x0F) << 12) | (byte2 << 6) | byte3;
  11805. if (codePoint >= 0x0800) {
  11806. checkScalarValue(codePoint);
  11807. return codePoint;
  11808. } else {
  11809. throw Error('Invalid continuation byte');
  11810. }
  11811. }
  11812. // 4-byte sequence
  11813. if ((byte1 & 0xF8) == 0xF0) {
  11814. byte2 = readContinuationByte();
  11815. byte3 = readContinuationByte();
  11816. byte4 = readContinuationByte();
  11817. codePoint = ((byte1 & 0x07) << 0x12) | (byte2 << 0x0C) |
  11818. (byte3 << 0x06) | byte4;
  11819. if (codePoint >= 0x010000 && codePoint <= 0x10FFFF) {
  11820. return codePoint;
  11821. }
  11822. }
  11823. throw Error('Invalid UTF-8 detected');
  11824. }
  11825. var byteArray;
  11826. var byteCount;
  11827. var byteIndex;
  11828. function utf8decode(byteString) {
  11829. byteArray = ucs2decode(byteString);
  11830. byteCount = byteArray.length;
  11831. byteIndex = 0;
  11832. var codePoints = [];
  11833. var tmp;
  11834. while ((tmp = decodeSymbol()) !== false) {
  11835. codePoints.push(tmp);
  11836. }
  11837. return ucs2encode(codePoints);
  11838. }
  11839. /*--------------------------------------------------------------------------*/
  11840. var utf8 = {
  11841. 'version': '2.1.2',
  11842. 'encode': utf8encode,
  11843. 'decode': utf8decode
  11844. };
  11845. // Some AMD build optimizers, like r.js, check for specific condition patterns
  11846. // like the following:
  11847. if (
  11848. typeof define == 'function' &&
  11849. typeof define.amd == 'object' &&
  11850. define.amd
  11851. ) {
  11852. define(function() {
  11853. return utf8;
  11854. });
  11855. } else if (freeExports && !freeExports.nodeType) {
  11856. if (freeModule) { // in Node.js or RingoJS v0.8.0+
  11857. freeModule.exports = utf8;
  11858. } else { // in Narwhal or RingoJS v0.7.0-
  11859. var object = {};
  11860. var hasOwnProperty = object.hasOwnProperty;
  11861. for (var key in utf8) {
  11862. hasOwnProperty.call(utf8, key) && (freeExports[key] = utf8[key]);
  11863. }
  11864. }
  11865. } else { // in Rhino or a web browser
  11866. root.utf8 = utf8;
  11867. }
  11868. }(this));
  11869. },{}],86:[function(require,module,exports){
  11870. module.exports = XMLHttpRequest;
  11871. },{}],"bignumber.js":[function(require,module,exports){
  11872. 'use strict';
  11873. module.exports = BigNumber; // jshint ignore:line
  11874. },{}],"web3":[function(require,module,exports){
  11875. var Web3 = require('./lib/web3');
  11876. // dont override global variable
  11877. if (typeof window !== 'undefined' && typeof window.Web3 === 'undefined') {
  11878. window.Web3 = Web3;
  11879. }
  11880. module.exports = Web3;
  11881. },{"./lib/web3":22}]},{},["web3"])
  11882. //# sourceMappingURL=web3-light.js.map