web3.js 392 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636
  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. // (Quorum) if receipt has no contractAddress and is a Quorum privacy marker transaction
  2587. // then check if there is a transaction receipt for the internal private transaction
  2588. if(!receipt.contractAddress && receipt.isPrivacyMarkerTransaction) {
  2589. contract._eth.getPrivateTransactionReceipt(contract.transactionHash, function(e, privateReceipt){
  2590. if(privateReceipt.contractAddress) {
  2591. receipt = privateReceipt
  2592. }
  2593. })
  2594. }
  2595. contract._eth.getCode(receipt.contractAddress, function(e, code){
  2596. /*jshint maxcomplexity: 6 */
  2597. if(callbackFired || !code)
  2598. return;
  2599. filter.stopWatching(function() {});
  2600. callbackFired = true;
  2601. if(code.length > 3) {
  2602. // console.log('Contract code deployed!');
  2603. contract.address = receipt.contractAddress;
  2604. // attach events and methods again after we have
  2605. addFunctionsToContract(contract);
  2606. addEventsToContract(contract);
  2607. // call callback for the second time
  2608. if(callback)
  2609. callback(null, contract);
  2610. } else {
  2611. if(callback)
  2612. callback(new Error('The contract code couldn\'t be stored, please check your gas amount.'));
  2613. else
  2614. throw new Error('The contract code couldn\'t be stored, please check your gas amount.');
  2615. }
  2616. });
  2617. }
  2618. });
  2619. }
  2620. }
  2621. });
  2622. };
  2623. /**
  2624. * Should be called to create new ContractFactory instance
  2625. *
  2626. * @method ContractFactory
  2627. * @param {Array} abi
  2628. */
  2629. var ContractFactory = function (eth, abi) {
  2630. this.eth = eth;
  2631. this.abi = abi;
  2632. /**
  2633. * Should be called to create new contract on a blockchain
  2634. *
  2635. * @method new
  2636. * @param {Any} contract constructor param1 (optional)
  2637. * @param {Any} contract constructor param2 (optional)
  2638. * @param {Object} contract transaction object (required)
  2639. * @param {Function} callback
  2640. * @returns {Contract} returns contract instance
  2641. */
  2642. this.new = function () {
  2643. /*jshint maxcomplexity: 7 */
  2644. var contract = new Contract(this.eth, this.abi);
  2645. // parse arguments
  2646. var options = {}; // required!
  2647. var callback;
  2648. var args = Array.prototype.slice.call(arguments);
  2649. if (utils.isFunction(args[args.length - 1])) {
  2650. callback = args.pop();
  2651. }
  2652. var last = args[args.length - 1];
  2653. if (utils.isObject(last) && !utils.isArray(last)) {
  2654. options = args.pop();
  2655. }
  2656. if (options.value > 0) {
  2657. var constructorAbi = abi.filter(function (json) {
  2658. return json.type === 'constructor' && json.inputs.length === args.length;
  2659. })[0] || {};
  2660. if (!constructorAbi.payable) {
  2661. throw new Error('Cannot send value to non-payable constructor');
  2662. }
  2663. }
  2664. var bytes = encodeConstructorParams(this.abi, args);
  2665. options.data += bytes;
  2666. if (callback) {
  2667. // wait for the contract address and check if the code was deployed
  2668. this.eth.sendTransaction(options, function (err, hash) {
  2669. if (err) {
  2670. callback(err);
  2671. } else {
  2672. // add the transaction hash
  2673. contract.transactionHash = hash;
  2674. // call callback for the first time
  2675. callback(null, contract);
  2676. checkForContractAddress(contract, callback);
  2677. }
  2678. });
  2679. } else {
  2680. var hash = this.eth.sendTransaction(options);
  2681. // add the transaction hash
  2682. contract.transactionHash = hash;
  2683. checkForContractAddress(contract);
  2684. }
  2685. return contract;
  2686. };
  2687. this.new.getData = this.getData.bind(this);
  2688. };
  2689. /**
  2690. * Should be called to create new ContractFactory
  2691. *
  2692. * @method contract
  2693. * @param {Array} abi
  2694. * @returns {ContractFactory} new contract factory
  2695. */
  2696. //var contract = function (abi) {
  2697. //return new ContractFactory(abi);
  2698. //};
  2699. /**
  2700. * Should be called to get access to existing contract on a blockchain
  2701. *
  2702. * @method at
  2703. * @param {Address} contract address (required)
  2704. * @param {Function} callback {optional)
  2705. * @returns {Contract} returns contract if no callback was passed,
  2706. * otherwise calls callback function (err, contract)
  2707. */
  2708. ContractFactory.prototype.at = function (address, callback) {
  2709. var contract = new Contract(this.eth, this.abi, address);
  2710. // this functions are not part of prototype,
  2711. // because we don't want to spoil the interface
  2712. addFunctionsToContract(contract);
  2713. addEventsToContract(contract);
  2714. if (callback) {
  2715. callback(null, contract);
  2716. }
  2717. return contract;
  2718. };
  2719. /**
  2720. * Gets the data, which is data to deploy plus constructor params
  2721. *
  2722. * @method getData
  2723. */
  2724. ContractFactory.prototype.getData = function () {
  2725. var options = {}; // required!
  2726. var args = Array.prototype.slice.call(arguments);
  2727. var last = args[args.length - 1];
  2728. if (utils.isObject(last) && !utils.isArray(last)) {
  2729. options = args.pop();
  2730. }
  2731. var bytes = encodeConstructorParams(this.abi, args);
  2732. options.data += bytes;
  2733. return options.data;
  2734. };
  2735. /**
  2736. * Should be called to create new contract instance
  2737. *
  2738. * @method Contract
  2739. * @param {Array} abi
  2740. * @param {Address} contract address
  2741. */
  2742. var Contract = function (eth, abi, address) {
  2743. this._eth = eth;
  2744. this.transactionHash = null;
  2745. this.address = address;
  2746. this.abi = abi;
  2747. };
  2748. module.exports = ContractFactory;
  2749. },{"../solidity/coder":7,"../utils/utils":20,"./allevents":23,"./event":27,"./function":31}],26:[function(require,module,exports){
  2750. /*
  2751. This file is part of web3.js.
  2752. web3.js is free software: you can redistribute it and/or modify
  2753. it under the terms of the GNU Lesser General Public License as published by
  2754. the Free Software Foundation, either version 3 of the License, or
  2755. (at your option) any later version.
  2756. web3.js is distributed in the hope that it will be useful,
  2757. but WITHOUT ANY WARRANTY; without even the implied warranty of
  2758. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  2759. GNU Lesser General Public License for more details.
  2760. You should have received a copy of the GNU Lesser General Public License
  2761. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  2762. */
  2763. /**
  2764. * @file errors.js
  2765. * @author Marek Kotewicz <marek@ethdev.com>
  2766. * @date 2015
  2767. */
  2768. module.exports = {
  2769. InvalidNumberOfSolidityArgs: function () {
  2770. return new Error('Invalid number of arguments to Solidity function');
  2771. },
  2772. InvalidNumberOfRPCParams: function () {
  2773. return new Error('Invalid number of input parameters to RPC method');
  2774. },
  2775. InvalidConnection: function (host){
  2776. return new Error('CONNECTION ERROR: Couldn\'t connect to node '+ host +'.');
  2777. },
  2778. InvalidProvider: function () {
  2779. return new Error('Provider not set or invalid');
  2780. },
  2781. InvalidResponse: function (result){
  2782. var message = !!result && !!result.error && !!result.error.message ? result.error.message : 'Invalid JSON RPC response: ' + JSON.stringify(result);
  2783. return new Error(message);
  2784. },
  2785. ConnectionTimeout: function (ms){
  2786. return new Error('CONNECTION TIMEOUT: timeout of ' + ms + ' ms achived');
  2787. }
  2788. };
  2789. },{}],27:[function(require,module,exports){
  2790. /*
  2791. This file is part of web3.js.
  2792. web3.js is free software: you can redistribute it and/or modify
  2793. it under the terms of the GNU Lesser General Public License as published by
  2794. the Free Software Foundation, either version 3 of the License, or
  2795. (at your option) any later version.
  2796. web3.js is distributed in the hope that it will be useful,
  2797. but WITHOUT ANY WARRANTY; without even the implied warranty of
  2798. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  2799. GNU Lesser General Public License for more details.
  2800. You should have received a copy of the GNU Lesser General Public License
  2801. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  2802. */
  2803. /**
  2804. * @file event.js
  2805. * @author Marek Kotewicz <marek@ethdev.com>
  2806. * @date 2014
  2807. */
  2808. var utils = require('../utils/utils');
  2809. var coder = require('../solidity/coder');
  2810. var formatters = require('./formatters');
  2811. var sha3 = require('../utils/sha3');
  2812. var Filter = require('./filter');
  2813. var watches = require('./methods/watches');
  2814. /**
  2815. * This prototype should be used to create event filters
  2816. */
  2817. var SolidityEvent = function (requestManager, json, address) {
  2818. this._requestManager = requestManager;
  2819. this._params = json.inputs;
  2820. this._name = utils.transformToFullName(json);
  2821. this._address = address;
  2822. this._anonymous = json.anonymous;
  2823. };
  2824. /**
  2825. * Should be used to get filtered param types
  2826. *
  2827. * @method types
  2828. * @param {Bool} decide if returned typed should be indexed
  2829. * @return {Array} array of types
  2830. */
  2831. SolidityEvent.prototype.types = function (indexed) {
  2832. return this._params.filter(function (i) {
  2833. return i.indexed === indexed;
  2834. }).map(function (i) {
  2835. return i.type;
  2836. });
  2837. };
  2838. /**
  2839. * Should be used to get event display name
  2840. *
  2841. * @method displayName
  2842. * @return {String} event display name
  2843. */
  2844. SolidityEvent.prototype.displayName = function () {
  2845. return utils.extractDisplayName(this._name);
  2846. };
  2847. /**
  2848. * Should be used to get event type name
  2849. *
  2850. * @method typeName
  2851. * @return {String} event type name
  2852. */
  2853. SolidityEvent.prototype.typeName = function () {
  2854. return utils.extractTypeName(this._name);
  2855. };
  2856. /**
  2857. * Should be used to get event signature
  2858. *
  2859. * @method signature
  2860. * @return {String} event signature
  2861. */
  2862. SolidityEvent.prototype.signature = function () {
  2863. return sha3(this._name);
  2864. };
  2865. /**
  2866. * Should be used to encode indexed params and options to one final object
  2867. *
  2868. * @method encode
  2869. * @param {Object} indexed
  2870. * @param {Object} options
  2871. * @return {Object} everything combined together and encoded
  2872. */
  2873. SolidityEvent.prototype.encode = function (indexed, options) {
  2874. indexed = indexed || {};
  2875. options = options || {};
  2876. var result = {};
  2877. ['fromBlock', 'toBlock'].filter(function (f) {
  2878. return options[f] !== undefined;
  2879. }).forEach(function (f) {
  2880. result[f] = formatters.inputBlockNumberFormatter(options[f]);
  2881. });
  2882. result.topics = [];
  2883. result.address = this._address;
  2884. if (!this._anonymous) {
  2885. result.topics.push('0x' + this.signature());
  2886. }
  2887. var indexedTopics = this._params.filter(function (i) {
  2888. return i.indexed === true;
  2889. }).map(function (i) {
  2890. var value = indexed[i.name];
  2891. if (value === undefined || value === null) {
  2892. return null;
  2893. }
  2894. if (utils.isArray(value)) {
  2895. return value.map(function (v) {
  2896. return '0x' + coder.encodeParam(i.type, v);
  2897. });
  2898. }
  2899. return '0x' + coder.encodeParam(i.type, value);
  2900. });
  2901. result.topics = result.topics.concat(indexedTopics);
  2902. return result;
  2903. };
  2904. /**
  2905. * Should be used to decode indexed params and options
  2906. *
  2907. * @method decode
  2908. * @param {Object} data
  2909. * @return {Object} result object with decoded indexed && not indexed params
  2910. */
  2911. SolidityEvent.prototype.decode = function (data) {
  2912. data.data = data.data || '';
  2913. data.topics = data.topics || [];
  2914. var argTopics = this._anonymous ? data.topics : data.topics.slice(1);
  2915. var indexedData = argTopics.map(function (topics) { return topics.slice(2); }).join("");
  2916. var indexedParams = coder.decodeParams(this.types(true), indexedData);
  2917. var notIndexedData = data.data.slice(2);
  2918. var notIndexedParams = coder.decodeParams(this.types(false), notIndexedData);
  2919. var result = formatters.outputLogFormatter(data);
  2920. result.event = this.displayName();
  2921. result.address = data.address;
  2922. result.args = this._params.reduce(function (acc, current) {
  2923. acc[current.name] = current.indexed ? indexedParams.shift() : notIndexedParams.shift();
  2924. return acc;
  2925. }, {});
  2926. delete result.data;
  2927. delete result.topics;
  2928. return result;
  2929. };
  2930. /**
  2931. * Should be used to create new filter object from event
  2932. *
  2933. * @method execute
  2934. * @param {Object} indexed
  2935. * @param {Object} options
  2936. * @return {Object} filter object
  2937. */
  2938. SolidityEvent.prototype.execute = function (indexed, options, callback) {
  2939. if (utils.isFunction(arguments[arguments.length - 1])) {
  2940. callback = arguments[arguments.length - 1];
  2941. if(arguments.length === 2)
  2942. options = null;
  2943. if(arguments.length === 1) {
  2944. options = null;
  2945. indexed = {};
  2946. }
  2947. }
  2948. var o = this.encode(indexed, options);
  2949. var formatter = this.decode.bind(this);
  2950. return new Filter(o, 'eth', this._requestManager, watches.eth(), formatter, callback);
  2951. };
  2952. /**
  2953. * Should be used to attach event to contract object
  2954. *
  2955. * @method attachToContract
  2956. * @param {Contract}
  2957. */
  2958. SolidityEvent.prototype.attachToContract = function (contract) {
  2959. var execute = this.execute.bind(this);
  2960. var displayName = this.displayName();
  2961. if (!contract[displayName]) {
  2962. contract[displayName] = execute;
  2963. }
  2964. contract[displayName][this.typeName()] = this.execute.bind(this, contract);
  2965. };
  2966. module.exports = SolidityEvent;
  2967. },{"../solidity/coder":7,"../utils/sha3":19,"../utils/utils":20,"./filter":29,"./formatters":30,"./methods/watches":43}],28:[function(require,module,exports){
  2968. var formatters = require('./formatters');
  2969. var utils = require('./../utils/utils');
  2970. var Method = require('./method');
  2971. var Property = require('./property');
  2972. // TODO: refactor, so the input params are not altered.
  2973. // it's necessary to make same 'extension' work with multiple providers
  2974. var extend = function (web3) {
  2975. /* jshint maxcomplexity:5 */
  2976. var ex = function (extension) {
  2977. var extendedObject;
  2978. if (extension.property) {
  2979. if (!web3[extension.property]) {
  2980. web3[extension.property] = {};
  2981. }
  2982. extendedObject = web3[extension.property];
  2983. } else {
  2984. extendedObject = web3;
  2985. }
  2986. if (extension.methods) {
  2987. extension.methods.forEach(function (method) {
  2988. method.attachToObject(extendedObject);
  2989. method.setRequestManager(web3._requestManager);
  2990. });
  2991. }
  2992. if (extension.properties) {
  2993. extension.properties.forEach(function (property) {
  2994. property.attachToObject(extendedObject);
  2995. property.setRequestManager(web3._requestManager);
  2996. });
  2997. }
  2998. };
  2999. ex.formatters = formatters;
  3000. ex.utils = utils;
  3001. ex.Method = Method;
  3002. ex.Property = Property;
  3003. return ex;
  3004. };
  3005. module.exports = extend;
  3006. },{"./../utils/utils":20,"./formatters":30,"./method":36,"./property":45}],29:[function(require,module,exports){
  3007. /*
  3008. This file is part of web3.js.
  3009. web3.js is free software: you can redistribute it and/or modify
  3010. it under the terms of the GNU Lesser General Public License as published by
  3011. the Free Software Foundation, either version 3 of the License, or
  3012. (at your option) any later version.
  3013. web3.js is distributed in the hope that it will be useful,
  3014. but WITHOUT ANY WARRANTY; without even the implied warranty of
  3015. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  3016. GNU Lesser General Public License for more details.
  3017. You should have received a copy of the GNU Lesser General Public License
  3018. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  3019. */
  3020. /** @file filter.js
  3021. * @authors:
  3022. * Jeffrey Wilcke <jeff@ethdev.com>
  3023. * Marek Kotewicz <marek@ethdev.com>
  3024. * Marian Oancea <marian@ethdev.com>
  3025. * Fabian Vogelsteller <fabian@ethdev.com>
  3026. * Gav Wood <g@ethdev.com>
  3027. * @date 2014
  3028. */
  3029. var formatters = require('./formatters');
  3030. var utils = require('../utils/utils');
  3031. /**
  3032. * Converts a given topic to a hex string, but also allows null values.
  3033. *
  3034. * @param {Mixed} value
  3035. * @return {String}
  3036. */
  3037. var toTopic = function(value){
  3038. if(value === null || typeof value === 'undefined')
  3039. return null;
  3040. value = String(value);
  3041. if(value.indexOf('0x') === 0)
  3042. return value;
  3043. else
  3044. return utils.fromUtf8(value);
  3045. };
  3046. /// This method should be called on options object, to verify deprecated properties && lazy load dynamic ones
  3047. /// @param should be string or object
  3048. /// @returns options string or object
  3049. var getOptions = function (options, type) {
  3050. /*jshint maxcomplexity: 6 */
  3051. if (utils.isString(options)) {
  3052. return options;
  3053. }
  3054. options = options || {};
  3055. switch(type) {
  3056. case 'eth':
  3057. // make sure topics, get converted to hex
  3058. options.topics = options.topics || [];
  3059. options.topics = options.topics.map(function(topic){
  3060. return (utils.isArray(topic)) ? topic.map(toTopic) : toTopic(topic);
  3061. });
  3062. return {
  3063. topics: options.topics,
  3064. from: options.from,
  3065. to: options.to,
  3066. address: options.address,
  3067. fromBlock: formatters.inputBlockNumberFormatter(options.fromBlock),
  3068. toBlock: formatters.inputBlockNumberFormatter(options.toBlock)
  3069. };
  3070. case 'shh':
  3071. return options;
  3072. }
  3073. };
  3074. /**
  3075. Adds the callback and sets up the methods, to iterate over the results.
  3076. @method getLogsAtStart
  3077. @param {Object} self
  3078. @param {function} callback
  3079. */
  3080. var getLogsAtStart = function(self, callback){
  3081. // call getFilterLogs for the first watch callback start
  3082. if (!utils.isString(self.options)) {
  3083. self.get(function (err, messages) {
  3084. // don't send all the responses to all the watches again... just to self one
  3085. if (err) {
  3086. callback(err);
  3087. }
  3088. if(utils.isArray(messages)) {
  3089. messages.forEach(function (message) {
  3090. callback(null, message);
  3091. });
  3092. }
  3093. });
  3094. }
  3095. };
  3096. /**
  3097. Adds the callback and sets up the methods, to iterate over the results.
  3098. @method pollFilter
  3099. @param {Object} self
  3100. */
  3101. var pollFilter = function(self) {
  3102. var onMessage = function (error, messages) {
  3103. if (error) {
  3104. return self.callbacks.forEach(function (callback) {
  3105. callback(error);
  3106. });
  3107. }
  3108. if(utils.isArray(messages)) {
  3109. messages.forEach(function (message) {
  3110. message = self.formatter ? self.formatter(message) : message;
  3111. self.callbacks.forEach(function (callback) {
  3112. callback(null, message);
  3113. });
  3114. });
  3115. }
  3116. };
  3117. self.requestManager.startPolling({
  3118. method: self.implementation.poll.call,
  3119. params: [self.filterId],
  3120. }, self.filterId, onMessage, self.stopWatching.bind(self));
  3121. };
  3122. var Filter = function (options, type, requestManager, methods, formatter, callback, filterCreationErrorCallback) {
  3123. var self = this;
  3124. var implementation = {};
  3125. methods.forEach(function (method) {
  3126. method.setRequestManager(requestManager);
  3127. method.attachToObject(implementation);
  3128. });
  3129. this.requestManager = requestManager;
  3130. this.options = getOptions(options, type);
  3131. this.implementation = implementation;
  3132. this.filterId = null;
  3133. this.callbacks = [];
  3134. this.getLogsCallbacks = [];
  3135. this.pollFilters = [];
  3136. this.formatter = formatter;
  3137. this.implementation.newFilter(this.options, function(error, id){
  3138. if(error) {
  3139. self.callbacks.forEach(function(cb){
  3140. cb(error);
  3141. });
  3142. if (typeof filterCreationErrorCallback === 'function') {
  3143. filterCreationErrorCallback(error);
  3144. }
  3145. } else {
  3146. self.filterId = id;
  3147. // check if there are get pending callbacks as a consequence
  3148. // of calling get() with filterId unassigned.
  3149. self.getLogsCallbacks.forEach(function (cb){
  3150. self.get(cb);
  3151. });
  3152. self.getLogsCallbacks = [];
  3153. // get filter logs for the already existing watch calls
  3154. self.callbacks.forEach(function(cb){
  3155. getLogsAtStart(self, cb);
  3156. });
  3157. if(self.callbacks.length > 0)
  3158. pollFilter(self);
  3159. // start to watch immediately
  3160. if(typeof callback === 'function') {
  3161. return self.watch(callback);
  3162. }
  3163. }
  3164. });
  3165. return this;
  3166. };
  3167. Filter.prototype.watch = function (callback) {
  3168. this.callbacks.push(callback);
  3169. if(this.filterId) {
  3170. getLogsAtStart(this, callback);
  3171. pollFilter(this);
  3172. }
  3173. return this;
  3174. };
  3175. Filter.prototype.stopWatching = function (callback) {
  3176. this.requestManager.stopPolling(this.filterId);
  3177. this.callbacks = [];
  3178. // remove filter async
  3179. if (callback) {
  3180. this.implementation.uninstallFilter(this.filterId, callback);
  3181. } else {
  3182. return this.implementation.uninstallFilter(this.filterId);
  3183. }
  3184. };
  3185. Filter.prototype.get = function (callback) {
  3186. var self = this;
  3187. if (utils.isFunction(callback)) {
  3188. if (this.filterId === null) {
  3189. // If filterId is not set yet, call it back
  3190. // when newFilter() assigns it.
  3191. this.getLogsCallbacks.push(callback);
  3192. } else {
  3193. this.implementation.getLogs(this.filterId, function(err, res){
  3194. if (err) {
  3195. callback(err);
  3196. } else {
  3197. callback(null, res.map(function (log) {
  3198. return self.formatter ? self.formatter(log) : log;
  3199. }));
  3200. }
  3201. });
  3202. }
  3203. } else {
  3204. if (this.filterId === null) {
  3205. throw new Error('Filter ID Error: filter().get() can\'t be chained synchronous, please provide a callback for the get() method.');
  3206. }
  3207. var logs = this.implementation.getLogs(this.filterId);
  3208. return logs.map(function (log) {
  3209. return self.formatter ? self.formatter(log) : log;
  3210. });
  3211. }
  3212. return this;
  3213. };
  3214. module.exports = Filter;
  3215. },{"../utils/utils":20,"./formatters":30}],30:[function(require,module,exports){
  3216. 'use strict'
  3217. /*
  3218. This file is part of web3.js.
  3219. web3.js is free software: you can redistribute it and/or modify
  3220. it under the terms of the GNU Lesser General Public License as published by
  3221. the Free Software Foundation, either version 3 of the License, or
  3222. (at your option) any later version.
  3223. web3.js is distributed in the hope that it will be useful,
  3224. but WITHOUT ANY WARRANTY; without even the implied warranty of
  3225. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  3226. GNU Lesser General Public License for more details.
  3227. You should have received a copy of the GNU Lesser General Public License
  3228. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  3229. */
  3230. /**
  3231. * @file formatters.js
  3232. * @author Marek Kotewicz <marek@ethdev.com>
  3233. * @author Fabian Vogelsteller <fabian@ethdev.com>
  3234. * @date 2015
  3235. */
  3236. var utils = require('../utils/utils');
  3237. var config = require('../utils/config');
  3238. var Iban = require('./iban');
  3239. /**
  3240. * Should the format output to a big number
  3241. *
  3242. * @method outputBigNumberFormatter
  3243. * @param {String|Number|BigNumber}
  3244. * @returns {BigNumber} object
  3245. */
  3246. var outputBigNumberFormatter = function (number) {
  3247. return utils.toBigNumber(number);
  3248. };
  3249. var isPredefinedBlockNumber = function (blockNumber) {
  3250. return blockNumber === 'latest' || blockNumber === 'pending' || blockNumber === 'earliest';
  3251. };
  3252. var inputDefaultBlockNumberFormatter = function (blockNumber) {
  3253. if (blockNumber === undefined) {
  3254. return config.defaultBlock;
  3255. }
  3256. return inputBlockNumberFormatter(blockNumber);
  3257. };
  3258. var inputBlockNumberFormatter = function (blockNumber) {
  3259. if (blockNumber === undefined) {
  3260. return undefined;
  3261. } else if (isPredefinedBlockNumber(blockNumber)) {
  3262. return blockNumber;
  3263. }
  3264. return utils.toHex(blockNumber);
  3265. };
  3266. /**
  3267. * Formats the input of a transaction and converts all values to HEX
  3268. *
  3269. * @method inputCallFormatter
  3270. * @param {Object} transaction options
  3271. * @returns object
  3272. */
  3273. var inputCallFormatter = function (options){
  3274. options.from = options.from || config.defaultAccount;
  3275. if (options.from) {
  3276. options.from = inputAddressFormatter(options.from);
  3277. }
  3278. if (options.to) { // it might be contract creation
  3279. options.to = inputAddressFormatter(options.to);
  3280. }
  3281. ['gasPrice', 'gas', 'value', 'nonce'].filter(function (key) {
  3282. return options[key] !== undefined;
  3283. }).forEach(function(key){
  3284. options[key] = utils.fromDecimal(options[key]);
  3285. });
  3286. return options;
  3287. };
  3288. /**
  3289. * Formats the input of a transaction and converts all values to HEX
  3290. *
  3291. * @method inputTransactionFormatter
  3292. * @param {Object} transaction options
  3293. * @returns object
  3294. */
  3295. var inputTransactionFormatter = function (options){
  3296. options.from = options.from || config.defaultAccount;
  3297. options.from = inputAddressFormatter(options.from);
  3298. if (options.to) { // it might be contract creation
  3299. options.to = inputAddressFormatter(options.to);
  3300. }
  3301. ['gasPrice', 'gas', 'value', 'nonce'].filter(function (key) {
  3302. return options[key] !== undefined;
  3303. }).forEach(function(key){
  3304. options[key] = utils.fromDecimal(options[key]);
  3305. });
  3306. return options;
  3307. };
  3308. /**
  3309. * Formats the output of a transaction to its proper values
  3310. *
  3311. * @method outputTransactionFormatter
  3312. * @param {Object} tx
  3313. * @returns {Object}
  3314. */
  3315. var outputTransactionFormatter = function (tx){
  3316. if(tx.blockNumber !== null)
  3317. tx.blockNumber = utils.toDecimal(tx.blockNumber);
  3318. if(tx.transactionIndex !== null)
  3319. tx.transactionIndex = utils.toDecimal(tx.transactionIndex);
  3320. tx.nonce = utils.toDecimal(tx.nonce);
  3321. tx.gas = utils.toDecimal(tx.gas);
  3322. tx.gasPrice = utils.toBigNumber(tx.gasPrice);
  3323. tx.value = utils.toBigNumber(tx.value);
  3324. return tx;
  3325. };
  3326. /**
  3327. * Formats the output of a transaction receipt to its proper values
  3328. *
  3329. * @method outputTransactionReceiptFormatter
  3330. * @param {Object} receipt
  3331. * @returns {Object}
  3332. */
  3333. var outputTransactionReceiptFormatter = function (receipt){
  3334. if(receipt.blockNumber !== null)
  3335. receipt.blockNumber = utils.toDecimal(receipt.blockNumber);
  3336. if(receipt.transactionIndex !== null)
  3337. receipt.transactionIndex = utils.toDecimal(receipt.transactionIndex);
  3338. receipt.cumulativeGasUsed = utils.toDecimal(receipt.cumulativeGasUsed);
  3339. receipt.gasUsed = utils.toDecimal(receipt.gasUsed);
  3340. if(utils.isArray(receipt.logs)) {
  3341. receipt.logs = receipt.logs.map(function(log){
  3342. return outputLogFormatter(log);
  3343. });
  3344. }
  3345. return receipt;
  3346. };
  3347. /**
  3348. * Formats the output of a block to its proper values
  3349. *
  3350. * @method outputBlockFormatter
  3351. * @param {Object} block
  3352. * @returns {Object}
  3353. */
  3354. var outputBlockFormatter = function(block) {
  3355. // transform to number
  3356. block.gasLimit = utils.toDecimal(block.gasLimit);
  3357. block.gasUsed = utils.toDecimal(block.gasUsed);
  3358. block.size = utils.toDecimal(block.size);
  3359. block.timestamp = utils.toDecimal(block.timestamp);
  3360. if(block.number !== null)
  3361. block.number = utils.toDecimal(block.number);
  3362. block.difficulty = utils.toBigNumber(block.difficulty);
  3363. block.totalDifficulty = utils.toBigNumber(block.totalDifficulty);
  3364. if (utils.isArray(block.transactions)) {
  3365. block.transactions.forEach(function(item){
  3366. if(!utils.isString(item))
  3367. return outputTransactionFormatter(item);
  3368. });
  3369. }
  3370. return block;
  3371. };
  3372. /**
  3373. * Formats the output of a log
  3374. *
  3375. * @method outputLogFormatter
  3376. * @param {Object} log object
  3377. * @returns {Object} log
  3378. */
  3379. var outputLogFormatter = function(log) {
  3380. if(log.blockNumber)
  3381. log.blockNumber = utils.toDecimal(log.blockNumber);
  3382. if(log.transactionIndex)
  3383. log.transactionIndex = utils.toDecimal(log.transactionIndex);
  3384. if(log.logIndex)
  3385. log.logIndex = utils.toDecimal(log.logIndex);
  3386. return log;
  3387. };
  3388. /**
  3389. * Formats the input of a whisper post and converts all values to HEX
  3390. *
  3391. * @method inputPostFormatter
  3392. * @param {Object} transaction object
  3393. * @returns {Object}
  3394. */
  3395. var inputPostFormatter = function(post) {
  3396. // post.payload = utils.toHex(post.payload);
  3397. post.ttl = utils.fromDecimal(post.ttl);
  3398. post.workToProve = utils.fromDecimal(post.workToProve);
  3399. post.priority = utils.fromDecimal(post.priority);
  3400. // fallback
  3401. if (!utils.isArray(post.topics)) {
  3402. post.topics = post.topics ? [post.topics] : [];
  3403. }
  3404. // format the following options
  3405. post.topics = post.topics.map(function(topic){
  3406. // convert only if not hex
  3407. return (topic.indexOf('0x') === 0) ? topic : utils.fromUtf8(topic);
  3408. });
  3409. return post;
  3410. };
  3411. /**
  3412. * Formats the output of a received post message
  3413. *
  3414. * @method outputPostFormatter
  3415. * @param {Object}
  3416. * @returns {Object}
  3417. */
  3418. var outputPostFormatter = function(post){
  3419. post.expiry = utils.toDecimal(post.expiry);
  3420. post.sent = utils.toDecimal(post.sent);
  3421. post.ttl = utils.toDecimal(post.ttl);
  3422. post.workProved = utils.toDecimal(post.workProved);
  3423. // post.payloadRaw = post.payload;
  3424. // post.payload = utils.toAscii(post.payload);
  3425. // if (utils.isJson(post.payload)) {
  3426. // post.payload = JSON.parse(post.payload);
  3427. // }
  3428. // format the following options
  3429. if (!post.topics) {
  3430. post.topics = [];
  3431. }
  3432. post.topics = post.topics.map(function(topic){
  3433. return utils.toAscii(topic);
  3434. });
  3435. return post;
  3436. };
  3437. var inputAddressFormatter = function (address) {
  3438. var iban = new Iban(address);
  3439. if (iban.isValid() && iban.isDirect()) {
  3440. return '0x' + iban.address();
  3441. } else if (utils.isStrictAddress(address)) {
  3442. return address;
  3443. } else if (utils.isAddress(address)) {
  3444. return '0x' + address;
  3445. }
  3446. throw new Error('invalid address');
  3447. };
  3448. var outputSyncingFormatter = function(result) {
  3449. if (!result) {
  3450. return result;
  3451. }
  3452. result.startingBlock = utils.toDecimal(result.startingBlock);
  3453. result.currentBlock = utils.toDecimal(result.currentBlock);
  3454. result.highestBlock = utils.toDecimal(result.highestBlock);
  3455. if (result.knownStates) {
  3456. result.knownStates = utils.toDecimal(result.knownStates);
  3457. result.pulledStates = utils.toDecimal(result.pulledStates);
  3458. }
  3459. return result;
  3460. };
  3461. module.exports = {
  3462. inputDefaultBlockNumberFormatter: inputDefaultBlockNumberFormatter,
  3463. inputBlockNumberFormatter: inputBlockNumberFormatter,
  3464. inputCallFormatter: inputCallFormatter,
  3465. inputTransactionFormatter: inputTransactionFormatter,
  3466. inputAddressFormatter: inputAddressFormatter,
  3467. inputPostFormatter: inputPostFormatter,
  3468. outputBigNumberFormatter: outputBigNumberFormatter,
  3469. outputTransactionFormatter: outputTransactionFormatter,
  3470. outputTransactionReceiptFormatter: outputTransactionReceiptFormatter,
  3471. outputBlockFormatter: outputBlockFormatter,
  3472. outputLogFormatter: outputLogFormatter,
  3473. outputPostFormatter: outputPostFormatter,
  3474. outputSyncingFormatter: outputSyncingFormatter
  3475. };
  3476. },{"../utils/config":18,"../utils/utils":20,"./iban":33}],31:[function(require,module,exports){
  3477. /*
  3478. This file is part of web3.js.
  3479. web3.js is free software: you can redistribute it and/or modify
  3480. it under the terms of the GNU Lesser General Public License as published by
  3481. the Free Software Foundation, either version 3 of the License, or
  3482. (at your option) any later version.
  3483. web3.js is distributed in the hope that it will be useful,
  3484. but WITHOUT ANY WARRANTY; without even the implied warranty of
  3485. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  3486. GNU Lesser General Public License for more details.
  3487. You should have received a copy of the GNU Lesser General Public License
  3488. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  3489. */
  3490. /**
  3491. * @file function.js
  3492. * @author Marek Kotewicz <marek@ethdev.com>
  3493. * @date 2015
  3494. */
  3495. var coder = require('../solidity/coder');
  3496. var utils = require('../utils/utils');
  3497. var errors = require('./errors');
  3498. var formatters = require('./formatters');
  3499. var sha3 = require('../utils/sha3');
  3500. /**
  3501. * This prototype should be used to call/sendTransaction to solidity functions
  3502. */
  3503. var SolidityFunction = function (eth, json, address) {
  3504. this._eth = eth;
  3505. this._inputTypes = json.inputs.map(function (i) {
  3506. return i.type;
  3507. });
  3508. this._outputTypes = json.outputs.map(function (i) {
  3509. return i.type;
  3510. });
  3511. this._constant = json.constant;
  3512. this._payable = json.payable;
  3513. this._name = utils.transformToFullName(json);
  3514. this._address = address;
  3515. };
  3516. SolidityFunction.prototype.extractCallback = function (args) {
  3517. if (utils.isFunction(args[args.length - 1])) {
  3518. return args.pop(); // modify the args array!
  3519. }
  3520. };
  3521. SolidityFunction.prototype.extractDefaultBlock = function (args) {
  3522. if (args.length > this._inputTypes.length && !utils.isObject(args[args.length -1])) {
  3523. return formatters.inputDefaultBlockNumberFormatter(args.pop()); // modify the args array!
  3524. }
  3525. };
  3526. /**
  3527. * Should be called to check if the number of arguments is correct
  3528. *
  3529. * @method validateArgs
  3530. * @param {Array} arguments
  3531. * @throws {Error} if it is not
  3532. */
  3533. SolidityFunction.prototype.validateArgs = function (args) {
  3534. var inputArgs = args.filter(function (a) {
  3535. // filter the options object but not arguments that are arrays
  3536. return !( (utils.isObject(a) === true) &&
  3537. (utils.isArray(a) === false) &&
  3538. (utils.isBigNumber(a) === false)
  3539. );
  3540. });
  3541. if (inputArgs.length !== this._inputTypes.length) {
  3542. throw errors.InvalidNumberOfSolidityArgs();
  3543. }
  3544. };
  3545. /**
  3546. * Should be used to create payload from arguments
  3547. *
  3548. * @method toPayload
  3549. * @param {Array} solidity function params
  3550. * @param {Object} optional payload options
  3551. */
  3552. SolidityFunction.prototype.toPayload = function (args) {
  3553. var options = {};
  3554. if (args.length > this._inputTypes.length && utils.isObject(args[args.length -1])) {
  3555. options = args[args.length - 1];
  3556. }
  3557. this.validateArgs(args);
  3558. options.to = this._address;
  3559. options.data = '0x' + this.signature() + coder.encodeParams(this._inputTypes, args);
  3560. return options;
  3561. };
  3562. /**
  3563. * Should be used to get function signature
  3564. *
  3565. * @method signature
  3566. * @return {String} function signature
  3567. */
  3568. SolidityFunction.prototype.signature = function () {
  3569. return sha3(this._name).slice(0, 8);
  3570. };
  3571. SolidityFunction.prototype.unpackOutput = function (output) {
  3572. if (!output) {
  3573. return;
  3574. }
  3575. output = output.length >= 2 ? output.slice(2) : output;
  3576. var result = coder.decodeParams(this._outputTypes, output);
  3577. return result.length === 1 ? result[0] : result;
  3578. };
  3579. /**
  3580. * Calls a contract function.
  3581. *
  3582. * @method call
  3583. * @param {...Object} Contract function arguments
  3584. * @param {function} If the last argument is a function, the contract function
  3585. * call will be asynchronous, and the callback will be passed the
  3586. * error and result.
  3587. * @return {String} output bytes
  3588. */
  3589. SolidityFunction.prototype.call = function () {
  3590. var args = Array.prototype.slice.call(arguments).filter(function (a) {return a !== undefined; });
  3591. var callback = this.extractCallback(args);
  3592. var defaultBlock = this.extractDefaultBlock(args);
  3593. var payload = this.toPayload(args);
  3594. if (!callback) {
  3595. var output = this._eth.call(payload, defaultBlock);
  3596. return this.unpackOutput(output);
  3597. }
  3598. var self = this;
  3599. this._eth.call(payload, defaultBlock, function (error, output) {
  3600. if (error) return callback(error, null);
  3601. var unpacked = null;
  3602. try {
  3603. unpacked = self.unpackOutput(output);
  3604. }
  3605. catch (e) {
  3606. error = e;
  3607. }
  3608. callback(error, unpacked);
  3609. });
  3610. };
  3611. /**
  3612. * Should be used to sendTransaction to solidity function
  3613. *
  3614. * @method sendTransaction
  3615. */
  3616. SolidityFunction.prototype.sendTransaction = function () {
  3617. var args = Array.prototype.slice.call(arguments).filter(function (a) {return a !== undefined; });
  3618. var callback = this.extractCallback(args);
  3619. var payload = this.toPayload(args);
  3620. if (payload.value > 0 && !this._payable) {
  3621. throw new Error('Cannot send value to non-payable function');
  3622. }
  3623. if (!callback) {
  3624. return this._eth.sendTransaction(payload);
  3625. }
  3626. this._eth.sendTransaction(payload, callback);
  3627. };
  3628. /**
  3629. * Should be used to estimateGas of solidity function
  3630. *
  3631. * @method estimateGas
  3632. */
  3633. SolidityFunction.prototype.estimateGas = function () {
  3634. var args = Array.prototype.slice.call(arguments);
  3635. var callback = this.extractCallback(args);
  3636. var payload = this.toPayload(args);
  3637. if (!callback) {
  3638. return this._eth.estimateGas(payload);
  3639. }
  3640. this._eth.estimateGas(payload, callback);
  3641. };
  3642. /**
  3643. * Return the encoded data of the call
  3644. *
  3645. * @method getData
  3646. * @return {String} the encoded data
  3647. */
  3648. SolidityFunction.prototype.getData = function () {
  3649. var args = Array.prototype.slice.call(arguments);
  3650. var payload = this.toPayload(args);
  3651. return payload.data;
  3652. };
  3653. /**
  3654. * Should be used to get function display name
  3655. *
  3656. * @method displayName
  3657. * @return {String} display name of the function
  3658. */
  3659. SolidityFunction.prototype.displayName = function () {
  3660. return utils.extractDisplayName(this._name);
  3661. };
  3662. /**
  3663. * Should be used to get function type name
  3664. *
  3665. * @method typeName
  3666. * @return {String} type name of the function
  3667. */
  3668. SolidityFunction.prototype.typeName = function () {
  3669. return utils.extractTypeName(this._name);
  3670. };
  3671. /**
  3672. * Should be called to get rpc requests from solidity function
  3673. *
  3674. * @method request
  3675. * @returns {Object}
  3676. */
  3677. SolidityFunction.prototype.request = function () {
  3678. var args = Array.prototype.slice.call(arguments);
  3679. var callback = this.extractCallback(args);
  3680. var payload = this.toPayload(args);
  3681. var format = this.unpackOutput.bind(this);
  3682. return {
  3683. method: this._constant ? 'eth_call' : 'eth_sendTransaction',
  3684. callback: callback,
  3685. params: [payload],
  3686. format: format
  3687. };
  3688. };
  3689. /**
  3690. * Should be called to execute function
  3691. *
  3692. * @method execute
  3693. */
  3694. SolidityFunction.prototype.execute = function () {
  3695. var transaction = !this._constant;
  3696. // send transaction
  3697. if (transaction) {
  3698. return this.sendTransaction.apply(this, Array.prototype.slice.call(arguments));
  3699. }
  3700. // call
  3701. return this.call.apply(this, Array.prototype.slice.call(arguments));
  3702. };
  3703. /**
  3704. * Should be called to attach function to contract
  3705. *
  3706. * @method attachToContract
  3707. * @param {Contract}
  3708. */
  3709. SolidityFunction.prototype.attachToContract = function (contract) {
  3710. var execute = this.execute.bind(this);
  3711. execute.request = this.request.bind(this);
  3712. execute.call = this.call.bind(this);
  3713. execute.sendTransaction = this.sendTransaction.bind(this);
  3714. execute.estimateGas = this.estimateGas.bind(this);
  3715. execute.getData = this.getData.bind(this);
  3716. var displayName = this.displayName();
  3717. if (!contract[displayName]) {
  3718. contract[displayName] = execute;
  3719. }
  3720. contract[displayName][this.typeName()] = execute; // circular!!!!
  3721. };
  3722. module.exports = SolidityFunction;
  3723. },{"../solidity/coder":7,"../utils/sha3":19,"../utils/utils":20,"./errors":26,"./formatters":30}],32:[function(require,module,exports){
  3724. /*
  3725. This file is part of web3.js.
  3726. web3.js is free software: you can redistribute it and/or modify
  3727. it under the terms of the GNU Lesser General Public License as published by
  3728. the Free Software Foundation, either version 3 of the License, or
  3729. (at your option) any later version.
  3730. web3.js is distributed in the hope that it will be useful,
  3731. but WITHOUT ANY WARRANTY; without even the implied warranty of
  3732. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  3733. GNU Lesser General Public License for more details.
  3734. You should have received a copy of the GNU Lesser General Public License
  3735. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  3736. */
  3737. /** @file httpprovider.js
  3738. * @authors:
  3739. * Marek Kotewicz <marek@ethdev.com>
  3740. * Marian Oancea <marian@ethdev.com>
  3741. * Fabian Vogelsteller <fabian@ethdev.com>
  3742. * @date 2015
  3743. */
  3744. var errors = require('./errors');
  3745. // workaround to use httpprovider in different envs
  3746. // browser
  3747. if (typeof window !== 'undefined' && window.XMLHttpRequest) {
  3748. XMLHttpRequest = window.XMLHttpRequest; // jshint ignore: line
  3749. // node
  3750. } else {
  3751. XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest; // jshint ignore: line
  3752. }
  3753. var XHR2 = require('xhr2'); // jshint ignore: line
  3754. /**
  3755. * HttpProvider should be used to send rpc calls over http
  3756. */
  3757. var HttpProvider = function (host, timeout, user, password) {
  3758. this.host = host || 'http://localhost:8545';
  3759. this.timeout = timeout || 0;
  3760. this.user = user;
  3761. this.password = password;
  3762. };
  3763. /**
  3764. * Should be called to prepare new XMLHttpRequest
  3765. *
  3766. * @method prepareRequest
  3767. * @param {Boolean} true if request should be async
  3768. * @return {XMLHttpRequest} object
  3769. */
  3770. HttpProvider.prototype.prepareRequest = function (async) {
  3771. var request;
  3772. if (async) {
  3773. request = new XHR2();
  3774. request.timeout = this.timeout;
  3775. } else {
  3776. request = new XMLHttpRequest();
  3777. }
  3778. request.open('POST', this.host, async);
  3779. if (this.user && this.password) {
  3780. var auth = 'Basic ' + new Buffer(this.user + ':' + this.password).toString('base64');
  3781. request.setRequestHeader('Authorization', auth);
  3782. } request.setRequestHeader('Content-Type', 'application/json');
  3783. return request;
  3784. };
  3785. /**
  3786. * Should be called to make sync request
  3787. *
  3788. * @method send
  3789. * @param {Object} payload
  3790. * @return {Object} result
  3791. */
  3792. HttpProvider.prototype.send = function (payload) {
  3793. var request = this.prepareRequest(false);
  3794. try {
  3795. request.send(JSON.stringify(payload));
  3796. } catch (error) {
  3797. throw errors.InvalidConnection(this.host);
  3798. }
  3799. var result = request.responseText;
  3800. try {
  3801. result = JSON.parse(result);
  3802. } catch (e) {
  3803. throw errors.InvalidResponse(request.responseText);
  3804. }
  3805. return result;
  3806. };
  3807. /**
  3808. * Should be used to make async request
  3809. *
  3810. * @method sendAsync
  3811. * @param {Object} payload
  3812. * @param {Function} callback triggered on end with (err, result)
  3813. */
  3814. HttpProvider.prototype.sendAsync = function (payload, callback) {
  3815. var request = this.prepareRequest(true);
  3816. request.onreadystatechange = function () {
  3817. if (request.readyState === 4 && request.timeout !== 1) {
  3818. var result = request.responseText;
  3819. var error = null;
  3820. try {
  3821. result = JSON.parse(result);
  3822. } catch (e) {
  3823. error = errors.InvalidResponse(request.responseText);
  3824. }
  3825. callback(error, result);
  3826. }
  3827. };
  3828. request.ontimeout = function () {
  3829. callback(errors.ConnectionTimeout(this.timeout));
  3830. };
  3831. try {
  3832. request.send(JSON.stringify(payload));
  3833. } catch (error) {
  3834. callback(errors.InvalidConnection(this.host));
  3835. }
  3836. };
  3837. /**
  3838. * Synchronously tries to make Http request
  3839. *
  3840. * @method isConnected
  3841. * @return {Boolean} returns true if request haven't failed. Otherwise false
  3842. */
  3843. HttpProvider.prototype.isConnected = function () {
  3844. try {
  3845. this.send({
  3846. id: 9999999999,
  3847. jsonrpc: '2.0',
  3848. method: 'net_listening',
  3849. params: []
  3850. });
  3851. return true;
  3852. } catch (e) {
  3853. return false;
  3854. }
  3855. };
  3856. module.exports = HttpProvider;
  3857. },{"./errors":26,"xhr2":86,"xmlhttprequest":17}],33:[function(require,module,exports){
  3858. /*
  3859. This file is part of web3.js.
  3860. web3.js is free software: you can redistribute it and/or modify
  3861. it under the terms of the GNU Lesser General Public License as published by
  3862. the Free Software Foundation, either version 3 of the License, or
  3863. (at your option) any later version.
  3864. web3.js is distributed in the hope that it will be useful,
  3865. but WITHOUT ANY WARRANTY; without even the implied warranty of
  3866. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  3867. GNU Lesser General Public License for more details.
  3868. You should have received a copy of the GNU Lesser General Public License
  3869. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  3870. */
  3871. /**
  3872. * @file iban.js
  3873. * @author Marek Kotewicz <marek@ethdev.com>
  3874. * @date 2015
  3875. */
  3876. var BigNumber = require('bignumber.js');
  3877. var padLeft = function (string, bytes) {
  3878. var result = string;
  3879. while (result.length < bytes * 2) {
  3880. result = '0' + result;
  3881. }
  3882. return result;
  3883. };
  3884. /**
  3885. * Prepare an IBAN for mod 97 computation by moving the first 4 chars to the end and transforming the letters to
  3886. * numbers (A = 10, B = 11, ..., Z = 35), as specified in ISO13616.
  3887. *
  3888. * @method iso13616Prepare
  3889. * @param {String} iban the IBAN
  3890. * @returns {String} the prepared IBAN
  3891. */
  3892. var iso13616Prepare = function (iban) {
  3893. var A = 'A'.charCodeAt(0);
  3894. var Z = 'Z'.charCodeAt(0);
  3895. iban = iban.toUpperCase();
  3896. iban = iban.substr(4) + iban.substr(0,4);
  3897. return iban.split('').map(function(n){
  3898. var code = n.charCodeAt(0);
  3899. if (code >= A && code <= Z){
  3900. // A = 10, B = 11, ... Z = 35
  3901. return code - A + 10;
  3902. } else {
  3903. return n;
  3904. }
  3905. }).join('');
  3906. };
  3907. /**
  3908. * Calculates the MOD 97 10 of the passed IBAN as specified in ISO7064.
  3909. *
  3910. * @method mod9710
  3911. * @param {String} iban
  3912. * @returns {Number}
  3913. */
  3914. var mod9710 = function (iban) {
  3915. var remainder = iban,
  3916. block;
  3917. while (remainder.length > 2){
  3918. block = remainder.slice(0, 9);
  3919. remainder = parseInt(block, 10) % 97 + remainder.slice(block.length);
  3920. }
  3921. return parseInt(remainder, 10) % 97;
  3922. };
  3923. /**
  3924. * This prototype should be used to create iban object from iban correct string
  3925. *
  3926. * @param {String} iban
  3927. */
  3928. var Iban = function (iban) {
  3929. this._iban = iban;
  3930. };
  3931. /**
  3932. * This method should be used to create iban object from ethereum address
  3933. *
  3934. * @method fromAddress
  3935. * @param {String} address
  3936. * @return {Iban} the IBAN object
  3937. */
  3938. Iban.fromAddress = function (address) {
  3939. var asBn = new BigNumber(address, 16);
  3940. var base36 = asBn.toString(36);
  3941. var padded = padLeft(base36, 15);
  3942. return Iban.fromBban(padded.toUpperCase());
  3943. };
  3944. /**
  3945. * Convert the passed BBAN to an IBAN for this country specification.
  3946. * Please note that <i>"generation of the IBAN shall be the exclusive responsibility of the bank/branch servicing the account"</i>.
  3947. * This method implements the preferred algorithm described in http://en.wikipedia.org/wiki/International_Bank_Account_Number#Generating_IBAN_check_digits
  3948. *
  3949. * @method fromBban
  3950. * @param {String} bban the BBAN to convert to IBAN
  3951. * @returns {Iban} the IBAN object
  3952. */
  3953. Iban.fromBban = function (bban) {
  3954. var countryCode = 'XE';
  3955. var remainder = mod9710(iso13616Prepare(countryCode + '00' + bban));
  3956. var checkDigit = ('0' + (98 - remainder)).slice(-2);
  3957. return new Iban(countryCode + checkDigit + bban);
  3958. };
  3959. /**
  3960. * Should be used to create IBAN object for given institution and identifier
  3961. *
  3962. * @method createIndirect
  3963. * @param {Object} options, required options are "institution" and "identifier"
  3964. * @return {Iban} the IBAN object
  3965. */
  3966. Iban.createIndirect = function (options) {
  3967. return Iban.fromBban('ETH' + options.institution + options.identifier);
  3968. };
  3969. /**
  3970. * Thos method should be used to check if given string is valid iban object
  3971. *
  3972. * @method isValid
  3973. * @param {String} iban string
  3974. * @return {Boolean} true if it is valid IBAN
  3975. */
  3976. Iban.isValid = function (iban) {
  3977. var i = new Iban(iban);
  3978. return i.isValid();
  3979. };
  3980. /**
  3981. * Should be called to check if iban is correct
  3982. *
  3983. * @method isValid
  3984. * @returns {Boolean} true if it is, otherwise false
  3985. */
  3986. Iban.prototype.isValid = function () {
  3987. return /^XE[0-9]{2}(ETH[0-9A-Z]{13}|[0-9A-Z]{30,31})$/.test(this._iban) &&
  3988. mod9710(iso13616Prepare(this._iban)) === 1;
  3989. };
  3990. /**
  3991. * Should be called to check if iban number is direct
  3992. *
  3993. * @method isDirect
  3994. * @returns {Boolean} true if it is, otherwise false
  3995. */
  3996. Iban.prototype.isDirect = function () {
  3997. return this._iban.length === 34 || this._iban.length === 35;
  3998. };
  3999. /**
  4000. * Should be called to check if iban number if indirect
  4001. *
  4002. * @method isIndirect
  4003. * @returns {Boolean} true if it is, otherwise false
  4004. */
  4005. Iban.prototype.isIndirect = function () {
  4006. return this._iban.length === 20;
  4007. };
  4008. /**
  4009. * Should be called to get iban checksum
  4010. * Uses the mod-97-10 checksumming protocol (ISO/IEC 7064:2003)
  4011. *
  4012. * @method checksum
  4013. * @returns {String} checksum
  4014. */
  4015. Iban.prototype.checksum = function () {
  4016. return this._iban.substr(2, 2);
  4017. };
  4018. /**
  4019. * Should be called to get institution identifier
  4020. * eg. XREG
  4021. *
  4022. * @method institution
  4023. * @returns {String} institution identifier
  4024. */
  4025. Iban.prototype.institution = function () {
  4026. return this.isIndirect() ? this._iban.substr(7, 4) : '';
  4027. };
  4028. /**
  4029. * Should be called to get client identifier within institution
  4030. * eg. GAVOFYORK
  4031. *
  4032. * @method client
  4033. * @returns {String} client identifier
  4034. */
  4035. Iban.prototype.client = function () {
  4036. return this.isIndirect() ? this._iban.substr(11) : '';
  4037. };
  4038. /**
  4039. * Should be called to get client direct address
  4040. *
  4041. * @method address
  4042. * @returns {String} client direct address
  4043. */
  4044. Iban.prototype.address = function () {
  4045. if (this.isDirect()) {
  4046. var base36 = this._iban.substr(4);
  4047. var asBn = new BigNumber(base36, 36);
  4048. return padLeft(asBn.toString(16), 20);
  4049. }
  4050. return '';
  4051. };
  4052. Iban.prototype.toString = function () {
  4053. return this._iban;
  4054. };
  4055. module.exports = Iban;
  4056. },{"bignumber.js":"bignumber.js"}],34:[function(require,module,exports){
  4057. /*
  4058. This file is part of web3.js.
  4059. web3.js is free software: you can redistribute it and/or modify
  4060. it under the terms of the GNU Lesser General Public License as published by
  4061. the Free Software Foundation, either version 3 of the License, or
  4062. (at your option) any later version.
  4063. web3.js is distributed in the hope that it will be useful,
  4064. but WITHOUT ANY WARRANTY; without even the implied warranty of
  4065. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  4066. GNU Lesser General Public License for more details.
  4067. You should have received a copy of the GNU Lesser General Public License
  4068. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  4069. */
  4070. /** @file ipcprovider.js
  4071. * @authors:
  4072. * Fabian Vogelsteller <fabian@ethdev.com>
  4073. * @date 2015
  4074. */
  4075. "use strict";
  4076. var utils = require('../utils/utils');
  4077. var errors = require('./errors');
  4078. var IpcProvider = function (path, net) {
  4079. var _this = this;
  4080. this.responseCallbacks = {};
  4081. this.path = path;
  4082. this.connection = net.connect({path: this.path});
  4083. this.connection.on('error', function(e){
  4084. console.error('IPC Connection Error', e);
  4085. _this._timeout();
  4086. });
  4087. this.connection.on('end', function(){
  4088. _this._timeout();
  4089. });
  4090. // LISTEN FOR CONNECTION RESPONSES
  4091. this.connection.on('data', function(data) {
  4092. /*jshint maxcomplexity: 6 */
  4093. _this._parseResponse(data.toString()).forEach(function(result){
  4094. var id = null;
  4095. // get the id which matches the returned id
  4096. if(utils.isArray(result)) {
  4097. result.forEach(function(load){
  4098. if(_this.responseCallbacks[load.id])
  4099. id = load.id;
  4100. });
  4101. } else {
  4102. id = result.id;
  4103. }
  4104. // fire the callback
  4105. if(_this.responseCallbacks[id]) {
  4106. _this.responseCallbacks[id](null, result);
  4107. delete _this.responseCallbacks[id];
  4108. }
  4109. });
  4110. });
  4111. };
  4112. /**
  4113. Will parse the response and make an array out of it.
  4114. @method _parseResponse
  4115. @param {String} data
  4116. */
  4117. IpcProvider.prototype._parseResponse = function(data) {
  4118. var _this = this,
  4119. returnValues = [];
  4120. // DE-CHUNKER
  4121. var dechunkedData = data
  4122. .replace(/\}[\n\r]?\{/g,'}|--|{') // }{
  4123. .replace(/\}\][\n\r]?\[\{/g,'}]|--|[{') // }][{
  4124. .replace(/\}[\n\r]?\[\{/g,'}|--|[{') // }[{
  4125. .replace(/\}\][\n\r]?\{/g,'}]|--|{') // }]{
  4126. .split('|--|');
  4127. dechunkedData.forEach(function(data){
  4128. // prepend the last chunk
  4129. if(_this.lastChunk)
  4130. data = _this.lastChunk + data;
  4131. var result = null;
  4132. try {
  4133. result = JSON.parse(data);
  4134. } catch(e) {
  4135. _this.lastChunk = data;
  4136. // start timeout to cancel all requests
  4137. clearTimeout(_this.lastChunkTimeout);
  4138. _this.lastChunkTimeout = setTimeout(function(){
  4139. _this._timeout();
  4140. throw errors.InvalidResponse(data);
  4141. }, 1000 * 15);
  4142. return;
  4143. }
  4144. // cancel timeout and set chunk to null
  4145. clearTimeout(_this.lastChunkTimeout);
  4146. _this.lastChunk = null;
  4147. if(result)
  4148. returnValues.push(result);
  4149. });
  4150. return returnValues;
  4151. };
  4152. /**
  4153. Get the adds a callback to the responseCallbacks object,
  4154. which will be called if a response matching the response Id will arrive.
  4155. @method _addResponseCallback
  4156. */
  4157. IpcProvider.prototype._addResponseCallback = function(payload, callback) {
  4158. var id = payload.id || payload[0].id;
  4159. var method = payload.method || payload[0].method;
  4160. this.responseCallbacks[id] = callback;
  4161. this.responseCallbacks[id].method = method;
  4162. };
  4163. /**
  4164. Timeout all requests when the end/error event is fired
  4165. @method _timeout
  4166. */
  4167. IpcProvider.prototype._timeout = function() {
  4168. for(var key in this.responseCallbacks) {
  4169. if(this.responseCallbacks.hasOwnProperty(key)){
  4170. this.responseCallbacks[key](errors.InvalidConnection('on IPC'));
  4171. delete this.responseCallbacks[key];
  4172. }
  4173. }
  4174. };
  4175. /**
  4176. Check if the current connection is still valid.
  4177. @method isConnected
  4178. */
  4179. IpcProvider.prototype.isConnected = function() {
  4180. var _this = this;
  4181. // try reconnect, when connection is gone
  4182. if(!_this.connection.writable)
  4183. _this.connection.connect({path: _this.path});
  4184. return !!this.connection.writable;
  4185. };
  4186. IpcProvider.prototype.send = function (payload) {
  4187. if(this.connection.writeSync) {
  4188. var result;
  4189. // try reconnect, when connection is gone
  4190. if(!this.connection.writable)
  4191. this.connection.connect({path: this.path});
  4192. var data = this.connection.writeSync(JSON.stringify(payload));
  4193. try {
  4194. result = JSON.parse(data);
  4195. } catch(e) {
  4196. throw errors.InvalidResponse(data);
  4197. }
  4198. return result;
  4199. } else {
  4200. throw new Error('You tried to send "'+ payload.method +'" synchronously. Synchronous requests are not supported by the IPC provider.');
  4201. }
  4202. };
  4203. IpcProvider.prototype.sendAsync = function (payload, callback) {
  4204. // try reconnect, when connection is gone
  4205. if(!this.connection.writable)
  4206. this.connection.connect({path: this.path});
  4207. this.connection.write(JSON.stringify(payload));
  4208. this._addResponseCallback(payload, callback);
  4209. };
  4210. module.exports = IpcProvider;
  4211. },{"../utils/utils":20,"./errors":26}],35:[function(require,module,exports){
  4212. /*
  4213. This file is part of web3.js.
  4214. web3.js is free software: you can redistribute it and/or modify
  4215. it under the terms of the GNU Lesser General Public License as published by
  4216. the Free Software Foundation, either version 3 of the License, or
  4217. (at your option) any later version.
  4218. web3.js is distributed in the hope that it will be useful,
  4219. but WITHOUT ANY WARRANTY; without even the implied warranty of
  4220. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  4221. GNU Lesser General Public License for more details.
  4222. You should have received a copy of the GNU Lesser General Public License
  4223. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  4224. */
  4225. /** @file jsonrpc.js
  4226. * @authors:
  4227. * Marek Kotewicz <marek@ethdev.com>
  4228. * Aaron Kumavis <aaron@kumavis.me>
  4229. * @date 2015
  4230. */
  4231. // Initialize Jsonrpc as a simple object with utility functions.
  4232. var Jsonrpc = {
  4233. messageId: 0
  4234. };
  4235. /**
  4236. * Should be called to valid json create payload object
  4237. *
  4238. * @method toPayload
  4239. * @param {Function} method of jsonrpc call, required
  4240. * @param {Array} params, an array of method params, optional
  4241. * @returns {Object} valid jsonrpc payload object
  4242. */
  4243. Jsonrpc.toPayload = function (method, params) {
  4244. if (!method)
  4245. console.error('jsonrpc method should be specified!');
  4246. // advance message ID
  4247. Jsonrpc.messageId++;
  4248. return {
  4249. jsonrpc: '2.0',
  4250. id: Jsonrpc.messageId,
  4251. method: method,
  4252. params: params || []
  4253. };
  4254. };
  4255. /**
  4256. * Should be called to check if jsonrpc response is valid
  4257. *
  4258. * @method isValidResponse
  4259. * @param {Object}
  4260. * @returns {Boolean} true if response is valid, otherwise false
  4261. */
  4262. Jsonrpc.isValidResponse = function (response) {
  4263. return Array.isArray(response) ? response.every(validateSingleMessage) : validateSingleMessage(response);
  4264. function validateSingleMessage(message){
  4265. return !!message &&
  4266. !message.error &&
  4267. message.jsonrpc === '2.0' &&
  4268. typeof message.id === 'number' &&
  4269. message.result !== undefined; // only undefined is not valid json object
  4270. }
  4271. };
  4272. /**
  4273. * Should be called to create batch payload object
  4274. *
  4275. * @method toBatchPayload
  4276. * @param {Array} messages, an array of objects with method (required) and params (optional) fields
  4277. * @returns {Array} batch payload
  4278. */
  4279. Jsonrpc.toBatchPayload = function (messages) {
  4280. return messages.map(function (message) {
  4281. return Jsonrpc.toPayload(message.method, message.params);
  4282. });
  4283. };
  4284. module.exports = Jsonrpc;
  4285. },{}],36:[function(require,module,exports){
  4286. /*
  4287. This file is part of web3.js.
  4288. web3.js is free software: you can redistribute it and/or modify
  4289. it under the terms of the GNU Lesser General Public License as published by
  4290. the Free Software Foundation, either version 3 of the License, or
  4291. (at your option) any later version.
  4292. web3.js is distributed in the hope that it will be useful,
  4293. but WITHOUT ANY WARRANTY; without even the implied warranty of
  4294. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  4295. GNU Lesser General Public License for more details.
  4296. You should have received a copy of the GNU Lesser General Public License
  4297. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  4298. */
  4299. /**
  4300. * @file method.js
  4301. * @author Marek Kotewicz <marek@ethdev.com>
  4302. * @date 2015
  4303. */
  4304. var utils = require('../utils/utils');
  4305. var errors = require('./errors');
  4306. var Method = function (options) {
  4307. this.name = options.name;
  4308. this.call = options.call;
  4309. this.params = options.params || 0;
  4310. this.inputFormatter = options.inputFormatter;
  4311. this.outputFormatter = options.outputFormatter;
  4312. this.requestManager = null;
  4313. };
  4314. Method.prototype.setRequestManager = function (rm) {
  4315. this.requestManager = rm;
  4316. };
  4317. /**
  4318. * Should be used to determine name of the jsonrpc method based on arguments
  4319. *
  4320. * @method getCall
  4321. * @param {Array} arguments
  4322. * @return {String} name of jsonrpc method
  4323. */
  4324. Method.prototype.getCall = function (args) {
  4325. return utils.isFunction(this.call) ? this.call(args) : this.call;
  4326. };
  4327. /**
  4328. * Should be used to extract callback from array of arguments. Modifies input param
  4329. *
  4330. * @method extractCallback
  4331. * @param {Array} arguments
  4332. * @return {Function|Null} callback, if exists
  4333. */
  4334. Method.prototype.extractCallback = function (args) {
  4335. if (utils.isFunction(args[args.length - 1])) {
  4336. return args.pop(); // modify the args array!
  4337. }
  4338. };
  4339. /**
  4340. * Should be called to check if the number of arguments is correct
  4341. *
  4342. * @method validateArgs
  4343. * @param {Array} arguments
  4344. * @throws {Error} if it is not
  4345. */
  4346. Method.prototype.validateArgs = function (args) {
  4347. if (args.length !== this.params) {
  4348. throw errors.InvalidNumberOfRPCParams();
  4349. }
  4350. };
  4351. /**
  4352. * Should be called to format input args of method
  4353. *
  4354. * @method formatInput
  4355. * @param {Array}
  4356. * @return {Array}
  4357. */
  4358. Method.prototype.formatInput = function (args) {
  4359. if (!this.inputFormatter) {
  4360. return args;
  4361. }
  4362. return this.inputFormatter.map(function (formatter, index) {
  4363. return formatter ? formatter(args[index]) : args[index];
  4364. });
  4365. };
  4366. /**
  4367. * Should be called to format output(result) of method
  4368. *
  4369. * @method formatOutput
  4370. * @param {Object}
  4371. * @return {Object}
  4372. */
  4373. Method.prototype.formatOutput = function (result) {
  4374. return this.outputFormatter && result ? this.outputFormatter(result) : result;
  4375. };
  4376. /**
  4377. * Should create payload from given input args
  4378. *
  4379. * @method toPayload
  4380. * @param {Array} args
  4381. * @return {Object}
  4382. */
  4383. Method.prototype.toPayload = function (args) {
  4384. var call = this.getCall(args);
  4385. var callback = this.extractCallback(args);
  4386. var params = this.formatInput(args);
  4387. this.validateArgs(params);
  4388. return {
  4389. method: call,
  4390. params: params,
  4391. callback: callback
  4392. };
  4393. };
  4394. Method.prototype.attachToObject = function (obj) {
  4395. var func = this.buildCall();
  4396. func.call = this.call; // TODO!!! that's ugly. filter.js uses it
  4397. var name = this.name.split('.');
  4398. if (name.length > 1) {
  4399. obj[name[0]] = obj[name[0]] || {};
  4400. obj[name[0]][name[1]] = func;
  4401. } else {
  4402. obj[name[0]] = func;
  4403. }
  4404. };
  4405. Method.prototype.buildCall = function() {
  4406. var method = this;
  4407. var send = function () {
  4408. var payload = method.toPayload(Array.prototype.slice.call(arguments));
  4409. if (payload.callback) {
  4410. return method.requestManager.sendAsync(payload, function (err, result) {
  4411. payload.callback(err, method.formatOutput(result));
  4412. });
  4413. }
  4414. return method.formatOutput(method.requestManager.send(payload));
  4415. };
  4416. send.request = this.request.bind(this);
  4417. return send;
  4418. };
  4419. /**
  4420. * Should be called to create pure JSONRPC request which can be used in batch request
  4421. *
  4422. * @method request
  4423. * @param {...} params
  4424. * @return {Object} jsonrpc request
  4425. */
  4426. Method.prototype.request = function () {
  4427. var payload = this.toPayload(Array.prototype.slice.call(arguments));
  4428. payload.format = this.formatOutput.bind(this);
  4429. return payload;
  4430. };
  4431. module.exports = Method;
  4432. },{"../utils/utils":20,"./errors":26}],37:[function(require,module,exports){
  4433. /*
  4434. This file is part of web3.js.
  4435. web3.js is free software: you can redistribute it and/or modify
  4436. it under the terms of the GNU Lesser General Public License as published by
  4437. the Free Software Foundation, either version 3 of the License, or
  4438. (at your option) any later version.
  4439. web3.js is distributed in the hope that it will be useful,
  4440. but WITHOUT ANY WARRANTY; without even the implied warranty of
  4441. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  4442. GNU Lesser General Public License for more details.
  4443. You should have received a copy of the GNU Lesser General Public License
  4444. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  4445. */
  4446. /** @file db.js
  4447. * @authors:
  4448. * Marek Kotewicz <marek@ethdev.com>
  4449. * @date 2015
  4450. */
  4451. var Method = require('../method');
  4452. var DB = function (web3) {
  4453. this._requestManager = web3._requestManager;
  4454. var self = this;
  4455. methods().forEach(function(method) {
  4456. method.attachToObject(self);
  4457. method.setRequestManager(web3._requestManager);
  4458. });
  4459. };
  4460. var methods = function () {
  4461. var putString = new Method({
  4462. name: 'putString',
  4463. call: 'db_putString',
  4464. params: 3
  4465. });
  4466. var getString = new Method({
  4467. name: 'getString',
  4468. call: 'db_getString',
  4469. params: 2
  4470. });
  4471. var putHex = new Method({
  4472. name: 'putHex',
  4473. call: 'db_putHex',
  4474. params: 3
  4475. });
  4476. var getHex = new Method({
  4477. name: 'getHex',
  4478. call: 'db_getHex',
  4479. params: 2
  4480. });
  4481. return [
  4482. putString, getString, putHex, getHex
  4483. ];
  4484. };
  4485. module.exports = DB;
  4486. },{"../method":36}],38:[function(require,module,exports){
  4487. /*
  4488. This file is part of web3.js.
  4489. web3.js is free software: you can redistribute it and/or modify
  4490. it under the terms of the GNU Lesser General Public License as published by
  4491. the Free Software Foundation, either version 3 of the License, or
  4492. (at your option) any later version.
  4493. web3.js is distributed in the hope that it will be useful,
  4494. but WITHOUT ANY WARRANTY; without even the implied warranty of
  4495. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  4496. GNU Lesser General Public License for more details.
  4497. You should have received a copy of the GNU Lesser General Public License
  4498. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  4499. */
  4500. /**
  4501. * @file eth.js
  4502. * @author Marek Kotewicz <marek@ethdev.com>
  4503. * @author Fabian Vogelsteller <fabian@ethdev.com>
  4504. * @date 2015
  4505. */
  4506. "use strict";
  4507. var formatters = require('../formatters');
  4508. var utils = require('../../utils/utils');
  4509. var Method = require('../method');
  4510. var Property = require('../property');
  4511. var c = require('../../utils/config');
  4512. var Contract = require('../contract');
  4513. var watches = require('./watches');
  4514. var Filter = require('../filter');
  4515. var IsSyncing = require('../syncing');
  4516. var namereg = require('../namereg');
  4517. var Iban = require('../iban');
  4518. var transfer = require('../transfer');
  4519. var blockCall = function (args) {
  4520. return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? "eth_getBlockByHash" : "eth_getBlockByNumber";
  4521. };
  4522. var transactionFromBlockCall = function (args) {
  4523. return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getTransactionByBlockHashAndIndex' : 'eth_getTransactionByBlockNumberAndIndex';
  4524. };
  4525. var uncleCall = function (args) {
  4526. return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getUncleByBlockHashAndIndex' : 'eth_getUncleByBlockNumberAndIndex';
  4527. };
  4528. var getBlockTransactionCountCall = function (args) {
  4529. return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getBlockTransactionCountByHash' : 'eth_getBlockTransactionCountByNumber';
  4530. };
  4531. var uncleCountCall = function (args) {
  4532. return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getUncleCountByBlockHash' : 'eth_getUncleCountByBlockNumber';
  4533. };
  4534. function Eth(web3) {
  4535. this._requestManager = web3._requestManager;
  4536. var self = this;
  4537. methods().forEach(function(method) {
  4538. method.attachToObject(self);
  4539. method.setRequestManager(self._requestManager);
  4540. });
  4541. properties().forEach(function(p) {
  4542. p.attachToObject(self);
  4543. p.setRequestManager(self._requestManager);
  4544. });
  4545. this.iban = Iban;
  4546. this.sendIBANTransaction = transfer.bind(null, this);
  4547. }
  4548. Object.defineProperty(Eth.prototype, 'defaultBlock', {
  4549. get: function () {
  4550. return c.defaultBlock;
  4551. },
  4552. set: function (val) {
  4553. c.defaultBlock = val;
  4554. return val;
  4555. }
  4556. });
  4557. Object.defineProperty(Eth.prototype, 'defaultAccount', {
  4558. get: function () {
  4559. return c.defaultAccount;
  4560. },
  4561. set: function (val) {
  4562. c.defaultAccount = val;
  4563. return val;
  4564. }
  4565. });
  4566. var methods = function () {
  4567. var getBalance = new Method({
  4568. name: 'getBalance',
  4569. call: 'eth_getBalance',
  4570. params: 2,
  4571. inputFormatter: [formatters.inputAddressFormatter, formatters.inputDefaultBlockNumberFormatter],
  4572. outputFormatter: formatters.outputBigNumberFormatter
  4573. });
  4574. var getStorageAt = new Method({
  4575. name: 'getStorageAt',
  4576. call: 'eth_getStorageAt',
  4577. params: 3,
  4578. inputFormatter: [null, utils.toHex, formatters.inputDefaultBlockNumberFormatter]
  4579. });
  4580. var getCode = new Method({
  4581. name: 'getCode',
  4582. call: 'eth_getCode',
  4583. params: 2,
  4584. inputFormatter: [formatters.inputAddressFormatter, formatters.inputDefaultBlockNumberFormatter]
  4585. });
  4586. var getBlock = new Method({
  4587. name: 'getBlock',
  4588. call: blockCall,
  4589. params: 2,
  4590. inputFormatter: [formatters.inputBlockNumberFormatter, function (val) { return !!val; }],
  4591. outputFormatter: formatters.outputBlockFormatter
  4592. });
  4593. var getUncle = new Method({
  4594. name: 'getUncle',
  4595. call: uncleCall,
  4596. params: 2,
  4597. inputFormatter: [formatters.inputBlockNumberFormatter, utils.toHex],
  4598. outputFormatter: formatters.outputBlockFormatter,
  4599. });
  4600. var getCompilers = new Method({
  4601. name: 'getCompilers',
  4602. call: 'eth_getCompilers',
  4603. params: 0
  4604. });
  4605. var getBlockTransactionCount = new Method({
  4606. name: 'getBlockTransactionCount',
  4607. call: getBlockTransactionCountCall,
  4608. params: 1,
  4609. inputFormatter: [formatters.inputBlockNumberFormatter],
  4610. outputFormatter: utils.toDecimal
  4611. });
  4612. var getBlockUncleCount = new Method({
  4613. name: 'getBlockUncleCount',
  4614. call: uncleCountCall,
  4615. params: 1,
  4616. inputFormatter: [formatters.inputBlockNumberFormatter],
  4617. outputFormatter: utils.toDecimal
  4618. });
  4619. var getTransaction = new Method({
  4620. name: 'getTransaction',
  4621. call: 'eth_getTransactionByHash',
  4622. params: 1,
  4623. outputFormatter: formatters.outputTransactionFormatter
  4624. });
  4625. var getTransactionFromBlock = new Method({
  4626. name: 'getTransactionFromBlock',
  4627. call: transactionFromBlockCall,
  4628. params: 2,
  4629. inputFormatter: [formatters.inputBlockNumberFormatter, utils.toHex],
  4630. outputFormatter: formatters.outputTransactionFormatter
  4631. });
  4632. var getTransactionReceipt = new Method({
  4633. name: 'getTransactionReceipt',
  4634. call: 'eth_getTransactionReceipt',
  4635. params: 1,
  4636. outputFormatter: formatters.outputTransactionReceiptFormatter
  4637. });
  4638. var getTransactionCount = new Method({
  4639. name: 'getTransactionCount',
  4640. call: 'eth_getTransactionCount',
  4641. params: 2,
  4642. inputFormatter: [null, formatters.inputDefaultBlockNumberFormatter],
  4643. outputFormatter: utils.toDecimal
  4644. });
  4645. var sendRawTransaction = new Method({
  4646. name: 'sendRawTransaction',
  4647. call: 'eth_sendRawTransaction',
  4648. params: 1,
  4649. inputFormatter: [null]
  4650. });
  4651. var sendTransaction = new Method({
  4652. name: 'sendTransaction',
  4653. call: 'eth_sendTransaction',
  4654. params: 1,
  4655. inputFormatter: [formatters.inputTransactionFormatter]
  4656. });
  4657. var signTransaction = new Method({
  4658. name: 'signTransaction',
  4659. call: 'eth_signTransaction',
  4660. params: 1,
  4661. inputFormatter: [formatters.inputTransactionFormatter]
  4662. });
  4663. var sign = new Method({
  4664. name: 'sign',
  4665. call: 'eth_sign',
  4666. params: 2,
  4667. inputFormatter: [formatters.inputAddressFormatter, null]
  4668. });
  4669. var call = new Method({
  4670. name: 'call',
  4671. call: 'eth_call',
  4672. params: 2,
  4673. inputFormatter: [formatters.inputCallFormatter, formatters.inputDefaultBlockNumberFormatter]
  4674. });
  4675. var estimateGas = new Method({
  4676. name: 'estimateGas',
  4677. call: 'eth_estimateGas',
  4678. params: 1,
  4679. inputFormatter: [formatters.inputCallFormatter],
  4680. outputFormatter: utils.toDecimal
  4681. });
  4682. var compileSolidity = new Method({
  4683. name: 'compile.solidity',
  4684. call: 'eth_compileSolidity',
  4685. params: 1
  4686. });
  4687. var compileLLL = new Method({
  4688. name: 'compile.lll',
  4689. call: 'eth_compileLLL',
  4690. params: 1
  4691. });
  4692. var compileSerpent = new Method({
  4693. name: 'compile.serpent',
  4694. call: 'eth_compileSerpent',
  4695. params: 1
  4696. });
  4697. var submitWork = new Method({
  4698. name: 'submitWork',
  4699. call: 'eth_submitWork',
  4700. params: 3
  4701. });
  4702. var getWork = new Method({
  4703. name: 'getWork',
  4704. call: 'eth_getWork',
  4705. params: 0
  4706. });
  4707. return [
  4708. getBalance,
  4709. getStorageAt,
  4710. getCode,
  4711. getBlock,
  4712. getUncle,
  4713. getCompilers,
  4714. getBlockTransactionCount,
  4715. getBlockUncleCount,
  4716. getTransaction,
  4717. getTransactionFromBlock,
  4718. getTransactionReceipt,
  4719. getTransactionCount,
  4720. call,
  4721. estimateGas,
  4722. sendRawTransaction,
  4723. signTransaction,
  4724. sendTransaction,
  4725. sign,
  4726. compileSolidity,
  4727. compileLLL,
  4728. compileSerpent,
  4729. submitWork,
  4730. getWork
  4731. ];
  4732. };
  4733. var properties = function () {
  4734. return [
  4735. new Property({
  4736. name: 'coinbase',
  4737. getter: 'eth_coinbase'
  4738. }),
  4739. new Property({
  4740. name: 'mining',
  4741. getter: 'eth_mining'
  4742. }),
  4743. new Property({
  4744. name: 'hashrate',
  4745. getter: 'eth_hashrate',
  4746. outputFormatter: utils.toDecimal
  4747. }),
  4748. new Property({
  4749. name: 'syncing',
  4750. getter: 'eth_syncing',
  4751. outputFormatter: formatters.outputSyncingFormatter
  4752. }),
  4753. new Property({
  4754. name: 'gasPrice',
  4755. getter: 'eth_gasPrice',
  4756. outputFormatter: formatters.outputBigNumberFormatter
  4757. }),
  4758. new Property({
  4759. name: 'accounts',
  4760. getter: 'eth_accounts'
  4761. }),
  4762. new Property({
  4763. name: 'blockNumber',
  4764. getter: 'eth_blockNumber',
  4765. outputFormatter: utils.toDecimal
  4766. }),
  4767. new Property({
  4768. name: 'protocolVersion',
  4769. getter: 'eth_protocolVersion'
  4770. })
  4771. ];
  4772. };
  4773. Eth.prototype.contract = function (abi) {
  4774. var factory = new Contract(this, abi);
  4775. return factory;
  4776. };
  4777. Eth.prototype.filter = function (options, callback, filterCreationErrorCallback) {
  4778. return new Filter(options, 'eth', this._requestManager, watches.eth(), formatters.outputLogFormatter, callback, filterCreationErrorCallback);
  4779. };
  4780. Eth.prototype.namereg = function () {
  4781. return this.contract(namereg.global.abi).at(namereg.global.address);
  4782. };
  4783. Eth.prototype.icapNamereg = function () {
  4784. return this.contract(namereg.icap.abi).at(namereg.icap.address);
  4785. };
  4786. Eth.prototype.isSyncing = function (callback) {
  4787. return new IsSyncing(this._requestManager, callback);
  4788. };
  4789. module.exports = Eth;
  4790. },{"../../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){
  4791. /*
  4792. This file is part of web3.js.
  4793. web3.js is free software: you can redistribute it and/or modify
  4794. it under the terms of the GNU Lesser General Public License as published by
  4795. the Free Software Foundation, either version 3 of the License, or
  4796. (at your option) any later version.
  4797. web3.js is distributed in the hope that it will be useful,
  4798. but WITHOUT ANY WARRANTY; without even the implied warranty of
  4799. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  4800. GNU Lesser General Public License for more details.
  4801. You should have received a copy of the GNU Lesser General Public License
  4802. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  4803. */
  4804. /** @file eth.js
  4805. * @authors:
  4806. * Marek Kotewicz <marek@ethdev.com>
  4807. * @date 2015
  4808. */
  4809. var utils = require('../../utils/utils');
  4810. var Property = require('../property');
  4811. var Net = function (web3) {
  4812. this._requestManager = web3._requestManager;
  4813. var self = this;
  4814. properties().forEach(function(p) {
  4815. p.attachToObject(self);
  4816. p.setRequestManager(web3._requestManager);
  4817. });
  4818. };
  4819. /// @returns an array of objects describing web3.eth api properties
  4820. var properties = function () {
  4821. return [
  4822. new Property({
  4823. name: 'listening',
  4824. getter: 'net_listening'
  4825. }),
  4826. new Property({
  4827. name: 'peerCount',
  4828. getter: 'net_peerCount',
  4829. outputFormatter: utils.toDecimal
  4830. })
  4831. ];
  4832. };
  4833. module.exports = Net;
  4834. },{"../../utils/utils":20,"../property":45}],40:[function(require,module,exports){
  4835. /*
  4836. This file is part of web3.js.
  4837. web3.js is free software: you can redistribute it and/or modify
  4838. it under the terms of the GNU Lesser General Public License as published by
  4839. the Free Software Foundation, either version 3 of the License, or
  4840. (at your option) any later version.
  4841. web3.js is distributed in the hope that it will be useful,
  4842. but WITHOUT ANY WARRANTY; without even the implied warranty of
  4843. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  4844. GNU Lesser General Public License for more details.
  4845. You should have received a copy of the GNU Lesser General Public License
  4846. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  4847. */
  4848. /**
  4849. * @file eth.js
  4850. * @author Marek Kotewicz <marek@ethdev.com>
  4851. * @author Fabian Vogelsteller <fabian@ethdev.com>
  4852. * @date 2015
  4853. */
  4854. "use strict";
  4855. var Method = require('../method');
  4856. var Property = require('../property');
  4857. var formatters = require('../formatters');
  4858. function Personal(web3) {
  4859. this._requestManager = web3._requestManager;
  4860. var self = this;
  4861. methods().forEach(function(method) {
  4862. method.attachToObject(self);
  4863. method.setRequestManager(self._requestManager);
  4864. });
  4865. properties().forEach(function(p) {
  4866. p.attachToObject(self);
  4867. p.setRequestManager(self._requestManager);
  4868. });
  4869. }
  4870. var methods = function () {
  4871. var newAccount = new Method({
  4872. name: 'newAccount',
  4873. call: 'personal_newAccount',
  4874. params: 1,
  4875. inputFormatter: [null]
  4876. });
  4877. var importRawKey = new Method({
  4878. name: 'importRawKey',
  4879. call: 'personal_importRawKey',
  4880. params: 2
  4881. });
  4882. var sign = new Method({
  4883. name: 'sign',
  4884. call: 'personal_sign',
  4885. params: 3,
  4886. inputFormatter: [null, formatters.inputAddressFormatter, null]
  4887. });
  4888. var ecRecover = new Method({
  4889. name: 'ecRecover',
  4890. call: 'personal_ecRecover',
  4891. params: 2
  4892. });
  4893. var unlockAccount = new Method({
  4894. name: 'unlockAccount',
  4895. call: 'personal_unlockAccount',
  4896. params: 3,
  4897. inputFormatter: [formatters.inputAddressFormatter, null, null]
  4898. });
  4899. var sendTransaction = new Method({
  4900. name: 'sendTransaction',
  4901. call: 'personal_sendTransaction',
  4902. params: 2,
  4903. inputFormatter: [formatters.inputTransactionFormatter, null]
  4904. });
  4905. var lockAccount = new Method({
  4906. name: 'lockAccount',
  4907. call: 'personal_lockAccount',
  4908. params: 1,
  4909. inputFormatter: [formatters.inputAddressFormatter]
  4910. });
  4911. return [
  4912. newAccount,
  4913. importRawKey,
  4914. unlockAccount,
  4915. ecRecover,
  4916. sign,
  4917. sendTransaction,
  4918. lockAccount
  4919. ];
  4920. };
  4921. var properties = function () {
  4922. return [
  4923. new Property({
  4924. name: 'listAccounts',
  4925. getter: 'personal_listAccounts'
  4926. })
  4927. ];
  4928. };
  4929. module.exports = Personal;
  4930. },{"../formatters":30,"../method":36,"../property":45}],41:[function(require,module,exports){
  4931. /*
  4932. This file is part of web3.js.
  4933. web3.js is free software: you can redistribute it and/or modify
  4934. it under the terms of the GNU Lesser General Public License as published by
  4935. the Free Software Foundation, either version 3 of the License, or
  4936. (at your option) any later version.
  4937. web3.js is distributed in the hope that it will be useful,
  4938. but WITHOUT ANY WARRANTY; without even the implied warranty of
  4939. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  4940. GNU Lesser General Public License for more details.
  4941. You should have received a copy of the GNU Lesser General Public License
  4942. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  4943. */
  4944. /** @file shh.js
  4945. * @authors:
  4946. * Fabian Vogelsteller <fabian@ethereum.org>
  4947. * Marek Kotewicz <marek@ethcore.io>
  4948. * @date 2017
  4949. */
  4950. var Method = require('../method');
  4951. var Filter = require('../filter');
  4952. var watches = require('./watches');
  4953. var Shh = function (web3) {
  4954. this._requestManager = web3._requestManager;
  4955. var self = this;
  4956. methods().forEach(function(method) {
  4957. method.attachToObject(self);
  4958. method.setRequestManager(self._requestManager);
  4959. });
  4960. };
  4961. Shh.prototype.newMessageFilter = function (options, callback, filterCreationErrorCallback) {
  4962. return new Filter(options, 'shh', this._requestManager, watches.shh(), null, callback, filterCreationErrorCallback);
  4963. };
  4964. var methods = function () {
  4965. return [
  4966. new Method({
  4967. name: 'version',
  4968. call: 'shh_version',
  4969. params: 0
  4970. }),
  4971. new Method({
  4972. name: 'info',
  4973. call: 'shh_info',
  4974. params: 0
  4975. }),
  4976. new Method({
  4977. name: 'setMaxMessageSize',
  4978. call: 'shh_setMaxMessageSize',
  4979. params: 1
  4980. }),
  4981. new Method({
  4982. name: 'setMinPoW',
  4983. call: 'shh_setMinPoW',
  4984. params: 1
  4985. }),
  4986. new Method({
  4987. name: 'markTrustedPeer',
  4988. call: 'shh_markTrustedPeer',
  4989. params: 1
  4990. }),
  4991. new Method({
  4992. name: 'newKeyPair',
  4993. call: 'shh_newKeyPair',
  4994. params: 0
  4995. }),
  4996. new Method({
  4997. name: 'addPrivateKey',
  4998. call: 'shh_addPrivateKey',
  4999. params: 1
  5000. }),
  5001. new Method({
  5002. name: 'deleteKeyPair',
  5003. call: 'shh_deleteKeyPair',
  5004. params: 1
  5005. }),
  5006. new Method({
  5007. name: 'hasKeyPair',
  5008. call: 'shh_hasKeyPair',
  5009. params: 1
  5010. }),
  5011. new Method({
  5012. name: 'getPublicKey',
  5013. call: 'shh_getPublicKey',
  5014. params: 1
  5015. }),
  5016. new Method({
  5017. name: 'getPrivateKey',
  5018. call: 'shh_getPrivateKey',
  5019. params: 1
  5020. }),
  5021. new Method({
  5022. name: 'newSymKey',
  5023. call: 'shh_newSymKey',
  5024. params: 0
  5025. }),
  5026. new Method({
  5027. name: 'addSymKey',
  5028. call: 'shh_addSymKey',
  5029. params: 1
  5030. }),
  5031. new Method({
  5032. name: 'generateSymKeyFromPassword',
  5033. call: 'shh_generateSymKeyFromPassword',
  5034. params: 1
  5035. }),
  5036. new Method({
  5037. name: 'hasSymKey',
  5038. call: 'shh_hasSymKey',
  5039. params: 1
  5040. }),
  5041. new Method({
  5042. name: 'getSymKey',
  5043. call: 'shh_getSymKey',
  5044. params: 1
  5045. }),
  5046. new Method({
  5047. name: 'deleteSymKey',
  5048. call: 'shh_deleteSymKey',
  5049. params: 1
  5050. }),
  5051. // subscribe and unsubscribe missing
  5052. new Method({
  5053. name: 'post',
  5054. call: 'shh_post',
  5055. params: 1,
  5056. inputFormatter: [null]
  5057. })
  5058. ];
  5059. };
  5060. module.exports = Shh;
  5061. },{"../filter":29,"../method":36,"./watches":43}],42:[function(require,module,exports){
  5062. /*
  5063. This file is part of web3.js.
  5064. web3.js is free software: you can redistribute it and/or modify
  5065. it under the terms of the GNU Lesser General Public License as published by
  5066. the Free Software Foundation, either version 3 of the License, or
  5067. (at your option) any later version.
  5068. web3.js is distributed in the hope that it will be useful,
  5069. but WITHOUT ANY WARRANTY; without even the implied warranty of
  5070. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  5071. GNU Lesser General Public License for more details.
  5072. You should have received a copy of the GNU Lesser General Public License
  5073. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  5074. */
  5075. /**
  5076. * @file bzz.js
  5077. * @author Alex Beregszaszi <alex@rtfs.hu>
  5078. * @date 2016
  5079. *
  5080. * Reference: https://github.com/ethereum/go-ethereum/blob/swarm/internal/web3ext/web3ext.go#L33
  5081. */
  5082. "use strict";
  5083. var Method = require('../method');
  5084. var Property = require('../property');
  5085. function Swarm(web3) {
  5086. this._requestManager = web3._requestManager;
  5087. var self = this;
  5088. methods().forEach(function(method) {
  5089. method.attachToObject(self);
  5090. method.setRequestManager(self._requestManager);
  5091. });
  5092. properties().forEach(function(p) {
  5093. p.attachToObject(self);
  5094. p.setRequestManager(self._requestManager);
  5095. });
  5096. }
  5097. var methods = function () {
  5098. var blockNetworkRead = new Method({
  5099. name: 'blockNetworkRead',
  5100. call: 'bzz_blockNetworkRead',
  5101. params: 1,
  5102. inputFormatter: [null]
  5103. });
  5104. var syncEnabled = new Method({
  5105. name: 'syncEnabled',
  5106. call: 'bzz_syncEnabled',
  5107. params: 1,
  5108. inputFormatter: [null]
  5109. });
  5110. var swapEnabled = new Method({
  5111. name: 'swapEnabled',
  5112. call: 'bzz_swapEnabled',
  5113. params: 1,
  5114. inputFormatter: [null]
  5115. });
  5116. var download = new Method({
  5117. name: 'download',
  5118. call: 'bzz_download',
  5119. params: 2,
  5120. inputFormatter: [null, null]
  5121. });
  5122. var upload = new Method({
  5123. name: 'upload',
  5124. call: 'bzz_upload',
  5125. params: 2,
  5126. inputFormatter: [null, null]
  5127. });
  5128. var retrieve = new Method({
  5129. name: 'retrieve',
  5130. call: 'bzz_retrieve',
  5131. params: 1,
  5132. inputFormatter: [null]
  5133. });
  5134. var store = new Method({
  5135. name: 'store',
  5136. call: 'bzz_store',
  5137. params: 2,
  5138. inputFormatter: [null, null]
  5139. });
  5140. var get = new Method({
  5141. name: 'get',
  5142. call: 'bzz_get',
  5143. params: 1,
  5144. inputFormatter: [null]
  5145. });
  5146. var put = new Method({
  5147. name: 'put',
  5148. call: 'bzz_put',
  5149. params: 2,
  5150. inputFormatter: [null, null]
  5151. });
  5152. var modify = new Method({
  5153. name: 'modify',
  5154. call: 'bzz_modify',
  5155. params: 4,
  5156. inputFormatter: [null, null, null, null]
  5157. });
  5158. return [
  5159. blockNetworkRead,
  5160. syncEnabled,
  5161. swapEnabled,
  5162. download,
  5163. upload,
  5164. retrieve,
  5165. store,
  5166. get,
  5167. put,
  5168. modify
  5169. ];
  5170. };
  5171. var properties = function () {
  5172. return [
  5173. new Property({
  5174. name: 'hive',
  5175. getter: 'bzz_hive'
  5176. }),
  5177. new Property({
  5178. name: 'info',
  5179. getter: 'bzz_info'
  5180. })
  5181. ];
  5182. };
  5183. module.exports = Swarm;
  5184. },{"../method":36,"../property":45}],43:[function(require,module,exports){
  5185. /*
  5186. This file is part of web3.js.
  5187. web3.js is free software: you can redistribute it and/or modify
  5188. it under the terms of the GNU Lesser General Public License as published by
  5189. the Free Software Foundation, either version 3 of the License, or
  5190. (at your option) any later version.
  5191. web3.js is distributed in the hope that it will be useful,
  5192. but WITHOUT ANY WARRANTY; without even the implied warranty of
  5193. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  5194. GNU Lesser General Public License for more details.
  5195. You should have received a copy of the GNU Lesser General Public License
  5196. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  5197. */
  5198. /** @file watches.js
  5199. * @authors:
  5200. * Marek Kotewicz <marek@ethdev.com>
  5201. * @date 2015
  5202. */
  5203. var Method = require('../method');
  5204. /// @returns an array of objects describing web3.eth.filter api methods
  5205. var eth = function () {
  5206. var newFilterCall = function (args) {
  5207. var type = args[0];
  5208. switch(type) {
  5209. case 'latest':
  5210. args.shift();
  5211. this.params = 0;
  5212. return 'eth_newBlockFilter';
  5213. case 'pending':
  5214. args.shift();
  5215. this.params = 0;
  5216. return 'eth_newPendingTransactionFilter';
  5217. default:
  5218. return 'eth_newFilter';
  5219. }
  5220. };
  5221. var newFilter = new Method({
  5222. name: 'newFilter',
  5223. call: newFilterCall,
  5224. params: 1
  5225. });
  5226. var uninstallFilter = new Method({
  5227. name: 'uninstallFilter',
  5228. call: 'eth_uninstallFilter',
  5229. params: 1
  5230. });
  5231. var getLogs = new Method({
  5232. name: 'getLogs',
  5233. call: 'eth_getFilterLogs',
  5234. params: 1
  5235. });
  5236. var poll = new Method({
  5237. name: 'poll',
  5238. call: 'eth_getFilterChanges',
  5239. params: 1
  5240. });
  5241. return [
  5242. newFilter,
  5243. uninstallFilter,
  5244. getLogs,
  5245. poll
  5246. ];
  5247. };
  5248. /// @returns an array of objects describing web3.shh.watch api methods
  5249. var shh = function () {
  5250. return [
  5251. new Method({
  5252. name: 'newFilter',
  5253. call: 'shh_newMessageFilter',
  5254. params: 1
  5255. }),
  5256. new Method({
  5257. name: 'uninstallFilter',
  5258. call: 'shh_deleteMessageFilter',
  5259. params: 1
  5260. }),
  5261. new Method({
  5262. name: 'getLogs',
  5263. call: 'shh_getFilterMessages',
  5264. params: 1
  5265. }),
  5266. new Method({
  5267. name: 'poll',
  5268. call: 'shh_getFilterMessages',
  5269. params: 1
  5270. })
  5271. ];
  5272. };
  5273. module.exports = {
  5274. eth: eth,
  5275. shh: shh
  5276. };
  5277. },{"../method":36}],44:[function(require,module,exports){
  5278. /*
  5279. This file is part of web3.js.
  5280. web3.js is free software: you can redistribute it and/or modify
  5281. it under the terms of the GNU Lesser General Public License as published by
  5282. the Free Software Foundation, either version 3 of the License, or
  5283. (at your option) any later version.
  5284. web3.js is distributed in the hope that it will be useful,
  5285. but WITHOUT ANY WARRANTY; without even the implied warranty of
  5286. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  5287. GNU Lesser General Public License for more details.
  5288. You should have received a copy of the GNU Lesser General Public License
  5289. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  5290. */
  5291. /**
  5292. * @file namereg.js
  5293. * @author Marek Kotewicz <marek@ethdev.com>
  5294. * @date 2015
  5295. */
  5296. var globalRegistrarAbi = require('../contracts/GlobalRegistrar.json');
  5297. var icapRegistrarAbi= require('../contracts/ICAPRegistrar.json');
  5298. var globalNameregAddress = '0xc6d9d2cd449a754c494264e1809c50e34d64562b';
  5299. var icapNameregAddress = '0xa1a111bc074c9cfa781f0c38e63bd51c91b8af00';
  5300. module.exports = {
  5301. global: {
  5302. abi: globalRegistrarAbi,
  5303. address: globalNameregAddress
  5304. },
  5305. icap: {
  5306. abi: icapRegistrarAbi,
  5307. address: icapNameregAddress
  5308. }
  5309. };
  5310. },{"../contracts/GlobalRegistrar.json":1,"../contracts/ICAPRegistrar.json":2}],45:[function(require,module,exports){
  5311. /*
  5312. This file is part of web3.js.
  5313. web3.js is free software: you can redistribute it and/or modify
  5314. it under the terms of the GNU Lesser General Public License as published by
  5315. the Free Software Foundation, either version 3 of the License, or
  5316. (at your option) any later version.
  5317. web3.js is distributed in the hope that it will be useful,
  5318. but WITHOUT ANY WARRANTY; without even the implied warranty of
  5319. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  5320. GNU Lesser General Public License for more details.
  5321. You should have received a copy of the GNU Lesser General Public License
  5322. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  5323. */
  5324. /**
  5325. * @file property.js
  5326. * @author Fabian Vogelsteller <fabian@frozeman.de>
  5327. * @author Marek Kotewicz <marek@ethdev.com>
  5328. * @date 2015
  5329. */
  5330. var utils = require('../utils/utils');
  5331. var Property = function (options) {
  5332. this.name = options.name;
  5333. this.getter = options.getter;
  5334. this.setter = options.setter;
  5335. this.outputFormatter = options.outputFormatter;
  5336. this.inputFormatter = options.inputFormatter;
  5337. this.requestManager = null;
  5338. };
  5339. Property.prototype.setRequestManager = function (rm) {
  5340. this.requestManager = rm;
  5341. };
  5342. /**
  5343. * Should be called to format input args of method
  5344. *
  5345. * @method formatInput
  5346. * @param {Array}
  5347. * @return {Array}
  5348. */
  5349. Property.prototype.formatInput = function (arg) {
  5350. return this.inputFormatter ? this.inputFormatter(arg) : arg;
  5351. };
  5352. /**
  5353. * Should be called to format output(result) of method
  5354. *
  5355. * @method formatOutput
  5356. * @param {Object}
  5357. * @return {Object}
  5358. */
  5359. Property.prototype.formatOutput = function (result) {
  5360. return this.outputFormatter && result !== null && result !== undefined ? this.outputFormatter(result) : result;
  5361. };
  5362. /**
  5363. * Should be used to extract callback from array of arguments. Modifies input param
  5364. *
  5365. * @method extractCallback
  5366. * @param {Array} arguments
  5367. * @return {Function|Null} callback, if exists
  5368. */
  5369. Property.prototype.extractCallback = function (args) {
  5370. if (utils.isFunction(args[args.length - 1])) {
  5371. return args.pop(); // modify the args array!
  5372. }
  5373. };
  5374. /**
  5375. * Should attach function to method
  5376. *
  5377. * @method attachToObject
  5378. * @param {Object}
  5379. * @param {Function}
  5380. */
  5381. Property.prototype.attachToObject = function (obj) {
  5382. var proto = {
  5383. get: this.buildGet(),
  5384. enumerable: true
  5385. };
  5386. var names = this.name.split('.');
  5387. var name = names[0];
  5388. if (names.length > 1) {
  5389. obj[names[0]] = obj[names[0]] || {};
  5390. obj = obj[names[0]];
  5391. name = names[1];
  5392. }
  5393. Object.defineProperty(obj, name, proto);
  5394. obj[asyncGetterName(name)] = this.buildAsyncGet();
  5395. };
  5396. var asyncGetterName = function (name) {
  5397. return 'get' + name.charAt(0).toUpperCase() + name.slice(1);
  5398. };
  5399. Property.prototype.buildGet = function () {
  5400. var property = this;
  5401. return function get() {
  5402. return property.formatOutput(property.requestManager.send({
  5403. method: property.getter
  5404. }));
  5405. };
  5406. };
  5407. Property.prototype.buildAsyncGet = function () {
  5408. var property = this;
  5409. var get = function (callback) {
  5410. property.requestManager.sendAsync({
  5411. method: property.getter
  5412. }, function (err, result) {
  5413. callback(err, property.formatOutput(result));
  5414. });
  5415. };
  5416. get.request = this.request.bind(this);
  5417. return get;
  5418. };
  5419. /**
  5420. * Should be called to create pure JSONRPC request which can be used in batch request
  5421. *
  5422. * @method request
  5423. * @param {...} params
  5424. * @return {Object} jsonrpc request
  5425. */
  5426. Property.prototype.request = function () {
  5427. var payload = {
  5428. method: this.getter,
  5429. params: [],
  5430. callback: this.extractCallback(Array.prototype.slice.call(arguments))
  5431. };
  5432. payload.format = this.formatOutput.bind(this);
  5433. return payload;
  5434. };
  5435. module.exports = Property;
  5436. },{"../utils/utils":20}],46:[function(require,module,exports){
  5437. /*
  5438. This file is part of web3.js.
  5439. web3.js is free software: you can redistribute it and/or modify
  5440. it under the terms of the GNU Lesser General Public License as published by
  5441. the Free Software Foundation, either version 3 of the License, or
  5442. (at your option) any later version.
  5443. web3.js is distributed in the hope that it will be useful,
  5444. but WITHOUT ANY WARRANTY; without even the implied warranty of
  5445. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  5446. GNU Lesser General Public License for more details.
  5447. You should have received a copy of the GNU Lesser General Public License
  5448. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  5449. */
  5450. /**
  5451. * @file requestmanager.js
  5452. * @author Jeffrey Wilcke <jeff@ethdev.com>
  5453. * @author Marek Kotewicz <marek@ethdev.com>
  5454. * @author Marian Oancea <marian@ethdev.com>
  5455. * @author Fabian Vogelsteller <fabian@ethdev.com>
  5456. * @author Gav Wood <g@ethdev.com>
  5457. * @date 2014
  5458. */
  5459. var Jsonrpc = require('./jsonrpc');
  5460. var utils = require('../utils/utils');
  5461. var c = require('../utils/config');
  5462. var errors = require('./errors');
  5463. /**
  5464. * It's responsible for passing messages to providers
  5465. * It's also responsible for polling the ethereum node for incoming messages
  5466. * Default poll timeout is 1 second
  5467. * Singleton
  5468. */
  5469. var RequestManager = function (provider) {
  5470. this.provider = provider;
  5471. this.polls = {};
  5472. this.timeout = null;
  5473. };
  5474. /**
  5475. * Should be used to synchronously send request
  5476. *
  5477. * @method send
  5478. * @param {Object} data
  5479. * @return {Object}
  5480. */
  5481. RequestManager.prototype.send = function (data) {
  5482. if (!this.provider) {
  5483. console.error(errors.InvalidProvider());
  5484. return null;
  5485. }
  5486. var payload = Jsonrpc.toPayload(data.method, data.params);
  5487. var result = this.provider.send(payload);
  5488. if (!Jsonrpc.isValidResponse(result)) {
  5489. throw errors.InvalidResponse(result);
  5490. }
  5491. return result.result;
  5492. };
  5493. /**
  5494. * Should be used to asynchronously send request
  5495. *
  5496. * @method sendAsync
  5497. * @param {Object} data
  5498. * @param {Function} callback
  5499. */
  5500. RequestManager.prototype.sendAsync = function (data, callback) {
  5501. if (!this.provider) {
  5502. return callback(errors.InvalidProvider());
  5503. }
  5504. var payload = Jsonrpc.toPayload(data.method, data.params);
  5505. this.provider.sendAsync(payload, function (err, result) {
  5506. if (err) {
  5507. return callback(err);
  5508. }
  5509. if (!Jsonrpc.isValidResponse(result)) {
  5510. return callback(errors.InvalidResponse(result));
  5511. }
  5512. callback(null, result.result);
  5513. });
  5514. };
  5515. /**
  5516. * Should be called to asynchronously send batch request
  5517. *
  5518. * @method sendBatch
  5519. * @param {Array} batch data
  5520. * @param {Function} callback
  5521. */
  5522. RequestManager.prototype.sendBatch = function (data, callback) {
  5523. if (!this.provider) {
  5524. return callback(errors.InvalidProvider());
  5525. }
  5526. var payload = Jsonrpc.toBatchPayload(data);
  5527. this.provider.sendAsync(payload, function (err, results) {
  5528. if (err) {
  5529. return callback(err);
  5530. }
  5531. if (!utils.isArray(results)) {
  5532. return callback(errors.InvalidResponse(results));
  5533. }
  5534. callback(err, results);
  5535. });
  5536. };
  5537. /**
  5538. * Should be used to set provider of request manager
  5539. *
  5540. * @method setProvider
  5541. * @param {Object}
  5542. */
  5543. RequestManager.prototype.setProvider = function (p) {
  5544. this.provider = p;
  5545. };
  5546. /**
  5547. * Should be used to start polling
  5548. *
  5549. * @method startPolling
  5550. * @param {Object} data
  5551. * @param {Number} pollId
  5552. * @param {Function} callback
  5553. * @param {Function} uninstall
  5554. *
  5555. * @todo cleanup number of params
  5556. */
  5557. RequestManager.prototype.startPolling = function (data, pollId, callback, uninstall) {
  5558. this.polls[pollId] = {data: data, id: pollId, callback: callback, uninstall: uninstall};
  5559. // start polling
  5560. if (!this.timeout) {
  5561. this.poll();
  5562. }
  5563. };
  5564. /**
  5565. * Should be used to stop polling for filter with given id
  5566. *
  5567. * @method stopPolling
  5568. * @param {Number} pollId
  5569. */
  5570. RequestManager.prototype.stopPolling = function (pollId) {
  5571. delete this.polls[pollId];
  5572. // stop polling
  5573. if(Object.keys(this.polls).length === 0 && this.timeout) {
  5574. clearTimeout(this.timeout);
  5575. this.timeout = null;
  5576. }
  5577. };
  5578. /**
  5579. * Should be called to reset the polling mechanism of the request manager
  5580. *
  5581. * @method reset
  5582. */
  5583. RequestManager.prototype.reset = function (keepIsSyncing) {
  5584. /*jshint maxcomplexity:5 */
  5585. for (var key in this.polls) {
  5586. // remove all polls, except sync polls,
  5587. // they need to be removed manually by calling syncing.stopWatching()
  5588. if(!keepIsSyncing || key.indexOf('syncPoll_') === -1) {
  5589. this.polls[key].uninstall();
  5590. delete this.polls[key];
  5591. }
  5592. }
  5593. // stop polling
  5594. if(Object.keys(this.polls).length === 0 && this.timeout) {
  5595. clearTimeout(this.timeout);
  5596. this.timeout = null;
  5597. }
  5598. };
  5599. /**
  5600. * Should be called to poll for changes on filter with given id
  5601. *
  5602. * @method poll
  5603. */
  5604. RequestManager.prototype.poll = function () {
  5605. /*jshint maxcomplexity: 6 */
  5606. this.timeout = setTimeout(this.poll.bind(this), c.ETH_POLLING_TIMEOUT);
  5607. if (Object.keys(this.polls).length === 0) {
  5608. return;
  5609. }
  5610. if (!this.provider) {
  5611. console.error(errors.InvalidProvider());
  5612. return;
  5613. }
  5614. var pollsData = [];
  5615. var pollsIds = [];
  5616. for (var key in this.polls) {
  5617. pollsData.push(this.polls[key].data);
  5618. pollsIds.push(key);
  5619. }
  5620. if (pollsData.length === 0) {
  5621. return;
  5622. }
  5623. var payload = Jsonrpc.toBatchPayload(pollsData);
  5624. // map the request id to they poll id
  5625. var pollsIdMap = {};
  5626. payload.forEach(function(load, index){
  5627. pollsIdMap[load.id] = pollsIds[index];
  5628. });
  5629. var self = this;
  5630. this.provider.sendAsync(payload, function (error, results) {
  5631. // TODO: console log?
  5632. if (error) {
  5633. return;
  5634. }
  5635. if (!utils.isArray(results)) {
  5636. throw errors.InvalidResponse(results);
  5637. }
  5638. results.map(function (result) {
  5639. var id = pollsIdMap[result.id];
  5640. // make sure the filter is still installed after arrival of the request
  5641. if (self.polls[id]) {
  5642. result.callback = self.polls[id].callback;
  5643. return result;
  5644. } else
  5645. return false;
  5646. }).filter(function (result) {
  5647. return !!result;
  5648. }).filter(function (result) {
  5649. var valid = Jsonrpc.isValidResponse(result);
  5650. if (!valid) {
  5651. result.callback(errors.InvalidResponse(result));
  5652. }
  5653. return valid;
  5654. }).forEach(function (result) {
  5655. result.callback(null, result.result);
  5656. });
  5657. });
  5658. };
  5659. module.exports = RequestManager;
  5660. },{"../utils/config":18,"../utils/utils":20,"./errors":26,"./jsonrpc":35}],47:[function(require,module,exports){
  5661. var Settings = function () {
  5662. this.defaultBlock = 'latest';
  5663. this.defaultAccount = undefined;
  5664. };
  5665. module.exports = Settings;
  5666. },{}],48:[function(require,module,exports){
  5667. /*
  5668. This file is part of web3.js.
  5669. web3.js is free software: you can redistribute it and/or modify
  5670. it under the terms of the GNU Lesser General Public License as published by
  5671. the Free Software Foundation, either version 3 of the License, or
  5672. (at your option) any later version.
  5673. web3.js is distributed in the hope that it will be useful,
  5674. but WITHOUT ANY WARRANTY; without even the implied warranty of
  5675. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  5676. GNU Lesser General Public License for more details.
  5677. You should have received a copy of the GNU Lesser General Public License
  5678. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  5679. */
  5680. /** @file syncing.js
  5681. * @authors:
  5682. * Fabian Vogelsteller <fabian@ethdev.com>
  5683. * @date 2015
  5684. */
  5685. var formatters = require('./formatters');
  5686. var utils = require('../utils/utils');
  5687. var count = 1;
  5688. /**
  5689. Adds the callback and sets up the methods, to iterate over the results.
  5690. @method pollSyncing
  5691. @param {Object} self
  5692. */
  5693. var pollSyncing = function(self) {
  5694. var onMessage = function (error, sync) {
  5695. if (error) {
  5696. return self.callbacks.forEach(function (callback) {
  5697. callback(error);
  5698. });
  5699. }
  5700. if(utils.isObject(sync) && sync.startingBlock)
  5701. sync = formatters.outputSyncingFormatter(sync);
  5702. self.callbacks.forEach(function (callback) {
  5703. if (self.lastSyncState !== sync) {
  5704. // call the callback with true first so the app can stop anything, before receiving the sync data
  5705. if(!self.lastSyncState && utils.isObject(sync))
  5706. callback(null, true);
  5707. // call on the next CPU cycle, so the actions of the sync stop can be processes first
  5708. setTimeout(function() {
  5709. callback(null, sync);
  5710. }, 0);
  5711. self.lastSyncState = sync;
  5712. }
  5713. });
  5714. };
  5715. self.requestManager.startPolling({
  5716. method: 'eth_syncing',
  5717. params: [],
  5718. }, self.pollId, onMessage, self.stopWatching.bind(self));
  5719. };
  5720. var IsSyncing = function (requestManager, callback) {
  5721. this.requestManager = requestManager;
  5722. this.pollId = 'syncPoll_'+ count++;
  5723. this.callbacks = [];
  5724. this.addCallback(callback);
  5725. this.lastSyncState = false;
  5726. pollSyncing(this);
  5727. return this;
  5728. };
  5729. IsSyncing.prototype.addCallback = function (callback) {
  5730. if(callback)
  5731. this.callbacks.push(callback);
  5732. return this;
  5733. };
  5734. IsSyncing.prototype.stopWatching = function () {
  5735. this.requestManager.stopPolling(this.pollId);
  5736. this.callbacks = [];
  5737. };
  5738. module.exports = IsSyncing;
  5739. },{"../utils/utils":20,"./formatters":30}],49:[function(require,module,exports){
  5740. /*
  5741. This file is part of web3.js.
  5742. web3.js is free software: you can redistribute it and/or modify
  5743. it under the terms of the GNU Lesser General Public License as published by
  5744. the Free Software Foundation, either version 3 of the License, or
  5745. (at your option) any later version.
  5746. web3.js is distributed in the hope that it will be useful,
  5747. but WITHOUT ANY WARRANTY; without even the implied warranty of
  5748. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  5749. GNU Lesser General Public License for more details.
  5750. You should have received a copy of the GNU Lesser General Public License
  5751. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  5752. */
  5753. /**
  5754. * @file transfer.js
  5755. * @author Marek Kotewicz <marek@ethdev.com>
  5756. * @date 2015
  5757. */
  5758. var Iban = require('./iban');
  5759. var exchangeAbi = require('../contracts/SmartExchange.json');
  5760. /**
  5761. * Should be used to make Iban transfer
  5762. *
  5763. * @method transfer
  5764. * @param {String} from
  5765. * @param {String} to iban
  5766. * @param {Value} value to be tranfered
  5767. * @param {Function} callback, callback
  5768. */
  5769. var transfer = function (eth, from, to, value, callback) {
  5770. var iban = new Iban(to);
  5771. if (!iban.isValid()) {
  5772. throw new Error('invalid iban address');
  5773. }
  5774. if (iban.isDirect()) {
  5775. return transferToAddress(eth, from, iban.address(), value, callback);
  5776. }
  5777. if (!callback) {
  5778. var address = eth.icapNamereg().addr(iban.institution());
  5779. return deposit(eth, from, address, value, iban.client());
  5780. }
  5781. eth.icapNamereg().addr(iban.institution(), function (err, address) {
  5782. return deposit(eth, from, address, value, iban.client(), callback);
  5783. });
  5784. };
  5785. /**
  5786. * Should be used to transfer funds to certain address
  5787. *
  5788. * @method transferToAddress
  5789. * @param {String} from
  5790. * @param {String} to
  5791. * @param {Value} value to be tranfered
  5792. * @param {Function} callback, callback
  5793. */
  5794. var transferToAddress = function (eth, from, to, value, callback) {
  5795. return eth.sendTransaction({
  5796. address: to,
  5797. from: from,
  5798. value: value
  5799. }, callback);
  5800. };
  5801. /**
  5802. * Should be used to deposit funds to generic Exchange contract (must implement deposit(bytes32) method!)
  5803. *
  5804. * @method deposit
  5805. * @param {String} from
  5806. * @param {String} to
  5807. * @param {Value} value to be transferred
  5808. * @param {String} client unique identifier
  5809. * @param {Function} callback, callback
  5810. */
  5811. var deposit = function (eth, from, to, value, client, callback) {
  5812. var abi = exchangeAbi;
  5813. return eth.contract(abi).at(to).deposit(client, {
  5814. from: from,
  5815. value: value
  5816. }, callback);
  5817. };
  5818. module.exports = transfer;
  5819. },{"../contracts/SmartExchange.json":3,"./iban":33}],50:[function(require,module,exports){
  5820. },{}],51:[function(require,module,exports){
  5821. ;(function (root, factory, undef) {
  5822. if (typeof exports === "object") {
  5823. // CommonJS
  5824. module.exports = exports = factory(require("./core"), require("./enc-base64"), require("./md5"), require("./evpkdf"), require("./cipher-core"));
  5825. }
  5826. else if (typeof define === "function" && define.amd) {
  5827. // AMD
  5828. define(["./core", "./enc-base64", "./md5", "./evpkdf", "./cipher-core"], factory);
  5829. }
  5830. else {
  5831. // Global (browser)
  5832. factory(root.CryptoJS);
  5833. }
  5834. }(this, function (CryptoJS) {
  5835. (function () {
  5836. // Shortcuts
  5837. var C = CryptoJS;
  5838. var C_lib = C.lib;
  5839. var BlockCipher = C_lib.BlockCipher;
  5840. var C_algo = C.algo;
  5841. // Lookup tables
  5842. var SBOX = [];
  5843. var INV_SBOX = [];
  5844. var SUB_MIX_0 = [];
  5845. var SUB_MIX_1 = [];
  5846. var SUB_MIX_2 = [];
  5847. var SUB_MIX_3 = [];
  5848. var INV_SUB_MIX_0 = [];
  5849. var INV_SUB_MIX_1 = [];
  5850. var INV_SUB_MIX_2 = [];
  5851. var INV_SUB_MIX_3 = [];
  5852. // Compute lookup tables
  5853. (function () {
  5854. // Compute double table
  5855. var d = [];
  5856. for (var i = 0; i < 256; i++) {
  5857. if (i < 128) {
  5858. d[i] = i << 1;
  5859. } else {
  5860. d[i] = (i << 1) ^ 0x11b;
  5861. }
  5862. }
  5863. // Walk GF(2^8)
  5864. var x = 0;
  5865. var xi = 0;
  5866. for (var i = 0; i < 256; i++) {
  5867. // Compute sbox
  5868. var sx = xi ^ (xi << 1) ^ (xi << 2) ^ (xi << 3) ^ (xi << 4);
  5869. sx = (sx >>> 8) ^ (sx & 0xff) ^ 0x63;
  5870. SBOX[x] = sx;
  5871. INV_SBOX[sx] = x;
  5872. // Compute multiplication
  5873. var x2 = d[x];
  5874. var x4 = d[x2];
  5875. var x8 = d[x4];
  5876. // Compute sub bytes, mix columns tables
  5877. var t = (d[sx] * 0x101) ^ (sx * 0x1010100);
  5878. SUB_MIX_0[x] = (t << 24) | (t >>> 8);
  5879. SUB_MIX_1[x] = (t << 16) | (t >>> 16);
  5880. SUB_MIX_2[x] = (t << 8) | (t >>> 24);
  5881. SUB_MIX_3[x] = t;
  5882. // Compute inv sub bytes, inv mix columns tables
  5883. var t = (x8 * 0x1010101) ^ (x4 * 0x10001) ^ (x2 * 0x101) ^ (x * 0x1010100);
  5884. INV_SUB_MIX_0[sx] = (t << 24) | (t >>> 8);
  5885. INV_SUB_MIX_1[sx] = (t << 16) | (t >>> 16);
  5886. INV_SUB_MIX_2[sx] = (t << 8) | (t >>> 24);
  5887. INV_SUB_MIX_3[sx] = t;
  5888. // Compute next counter
  5889. if (!x) {
  5890. x = xi = 1;
  5891. } else {
  5892. x = x2 ^ d[d[d[x8 ^ x2]]];
  5893. xi ^= d[d[xi]];
  5894. }
  5895. }
  5896. }());
  5897. // Precomputed Rcon lookup
  5898. var RCON = [0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36];
  5899. /**
  5900. * AES block cipher algorithm.
  5901. */
  5902. var AES = C_algo.AES = BlockCipher.extend({
  5903. _doReset: function () {
  5904. // Skip reset of nRounds has been set before and key did not change
  5905. if (this._nRounds && this._keyPriorReset === this._key) {
  5906. return;
  5907. }
  5908. // Shortcuts
  5909. var key = this._keyPriorReset = this._key;
  5910. var keyWords = key.words;
  5911. var keySize = key.sigBytes / 4;
  5912. // Compute number of rounds
  5913. var nRounds = this._nRounds = keySize + 6;
  5914. // Compute number of key schedule rows
  5915. var ksRows = (nRounds + 1) * 4;
  5916. // Compute key schedule
  5917. var keySchedule = this._keySchedule = [];
  5918. for (var ksRow = 0; ksRow < ksRows; ksRow++) {
  5919. if (ksRow < keySize) {
  5920. keySchedule[ksRow] = keyWords[ksRow];
  5921. } else {
  5922. var t = keySchedule[ksRow - 1];
  5923. if (!(ksRow % keySize)) {
  5924. // Rot word
  5925. t = (t << 8) | (t >>> 24);
  5926. // Sub word
  5927. t = (SBOX[t >>> 24] << 24) | (SBOX[(t >>> 16) & 0xff] << 16) | (SBOX[(t >>> 8) & 0xff] << 8) | SBOX[t & 0xff];
  5928. // Mix Rcon
  5929. t ^= RCON[(ksRow / keySize) | 0] << 24;
  5930. } else if (keySize > 6 && ksRow % keySize == 4) {
  5931. // Sub word
  5932. t = (SBOX[t >>> 24] << 24) | (SBOX[(t >>> 16) & 0xff] << 16) | (SBOX[(t >>> 8) & 0xff] << 8) | SBOX[t & 0xff];
  5933. }
  5934. keySchedule[ksRow] = keySchedule[ksRow - keySize] ^ t;
  5935. }
  5936. }
  5937. // Compute inv key schedule
  5938. var invKeySchedule = this._invKeySchedule = [];
  5939. for (var invKsRow = 0; invKsRow < ksRows; invKsRow++) {
  5940. var ksRow = ksRows - invKsRow;
  5941. if (invKsRow % 4) {
  5942. var t = keySchedule[ksRow];
  5943. } else {
  5944. var t = keySchedule[ksRow - 4];
  5945. }
  5946. if (invKsRow < 4 || ksRow <= 4) {
  5947. invKeySchedule[invKsRow] = t;
  5948. } else {
  5949. invKeySchedule[invKsRow] = INV_SUB_MIX_0[SBOX[t >>> 24]] ^ INV_SUB_MIX_1[SBOX[(t >>> 16) & 0xff]] ^
  5950. INV_SUB_MIX_2[SBOX[(t >>> 8) & 0xff]] ^ INV_SUB_MIX_3[SBOX[t & 0xff]];
  5951. }
  5952. }
  5953. },
  5954. encryptBlock: function (M, offset) {
  5955. this._doCryptBlock(M, offset, this._keySchedule, SUB_MIX_0, SUB_MIX_1, SUB_MIX_2, SUB_MIX_3, SBOX);
  5956. },
  5957. decryptBlock: function (M, offset) {
  5958. // Swap 2nd and 4th rows
  5959. var t = M[offset + 1];
  5960. M[offset + 1] = M[offset + 3];
  5961. M[offset + 3] = t;
  5962. this._doCryptBlock(M, offset, this._invKeySchedule, INV_SUB_MIX_0, INV_SUB_MIX_1, INV_SUB_MIX_2, INV_SUB_MIX_3, INV_SBOX);
  5963. // Inv swap 2nd and 4th rows
  5964. var t = M[offset + 1];
  5965. M[offset + 1] = M[offset + 3];
  5966. M[offset + 3] = t;
  5967. },
  5968. _doCryptBlock: function (M, offset, keySchedule, SUB_MIX_0, SUB_MIX_1, SUB_MIX_2, SUB_MIX_3, SBOX) {
  5969. // Shortcut
  5970. var nRounds = this._nRounds;
  5971. // Get input, add round key
  5972. var s0 = M[offset] ^ keySchedule[0];
  5973. var s1 = M[offset + 1] ^ keySchedule[1];
  5974. var s2 = M[offset + 2] ^ keySchedule[2];
  5975. var s3 = M[offset + 3] ^ keySchedule[3];
  5976. // Key schedule row counter
  5977. var ksRow = 4;
  5978. // Rounds
  5979. for (var round = 1; round < nRounds; round++) {
  5980. // Shift rows, sub bytes, mix columns, add round key
  5981. 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++];
  5982. 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++];
  5983. 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++];
  5984. 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++];
  5985. // Update state
  5986. s0 = t0;
  5987. s1 = t1;
  5988. s2 = t2;
  5989. s3 = t3;
  5990. }
  5991. // Shift rows, sub bytes, add round key
  5992. var t0 = ((SBOX[s0 >>> 24] << 24) | (SBOX[(s1 >>> 16) & 0xff] << 16) | (SBOX[(s2 >>> 8) & 0xff] << 8) | SBOX[s3 & 0xff]) ^ keySchedule[ksRow++];
  5993. var t1 = ((SBOX[s1 >>> 24] << 24) | (SBOX[(s2 >>> 16) & 0xff] << 16) | (SBOX[(s3 >>> 8) & 0xff] << 8) | SBOX[s0 & 0xff]) ^ keySchedule[ksRow++];
  5994. var t2 = ((SBOX[s2 >>> 24] << 24) | (SBOX[(s3 >>> 16) & 0xff] << 16) | (SBOX[(s0 >>> 8) & 0xff] << 8) | SBOX[s1 & 0xff]) ^ keySchedule[ksRow++];
  5995. var t3 = ((SBOX[s3 >>> 24] << 24) | (SBOX[(s0 >>> 16) & 0xff] << 16) | (SBOX[(s1 >>> 8) & 0xff] << 8) | SBOX[s2 & 0xff]) ^ keySchedule[ksRow++];
  5996. // Set output
  5997. M[offset] = t0;
  5998. M[offset + 1] = t1;
  5999. M[offset + 2] = t2;
  6000. M[offset + 3] = t3;
  6001. },
  6002. keySize: 256/32
  6003. });
  6004. /**
  6005. * Shortcut functions to the cipher's object interface.
  6006. *
  6007. * @example
  6008. *
  6009. * var ciphertext = CryptoJS.AES.encrypt(message, key, cfg);
  6010. * var plaintext = CryptoJS.AES.decrypt(ciphertext, key, cfg);
  6011. */
  6012. C.AES = BlockCipher._createHelper(AES);
  6013. }());
  6014. return CryptoJS.AES;
  6015. }));
  6016. },{"./cipher-core":52,"./core":53,"./enc-base64":54,"./evpkdf":56,"./md5":61}],52:[function(require,module,exports){
  6017. ;(function (root, factory) {
  6018. if (typeof exports === "object") {
  6019. // CommonJS
  6020. module.exports = exports = factory(require("./core"));
  6021. }
  6022. else if (typeof define === "function" && define.amd) {
  6023. // AMD
  6024. define(["./core"], factory);
  6025. }
  6026. else {
  6027. // Global (browser)
  6028. factory(root.CryptoJS);
  6029. }
  6030. }(this, function (CryptoJS) {
  6031. /**
  6032. * Cipher core components.
  6033. */
  6034. CryptoJS.lib.Cipher || (function (undefined) {
  6035. // Shortcuts
  6036. var C = CryptoJS;
  6037. var C_lib = C.lib;
  6038. var Base = C_lib.Base;
  6039. var WordArray = C_lib.WordArray;
  6040. var BufferedBlockAlgorithm = C_lib.BufferedBlockAlgorithm;
  6041. var C_enc = C.enc;
  6042. var Utf8 = C_enc.Utf8;
  6043. var Base64 = C_enc.Base64;
  6044. var C_algo = C.algo;
  6045. var EvpKDF = C_algo.EvpKDF;
  6046. /**
  6047. * Abstract base cipher template.
  6048. *
  6049. * @property {number} keySize This cipher's key size. Default: 4 (128 bits)
  6050. * @property {number} ivSize This cipher's IV size. Default: 4 (128 bits)
  6051. * @property {number} _ENC_XFORM_MODE A constant representing encryption mode.
  6052. * @property {number} _DEC_XFORM_MODE A constant representing decryption mode.
  6053. */
  6054. var Cipher = C_lib.Cipher = BufferedBlockAlgorithm.extend({
  6055. /**
  6056. * Configuration options.
  6057. *
  6058. * @property {WordArray} iv The IV to use for this operation.
  6059. */
  6060. cfg: Base.extend(),
  6061. /**
  6062. * Creates this cipher in encryption mode.
  6063. *
  6064. * @param {WordArray} key The key.
  6065. * @param {Object} cfg (Optional) The configuration options to use for this operation.
  6066. *
  6067. * @return {Cipher} A cipher instance.
  6068. *
  6069. * @static
  6070. *
  6071. * @example
  6072. *
  6073. * var cipher = CryptoJS.algo.AES.createEncryptor(keyWordArray, { iv: ivWordArray });
  6074. */
  6075. createEncryptor: function (key, cfg) {
  6076. return this.create(this._ENC_XFORM_MODE, key, cfg);
  6077. },
  6078. /**
  6079. * Creates this cipher in decryption mode.
  6080. *
  6081. * @param {WordArray} key The key.
  6082. * @param {Object} cfg (Optional) The configuration options to use for this operation.
  6083. *
  6084. * @return {Cipher} A cipher instance.
  6085. *
  6086. * @static
  6087. *
  6088. * @example
  6089. *
  6090. * var cipher = CryptoJS.algo.AES.createDecryptor(keyWordArray, { iv: ivWordArray });
  6091. */
  6092. createDecryptor: function (key, cfg) {
  6093. return this.create(this._DEC_XFORM_MODE, key, cfg);
  6094. },
  6095. /**
  6096. * Initializes a newly created cipher.
  6097. *
  6098. * @param {number} xformMode Either the encryption or decryption transormation mode constant.
  6099. * @param {WordArray} key The key.
  6100. * @param {Object} cfg (Optional) The configuration options to use for this operation.
  6101. *
  6102. * @example
  6103. *
  6104. * var cipher = CryptoJS.algo.AES.create(CryptoJS.algo.AES._ENC_XFORM_MODE, keyWordArray, { iv: ivWordArray });
  6105. */
  6106. init: function (xformMode, key, cfg) {
  6107. // Apply config defaults
  6108. this.cfg = this.cfg.extend(cfg);
  6109. // Store transform mode and key
  6110. this._xformMode = xformMode;
  6111. this._key = key;
  6112. // Set initial values
  6113. this.reset();
  6114. },
  6115. /**
  6116. * Resets this cipher to its initial state.
  6117. *
  6118. * @example
  6119. *
  6120. * cipher.reset();
  6121. */
  6122. reset: function () {
  6123. // Reset data buffer
  6124. BufferedBlockAlgorithm.reset.call(this);
  6125. // Perform concrete-cipher logic
  6126. this._doReset();
  6127. },
  6128. /**
  6129. * Adds data to be encrypted or decrypted.
  6130. *
  6131. * @param {WordArray|string} dataUpdate The data to encrypt or decrypt.
  6132. *
  6133. * @return {WordArray} The data after processing.
  6134. *
  6135. * @example
  6136. *
  6137. * var encrypted = cipher.process('data');
  6138. * var encrypted = cipher.process(wordArray);
  6139. */
  6140. process: function (dataUpdate) {
  6141. // Append
  6142. this._append(dataUpdate);
  6143. // Process available blocks
  6144. return this._process();
  6145. },
  6146. /**
  6147. * Finalizes the encryption or decryption process.
  6148. * Note that the finalize operation is effectively a destructive, read-once operation.
  6149. *
  6150. * @param {WordArray|string} dataUpdate The final data to encrypt or decrypt.
  6151. *
  6152. * @return {WordArray} The data after final processing.
  6153. *
  6154. * @example
  6155. *
  6156. * var encrypted = cipher.finalize();
  6157. * var encrypted = cipher.finalize('data');
  6158. * var encrypted = cipher.finalize(wordArray);
  6159. */
  6160. finalize: function (dataUpdate) {
  6161. // Final data update
  6162. if (dataUpdate) {
  6163. this._append(dataUpdate);
  6164. }
  6165. // Perform concrete-cipher logic
  6166. var finalProcessedData = this._doFinalize();
  6167. return finalProcessedData;
  6168. },
  6169. keySize: 128/32,
  6170. ivSize: 128/32,
  6171. _ENC_XFORM_MODE: 1,
  6172. _DEC_XFORM_MODE: 2,
  6173. /**
  6174. * Creates shortcut functions to a cipher's object interface.
  6175. *
  6176. * @param {Cipher} cipher The cipher to create a helper for.
  6177. *
  6178. * @return {Object} An object with encrypt and decrypt shortcut functions.
  6179. *
  6180. * @static
  6181. *
  6182. * @example
  6183. *
  6184. * var AES = CryptoJS.lib.Cipher._createHelper(CryptoJS.algo.AES);
  6185. */
  6186. _createHelper: (function () {
  6187. function selectCipherStrategy(key) {
  6188. if (typeof key == 'string') {
  6189. return PasswordBasedCipher;
  6190. } else {
  6191. return SerializableCipher;
  6192. }
  6193. }
  6194. return function (cipher) {
  6195. return {
  6196. encrypt: function (message, key, cfg) {
  6197. return selectCipherStrategy(key).encrypt(cipher, message, key, cfg);
  6198. },
  6199. decrypt: function (ciphertext, key, cfg) {
  6200. return selectCipherStrategy(key).decrypt(cipher, ciphertext, key, cfg);
  6201. }
  6202. };
  6203. };
  6204. }())
  6205. });
  6206. /**
  6207. * Abstract base stream cipher template.
  6208. *
  6209. * @property {number} blockSize The number of 32-bit words this cipher operates on. Default: 1 (32 bits)
  6210. */
  6211. var StreamCipher = C_lib.StreamCipher = Cipher.extend({
  6212. _doFinalize: function () {
  6213. // Process partial blocks
  6214. var finalProcessedBlocks = this._process(!!'flush');
  6215. return finalProcessedBlocks;
  6216. },
  6217. blockSize: 1
  6218. });
  6219. /**
  6220. * Mode namespace.
  6221. */
  6222. var C_mode = C.mode = {};
  6223. /**
  6224. * Abstract base block cipher mode template.
  6225. */
  6226. var BlockCipherMode = C_lib.BlockCipherMode = Base.extend({
  6227. /**
  6228. * Creates this mode for encryption.
  6229. *
  6230. * @param {Cipher} cipher A block cipher instance.
  6231. * @param {Array} iv The IV words.
  6232. *
  6233. * @static
  6234. *
  6235. * @example
  6236. *
  6237. * var mode = CryptoJS.mode.CBC.createEncryptor(cipher, iv.words);
  6238. */
  6239. createEncryptor: function (cipher, iv) {
  6240. return this.Encryptor.create(cipher, iv);
  6241. },
  6242. /**
  6243. * Creates this mode for decryption.
  6244. *
  6245. * @param {Cipher} cipher A block cipher instance.
  6246. * @param {Array} iv The IV words.
  6247. *
  6248. * @static
  6249. *
  6250. * @example
  6251. *
  6252. * var mode = CryptoJS.mode.CBC.createDecryptor(cipher, iv.words);
  6253. */
  6254. createDecryptor: function (cipher, iv) {
  6255. return this.Decryptor.create(cipher, iv);
  6256. },
  6257. /**
  6258. * Initializes a newly created mode.
  6259. *
  6260. * @param {Cipher} cipher A block cipher instance.
  6261. * @param {Array} iv The IV words.
  6262. *
  6263. * @example
  6264. *
  6265. * var mode = CryptoJS.mode.CBC.Encryptor.create(cipher, iv.words);
  6266. */
  6267. init: function (cipher, iv) {
  6268. this._cipher = cipher;
  6269. this._iv = iv;
  6270. }
  6271. });
  6272. /**
  6273. * Cipher Block Chaining mode.
  6274. */
  6275. var CBC = C_mode.CBC = (function () {
  6276. /**
  6277. * Abstract base CBC mode.
  6278. */
  6279. var CBC = BlockCipherMode.extend();
  6280. /**
  6281. * CBC encryptor.
  6282. */
  6283. CBC.Encryptor = CBC.extend({
  6284. /**
  6285. * Processes the data block at offset.
  6286. *
  6287. * @param {Array} words The data words to operate on.
  6288. * @param {number} offset The offset where the block starts.
  6289. *
  6290. * @example
  6291. *
  6292. * mode.processBlock(data.words, offset);
  6293. */
  6294. processBlock: function (words, offset) {
  6295. // Shortcuts
  6296. var cipher = this._cipher;
  6297. var blockSize = cipher.blockSize;
  6298. // XOR and encrypt
  6299. xorBlock.call(this, words, offset, blockSize);
  6300. cipher.encryptBlock(words, offset);
  6301. // Remember this block to use with next block
  6302. this._prevBlock = words.slice(offset, offset + blockSize);
  6303. }
  6304. });
  6305. /**
  6306. * CBC decryptor.
  6307. */
  6308. CBC.Decryptor = CBC.extend({
  6309. /**
  6310. * Processes the data block at offset.
  6311. *
  6312. * @param {Array} words The data words to operate on.
  6313. * @param {number} offset The offset where the block starts.
  6314. *
  6315. * @example
  6316. *
  6317. * mode.processBlock(data.words, offset);
  6318. */
  6319. processBlock: function (words, offset) {
  6320. // Shortcuts
  6321. var cipher = this._cipher;
  6322. var blockSize = cipher.blockSize;
  6323. // Remember this block to use with next block
  6324. var thisBlock = words.slice(offset, offset + blockSize);
  6325. // Decrypt and XOR
  6326. cipher.decryptBlock(words, offset);
  6327. xorBlock.call(this, words, offset, blockSize);
  6328. // This block becomes the previous block
  6329. this._prevBlock = thisBlock;
  6330. }
  6331. });
  6332. function xorBlock(words, offset, blockSize) {
  6333. // Shortcut
  6334. var iv = this._iv;
  6335. // Choose mixing block
  6336. if (iv) {
  6337. var block = iv;
  6338. // Remove IV for subsequent blocks
  6339. this._iv = undefined;
  6340. } else {
  6341. var block = this._prevBlock;
  6342. }
  6343. // XOR blocks
  6344. for (var i = 0; i < blockSize; i++) {
  6345. words[offset + i] ^= block[i];
  6346. }
  6347. }
  6348. return CBC;
  6349. }());
  6350. /**
  6351. * Padding namespace.
  6352. */
  6353. var C_pad = C.pad = {};
  6354. /**
  6355. * PKCS #5/7 padding strategy.
  6356. */
  6357. var Pkcs7 = C_pad.Pkcs7 = {
  6358. /**
  6359. * Pads data using the algorithm defined in PKCS #5/7.
  6360. *
  6361. * @param {WordArray} data The data to pad.
  6362. * @param {number} blockSize The multiple that the data should be padded to.
  6363. *
  6364. * @static
  6365. *
  6366. * @example
  6367. *
  6368. * CryptoJS.pad.Pkcs7.pad(wordArray, 4);
  6369. */
  6370. pad: function (data, blockSize) {
  6371. // Shortcut
  6372. var blockSizeBytes = blockSize * 4;
  6373. // Count padding bytes
  6374. var nPaddingBytes = blockSizeBytes - data.sigBytes % blockSizeBytes;
  6375. // Create padding word
  6376. var paddingWord = (nPaddingBytes << 24) | (nPaddingBytes << 16) | (nPaddingBytes << 8) | nPaddingBytes;
  6377. // Create padding
  6378. var paddingWords = [];
  6379. for (var i = 0; i < nPaddingBytes; i += 4) {
  6380. paddingWords.push(paddingWord);
  6381. }
  6382. var padding = WordArray.create(paddingWords, nPaddingBytes);
  6383. // Add padding
  6384. data.concat(padding);
  6385. },
  6386. /**
  6387. * Unpads data that had been padded using the algorithm defined in PKCS #5/7.
  6388. *
  6389. * @param {WordArray} data The data to unpad.
  6390. *
  6391. * @static
  6392. *
  6393. * @example
  6394. *
  6395. * CryptoJS.pad.Pkcs7.unpad(wordArray);
  6396. */
  6397. unpad: function (data) {
  6398. // Get number of padding bytes from last byte
  6399. var nPaddingBytes = data.words[(data.sigBytes - 1) >>> 2] & 0xff;
  6400. // Remove padding
  6401. data.sigBytes -= nPaddingBytes;
  6402. }
  6403. };
  6404. /**
  6405. * Abstract base block cipher template.
  6406. *
  6407. * @property {number} blockSize The number of 32-bit words this cipher operates on. Default: 4 (128 bits)
  6408. */
  6409. var BlockCipher = C_lib.BlockCipher = Cipher.extend({
  6410. /**
  6411. * Configuration options.
  6412. *
  6413. * @property {Mode} mode The block mode to use. Default: CBC
  6414. * @property {Padding} padding The padding strategy to use. Default: Pkcs7
  6415. */
  6416. cfg: Cipher.cfg.extend({
  6417. mode: CBC,
  6418. padding: Pkcs7
  6419. }),
  6420. reset: function () {
  6421. // Reset cipher
  6422. Cipher.reset.call(this);
  6423. // Shortcuts
  6424. var cfg = this.cfg;
  6425. var iv = cfg.iv;
  6426. var mode = cfg.mode;
  6427. // Reset block mode
  6428. if (this._xformMode == this._ENC_XFORM_MODE) {
  6429. var modeCreator = mode.createEncryptor;
  6430. } else /* if (this._xformMode == this._DEC_XFORM_MODE) */ {
  6431. var modeCreator = mode.createDecryptor;
  6432. // Keep at least one block in the buffer for unpadding
  6433. this._minBufferSize = 1;
  6434. }
  6435. this._mode = modeCreator.call(mode, this, iv && iv.words);
  6436. },
  6437. _doProcessBlock: function (words, offset) {
  6438. this._mode.processBlock(words, offset);
  6439. },
  6440. _doFinalize: function () {
  6441. // Shortcut
  6442. var padding = this.cfg.padding;
  6443. // Finalize
  6444. if (this._xformMode == this._ENC_XFORM_MODE) {
  6445. // Pad data
  6446. padding.pad(this._data, this.blockSize);
  6447. // Process final blocks
  6448. var finalProcessedBlocks = this._process(!!'flush');
  6449. } else /* if (this._xformMode == this._DEC_XFORM_MODE) */ {
  6450. // Process final blocks
  6451. var finalProcessedBlocks = this._process(!!'flush');
  6452. // Unpad data
  6453. padding.unpad(finalProcessedBlocks);
  6454. }
  6455. return finalProcessedBlocks;
  6456. },
  6457. blockSize: 128/32
  6458. });
  6459. /**
  6460. * A collection of cipher parameters.
  6461. *
  6462. * @property {WordArray} ciphertext The raw ciphertext.
  6463. * @property {WordArray} key The key to this ciphertext.
  6464. * @property {WordArray} iv The IV used in the ciphering operation.
  6465. * @property {WordArray} salt The salt used with a key derivation function.
  6466. * @property {Cipher} algorithm The cipher algorithm.
  6467. * @property {Mode} mode The block mode used in the ciphering operation.
  6468. * @property {Padding} padding The padding scheme used in the ciphering operation.
  6469. * @property {number} blockSize The block size of the cipher.
  6470. * @property {Format} formatter The default formatting strategy to convert this cipher params object to a string.
  6471. */
  6472. var CipherParams = C_lib.CipherParams = Base.extend({
  6473. /**
  6474. * Initializes a newly created cipher params object.
  6475. *
  6476. * @param {Object} cipherParams An object with any of the possible cipher parameters.
  6477. *
  6478. * @example
  6479. *
  6480. * var cipherParams = CryptoJS.lib.CipherParams.create({
  6481. * ciphertext: ciphertextWordArray,
  6482. * key: keyWordArray,
  6483. * iv: ivWordArray,
  6484. * salt: saltWordArray,
  6485. * algorithm: CryptoJS.algo.AES,
  6486. * mode: CryptoJS.mode.CBC,
  6487. * padding: CryptoJS.pad.PKCS7,
  6488. * blockSize: 4,
  6489. * formatter: CryptoJS.format.OpenSSL
  6490. * });
  6491. */
  6492. init: function (cipherParams) {
  6493. this.mixIn(cipherParams);
  6494. },
  6495. /**
  6496. * Converts this cipher params object to a string.
  6497. *
  6498. * @param {Format} formatter (Optional) The formatting strategy to use.
  6499. *
  6500. * @return {string} The stringified cipher params.
  6501. *
  6502. * @throws Error If neither the formatter nor the default formatter is set.
  6503. *
  6504. * @example
  6505. *
  6506. * var string = cipherParams + '';
  6507. * var string = cipherParams.toString();
  6508. * var string = cipherParams.toString(CryptoJS.format.OpenSSL);
  6509. */
  6510. toString: function (formatter) {
  6511. return (formatter || this.formatter).stringify(this);
  6512. }
  6513. });
  6514. /**
  6515. * Format namespace.
  6516. */
  6517. var C_format = C.format = {};
  6518. /**
  6519. * OpenSSL formatting strategy.
  6520. */
  6521. var OpenSSLFormatter = C_format.OpenSSL = {
  6522. /**
  6523. * Converts a cipher params object to an OpenSSL-compatible string.
  6524. *
  6525. * @param {CipherParams} cipherParams The cipher params object.
  6526. *
  6527. * @return {string} The OpenSSL-compatible string.
  6528. *
  6529. * @static
  6530. *
  6531. * @example
  6532. *
  6533. * var openSSLString = CryptoJS.format.OpenSSL.stringify(cipherParams);
  6534. */
  6535. stringify: function (cipherParams) {
  6536. // Shortcuts
  6537. var ciphertext = cipherParams.ciphertext;
  6538. var salt = cipherParams.salt;
  6539. // Format
  6540. if (salt) {
  6541. var wordArray = WordArray.create([0x53616c74, 0x65645f5f]).concat(salt).concat(ciphertext);
  6542. } else {
  6543. var wordArray = ciphertext;
  6544. }
  6545. return wordArray.toString(Base64);
  6546. },
  6547. /**
  6548. * Converts an OpenSSL-compatible string to a cipher params object.
  6549. *
  6550. * @param {string} openSSLStr The OpenSSL-compatible string.
  6551. *
  6552. * @return {CipherParams} The cipher params object.
  6553. *
  6554. * @static
  6555. *
  6556. * @example
  6557. *
  6558. * var cipherParams = CryptoJS.format.OpenSSL.parse(openSSLString);
  6559. */
  6560. parse: function (openSSLStr) {
  6561. // Parse base64
  6562. var ciphertext = Base64.parse(openSSLStr);
  6563. // Shortcut
  6564. var ciphertextWords = ciphertext.words;
  6565. // Test for salt
  6566. if (ciphertextWords[0] == 0x53616c74 && ciphertextWords[1] == 0x65645f5f) {
  6567. // Extract salt
  6568. var salt = WordArray.create(ciphertextWords.slice(2, 4));
  6569. // Remove salt from ciphertext
  6570. ciphertextWords.splice(0, 4);
  6571. ciphertext.sigBytes -= 16;
  6572. }
  6573. return CipherParams.create({ ciphertext: ciphertext, salt: salt });
  6574. }
  6575. };
  6576. /**
  6577. * A cipher wrapper that returns ciphertext as a serializable cipher params object.
  6578. */
  6579. var SerializableCipher = C_lib.SerializableCipher = Base.extend({
  6580. /**
  6581. * Configuration options.
  6582. *
  6583. * @property {Formatter} format The formatting strategy to convert cipher param objects to and from a string. Default: OpenSSL
  6584. */
  6585. cfg: Base.extend({
  6586. format: OpenSSLFormatter
  6587. }),
  6588. /**
  6589. * Encrypts a message.
  6590. *
  6591. * @param {Cipher} cipher The cipher algorithm to use.
  6592. * @param {WordArray|string} message The message to encrypt.
  6593. * @param {WordArray} key The key.
  6594. * @param {Object} cfg (Optional) The configuration options to use for this operation.
  6595. *
  6596. * @return {CipherParams} A cipher params object.
  6597. *
  6598. * @static
  6599. *
  6600. * @example
  6601. *
  6602. * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key);
  6603. * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key, { iv: iv });
  6604. * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key, { iv: iv, format: CryptoJS.format.OpenSSL });
  6605. */
  6606. encrypt: function (cipher, message, key, cfg) {
  6607. // Apply config defaults
  6608. cfg = this.cfg.extend(cfg);
  6609. // Encrypt
  6610. var encryptor = cipher.createEncryptor(key, cfg);
  6611. var ciphertext = encryptor.finalize(message);
  6612. // Shortcut
  6613. var cipherCfg = encryptor.cfg;
  6614. // Create and return serializable cipher params
  6615. return CipherParams.create({
  6616. ciphertext: ciphertext,
  6617. key: key,
  6618. iv: cipherCfg.iv,
  6619. algorithm: cipher,
  6620. mode: cipherCfg.mode,
  6621. padding: cipherCfg.padding,
  6622. blockSize: cipher.blockSize,
  6623. formatter: cfg.format
  6624. });
  6625. },
  6626. /**
  6627. * Decrypts serialized ciphertext.
  6628. *
  6629. * @param {Cipher} cipher The cipher algorithm to use.
  6630. * @param {CipherParams|string} ciphertext The ciphertext to decrypt.
  6631. * @param {WordArray} key The key.
  6632. * @param {Object} cfg (Optional) The configuration options to use for this operation.
  6633. *
  6634. * @return {WordArray} The plaintext.
  6635. *
  6636. * @static
  6637. *
  6638. * @example
  6639. *
  6640. * var plaintext = CryptoJS.lib.SerializableCipher.decrypt(CryptoJS.algo.AES, formattedCiphertext, key, { iv: iv, format: CryptoJS.format.OpenSSL });
  6641. * var plaintext = CryptoJS.lib.SerializableCipher.decrypt(CryptoJS.algo.AES, ciphertextParams, key, { iv: iv, format: CryptoJS.format.OpenSSL });
  6642. */
  6643. decrypt: function (cipher, ciphertext, key, cfg) {
  6644. // Apply config defaults
  6645. cfg = this.cfg.extend(cfg);
  6646. // Convert string to CipherParams
  6647. ciphertext = this._parse(ciphertext, cfg.format);
  6648. // Decrypt
  6649. var plaintext = cipher.createDecryptor(key, cfg).finalize(ciphertext.ciphertext);
  6650. return plaintext;
  6651. },
  6652. /**
  6653. * Converts serialized ciphertext to CipherParams,
  6654. * else assumed CipherParams already and returns ciphertext unchanged.
  6655. *
  6656. * @param {CipherParams|string} ciphertext The ciphertext.
  6657. * @param {Formatter} format The formatting strategy to use to parse serialized ciphertext.
  6658. *
  6659. * @return {CipherParams} The unserialized ciphertext.
  6660. *
  6661. * @static
  6662. *
  6663. * @example
  6664. *
  6665. * var ciphertextParams = CryptoJS.lib.SerializableCipher._parse(ciphertextStringOrParams, format);
  6666. */
  6667. _parse: function (ciphertext, format) {
  6668. if (typeof ciphertext == 'string') {
  6669. return format.parse(ciphertext, this);
  6670. } else {
  6671. return ciphertext;
  6672. }
  6673. }
  6674. });
  6675. /**
  6676. * Key derivation function namespace.
  6677. */
  6678. var C_kdf = C.kdf = {};
  6679. /**
  6680. * OpenSSL key derivation function.
  6681. */
  6682. var OpenSSLKdf = C_kdf.OpenSSL = {
  6683. /**
  6684. * Derives a key and IV from a password.
  6685. *
  6686. * @param {string} password The password to derive from.
  6687. * @param {number} keySize The size in words of the key to generate.
  6688. * @param {number} ivSize The size in words of the IV to generate.
  6689. * @param {WordArray|string} salt (Optional) A 64-bit salt to use. If omitted, a salt will be generated randomly.
  6690. *
  6691. * @return {CipherParams} A cipher params object with the key, IV, and salt.
  6692. *
  6693. * @static
  6694. *
  6695. * @example
  6696. *
  6697. * var derivedParams = CryptoJS.kdf.OpenSSL.execute('Password', 256/32, 128/32);
  6698. * var derivedParams = CryptoJS.kdf.OpenSSL.execute('Password', 256/32, 128/32, 'saltsalt');
  6699. */
  6700. execute: function (password, keySize, ivSize, salt) {
  6701. // Generate random salt
  6702. if (!salt) {
  6703. salt = WordArray.random(64/8);
  6704. }
  6705. // Derive key and IV
  6706. var key = EvpKDF.create({ keySize: keySize + ivSize }).compute(password, salt);
  6707. // Separate key and IV
  6708. var iv = WordArray.create(key.words.slice(keySize), ivSize * 4);
  6709. key.sigBytes = keySize * 4;
  6710. // Return params
  6711. return CipherParams.create({ key: key, iv: iv, salt: salt });
  6712. }
  6713. };
  6714. /**
  6715. * A serializable cipher wrapper that derives the key from a password,
  6716. * and returns ciphertext as a serializable cipher params object.
  6717. */
  6718. var PasswordBasedCipher = C_lib.PasswordBasedCipher = SerializableCipher.extend({
  6719. /**
  6720. * Configuration options.
  6721. *
  6722. * @property {KDF} kdf The key derivation function to use to generate a key and IV from a password. Default: OpenSSL
  6723. */
  6724. cfg: SerializableCipher.cfg.extend({
  6725. kdf: OpenSSLKdf
  6726. }),
  6727. /**
  6728. * Encrypts a message using a password.
  6729. *
  6730. * @param {Cipher} cipher The cipher algorithm to use.
  6731. * @param {WordArray|string} message The message to encrypt.
  6732. * @param {string} password The password.
  6733. * @param {Object} cfg (Optional) The configuration options to use for this operation.
  6734. *
  6735. * @return {CipherParams} A cipher params object.
  6736. *
  6737. * @static
  6738. *
  6739. * @example
  6740. *
  6741. * var ciphertextParams = CryptoJS.lib.PasswordBasedCipher.encrypt(CryptoJS.algo.AES, message, 'password');
  6742. * var ciphertextParams = CryptoJS.lib.PasswordBasedCipher.encrypt(CryptoJS.algo.AES, message, 'password', { format: CryptoJS.format.OpenSSL });
  6743. */
  6744. encrypt: function (cipher, message, password, cfg) {
  6745. // Apply config defaults
  6746. cfg = this.cfg.extend(cfg);
  6747. // Derive key and other params
  6748. var derivedParams = cfg.kdf.execute(password, cipher.keySize, cipher.ivSize);
  6749. // Add IV to config
  6750. cfg.iv = derivedParams.iv;
  6751. // Encrypt
  6752. var ciphertext = SerializableCipher.encrypt.call(this, cipher, message, derivedParams.key, cfg);
  6753. // Mix in derived params
  6754. ciphertext.mixIn(derivedParams);
  6755. return ciphertext;
  6756. },
  6757. /**
  6758. * Decrypts serialized ciphertext using a password.
  6759. *
  6760. * @param {Cipher} cipher The cipher algorithm to use.
  6761. * @param {CipherParams|string} ciphertext The ciphertext to decrypt.
  6762. * @param {string} password The password.
  6763. * @param {Object} cfg (Optional) The configuration options to use for this operation.
  6764. *
  6765. * @return {WordArray} The plaintext.
  6766. *
  6767. * @static
  6768. *
  6769. * @example
  6770. *
  6771. * var plaintext = CryptoJS.lib.PasswordBasedCipher.decrypt(CryptoJS.algo.AES, formattedCiphertext, 'password', { format: CryptoJS.format.OpenSSL });
  6772. * var plaintext = CryptoJS.lib.PasswordBasedCipher.decrypt(CryptoJS.algo.AES, ciphertextParams, 'password', { format: CryptoJS.format.OpenSSL });
  6773. */
  6774. decrypt: function (cipher, ciphertext, password, cfg) {
  6775. // Apply config defaults
  6776. cfg = this.cfg.extend(cfg);
  6777. // Convert string to CipherParams
  6778. ciphertext = this._parse(ciphertext, cfg.format);
  6779. // Derive key and other params
  6780. var derivedParams = cfg.kdf.execute(password, cipher.keySize, cipher.ivSize, ciphertext.salt);
  6781. // Add IV to config
  6782. cfg.iv = derivedParams.iv;
  6783. // Decrypt
  6784. var plaintext = SerializableCipher.decrypt.call(this, cipher, ciphertext, derivedParams.key, cfg);
  6785. return plaintext;
  6786. }
  6787. });
  6788. }());
  6789. }));
  6790. },{"./core":53}],53:[function(require,module,exports){
  6791. ;(function (root, factory) {
  6792. if (typeof exports === "object") {
  6793. // CommonJS
  6794. module.exports = exports = factory();
  6795. }
  6796. else if (typeof define === "function" && define.amd) {
  6797. // AMD
  6798. define([], factory);
  6799. }
  6800. else {
  6801. // Global (browser)
  6802. root.CryptoJS = factory();
  6803. }
  6804. }(this, function () {
  6805. /**
  6806. * CryptoJS core components.
  6807. */
  6808. var CryptoJS = CryptoJS || (function (Math, undefined) {
  6809. /*
  6810. * Local polyfil of Object.create
  6811. */
  6812. var create = Object.create || (function () {
  6813. function F() {};
  6814. return function (obj) {
  6815. var subtype;
  6816. F.prototype = obj;
  6817. subtype = new F();
  6818. F.prototype = null;
  6819. return subtype;
  6820. };
  6821. }())
  6822. /**
  6823. * CryptoJS namespace.
  6824. */
  6825. var C = {};
  6826. /**
  6827. * Library namespace.
  6828. */
  6829. var C_lib = C.lib = {};
  6830. /**
  6831. * Base object for prototypal inheritance.
  6832. */
  6833. var Base = C_lib.Base = (function () {
  6834. return {
  6835. /**
  6836. * Creates a new object that inherits from this object.
  6837. *
  6838. * @param {Object} overrides Properties to copy into the new object.
  6839. *
  6840. * @return {Object} The new object.
  6841. *
  6842. * @static
  6843. *
  6844. * @example
  6845. *
  6846. * var MyType = CryptoJS.lib.Base.extend({
  6847. * field: 'value',
  6848. *
  6849. * method: function () {
  6850. * }
  6851. * });
  6852. */
  6853. extend: function (overrides) {
  6854. // Spawn
  6855. var subtype = create(this);
  6856. // Augment
  6857. if (overrides) {
  6858. subtype.mixIn(overrides);
  6859. }
  6860. // Create default initializer
  6861. if (!subtype.hasOwnProperty('init') || this.init === subtype.init) {
  6862. subtype.init = function () {
  6863. subtype.$super.init.apply(this, arguments);
  6864. };
  6865. }
  6866. // Initializer's prototype is the subtype object
  6867. subtype.init.prototype = subtype;
  6868. // Reference supertype
  6869. subtype.$super = this;
  6870. return subtype;
  6871. },
  6872. /**
  6873. * Extends this object and runs the init method.
  6874. * Arguments to create() will be passed to init().
  6875. *
  6876. * @return {Object} The new object.
  6877. *
  6878. * @static
  6879. *
  6880. * @example
  6881. *
  6882. * var instance = MyType.create();
  6883. */
  6884. create: function () {
  6885. var instance = this.extend();
  6886. instance.init.apply(instance, arguments);
  6887. return instance;
  6888. },
  6889. /**
  6890. * Initializes a newly created object.
  6891. * Override this method to add some logic when your objects are created.
  6892. *
  6893. * @example
  6894. *
  6895. * var MyType = CryptoJS.lib.Base.extend({
  6896. * init: function () {
  6897. * // ...
  6898. * }
  6899. * });
  6900. */
  6901. init: function () {
  6902. },
  6903. /**
  6904. * Copies properties into this object.
  6905. *
  6906. * @param {Object} properties The properties to mix in.
  6907. *
  6908. * @example
  6909. *
  6910. * MyType.mixIn({
  6911. * field: 'value'
  6912. * });
  6913. */
  6914. mixIn: function (properties) {
  6915. for (var propertyName in properties) {
  6916. if (properties.hasOwnProperty(propertyName)) {
  6917. this[propertyName] = properties[propertyName];
  6918. }
  6919. }
  6920. // IE won't copy toString using the loop above
  6921. if (properties.hasOwnProperty('toString')) {
  6922. this.toString = properties.toString;
  6923. }
  6924. },
  6925. /**
  6926. * Creates a copy of this object.
  6927. *
  6928. * @return {Object} The clone.
  6929. *
  6930. * @example
  6931. *
  6932. * var clone = instance.clone();
  6933. */
  6934. clone: function () {
  6935. return this.init.prototype.extend(this);
  6936. }
  6937. };
  6938. }());
  6939. /**
  6940. * An array of 32-bit words.
  6941. *
  6942. * @property {Array} words The array of 32-bit words.
  6943. * @property {number} sigBytes The number of significant bytes in this word array.
  6944. */
  6945. var WordArray = C_lib.WordArray = Base.extend({
  6946. /**
  6947. * Initializes a newly created word array.
  6948. *
  6949. * @param {Array} words (Optional) An array of 32-bit words.
  6950. * @param {number} sigBytes (Optional) The number of significant bytes in the words.
  6951. *
  6952. * @example
  6953. *
  6954. * var wordArray = CryptoJS.lib.WordArray.create();
  6955. * var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607]);
  6956. * var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607], 6);
  6957. */
  6958. init: function (words, sigBytes) {
  6959. words = this.words = words || [];
  6960. if (sigBytes != undefined) {
  6961. this.sigBytes = sigBytes;
  6962. } else {
  6963. this.sigBytes = words.length * 4;
  6964. }
  6965. },
  6966. /**
  6967. * Converts this word array to a string.
  6968. *
  6969. * @param {Encoder} encoder (Optional) The encoding strategy to use. Default: CryptoJS.enc.Hex
  6970. *
  6971. * @return {string} The stringified word array.
  6972. *
  6973. * @example
  6974. *
  6975. * var string = wordArray + '';
  6976. * var string = wordArray.toString();
  6977. * var string = wordArray.toString(CryptoJS.enc.Utf8);
  6978. */
  6979. toString: function (encoder) {
  6980. return (encoder || Hex).stringify(this);
  6981. },
  6982. /**
  6983. * Concatenates a word array to this word array.
  6984. *
  6985. * @param {WordArray} wordArray The word array to append.
  6986. *
  6987. * @return {WordArray} This word array.
  6988. *
  6989. * @example
  6990. *
  6991. * wordArray1.concat(wordArray2);
  6992. */
  6993. concat: function (wordArray) {
  6994. // Shortcuts
  6995. var thisWords = this.words;
  6996. var thatWords = wordArray.words;
  6997. var thisSigBytes = this.sigBytes;
  6998. var thatSigBytes = wordArray.sigBytes;
  6999. // Clamp excess bits
  7000. this.clamp();
  7001. // Concat
  7002. if (thisSigBytes % 4) {
  7003. // Copy one byte at a time
  7004. for (var i = 0; i < thatSigBytes; i++) {
  7005. var thatByte = (thatWords[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff;
  7006. thisWords[(thisSigBytes + i) >>> 2] |= thatByte << (24 - ((thisSigBytes + i) % 4) * 8);
  7007. }
  7008. } else {
  7009. // Copy one word at a time
  7010. for (var i = 0; i < thatSigBytes; i += 4) {
  7011. thisWords[(thisSigBytes + i) >>> 2] = thatWords[i >>> 2];
  7012. }
  7013. }
  7014. this.sigBytes += thatSigBytes;
  7015. // Chainable
  7016. return this;
  7017. },
  7018. /**
  7019. * Removes insignificant bits.
  7020. *
  7021. * @example
  7022. *
  7023. * wordArray.clamp();
  7024. */
  7025. clamp: function () {
  7026. // Shortcuts
  7027. var words = this.words;
  7028. var sigBytes = this.sigBytes;
  7029. // Clamp
  7030. words[sigBytes >>> 2] &= 0xffffffff << (32 - (sigBytes % 4) * 8);
  7031. words.length = Math.ceil(sigBytes / 4);
  7032. },
  7033. /**
  7034. * Creates a copy of this word array.
  7035. *
  7036. * @return {WordArray} The clone.
  7037. *
  7038. * @example
  7039. *
  7040. * var clone = wordArray.clone();
  7041. */
  7042. clone: function () {
  7043. var clone = Base.clone.call(this);
  7044. clone.words = this.words.slice(0);
  7045. return clone;
  7046. },
  7047. /**
  7048. * Creates a word array filled with random bytes.
  7049. *
  7050. * @param {number} nBytes The number of random bytes to generate.
  7051. *
  7052. * @return {WordArray} The random word array.
  7053. *
  7054. * @static
  7055. *
  7056. * @example
  7057. *
  7058. * var wordArray = CryptoJS.lib.WordArray.random(16);
  7059. */
  7060. random: function (nBytes) {
  7061. var words = [];
  7062. var r = (function (m_w) {
  7063. var m_w = m_w;
  7064. var m_z = 0x3ade68b1;
  7065. var mask = 0xffffffff;
  7066. return function () {
  7067. m_z = (0x9069 * (m_z & 0xFFFF) + (m_z >> 0x10)) & mask;
  7068. m_w = (0x4650 * (m_w & 0xFFFF) + (m_w >> 0x10)) & mask;
  7069. var result = ((m_z << 0x10) + m_w) & mask;
  7070. result /= 0x100000000;
  7071. result += 0.5;
  7072. return result * (Math.random() > .5 ? 1 : -1);
  7073. }
  7074. });
  7075. for (var i = 0, rcache; i < nBytes; i += 4) {
  7076. var _r = r((rcache || Math.random()) * 0x100000000);
  7077. rcache = _r() * 0x3ade67b7;
  7078. words.push((_r() * 0x100000000) | 0);
  7079. }
  7080. return new WordArray.init(words, nBytes);
  7081. }
  7082. });
  7083. /**
  7084. * Encoder namespace.
  7085. */
  7086. var C_enc = C.enc = {};
  7087. /**
  7088. * Hex encoding strategy.
  7089. */
  7090. var Hex = C_enc.Hex = {
  7091. /**
  7092. * Converts a word array to a hex string.
  7093. *
  7094. * @param {WordArray} wordArray The word array.
  7095. *
  7096. * @return {string} The hex string.
  7097. *
  7098. * @static
  7099. *
  7100. * @example
  7101. *
  7102. * var hexString = CryptoJS.enc.Hex.stringify(wordArray);
  7103. */
  7104. stringify: function (wordArray) {
  7105. // Shortcuts
  7106. var words = wordArray.words;
  7107. var sigBytes = wordArray.sigBytes;
  7108. // Convert
  7109. var hexChars = [];
  7110. for (var i = 0; i < sigBytes; i++) {
  7111. var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff;
  7112. hexChars.push((bite >>> 4).toString(16));
  7113. hexChars.push((bite & 0x0f).toString(16));
  7114. }
  7115. return hexChars.join('');
  7116. },
  7117. /**
  7118. * Converts a hex string to a word array.
  7119. *
  7120. * @param {string} hexStr The hex string.
  7121. *
  7122. * @return {WordArray} The word array.
  7123. *
  7124. * @static
  7125. *
  7126. * @example
  7127. *
  7128. * var wordArray = CryptoJS.enc.Hex.parse(hexString);
  7129. */
  7130. parse: function (hexStr) {
  7131. // Shortcut
  7132. var hexStrLength = hexStr.length;
  7133. // Convert
  7134. var words = [];
  7135. for (var i = 0; i < hexStrLength; i += 2) {
  7136. words[i >>> 3] |= parseInt(hexStr.substr(i, 2), 16) << (24 - (i % 8) * 4);
  7137. }
  7138. return new WordArray.init(words, hexStrLength / 2);
  7139. }
  7140. };
  7141. /**
  7142. * Latin1 encoding strategy.
  7143. */
  7144. var Latin1 = C_enc.Latin1 = {
  7145. /**
  7146. * Converts a word array to a Latin1 string.
  7147. *
  7148. * @param {WordArray} wordArray The word array.
  7149. *
  7150. * @return {string} The Latin1 string.
  7151. *
  7152. * @static
  7153. *
  7154. * @example
  7155. *
  7156. * var latin1String = CryptoJS.enc.Latin1.stringify(wordArray);
  7157. */
  7158. stringify: function (wordArray) {
  7159. // Shortcuts
  7160. var words = wordArray.words;
  7161. var sigBytes = wordArray.sigBytes;
  7162. // Convert
  7163. var latin1Chars = [];
  7164. for (var i = 0; i < sigBytes; i++) {
  7165. var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff;
  7166. latin1Chars.push(String.fromCharCode(bite));
  7167. }
  7168. return latin1Chars.join('');
  7169. },
  7170. /**
  7171. * Converts a Latin1 string to a word array.
  7172. *
  7173. * @param {string} latin1Str The Latin1 string.
  7174. *
  7175. * @return {WordArray} The word array.
  7176. *
  7177. * @static
  7178. *
  7179. * @example
  7180. *
  7181. * var wordArray = CryptoJS.enc.Latin1.parse(latin1String);
  7182. */
  7183. parse: function (latin1Str) {
  7184. // Shortcut
  7185. var latin1StrLength = latin1Str.length;
  7186. // Convert
  7187. var words = [];
  7188. for (var i = 0; i < latin1StrLength; i++) {
  7189. words[i >>> 2] |= (latin1Str.charCodeAt(i) & 0xff) << (24 - (i % 4) * 8);
  7190. }
  7191. return new WordArray.init(words, latin1StrLength);
  7192. }
  7193. };
  7194. /**
  7195. * UTF-8 encoding strategy.
  7196. */
  7197. var Utf8 = C_enc.Utf8 = {
  7198. /**
  7199. * Converts a word array to a UTF-8 string.
  7200. *
  7201. * @param {WordArray} wordArray The word array.
  7202. *
  7203. * @return {string} The UTF-8 string.
  7204. *
  7205. * @static
  7206. *
  7207. * @example
  7208. *
  7209. * var utf8String = CryptoJS.enc.Utf8.stringify(wordArray);
  7210. */
  7211. stringify: function (wordArray) {
  7212. try {
  7213. return decodeURIComponent(escape(Latin1.stringify(wordArray)));
  7214. } catch (e) {
  7215. throw new Error('Malformed UTF-8 data');
  7216. }
  7217. },
  7218. /**
  7219. * Converts a UTF-8 string to a word array.
  7220. *
  7221. * @param {string} utf8Str The UTF-8 string.
  7222. *
  7223. * @return {WordArray} The word array.
  7224. *
  7225. * @static
  7226. *
  7227. * @example
  7228. *
  7229. * var wordArray = CryptoJS.enc.Utf8.parse(utf8String);
  7230. */
  7231. parse: function (utf8Str) {
  7232. return Latin1.parse(unescape(encodeURIComponent(utf8Str)));
  7233. }
  7234. };
  7235. /**
  7236. * Abstract buffered block algorithm template.
  7237. *
  7238. * The property blockSize must be implemented in a concrete subtype.
  7239. *
  7240. * @property {number} _minBufferSize The number of blocks that should be kept unprocessed in the buffer. Default: 0
  7241. */
  7242. var BufferedBlockAlgorithm = C_lib.BufferedBlockAlgorithm = Base.extend({
  7243. /**
  7244. * Resets this block algorithm's data buffer to its initial state.
  7245. *
  7246. * @example
  7247. *
  7248. * bufferedBlockAlgorithm.reset();
  7249. */
  7250. reset: function () {
  7251. // Initial values
  7252. this._data = new WordArray.init();
  7253. this._nDataBytes = 0;
  7254. },
  7255. /**
  7256. * Adds new data to this block algorithm's buffer.
  7257. *
  7258. * @param {WordArray|string} data The data to append. Strings are converted to a WordArray using UTF-8.
  7259. *
  7260. * @example
  7261. *
  7262. * bufferedBlockAlgorithm._append('data');
  7263. * bufferedBlockAlgorithm._append(wordArray);
  7264. */
  7265. _append: function (data) {
  7266. // Convert string to WordArray, else assume WordArray already
  7267. if (typeof data == 'string') {
  7268. data = Utf8.parse(data);
  7269. }
  7270. // Append
  7271. this._data.concat(data);
  7272. this._nDataBytes += data.sigBytes;
  7273. },
  7274. /**
  7275. * Processes available data blocks.
  7276. *
  7277. * This method invokes _doProcessBlock(offset), which must be implemented by a concrete subtype.
  7278. *
  7279. * @param {boolean} doFlush Whether all blocks and partial blocks should be processed.
  7280. *
  7281. * @return {WordArray} The processed data.
  7282. *
  7283. * @example
  7284. *
  7285. * var processedData = bufferedBlockAlgorithm._process();
  7286. * var processedData = bufferedBlockAlgorithm._process(!!'flush');
  7287. */
  7288. _process: function (doFlush) {
  7289. // Shortcuts
  7290. var data = this._data;
  7291. var dataWords = data.words;
  7292. var dataSigBytes = data.sigBytes;
  7293. var blockSize = this.blockSize;
  7294. var blockSizeBytes = blockSize * 4;
  7295. // Count blocks ready
  7296. var nBlocksReady = dataSigBytes / blockSizeBytes;
  7297. if (doFlush) {
  7298. // Round up to include partial blocks
  7299. nBlocksReady = Math.ceil(nBlocksReady);
  7300. } else {
  7301. // Round down to include only full blocks,
  7302. // less the number of blocks that must remain in the buffer
  7303. nBlocksReady = Math.max((nBlocksReady | 0) - this._minBufferSize, 0);
  7304. }
  7305. // Count words ready
  7306. var nWordsReady = nBlocksReady * blockSize;
  7307. // Count bytes ready
  7308. var nBytesReady = Math.min(nWordsReady * 4, dataSigBytes);
  7309. // Process blocks
  7310. if (nWordsReady) {
  7311. for (var offset = 0; offset < nWordsReady; offset += blockSize) {
  7312. // Perform concrete-algorithm logic
  7313. this._doProcessBlock(dataWords, offset);
  7314. }
  7315. // Remove processed words
  7316. var processedWords = dataWords.splice(0, nWordsReady);
  7317. data.sigBytes -= nBytesReady;
  7318. }
  7319. // Return processed words
  7320. return new WordArray.init(processedWords, nBytesReady);
  7321. },
  7322. /**
  7323. * Creates a copy of this object.
  7324. *
  7325. * @return {Object} The clone.
  7326. *
  7327. * @example
  7328. *
  7329. * var clone = bufferedBlockAlgorithm.clone();
  7330. */
  7331. clone: function () {
  7332. var clone = Base.clone.call(this);
  7333. clone._data = this._data.clone();
  7334. return clone;
  7335. },
  7336. _minBufferSize: 0
  7337. });
  7338. /**
  7339. * Abstract hasher template.
  7340. *
  7341. * @property {number} blockSize The number of 32-bit words this hasher operates on. Default: 16 (512 bits)
  7342. */
  7343. var Hasher = C_lib.Hasher = BufferedBlockAlgorithm.extend({
  7344. /**
  7345. * Configuration options.
  7346. */
  7347. cfg: Base.extend(),
  7348. /**
  7349. * Initializes a newly created hasher.
  7350. *
  7351. * @param {Object} cfg (Optional) The configuration options to use for this hash computation.
  7352. *
  7353. * @example
  7354. *
  7355. * var hasher = CryptoJS.algo.SHA256.create();
  7356. */
  7357. init: function (cfg) {
  7358. // Apply config defaults
  7359. this.cfg = this.cfg.extend(cfg);
  7360. // Set initial values
  7361. this.reset();
  7362. },
  7363. /**
  7364. * Resets this hasher to its initial state.
  7365. *
  7366. * @example
  7367. *
  7368. * hasher.reset();
  7369. */
  7370. reset: function () {
  7371. // Reset data buffer
  7372. BufferedBlockAlgorithm.reset.call(this);
  7373. // Perform concrete-hasher logic
  7374. this._doReset();
  7375. },
  7376. /**
  7377. * Updates this hasher with a message.
  7378. *
  7379. * @param {WordArray|string} messageUpdate The message to append.
  7380. *
  7381. * @return {Hasher} This hasher.
  7382. *
  7383. * @example
  7384. *
  7385. * hasher.update('message');
  7386. * hasher.update(wordArray);
  7387. */
  7388. update: function (messageUpdate) {
  7389. // Append
  7390. this._append(messageUpdate);
  7391. // Update the hash
  7392. this._process();
  7393. // Chainable
  7394. return this;
  7395. },
  7396. /**
  7397. * Finalizes the hash computation.
  7398. * Note that the finalize operation is effectively a destructive, read-once operation.
  7399. *
  7400. * @param {WordArray|string} messageUpdate (Optional) A final message update.
  7401. *
  7402. * @return {WordArray} The hash.
  7403. *
  7404. * @example
  7405. *
  7406. * var hash = hasher.finalize();
  7407. * var hash = hasher.finalize('message');
  7408. * var hash = hasher.finalize(wordArray);
  7409. */
  7410. finalize: function (messageUpdate) {
  7411. // Final message update
  7412. if (messageUpdate) {
  7413. this._append(messageUpdate);
  7414. }
  7415. // Perform concrete-hasher logic
  7416. var hash = this._doFinalize();
  7417. return hash;
  7418. },
  7419. blockSize: 512/32,
  7420. /**
  7421. * Creates a shortcut function to a hasher's object interface.
  7422. *
  7423. * @param {Hasher} hasher The hasher to create a helper for.
  7424. *
  7425. * @return {Function} The shortcut function.
  7426. *
  7427. * @static
  7428. *
  7429. * @example
  7430. *
  7431. * var SHA256 = CryptoJS.lib.Hasher._createHelper(CryptoJS.algo.SHA256);
  7432. */
  7433. _createHelper: function (hasher) {
  7434. return function (message, cfg) {
  7435. return new hasher.init(cfg).finalize(message);
  7436. };
  7437. },
  7438. /**
  7439. * Creates a shortcut function to the HMAC's object interface.
  7440. *
  7441. * @param {Hasher} hasher The hasher to use in this HMAC helper.
  7442. *
  7443. * @return {Function} The shortcut function.
  7444. *
  7445. * @static
  7446. *
  7447. * @example
  7448. *
  7449. * var HmacSHA256 = CryptoJS.lib.Hasher._createHmacHelper(CryptoJS.algo.SHA256);
  7450. */
  7451. _createHmacHelper: function (hasher) {
  7452. return function (message, key) {
  7453. return new C_algo.HMAC.init(hasher, key).finalize(message);
  7454. };
  7455. }
  7456. });
  7457. /**
  7458. * Algorithm namespace.
  7459. */
  7460. var C_algo = C.algo = {};
  7461. return C;
  7462. }(Math));
  7463. return CryptoJS;
  7464. }));
  7465. },{}],54:[function(require,module,exports){
  7466. ;(function (root, factory) {
  7467. if (typeof exports === "object") {
  7468. // CommonJS
  7469. module.exports = exports = factory(require("./core"));
  7470. }
  7471. else if (typeof define === "function" && define.amd) {
  7472. // AMD
  7473. define(["./core"], factory);
  7474. }
  7475. else {
  7476. // Global (browser)
  7477. factory(root.CryptoJS);
  7478. }
  7479. }(this, function (CryptoJS) {
  7480. (function () {
  7481. // Shortcuts
  7482. var C = CryptoJS;
  7483. var C_lib = C.lib;
  7484. var WordArray = C_lib.WordArray;
  7485. var C_enc = C.enc;
  7486. /**
  7487. * Base64 encoding strategy.
  7488. */
  7489. var Base64 = C_enc.Base64 = {
  7490. /**
  7491. * Converts a word array to a Base64 string.
  7492. *
  7493. * @param {WordArray} wordArray The word array.
  7494. *
  7495. * @return {string} The Base64 string.
  7496. *
  7497. * @static
  7498. *
  7499. * @example
  7500. *
  7501. * var base64String = CryptoJS.enc.Base64.stringify(wordArray);
  7502. */
  7503. stringify: function (wordArray) {
  7504. // Shortcuts
  7505. var words = wordArray.words;
  7506. var sigBytes = wordArray.sigBytes;
  7507. var map = this._map;
  7508. // Clamp excess bits
  7509. wordArray.clamp();
  7510. // Convert
  7511. var base64Chars = [];
  7512. for (var i = 0; i < sigBytes; i += 3) {
  7513. var byte1 = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff;
  7514. var byte2 = (words[(i + 1) >>> 2] >>> (24 - ((i + 1) % 4) * 8)) & 0xff;
  7515. var byte3 = (words[(i + 2) >>> 2] >>> (24 - ((i + 2) % 4) * 8)) & 0xff;
  7516. var triplet = (byte1 << 16) | (byte2 << 8) | byte3;
  7517. for (var j = 0; (j < 4) && (i + j * 0.75 < sigBytes); j++) {
  7518. base64Chars.push(map.charAt((triplet >>> (6 * (3 - j))) & 0x3f));
  7519. }
  7520. }
  7521. // Add padding
  7522. var paddingChar = map.charAt(64);
  7523. if (paddingChar) {
  7524. while (base64Chars.length % 4) {
  7525. base64Chars.push(paddingChar);
  7526. }
  7527. }
  7528. return base64Chars.join('');
  7529. },
  7530. /**
  7531. * Converts a Base64 string to a word array.
  7532. *
  7533. * @param {string} base64Str The Base64 string.
  7534. *
  7535. * @return {WordArray} The word array.
  7536. *
  7537. * @static
  7538. *
  7539. * @example
  7540. *
  7541. * var wordArray = CryptoJS.enc.Base64.parse(base64String);
  7542. */
  7543. parse: function (base64Str) {
  7544. // Shortcuts
  7545. var base64StrLength = base64Str.length;
  7546. var map = this._map;
  7547. var reverseMap = this._reverseMap;
  7548. if (!reverseMap) {
  7549. reverseMap = this._reverseMap = [];
  7550. for (var j = 0; j < map.length; j++) {
  7551. reverseMap[map.charCodeAt(j)] = j;
  7552. }
  7553. }
  7554. // Ignore padding
  7555. var paddingChar = map.charAt(64);
  7556. if (paddingChar) {
  7557. var paddingIndex = base64Str.indexOf(paddingChar);
  7558. if (paddingIndex !== -1) {
  7559. base64StrLength = paddingIndex;
  7560. }
  7561. }
  7562. // Convert
  7563. return parseLoop(base64Str, base64StrLength, reverseMap);
  7564. },
  7565. _map: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='
  7566. };
  7567. function parseLoop(base64Str, base64StrLength, reverseMap) {
  7568. var words = [];
  7569. var nBytes = 0;
  7570. for (var i = 0; i < base64StrLength; i++) {
  7571. if (i % 4) {
  7572. var bits1 = reverseMap[base64Str.charCodeAt(i - 1)] << ((i % 4) * 2);
  7573. var bits2 = reverseMap[base64Str.charCodeAt(i)] >>> (6 - (i % 4) * 2);
  7574. words[nBytes >>> 2] |= (bits1 | bits2) << (24 - (nBytes % 4) * 8);
  7575. nBytes++;
  7576. }
  7577. }
  7578. return WordArray.create(words, nBytes);
  7579. }
  7580. }());
  7581. return CryptoJS.enc.Base64;
  7582. }));
  7583. },{"./core":53}],55:[function(require,module,exports){
  7584. ;(function (root, factory) {
  7585. if (typeof exports === "object") {
  7586. // CommonJS
  7587. module.exports = exports = factory(require("./core"));
  7588. }
  7589. else if (typeof define === "function" && define.amd) {
  7590. // AMD
  7591. define(["./core"], factory);
  7592. }
  7593. else {
  7594. // Global (browser)
  7595. factory(root.CryptoJS);
  7596. }
  7597. }(this, function (CryptoJS) {
  7598. (function () {
  7599. // Shortcuts
  7600. var C = CryptoJS;
  7601. var C_lib = C.lib;
  7602. var WordArray = C_lib.WordArray;
  7603. var C_enc = C.enc;
  7604. /**
  7605. * UTF-16 BE encoding strategy.
  7606. */
  7607. var Utf16BE = C_enc.Utf16 = C_enc.Utf16BE = {
  7608. /**
  7609. * Converts a word array to a UTF-16 BE string.
  7610. *
  7611. * @param {WordArray} wordArray The word array.
  7612. *
  7613. * @return {string} The UTF-16 BE string.
  7614. *
  7615. * @static
  7616. *
  7617. * @example
  7618. *
  7619. * var utf16String = CryptoJS.enc.Utf16.stringify(wordArray);
  7620. */
  7621. stringify: function (wordArray) {
  7622. // Shortcuts
  7623. var words = wordArray.words;
  7624. var sigBytes = wordArray.sigBytes;
  7625. // Convert
  7626. var utf16Chars = [];
  7627. for (var i = 0; i < sigBytes; i += 2) {
  7628. var codePoint = (words[i >>> 2] >>> (16 - (i % 4) * 8)) & 0xffff;
  7629. utf16Chars.push(String.fromCharCode(codePoint));
  7630. }
  7631. return utf16Chars.join('');
  7632. },
  7633. /**
  7634. * Converts a UTF-16 BE string to a word array.
  7635. *
  7636. * @param {string} utf16Str The UTF-16 BE string.
  7637. *
  7638. * @return {WordArray} The word array.
  7639. *
  7640. * @static
  7641. *
  7642. * @example
  7643. *
  7644. * var wordArray = CryptoJS.enc.Utf16.parse(utf16String);
  7645. */
  7646. parse: function (utf16Str) {
  7647. // Shortcut
  7648. var utf16StrLength = utf16Str.length;
  7649. // Convert
  7650. var words = [];
  7651. for (var i = 0; i < utf16StrLength; i++) {
  7652. words[i >>> 1] |= utf16Str.charCodeAt(i) << (16 - (i % 2) * 16);
  7653. }
  7654. return WordArray.create(words, utf16StrLength * 2);
  7655. }
  7656. };
  7657. /**
  7658. * UTF-16 LE encoding strategy.
  7659. */
  7660. C_enc.Utf16LE = {
  7661. /**
  7662. * Converts a word array to a UTF-16 LE string.
  7663. *
  7664. * @param {WordArray} wordArray The word array.
  7665. *
  7666. * @return {string} The UTF-16 LE string.
  7667. *
  7668. * @static
  7669. *
  7670. * @example
  7671. *
  7672. * var utf16Str = CryptoJS.enc.Utf16LE.stringify(wordArray);
  7673. */
  7674. stringify: function (wordArray) {
  7675. // Shortcuts
  7676. var words = wordArray.words;
  7677. var sigBytes = wordArray.sigBytes;
  7678. // Convert
  7679. var utf16Chars = [];
  7680. for (var i = 0; i < sigBytes; i += 2) {
  7681. var codePoint = swapEndian((words[i >>> 2] >>> (16 - (i % 4) * 8)) & 0xffff);
  7682. utf16Chars.push(String.fromCharCode(codePoint));
  7683. }
  7684. return utf16Chars.join('');
  7685. },
  7686. /**
  7687. * Converts a UTF-16 LE string to a word array.
  7688. *
  7689. * @param {string} utf16Str The UTF-16 LE string.
  7690. *
  7691. * @return {WordArray} The word array.
  7692. *
  7693. * @static
  7694. *
  7695. * @example
  7696. *
  7697. * var wordArray = CryptoJS.enc.Utf16LE.parse(utf16Str);
  7698. */
  7699. parse: function (utf16Str) {
  7700. // Shortcut
  7701. var utf16StrLength = utf16Str.length;
  7702. // Convert
  7703. var words = [];
  7704. for (var i = 0; i < utf16StrLength; i++) {
  7705. words[i >>> 1] |= swapEndian(utf16Str.charCodeAt(i) << (16 - (i % 2) * 16));
  7706. }
  7707. return WordArray.create(words, utf16StrLength * 2);
  7708. }
  7709. };
  7710. function swapEndian(word) {
  7711. return ((word << 8) & 0xff00ff00) | ((word >>> 8) & 0x00ff00ff);
  7712. }
  7713. }());
  7714. return CryptoJS.enc.Utf16;
  7715. }));
  7716. },{"./core":53}],56:[function(require,module,exports){
  7717. ;(function (root, factory, undef) {
  7718. if (typeof exports === "object") {
  7719. // CommonJS
  7720. module.exports = exports = factory(require("./core"), require("./sha1"), require("./hmac"));
  7721. }
  7722. else if (typeof define === "function" && define.amd) {
  7723. // AMD
  7724. define(["./core", "./sha1", "./hmac"], factory);
  7725. }
  7726. else {
  7727. // Global (browser)
  7728. factory(root.CryptoJS);
  7729. }
  7730. }(this, function (CryptoJS) {
  7731. (function () {
  7732. // Shortcuts
  7733. var C = CryptoJS;
  7734. var C_lib = C.lib;
  7735. var Base = C_lib.Base;
  7736. var WordArray = C_lib.WordArray;
  7737. var C_algo = C.algo;
  7738. var MD5 = C_algo.MD5;
  7739. /**
  7740. * This key derivation function is meant to conform with EVP_BytesToKey.
  7741. * www.openssl.org/docs/crypto/EVP_BytesToKey.html
  7742. */
  7743. var EvpKDF = C_algo.EvpKDF = Base.extend({
  7744. /**
  7745. * Configuration options.
  7746. *
  7747. * @property {number} keySize The key size in words to generate. Default: 4 (128 bits)
  7748. * @property {Hasher} hasher The hash algorithm to use. Default: MD5
  7749. * @property {number} iterations The number of iterations to perform. Default: 1
  7750. */
  7751. cfg: Base.extend({
  7752. keySize: 128/32,
  7753. hasher: MD5,
  7754. iterations: 1
  7755. }),
  7756. /**
  7757. * Initializes a newly created key derivation function.
  7758. *
  7759. * @param {Object} cfg (Optional) The configuration options to use for the derivation.
  7760. *
  7761. * @example
  7762. *
  7763. * var kdf = CryptoJS.algo.EvpKDF.create();
  7764. * var kdf = CryptoJS.algo.EvpKDF.create({ keySize: 8 });
  7765. * var kdf = CryptoJS.algo.EvpKDF.create({ keySize: 8, iterations: 1000 });
  7766. */
  7767. init: function (cfg) {
  7768. this.cfg = this.cfg.extend(cfg);
  7769. },
  7770. /**
  7771. * Derives a key from a password.
  7772. *
  7773. * @param {WordArray|string} password The password.
  7774. * @param {WordArray|string} salt A salt.
  7775. *
  7776. * @return {WordArray} The derived key.
  7777. *
  7778. * @example
  7779. *
  7780. * var key = kdf.compute(password, salt);
  7781. */
  7782. compute: function (password, salt) {
  7783. // Shortcut
  7784. var cfg = this.cfg;
  7785. // Init hasher
  7786. var hasher = cfg.hasher.create();
  7787. // Initial values
  7788. var derivedKey = WordArray.create();
  7789. // Shortcuts
  7790. var derivedKeyWords = derivedKey.words;
  7791. var keySize = cfg.keySize;
  7792. var iterations = cfg.iterations;
  7793. // Generate key
  7794. while (derivedKeyWords.length < keySize) {
  7795. if (block) {
  7796. hasher.update(block);
  7797. }
  7798. var block = hasher.update(password).finalize(salt);
  7799. hasher.reset();
  7800. // Iterations
  7801. for (var i = 1; i < iterations; i++) {
  7802. block = hasher.finalize(block);
  7803. hasher.reset();
  7804. }
  7805. derivedKey.concat(block);
  7806. }
  7807. derivedKey.sigBytes = keySize * 4;
  7808. return derivedKey;
  7809. }
  7810. });
  7811. /**
  7812. * Derives a key from a password.
  7813. *
  7814. * @param {WordArray|string} password The password.
  7815. * @param {WordArray|string} salt A salt.
  7816. * @param {Object} cfg (Optional) The configuration options to use for this computation.
  7817. *
  7818. * @return {WordArray} The derived key.
  7819. *
  7820. * @static
  7821. *
  7822. * @example
  7823. *
  7824. * var key = CryptoJS.EvpKDF(password, salt);
  7825. * var key = CryptoJS.EvpKDF(password, salt, { keySize: 8 });
  7826. * var key = CryptoJS.EvpKDF(password, salt, { keySize: 8, iterations: 1000 });
  7827. */
  7828. C.EvpKDF = function (password, salt, cfg) {
  7829. return EvpKDF.create(cfg).compute(password, salt);
  7830. };
  7831. }());
  7832. return CryptoJS.EvpKDF;
  7833. }));
  7834. },{"./core":53,"./hmac":58,"./sha1":77}],57:[function(require,module,exports){
  7835. ;(function (root, factory, undef) {
  7836. if (typeof exports === "object") {
  7837. // CommonJS
  7838. module.exports = exports = factory(require("./core"), require("./cipher-core"));
  7839. }
  7840. else if (typeof define === "function" && define.amd) {
  7841. // AMD
  7842. define(["./core", "./cipher-core"], factory);
  7843. }
  7844. else {
  7845. // Global (browser)
  7846. factory(root.CryptoJS);
  7847. }
  7848. }(this, function (CryptoJS) {
  7849. (function (undefined) {
  7850. // Shortcuts
  7851. var C = CryptoJS;
  7852. var C_lib = C.lib;
  7853. var CipherParams = C_lib.CipherParams;
  7854. var C_enc = C.enc;
  7855. var Hex = C_enc.Hex;
  7856. var C_format = C.format;
  7857. var HexFormatter = C_format.Hex = {
  7858. /**
  7859. * Converts the ciphertext of a cipher params object to a hexadecimally encoded string.
  7860. *
  7861. * @param {CipherParams} cipherParams The cipher params object.
  7862. *
  7863. * @return {string} The hexadecimally encoded string.
  7864. *
  7865. * @static
  7866. *
  7867. * @example
  7868. *
  7869. * var hexString = CryptoJS.format.Hex.stringify(cipherParams);
  7870. */
  7871. stringify: function (cipherParams) {
  7872. return cipherParams.ciphertext.toString(Hex);
  7873. },
  7874. /**
  7875. * Converts a hexadecimally encoded ciphertext string to a cipher params object.
  7876. *
  7877. * @param {string} input The hexadecimally encoded string.
  7878. *
  7879. * @return {CipherParams} The cipher params object.
  7880. *
  7881. * @static
  7882. *
  7883. * @example
  7884. *
  7885. * var cipherParams = CryptoJS.format.Hex.parse(hexString);
  7886. */
  7887. parse: function (input) {
  7888. var ciphertext = Hex.parse(input);
  7889. return CipherParams.create({ ciphertext: ciphertext });
  7890. }
  7891. };
  7892. }());
  7893. return CryptoJS.format.Hex;
  7894. }));
  7895. },{"./cipher-core":52,"./core":53}],58:[function(require,module,exports){
  7896. ;(function (root, factory) {
  7897. if (typeof exports === "object") {
  7898. // CommonJS
  7899. module.exports = exports = factory(require("./core"));
  7900. }
  7901. else if (typeof define === "function" && define.amd) {
  7902. // AMD
  7903. define(["./core"], factory);
  7904. }
  7905. else {
  7906. // Global (browser)
  7907. factory(root.CryptoJS);
  7908. }
  7909. }(this, function (CryptoJS) {
  7910. (function () {
  7911. // Shortcuts
  7912. var C = CryptoJS;
  7913. var C_lib = C.lib;
  7914. var Base = C_lib.Base;
  7915. var C_enc = C.enc;
  7916. var Utf8 = C_enc.Utf8;
  7917. var C_algo = C.algo;
  7918. /**
  7919. * HMAC algorithm.
  7920. */
  7921. var HMAC = C_algo.HMAC = Base.extend({
  7922. /**
  7923. * Initializes a newly created HMAC.
  7924. *
  7925. * @param {Hasher} hasher The hash algorithm to use.
  7926. * @param {WordArray|string} key The secret key.
  7927. *
  7928. * @example
  7929. *
  7930. * var hmacHasher = CryptoJS.algo.HMAC.create(CryptoJS.algo.SHA256, key);
  7931. */
  7932. init: function (hasher, key) {
  7933. // Init hasher
  7934. hasher = this._hasher = new hasher.init();
  7935. // Convert string to WordArray, else assume WordArray already
  7936. if (typeof key == 'string') {
  7937. key = Utf8.parse(key);
  7938. }
  7939. // Shortcuts
  7940. var hasherBlockSize = hasher.blockSize;
  7941. var hasherBlockSizeBytes = hasherBlockSize * 4;
  7942. // Allow arbitrary length keys
  7943. if (key.sigBytes > hasherBlockSizeBytes) {
  7944. key = hasher.finalize(key);
  7945. }
  7946. // Clamp excess bits
  7947. key.clamp();
  7948. // Clone key for inner and outer pads
  7949. var oKey = this._oKey = key.clone();
  7950. var iKey = this._iKey = key.clone();
  7951. // Shortcuts
  7952. var oKeyWords = oKey.words;
  7953. var iKeyWords = iKey.words;
  7954. // XOR keys with pad constants
  7955. for (var i = 0; i < hasherBlockSize; i++) {
  7956. oKeyWords[i] ^= 0x5c5c5c5c;
  7957. iKeyWords[i] ^= 0x36363636;
  7958. }
  7959. oKey.sigBytes = iKey.sigBytes = hasherBlockSizeBytes;
  7960. // Set initial values
  7961. this.reset();
  7962. },
  7963. /**
  7964. * Resets this HMAC to its initial state.
  7965. *
  7966. * @example
  7967. *
  7968. * hmacHasher.reset();
  7969. */
  7970. reset: function () {
  7971. // Shortcut
  7972. var hasher = this._hasher;
  7973. // Reset
  7974. hasher.reset();
  7975. hasher.update(this._iKey);
  7976. },
  7977. /**
  7978. * Updates this HMAC with a message.
  7979. *
  7980. * @param {WordArray|string} messageUpdate The message to append.
  7981. *
  7982. * @return {HMAC} This HMAC instance.
  7983. *
  7984. * @example
  7985. *
  7986. * hmacHasher.update('message');
  7987. * hmacHasher.update(wordArray);
  7988. */
  7989. update: function (messageUpdate) {
  7990. this._hasher.update(messageUpdate);
  7991. // Chainable
  7992. return this;
  7993. },
  7994. /**
  7995. * Finalizes the HMAC computation.
  7996. * Note that the finalize operation is effectively a destructive, read-once operation.
  7997. *
  7998. * @param {WordArray|string} messageUpdate (Optional) A final message update.
  7999. *
  8000. * @return {WordArray} The HMAC.
  8001. *
  8002. * @example
  8003. *
  8004. * var hmac = hmacHasher.finalize();
  8005. * var hmac = hmacHasher.finalize('message');
  8006. * var hmac = hmacHasher.finalize(wordArray);
  8007. */
  8008. finalize: function (messageUpdate) {
  8009. // Shortcut
  8010. var hasher = this._hasher;
  8011. // Compute HMAC
  8012. var innerHash = hasher.finalize(messageUpdate);
  8013. hasher.reset();
  8014. var hmac = hasher.finalize(this._oKey.clone().concat(innerHash));
  8015. return hmac;
  8016. }
  8017. });
  8018. }());
  8019. }));
  8020. },{"./core":53}],59:[function(require,module,exports){
  8021. ;(function (root, factory, undef) {
  8022. if (typeof exports === "object") {
  8023. // CommonJS
  8024. 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"));
  8025. }
  8026. else if (typeof define === "function" && define.amd) {
  8027. // AMD
  8028. 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);
  8029. }
  8030. else {
  8031. // Global (browser)
  8032. root.CryptoJS = factory(root.CryptoJS);
  8033. }
  8034. }(this, function (CryptoJS) {
  8035. return CryptoJS;
  8036. }));
  8037. },{"./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){
  8038. ;(function (root, factory) {
  8039. if (typeof exports === "object") {
  8040. // CommonJS
  8041. module.exports = exports = factory(require("./core"));
  8042. }
  8043. else if (typeof define === "function" && define.amd) {
  8044. // AMD
  8045. define(["./core"], factory);
  8046. }
  8047. else {
  8048. // Global (browser)
  8049. factory(root.CryptoJS);
  8050. }
  8051. }(this, function (CryptoJS) {
  8052. (function () {
  8053. // Check if typed arrays are supported
  8054. if (typeof ArrayBuffer != 'function') {
  8055. return;
  8056. }
  8057. // Shortcuts
  8058. var C = CryptoJS;
  8059. var C_lib = C.lib;
  8060. var WordArray = C_lib.WordArray;
  8061. // Reference original init
  8062. var superInit = WordArray.init;
  8063. // Augment WordArray.init to handle typed arrays
  8064. var subInit = WordArray.init = function (typedArray) {
  8065. // Convert buffers to uint8
  8066. if (typedArray instanceof ArrayBuffer) {
  8067. typedArray = new Uint8Array(typedArray);
  8068. }
  8069. // Convert other array views to uint8
  8070. if (
  8071. typedArray instanceof Int8Array ||
  8072. (typeof Uint8ClampedArray !== "undefined" && typedArray instanceof Uint8ClampedArray) ||
  8073. typedArray instanceof Int16Array ||
  8074. typedArray instanceof Uint16Array ||
  8075. typedArray instanceof Int32Array ||
  8076. typedArray instanceof Uint32Array ||
  8077. typedArray instanceof Float32Array ||
  8078. typedArray instanceof Float64Array
  8079. ) {
  8080. typedArray = new Uint8Array(typedArray.buffer, typedArray.byteOffset, typedArray.byteLength);
  8081. }
  8082. // Handle Uint8Array
  8083. if (typedArray instanceof Uint8Array) {
  8084. // Shortcut
  8085. var typedArrayByteLength = typedArray.byteLength;
  8086. // Extract bytes
  8087. var words = [];
  8088. for (var i = 0; i < typedArrayByteLength; i++) {
  8089. words[i >>> 2] |= typedArray[i] << (24 - (i % 4) * 8);
  8090. }
  8091. // Initialize this word array
  8092. superInit.call(this, words, typedArrayByteLength);
  8093. } else {
  8094. // Else call normal init
  8095. superInit.apply(this, arguments);
  8096. }
  8097. };
  8098. subInit.prototype = WordArray;
  8099. }());
  8100. return CryptoJS.lib.WordArray;
  8101. }));
  8102. },{"./core":53}],61:[function(require,module,exports){
  8103. ;(function (root, factory) {
  8104. if (typeof exports === "object") {
  8105. // CommonJS
  8106. module.exports = exports = factory(require("./core"));
  8107. }
  8108. else if (typeof define === "function" && define.amd) {
  8109. // AMD
  8110. define(["./core"], factory);
  8111. }
  8112. else {
  8113. // Global (browser)
  8114. factory(root.CryptoJS);
  8115. }
  8116. }(this, function (CryptoJS) {
  8117. (function (Math) {
  8118. // Shortcuts
  8119. var C = CryptoJS;
  8120. var C_lib = C.lib;
  8121. var WordArray = C_lib.WordArray;
  8122. var Hasher = C_lib.Hasher;
  8123. var C_algo = C.algo;
  8124. // Constants table
  8125. var T = [];
  8126. // Compute constants
  8127. (function () {
  8128. for (var i = 0; i < 64; i++) {
  8129. T[i] = (Math.abs(Math.sin(i + 1)) * 0x100000000) | 0;
  8130. }
  8131. }());
  8132. /**
  8133. * MD5 hash algorithm.
  8134. */
  8135. var MD5 = C_algo.MD5 = Hasher.extend({
  8136. _doReset: function () {
  8137. this._hash = new WordArray.init([
  8138. 0x67452301, 0xefcdab89,
  8139. 0x98badcfe, 0x10325476
  8140. ]);
  8141. },
  8142. _doProcessBlock: function (M, offset) {
  8143. // Swap endian
  8144. for (var i = 0; i < 16; i++) {
  8145. // Shortcuts
  8146. var offset_i = offset + i;
  8147. var M_offset_i = M[offset_i];
  8148. M[offset_i] = (
  8149. (((M_offset_i << 8) | (M_offset_i >>> 24)) & 0x00ff00ff) |
  8150. (((M_offset_i << 24) | (M_offset_i >>> 8)) & 0xff00ff00)
  8151. );
  8152. }
  8153. // Shortcuts
  8154. var H = this._hash.words;
  8155. var M_offset_0 = M[offset + 0];
  8156. var M_offset_1 = M[offset + 1];
  8157. var M_offset_2 = M[offset + 2];
  8158. var M_offset_3 = M[offset + 3];
  8159. var M_offset_4 = M[offset + 4];
  8160. var M_offset_5 = M[offset + 5];
  8161. var M_offset_6 = M[offset + 6];
  8162. var M_offset_7 = M[offset + 7];
  8163. var M_offset_8 = M[offset + 8];
  8164. var M_offset_9 = M[offset + 9];
  8165. var M_offset_10 = M[offset + 10];
  8166. var M_offset_11 = M[offset + 11];
  8167. var M_offset_12 = M[offset + 12];
  8168. var M_offset_13 = M[offset + 13];
  8169. var M_offset_14 = M[offset + 14];
  8170. var M_offset_15 = M[offset + 15];
  8171. // Working varialbes
  8172. var a = H[0];
  8173. var b = H[1];
  8174. var c = H[2];
  8175. var d = H[3];
  8176. // Computation
  8177. a = FF(a, b, c, d, M_offset_0, 7, T[0]);
  8178. d = FF(d, a, b, c, M_offset_1, 12, T[1]);
  8179. c = FF(c, d, a, b, M_offset_2, 17, T[2]);
  8180. b = FF(b, c, d, a, M_offset_3, 22, T[3]);
  8181. a = FF(a, b, c, d, M_offset_4, 7, T[4]);
  8182. d = FF(d, a, b, c, M_offset_5, 12, T[5]);
  8183. c = FF(c, d, a, b, M_offset_6, 17, T[6]);
  8184. b = FF(b, c, d, a, M_offset_7, 22, T[7]);
  8185. a = FF(a, b, c, d, M_offset_8, 7, T[8]);
  8186. d = FF(d, a, b, c, M_offset_9, 12, T[9]);
  8187. c = FF(c, d, a, b, M_offset_10, 17, T[10]);
  8188. b = FF(b, c, d, a, M_offset_11, 22, T[11]);
  8189. a = FF(a, b, c, d, M_offset_12, 7, T[12]);
  8190. d = FF(d, a, b, c, M_offset_13, 12, T[13]);
  8191. c = FF(c, d, a, b, M_offset_14, 17, T[14]);
  8192. b = FF(b, c, d, a, M_offset_15, 22, T[15]);
  8193. a = GG(a, b, c, d, M_offset_1, 5, T[16]);
  8194. d = GG(d, a, b, c, M_offset_6, 9, T[17]);
  8195. c = GG(c, d, a, b, M_offset_11, 14, T[18]);
  8196. b = GG(b, c, d, a, M_offset_0, 20, T[19]);
  8197. a = GG(a, b, c, d, M_offset_5, 5, T[20]);
  8198. d = GG(d, a, b, c, M_offset_10, 9, T[21]);
  8199. c = GG(c, d, a, b, M_offset_15, 14, T[22]);
  8200. b = GG(b, c, d, a, M_offset_4, 20, T[23]);
  8201. a = GG(a, b, c, d, M_offset_9, 5, T[24]);
  8202. d = GG(d, a, b, c, M_offset_14, 9, T[25]);
  8203. c = GG(c, d, a, b, M_offset_3, 14, T[26]);
  8204. b = GG(b, c, d, a, M_offset_8, 20, T[27]);
  8205. a = GG(a, b, c, d, M_offset_13, 5, T[28]);
  8206. d = GG(d, a, b, c, M_offset_2, 9, T[29]);
  8207. c = GG(c, d, a, b, M_offset_7, 14, T[30]);
  8208. b = GG(b, c, d, a, M_offset_12, 20, T[31]);
  8209. a = HH(a, b, c, d, M_offset_5, 4, T[32]);
  8210. d = HH(d, a, b, c, M_offset_8, 11, T[33]);
  8211. c = HH(c, d, a, b, M_offset_11, 16, T[34]);
  8212. b = HH(b, c, d, a, M_offset_14, 23, T[35]);
  8213. a = HH(a, b, c, d, M_offset_1, 4, T[36]);
  8214. d = HH(d, a, b, c, M_offset_4, 11, T[37]);
  8215. c = HH(c, d, a, b, M_offset_7, 16, T[38]);
  8216. b = HH(b, c, d, a, M_offset_10, 23, T[39]);
  8217. a = HH(a, b, c, d, M_offset_13, 4, T[40]);
  8218. d = HH(d, a, b, c, M_offset_0, 11, T[41]);
  8219. c = HH(c, d, a, b, M_offset_3, 16, T[42]);
  8220. b = HH(b, c, d, a, M_offset_6, 23, T[43]);
  8221. a = HH(a, b, c, d, M_offset_9, 4, T[44]);
  8222. d = HH(d, a, b, c, M_offset_12, 11, T[45]);
  8223. c = HH(c, d, a, b, M_offset_15, 16, T[46]);
  8224. b = HH(b, c, d, a, M_offset_2, 23, T[47]);
  8225. a = II(a, b, c, d, M_offset_0, 6, T[48]);
  8226. d = II(d, a, b, c, M_offset_7, 10, T[49]);
  8227. c = II(c, d, a, b, M_offset_14, 15, T[50]);
  8228. b = II(b, c, d, a, M_offset_5, 21, T[51]);
  8229. a = II(a, b, c, d, M_offset_12, 6, T[52]);
  8230. d = II(d, a, b, c, M_offset_3, 10, T[53]);
  8231. c = II(c, d, a, b, M_offset_10, 15, T[54]);
  8232. b = II(b, c, d, a, M_offset_1, 21, T[55]);
  8233. a = II(a, b, c, d, M_offset_8, 6, T[56]);
  8234. d = II(d, a, b, c, M_offset_15, 10, T[57]);
  8235. c = II(c, d, a, b, M_offset_6, 15, T[58]);
  8236. b = II(b, c, d, a, M_offset_13, 21, T[59]);
  8237. a = II(a, b, c, d, M_offset_4, 6, T[60]);
  8238. d = II(d, a, b, c, M_offset_11, 10, T[61]);
  8239. c = II(c, d, a, b, M_offset_2, 15, T[62]);
  8240. b = II(b, c, d, a, M_offset_9, 21, T[63]);
  8241. // Intermediate hash value
  8242. H[0] = (H[0] + a) | 0;
  8243. H[1] = (H[1] + b) | 0;
  8244. H[2] = (H[2] + c) | 0;
  8245. H[3] = (H[3] + d) | 0;
  8246. },
  8247. _doFinalize: function () {
  8248. // Shortcuts
  8249. var data = this._data;
  8250. var dataWords = data.words;
  8251. var nBitsTotal = this._nDataBytes * 8;
  8252. var nBitsLeft = data.sigBytes * 8;
  8253. // Add padding
  8254. dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32);
  8255. var nBitsTotalH = Math.floor(nBitsTotal / 0x100000000);
  8256. var nBitsTotalL = nBitsTotal;
  8257. dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = (
  8258. (((nBitsTotalH << 8) | (nBitsTotalH >>> 24)) & 0x00ff00ff) |
  8259. (((nBitsTotalH << 24) | (nBitsTotalH >>> 8)) & 0xff00ff00)
  8260. );
  8261. dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = (
  8262. (((nBitsTotalL << 8) | (nBitsTotalL >>> 24)) & 0x00ff00ff) |
  8263. (((nBitsTotalL << 24) | (nBitsTotalL >>> 8)) & 0xff00ff00)
  8264. );
  8265. data.sigBytes = (dataWords.length + 1) * 4;
  8266. // Hash final blocks
  8267. this._process();
  8268. // Shortcuts
  8269. var hash = this._hash;
  8270. var H = hash.words;
  8271. // Swap endian
  8272. for (var i = 0; i < 4; i++) {
  8273. // Shortcut
  8274. var H_i = H[i];
  8275. H[i] = (((H_i << 8) | (H_i >>> 24)) & 0x00ff00ff) |
  8276. (((H_i << 24) | (H_i >>> 8)) & 0xff00ff00);
  8277. }
  8278. // Return final computed hash
  8279. return hash;
  8280. },
  8281. clone: function () {
  8282. var clone = Hasher.clone.call(this);
  8283. clone._hash = this._hash.clone();
  8284. return clone;
  8285. }
  8286. });
  8287. function FF(a, b, c, d, x, s, t) {
  8288. var n = a + ((b & c) | (~b & d)) + x + t;
  8289. return ((n << s) | (n >>> (32 - s))) + b;
  8290. }
  8291. function GG(a, b, c, d, x, s, t) {
  8292. var n = a + ((b & d) | (c & ~d)) + x + t;
  8293. return ((n << s) | (n >>> (32 - s))) + b;
  8294. }
  8295. function HH(a, b, c, d, x, s, t) {
  8296. var n = a + (b ^ c ^ d) + x + t;
  8297. return ((n << s) | (n >>> (32 - s))) + b;
  8298. }
  8299. function II(a, b, c, d, x, s, t) {
  8300. var n = a + (c ^ (b | ~d)) + x + t;
  8301. return ((n << s) | (n >>> (32 - s))) + b;
  8302. }
  8303. /**
  8304. * Shortcut function to the hasher's object interface.
  8305. *
  8306. * @param {WordArray|string} message The message to hash.
  8307. *
  8308. * @return {WordArray} The hash.
  8309. *
  8310. * @static
  8311. *
  8312. * @example
  8313. *
  8314. * var hash = CryptoJS.MD5('message');
  8315. * var hash = CryptoJS.MD5(wordArray);
  8316. */
  8317. C.MD5 = Hasher._createHelper(MD5);
  8318. /**
  8319. * Shortcut function to the HMAC's object interface.
  8320. *
  8321. * @param {WordArray|string} message The message to hash.
  8322. * @param {WordArray|string} key The secret key.
  8323. *
  8324. * @return {WordArray} The HMAC.
  8325. *
  8326. * @static
  8327. *
  8328. * @example
  8329. *
  8330. * var hmac = CryptoJS.HmacMD5(message, key);
  8331. */
  8332. C.HmacMD5 = Hasher._createHmacHelper(MD5);
  8333. }(Math));
  8334. return CryptoJS.MD5;
  8335. }));
  8336. },{"./core":53}],62:[function(require,module,exports){
  8337. ;(function (root, factory, undef) {
  8338. if (typeof exports === "object") {
  8339. // CommonJS
  8340. module.exports = exports = factory(require("./core"), require("./cipher-core"));
  8341. }
  8342. else if (typeof define === "function" && define.amd) {
  8343. // AMD
  8344. define(["./core", "./cipher-core"], factory);
  8345. }
  8346. else {
  8347. // Global (browser)
  8348. factory(root.CryptoJS);
  8349. }
  8350. }(this, function (CryptoJS) {
  8351. /**
  8352. * Cipher Feedback block mode.
  8353. */
  8354. CryptoJS.mode.CFB = (function () {
  8355. var CFB = CryptoJS.lib.BlockCipherMode.extend();
  8356. CFB.Encryptor = CFB.extend({
  8357. processBlock: function (words, offset) {
  8358. // Shortcuts
  8359. var cipher = this._cipher;
  8360. var blockSize = cipher.blockSize;
  8361. generateKeystreamAndEncrypt.call(this, words, offset, blockSize, cipher);
  8362. // Remember this block to use with next block
  8363. this._prevBlock = words.slice(offset, offset + blockSize);
  8364. }
  8365. });
  8366. CFB.Decryptor = CFB.extend({
  8367. processBlock: function (words, offset) {
  8368. // Shortcuts
  8369. var cipher = this._cipher;
  8370. var blockSize = cipher.blockSize;
  8371. // Remember this block to use with next block
  8372. var thisBlock = words.slice(offset, offset + blockSize);
  8373. generateKeystreamAndEncrypt.call(this, words, offset, blockSize, cipher);
  8374. // This block becomes the previous block
  8375. this._prevBlock = thisBlock;
  8376. }
  8377. });
  8378. function generateKeystreamAndEncrypt(words, offset, blockSize, cipher) {
  8379. // Shortcut
  8380. var iv = this._iv;
  8381. // Generate keystream
  8382. if (iv) {
  8383. var keystream = iv.slice(0);
  8384. // Remove IV for subsequent blocks
  8385. this._iv = undefined;
  8386. } else {
  8387. var keystream = this._prevBlock;
  8388. }
  8389. cipher.encryptBlock(keystream, 0);
  8390. // Encrypt
  8391. for (var i = 0; i < blockSize; i++) {
  8392. words[offset + i] ^= keystream[i];
  8393. }
  8394. }
  8395. return CFB;
  8396. }());
  8397. return CryptoJS.mode.CFB;
  8398. }));
  8399. },{"./cipher-core":52,"./core":53}],63:[function(require,module,exports){
  8400. ;(function (root, factory, undef) {
  8401. if (typeof exports === "object") {
  8402. // CommonJS
  8403. module.exports = exports = factory(require("./core"), require("./cipher-core"));
  8404. }
  8405. else if (typeof define === "function" && define.amd) {
  8406. // AMD
  8407. define(["./core", "./cipher-core"], factory);
  8408. }
  8409. else {
  8410. // Global (browser)
  8411. factory(root.CryptoJS);
  8412. }
  8413. }(this, function (CryptoJS) {
  8414. /** @preserve
  8415. * Counter block mode compatible with Dr Brian Gladman fileenc.c
  8416. * derived from CryptoJS.mode.CTR
  8417. * Jan Hruby jhruby.web@gmail.com
  8418. */
  8419. CryptoJS.mode.CTRGladman = (function () {
  8420. var CTRGladman = CryptoJS.lib.BlockCipherMode.extend();
  8421. function incWord(word)
  8422. {
  8423. if (((word >> 24) & 0xff) === 0xff) { //overflow
  8424. var b1 = (word >> 16)&0xff;
  8425. var b2 = (word >> 8)&0xff;
  8426. var b3 = word & 0xff;
  8427. if (b1 === 0xff) // overflow b1
  8428. {
  8429. b1 = 0;
  8430. if (b2 === 0xff)
  8431. {
  8432. b2 = 0;
  8433. if (b3 === 0xff)
  8434. {
  8435. b3 = 0;
  8436. }
  8437. else
  8438. {
  8439. ++b3;
  8440. }
  8441. }
  8442. else
  8443. {
  8444. ++b2;
  8445. }
  8446. }
  8447. else
  8448. {
  8449. ++b1;
  8450. }
  8451. word = 0;
  8452. word += (b1 << 16);
  8453. word += (b2 << 8);
  8454. word += b3;
  8455. }
  8456. else
  8457. {
  8458. word += (0x01 << 24);
  8459. }
  8460. return word;
  8461. }
  8462. function incCounter(counter)
  8463. {
  8464. if ((counter[0] = incWord(counter[0])) === 0)
  8465. {
  8466. // encr_data in fileenc.c from Dr Brian Gladman's counts only with DWORD j < 8
  8467. counter[1] = incWord(counter[1]);
  8468. }
  8469. return counter;
  8470. }
  8471. var Encryptor = CTRGladman.Encryptor = CTRGladman.extend({
  8472. processBlock: function (words, offset) {
  8473. // Shortcuts
  8474. var cipher = this._cipher
  8475. var blockSize = cipher.blockSize;
  8476. var iv = this._iv;
  8477. var counter = this._counter;
  8478. // Generate keystream
  8479. if (iv) {
  8480. counter = this._counter = iv.slice(0);
  8481. // Remove IV for subsequent blocks
  8482. this._iv = undefined;
  8483. }
  8484. incCounter(counter);
  8485. var keystream = counter.slice(0);
  8486. cipher.encryptBlock(keystream, 0);
  8487. // Encrypt
  8488. for (var i = 0; i < blockSize; i++) {
  8489. words[offset + i] ^= keystream[i];
  8490. }
  8491. }
  8492. });
  8493. CTRGladman.Decryptor = Encryptor;
  8494. return CTRGladman;
  8495. }());
  8496. return CryptoJS.mode.CTRGladman;
  8497. }));
  8498. },{"./cipher-core":52,"./core":53}],64:[function(require,module,exports){
  8499. ;(function (root, factory, undef) {
  8500. if (typeof exports === "object") {
  8501. // CommonJS
  8502. module.exports = exports = factory(require("./core"), require("./cipher-core"));
  8503. }
  8504. else if (typeof define === "function" && define.amd) {
  8505. // AMD
  8506. define(["./core", "./cipher-core"], factory);
  8507. }
  8508. else {
  8509. // Global (browser)
  8510. factory(root.CryptoJS);
  8511. }
  8512. }(this, function (CryptoJS) {
  8513. /**
  8514. * Counter block mode.
  8515. */
  8516. CryptoJS.mode.CTR = (function () {
  8517. var CTR = CryptoJS.lib.BlockCipherMode.extend();
  8518. var Encryptor = CTR.Encryptor = CTR.extend({
  8519. processBlock: function (words, offset) {
  8520. // Shortcuts
  8521. var cipher = this._cipher
  8522. var blockSize = cipher.blockSize;
  8523. var iv = this._iv;
  8524. var counter = this._counter;
  8525. // Generate keystream
  8526. if (iv) {
  8527. counter = this._counter = iv.slice(0);
  8528. // Remove IV for subsequent blocks
  8529. this._iv = undefined;
  8530. }
  8531. var keystream = counter.slice(0);
  8532. cipher.encryptBlock(keystream, 0);
  8533. // Increment counter
  8534. counter[blockSize - 1] = (counter[blockSize - 1] + 1) | 0
  8535. // Encrypt
  8536. for (var i = 0; i < blockSize; i++) {
  8537. words[offset + i] ^= keystream[i];
  8538. }
  8539. }
  8540. });
  8541. CTR.Decryptor = Encryptor;
  8542. return CTR;
  8543. }());
  8544. return CryptoJS.mode.CTR;
  8545. }));
  8546. },{"./cipher-core":52,"./core":53}],65:[function(require,module,exports){
  8547. ;(function (root, factory, undef) {
  8548. if (typeof exports === "object") {
  8549. // CommonJS
  8550. module.exports = exports = factory(require("./core"), require("./cipher-core"));
  8551. }
  8552. else if (typeof define === "function" && define.amd) {
  8553. // AMD
  8554. define(["./core", "./cipher-core"], factory);
  8555. }
  8556. else {
  8557. // Global (browser)
  8558. factory(root.CryptoJS);
  8559. }
  8560. }(this, function (CryptoJS) {
  8561. /**
  8562. * Electronic Codebook block mode.
  8563. */
  8564. CryptoJS.mode.ECB = (function () {
  8565. var ECB = CryptoJS.lib.BlockCipherMode.extend();
  8566. ECB.Encryptor = ECB.extend({
  8567. processBlock: function (words, offset) {
  8568. this._cipher.encryptBlock(words, offset);
  8569. }
  8570. });
  8571. ECB.Decryptor = ECB.extend({
  8572. processBlock: function (words, offset) {
  8573. this._cipher.decryptBlock(words, offset);
  8574. }
  8575. });
  8576. return ECB;
  8577. }());
  8578. return CryptoJS.mode.ECB;
  8579. }));
  8580. },{"./cipher-core":52,"./core":53}],66:[function(require,module,exports){
  8581. ;(function (root, factory, undef) {
  8582. if (typeof exports === "object") {
  8583. // CommonJS
  8584. module.exports = exports = factory(require("./core"), require("./cipher-core"));
  8585. }
  8586. else if (typeof define === "function" && define.amd) {
  8587. // AMD
  8588. define(["./core", "./cipher-core"], factory);
  8589. }
  8590. else {
  8591. // Global (browser)
  8592. factory(root.CryptoJS);
  8593. }
  8594. }(this, function (CryptoJS) {
  8595. /**
  8596. * Output Feedback block mode.
  8597. */
  8598. CryptoJS.mode.OFB = (function () {
  8599. var OFB = CryptoJS.lib.BlockCipherMode.extend();
  8600. var Encryptor = OFB.Encryptor = OFB.extend({
  8601. processBlock: function (words, offset) {
  8602. // Shortcuts
  8603. var cipher = this._cipher
  8604. var blockSize = cipher.blockSize;
  8605. var iv = this._iv;
  8606. var keystream = this._keystream;
  8607. // Generate keystream
  8608. if (iv) {
  8609. keystream = this._keystream = iv.slice(0);
  8610. // Remove IV for subsequent blocks
  8611. this._iv = undefined;
  8612. }
  8613. cipher.encryptBlock(keystream, 0);
  8614. // Encrypt
  8615. for (var i = 0; i < blockSize; i++) {
  8616. words[offset + i] ^= keystream[i];
  8617. }
  8618. }
  8619. });
  8620. OFB.Decryptor = Encryptor;
  8621. return OFB;
  8622. }());
  8623. return CryptoJS.mode.OFB;
  8624. }));
  8625. },{"./cipher-core":52,"./core":53}],67:[function(require,module,exports){
  8626. ;(function (root, factory, undef) {
  8627. if (typeof exports === "object") {
  8628. // CommonJS
  8629. module.exports = exports = factory(require("./core"), require("./cipher-core"));
  8630. }
  8631. else if (typeof define === "function" && define.amd) {
  8632. // AMD
  8633. define(["./core", "./cipher-core"], factory);
  8634. }
  8635. else {
  8636. // Global (browser)
  8637. factory(root.CryptoJS);
  8638. }
  8639. }(this, function (CryptoJS) {
  8640. /**
  8641. * ANSI X.923 padding strategy.
  8642. */
  8643. CryptoJS.pad.AnsiX923 = {
  8644. pad: function (data, blockSize) {
  8645. // Shortcuts
  8646. var dataSigBytes = data.sigBytes;
  8647. var blockSizeBytes = blockSize * 4;
  8648. // Count padding bytes
  8649. var nPaddingBytes = blockSizeBytes - dataSigBytes % blockSizeBytes;
  8650. // Compute last byte position
  8651. var lastBytePos = dataSigBytes + nPaddingBytes - 1;
  8652. // Pad
  8653. data.clamp();
  8654. data.words[lastBytePos >>> 2] |= nPaddingBytes << (24 - (lastBytePos % 4) * 8);
  8655. data.sigBytes += nPaddingBytes;
  8656. },
  8657. unpad: function (data) {
  8658. // Get number of padding bytes from last byte
  8659. var nPaddingBytes = data.words[(data.sigBytes - 1) >>> 2] & 0xff;
  8660. // Remove padding
  8661. data.sigBytes -= nPaddingBytes;
  8662. }
  8663. };
  8664. return CryptoJS.pad.Ansix923;
  8665. }));
  8666. },{"./cipher-core":52,"./core":53}],68:[function(require,module,exports){
  8667. ;(function (root, factory, undef) {
  8668. if (typeof exports === "object") {
  8669. // CommonJS
  8670. module.exports = exports = factory(require("./core"), require("./cipher-core"));
  8671. }
  8672. else if (typeof define === "function" && define.amd) {
  8673. // AMD
  8674. define(["./core", "./cipher-core"], factory);
  8675. }
  8676. else {
  8677. // Global (browser)
  8678. factory(root.CryptoJS);
  8679. }
  8680. }(this, function (CryptoJS) {
  8681. /**
  8682. * ISO 10126 padding strategy.
  8683. */
  8684. CryptoJS.pad.Iso10126 = {
  8685. pad: function (data, blockSize) {
  8686. // Shortcut
  8687. var blockSizeBytes = blockSize * 4;
  8688. // Count padding bytes
  8689. var nPaddingBytes = blockSizeBytes - data.sigBytes % blockSizeBytes;
  8690. // Pad
  8691. data.concat(CryptoJS.lib.WordArray.random(nPaddingBytes - 1)).
  8692. concat(CryptoJS.lib.WordArray.create([nPaddingBytes << 24], 1));
  8693. },
  8694. unpad: function (data) {
  8695. // Get number of padding bytes from last byte
  8696. var nPaddingBytes = data.words[(data.sigBytes - 1) >>> 2] & 0xff;
  8697. // Remove padding
  8698. data.sigBytes -= nPaddingBytes;
  8699. }
  8700. };
  8701. return CryptoJS.pad.Iso10126;
  8702. }));
  8703. },{"./cipher-core":52,"./core":53}],69:[function(require,module,exports){
  8704. ;(function (root, factory, undef) {
  8705. if (typeof exports === "object") {
  8706. // CommonJS
  8707. module.exports = exports = factory(require("./core"), require("./cipher-core"));
  8708. }
  8709. else if (typeof define === "function" && define.amd) {
  8710. // AMD
  8711. define(["./core", "./cipher-core"], factory);
  8712. }
  8713. else {
  8714. // Global (browser)
  8715. factory(root.CryptoJS);
  8716. }
  8717. }(this, function (CryptoJS) {
  8718. /**
  8719. * ISO/IEC 9797-1 Padding Method 2.
  8720. */
  8721. CryptoJS.pad.Iso97971 = {
  8722. pad: function (data, blockSize) {
  8723. // Add 0x80 byte
  8724. data.concat(CryptoJS.lib.WordArray.create([0x80000000], 1));
  8725. // Zero pad the rest
  8726. CryptoJS.pad.ZeroPadding.pad(data, blockSize);
  8727. },
  8728. unpad: function (data) {
  8729. // Remove zero padding
  8730. CryptoJS.pad.ZeroPadding.unpad(data);
  8731. // Remove one more byte -- the 0x80 byte
  8732. data.sigBytes--;
  8733. }
  8734. };
  8735. return CryptoJS.pad.Iso97971;
  8736. }));
  8737. },{"./cipher-core":52,"./core":53}],70:[function(require,module,exports){
  8738. ;(function (root, factory, undef) {
  8739. if (typeof exports === "object") {
  8740. // CommonJS
  8741. module.exports = exports = factory(require("./core"), require("./cipher-core"));
  8742. }
  8743. else if (typeof define === "function" && define.amd) {
  8744. // AMD
  8745. define(["./core", "./cipher-core"], factory);
  8746. }
  8747. else {
  8748. // Global (browser)
  8749. factory(root.CryptoJS);
  8750. }
  8751. }(this, function (CryptoJS) {
  8752. /**
  8753. * A noop padding strategy.
  8754. */
  8755. CryptoJS.pad.NoPadding = {
  8756. pad: function () {
  8757. },
  8758. unpad: function () {
  8759. }
  8760. };
  8761. return CryptoJS.pad.NoPadding;
  8762. }));
  8763. },{"./cipher-core":52,"./core":53}],71:[function(require,module,exports){
  8764. ;(function (root, factory, undef) {
  8765. if (typeof exports === "object") {
  8766. // CommonJS
  8767. module.exports = exports = factory(require("./core"), require("./cipher-core"));
  8768. }
  8769. else if (typeof define === "function" && define.amd) {
  8770. // AMD
  8771. define(["./core", "./cipher-core"], factory);
  8772. }
  8773. else {
  8774. // Global (browser)
  8775. factory(root.CryptoJS);
  8776. }
  8777. }(this, function (CryptoJS) {
  8778. /**
  8779. * Zero padding strategy.
  8780. */
  8781. CryptoJS.pad.ZeroPadding = {
  8782. pad: function (data, blockSize) {
  8783. // Shortcut
  8784. var blockSizeBytes = blockSize * 4;
  8785. // Pad
  8786. data.clamp();
  8787. data.sigBytes += blockSizeBytes - ((data.sigBytes % blockSizeBytes) || blockSizeBytes);
  8788. },
  8789. unpad: function (data) {
  8790. // Shortcut
  8791. var dataWords = data.words;
  8792. // Unpad
  8793. var i = data.sigBytes - 1;
  8794. while (!((dataWords[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff)) {
  8795. i--;
  8796. }
  8797. data.sigBytes = i + 1;
  8798. }
  8799. };
  8800. return CryptoJS.pad.ZeroPadding;
  8801. }));
  8802. },{"./cipher-core":52,"./core":53}],72:[function(require,module,exports){
  8803. ;(function (root, factory, undef) {
  8804. if (typeof exports === "object") {
  8805. // CommonJS
  8806. module.exports = exports = factory(require("./core"), require("./sha1"), require("./hmac"));
  8807. }
  8808. else if (typeof define === "function" && define.amd) {
  8809. // AMD
  8810. define(["./core", "./sha1", "./hmac"], factory);
  8811. }
  8812. else {
  8813. // Global (browser)
  8814. factory(root.CryptoJS);
  8815. }
  8816. }(this, function (CryptoJS) {
  8817. (function () {
  8818. // Shortcuts
  8819. var C = CryptoJS;
  8820. var C_lib = C.lib;
  8821. var Base = C_lib.Base;
  8822. var WordArray = C_lib.WordArray;
  8823. var C_algo = C.algo;
  8824. var SHA1 = C_algo.SHA1;
  8825. var HMAC = C_algo.HMAC;
  8826. /**
  8827. * Password-Based Key Derivation Function 2 algorithm.
  8828. */
  8829. var PBKDF2 = C_algo.PBKDF2 = Base.extend({
  8830. /**
  8831. * Configuration options.
  8832. *
  8833. * @property {number} keySize The key size in words to generate. Default: 4 (128 bits)
  8834. * @property {Hasher} hasher The hasher to use. Default: SHA1
  8835. * @property {number} iterations The number of iterations to perform. Default: 1
  8836. */
  8837. cfg: Base.extend({
  8838. keySize: 128/32,
  8839. hasher: SHA1,
  8840. iterations: 1
  8841. }),
  8842. /**
  8843. * Initializes a newly created key derivation function.
  8844. *
  8845. * @param {Object} cfg (Optional) The configuration options to use for the derivation.
  8846. *
  8847. * @example
  8848. *
  8849. * var kdf = CryptoJS.algo.PBKDF2.create();
  8850. * var kdf = CryptoJS.algo.PBKDF2.create({ keySize: 8 });
  8851. * var kdf = CryptoJS.algo.PBKDF2.create({ keySize: 8, iterations: 1000 });
  8852. */
  8853. init: function (cfg) {
  8854. this.cfg = this.cfg.extend(cfg);
  8855. },
  8856. /**
  8857. * Computes the Password-Based Key Derivation Function 2.
  8858. *
  8859. * @param {WordArray|string} password The password.
  8860. * @param {WordArray|string} salt A salt.
  8861. *
  8862. * @return {WordArray} The derived key.
  8863. *
  8864. * @example
  8865. *
  8866. * var key = kdf.compute(password, salt);
  8867. */
  8868. compute: function (password, salt) {
  8869. // Shortcut
  8870. var cfg = this.cfg;
  8871. // Init HMAC
  8872. var hmac = HMAC.create(cfg.hasher, password);
  8873. // Initial values
  8874. var derivedKey = WordArray.create();
  8875. var blockIndex = WordArray.create([0x00000001]);
  8876. // Shortcuts
  8877. var derivedKeyWords = derivedKey.words;
  8878. var blockIndexWords = blockIndex.words;
  8879. var keySize = cfg.keySize;
  8880. var iterations = cfg.iterations;
  8881. // Generate key
  8882. while (derivedKeyWords.length < keySize) {
  8883. var block = hmac.update(salt).finalize(blockIndex);
  8884. hmac.reset();
  8885. // Shortcuts
  8886. var blockWords = block.words;
  8887. var blockWordsLength = blockWords.length;
  8888. // Iterations
  8889. var intermediate = block;
  8890. for (var i = 1; i < iterations; i++) {
  8891. intermediate = hmac.finalize(intermediate);
  8892. hmac.reset();
  8893. // Shortcut
  8894. var intermediateWords = intermediate.words;
  8895. // XOR intermediate with block
  8896. for (var j = 0; j < blockWordsLength; j++) {
  8897. blockWords[j] ^= intermediateWords[j];
  8898. }
  8899. }
  8900. derivedKey.concat(block);
  8901. blockIndexWords[0]++;
  8902. }
  8903. derivedKey.sigBytes = keySize * 4;
  8904. return derivedKey;
  8905. }
  8906. });
  8907. /**
  8908. * Computes the Password-Based Key Derivation Function 2.
  8909. *
  8910. * @param {WordArray|string} password The password.
  8911. * @param {WordArray|string} salt A salt.
  8912. * @param {Object} cfg (Optional) The configuration options to use for this computation.
  8913. *
  8914. * @return {WordArray} The derived key.
  8915. *
  8916. * @static
  8917. *
  8918. * @example
  8919. *
  8920. * var key = CryptoJS.PBKDF2(password, salt);
  8921. * var key = CryptoJS.PBKDF2(password, salt, { keySize: 8 });
  8922. * var key = CryptoJS.PBKDF2(password, salt, { keySize: 8, iterations: 1000 });
  8923. */
  8924. C.PBKDF2 = function (password, salt, cfg) {
  8925. return PBKDF2.create(cfg).compute(password, salt);
  8926. };
  8927. }());
  8928. return CryptoJS.PBKDF2;
  8929. }));
  8930. },{"./core":53,"./hmac":58,"./sha1":77}],73:[function(require,module,exports){
  8931. ;(function (root, factory, undef) {
  8932. if (typeof exports === "object") {
  8933. // CommonJS
  8934. module.exports = exports = factory(require("./core"), require("./enc-base64"), require("./md5"), require("./evpkdf"), require("./cipher-core"));
  8935. }
  8936. else if (typeof define === "function" && define.amd) {
  8937. // AMD
  8938. define(["./core", "./enc-base64", "./md5", "./evpkdf", "./cipher-core"], factory);
  8939. }
  8940. else {
  8941. // Global (browser)
  8942. factory(root.CryptoJS);
  8943. }
  8944. }(this, function (CryptoJS) {
  8945. (function () {
  8946. // Shortcuts
  8947. var C = CryptoJS;
  8948. var C_lib = C.lib;
  8949. var StreamCipher = C_lib.StreamCipher;
  8950. var C_algo = C.algo;
  8951. // Reusable objects
  8952. var S = [];
  8953. var C_ = [];
  8954. var G = [];
  8955. /**
  8956. * Rabbit stream cipher algorithm.
  8957. *
  8958. * This is a legacy version that neglected to convert the key to little-endian.
  8959. * This error doesn't affect the cipher's security,
  8960. * but it does affect its compatibility with other implementations.
  8961. */
  8962. var RabbitLegacy = C_algo.RabbitLegacy = StreamCipher.extend({
  8963. _doReset: function () {
  8964. // Shortcuts
  8965. var K = this._key.words;
  8966. var iv = this.cfg.iv;
  8967. // Generate initial state values
  8968. var X = this._X = [
  8969. K[0], (K[3] << 16) | (K[2] >>> 16),
  8970. K[1], (K[0] << 16) | (K[3] >>> 16),
  8971. K[2], (K[1] << 16) | (K[0] >>> 16),
  8972. K[3], (K[2] << 16) | (K[1] >>> 16)
  8973. ];
  8974. // Generate initial counter values
  8975. var C = this._C = [
  8976. (K[2] << 16) | (K[2] >>> 16), (K[0] & 0xffff0000) | (K[1] & 0x0000ffff),
  8977. (K[3] << 16) | (K[3] >>> 16), (K[1] & 0xffff0000) | (K[2] & 0x0000ffff),
  8978. (K[0] << 16) | (K[0] >>> 16), (K[2] & 0xffff0000) | (K[3] & 0x0000ffff),
  8979. (K[1] << 16) | (K[1] >>> 16), (K[3] & 0xffff0000) | (K[0] & 0x0000ffff)
  8980. ];
  8981. // Carry bit
  8982. this._b = 0;
  8983. // Iterate the system four times
  8984. for (var i = 0; i < 4; i++) {
  8985. nextState.call(this);
  8986. }
  8987. // Modify the counters
  8988. for (var i = 0; i < 8; i++) {
  8989. C[i] ^= X[(i + 4) & 7];
  8990. }
  8991. // IV setup
  8992. if (iv) {
  8993. // Shortcuts
  8994. var IV = iv.words;
  8995. var IV_0 = IV[0];
  8996. var IV_1 = IV[1];
  8997. // Generate four subvectors
  8998. var i0 = (((IV_0 << 8) | (IV_0 >>> 24)) & 0x00ff00ff) | (((IV_0 << 24) | (IV_0 >>> 8)) & 0xff00ff00);
  8999. var i2 = (((IV_1 << 8) | (IV_1 >>> 24)) & 0x00ff00ff) | (((IV_1 << 24) | (IV_1 >>> 8)) & 0xff00ff00);
  9000. var i1 = (i0 >>> 16) | (i2 & 0xffff0000);
  9001. var i3 = (i2 << 16) | (i0 & 0x0000ffff);
  9002. // Modify counter values
  9003. C[0] ^= i0;
  9004. C[1] ^= i1;
  9005. C[2] ^= i2;
  9006. C[3] ^= i3;
  9007. C[4] ^= i0;
  9008. C[5] ^= i1;
  9009. C[6] ^= i2;
  9010. C[7] ^= i3;
  9011. // Iterate the system four times
  9012. for (var i = 0; i < 4; i++) {
  9013. nextState.call(this);
  9014. }
  9015. }
  9016. },
  9017. _doProcessBlock: function (M, offset) {
  9018. // Shortcut
  9019. var X = this._X;
  9020. // Iterate the system
  9021. nextState.call(this);
  9022. // Generate four keystream words
  9023. S[0] = X[0] ^ (X[5] >>> 16) ^ (X[3] << 16);
  9024. S[1] = X[2] ^ (X[7] >>> 16) ^ (X[5] << 16);
  9025. S[2] = X[4] ^ (X[1] >>> 16) ^ (X[7] << 16);
  9026. S[3] = X[6] ^ (X[3] >>> 16) ^ (X[1] << 16);
  9027. for (var i = 0; i < 4; i++) {
  9028. // Swap endian
  9029. S[i] = (((S[i] << 8) | (S[i] >>> 24)) & 0x00ff00ff) |
  9030. (((S[i] << 24) | (S[i] >>> 8)) & 0xff00ff00);
  9031. // Encrypt
  9032. M[offset + i] ^= S[i];
  9033. }
  9034. },
  9035. blockSize: 128/32,
  9036. ivSize: 64/32
  9037. });
  9038. function nextState() {
  9039. // Shortcuts
  9040. var X = this._X;
  9041. var C = this._C;
  9042. // Save old counter values
  9043. for (var i = 0; i < 8; i++) {
  9044. C_[i] = C[i];
  9045. }
  9046. // Calculate new counter values
  9047. C[0] = (C[0] + 0x4d34d34d + this._b) | 0;
  9048. C[1] = (C[1] + 0xd34d34d3 + ((C[0] >>> 0) < (C_[0] >>> 0) ? 1 : 0)) | 0;
  9049. C[2] = (C[2] + 0x34d34d34 + ((C[1] >>> 0) < (C_[1] >>> 0) ? 1 : 0)) | 0;
  9050. C[3] = (C[3] + 0x4d34d34d + ((C[2] >>> 0) < (C_[2] >>> 0) ? 1 : 0)) | 0;
  9051. C[4] = (C[4] + 0xd34d34d3 + ((C[3] >>> 0) < (C_[3] >>> 0) ? 1 : 0)) | 0;
  9052. C[5] = (C[5] + 0x34d34d34 + ((C[4] >>> 0) < (C_[4] >>> 0) ? 1 : 0)) | 0;
  9053. C[6] = (C[6] + 0x4d34d34d + ((C[5] >>> 0) < (C_[5] >>> 0) ? 1 : 0)) | 0;
  9054. C[7] = (C[7] + 0xd34d34d3 + ((C[6] >>> 0) < (C_[6] >>> 0) ? 1 : 0)) | 0;
  9055. this._b = (C[7] >>> 0) < (C_[7] >>> 0) ? 1 : 0;
  9056. // Calculate the g-values
  9057. for (var i = 0; i < 8; i++) {
  9058. var gx = X[i] + C[i];
  9059. // Construct high and low argument for squaring
  9060. var ga = gx & 0xffff;
  9061. var gb = gx >>> 16;
  9062. // Calculate high and low result of squaring
  9063. var gh = ((((ga * ga) >>> 17) + ga * gb) >>> 15) + gb * gb;
  9064. var gl = (((gx & 0xffff0000) * gx) | 0) + (((gx & 0x0000ffff) * gx) | 0);
  9065. // High XOR low
  9066. G[i] = gh ^ gl;
  9067. }
  9068. // Calculate new state values
  9069. X[0] = (G[0] + ((G[7] << 16) | (G[7] >>> 16)) + ((G[6] << 16) | (G[6] >>> 16))) | 0;
  9070. X[1] = (G[1] + ((G[0] << 8) | (G[0] >>> 24)) + G[7]) | 0;
  9071. X[2] = (G[2] + ((G[1] << 16) | (G[1] >>> 16)) + ((G[0] << 16) | (G[0] >>> 16))) | 0;
  9072. X[3] = (G[3] + ((G[2] << 8) | (G[2] >>> 24)) + G[1]) | 0;
  9073. X[4] = (G[4] + ((G[3] << 16) | (G[3] >>> 16)) + ((G[2] << 16) | (G[2] >>> 16))) | 0;
  9074. X[5] = (G[5] + ((G[4] << 8) | (G[4] >>> 24)) + G[3]) | 0;
  9075. X[6] = (G[6] + ((G[5] << 16) | (G[5] >>> 16)) + ((G[4] << 16) | (G[4] >>> 16))) | 0;
  9076. X[7] = (G[7] + ((G[6] << 8) | (G[6] >>> 24)) + G[5]) | 0;
  9077. }
  9078. /**
  9079. * Shortcut functions to the cipher's object interface.
  9080. *
  9081. * @example
  9082. *
  9083. * var ciphertext = CryptoJS.RabbitLegacy.encrypt(message, key, cfg);
  9084. * var plaintext = CryptoJS.RabbitLegacy.decrypt(ciphertext, key, cfg);
  9085. */
  9086. C.RabbitLegacy = StreamCipher._createHelper(RabbitLegacy);
  9087. }());
  9088. return CryptoJS.RabbitLegacy;
  9089. }));
  9090. },{"./cipher-core":52,"./core":53,"./enc-base64":54,"./evpkdf":56,"./md5":61}],74:[function(require,module,exports){
  9091. ;(function (root, factory, undef) {
  9092. if (typeof exports === "object") {
  9093. // CommonJS
  9094. module.exports = exports = factory(require("./core"), require("./enc-base64"), require("./md5"), require("./evpkdf"), require("./cipher-core"));
  9095. }
  9096. else if (typeof define === "function" && define.amd) {
  9097. // AMD
  9098. define(["./core", "./enc-base64", "./md5", "./evpkdf", "./cipher-core"], factory);
  9099. }
  9100. else {
  9101. // Global (browser)
  9102. factory(root.CryptoJS);
  9103. }
  9104. }(this, function (CryptoJS) {
  9105. (function () {
  9106. // Shortcuts
  9107. var C = CryptoJS;
  9108. var C_lib = C.lib;
  9109. var StreamCipher = C_lib.StreamCipher;
  9110. var C_algo = C.algo;
  9111. // Reusable objects
  9112. var S = [];
  9113. var C_ = [];
  9114. var G = [];
  9115. /**
  9116. * Rabbit stream cipher algorithm
  9117. */
  9118. var Rabbit = C_algo.Rabbit = StreamCipher.extend({
  9119. _doReset: function () {
  9120. // Shortcuts
  9121. var K = this._key.words;
  9122. var iv = this.cfg.iv;
  9123. // Swap endian
  9124. for (var i = 0; i < 4; i++) {
  9125. K[i] = (((K[i] << 8) | (K[i] >>> 24)) & 0x00ff00ff) |
  9126. (((K[i] << 24) | (K[i] >>> 8)) & 0xff00ff00);
  9127. }
  9128. // Generate initial state values
  9129. var X = this._X = [
  9130. K[0], (K[3] << 16) | (K[2] >>> 16),
  9131. K[1], (K[0] << 16) | (K[3] >>> 16),
  9132. K[2], (K[1] << 16) | (K[0] >>> 16),
  9133. K[3], (K[2] << 16) | (K[1] >>> 16)
  9134. ];
  9135. // Generate initial counter values
  9136. var C = this._C = [
  9137. (K[2] << 16) | (K[2] >>> 16), (K[0] & 0xffff0000) | (K[1] & 0x0000ffff),
  9138. (K[3] << 16) | (K[3] >>> 16), (K[1] & 0xffff0000) | (K[2] & 0x0000ffff),
  9139. (K[0] << 16) | (K[0] >>> 16), (K[2] & 0xffff0000) | (K[3] & 0x0000ffff),
  9140. (K[1] << 16) | (K[1] >>> 16), (K[3] & 0xffff0000) | (K[0] & 0x0000ffff)
  9141. ];
  9142. // Carry bit
  9143. this._b = 0;
  9144. // Iterate the system four times
  9145. for (var i = 0; i < 4; i++) {
  9146. nextState.call(this);
  9147. }
  9148. // Modify the counters
  9149. for (var i = 0; i < 8; i++) {
  9150. C[i] ^= X[(i + 4) & 7];
  9151. }
  9152. // IV setup
  9153. if (iv) {
  9154. // Shortcuts
  9155. var IV = iv.words;
  9156. var IV_0 = IV[0];
  9157. var IV_1 = IV[1];
  9158. // Generate four subvectors
  9159. var i0 = (((IV_0 << 8) | (IV_0 >>> 24)) & 0x00ff00ff) | (((IV_0 << 24) | (IV_0 >>> 8)) & 0xff00ff00);
  9160. var i2 = (((IV_1 << 8) | (IV_1 >>> 24)) & 0x00ff00ff) | (((IV_1 << 24) | (IV_1 >>> 8)) & 0xff00ff00);
  9161. var i1 = (i0 >>> 16) | (i2 & 0xffff0000);
  9162. var i3 = (i2 << 16) | (i0 & 0x0000ffff);
  9163. // Modify counter values
  9164. C[0] ^= i0;
  9165. C[1] ^= i1;
  9166. C[2] ^= i2;
  9167. C[3] ^= i3;
  9168. C[4] ^= i0;
  9169. C[5] ^= i1;
  9170. C[6] ^= i2;
  9171. C[7] ^= i3;
  9172. // Iterate the system four times
  9173. for (var i = 0; i < 4; i++) {
  9174. nextState.call(this);
  9175. }
  9176. }
  9177. },
  9178. _doProcessBlock: function (M, offset) {
  9179. // Shortcut
  9180. var X = this._X;
  9181. // Iterate the system
  9182. nextState.call(this);
  9183. // Generate four keystream words
  9184. S[0] = X[0] ^ (X[5] >>> 16) ^ (X[3] << 16);
  9185. S[1] = X[2] ^ (X[7] >>> 16) ^ (X[5] << 16);
  9186. S[2] = X[4] ^ (X[1] >>> 16) ^ (X[7] << 16);
  9187. S[3] = X[6] ^ (X[3] >>> 16) ^ (X[1] << 16);
  9188. for (var i = 0; i < 4; i++) {
  9189. // Swap endian
  9190. S[i] = (((S[i] << 8) | (S[i] >>> 24)) & 0x00ff00ff) |
  9191. (((S[i] << 24) | (S[i] >>> 8)) & 0xff00ff00);
  9192. // Encrypt
  9193. M[offset + i] ^= S[i];
  9194. }
  9195. },
  9196. blockSize: 128/32,
  9197. ivSize: 64/32
  9198. });
  9199. function nextState() {
  9200. // Shortcuts
  9201. var X = this._X;
  9202. var C = this._C;
  9203. // Save old counter values
  9204. for (var i = 0; i < 8; i++) {
  9205. C_[i] = C[i];
  9206. }
  9207. // Calculate new counter values
  9208. C[0] = (C[0] + 0x4d34d34d + this._b) | 0;
  9209. C[1] = (C[1] + 0xd34d34d3 + ((C[0] >>> 0) < (C_[0] >>> 0) ? 1 : 0)) | 0;
  9210. C[2] = (C[2] + 0x34d34d34 + ((C[1] >>> 0) < (C_[1] >>> 0) ? 1 : 0)) | 0;
  9211. C[3] = (C[3] + 0x4d34d34d + ((C[2] >>> 0) < (C_[2] >>> 0) ? 1 : 0)) | 0;
  9212. C[4] = (C[4] + 0xd34d34d3 + ((C[3] >>> 0) < (C_[3] >>> 0) ? 1 : 0)) | 0;
  9213. C[5] = (C[5] + 0x34d34d34 + ((C[4] >>> 0) < (C_[4] >>> 0) ? 1 : 0)) | 0;
  9214. C[6] = (C[6] + 0x4d34d34d + ((C[5] >>> 0) < (C_[5] >>> 0) ? 1 : 0)) | 0;
  9215. C[7] = (C[7] + 0xd34d34d3 + ((C[6] >>> 0) < (C_[6] >>> 0) ? 1 : 0)) | 0;
  9216. this._b = (C[7] >>> 0) < (C_[7] >>> 0) ? 1 : 0;
  9217. // Calculate the g-values
  9218. for (var i = 0; i < 8; i++) {
  9219. var gx = X[i] + C[i];
  9220. // Construct high and low argument for squaring
  9221. var ga = gx & 0xffff;
  9222. var gb = gx >>> 16;
  9223. // Calculate high and low result of squaring
  9224. var gh = ((((ga * ga) >>> 17) + ga * gb) >>> 15) + gb * gb;
  9225. var gl = (((gx & 0xffff0000) * gx) | 0) + (((gx & 0x0000ffff) * gx) | 0);
  9226. // High XOR low
  9227. G[i] = gh ^ gl;
  9228. }
  9229. // Calculate new state values
  9230. X[0] = (G[0] + ((G[7] << 16) | (G[7] >>> 16)) + ((G[6] << 16) | (G[6] >>> 16))) | 0;
  9231. X[1] = (G[1] + ((G[0] << 8) | (G[0] >>> 24)) + G[7]) | 0;
  9232. X[2] = (G[2] + ((G[1] << 16) | (G[1] >>> 16)) + ((G[0] << 16) | (G[0] >>> 16))) | 0;
  9233. X[3] = (G[3] + ((G[2] << 8) | (G[2] >>> 24)) + G[1]) | 0;
  9234. X[4] = (G[4] + ((G[3] << 16) | (G[3] >>> 16)) + ((G[2] << 16) | (G[2] >>> 16))) | 0;
  9235. X[5] = (G[5] + ((G[4] << 8) | (G[4] >>> 24)) + G[3]) | 0;
  9236. X[6] = (G[6] + ((G[5] << 16) | (G[5] >>> 16)) + ((G[4] << 16) | (G[4] >>> 16))) | 0;
  9237. X[7] = (G[7] + ((G[6] << 8) | (G[6] >>> 24)) + G[5]) | 0;
  9238. }
  9239. /**
  9240. * Shortcut functions to the cipher's object interface.
  9241. *
  9242. * @example
  9243. *
  9244. * var ciphertext = CryptoJS.Rabbit.encrypt(message, key, cfg);
  9245. * var plaintext = CryptoJS.Rabbit.decrypt(ciphertext, key, cfg);
  9246. */
  9247. C.Rabbit = StreamCipher._createHelper(Rabbit);
  9248. }());
  9249. return CryptoJS.Rabbit;
  9250. }));
  9251. },{"./cipher-core":52,"./core":53,"./enc-base64":54,"./evpkdf":56,"./md5":61}],75:[function(require,module,exports){
  9252. ;(function (root, factory, undef) {
  9253. if (typeof exports === "object") {
  9254. // CommonJS
  9255. module.exports = exports = factory(require("./core"), require("./enc-base64"), require("./md5"), require("./evpkdf"), require("./cipher-core"));
  9256. }
  9257. else if (typeof define === "function" && define.amd) {
  9258. // AMD
  9259. define(["./core", "./enc-base64", "./md5", "./evpkdf", "./cipher-core"], factory);
  9260. }
  9261. else {
  9262. // Global (browser)
  9263. factory(root.CryptoJS);
  9264. }
  9265. }(this, function (CryptoJS) {
  9266. (function () {
  9267. // Shortcuts
  9268. var C = CryptoJS;
  9269. var C_lib = C.lib;
  9270. var StreamCipher = C_lib.StreamCipher;
  9271. var C_algo = C.algo;
  9272. /**
  9273. * RC4 stream cipher algorithm.
  9274. */
  9275. var RC4 = C_algo.RC4 = StreamCipher.extend({
  9276. _doReset: function () {
  9277. // Shortcuts
  9278. var key = this._key;
  9279. var keyWords = key.words;
  9280. var keySigBytes = key.sigBytes;
  9281. // Init sbox
  9282. var S = this._S = [];
  9283. for (var i = 0; i < 256; i++) {
  9284. S[i] = i;
  9285. }
  9286. // Key setup
  9287. for (var i = 0, j = 0; i < 256; i++) {
  9288. var keyByteIndex = i % keySigBytes;
  9289. var keyByte = (keyWords[keyByteIndex >>> 2] >>> (24 - (keyByteIndex % 4) * 8)) & 0xff;
  9290. j = (j + S[i] + keyByte) % 256;
  9291. // Swap
  9292. var t = S[i];
  9293. S[i] = S[j];
  9294. S[j] = t;
  9295. }
  9296. // Counters
  9297. this._i = this._j = 0;
  9298. },
  9299. _doProcessBlock: function (M, offset) {
  9300. M[offset] ^= generateKeystreamWord.call(this);
  9301. },
  9302. keySize: 256/32,
  9303. ivSize: 0
  9304. });
  9305. function generateKeystreamWord() {
  9306. // Shortcuts
  9307. var S = this._S;
  9308. var i = this._i;
  9309. var j = this._j;
  9310. // Generate keystream word
  9311. var keystreamWord = 0;
  9312. for (var n = 0; n < 4; n++) {
  9313. i = (i + 1) % 256;
  9314. j = (j + S[i]) % 256;
  9315. // Swap
  9316. var t = S[i];
  9317. S[i] = S[j];
  9318. S[j] = t;
  9319. keystreamWord |= S[(S[i] + S[j]) % 256] << (24 - n * 8);
  9320. }
  9321. // Update counters
  9322. this._i = i;
  9323. this._j = j;
  9324. return keystreamWord;
  9325. }
  9326. /**
  9327. * Shortcut functions to the cipher's object interface.
  9328. *
  9329. * @example
  9330. *
  9331. * var ciphertext = CryptoJS.RC4.encrypt(message, key, cfg);
  9332. * var plaintext = CryptoJS.RC4.decrypt(ciphertext, key, cfg);
  9333. */
  9334. C.RC4 = StreamCipher._createHelper(RC4);
  9335. /**
  9336. * Modified RC4 stream cipher algorithm.
  9337. */
  9338. var RC4Drop = C_algo.RC4Drop = RC4.extend({
  9339. /**
  9340. * Configuration options.
  9341. *
  9342. * @property {number} drop The number of keystream words to drop. Default 192
  9343. */
  9344. cfg: RC4.cfg.extend({
  9345. drop: 192
  9346. }),
  9347. _doReset: function () {
  9348. RC4._doReset.call(this);
  9349. // Drop
  9350. for (var i = this.cfg.drop; i > 0; i--) {
  9351. generateKeystreamWord.call(this);
  9352. }
  9353. }
  9354. });
  9355. /**
  9356. * Shortcut functions to the cipher's object interface.
  9357. *
  9358. * @example
  9359. *
  9360. * var ciphertext = CryptoJS.RC4Drop.encrypt(message, key, cfg);
  9361. * var plaintext = CryptoJS.RC4Drop.decrypt(ciphertext, key, cfg);
  9362. */
  9363. C.RC4Drop = StreamCipher._createHelper(RC4Drop);
  9364. }());
  9365. return CryptoJS.RC4;
  9366. }));
  9367. },{"./cipher-core":52,"./core":53,"./enc-base64":54,"./evpkdf":56,"./md5":61}],76:[function(require,module,exports){
  9368. ;(function (root, factory) {
  9369. if (typeof exports === "object") {
  9370. // CommonJS
  9371. module.exports = exports = factory(require("./core"));
  9372. }
  9373. else if (typeof define === "function" && define.amd) {
  9374. // AMD
  9375. define(["./core"], factory);
  9376. }
  9377. else {
  9378. // Global (browser)
  9379. factory(root.CryptoJS);
  9380. }
  9381. }(this, function (CryptoJS) {
  9382. /** @preserve
  9383. (c) 2012 by Cédric Mesnil. All rights reserved.
  9384. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
  9385. - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  9386. - 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.
  9387. 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.
  9388. */
  9389. (function (Math) {
  9390. // Shortcuts
  9391. var C = CryptoJS;
  9392. var C_lib = C.lib;
  9393. var WordArray = C_lib.WordArray;
  9394. var Hasher = C_lib.Hasher;
  9395. var C_algo = C.algo;
  9396. // Constants table
  9397. var _zl = WordArray.create([
  9398. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
  9399. 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8,
  9400. 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12,
  9401. 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2,
  9402. 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13]);
  9403. var _zr = WordArray.create([
  9404. 5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12,
  9405. 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2,
  9406. 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13,
  9407. 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14,
  9408. 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11]);
  9409. var _sl = WordArray.create([
  9410. 11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8,
  9411. 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12,
  9412. 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5,
  9413. 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12,
  9414. 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6 ]);
  9415. var _sr = WordArray.create([
  9416. 8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6,
  9417. 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11,
  9418. 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5,
  9419. 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8,
  9420. 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11 ]);
  9421. var _hl = WordArray.create([ 0x00000000, 0x5A827999, 0x6ED9EBA1, 0x8F1BBCDC, 0xA953FD4E]);
  9422. var _hr = WordArray.create([ 0x50A28BE6, 0x5C4DD124, 0x6D703EF3, 0x7A6D76E9, 0x00000000]);
  9423. /**
  9424. * RIPEMD160 hash algorithm.
  9425. */
  9426. var RIPEMD160 = C_algo.RIPEMD160 = Hasher.extend({
  9427. _doReset: function () {
  9428. this._hash = WordArray.create([0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0]);
  9429. },
  9430. _doProcessBlock: function (M, offset) {
  9431. // Swap endian
  9432. for (var i = 0; i < 16; i++) {
  9433. // Shortcuts
  9434. var offset_i = offset + i;
  9435. var M_offset_i = M[offset_i];
  9436. // Swap
  9437. M[offset_i] = (
  9438. (((M_offset_i << 8) | (M_offset_i >>> 24)) & 0x00ff00ff) |
  9439. (((M_offset_i << 24) | (M_offset_i >>> 8)) & 0xff00ff00)
  9440. );
  9441. }
  9442. // Shortcut
  9443. var H = this._hash.words;
  9444. var hl = _hl.words;
  9445. var hr = _hr.words;
  9446. var zl = _zl.words;
  9447. var zr = _zr.words;
  9448. var sl = _sl.words;
  9449. var sr = _sr.words;
  9450. // Working variables
  9451. var al, bl, cl, dl, el;
  9452. var ar, br, cr, dr, er;
  9453. ar = al = H[0];
  9454. br = bl = H[1];
  9455. cr = cl = H[2];
  9456. dr = dl = H[3];
  9457. er = el = H[4];
  9458. // Computation
  9459. var t;
  9460. for (var i = 0; i < 80; i += 1) {
  9461. t = (al + M[offset+zl[i]])|0;
  9462. if (i<16){
  9463. t += f1(bl,cl,dl) + hl[0];
  9464. } else if (i<32) {
  9465. t += f2(bl,cl,dl) + hl[1];
  9466. } else if (i<48) {
  9467. t += f3(bl,cl,dl) + hl[2];
  9468. } else if (i<64) {
  9469. t += f4(bl,cl,dl) + hl[3];
  9470. } else {// if (i<80) {
  9471. t += f5(bl,cl,dl) + hl[4];
  9472. }
  9473. t = t|0;
  9474. t = rotl(t,sl[i]);
  9475. t = (t+el)|0;
  9476. al = el;
  9477. el = dl;
  9478. dl = rotl(cl, 10);
  9479. cl = bl;
  9480. bl = t;
  9481. t = (ar + M[offset+zr[i]])|0;
  9482. if (i<16){
  9483. t += f5(br,cr,dr) + hr[0];
  9484. } else if (i<32) {
  9485. t += f4(br,cr,dr) + hr[1];
  9486. } else if (i<48) {
  9487. t += f3(br,cr,dr) + hr[2];
  9488. } else if (i<64) {
  9489. t += f2(br,cr,dr) + hr[3];
  9490. } else {// if (i<80) {
  9491. t += f1(br,cr,dr) + hr[4];
  9492. }
  9493. t = t|0;
  9494. t = rotl(t,sr[i]) ;
  9495. t = (t+er)|0;
  9496. ar = er;
  9497. er = dr;
  9498. dr = rotl(cr, 10);
  9499. cr = br;
  9500. br = t;
  9501. }
  9502. // Intermediate hash value
  9503. t = (H[1] + cl + dr)|0;
  9504. H[1] = (H[2] + dl + er)|0;
  9505. H[2] = (H[3] + el + ar)|0;
  9506. H[3] = (H[4] + al + br)|0;
  9507. H[4] = (H[0] + bl + cr)|0;
  9508. H[0] = t;
  9509. },
  9510. _doFinalize: function () {
  9511. // Shortcuts
  9512. var data = this._data;
  9513. var dataWords = data.words;
  9514. var nBitsTotal = this._nDataBytes * 8;
  9515. var nBitsLeft = data.sigBytes * 8;
  9516. // Add padding
  9517. dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32);
  9518. dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = (
  9519. (((nBitsTotal << 8) | (nBitsTotal >>> 24)) & 0x00ff00ff) |
  9520. (((nBitsTotal << 24) | (nBitsTotal >>> 8)) & 0xff00ff00)
  9521. );
  9522. data.sigBytes = (dataWords.length + 1) * 4;
  9523. // Hash final blocks
  9524. this._process();
  9525. // Shortcuts
  9526. var hash = this._hash;
  9527. var H = hash.words;
  9528. // Swap endian
  9529. for (var i = 0; i < 5; i++) {
  9530. // Shortcut
  9531. var H_i = H[i];
  9532. // Swap
  9533. H[i] = (((H_i << 8) | (H_i >>> 24)) & 0x00ff00ff) |
  9534. (((H_i << 24) | (H_i >>> 8)) & 0xff00ff00);
  9535. }
  9536. // Return final computed hash
  9537. return hash;
  9538. },
  9539. clone: function () {
  9540. var clone = Hasher.clone.call(this);
  9541. clone._hash = this._hash.clone();
  9542. return clone;
  9543. }
  9544. });
  9545. function f1(x, y, z) {
  9546. return ((x) ^ (y) ^ (z));
  9547. }
  9548. function f2(x, y, z) {
  9549. return (((x)&(y)) | ((~x)&(z)));
  9550. }
  9551. function f3(x, y, z) {
  9552. return (((x) | (~(y))) ^ (z));
  9553. }
  9554. function f4(x, y, z) {
  9555. return (((x) & (z)) | ((y)&(~(z))));
  9556. }
  9557. function f5(x, y, z) {
  9558. return ((x) ^ ((y) |(~(z))));
  9559. }
  9560. function rotl(x,n) {
  9561. return (x<<n) | (x>>>(32-n));
  9562. }
  9563. /**
  9564. * Shortcut function to the hasher's object interface.
  9565. *
  9566. * @param {WordArray|string} message The message to hash.
  9567. *
  9568. * @return {WordArray} The hash.
  9569. *
  9570. * @static
  9571. *
  9572. * @example
  9573. *
  9574. * var hash = CryptoJS.RIPEMD160('message');
  9575. * var hash = CryptoJS.RIPEMD160(wordArray);
  9576. */
  9577. C.RIPEMD160 = Hasher._createHelper(RIPEMD160);
  9578. /**
  9579. * Shortcut function to the HMAC's object interface.
  9580. *
  9581. * @param {WordArray|string} message The message to hash.
  9582. * @param {WordArray|string} key The secret key.
  9583. *
  9584. * @return {WordArray} The HMAC.
  9585. *
  9586. * @static
  9587. *
  9588. * @example
  9589. *
  9590. * var hmac = CryptoJS.HmacRIPEMD160(message, key);
  9591. */
  9592. C.HmacRIPEMD160 = Hasher._createHmacHelper(RIPEMD160);
  9593. }(Math));
  9594. return CryptoJS.RIPEMD160;
  9595. }));
  9596. },{"./core":53}],77:[function(require,module,exports){
  9597. ;(function (root, factory) {
  9598. if (typeof exports === "object") {
  9599. // CommonJS
  9600. module.exports = exports = factory(require("./core"));
  9601. }
  9602. else if (typeof define === "function" && define.amd) {
  9603. // AMD
  9604. define(["./core"], factory);
  9605. }
  9606. else {
  9607. // Global (browser)
  9608. factory(root.CryptoJS);
  9609. }
  9610. }(this, function (CryptoJS) {
  9611. (function () {
  9612. // Shortcuts
  9613. var C = CryptoJS;
  9614. var C_lib = C.lib;
  9615. var WordArray = C_lib.WordArray;
  9616. var Hasher = C_lib.Hasher;
  9617. var C_algo = C.algo;
  9618. // Reusable object
  9619. var W = [];
  9620. /**
  9621. * SHA-1 hash algorithm.
  9622. */
  9623. var SHA1 = C_algo.SHA1 = Hasher.extend({
  9624. _doReset: function () {
  9625. this._hash = new WordArray.init([
  9626. 0x67452301, 0xefcdab89,
  9627. 0x98badcfe, 0x10325476,
  9628. 0xc3d2e1f0
  9629. ]);
  9630. },
  9631. _doProcessBlock: function (M, offset) {
  9632. // Shortcut
  9633. var H = this._hash.words;
  9634. // Working variables
  9635. var a = H[0];
  9636. var b = H[1];
  9637. var c = H[2];
  9638. var d = H[3];
  9639. var e = H[4];
  9640. // Computation
  9641. for (var i = 0; i < 80; i++) {
  9642. if (i < 16) {
  9643. W[i] = M[offset + i] | 0;
  9644. } else {
  9645. var n = W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16];
  9646. W[i] = (n << 1) | (n >>> 31);
  9647. }
  9648. var t = ((a << 5) | (a >>> 27)) + e + W[i];
  9649. if (i < 20) {
  9650. t += ((b & c) | (~b & d)) + 0x5a827999;
  9651. } else if (i < 40) {
  9652. t += (b ^ c ^ d) + 0x6ed9eba1;
  9653. } else if (i < 60) {
  9654. t += ((b & c) | (b & d) | (c & d)) - 0x70e44324;
  9655. } else /* if (i < 80) */ {
  9656. t += (b ^ c ^ d) - 0x359d3e2a;
  9657. }
  9658. e = d;
  9659. d = c;
  9660. c = (b << 30) | (b >>> 2);
  9661. b = a;
  9662. a = t;
  9663. }
  9664. // Intermediate hash value
  9665. H[0] = (H[0] + a) | 0;
  9666. H[1] = (H[1] + b) | 0;
  9667. H[2] = (H[2] + c) | 0;
  9668. H[3] = (H[3] + d) | 0;
  9669. H[4] = (H[4] + e) | 0;
  9670. },
  9671. _doFinalize: function () {
  9672. // Shortcuts
  9673. var data = this._data;
  9674. var dataWords = data.words;
  9675. var nBitsTotal = this._nDataBytes * 8;
  9676. var nBitsLeft = data.sigBytes * 8;
  9677. // Add padding
  9678. dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32);
  9679. dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = Math.floor(nBitsTotal / 0x100000000);
  9680. dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = nBitsTotal;
  9681. data.sigBytes = dataWords.length * 4;
  9682. // Hash final blocks
  9683. this._process();
  9684. // Return final computed hash
  9685. return this._hash;
  9686. },
  9687. clone: function () {
  9688. var clone = Hasher.clone.call(this);
  9689. clone._hash = this._hash.clone();
  9690. return clone;
  9691. }
  9692. });
  9693. /**
  9694. * Shortcut function to the hasher's object interface.
  9695. *
  9696. * @param {WordArray|string} message The message to hash.
  9697. *
  9698. * @return {WordArray} The hash.
  9699. *
  9700. * @static
  9701. *
  9702. * @example
  9703. *
  9704. * var hash = CryptoJS.SHA1('message');
  9705. * var hash = CryptoJS.SHA1(wordArray);
  9706. */
  9707. C.SHA1 = Hasher._createHelper(SHA1);
  9708. /**
  9709. * Shortcut function to the HMAC's object interface.
  9710. *
  9711. * @param {WordArray|string} message The message to hash.
  9712. * @param {WordArray|string} key The secret key.
  9713. *
  9714. * @return {WordArray} The HMAC.
  9715. *
  9716. * @static
  9717. *
  9718. * @example
  9719. *
  9720. * var hmac = CryptoJS.HmacSHA1(message, key);
  9721. */
  9722. C.HmacSHA1 = Hasher._createHmacHelper(SHA1);
  9723. }());
  9724. return CryptoJS.SHA1;
  9725. }));
  9726. },{"./core":53}],78:[function(require,module,exports){
  9727. ;(function (root, factory, undef) {
  9728. if (typeof exports === "object") {
  9729. // CommonJS
  9730. module.exports = exports = factory(require("./core"), require("./sha256"));
  9731. }
  9732. else if (typeof define === "function" && define.amd) {
  9733. // AMD
  9734. define(["./core", "./sha256"], factory);
  9735. }
  9736. else {
  9737. // Global (browser)
  9738. factory(root.CryptoJS);
  9739. }
  9740. }(this, function (CryptoJS) {
  9741. (function () {
  9742. // Shortcuts
  9743. var C = CryptoJS;
  9744. var C_lib = C.lib;
  9745. var WordArray = C_lib.WordArray;
  9746. var C_algo = C.algo;
  9747. var SHA256 = C_algo.SHA256;
  9748. /**
  9749. * SHA-224 hash algorithm.
  9750. */
  9751. var SHA224 = C_algo.SHA224 = SHA256.extend({
  9752. _doReset: function () {
  9753. this._hash = new WordArray.init([
  9754. 0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939,
  9755. 0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4
  9756. ]);
  9757. },
  9758. _doFinalize: function () {
  9759. var hash = SHA256._doFinalize.call(this);
  9760. hash.sigBytes -= 4;
  9761. return hash;
  9762. }
  9763. });
  9764. /**
  9765. * Shortcut function to the hasher's object interface.
  9766. *
  9767. * @param {WordArray|string} message The message to hash.
  9768. *
  9769. * @return {WordArray} The hash.
  9770. *
  9771. * @static
  9772. *
  9773. * @example
  9774. *
  9775. * var hash = CryptoJS.SHA224('message');
  9776. * var hash = CryptoJS.SHA224(wordArray);
  9777. */
  9778. C.SHA224 = SHA256._createHelper(SHA224);
  9779. /**
  9780. * Shortcut function to the HMAC's object interface.
  9781. *
  9782. * @param {WordArray|string} message The message to hash.
  9783. * @param {WordArray|string} key The secret key.
  9784. *
  9785. * @return {WordArray} The HMAC.
  9786. *
  9787. * @static
  9788. *
  9789. * @example
  9790. *
  9791. * var hmac = CryptoJS.HmacSHA224(message, key);
  9792. */
  9793. C.HmacSHA224 = SHA256._createHmacHelper(SHA224);
  9794. }());
  9795. return CryptoJS.SHA224;
  9796. }));
  9797. },{"./core":53,"./sha256":79}],79:[function(require,module,exports){
  9798. ;(function (root, factory) {
  9799. if (typeof exports === "object") {
  9800. // CommonJS
  9801. module.exports = exports = factory(require("./core"));
  9802. }
  9803. else if (typeof define === "function" && define.amd) {
  9804. // AMD
  9805. define(["./core"], factory);
  9806. }
  9807. else {
  9808. // Global (browser)
  9809. factory(root.CryptoJS);
  9810. }
  9811. }(this, function (CryptoJS) {
  9812. (function (Math) {
  9813. // Shortcuts
  9814. var C = CryptoJS;
  9815. var C_lib = C.lib;
  9816. var WordArray = C_lib.WordArray;
  9817. var Hasher = C_lib.Hasher;
  9818. var C_algo = C.algo;
  9819. // Initialization and round constants tables
  9820. var H = [];
  9821. var K = [];
  9822. // Compute constants
  9823. (function () {
  9824. function isPrime(n) {
  9825. var sqrtN = Math.sqrt(n);
  9826. for (var factor = 2; factor <= sqrtN; factor++) {
  9827. if (!(n % factor)) {
  9828. return false;
  9829. }
  9830. }
  9831. return true;
  9832. }
  9833. function getFractionalBits(n) {
  9834. return ((n - (n | 0)) * 0x100000000) | 0;
  9835. }
  9836. var n = 2;
  9837. var nPrime = 0;
  9838. while (nPrime < 64) {
  9839. if (isPrime(n)) {
  9840. if (nPrime < 8) {
  9841. H[nPrime] = getFractionalBits(Math.pow(n, 1 / 2));
  9842. }
  9843. K[nPrime] = getFractionalBits(Math.pow(n, 1 / 3));
  9844. nPrime++;
  9845. }
  9846. n++;
  9847. }
  9848. }());
  9849. // Reusable object
  9850. var W = [];
  9851. /**
  9852. * SHA-256 hash algorithm.
  9853. */
  9854. var SHA256 = C_algo.SHA256 = Hasher.extend({
  9855. _doReset: function () {
  9856. this._hash = new WordArray.init(H.slice(0));
  9857. },
  9858. _doProcessBlock: function (M, offset) {
  9859. // Shortcut
  9860. var H = this._hash.words;
  9861. // Working variables
  9862. var a = H[0];
  9863. var b = H[1];
  9864. var c = H[2];
  9865. var d = H[3];
  9866. var e = H[4];
  9867. var f = H[5];
  9868. var g = H[6];
  9869. var h = H[7];
  9870. // Computation
  9871. for (var i = 0; i < 64; i++) {
  9872. if (i < 16) {
  9873. W[i] = M[offset + i] | 0;
  9874. } else {
  9875. var gamma0x = W[i - 15];
  9876. var gamma0 = ((gamma0x << 25) | (gamma0x >>> 7)) ^
  9877. ((gamma0x << 14) | (gamma0x >>> 18)) ^
  9878. (gamma0x >>> 3);
  9879. var gamma1x = W[i - 2];
  9880. var gamma1 = ((gamma1x << 15) | (gamma1x >>> 17)) ^
  9881. ((gamma1x << 13) | (gamma1x >>> 19)) ^
  9882. (gamma1x >>> 10);
  9883. W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16];
  9884. }
  9885. var ch = (e & f) ^ (~e & g);
  9886. var maj = (a & b) ^ (a & c) ^ (b & c);
  9887. var sigma0 = ((a << 30) | (a >>> 2)) ^ ((a << 19) | (a >>> 13)) ^ ((a << 10) | (a >>> 22));
  9888. var sigma1 = ((e << 26) | (e >>> 6)) ^ ((e << 21) | (e >>> 11)) ^ ((e << 7) | (e >>> 25));
  9889. var t1 = h + sigma1 + ch + K[i] + W[i];
  9890. var t2 = sigma0 + maj;
  9891. h = g;
  9892. g = f;
  9893. f = e;
  9894. e = (d + t1) | 0;
  9895. d = c;
  9896. c = b;
  9897. b = a;
  9898. a = (t1 + t2) | 0;
  9899. }
  9900. // Intermediate hash value
  9901. H[0] = (H[0] + a) | 0;
  9902. H[1] = (H[1] + b) | 0;
  9903. H[2] = (H[2] + c) | 0;
  9904. H[3] = (H[3] + d) | 0;
  9905. H[4] = (H[4] + e) | 0;
  9906. H[5] = (H[5] + f) | 0;
  9907. H[6] = (H[6] + g) | 0;
  9908. H[7] = (H[7] + h) | 0;
  9909. },
  9910. _doFinalize: function () {
  9911. // Shortcuts
  9912. var data = this._data;
  9913. var dataWords = data.words;
  9914. var nBitsTotal = this._nDataBytes * 8;
  9915. var nBitsLeft = data.sigBytes * 8;
  9916. // Add padding
  9917. dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32);
  9918. dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = Math.floor(nBitsTotal / 0x100000000);
  9919. dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = nBitsTotal;
  9920. data.sigBytes = dataWords.length * 4;
  9921. // Hash final blocks
  9922. this._process();
  9923. // Return final computed hash
  9924. return this._hash;
  9925. },
  9926. clone: function () {
  9927. var clone = Hasher.clone.call(this);
  9928. clone._hash = this._hash.clone();
  9929. return clone;
  9930. }
  9931. });
  9932. /**
  9933. * Shortcut function to the hasher's object interface.
  9934. *
  9935. * @param {WordArray|string} message The message to hash.
  9936. *
  9937. * @return {WordArray} The hash.
  9938. *
  9939. * @static
  9940. *
  9941. * @example
  9942. *
  9943. * var hash = CryptoJS.SHA256('message');
  9944. * var hash = CryptoJS.SHA256(wordArray);
  9945. */
  9946. C.SHA256 = Hasher._createHelper(SHA256);
  9947. /**
  9948. * Shortcut function to the HMAC's object interface.
  9949. *
  9950. * @param {WordArray|string} message The message to hash.
  9951. * @param {WordArray|string} key The secret key.
  9952. *
  9953. * @return {WordArray} The HMAC.
  9954. *
  9955. * @static
  9956. *
  9957. * @example
  9958. *
  9959. * var hmac = CryptoJS.HmacSHA256(message, key);
  9960. */
  9961. C.HmacSHA256 = Hasher._createHmacHelper(SHA256);
  9962. }(Math));
  9963. return CryptoJS.SHA256;
  9964. }));
  9965. },{"./core":53}],80:[function(require,module,exports){
  9966. ;(function (root, factory, undef) {
  9967. if (typeof exports === "object") {
  9968. // CommonJS
  9969. module.exports = exports = factory(require("./core"), require("./x64-core"));
  9970. }
  9971. else if (typeof define === "function" && define.amd) {
  9972. // AMD
  9973. define(["./core", "./x64-core"], factory);
  9974. }
  9975. else {
  9976. // Global (browser)
  9977. factory(root.CryptoJS);
  9978. }
  9979. }(this, function (CryptoJS) {
  9980. (function (Math) {
  9981. // Shortcuts
  9982. var C = CryptoJS;
  9983. var C_lib = C.lib;
  9984. var WordArray = C_lib.WordArray;
  9985. var Hasher = C_lib.Hasher;
  9986. var C_x64 = C.x64;
  9987. var X64Word = C_x64.Word;
  9988. var C_algo = C.algo;
  9989. // Constants tables
  9990. var RHO_OFFSETS = [];
  9991. var PI_INDEXES = [];
  9992. var ROUND_CONSTANTS = [];
  9993. // Compute Constants
  9994. (function () {
  9995. // Compute rho offset constants
  9996. var x = 1, y = 0;
  9997. for (var t = 0; t < 24; t++) {
  9998. RHO_OFFSETS[x + 5 * y] = ((t + 1) * (t + 2) / 2) % 64;
  9999. var newX = y % 5;
  10000. var newY = (2 * x + 3 * y) % 5;
  10001. x = newX;
  10002. y = newY;
  10003. }
  10004. // Compute pi index constants
  10005. for (var x = 0; x < 5; x++) {
  10006. for (var y = 0; y < 5; y++) {
  10007. PI_INDEXES[x + 5 * y] = y + ((2 * x + 3 * y) % 5) * 5;
  10008. }
  10009. }
  10010. // Compute round constants
  10011. var LFSR = 0x01;
  10012. for (var i = 0; i < 24; i++) {
  10013. var roundConstantMsw = 0;
  10014. var roundConstantLsw = 0;
  10015. for (var j = 0; j < 7; j++) {
  10016. if (LFSR & 0x01) {
  10017. var bitPosition = (1 << j) - 1;
  10018. if (bitPosition < 32) {
  10019. roundConstantLsw ^= 1 << bitPosition;
  10020. } else /* if (bitPosition >= 32) */ {
  10021. roundConstantMsw ^= 1 << (bitPosition - 32);
  10022. }
  10023. }
  10024. // Compute next LFSR
  10025. if (LFSR & 0x80) {
  10026. // Primitive polynomial over GF(2): x^8 + x^6 + x^5 + x^4 + 1
  10027. LFSR = (LFSR << 1) ^ 0x71;
  10028. } else {
  10029. LFSR <<= 1;
  10030. }
  10031. }
  10032. ROUND_CONSTANTS[i] = X64Word.create(roundConstantMsw, roundConstantLsw);
  10033. }
  10034. }());
  10035. // Reusable objects for temporary values
  10036. var T = [];
  10037. (function () {
  10038. for (var i = 0; i < 25; i++) {
  10039. T[i] = X64Word.create();
  10040. }
  10041. }());
  10042. /**
  10043. * SHA-3 hash algorithm.
  10044. */
  10045. var SHA3 = C_algo.SHA3 = Hasher.extend({
  10046. /**
  10047. * Configuration options.
  10048. *
  10049. * @property {number} outputLength
  10050. * The desired number of bits in the output hash.
  10051. * Only values permitted are: 224, 256, 384, 512.
  10052. * Default: 512
  10053. */
  10054. cfg: Hasher.cfg.extend({
  10055. outputLength: 512
  10056. }),
  10057. _doReset: function () {
  10058. var state = this._state = []
  10059. for (var i = 0; i < 25; i++) {
  10060. state[i] = new X64Word.init();
  10061. }
  10062. this.blockSize = (1600 - 2 * this.cfg.outputLength) / 32;
  10063. },
  10064. _doProcessBlock: function (M, offset) {
  10065. // Shortcuts
  10066. var state = this._state;
  10067. var nBlockSizeLanes = this.blockSize / 2;
  10068. // Absorb
  10069. for (var i = 0; i < nBlockSizeLanes; i++) {
  10070. // Shortcuts
  10071. var M2i = M[offset + 2 * i];
  10072. var M2i1 = M[offset + 2 * i + 1];
  10073. // Swap endian
  10074. M2i = (
  10075. (((M2i << 8) | (M2i >>> 24)) & 0x00ff00ff) |
  10076. (((M2i << 24) | (M2i >>> 8)) & 0xff00ff00)
  10077. );
  10078. M2i1 = (
  10079. (((M2i1 << 8) | (M2i1 >>> 24)) & 0x00ff00ff) |
  10080. (((M2i1 << 24) | (M2i1 >>> 8)) & 0xff00ff00)
  10081. );
  10082. // Absorb message into state
  10083. var lane = state[i];
  10084. lane.high ^= M2i1;
  10085. lane.low ^= M2i;
  10086. }
  10087. // Rounds
  10088. for (var round = 0; round < 24; round++) {
  10089. // Theta
  10090. for (var x = 0; x < 5; x++) {
  10091. // Mix column lanes
  10092. var tMsw = 0, tLsw = 0;
  10093. for (var y = 0; y < 5; y++) {
  10094. var lane = state[x + 5 * y];
  10095. tMsw ^= lane.high;
  10096. tLsw ^= lane.low;
  10097. }
  10098. // Temporary values
  10099. var Tx = T[x];
  10100. Tx.high = tMsw;
  10101. Tx.low = tLsw;
  10102. }
  10103. for (var x = 0; x < 5; x++) {
  10104. // Shortcuts
  10105. var Tx4 = T[(x + 4) % 5];
  10106. var Tx1 = T[(x + 1) % 5];
  10107. var Tx1Msw = Tx1.high;
  10108. var Tx1Lsw = Tx1.low;
  10109. // Mix surrounding columns
  10110. var tMsw = Tx4.high ^ ((Tx1Msw << 1) | (Tx1Lsw >>> 31));
  10111. var tLsw = Tx4.low ^ ((Tx1Lsw << 1) | (Tx1Msw >>> 31));
  10112. for (var y = 0; y < 5; y++) {
  10113. var lane = state[x + 5 * y];
  10114. lane.high ^= tMsw;
  10115. lane.low ^= tLsw;
  10116. }
  10117. }
  10118. // Rho Pi
  10119. for (var laneIndex = 1; laneIndex < 25; laneIndex++) {
  10120. // Shortcuts
  10121. var lane = state[laneIndex];
  10122. var laneMsw = lane.high;
  10123. var laneLsw = lane.low;
  10124. var rhoOffset = RHO_OFFSETS[laneIndex];
  10125. // Rotate lanes
  10126. if (rhoOffset < 32) {
  10127. var tMsw = (laneMsw << rhoOffset) | (laneLsw >>> (32 - rhoOffset));
  10128. var tLsw = (laneLsw << rhoOffset) | (laneMsw >>> (32 - rhoOffset));
  10129. } else /* if (rhoOffset >= 32) */ {
  10130. var tMsw = (laneLsw << (rhoOffset - 32)) | (laneMsw >>> (64 - rhoOffset));
  10131. var tLsw = (laneMsw << (rhoOffset - 32)) | (laneLsw >>> (64 - rhoOffset));
  10132. }
  10133. // Transpose lanes
  10134. var TPiLane = T[PI_INDEXES[laneIndex]];
  10135. TPiLane.high = tMsw;
  10136. TPiLane.low = tLsw;
  10137. }
  10138. // Rho pi at x = y = 0
  10139. var T0 = T[0];
  10140. var state0 = state[0];
  10141. T0.high = state0.high;
  10142. T0.low = state0.low;
  10143. // Chi
  10144. for (var x = 0; x < 5; x++) {
  10145. for (var y = 0; y < 5; y++) {
  10146. // Shortcuts
  10147. var laneIndex = x + 5 * y;
  10148. var lane = state[laneIndex];
  10149. var TLane = T[laneIndex];
  10150. var Tx1Lane = T[((x + 1) % 5) + 5 * y];
  10151. var Tx2Lane = T[((x + 2) % 5) + 5 * y];
  10152. // Mix rows
  10153. lane.high = TLane.high ^ (~Tx1Lane.high & Tx2Lane.high);
  10154. lane.low = TLane.low ^ (~Tx1Lane.low & Tx2Lane.low);
  10155. }
  10156. }
  10157. // Iota
  10158. var lane = state[0];
  10159. var roundConstant = ROUND_CONSTANTS[round];
  10160. lane.high ^= roundConstant.high;
  10161. lane.low ^= roundConstant.low;;
  10162. }
  10163. },
  10164. _doFinalize: function () {
  10165. // Shortcuts
  10166. var data = this._data;
  10167. var dataWords = data.words;
  10168. var nBitsTotal = this._nDataBytes * 8;
  10169. var nBitsLeft = data.sigBytes * 8;
  10170. var blockSizeBits = this.blockSize * 32;
  10171. // Add padding
  10172. dataWords[nBitsLeft >>> 5] |= 0x1 << (24 - nBitsLeft % 32);
  10173. dataWords[((Math.ceil((nBitsLeft + 1) / blockSizeBits) * blockSizeBits) >>> 5) - 1] |= 0x80;
  10174. data.sigBytes = dataWords.length * 4;
  10175. // Hash final blocks
  10176. this._process();
  10177. // Shortcuts
  10178. var state = this._state;
  10179. var outputLengthBytes = this.cfg.outputLength / 8;
  10180. var outputLengthLanes = outputLengthBytes / 8;
  10181. // Squeeze
  10182. var hashWords = [];
  10183. for (var i = 0; i < outputLengthLanes; i++) {
  10184. // Shortcuts
  10185. var lane = state[i];
  10186. var laneMsw = lane.high;
  10187. var laneLsw = lane.low;
  10188. // Swap endian
  10189. laneMsw = (
  10190. (((laneMsw << 8) | (laneMsw >>> 24)) & 0x00ff00ff) |
  10191. (((laneMsw << 24) | (laneMsw >>> 8)) & 0xff00ff00)
  10192. );
  10193. laneLsw = (
  10194. (((laneLsw << 8) | (laneLsw >>> 24)) & 0x00ff00ff) |
  10195. (((laneLsw << 24) | (laneLsw >>> 8)) & 0xff00ff00)
  10196. );
  10197. // Squeeze state to retrieve hash
  10198. hashWords.push(laneLsw);
  10199. hashWords.push(laneMsw);
  10200. }
  10201. // Return final computed hash
  10202. return new WordArray.init(hashWords, outputLengthBytes);
  10203. },
  10204. clone: function () {
  10205. var clone = Hasher.clone.call(this);
  10206. var state = clone._state = this._state.slice(0);
  10207. for (var i = 0; i < 25; i++) {
  10208. state[i] = state[i].clone();
  10209. }
  10210. return clone;
  10211. }
  10212. });
  10213. /**
  10214. * Shortcut function to the hasher's object interface.
  10215. *
  10216. * @param {WordArray|string} message The message to hash.
  10217. *
  10218. * @return {WordArray} The hash.
  10219. *
  10220. * @static
  10221. *
  10222. * @example
  10223. *
  10224. * var hash = CryptoJS.SHA3('message');
  10225. * var hash = CryptoJS.SHA3(wordArray);
  10226. */
  10227. C.SHA3 = Hasher._createHelper(SHA3);
  10228. /**
  10229. * Shortcut function to the HMAC's object interface.
  10230. *
  10231. * @param {WordArray|string} message The message to hash.
  10232. * @param {WordArray|string} key The secret key.
  10233. *
  10234. * @return {WordArray} The HMAC.
  10235. *
  10236. * @static
  10237. *
  10238. * @example
  10239. *
  10240. * var hmac = CryptoJS.HmacSHA3(message, key);
  10241. */
  10242. C.HmacSHA3 = Hasher._createHmacHelper(SHA3);
  10243. }(Math));
  10244. return CryptoJS.SHA3;
  10245. }));
  10246. },{"./core":53,"./x64-core":84}],81:[function(require,module,exports){
  10247. ;(function (root, factory, undef) {
  10248. if (typeof exports === "object") {
  10249. // CommonJS
  10250. module.exports = exports = factory(require("./core"), require("./x64-core"), require("./sha512"));
  10251. }
  10252. else if (typeof define === "function" && define.amd) {
  10253. // AMD
  10254. define(["./core", "./x64-core", "./sha512"], factory);
  10255. }
  10256. else {
  10257. // Global (browser)
  10258. factory(root.CryptoJS);
  10259. }
  10260. }(this, function (CryptoJS) {
  10261. (function () {
  10262. // Shortcuts
  10263. var C = CryptoJS;
  10264. var C_x64 = C.x64;
  10265. var X64Word = C_x64.Word;
  10266. var X64WordArray = C_x64.WordArray;
  10267. var C_algo = C.algo;
  10268. var SHA512 = C_algo.SHA512;
  10269. /**
  10270. * SHA-384 hash algorithm.
  10271. */
  10272. var SHA384 = C_algo.SHA384 = SHA512.extend({
  10273. _doReset: function () {
  10274. this._hash = new X64WordArray.init([
  10275. new X64Word.init(0xcbbb9d5d, 0xc1059ed8), new X64Word.init(0x629a292a, 0x367cd507),
  10276. new X64Word.init(0x9159015a, 0x3070dd17), new X64Word.init(0x152fecd8, 0xf70e5939),
  10277. new X64Word.init(0x67332667, 0xffc00b31), new X64Word.init(0x8eb44a87, 0x68581511),
  10278. new X64Word.init(0xdb0c2e0d, 0x64f98fa7), new X64Word.init(0x47b5481d, 0xbefa4fa4)
  10279. ]);
  10280. },
  10281. _doFinalize: function () {
  10282. var hash = SHA512._doFinalize.call(this);
  10283. hash.sigBytes -= 16;
  10284. return hash;
  10285. }
  10286. });
  10287. /**
  10288. * Shortcut function to the hasher's object interface.
  10289. *
  10290. * @param {WordArray|string} message The message to hash.
  10291. *
  10292. * @return {WordArray} The hash.
  10293. *
  10294. * @static
  10295. *
  10296. * @example
  10297. *
  10298. * var hash = CryptoJS.SHA384('message');
  10299. * var hash = CryptoJS.SHA384(wordArray);
  10300. */
  10301. C.SHA384 = SHA512._createHelper(SHA384);
  10302. /**
  10303. * Shortcut function to the HMAC's object interface.
  10304. *
  10305. * @param {WordArray|string} message The message to hash.
  10306. * @param {WordArray|string} key The secret key.
  10307. *
  10308. * @return {WordArray} The HMAC.
  10309. *
  10310. * @static
  10311. *
  10312. * @example
  10313. *
  10314. * var hmac = CryptoJS.HmacSHA384(message, key);
  10315. */
  10316. C.HmacSHA384 = SHA512._createHmacHelper(SHA384);
  10317. }());
  10318. return CryptoJS.SHA384;
  10319. }));
  10320. },{"./core":53,"./sha512":82,"./x64-core":84}],82:[function(require,module,exports){
  10321. ;(function (root, factory, undef) {
  10322. if (typeof exports === "object") {
  10323. // CommonJS
  10324. module.exports = exports = factory(require("./core"), require("./x64-core"));
  10325. }
  10326. else if (typeof define === "function" && define.amd) {
  10327. // AMD
  10328. define(["./core", "./x64-core"], factory);
  10329. }
  10330. else {
  10331. // Global (browser)
  10332. factory(root.CryptoJS);
  10333. }
  10334. }(this, function (CryptoJS) {
  10335. (function () {
  10336. // Shortcuts
  10337. var C = CryptoJS;
  10338. var C_lib = C.lib;
  10339. var Hasher = C_lib.Hasher;
  10340. var C_x64 = C.x64;
  10341. var X64Word = C_x64.Word;
  10342. var X64WordArray = C_x64.WordArray;
  10343. var C_algo = C.algo;
  10344. function X64Word_create() {
  10345. return X64Word.create.apply(X64Word, arguments);
  10346. }
  10347. // Constants
  10348. var K = [
  10349. X64Word_create(0x428a2f98, 0xd728ae22), X64Word_create(0x71374491, 0x23ef65cd),
  10350. X64Word_create(0xb5c0fbcf, 0xec4d3b2f), X64Word_create(0xe9b5dba5, 0x8189dbbc),
  10351. X64Word_create(0x3956c25b, 0xf348b538), X64Word_create(0x59f111f1, 0xb605d019),
  10352. X64Word_create(0x923f82a4, 0xaf194f9b), X64Word_create(0xab1c5ed5, 0xda6d8118),
  10353. X64Word_create(0xd807aa98, 0xa3030242), X64Word_create(0x12835b01, 0x45706fbe),
  10354. X64Word_create(0x243185be, 0x4ee4b28c), X64Word_create(0x550c7dc3, 0xd5ffb4e2),
  10355. X64Word_create(0x72be5d74, 0xf27b896f), X64Word_create(0x80deb1fe, 0x3b1696b1),
  10356. X64Word_create(0x9bdc06a7, 0x25c71235), X64Word_create(0xc19bf174, 0xcf692694),
  10357. X64Word_create(0xe49b69c1, 0x9ef14ad2), X64Word_create(0xefbe4786, 0x384f25e3),
  10358. X64Word_create(0x0fc19dc6, 0x8b8cd5b5), X64Word_create(0x240ca1cc, 0x77ac9c65),
  10359. X64Word_create(0x2de92c6f, 0x592b0275), X64Word_create(0x4a7484aa, 0x6ea6e483),
  10360. X64Word_create(0x5cb0a9dc, 0xbd41fbd4), X64Word_create(0x76f988da, 0x831153b5),
  10361. X64Word_create(0x983e5152, 0xee66dfab), X64Word_create(0xa831c66d, 0x2db43210),
  10362. X64Word_create(0xb00327c8, 0x98fb213f), X64Word_create(0xbf597fc7, 0xbeef0ee4),
  10363. X64Word_create(0xc6e00bf3, 0x3da88fc2), X64Word_create(0xd5a79147, 0x930aa725),
  10364. X64Word_create(0x06ca6351, 0xe003826f), X64Word_create(0x14292967, 0x0a0e6e70),
  10365. X64Word_create(0x27b70a85, 0x46d22ffc), X64Word_create(0x2e1b2138, 0x5c26c926),
  10366. X64Word_create(0x4d2c6dfc, 0x5ac42aed), X64Word_create(0x53380d13, 0x9d95b3df),
  10367. X64Word_create(0x650a7354, 0x8baf63de), X64Word_create(0x766a0abb, 0x3c77b2a8),
  10368. X64Word_create(0x81c2c92e, 0x47edaee6), X64Word_create(0x92722c85, 0x1482353b),
  10369. X64Word_create(0xa2bfe8a1, 0x4cf10364), X64Word_create(0xa81a664b, 0xbc423001),
  10370. X64Word_create(0xc24b8b70, 0xd0f89791), X64Word_create(0xc76c51a3, 0x0654be30),
  10371. X64Word_create(0xd192e819, 0xd6ef5218), X64Word_create(0xd6990624, 0x5565a910),
  10372. X64Word_create(0xf40e3585, 0x5771202a), X64Word_create(0x106aa070, 0x32bbd1b8),
  10373. X64Word_create(0x19a4c116, 0xb8d2d0c8), X64Word_create(0x1e376c08, 0x5141ab53),
  10374. X64Word_create(0x2748774c, 0xdf8eeb99), X64Word_create(0x34b0bcb5, 0xe19b48a8),
  10375. X64Word_create(0x391c0cb3, 0xc5c95a63), X64Word_create(0x4ed8aa4a, 0xe3418acb),
  10376. X64Word_create(0x5b9cca4f, 0x7763e373), X64Word_create(0x682e6ff3, 0xd6b2b8a3),
  10377. X64Word_create(0x748f82ee, 0x5defb2fc), X64Word_create(0x78a5636f, 0x43172f60),
  10378. X64Word_create(0x84c87814, 0xa1f0ab72), X64Word_create(0x8cc70208, 0x1a6439ec),
  10379. X64Word_create(0x90befffa, 0x23631e28), X64Word_create(0xa4506ceb, 0xde82bde9),
  10380. X64Word_create(0xbef9a3f7, 0xb2c67915), X64Word_create(0xc67178f2, 0xe372532b),
  10381. X64Word_create(0xca273ece, 0xea26619c), X64Word_create(0xd186b8c7, 0x21c0c207),
  10382. X64Word_create(0xeada7dd6, 0xcde0eb1e), X64Word_create(0xf57d4f7f, 0xee6ed178),
  10383. X64Word_create(0x06f067aa, 0x72176fba), X64Word_create(0x0a637dc5, 0xa2c898a6),
  10384. X64Word_create(0x113f9804, 0xbef90dae), X64Word_create(0x1b710b35, 0x131c471b),
  10385. X64Word_create(0x28db77f5, 0x23047d84), X64Word_create(0x32caab7b, 0x40c72493),
  10386. X64Word_create(0x3c9ebe0a, 0x15c9bebc), X64Word_create(0x431d67c4, 0x9c100d4c),
  10387. X64Word_create(0x4cc5d4be, 0xcb3e42b6), X64Word_create(0x597f299c, 0xfc657e2a),
  10388. X64Word_create(0x5fcb6fab, 0x3ad6faec), X64Word_create(0x6c44198c, 0x4a475817)
  10389. ];
  10390. // Reusable objects
  10391. var W = [];
  10392. (function () {
  10393. for (var i = 0; i < 80; i++) {
  10394. W[i] = X64Word_create();
  10395. }
  10396. }());
  10397. /**
  10398. * SHA-512 hash algorithm.
  10399. */
  10400. var SHA512 = C_algo.SHA512 = Hasher.extend({
  10401. _doReset: function () {
  10402. this._hash = new X64WordArray.init([
  10403. new X64Word.init(0x6a09e667, 0xf3bcc908), new X64Word.init(0xbb67ae85, 0x84caa73b),
  10404. new X64Word.init(0x3c6ef372, 0xfe94f82b), new X64Word.init(0xa54ff53a, 0x5f1d36f1),
  10405. new X64Word.init(0x510e527f, 0xade682d1), new X64Word.init(0x9b05688c, 0x2b3e6c1f),
  10406. new X64Word.init(0x1f83d9ab, 0xfb41bd6b), new X64Word.init(0x5be0cd19, 0x137e2179)
  10407. ]);
  10408. },
  10409. _doProcessBlock: function (M, offset) {
  10410. // Shortcuts
  10411. var H = this._hash.words;
  10412. var H0 = H[0];
  10413. var H1 = H[1];
  10414. var H2 = H[2];
  10415. var H3 = H[3];
  10416. var H4 = H[4];
  10417. var H5 = H[5];
  10418. var H6 = H[6];
  10419. var H7 = H[7];
  10420. var H0h = H0.high;
  10421. var H0l = H0.low;
  10422. var H1h = H1.high;
  10423. var H1l = H1.low;
  10424. var H2h = H2.high;
  10425. var H2l = H2.low;
  10426. var H3h = H3.high;
  10427. var H3l = H3.low;
  10428. var H4h = H4.high;
  10429. var H4l = H4.low;
  10430. var H5h = H5.high;
  10431. var H5l = H5.low;
  10432. var H6h = H6.high;
  10433. var H6l = H6.low;
  10434. var H7h = H7.high;
  10435. var H7l = H7.low;
  10436. // Working variables
  10437. var ah = H0h;
  10438. var al = H0l;
  10439. var bh = H1h;
  10440. var bl = H1l;
  10441. var ch = H2h;
  10442. var cl = H2l;
  10443. var dh = H3h;
  10444. var dl = H3l;
  10445. var eh = H4h;
  10446. var el = H4l;
  10447. var fh = H5h;
  10448. var fl = H5l;
  10449. var gh = H6h;
  10450. var gl = H6l;
  10451. var hh = H7h;
  10452. var hl = H7l;
  10453. // Rounds
  10454. for (var i = 0; i < 80; i++) {
  10455. // Shortcut
  10456. var Wi = W[i];
  10457. // Extend message
  10458. if (i < 16) {
  10459. var Wih = Wi.high = M[offset + i * 2] | 0;
  10460. var Wil = Wi.low = M[offset + i * 2 + 1] | 0;
  10461. } else {
  10462. // Gamma0
  10463. var gamma0x = W[i - 15];
  10464. var gamma0xh = gamma0x.high;
  10465. var gamma0xl = gamma0x.low;
  10466. var gamma0h = ((gamma0xh >>> 1) | (gamma0xl << 31)) ^ ((gamma0xh >>> 8) | (gamma0xl << 24)) ^ (gamma0xh >>> 7);
  10467. var gamma0l = ((gamma0xl >>> 1) | (gamma0xh << 31)) ^ ((gamma0xl >>> 8) | (gamma0xh << 24)) ^ ((gamma0xl >>> 7) | (gamma0xh << 25));
  10468. // Gamma1
  10469. var gamma1x = W[i - 2];
  10470. var gamma1xh = gamma1x.high;
  10471. var gamma1xl = gamma1x.low;
  10472. var gamma1h = ((gamma1xh >>> 19) | (gamma1xl << 13)) ^ ((gamma1xh << 3) | (gamma1xl >>> 29)) ^ (gamma1xh >>> 6);
  10473. var gamma1l = ((gamma1xl >>> 19) | (gamma1xh << 13)) ^ ((gamma1xl << 3) | (gamma1xh >>> 29)) ^ ((gamma1xl >>> 6) | (gamma1xh << 26));
  10474. // W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16]
  10475. var Wi7 = W[i - 7];
  10476. var Wi7h = Wi7.high;
  10477. var Wi7l = Wi7.low;
  10478. var Wi16 = W[i - 16];
  10479. var Wi16h = Wi16.high;
  10480. var Wi16l = Wi16.low;
  10481. var Wil = gamma0l + Wi7l;
  10482. var Wih = gamma0h + Wi7h + ((Wil >>> 0) < (gamma0l >>> 0) ? 1 : 0);
  10483. var Wil = Wil + gamma1l;
  10484. var Wih = Wih + gamma1h + ((Wil >>> 0) < (gamma1l >>> 0) ? 1 : 0);
  10485. var Wil = Wil + Wi16l;
  10486. var Wih = Wih + Wi16h + ((Wil >>> 0) < (Wi16l >>> 0) ? 1 : 0);
  10487. Wi.high = Wih;
  10488. Wi.low = Wil;
  10489. }
  10490. var chh = (eh & fh) ^ (~eh & gh);
  10491. var chl = (el & fl) ^ (~el & gl);
  10492. var majh = (ah & bh) ^ (ah & ch) ^ (bh & ch);
  10493. var majl = (al & bl) ^ (al & cl) ^ (bl & cl);
  10494. var sigma0h = ((ah >>> 28) | (al << 4)) ^ ((ah << 30) | (al >>> 2)) ^ ((ah << 25) | (al >>> 7));
  10495. var sigma0l = ((al >>> 28) | (ah << 4)) ^ ((al << 30) | (ah >>> 2)) ^ ((al << 25) | (ah >>> 7));
  10496. var sigma1h = ((eh >>> 14) | (el << 18)) ^ ((eh >>> 18) | (el << 14)) ^ ((eh << 23) | (el >>> 9));
  10497. var sigma1l = ((el >>> 14) | (eh << 18)) ^ ((el >>> 18) | (eh << 14)) ^ ((el << 23) | (eh >>> 9));
  10498. // t1 = h + sigma1 + ch + K[i] + W[i]
  10499. var Ki = K[i];
  10500. var Kih = Ki.high;
  10501. var Kil = Ki.low;
  10502. var t1l = hl + sigma1l;
  10503. var t1h = hh + sigma1h + ((t1l >>> 0) < (hl >>> 0) ? 1 : 0);
  10504. var t1l = t1l + chl;
  10505. var t1h = t1h + chh + ((t1l >>> 0) < (chl >>> 0) ? 1 : 0);
  10506. var t1l = t1l + Kil;
  10507. var t1h = t1h + Kih + ((t1l >>> 0) < (Kil >>> 0) ? 1 : 0);
  10508. var t1l = t1l + Wil;
  10509. var t1h = t1h + Wih + ((t1l >>> 0) < (Wil >>> 0) ? 1 : 0);
  10510. // t2 = sigma0 + maj
  10511. var t2l = sigma0l + majl;
  10512. var t2h = sigma0h + majh + ((t2l >>> 0) < (sigma0l >>> 0) ? 1 : 0);
  10513. // Update working variables
  10514. hh = gh;
  10515. hl = gl;
  10516. gh = fh;
  10517. gl = fl;
  10518. fh = eh;
  10519. fl = el;
  10520. el = (dl + t1l) | 0;
  10521. eh = (dh + t1h + ((el >>> 0) < (dl >>> 0) ? 1 : 0)) | 0;
  10522. dh = ch;
  10523. dl = cl;
  10524. ch = bh;
  10525. cl = bl;
  10526. bh = ah;
  10527. bl = al;
  10528. al = (t1l + t2l) | 0;
  10529. ah = (t1h + t2h + ((al >>> 0) < (t1l >>> 0) ? 1 : 0)) | 0;
  10530. }
  10531. // Intermediate hash value
  10532. H0l = H0.low = (H0l + al);
  10533. H0.high = (H0h + ah + ((H0l >>> 0) < (al >>> 0) ? 1 : 0));
  10534. H1l = H1.low = (H1l + bl);
  10535. H1.high = (H1h + bh + ((H1l >>> 0) < (bl >>> 0) ? 1 : 0));
  10536. H2l = H2.low = (H2l + cl);
  10537. H2.high = (H2h + ch + ((H2l >>> 0) < (cl >>> 0) ? 1 : 0));
  10538. H3l = H3.low = (H3l + dl);
  10539. H3.high = (H3h + dh + ((H3l >>> 0) < (dl >>> 0) ? 1 : 0));
  10540. H4l = H4.low = (H4l + el);
  10541. H4.high = (H4h + eh + ((H4l >>> 0) < (el >>> 0) ? 1 : 0));
  10542. H5l = H5.low = (H5l + fl);
  10543. H5.high = (H5h + fh + ((H5l >>> 0) < (fl >>> 0) ? 1 : 0));
  10544. H6l = H6.low = (H6l + gl);
  10545. H6.high = (H6h + gh + ((H6l >>> 0) < (gl >>> 0) ? 1 : 0));
  10546. H7l = H7.low = (H7l + hl);
  10547. H7.high = (H7h + hh + ((H7l >>> 0) < (hl >>> 0) ? 1 : 0));
  10548. },
  10549. _doFinalize: function () {
  10550. // Shortcuts
  10551. var data = this._data;
  10552. var dataWords = data.words;
  10553. var nBitsTotal = this._nDataBytes * 8;
  10554. var nBitsLeft = data.sigBytes * 8;
  10555. // Add padding
  10556. dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32);
  10557. dataWords[(((nBitsLeft + 128) >>> 10) << 5) + 30] = Math.floor(nBitsTotal / 0x100000000);
  10558. dataWords[(((nBitsLeft + 128) >>> 10) << 5) + 31] = nBitsTotal;
  10559. data.sigBytes = dataWords.length * 4;
  10560. // Hash final blocks
  10561. this._process();
  10562. // Convert hash to 32-bit word array before returning
  10563. var hash = this._hash.toX32();
  10564. // Return final computed hash
  10565. return hash;
  10566. },
  10567. clone: function () {
  10568. var clone = Hasher.clone.call(this);
  10569. clone._hash = this._hash.clone();
  10570. return clone;
  10571. },
  10572. blockSize: 1024/32
  10573. });
  10574. /**
  10575. * Shortcut function to the hasher's object interface.
  10576. *
  10577. * @param {WordArray|string} message The message to hash.
  10578. *
  10579. * @return {WordArray} The hash.
  10580. *
  10581. * @static
  10582. *
  10583. * @example
  10584. *
  10585. * var hash = CryptoJS.SHA512('message');
  10586. * var hash = CryptoJS.SHA512(wordArray);
  10587. */
  10588. C.SHA512 = Hasher._createHelper(SHA512);
  10589. /**
  10590. * Shortcut function to the HMAC's object interface.
  10591. *
  10592. * @param {WordArray|string} message The message to hash.
  10593. * @param {WordArray|string} key The secret key.
  10594. *
  10595. * @return {WordArray} The HMAC.
  10596. *
  10597. * @static
  10598. *
  10599. * @example
  10600. *
  10601. * var hmac = CryptoJS.HmacSHA512(message, key);
  10602. */
  10603. C.HmacSHA512 = Hasher._createHmacHelper(SHA512);
  10604. }());
  10605. return CryptoJS.SHA512;
  10606. }));
  10607. },{"./core":53,"./x64-core":84}],83:[function(require,module,exports){
  10608. ;(function (root, factory, undef) {
  10609. if (typeof exports === "object") {
  10610. // CommonJS
  10611. module.exports = exports = factory(require("./core"), require("./enc-base64"), require("./md5"), require("./evpkdf"), require("./cipher-core"));
  10612. }
  10613. else if (typeof define === "function" && define.amd) {
  10614. // AMD
  10615. define(["./core", "./enc-base64", "./md5", "./evpkdf", "./cipher-core"], factory);
  10616. }
  10617. else {
  10618. // Global (browser)
  10619. factory(root.CryptoJS);
  10620. }
  10621. }(this, function (CryptoJS) {
  10622. (function () {
  10623. // Shortcuts
  10624. var C = CryptoJS;
  10625. var C_lib = C.lib;
  10626. var WordArray = C_lib.WordArray;
  10627. var BlockCipher = C_lib.BlockCipher;
  10628. var C_algo = C.algo;
  10629. // Permuted Choice 1 constants
  10630. var PC1 = [
  10631. 57, 49, 41, 33, 25, 17, 9, 1,
  10632. 58, 50, 42, 34, 26, 18, 10, 2,
  10633. 59, 51, 43, 35, 27, 19, 11, 3,
  10634. 60, 52, 44, 36, 63, 55, 47, 39,
  10635. 31, 23, 15, 7, 62, 54, 46, 38,
  10636. 30, 22, 14, 6, 61, 53, 45, 37,
  10637. 29, 21, 13, 5, 28, 20, 12, 4
  10638. ];
  10639. // Permuted Choice 2 constants
  10640. var PC2 = [
  10641. 14, 17, 11, 24, 1, 5,
  10642. 3, 28, 15, 6, 21, 10,
  10643. 23, 19, 12, 4, 26, 8,
  10644. 16, 7, 27, 20, 13, 2,
  10645. 41, 52, 31, 37, 47, 55,
  10646. 30, 40, 51, 45, 33, 48,
  10647. 44, 49, 39, 56, 34, 53,
  10648. 46, 42, 50, 36, 29, 32
  10649. ];
  10650. // Cumulative bit shift constants
  10651. var BIT_SHIFTS = [1, 2, 4, 6, 8, 10, 12, 14, 15, 17, 19, 21, 23, 25, 27, 28];
  10652. // SBOXes and round permutation constants
  10653. var SBOX_P = [
  10654. {
  10655. 0x0: 0x808200,
  10656. 0x10000000: 0x8000,
  10657. 0x20000000: 0x808002,
  10658. 0x30000000: 0x2,
  10659. 0x40000000: 0x200,
  10660. 0x50000000: 0x808202,
  10661. 0x60000000: 0x800202,
  10662. 0x70000000: 0x800000,
  10663. 0x80000000: 0x202,
  10664. 0x90000000: 0x800200,
  10665. 0xa0000000: 0x8200,
  10666. 0xb0000000: 0x808000,
  10667. 0xc0000000: 0x8002,
  10668. 0xd0000000: 0x800002,
  10669. 0xe0000000: 0x0,
  10670. 0xf0000000: 0x8202,
  10671. 0x8000000: 0x0,
  10672. 0x18000000: 0x808202,
  10673. 0x28000000: 0x8202,
  10674. 0x38000000: 0x8000,
  10675. 0x48000000: 0x808200,
  10676. 0x58000000: 0x200,
  10677. 0x68000000: 0x808002,
  10678. 0x78000000: 0x2,
  10679. 0x88000000: 0x800200,
  10680. 0x98000000: 0x8200,
  10681. 0xa8000000: 0x808000,
  10682. 0xb8000000: 0x800202,
  10683. 0xc8000000: 0x800002,
  10684. 0xd8000000: 0x8002,
  10685. 0xe8000000: 0x202,
  10686. 0xf8000000: 0x800000,
  10687. 0x1: 0x8000,
  10688. 0x10000001: 0x2,
  10689. 0x20000001: 0x808200,
  10690. 0x30000001: 0x800000,
  10691. 0x40000001: 0x808002,
  10692. 0x50000001: 0x8200,
  10693. 0x60000001: 0x200,
  10694. 0x70000001: 0x800202,
  10695. 0x80000001: 0x808202,
  10696. 0x90000001: 0x808000,
  10697. 0xa0000001: 0x800002,
  10698. 0xb0000001: 0x8202,
  10699. 0xc0000001: 0x202,
  10700. 0xd0000001: 0x800200,
  10701. 0xe0000001: 0x8002,
  10702. 0xf0000001: 0x0,
  10703. 0x8000001: 0x808202,
  10704. 0x18000001: 0x808000,
  10705. 0x28000001: 0x800000,
  10706. 0x38000001: 0x200,
  10707. 0x48000001: 0x8000,
  10708. 0x58000001: 0x800002,
  10709. 0x68000001: 0x2,
  10710. 0x78000001: 0x8202,
  10711. 0x88000001: 0x8002,
  10712. 0x98000001: 0x800202,
  10713. 0xa8000001: 0x202,
  10714. 0xb8000001: 0x808200,
  10715. 0xc8000001: 0x800200,
  10716. 0xd8000001: 0x0,
  10717. 0xe8000001: 0x8200,
  10718. 0xf8000001: 0x808002
  10719. },
  10720. {
  10721. 0x0: 0x40084010,
  10722. 0x1000000: 0x4000,
  10723. 0x2000000: 0x80000,
  10724. 0x3000000: 0x40080010,
  10725. 0x4000000: 0x40000010,
  10726. 0x5000000: 0x40084000,
  10727. 0x6000000: 0x40004000,
  10728. 0x7000000: 0x10,
  10729. 0x8000000: 0x84000,
  10730. 0x9000000: 0x40004010,
  10731. 0xa000000: 0x40000000,
  10732. 0xb000000: 0x84010,
  10733. 0xc000000: 0x80010,
  10734. 0xd000000: 0x0,
  10735. 0xe000000: 0x4010,
  10736. 0xf000000: 0x40080000,
  10737. 0x800000: 0x40004000,
  10738. 0x1800000: 0x84010,
  10739. 0x2800000: 0x10,
  10740. 0x3800000: 0x40004010,
  10741. 0x4800000: 0x40084010,
  10742. 0x5800000: 0x40000000,
  10743. 0x6800000: 0x80000,
  10744. 0x7800000: 0x40080010,
  10745. 0x8800000: 0x80010,
  10746. 0x9800000: 0x0,
  10747. 0xa800000: 0x4000,
  10748. 0xb800000: 0x40080000,
  10749. 0xc800000: 0x40000010,
  10750. 0xd800000: 0x84000,
  10751. 0xe800000: 0x40084000,
  10752. 0xf800000: 0x4010,
  10753. 0x10000000: 0x0,
  10754. 0x11000000: 0x40080010,
  10755. 0x12000000: 0x40004010,
  10756. 0x13000000: 0x40084000,
  10757. 0x14000000: 0x40080000,
  10758. 0x15000000: 0x10,
  10759. 0x16000000: 0x84010,
  10760. 0x17000000: 0x4000,
  10761. 0x18000000: 0x4010,
  10762. 0x19000000: 0x80000,
  10763. 0x1a000000: 0x80010,
  10764. 0x1b000000: 0x40000010,
  10765. 0x1c000000: 0x84000,
  10766. 0x1d000000: 0x40004000,
  10767. 0x1e000000: 0x40000000,
  10768. 0x1f000000: 0x40084010,
  10769. 0x10800000: 0x84010,
  10770. 0x11800000: 0x80000,
  10771. 0x12800000: 0x40080000,
  10772. 0x13800000: 0x4000,
  10773. 0x14800000: 0x40004000,
  10774. 0x15800000: 0x40084010,
  10775. 0x16800000: 0x10,
  10776. 0x17800000: 0x40000000,
  10777. 0x18800000: 0x40084000,
  10778. 0x19800000: 0x40000010,
  10779. 0x1a800000: 0x40004010,
  10780. 0x1b800000: 0x80010,
  10781. 0x1c800000: 0x0,
  10782. 0x1d800000: 0x4010,
  10783. 0x1e800000: 0x40080010,
  10784. 0x1f800000: 0x84000
  10785. },
  10786. {
  10787. 0x0: 0x104,
  10788. 0x100000: 0x0,
  10789. 0x200000: 0x4000100,
  10790. 0x300000: 0x10104,
  10791. 0x400000: 0x10004,
  10792. 0x500000: 0x4000004,
  10793. 0x600000: 0x4010104,
  10794. 0x700000: 0x4010000,
  10795. 0x800000: 0x4000000,
  10796. 0x900000: 0x4010100,
  10797. 0xa00000: 0x10100,
  10798. 0xb00000: 0x4010004,
  10799. 0xc00000: 0x4000104,
  10800. 0xd00000: 0x10000,
  10801. 0xe00000: 0x4,
  10802. 0xf00000: 0x100,
  10803. 0x80000: 0x4010100,
  10804. 0x180000: 0x4010004,
  10805. 0x280000: 0x0,
  10806. 0x380000: 0x4000100,
  10807. 0x480000: 0x4000004,
  10808. 0x580000: 0x10000,
  10809. 0x680000: 0x10004,
  10810. 0x780000: 0x104,
  10811. 0x880000: 0x4,
  10812. 0x980000: 0x100,
  10813. 0xa80000: 0x4010000,
  10814. 0xb80000: 0x10104,
  10815. 0xc80000: 0x10100,
  10816. 0xd80000: 0x4000104,
  10817. 0xe80000: 0x4010104,
  10818. 0xf80000: 0x4000000,
  10819. 0x1000000: 0x4010100,
  10820. 0x1100000: 0x10004,
  10821. 0x1200000: 0x10000,
  10822. 0x1300000: 0x4000100,
  10823. 0x1400000: 0x100,
  10824. 0x1500000: 0x4010104,
  10825. 0x1600000: 0x4000004,
  10826. 0x1700000: 0x0,
  10827. 0x1800000: 0x4000104,
  10828. 0x1900000: 0x4000000,
  10829. 0x1a00000: 0x4,
  10830. 0x1b00000: 0x10100,
  10831. 0x1c00000: 0x4010000,
  10832. 0x1d00000: 0x104,
  10833. 0x1e00000: 0x10104,
  10834. 0x1f00000: 0x4010004,
  10835. 0x1080000: 0x4000000,
  10836. 0x1180000: 0x104,
  10837. 0x1280000: 0x4010100,
  10838. 0x1380000: 0x0,
  10839. 0x1480000: 0x10004,
  10840. 0x1580000: 0x4000100,
  10841. 0x1680000: 0x100,
  10842. 0x1780000: 0x4010004,
  10843. 0x1880000: 0x10000,
  10844. 0x1980000: 0x4010104,
  10845. 0x1a80000: 0x10104,
  10846. 0x1b80000: 0x4000004,
  10847. 0x1c80000: 0x4000104,
  10848. 0x1d80000: 0x4010000,
  10849. 0x1e80000: 0x4,
  10850. 0x1f80000: 0x10100
  10851. },
  10852. {
  10853. 0x0: 0x80401000,
  10854. 0x10000: 0x80001040,
  10855. 0x20000: 0x401040,
  10856. 0x30000: 0x80400000,
  10857. 0x40000: 0x0,
  10858. 0x50000: 0x401000,
  10859. 0x60000: 0x80000040,
  10860. 0x70000: 0x400040,
  10861. 0x80000: 0x80000000,
  10862. 0x90000: 0x400000,
  10863. 0xa0000: 0x40,
  10864. 0xb0000: 0x80001000,
  10865. 0xc0000: 0x80400040,
  10866. 0xd0000: 0x1040,
  10867. 0xe0000: 0x1000,
  10868. 0xf0000: 0x80401040,
  10869. 0x8000: 0x80001040,
  10870. 0x18000: 0x40,
  10871. 0x28000: 0x80400040,
  10872. 0x38000: 0x80001000,
  10873. 0x48000: 0x401000,
  10874. 0x58000: 0x80401040,
  10875. 0x68000: 0x0,
  10876. 0x78000: 0x80400000,
  10877. 0x88000: 0x1000,
  10878. 0x98000: 0x80401000,
  10879. 0xa8000: 0x400000,
  10880. 0xb8000: 0x1040,
  10881. 0xc8000: 0x80000000,
  10882. 0xd8000: 0x400040,
  10883. 0xe8000: 0x401040,
  10884. 0xf8000: 0x80000040,
  10885. 0x100000: 0x400040,
  10886. 0x110000: 0x401000,
  10887. 0x120000: 0x80000040,
  10888. 0x130000: 0x0,
  10889. 0x140000: 0x1040,
  10890. 0x150000: 0x80400040,
  10891. 0x160000: 0x80401000,
  10892. 0x170000: 0x80001040,
  10893. 0x180000: 0x80401040,
  10894. 0x190000: 0x80000000,
  10895. 0x1a0000: 0x80400000,
  10896. 0x1b0000: 0x401040,
  10897. 0x1c0000: 0x80001000,
  10898. 0x1d0000: 0x400000,
  10899. 0x1e0000: 0x40,
  10900. 0x1f0000: 0x1000,
  10901. 0x108000: 0x80400000,
  10902. 0x118000: 0x80401040,
  10903. 0x128000: 0x0,
  10904. 0x138000: 0x401000,
  10905. 0x148000: 0x400040,
  10906. 0x158000: 0x80000000,
  10907. 0x168000: 0x80001040,
  10908. 0x178000: 0x40,
  10909. 0x188000: 0x80000040,
  10910. 0x198000: 0x1000,
  10911. 0x1a8000: 0x80001000,
  10912. 0x1b8000: 0x80400040,
  10913. 0x1c8000: 0x1040,
  10914. 0x1d8000: 0x80401000,
  10915. 0x1e8000: 0x400000,
  10916. 0x1f8000: 0x401040
  10917. },
  10918. {
  10919. 0x0: 0x80,
  10920. 0x1000: 0x1040000,
  10921. 0x2000: 0x40000,
  10922. 0x3000: 0x20000000,
  10923. 0x4000: 0x20040080,
  10924. 0x5000: 0x1000080,
  10925. 0x6000: 0x21000080,
  10926. 0x7000: 0x40080,
  10927. 0x8000: 0x1000000,
  10928. 0x9000: 0x20040000,
  10929. 0xa000: 0x20000080,
  10930. 0xb000: 0x21040080,
  10931. 0xc000: 0x21040000,
  10932. 0xd000: 0x0,
  10933. 0xe000: 0x1040080,
  10934. 0xf000: 0x21000000,
  10935. 0x800: 0x1040080,
  10936. 0x1800: 0x21000080,
  10937. 0x2800: 0x80,
  10938. 0x3800: 0x1040000,
  10939. 0x4800: 0x40000,
  10940. 0x5800: 0x20040080,
  10941. 0x6800: 0x21040000,
  10942. 0x7800: 0x20000000,
  10943. 0x8800: 0x20040000,
  10944. 0x9800: 0x0,
  10945. 0xa800: 0x21040080,
  10946. 0xb800: 0x1000080,
  10947. 0xc800: 0x20000080,
  10948. 0xd800: 0x21000000,
  10949. 0xe800: 0x1000000,
  10950. 0xf800: 0x40080,
  10951. 0x10000: 0x40000,
  10952. 0x11000: 0x80,
  10953. 0x12000: 0x20000000,
  10954. 0x13000: 0x21000080,
  10955. 0x14000: 0x1000080,
  10956. 0x15000: 0x21040000,
  10957. 0x16000: 0x20040080,
  10958. 0x17000: 0x1000000,
  10959. 0x18000: 0x21040080,
  10960. 0x19000: 0x21000000,
  10961. 0x1a000: 0x1040000,
  10962. 0x1b000: 0x20040000,
  10963. 0x1c000: 0x40080,
  10964. 0x1d000: 0x20000080,
  10965. 0x1e000: 0x0,
  10966. 0x1f000: 0x1040080,
  10967. 0x10800: 0x21000080,
  10968. 0x11800: 0x1000000,
  10969. 0x12800: 0x1040000,
  10970. 0x13800: 0x20040080,
  10971. 0x14800: 0x20000000,
  10972. 0x15800: 0x1040080,
  10973. 0x16800: 0x80,
  10974. 0x17800: 0x21040000,
  10975. 0x18800: 0x40080,
  10976. 0x19800: 0x21040080,
  10977. 0x1a800: 0x0,
  10978. 0x1b800: 0x21000000,
  10979. 0x1c800: 0x1000080,
  10980. 0x1d800: 0x40000,
  10981. 0x1e800: 0x20040000,
  10982. 0x1f800: 0x20000080
  10983. },
  10984. {
  10985. 0x0: 0x10000008,
  10986. 0x100: 0x2000,
  10987. 0x200: 0x10200000,
  10988. 0x300: 0x10202008,
  10989. 0x400: 0x10002000,
  10990. 0x500: 0x200000,
  10991. 0x600: 0x200008,
  10992. 0x700: 0x10000000,
  10993. 0x800: 0x0,
  10994. 0x900: 0x10002008,
  10995. 0xa00: 0x202000,
  10996. 0xb00: 0x8,
  10997. 0xc00: 0x10200008,
  10998. 0xd00: 0x202008,
  10999. 0xe00: 0x2008,
  11000. 0xf00: 0x10202000,
  11001. 0x80: 0x10200000,
  11002. 0x180: 0x10202008,
  11003. 0x280: 0x8,
  11004. 0x380: 0x200000,
  11005. 0x480: 0x202008,
  11006. 0x580: 0x10000008,
  11007. 0x680: 0x10002000,
  11008. 0x780: 0x2008,
  11009. 0x880: 0x200008,
  11010. 0x980: 0x2000,
  11011. 0xa80: 0x10002008,
  11012. 0xb80: 0x10200008,
  11013. 0xc80: 0x0,
  11014. 0xd80: 0x10202000,
  11015. 0xe80: 0x202000,
  11016. 0xf80: 0x10000000,
  11017. 0x1000: 0x10002000,
  11018. 0x1100: 0x10200008,
  11019. 0x1200: 0x10202008,
  11020. 0x1300: 0x2008,
  11021. 0x1400: 0x200000,
  11022. 0x1500: 0x10000000,
  11023. 0x1600: 0x10000008,
  11024. 0x1700: 0x202000,
  11025. 0x1800: 0x202008,
  11026. 0x1900: 0x0,
  11027. 0x1a00: 0x8,
  11028. 0x1b00: 0x10200000,
  11029. 0x1c00: 0x2000,
  11030. 0x1d00: 0x10002008,
  11031. 0x1e00: 0x10202000,
  11032. 0x1f00: 0x200008,
  11033. 0x1080: 0x8,
  11034. 0x1180: 0x202000,
  11035. 0x1280: 0x200000,
  11036. 0x1380: 0x10000008,
  11037. 0x1480: 0x10002000,
  11038. 0x1580: 0x2008,
  11039. 0x1680: 0x10202008,
  11040. 0x1780: 0x10200000,
  11041. 0x1880: 0x10202000,
  11042. 0x1980: 0x10200008,
  11043. 0x1a80: 0x2000,
  11044. 0x1b80: 0x202008,
  11045. 0x1c80: 0x200008,
  11046. 0x1d80: 0x0,
  11047. 0x1e80: 0x10000000,
  11048. 0x1f80: 0x10002008
  11049. },
  11050. {
  11051. 0x0: 0x100000,
  11052. 0x10: 0x2000401,
  11053. 0x20: 0x400,
  11054. 0x30: 0x100401,
  11055. 0x40: 0x2100401,
  11056. 0x50: 0x0,
  11057. 0x60: 0x1,
  11058. 0x70: 0x2100001,
  11059. 0x80: 0x2000400,
  11060. 0x90: 0x100001,
  11061. 0xa0: 0x2000001,
  11062. 0xb0: 0x2100400,
  11063. 0xc0: 0x2100000,
  11064. 0xd0: 0x401,
  11065. 0xe0: 0x100400,
  11066. 0xf0: 0x2000000,
  11067. 0x8: 0x2100001,
  11068. 0x18: 0x0,
  11069. 0x28: 0x2000401,
  11070. 0x38: 0x2100400,
  11071. 0x48: 0x100000,
  11072. 0x58: 0x2000001,
  11073. 0x68: 0x2000000,
  11074. 0x78: 0x401,
  11075. 0x88: 0x100401,
  11076. 0x98: 0x2000400,
  11077. 0xa8: 0x2100000,
  11078. 0xb8: 0x100001,
  11079. 0xc8: 0x400,
  11080. 0xd8: 0x2100401,
  11081. 0xe8: 0x1,
  11082. 0xf8: 0x100400,
  11083. 0x100: 0x2000000,
  11084. 0x110: 0x100000,
  11085. 0x120: 0x2000401,
  11086. 0x130: 0x2100001,
  11087. 0x140: 0x100001,
  11088. 0x150: 0x2000400,
  11089. 0x160: 0x2100400,
  11090. 0x170: 0x100401,
  11091. 0x180: 0x401,
  11092. 0x190: 0x2100401,
  11093. 0x1a0: 0x100400,
  11094. 0x1b0: 0x1,
  11095. 0x1c0: 0x0,
  11096. 0x1d0: 0x2100000,
  11097. 0x1e0: 0x2000001,
  11098. 0x1f0: 0x400,
  11099. 0x108: 0x100400,
  11100. 0x118: 0x2000401,
  11101. 0x128: 0x2100001,
  11102. 0x138: 0x1,
  11103. 0x148: 0x2000000,
  11104. 0x158: 0x100000,
  11105. 0x168: 0x401,
  11106. 0x178: 0x2100400,
  11107. 0x188: 0x2000001,
  11108. 0x198: 0x2100000,
  11109. 0x1a8: 0x0,
  11110. 0x1b8: 0x2100401,
  11111. 0x1c8: 0x100401,
  11112. 0x1d8: 0x400,
  11113. 0x1e8: 0x2000400,
  11114. 0x1f8: 0x100001
  11115. },
  11116. {
  11117. 0x0: 0x8000820,
  11118. 0x1: 0x20000,
  11119. 0x2: 0x8000000,
  11120. 0x3: 0x20,
  11121. 0x4: 0x20020,
  11122. 0x5: 0x8020820,
  11123. 0x6: 0x8020800,
  11124. 0x7: 0x800,
  11125. 0x8: 0x8020000,
  11126. 0x9: 0x8000800,
  11127. 0xa: 0x20800,
  11128. 0xb: 0x8020020,
  11129. 0xc: 0x820,
  11130. 0xd: 0x0,
  11131. 0xe: 0x8000020,
  11132. 0xf: 0x20820,
  11133. 0x80000000: 0x800,
  11134. 0x80000001: 0x8020820,
  11135. 0x80000002: 0x8000820,
  11136. 0x80000003: 0x8000000,
  11137. 0x80000004: 0x8020000,
  11138. 0x80000005: 0x20800,
  11139. 0x80000006: 0x20820,
  11140. 0x80000007: 0x20,
  11141. 0x80000008: 0x8000020,
  11142. 0x80000009: 0x820,
  11143. 0x8000000a: 0x20020,
  11144. 0x8000000b: 0x8020800,
  11145. 0x8000000c: 0x0,
  11146. 0x8000000d: 0x8020020,
  11147. 0x8000000e: 0x8000800,
  11148. 0x8000000f: 0x20000,
  11149. 0x10: 0x20820,
  11150. 0x11: 0x8020800,
  11151. 0x12: 0x20,
  11152. 0x13: 0x800,
  11153. 0x14: 0x8000800,
  11154. 0x15: 0x8000020,
  11155. 0x16: 0x8020020,
  11156. 0x17: 0x20000,
  11157. 0x18: 0x0,
  11158. 0x19: 0x20020,
  11159. 0x1a: 0x8020000,
  11160. 0x1b: 0x8000820,
  11161. 0x1c: 0x8020820,
  11162. 0x1d: 0x20800,
  11163. 0x1e: 0x820,
  11164. 0x1f: 0x8000000,
  11165. 0x80000010: 0x20000,
  11166. 0x80000011: 0x800,
  11167. 0x80000012: 0x8020020,
  11168. 0x80000013: 0x20820,
  11169. 0x80000014: 0x20,
  11170. 0x80000015: 0x8020000,
  11171. 0x80000016: 0x8000000,
  11172. 0x80000017: 0x8000820,
  11173. 0x80000018: 0x8020820,
  11174. 0x80000019: 0x8000020,
  11175. 0x8000001a: 0x8000800,
  11176. 0x8000001b: 0x0,
  11177. 0x8000001c: 0x20800,
  11178. 0x8000001d: 0x820,
  11179. 0x8000001e: 0x20020,
  11180. 0x8000001f: 0x8020800
  11181. }
  11182. ];
  11183. // Masks that select the SBOX input
  11184. var SBOX_MASK = [
  11185. 0xf8000001, 0x1f800000, 0x01f80000, 0x001f8000,
  11186. 0x0001f800, 0x00001f80, 0x000001f8, 0x8000001f
  11187. ];
  11188. /**
  11189. * DES block cipher algorithm.
  11190. */
  11191. var DES = C_algo.DES = BlockCipher.extend({
  11192. _doReset: function () {
  11193. // Shortcuts
  11194. var key = this._key;
  11195. var keyWords = key.words;
  11196. // Select 56 bits according to PC1
  11197. var keyBits = [];
  11198. for (var i = 0; i < 56; i++) {
  11199. var keyBitPos = PC1[i] - 1;
  11200. keyBits[i] = (keyWords[keyBitPos >>> 5] >>> (31 - keyBitPos % 32)) & 1;
  11201. }
  11202. // Assemble 16 subkeys
  11203. var subKeys = this._subKeys = [];
  11204. for (var nSubKey = 0; nSubKey < 16; nSubKey++) {
  11205. // Create subkey
  11206. var subKey = subKeys[nSubKey] = [];
  11207. // Shortcut
  11208. var bitShift = BIT_SHIFTS[nSubKey];
  11209. // Select 48 bits according to PC2
  11210. for (var i = 0; i < 24; i++) {
  11211. // Select from the left 28 key bits
  11212. subKey[(i / 6) | 0] |= keyBits[((PC2[i] - 1) + bitShift) % 28] << (31 - i % 6);
  11213. // Select from the right 28 key bits
  11214. subKey[4 + ((i / 6) | 0)] |= keyBits[28 + (((PC2[i + 24] - 1) + bitShift) % 28)] << (31 - i % 6);
  11215. }
  11216. // Since each subkey is applied to an expanded 32-bit input,
  11217. // the subkey can be broken into 8 values scaled to 32-bits,
  11218. // which allows the key to be used without expansion
  11219. subKey[0] = (subKey[0] << 1) | (subKey[0] >>> 31);
  11220. for (var i = 1; i < 7; i++) {
  11221. subKey[i] = subKey[i] >>> ((i - 1) * 4 + 3);
  11222. }
  11223. subKey[7] = (subKey[7] << 5) | (subKey[7] >>> 27);
  11224. }
  11225. // Compute inverse subkeys
  11226. var invSubKeys = this._invSubKeys = [];
  11227. for (var i = 0; i < 16; i++) {
  11228. invSubKeys[i] = subKeys[15 - i];
  11229. }
  11230. },
  11231. encryptBlock: function (M, offset) {
  11232. this._doCryptBlock(M, offset, this._subKeys);
  11233. },
  11234. decryptBlock: function (M, offset) {
  11235. this._doCryptBlock(M, offset, this._invSubKeys);
  11236. },
  11237. _doCryptBlock: function (M, offset, subKeys) {
  11238. // Get input
  11239. this._lBlock = M[offset];
  11240. this._rBlock = M[offset + 1];
  11241. // Initial permutation
  11242. exchangeLR.call(this, 4, 0x0f0f0f0f);
  11243. exchangeLR.call(this, 16, 0x0000ffff);
  11244. exchangeRL.call(this, 2, 0x33333333);
  11245. exchangeRL.call(this, 8, 0x00ff00ff);
  11246. exchangeLR.call(this, 1, 0x55555555);
  11247. // Rounds
  11248. for (var round = 0; round < 16; round++) {
  11249. // Shortcuts
  11250. var subKey = subKeys[round];
  11251. var lBlock = this._lBlock;
  11252. var rBlock = this._rBlock;
  11253. // Feistel function
  11254. var f = 0;
  11255. for (var i = 0; i < 8; i++) {
  11256. f |= SBOX_P[i][((rBlock ^ subKey[i]) & SBOX_MASK[i]) >>> 0];
  11257. }
  11258. this._lBlock = rBlock;
  11259. this._rBlock = lBlock ^ f;
  11260. }
  11261. // Undo swap from last round
  11262. var t = this._lBlock;
  11263. this._lBlock = this._rBlock;
  11264. this._rBlock = t;
  11265. // Final permutation
  11266. exchangeLR.call(this, 1, 0x55555555);
  11267. exchangeRL.call(this, 8, 0x00ff00ff);
  11268. exchangeRL.call(this, 2, 0x33333333);
  11269. exchangeLR.call(this, 16, 0x0000ffff);
  11270. exchangeLR.call(this, 4, 0x0f0f0f0f);
  11271. // Set output
  11272. M[offset] = this._lBlock;
  11273. M[offset + 1] = this._rBlock;
  11274. },
  11275. keySize: 64/32,
  11276. ivSize: 64/32,
  11277. blockSize: 64/32
  11278. });
  11279. // Swap bits across the left and right words
  11280. function exchangeLR(offset, mask) {
  11281. var t = ((this._lBlock >>> offset) ^ this._rBlock) & mask;
  11282. this._rBlock ^= t;
  11283. this._lBlock ^= t << offset;
  11284. }
  11285. function exchangeRL(offset, mask) {
  11286. var t = ((this._rBlock >>> offset) ^ this._lBlock) & mask;
  11287. this._lBlock ^= t;
  11288. this._rBlock ^= t << offset;
  11289. }
  11290. /**
  11291. * Shortcut functions to the cipher's object interface.
  11292. *
  11293. * @example
  11294. *
  11295. * var ciphertext = CryptoJS.DES.encrypt(message, key, cfg);
  11296. * var plaintext = CryptoJS.DES.decrypt(ciphertext, key, cfg);
  11297. */
  11298. C.DES = BlockCipher._createHelper(DES);
  11299. /**
  11300. * Triple-DES block cipher algorithm.
  11301. */
  11302. var TripleDES = C_algo.TripleDES = BlockCipher.extend({
  11303. _doReset: function () {
  11304. // Shortcuts
  11305. var key = this._key;
  11306. var keyWords = key.words;
  11307. // Create DES instances
  11308. this._des1 = DES.createEncryptor(WordArray.create(keyWords.slice(0, 2)));
  11309. this._des2 = DES.createEncryptor(WordArray.create(keyWords.slice(2, 4)));
  11310. this._des3 = DES.createEncryptor(WordArray.create(keyWords.slice(4, 6)));
  11311. },
  11312. encryptBlock: function (M, offset) {
  11313. this._des1.encryptBlock(M, offset);
  11314. this._des2.decryptBlock(M, offset);
  11315. this._des3.encryptBlock(M, offset);
  11316. },
  11317. decryptBlock: function (M, offset) {
  11318. this._des3.decryptBlock(M, offset);
  11319. this._des2.encryptBlock(M, offset);
  11320. this._des1.decryptBlock(M, offset);
  11321. },
  11322. keySize: 192/32,
  11323. ivSize: 64/32,
  11324. blockSize: 64/32
  11325. });
  11326. /**
  11327. * Shortcut functions to the cipher's object interface.
  11328. *
  11329. * @example
  11330. *
  11331. * var ciphertext = CryptoJS.TripleDES.encrypt(message, key, cfg);
  11332. * var plaintext = CryptoJS.TripleDES.decrypt(ciphertext, key, cfg);
  11333. */
  11334. C.TripleDES = BlockCipher._createHelper(TripleDES);
  11335. }());
  11336. return CryptoJS.TripleDES;
  11337. }));
  11338. },{"./cipher-core":52,"./core":53,"./enc-base64":54,"./evpkdf":56,"./md5":61}],84:[function(require,module,exports){
  11339. ;(function (root, factory) {
  11340. if (typeof exports === "object") {
  11341. // CommonJS
  11342. module.exports = exports = factory(require("./core"));
  11343. }
  11344. else if (typeof define === "function" && define.amd) {
  11345. // AMD
  11346. define(["./core"], factory);
  11347. }
  11348. else {
  11349. // Global (browser)
  11350. factory(root.CryptoJS);
  11351. }
  11352. }(this, function (CryptoJS) {
  11353. (function (undefined) {
  11354. // Shortcuts
  11355. var C = CryptoJS;
  11356. var C_lib = C.lib;
  11357. var Base = C_lib.Base;
  11358. var X32WordArray = C_lib.WordArray;
  11359. /**
  11360. * x64 namespace.
  11361. */
  11362. var C_x64 = C.x64 = {};
  11363. /**
  11364. * A 64-bit word.
  11365. */
  11366. var X64Word = C_x64.Word = Base.extend({
  11367. /**
  11368. * Initializes a newly created 64-bit word.
  11369. *
  11370. * @param {number} high The high 32 bits.
  11371. * @param {number} low The low 32 bits.
  11372. *
  11373. * @example
  11374. *
  11375. * var x64Word = CryptoJS.x64.Word.create(0x00010203, 0x04050607);
  11376. */
  11377. init: function (high, low) {
  11378. this.high = high;
  11379. this.low = low;
  11380. }
  11381. /**
  11382. * Bitwise NOTs this word.
  11383. *
  11384. * @return {X64Word} A new x64-Word object after negating.
  11385. *
  11386. * @example
  11387. *
  11388. * var negated = x64Word.not();
  11389. */
  11390. // not: function () {
  11391. // var high = ~this.high;
  11392. // var low = ~this.low;
  11393. // return X64Word.create(high, low);
  11394. // },
  11395. /**
  11396. * Bitwise ANDs this word with the passed word.
  11397. *
  11398. * @param {X64Word} word The x64-Word to AND with this word.
  11399. *
  11400. * @return {X64Word} A new x64-Word object after ANDing.
  11401. *
  11402. * @example
  11403. *
  11404. * var anded = x64Word.and(anotherX64Word);
  11405. */
  11406. // and: function (word) {
  11407. // var high = this.high & word.high;
  11408. // var low = this.low & word.low;
  11409. // return X64Word.create(high, low);
  11410. // },
  11411. /**
  11412. * Bitwise ORs this word with the passed word.
  11413. *
  11414. * @param {X64Word} word The x64-Word to OR with this word.
  11415. *
  11416. * @return {X64Word} A new x64-Word object after ORing.
  11417. *
  11418. * @example
  11419. *
  11420. * var ored = x64Word.or(anotherX64Word);
  11421. */
  11422. // or: function (word) {
  11423. // var high = this.high | word.high;
  11424. // var low = this.low | word.low;
  11425. // return X64Word.create(high, low);
  11426. // },
  11427. /**
  11428. * Bitwise XORs this word with the passed word.
  11429. *
  11430. * @param {X64Word} word The x64-Word to XOR with this word.
  11431. *
  11432. * @return {X64Word} A new x64-Word object after XORing.
  11433. *
  11434. * @example
  11435. *
  11436. * var xored = x64Word.xor(anotherX64Word);
  11437. */
  11438. // xor: function (word) {
  11439. // var high = this.high ^ word.high;
  11440. // var low = this.low ^ word.low;
  11441. // return X64Word.create(high, low);
  11442. // },
  11443. /**
  11444. * Shifts this word n bits to the left.
  11445. *
  11446. * @param {number} n The number of bits to shift.
  11447. *
  11448. * @return {X64Word} A new x64-Word object after shifting.
  11449. *
  11450. * @example
  11451. *
  11452. * var shifted = x64Word.shiftL(25);
  11453. */
  11454. // shiftL: function (n) {
  11455. // if (n < 32) {
  11456. // var high = (this.high << n) | (this.low >>> (32 - n));
  11457. // var low = this.low << n;
  11458. // } else {
  11459. // var high = this.low << (n - 32);
  11460. // var low = 0;
  11461. // }
  11462. // return X64Word.create(high, low);
  11463. // },
  11464. /**
  11465. * Shifts this word n bits to the right.
  11466. *
  11467. * @param {number} n The number of bits to shift.
  11468. *
  11469. * @return {X64Word} A new x64-Word object after shifting.
  11470. *
  11471. * @example
  11472. *
  11473. * var shifted = x64Word.shiftR(7);
  11474. */
  11475. // shiftR: function (n) {
  11476. // if (n < 32) {
  11477. // var low = (this.low >>> n) | (this.high << (32 - n));
  11478. // var high = this.high >>> n;
  11479. // } else {
  11480. // var low = this.high >>> (n - 32);
  11481. // var high = 0;
  11482. // }
  11483. // return X64Word.create(high, low);
  11484. // },
  11485. /**
  11486. * Rotates this word n bits to the left.
  11487. *
  11488. * @param {number} n The number of bits to rotate.
  11489. *
  11490. * @return {X64Word} A new x64-Word object after rotating.
  11491. *
  11492. * @example
  11493. *
  11494. * var rotated = x64Word.rotL(25);
  11495. */
  11496. // rotL: function (n) {
  11497. // return this.shiftL(n).or(this.shiftR(64 - n));
  11498. // },
  11499. /**
  11500. * Rotates this word n bits to the right.
  11501. *
  11502. * @param {number} n The number of bits to rotate.
  11503. *
  11504. * @return {X64Word} A new x64-Word object after rotating.
  11505. *
  11506. * @example
  11507. *
  11508. * var rotated = x64Word.rotR(7);
  11509. */
  11510. // rotR: function (n) {
  11511. // return this.shiftR(n).or(this.shiftL(64 - n));
  11512. // },
  11513. /**
  11514. * Adds this word with the passed word.
  11515. *
  11516. * @param {X64Word} word The x64-Word to add with this word.
  11517. *
  11518. * @return {X64Word} A new x64-Word object after adding.
  11519. *
  11520. * @example
  11521. *
  11522. * var added = x64Word.add(anotherX64Word);
  11523. */
  11524. // add: function (word) {
  11525. // var low = (this.low + word.low) | 0;
  11526. // var carry = (low >>> 0) < (this.low >>> 0) ? 1 : 0;
  11527. // var high = (this.high + word.high + carry) | 0;
  11528. // return X64Word.create(high, low);
  11529. // }
  11530. });
  11531. /**
  11532. * An array of 64-bit words.
  11533. *
  11534. * @property {Array} words The array of CryptoJS.x64.Word objects.
  11535. * @property {number} sigBytes The number of significant bytes in this word array.
  11536. */
  11537. var X64WordArray = C_x64.WordArray = Base.extend({
  11538. /**
  11539. * Initializes a newly created word array.
  11540. *
  11541. * @param {Array} words (Optional) An array of CryptoJS.x64.Word objects.
  11542. * @param {number} sigBytes (Optional) The number of significant bytes in the words.
  11543. *
  11544. * @example
  11545. *
  11546. * var wordArray = CryptoJS.x64.WordArray.create();
  11547. *
  11548. * var wordArray = CryptoJS.x64.WordArray.create([
  11549. * CryptoJS.x64.Word.create(0x00010203, 0x04050607),
  11550. * CryptoJS.x64.Word.create(0x18191a1b, 0x1c1d1e1f)
  11551. * ]);
  11552. *
  11553. * var wordArray = CryptoJS.x64.WordArray.create([
  11554. * CryptoJS.x64.Word.create(0x00010203, 0x04050607),
  11555. * CryptoJS.x64.Word.create(0x18191a1b, 0x1c1d1e1f)
  11556. * ], 10);
  11557. */
  11558. init: function (words, sigBytes) {
  11559. words = this.words = words || [];
  11560. if (sigBytes != undefined) {
  11561. this.sigBytes = sigBytes;
  11562. } else {
  11563. this.sigBytes = words.length * 8;
  11564. }
  11565. },
  11566. /**
  11567. * Converts this 64-bit word array to a 32-bit word array.
  11568. *
  11569. * @return {CryptoJS.lib.WordArray} This word array's data as a 32-bit word array.
  11570. *
  11571. * @example
  11572. *
  11573. * var x32WordArray = x64WordArray.toX32();
  11574. */
  11575. toX32: function () {
  11576. // Shortcuts
  11577. var x64Words = this.words;
  11578. var x64WordsLength = x64Words.length;
  11579. // Convert
  11580. var x32Words = [];
  11581. for (var i = 0; i < x64WordsLength; i++) {
  11582. var x64Word = x64Words[i];
  11583. x32Words.push(x64Word.high);
  11584. x32Words.push(x64Word.low);
  11585. }
  11586. return X32WordArray.create(x32Words, this.sigBytes);
  11587. },
  11588. /**
  11589. * Creates a copy of this word array.
  11590. *
  11591. * @return {X64WordArray} The clone.
  11592. *
  11593. * @example
  11594. *
  11595. * var clone = x64WordArray.clone();
  11596. */
  11597. clone: function () {
  11598. var clone = Base.clone.call(this);
  11599. // Clone "words" array
  11600. var words = clone.words = this.words.slice(0);
  11601. // Clone each X64Word object
  11602. var wordsLength = words.length;
  11603. for (var i = 0; i < wordsLength; i++) {
  11604. words[i] = words[i].clone();
  11605. }
  11606. return clone;
  11607. }
  11608. });
  11609. }());
  11610. return CryptoJS;
  11611. }));
  11612. },{"./core":53}],85:[function(require,module,exports){
  11613. /*! https://mths.be/utf8js v2.1.2 by @mathias */
  11614. ;(function(root) {
  11615. // Detect free variables `exports`
  11616. var freeExports = typeof exports == 'object' && exports;
  11617. // Detect free variable `module`
  11618. var freeModule = typeof module == 'object' && module &&
  11619. module.exports == freeExports && module;
  11620. // Detect free variable `global`, from Node.js or Browserified code,
  11621. // and use it as `root`
  11622. var freeGlobal = typeof global == 'object' && global;
  11623. if (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal) {
  11624. root = freeGlobal;
  11625. }
  11626. /*--------------------------------------------------------------------------*/
  11627. var stringFromCharCode = String.fromCharCode;
  11628. // Taken from https://mths.be/punycode
  11629. function ucs2decode(string) {
  11630. var output = [];
  11631. var counter = 0;
  11632. var length = string.length;
  11633. var value;
  11634. var extra;
  11635. while (counter < length) {
  11636. value = string.charCodeAt(counter++);
  11637. if (value >= 0xD800 && value <= 0xDBFF && counter < length) {
  11638. // high surrogate, and there is a next character
  11639. extra = string.charCodeAt(counter++);
  11640. if ((extra & 0xFC00) == 0xDC00) { // low surrogate
  11641. output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000);
  11642. } else {
  11643. // unmatched surrogate; only append this code unit, in case the next
  11644. // code unit is the high surrogate of a surrogate pair
  11645. output.push(value);
  11646. counter--;
  11647. }
  11648. } else {
  11649. output.push(value);
  11650. }
  11651. }
  11652. return output;
  11653. }
  11654. // Taken from https://mths.be/punycode
  11655. function ucs2encode(array) {
  11656. var length = array.length;
  11657. var index = -1;
  11658. var value;
  11659. var output = '';
  11660. while (++index < length) {
  11661. value = array[index];
  11662. if (value > 0xFFFF) {
  11663. value -= 0x10000;
  11664. output += stringFromCharCode(value >>> 10 & 0x3FF | 0xD800);
  11665. value = 0xDC00 | value & 0x3FF;
  11666. }
  11667. output += stringFromCharCode(value);
  11668. }
  11669. return output;
  11670. }
  11671. function checkScalarValue(codePoint) {
  11672. if (codePoint >= 0xD800 && codePoint <= 0xDFFF) {
  11673. throw Error(
  11674. 'Lone surrogate U+' + codePoint.toString(16).toUpperCase() +
  11675. ' is not a scalar value'
  11676. );
  11677. }
  11678. }
  11679. /*--------------------------------------------------------------------------*/
  11680. function createByte(codePoint, shift) {
  11681. return stringFromCharCode(((codePoint >> shift) & 0x3F) | 0x80);
  11682. }
  11683. function encodeCodePoint(codePoint) {
  11684. if ((codePoint & 0xFFFFFF80) == 0) { // 1-byte sequence
  11685. return stringFromCharCode(codePoint);
  11686. }
  11687. var symbol = '';
  11688. if ((codePoint & 0xFFFFF800) == 0) { // 2-byte sequence
  11689. symbol = stringFromCharCode(((codePoint >> 6) & 0x1F) | 0xC0);
  11690. }
  11691. else if ((codePoint & 0xFFFF0000) == 0) { // 3-byte sequence
  11692. checkScalarValue(codePoint);
  11693. symbol = stringFromCharCode(((codePoint >> 12) & 0x0F) | 0xE0);
  11694. symbol += createByte(codePoint, 6);
  11695. }
  11696. else if ((codePoint & 0xFFE00000) == 0) { // 4-byte sequence
  11697. symbol = stringFromCharCode(((codePoint >> 18) & 0x07) | 0xF0);
  11698. symbol += createByte(codePoint, 12);
  11699. symbol += createByte(codePoint, 6);
  11700. }
  11701. symbol += stringFromCharCode((codePoint & 0x3F) | 0x80);
  11702. return symbol;
  11703. }
  11704. function utf8encode(string) {
  11705. var codePoints = ucs2decode(string);
  11706. var length = codePoints.length;
  11707. var index = -1;
  11708. var codePoint;
  11709. var byteString = '';
  11710. while (++index < length) {
  11711. codePoint = codePoints[index];
  11712. byteString += encodeCodePoint(codePoint);
  11713. }
  11714. return byteString;
  11715. }
  11716. /*--------------------------------------------------------------------------*/
  11717. function readContinuationByte() {
  11718. if (byteIndex >= byteCount) {
  11719. throw Error('Invalid byte index');
  11720. }
  11721. var continuationByte = byteArray[byteIndex] & 0xFF;
  11722. byteIndex++;
  11723. if ((continuationByte & 0xC0) == 0x80) {
  11724. return continuationByte & 0x3F;
  11725. }
  11726. // If we end up here, it’s not a continuation byte
  11727. throw Error('Invalid continuation byte');
  11728. }
  11729. function decodeSymbol() {
  11730. var byte1;
  11731. var byte2;
  11732. var byte3;
  11733. var byte4;
  11734. var codePoint;
  11735. if (byteIndex > byteCount) {
  11736. throw Error('Invalid byte index');
  11737. }
  11738. if (byteIndex == byteCount) {
  11739. return false;
  11740. }
  11741. // Read first byte
  11742. byte1 = byteArray[byteIndex] & 0xFF;
  11743. byteIndex++;
  11744. // 1-byte sequence (no continuation bytes)
  11745. if ((byte1 & 0x80) == 0) {
  11746. return byte1;
  11747. }
  11748. // 2-byte sequence
  11749. if ((byte1 & 0xE0) == 0xC0) {
  11750. byte2 = readContinuationByte();
  11751. codePoint = ((byte1 & 0x1F) << 6) | byte2;
  11752. if (codePoint >= 0x80) {
  11753. return codePoint;
  11754. } else {
  11755. throw Error('Invalid continuation byte');
  11756. }
  11757. }
  11758. // 3-byte sequence (may include unpaired surrogates)
  11759. if ((byte1 & 0xF0) == 0xE0) {
  11760. byte2 = readContinuationByte();
  11761. byte3 = readContinuationByte();
  11762. codePoint = ((byte1 & 0x0F) << 12) | (byte2 << 6) | byte3;
  11763. if (codePoint >= 0x0800) {
  11764. checkScalarValue(codePoint);
  11765. return codePoint;
  11766. } else {
  11767. throw Error('Invalid continuation byte');
  11768. }
  11769. }
  11770. // 4-byte sequence
  11771. if ((byte1 & 0xF8) == 0xF0) {
  11772. byte2 = readContinuationByte();
  11773. byte3 = readContinuationByte();
  11774. byte4 = readContinuationByte();
  11775. codePoint = ((byte1 & 0x07) << 0x12) | (byte2 << 0x0C) |
  11776. (byte3 << 0x06) | byte4;
  11777. if (codePoint >= 0x010000 && codePoint <= 0x10FFFF) {
  11778. return codePoint;
  11779. }
  11780. }
  11781. throw Error('Invalid UTF-8 detected');
  11782. }
  11783. var byteArray;
  11784. var byteCount;
  11785. var byteIndex;
  11786. function utf8decode(byteString) {
  11787. byteArray = ucs2decode(byteString);
  11788. byteCount = byteArray.length;
  11789. byteIndex = 0;
  11790. var codePoints = [];
  11791. var tmp;
  11792. while ((tmp = decodeSymbol()) !== false) {
  11793. codePoints.push(tmp);
  11794. }
  11795. return ucs2encode(codePoints);
  11796. }
  11797. /*--------------------------------------------------------------------------*/
  11798. var utf8 = {
  11799. 'version': '2.1.2',
  11800. 'encode': utf8encode,
  11801. 'decode': utf8decode
  11802. };
  11803. // Some AMD build optimizers, like r.js, check for specific condition patterns
  11804. // like the following:
  11805. if (
  11806. typeof define == 'function' &&
  11807. typeof define.amd == 'object' &&
  11808. define.amd
  11809. ) {
  11810. define(function() {
  11811. return utf8;
  11812. });
  11813. } else if (freeExports && !freeExports.nodeType) {
  11814. if (freeModule) { // in Node.js or RingoJS v0.8.0+
  11815. freeModule.exports = utf8;
  11816. } else { // in Narwhal or RingoJS v0.7.0-
  11817. var object = {};
  11818. var hasOwnProperty = object.hasOwnProperty;
  11819. for (var key in utf8) {
  11820. hasOwnProperty.call(utf8, key) && (freeExports[key] = utf8[key]);
  11821. }
  11822. }
  11823. } else { // in Rhino or a web browser
  11824. root.utf8 = utf8;
  11825. }
  11826. }(this));
  11827. },{}],86:[function(require,module,exports){
  11828. module.exports = XMLHttpRequest;
  11829. },{}],"bignumber.js":[function(require,module,exports){
  11830. 'use strict';
  11831. module.exports = BigNumber; // jshint ignore:line
  11832. },{}],"web3":[function(require,module,exports){
  11833. var Web3 = require('./lib/web3');
  11834. // don't override global variable
  11835. if (typeof window !== 'undefined' && typeof window.Web3 === 'undefined') {
  11836. window.Web3 = Web3;
  11837. }
  11838. module.exports = Web3;
  11839. },{"./lib/web3":22}]},{},["web3"])
  11840. //# sourceMappingURL=web3-light.js.map