web3.js 393 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646
  1. require=(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
  2. module.exports=[
  3. {
  4. "constant": true,
  5. "inputs": [
  6. {
  7. "name": "_owner",
  8. "type": "address"
  9. }
  10. ],
  11. "name": "name",
  12. "outputs": [
  13. {
  14. "name": "o_name",
  15. "type": "bytes32"
  16. }
  17. ],
  18. "type": "function"
  19. },
  20. {
  21. "constant": true,
  22. "inputs": [
  23. {
  24. "name": "_name",
  25. "type": "bytes32"
  26. }
  27. ],
  28. "name": "owner",
  29. "outputs": [
  30. {
  31. "name": "",
  32. "type": "address"
  33. }
  34. ],
  35. "type": "function"
  36. },
  37. {
  38. "constant": true,
  39. "inputs": [
  40. {
  41. "name": "_name",
  42. "type": "bytes32"
  43. }
  44. ],
  45. "name": "content",
  46. "outputs": [
  47. {
  48. "name": "",
  49. "type": "bytes32"
  50. }
  51. ],
  52. "type": "function"
  53. },
  54. {
  55. "constant": true,
  56. "inputs": [
  57. {
  58. "name": "_name",
  59. "type": "bytes32"
  60. }
  61. ],
  62. "name": "addr",
  63. "outputs": [
  64. {
  65. "name": "",
  66. "type": "address"
  67. }
  68. ],
  69. "type": "function"
  70. },
  71. {
  72. "constant": false,
  73. "inputs": [
  74. {
  75. "name": "_name",
  76. "type": "bytes32"
  77. }
  78. ],
  79. "name": "reserve",
  80. "outputs": [],
  81. "type": "function"
  82. },
  83. {
  84. "constant": true,
  85. "inputs": [
  86. {
  87. "name": "_name",
  88. "type": "bytes32"
  89. }
  90. ],
  91. "name": "subRegistrar",
  92. "outputs": [
  93. {
  94. "name": "",
  95. "type": "address"
  96. }
  97. ],
  98. "type": "function"
  99. },
  100. {
  101. "constant": false,
  102. "inputs": [
  103. {
  104. "name": "_name",
  105. "type": "bytes32"
  106. },
  107. {
  108. "name": "_newOwner",
  109. "type": "address"
  110. }
  111. ],
  112. "name": "transfer",
  113. "outputs": [],
  114. "type": "function"
  115. },
  116. {
  117. "constant": false,
  118. "inputs": [
  119. {
  120. "name": "_name",
  121. "type": "bytes32"
  122. },
  123. {
  124. "name": "_registrar",
  125. "type": "address"
  126. }
  127. ],
  128. "name": "setSubRegistrar",
  129. "outputs": [],
  130. "type": "function"
  131. },
  132. {
  133. "constant": false,
  134. "inputs": [],
  135. "name": "Registrar",
  136. "outputs": [],
  137. "type": "function"
  138. },
  139. {
  140. "constant": false,
  141. "inputs": [
  142. {
  143. "name": "_name",
  144. "type": "bytes32"
  145. },
  146. {
  147. "name": "_a",
  148. "type": "address"
  149. },
  150. {
  151. "name": "_primary",
  152. "type": "bool"
  153. }
  154. ],
  155. "name": "setAddress",
  156. "outputs": [],
  157. "type": "function"
  158. },
  159. {
  160. "constant": false,
  161. "inputs": [
  162. {
  163. "name": "_name",
  164. "type": "bytes32"
  165. },
  166. {
  167. "name": "_content",
  168. "type": "bytes32"
  169. }
  170. ],
  171. "name": "setContent",
  172. "outputs": [],
  173. "type": "function"
  174. },
  175. {
  176. "constant": false,
  177. "inputs": [
  178. {
  179. "name": "_name",
  180. "type": "bytes32"
  181. }
  182. ],
  183. "name": "disown",
  184. "outputs": [],
  185. "type": "function"
  186. },
  187. {
  188. "anonymous": false,
  189. "inputs": [
  190. {
  191. "indexed": true,
  192. "name": "_name",
  193. "type": "bytes32"
  194. },
  195. {
  196. "indexed": false,
  197. "name": "_winner",
  198. "type": "address"
  199. }
  200. ],
  201. "name": "AuctionEnded",
  202. "type": "event"
  203. },
  204. {
  205. "anonymous": false,
  206. "inputs": [
  207. {
  208. "indexed": true,
  209. "name": "_name",
  210. "type": "bytes32"
  211. },
  212. {
  213. "indexed": false,
  214. "name": "_bidder",
  215. "type": "address"
  216. },
  217. {
  218. "indexed": false,
  219. "name": "_value",
  220. "type": "uint256"
  221. }
  222. ],
  223. "name": "NewBid",
  224. "type": "event"
  225. },
  226. {
  227. "anonymous": false,
  228. "inputs": [
  229. {
  230. "indexed": true,
  231. "name": "name",
  232. "type": "bytes32"
  233. }
  234. ],
  235. "name": "Changed",
  236. "type": "event"
  237. },
  238. {
  239. "anonymous": false,
  240. "inputs": [
  241. {
  242. "indexed": true,
  243. "name": "name",
  244. "type": "bytes32"
  245. },
  246. {
  247. "indexed": true,
  248. "name": "addr",
  249. "type": "address"
  250. }
  251. ],
  252. "name": "PrimaryChanged",
  253. "type": "event"
  254. }
  255. ]
  256. },{}],2:[function(require,module,exports){
  257. module.exports=[
  258. {
  259. "constant": true,
  260. "inputs": [
  261. {
  262. "name": "_name",
  263. "type": "bytes32"
  264. }
  265. ],
  266. "name": "owner",
  267. "outputs": [
  268. {
  269. "name": "",
  270. "type": "address"
  271. }
  272. ],
  273. "type": "function"
  274. },
  275. {
  276. "constant": false,
  277. "inputs": [
  278. {
  279. "name": "_name",
  280. "type": "bytes32"
  281. },
  282. {
  283. "name": "_refund",
  284. "type": "address"
  285. }
  286. ],
  287. "name": "disown",
  288. "outputs": [],
  289. "type": "function"
  290. },
  291. {
  292. "constant": true,
  293. "inputs": [
  294. {
  295. "name": "_name",
  296. "type": "bytes32"
  297. }
  298. ],
  299. "name": "addr",
  300. "outputs": [
  301. {
  302. "name": "",
  303. "type": "address"
  304. }
  305. ],
  306. "type": "function"
  307. },
  308. {
  309. "constant": false,
  310. "inputs": [
  311. {
  312. "name": "_name",
  313. "type": "bytes32"
  314. }
  315. ],
  316. "name": "reserve",
  317. "outputs": [],
  318. "type": "function"
  319. },
  320. {
  321. "constant": false,
  322. "inputs": [
  323. {
  324. "name": "_name",
  325. "type": "bytes32"
  326. },
  327. {
  328. "name": "_newOwner",
  329. "type": "address"
  330. }
  331. ],
  332. "name": "transfer",
  333. "outputs": [],
  334. "type": "function"
  335. },
  336. {
  337. "constant": false,
  338. "inputs": [
  339. {
  340. "name": "_name",
  341. "type": "bytes32"
  342. },
  343. {
  344. "name": "_a",
  345. "type": "address"
  346. }
  347. ],
  348. "name": "setAddr",
  349. "outputs": [],
  350. "type": "function"
  351. },
  352. {
  353. "anonymous": false,
  354. "inputs": [
  355. {
  356. "indexed": true,
  357. "name": "name",
  358. "type": "bytes32"
  359. }
  360. ],
  361. "name": "Changed",
  362. "type": "event"
  363. }
  364. ]
  365. },{}],3:[function(require,module,exports){
  366. module.exports=[
  367. {
  368. "constant": false,
  369. "inputs": [
  370. {
  371. "name": "from",
  372. "type": "bytes32"
  373. },
  374. {
  375. "name": "to",
  376. "type": "address"
  377. },
  378. {
  379. "name": "value",
  380. "type": "uint256"
  381. }
  382. ],
  383. "name": "transfer",
  384. "outputs": [],
  385. "type": "function"
  386. },
  387. {
  388. "constant": false,
  389. "inputs": [
  390. {
  391. "name": "from",
  392. "type": "bytes32"
  393. },
  394. {
  395. "name": "to",
  396. "type": "address"
  397. },
  398. {
  399. "name": "indirectId",
  400. "type": "bytes32"
  401. },
  402. {
  403. "name": "value",
  404. "type": "uint256"
  405. }
  406. ],
  407. "name": "icapTransfer",
  408. "outputs": [],
  409. "type": "function"
  410. },
  411. {
  412. "constant": false,
  413. "inputs": [
  414. {
  415. "name": "to",
  416. "type": "bytes32"
  417. }
  418. ],
  419. "name": "deposit",
  420. "outputs": [],
  421. "payable": true,
  422. "type": "function"
  423. },
  424. {
  425. "anonymous": false,
  426. "inputs": [
  427. {
  428. "indexed": true,
  429. "name": "from",
  430. "type": "address"
  431. },
  432. {
  433. "indexed": false,
  434. "name": "value",
  435. "type": "uint256"
  436. }
  437. ],
  438. "name": "AnonymousDeposit",
  439. "type": "event"
  440. },
  441. {
  442. "anonymous": false,
  443. "inputs": [
  444. {
  445. "indexed": true,
  446. "name": "from",
  447. "type": "address"
  448. },
  449. {
  450. "indexed": true,
  451. "name": "to",
  452. "type": "bytes32"
  453. },
  454. {
  455. "indexed": false,
  456. "name": "value",
  457. "type": "uint256"
  458. }
  459. ],
  460. "name": "Deposit",
  461. "type": "event"
  462. },
  463. {
  464. "anonymous": false,
  465. "inputs": [
  466. {
  467. "indexed": true,
  468. "name": "from",
  469. "type": "bytes32"
  470. },
  471. {
  472. "indexed": true,
  473. "name": "to",
  474. "type": "address"
  475. },
  476. {
  477. "indexed": false,
  478. "name": "value",
  479. "type": "uint256"
  480. }
  481. ],
  482. "name": "Transfer",
  483. "type": "event"
  484. },
  485. {
  486. "anonymous": false,
  487. "inputs": [
  488. {
  489. "indexed": true,
  490. "name": "from",
  491. "type": "bytes32"
  492. },
  493. {
  494. "indexed": true,
  495. "name": "to",
  496. "type": "address"
  497. },
  498. {
  499. "indexed": false,
  500. "name": "indirectId",
  501. "type": "bytes32"
  502. },
  503. {
  504. "indexed": false,
  505. "name": "value",
  506. "type": "uint256"
  507. }
  508. ],
  509. "name": "IcapTransfer",
  510. "type": "event"
  511. }
  512. ]
  513. },{}],4:[function(require,module,exports){
  514. var f = require('./formatters');
  515. var SolidityType = require('./type');
  516. /**
  517. * SolidityTypeAddress is a prootype that represents address type
  518. * It matches:
  519. * address
  520. * address[]
  521. * address[4]
  522. * address[][]
  523. * address[3][]
  524. * address[][6][], ...
  525. */
  526. var SolidityTypeAddress = function () {
  527. this._inputFormatter = f.formatInputInt;
  528. this._outputFormatter = f.formatOutputAddress;
  529. };
  530. SolidityTypeAddress.prototype = new SolidityType({});
  531. SolidityTypeAddress.prototype.constructor = SolidityTypeAddress;
  532. SolidityTypeAddress.prototype.isType = function (name) {
  533. return !!name.match(/address(\[([0-9]*)\])?/);
  534. };
  535. module.exports = SolidityTypeAddress;
  536. },{"./formatters":9,"./type":14}],5:[function(require,module,exports){
  537. var f = require('./formatters');
  538. var SolidityType = require('./type');
  539. /**
  540. * SolidityTypeBool is a prootype that represents bool type
  541. * It matches:
  542. * bool
  543. * bool[]
  544. * bool[4]
  545. * bool[][]
  546. * bool[3][]
  547. * bool[][6][], ...
  548. */
  549. var SolidityTypeBool = function () {
  550. this._inputFormatter = f.formatInputBool;
  551. this._outputFormatter = f.formatOutputBool;
  552. };
  553. SolidityTypeBool.prototype = new SolidityType({});
  554. SolidityTypeBool.prototype.constructor = SolidityTypeBool;
  555. SolidityTypeBool.prototype.isType = function (name) {
  556. return !!name.match(/^bool(\[([0-9]*)\])*$/);
  557. };
  558. module.exports = SolidityTypeBool;
  559. },{"./formatters":9,"./type":14}],6:[function(require,module,exports){
  560. var f = require('./formatters');
  561. var SolidityType = require('./type');
  562. /**
  563. * SolidityTypeBytes is a prototype that represents the bytes type.
  564. * It matches:
  565. * bytes
  566. * bytes[]
  567. * bytes[4]
  568. * bytes[][]
  569. * bytes[3][]
  570. * bytes[][6][], ...
  571. * bytes32
  572. * bytes8[4]
  573. * bytes[3][]
  574. */
  575. var SolidityTypeBytes = function () {
  576. this._inputFormatter = f.formatInputBytes;
  577. this._outputFormatter = f.formatOutputBytes;
  578. };
  579. SolidityTypeBytes.prototype = new SolidityType({});
  580. SolidityTypeBytes.prototype.constructor = SolidityTypeBytes;
  581. SolidityTypeBytes.prototype.isType = function (name) {
  582. return !!name.match(/^bytes([0-9]{1,})(\[([0-9]*)\])*$/);
  583. };
  584. module.exports = SolidityTypeBytes;
  585. },{"./formatters":9,"./type":14}],7:[function(require,module,exports){
  586. /*
  587. This file is part of web3.js.
  588. web3.js is free software: you can redistribute it and/or modify
  589. it under the terms of the GNU Lesser General Public License as published by
  590. the Free Software Foundation, either version 3 of the License, or
  591. (at your option) any later version.
  592. web3.js is distributed in the hope that it will be useful,
  593. but WITHOUT ANY WARRANTY; without even the implied warranty of
  594. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  595. GNU Lesser General Public License for more details.
  596. You should have received a copy of the GNU Lesser General Public License
  597. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  598. */
  599. /**
  600. * @file coder.js
  601. * @author Marek Kotewicz <marek@ethdev.com>
  602. * @date 2015
  603. */
  604. var f = require('./formatters');
  605. var SolidityTypeAddress = require('./address');
  606. var SolidityTypeBool = require('./bool');
  607. var SolidityTypeInt = require('./int');
  608. var SolidityTypeUInt = require('./uint');
  609. var SolidityTypeDynamicBytes = require('./dynamicbytes');
  610. var SolidityTypeString = require('./string');
  611. var SolidityTypeReal = require('./real');
  612. var SolidityTypeUReal = require('./ureal');
  613. var SolidityTypeBytes = require('./bytes');
  614. var isDynamic = function (solidityType, type) {
  615. return solidityType.isDynamicType(type) ||
  616. solidityType.isDynamicArray(type);
  617. };
  618. /**
  619. * SolidityCoder prototype should be used to encode/decode solidity params of any type
  620. */
  621. var SolidityCoder = function (types) {
  622. this._types = types;
  623. };
  624. /**
  625. * This method should be used to transform type to SolidityType
  626. *
  627. * @method _requireType
  628. * @param {String} type
  629. * @returns {SolidityType}
  630. * @throws {Error} throws if no matching type is found
  631. */
  632. SolidityCoder.prototype._requireType = function (type) {
  633. var solidityType = this._types.filter(function (t) {
  634. return t.isType(type);
  635. })[0];
  636. if (!solidityType) {
  637. throw Error('invalid solidity type!: ' + type);
  638. }
  639. return solidityType;
  640. };
  641. /**
  642. * Should be used to encode plain param
  643. *
  644. * @method encodeParam
  645. * @param {String} type
  646. * @param {Object} plain param
  647. * @return {String} encoded plain param
  648. */
  649. SolidityCoder.prototype.encodeParam = function (type, param) {
  650. return this.encodeParams([type], [param]);
  651. };
  652. /**
  653. * Should be used to encode list of params
  654. *
  655. * @method encodeParams
  656. * @param {Array} types
  657. * @param {Array} params
  658. * @return {String} encoded list of params
  659. */
  660. SolidityCoder.prototype.encodeParams = function (types, params) {
  661. var solidityTypes = this.getSolidityTypes(types);
  662. var encodeds = solidityTypes.map(function (solidityType, index) {
  663. return solidityType.encode(params[index], types[index]);
  664. });
  665. var dynamicOffset = solidityTypes.reduce(function (acc, solidityType, index) {
  666. var staticPartLength = solidityType.staticPartLength(types[index]);
  667. var roundedStaticPartLength = Math.floor((staticPartLength + 31) / 32) * 32;
  668. return acc + (isDynamic(solidityTypes[index], types[index]) ?
  669. 32 :
  670. roundedStaticPartLength);
  671. }, 0);
  672. var result = this.encodeMultiWithOffset(types, solidityTypes, encodeds, dynamicOffset);
  673. return result;
  674. };
  675. SolidityCoder.prototype.encodeMultiWithOffset = function (types, solidityTypes, encodeds, dynamicOffset) {
  676. var result = "";
  677. var self = this;
  678. types.forEach(function (type, i) {
  679. if (isDynamic(solidityTypes[i], types[i])) {
  680. result += f.formatInputInt(dynamicOffset).encode();
  681. var e = self.encodeWithOffset(types[i], solidityTypes[i], encodeds[i], dynamicOffset);
  682. dynamicOffset += e.length / 2;
  683. } else {
  684. // don't add length to dynamicOffset. it's already counted
  685. result += self.encodeWithOffset(types[i], solidityTypes[i], encodeds[i], dynamicOffset);
  686. }
  687. // TODO: figure out nested arrays
  688. });
  689. types.forEach(function (type, i) {
  690. if (isDynamic(solidityTypes[i], types[i])) {
  691. var e = self.encodeWithOffset(types[i], solidityTypes[i], encodeds[i], dynamicOffset);
  692. dynamicOffset += e.length / 2;
  693. result += e;
  694. }
  695. });
  696. return result;
  697. };
  698. // TODO: refactor whole encoding!
  699. SolidityCoder.prototype.encodeWithOffset = function (type, solidityType, encoded, offset) {
  700. var self = this;
  701. if (solidityType.isDynamicArray(type)) {
  702. return (function () {
  703. // offset was already set
  704. var nestedName = solidityType.nestedName(type);
  705. var nestedStaticPartLength = solidityType.staticPartLength(nestedName);
  706. var result = encoded[0];
  707. (function () {
  708. var previousLength = 2; // in int
  709. if (solidityType.isDynamicArray(nestedName)) {
  710. for (var i = 1; i < encoded.length; i++) {
  711. previousLength += +(encoded[i - 1])[0] || 0;
  712. result += f.formatInputInt(offset + i * nestedStaticPartLength + previousLength * 32).encode();
  713. }
  714. }
  715. })();
  716. // first element is length, skip it
  717. (function () {
  718. for (var i = 0; i < encoded.length - 1; i++) {
  719. var additionalOffset = result / 2;
  720. result += self.encodeWithOffset(nestedName, solidityType, encoded[i + 1], offset + additionalOffset);
  721. }
  722. })();
  723. return result;
  724. })();
  725. } else if (solidityType.isStaticArray(type)) {
  726. return (function () {
  727. var nestedName = solidityType.nestedName(type);
  728. var nestedStaticPartLength = solidityType.staticPartLength(nestedName);
  729. var result = "";
  730. if (solidityType.isDynamicArray(nestedName)) {
  731. (function () {
  732. var previousLength = 0; // in int
  733. for (var i = 0; i < encoded.length; i++) {
  734. // calculate length of previous item
  735. previousLength += +(encoded[i - 1] || [])[0] || 0;
  736. result += f.formatInputInt(offset + i * nestedStaticPartLength + previousLength * 32).encode();
  737. }
  738. })();
  739. }
  740. (function () {
  741. for (var i = 0; i < encoded.length; i++) {
  742. var additionalOffset = result / 2;
  743. result += self.encodeWithOffset(nestedName, solidityType, encoded[i], offset + additionalOffset);
  744. }
  745. })();
  746. return result;
  747. })();
  748. }
  749. return encoded;
  750. };
  751. /**
  752. * Should be used to decode bytes to plain param
  753. *
  754. * @method decodeParam
  755. * @param {String} type
  756. * @param {String} bytes
  757. * @return {Object} plain param
  758. */
  759. SolidityCoder.prototype.decodeParam = function (type, bytes) {
  760. return this.decodeParams([type], bytes)[0];
  761. };
  762. /**
  763. * Should be used to decode list of params
  764. *
  765. * @method decodeParam
  766. * @param {Array} types
  767. * @param {String} bytes
  768. * @return {Array} array of plain params
  769. */
  770. SolidityCoder.prototype.decodeParams = function (types, bytes) {
  771. var solidityTypes = this.getSolidityTypes(types);
  772. var offsets = this.getOffsets(types, solidityTypes);
  773. return solidityTypes.map(function (solidityType, index) {
  774. return solidityType.decode(bytes, offsets[index], types[index], index);
  775. });
  776. };
  777. SolidityCoder.prototype.getOffsets = function (types, solidityTypes) {
  778. var lengths = solidityTypes.map(function (solidityType, index) {
  779. return solidityType.staticPartLength(types[index]);
  780. });
  781. for (var i = 1; i < lengths.length; i++) {
  782. // sum with length of previous element
  783. lengths[i] += lengths[i - 1];
  784. }
  785. return lengths.map(function (length, index) {
  786. // remove the current length, so the length is sum of previous elements
  787. var staticPartLength = solidityTypes[index].staticPartLength(types[index]);
  788. return length - staticPartLength;
  789. });
  790. };
  791. SolidityCoder.prototype.getSolidityTypes = function (types) {
  792. var self = this;
  793. return types.map(function (type) {
  794. return self._requireType(type);
  795. });
  796. };
  797. var coder = new SolidityCoder([
  798. new SolidityTypeAddress(),
  799. new SolidityTypeBool(),
  800. new SolidityTypeInt(),
  801. new SolidityTypeUInt(),
  802. new SolidityTypeDynamicBytes(),
  803. new SolidityTypeBytes(),
  804. new SolidityTypeString(),
  805. new SolidityTypeReal(),
  806. new SolidityTypeUReal()
  807. ]);
  808. module.exports = coder;
  809. },{"./address":4,"./bool":5,"./bytes":6,"./dynamicbytes":8,"./formatters":9,"./int":10,"./real":12,"./string":13,"./uint":15,"./ureal":16}],8:[function(require,module,exports){
  810. var f = require('./formatters');
  811. var SolidityType = require('./type');
  812. var SolidityTypeDynamicBytes = function () {
  813. this._inputFormatter = f.formatInputDynamicBytes;
  814. this._outputFormatter = f.formatOutputDynamicBytes;
  815. };
  816. SolidityTypeDynamicBytes.prototype = new SolidityType({});
  817. SolidityTypeDynamicBytes.prototype.constructor = SolidityTypeDynamicBytes;
  818. SolidityTypeDynamicBytes.prototype.isType = function (name) {
  819. return !!name.match(/^bytes(\[([0-9]*)\])*$/);
  820. };
  821. SolidityTypeDynamicBytes.prototype.isDynamicType = function () {
  822. return true;
  823. };
  824. module.exports = SolidityTypeDynamicBytes;
  825. },{"./formatters":9,"./type":14}],9:[function(require,module,exports){
  826. /*
  827. This file is part of web3.js.
  828. web3.js is free software: you can redistribute it and/or modify
  829. it under the terms of the GNU Lesser General Public License as published by
  830. the Free Software Foundation, either version 3 of the License, or
  831. (at your option) any later version.
  832. web3.js is distributed in the hope that it will be useful,
  833. but WITHOUT ANY WARRANTY; without even the implied warranty of
  834. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  835. GNU Lesser General Public License for more details.
  836. You should have received a copy of the GNU Lesser General Public License
  837. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  838. */
  839. /**
  840. * @file formatters.js
  841. * @author Marek Kotewicz <marek@ethdev.com>
  842. * @date 2015
  843. */
  844. var BigNumber = require('bignumber.js');
  845. var utils = require('../utils/utils');
  846. var c = require('../utils/config');
  847. var SolidityParam = require('./param');
  848. /**
  849. * Formats input value to byte representation of int
  850. * If value is negative, return it's two's complement
  851. * If the value is floating point, round it down
  852. *
  853. * @method formatInputInt
  854. * @param {String|Number|BigNumber} value that needs to be formatted
  855. * @returns {SolidityParam}
  856. */
  857. var formatInputInt = function (value) {
  858. BigNumber.config(c.ETH_BIGNUMBER_ROUNDING_MODE);
  859. var result = utils.padLeft(utils.toTwosComplement(value).toString(16), 64);
  860. return new SolidityParam(result);
  861. };
  862. /**
  863. * Formats input bytes
  864. *
  865. * @method formatInputBytes
  866. * @param {String}
  867. * @returns {SolidityParam}
  868. */
  869. var formatInputBytes = function (value) {
  870. var result = utils.toHex(value).substr(2);
  871. var l = Math.floor((result.length + 63) / 64);
  872. result = utils.padRight(result, l * 64);
  873. return new SolidityParam(result);
  874. };
  875. /**
  876. * Formats input bytes
  877. *
  878. * @method formatDynamicInputBytes
  879. * @param {String}
  880. * @returns {SolidityParam}
  881. */
  882. var formatInputDynamicBytes = function (value) {
  883. var result = utils.toHex(value).substr(2);
  884. var length = result.length / 2;
  885. var l = Math.floor((result.length + 63) / 64);
  886. result = utils.padRight(result, l * 64);
  887. return new SolidityParam(formatInputInt(length).value + result);
  888. };
  889. /**
  890. * Formats input value to byte representation of string
  891. *
  892. * @method formatInputString
  893. * @param {String}
  894. * @returns {SolidityParam}
  895. */
  896. var formatInputString = function (value) {
  897. var result = utils.fromUtf8(value).substr(2);
  898. var length = result.length / 2;
  899. var l = Math.floor((result.length + 63) / 64);
  900. result = utils.padRight(result, l * 64);
  901. return new SolidityParam(formatInputInt(length).value + result);
  902. };
  903. /**
  904. * Formats input value to byte representation of bool
  905. *
  906. * @method formatInputBool
  907. * @param {Boolean}
  908. * @returns {SolidityParam}
  909. */
  910. var formatInputBool = function (value) {
  911. var result = '000000000000000000000000000000000000000000000000000000000000000' + (value ? '1' : '0');
  912. return new SolidityParam(result);
  913. };
  914. /**
  915. * Formats input value to byte representation of real
  916. * Values are multiplied by 2^m and encoded as integers
  917. *
  918. * @method formatInputReal
  919. * @param {String|Number|BigNumber}
  920. * @returns {SolidityParam}
  921. */
  922. var formatInputReal = function (value) {
  923. return formatInputInt(new BigNumber(value).times(new BigNumber(2).pow(128)));
  924. };
  925. /**
  926. * Check if input value is negative
  927. *
  928. * @method signedIsNegative
  929. * @param {String} value is hex format
  930. * @returns {Boolean} true if it is negative, otherwise false
  931. */
  932. var signedIsNegative = function (value) {
  933. return (new BigNumber(value.substr(0, 1), 16).toString(2).substr(0, 1)) === '1';
  934. };
  935. /**
  936. * Formats right-aligned output bytes to int
  937. *
  938. * @method formatOutputInt
  939. * @param {SolidityParam} param
  940. * @returns {BigNumber} right-aligned output bytes formatted to big number
  941. */
  942. var formatOutputInt = function (param) {
  943. var value = param.staticPart() || "0";
  944. // check if it's negative number
  945. // it is, return two's complement
  946. if (signedIsNegative(value)) {
  947. return new BigNumber(value, 16).minus(new BigNumber('ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', 16)).minus(1);
  948. }
  949. return new BigNumber(value, 16);
  950. };
  951. /**
  952. * Formats right-aligned output bytes to uint
  953. *
  954. * @method formatOutputUInt
  955. * @param {SolidityParam}
  956. * @returns {BigNumeber} right-aligned output bytes formatted to uint
  957. */
  958. var formatOutputUInt = function (param) {
  959. var value = param.staticPart() || "0";
  960. return new BigNumber(value, 16);
  961. };
  962. /**
  963. * Formats right-aligned output bytes to real
  964. *
  965. * @method formatOutputReal
  966. * @param {SolidityParam}
  967. * @returns {BigNumber} input bytes formatted to real
  968. */
  969. var formatOutputReal = function (param) {
  970. return formatOutputInt(param).dividedBy(new BigNumber(2).pow(128));
  971. };
  972. /**
  973. * Formats right-aligned output bytes to ureal
  974. *
  975. * @method formatOutputUReal
  976. * @param {SolidityParam}
  977. * @returns {BigNumber} input bytes formatted to ureal
  978. */
  979. var formatOutputUReal = function (param) {
  980. return formatOutputUInt(param).dividedBy(new BigNumber(2).pow(128));
  981. };
  982. /**
  983. * Should be used to format output bool
  984. *
  985. * @method formatOutputBool
  986. * @param {SolidityParam}
  987. * @returns {Boolean} right-aligned input bytes formatted to bool
  988. */
  989. var formatOutputBool = function (param) {
  990. return param.staticPart() === '0000000000000000000000000000000000000000000000000000000000000001' ? true : false;
  991. };
  992. /**
  993. * Should be used to format output bytes
  994. *
  995. * @method formatOutputBytes
  996. * @param {SolidityParam} left-aligned hex representation of string
  997. * @param {String} name type name
  998. * @returns {String} hex string
  999. */
  1000. var formatOutputBytes = function (param, name) {
  1001. var matches = name.match(/^bytes([0-9]*)/);
  1002. var size = parseInt(matches[1]);
  1003. return '0x' + param.staticPart().slice(0, 2 * size);
  1004. };
  1005. /**
  1006. * Should be used to format output bytes
  1007. *
  1008. * @method formatOutputDynamicBytes
  1009. * @param {SolidityParam} left-aligned hex representation of string
  1010. * @returns {String} hex string
  1011. */
  1012. var formatOutputDynamicBytes = function (param) {
  1013. var length = (new BigNumber(param.dynamicPart().slice(0, 64), 16)).toNumber() * 2;
  1014. return '0x' + param.dynamicPart().substr(64, length);
  1015. };
  1016. /**
  1017. * Should be used to format output string
  1018. *
  1019. * @method formatOutputString
  1020. * @param {SolidityParam} left-aligned hex representation of string
  1021. * @returns {String} ascii string
  1022. */
  1023. var formatOutputString = function (param) {
  1024. var length = (new BigNumber(param.dynamicPart().slice(0, 64), 16)).toNumber() * 2;
  1025. return utils.toUtf8(param.dynamicPart().substr(64, length));
  1026. };
  1027. /**
  1028. * Should be used to format output address
  1029. *
  1030. * @method formatOutputAddress
  1031. * @param {SolidityParam} right-aligned input bytes
  1032. * @returns {String} address
  1033. */
  1034. var formatOutputAddress = function (param) {
  1035. var value = param.staticPart();
  1036. return "0x" + value.slice(value.length - 40, value.length);
  1037. };
  1038. module.exports = {
  1039. formatInputInt: formatInputInt,
  1040. formatInputBytes: formatInputBytes,
  1041. formatInputDynamicBytes: formatInputDynamicBytes,
  1042. formatInputString: formatInputString,
  1043. formatInputBool: formatInputBool,
  1044. formatInputReal: formatInputReal,
  1045. formatOutputInt: formatOutputInt,
  1046. formatOutputUInt: formatOutputUInt,
  1047. formatOutputReal: formatOutputReal,
  1048. formatOutputUReal: formatOutputUReal,
  1049. formatOutputBool: formatOutputBool,
  1050. formatOutputBytes: formatOutputBytes,
  1051. formatOutputDynamicBytes: formatOutputDynamicBytes,
  1052. formatOutputString: formatOutputString,
  1053. formatOutputAddress: formatOutputAddress
  1054. };
  1055. },{"../utils/config":18,"../utils/utils":20,"./param":11,"bignumber.js":"bignumber.js"}],10:[function(require,module,exports){
  1056. var f = require('./formatters');
  1057. var SolidityType = require('./type');
  1058. /**
  1059. * SolidityTypeInt is a prootype that represents int type
  1060. * It matches:
  1061. * int
  1062. * int[]
  1063. * int[4]
  1064. * int[][]
  1065. * int[3][]
  1066. * int[][6][], ...
  1067. * int32
  1068. * int64[]
  1069. * int8[4]
  1070. * int256[][]
  1071. * int[3][]
  1072. * int64[][6][], ...
  1073. */
  1074. var SolidityTypeInt = function () {
  1075. this._inputFormatter = f.formatInputInt;
  1076. this._outputFormatter = f.formatOutputInt;
  1077. };
  1078. SolidityTypeInt.prototype = new SolidityType({});
  1079. SolidityTypeInt.prototype.constructor = SolidityTypeInt;
  1080. SolidityTypeInt.prototype.isType = function (name) {
  1081. return !!name.match(/^int([0-9]*)?(\[([0-9]*)\])*$/);
  1082. };
  1083. module.exports = SolidityTypeInt;
  1084. },{"./formatters":9,"./type":14}],11:[function(require,module,exports){
  1085. /*
  1086. This file is part of web3.js.
  1087. web3.js is free software: you can redistribute it and/or modify
  1088. it under the terms of the GNU Lesser General Public License as published by
  1089. the Free Software Foundation, either version 3 of the License, or
  1090. (at your option) any later version.
  1091. web3.js is distributed in the hope that it will be useful,
  1092. but WITHOUT ANY WARRANTY; without even the implied warranty of
  1093. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  1094. GNU Lesser General Public License for more details.
  1095. You should have received a copy of the GNU Lesser General Public License
  1096. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  1097. */
  1098. /**
  1099. * @file param.js
  1100. * @author Marek Kotewicz <marek@ethdev.com>
  1101. * @date 2015
  1102. */
  1103. var utils = require('../utils/utils');
  1104. /**
  1105. * SolidityParam object prototype.
  1106. * Should be used when encoding, decoding solidity bytes
  1107. */
  1108. var SolidityParam = function (value, offset) {
  1109. this.value = value || '';
  1110. this.offset = offset; // offset in bytes
  1111. };
  1112. /**
  1113. * This method should be used to get length of params's dynamic part
  1114. *
  1115. * @method dynamicPartLength
  1116. * @returns {Number} length of dynamic part (in bytes)
  1117. */
  1118. SolidityParam.prototype.dynamicPartLength = function () {
  1119. return this.dynamicPart().length / 2;
  1120. };
  1121. /**
  1122. * This method should be used to create copy of solidity param with different offset
  1123. *
  1124. * @method withOffset
  1125. * @param {Number} offset length in bytes
  1126. * @returns {SolidityParam} new solidity param with applied offset
  1127. */
  1128. SolidityParam.prototype.withOffset = function (offset) {
  1129. return new SolidityParam(this.value, offset);
  1130. };
  1131. /**
  1132. * This method should be used to combine solidity params together
  1133. * eg. when appending an array
  1134. *
  1135. * @method combine
  1136. * @param {SolidityParam} param with which we should combine
  1137. * @param {SolidityParam} result of combination
  1138. */
  1139. SolidityParam.prototype.combine = function (param) {
  1140. return new SolidityParam(this.value + param.value);
  1141. };
  1142. /**
  1143. * This method should be called to check if param has dynamic size.
  1144. * If it has, it returns true, otherwise false
  1145. *
  1146. * @method isDynamic
  1147. * @returns {Boolean}
  1148. */
  1149. SolidityParam.prototype.isDynamic = function () {
  1150. return this.offset !== undefined;
  1151. };
  1152. /**
  1153. * This method should be called to transform offset to bytes
  1154. *
  1155. * @method offsetAsBytes
  1156. * @returns {String} bytes representation of offset
  1157. */
  1158. SolidityParam.prototype.offsetAsBytes = function () {
  1159. return !this.isDynamic() ? '' : utils.padLeft(utils.toTwosComplement(this.offset).toString(16), 64);
  1160. };
  1161. /**
  1162. * This method should be called to get static part of param
  1163. *
  1164. * @method staticPart
  1165. * @returns {String} offset if it is a dynamic param, otherwise value
  1166. */
  1167. SolidityParam.prototype.staticPart = function () {
  1168. if (!this.isDynamic()) {
  1169. return this.value;
  1170. }
  1171. return this.offsetAsBytes();
  1172. };
  1173. /**
  1174. * This method should be called to get dynamic part of param
  1175. *
  1176. * @method dynamicPart
  1177. * @returns {String} returns a value if it is a dynamic param, otherwise empty string
  1178. */
  1179. SolidityParam.prototype.dynamicPart = function () {
  1180. return this.isDynamic() ? this.value : '';
  1181. };
  1182. /**
  1183. * This method should be called to encode param
  1184. *
  1185. * @method encode
  1186. * @returns {String}
  1187. */
  1188. SolidityParam.prototype.encode = function () {
  1189. return this.staticPart() + this.dynamicPart();
  1190. };
  1191. /**
  1192. * This method should be called to encode array of params
  1193. *
  1194. * @method encodeList
  1195. * @param {Array[SolidityParam]} params
  1196. * @returns {String}
  1197. */
  1198. SolidityParam.encodeList = function (params) {
  1199. // updating offsets
  1200. var totalOffset = params.length * 32;
  1201. var offsetParams = params.map(function (param) {
  1202. if (!param.isDynamic()) {
  1203. return param;
  1204. }
  1205. var offset = totalOffset;
  1206. totalOffset += param.dynamicPartLength();
  1207. return param.withOffset(offset);
  1208. });
  1209. // encode everything!
  1210. return offsetParams.reduce(function (result, param) {
  1211. return result + param.dynamicPart();
  1212. }, offsetParams.reduce(function (result, param) {
  1213. return result + param.staticPart();
  1214. }, ''));
  1215. };
  1216. module.exports = SolidityParam;
  1217. },{"../utils/utils":20}],12:[function(require,module,exports){
  1218. var f = require('./formatters');
  1219. var SolidityType = require('./type');
  1220. /**
  1221. * SolidityTypeReal is a prootype that represents real type
  1222. * It matches:
  1223. * real
  1224. * real[]
  1225. * real[4]
  1226. * real[][]
  1227. * real[3][]
  1228. * real[][6][], ...
  1229. * real32
  1230. * real64[]
  1231. * real8[4]
  1232. * real256[][]
  1233. * real[3][]
  1234. * real64[][6][], ...
  1235. */
  1236. var SolidityTypeReal = function () {
  1237. this._inputFormatter = f.formatInputReal;
  1238. this._outputFormatter = f.formatOutputReal;
  1239. };
  1240. SolidityTypeReal.prototype = new SolidityType({});
  1241. SolidityTypeReal.prototype.constructor = SolidityTypeReal;
  1242. SolidityTypeReal.prototype.isType = function (name) {
  1243. return !!name.match(/real([0-9]*)?(\[([0-9]*)\])?/);
  1244. };
  1245. module.exports = SolidityTypeReal;
  1246. },{"./formatters":9,"./type":14}],13:[function(require,module,exports){
  1247. var f = require('./formatters');
  1248. var SolidityType = require('./type');
  1249. var SolidityTypeString = function () {
  1250. this._inputFormatter = f.formatInputString;
  1251. this._outputFormatter = f.formatOutputString;
  1252. };
  1253. SolidityTypeString.prototype = new SolidityType({});
  1254. SolidityTypeString.prototype.constructor = SolidityTypeString;
  1255. SolidityTypeString.prototype.isType = function (name) {
  1256. return !!name.match(/^string(\[([0-9]*)\])*$/);
  1257. };
  1258. SolidityTypeString.prototype.isDynamicType = function () {
  1259. return true;
  1260. };
  1261. module.exports = SolidityTypeString;
  1262. },{"./formatters":9,"./type":14}],14:[function(require,module,exports){
  1263. var f = require('./formatters');
  1264. var SolidityParam = require('./param');
  1265. /**
  1266. * SolidityType prototype is used to encode/decode solidity params of certain type
  1267. */
  1268. var SolidityType = function (config) {
  1269. this._inputFormatter = config.inputFormatter;
  1270. this._outputFormatter = config.outputFormatter;
  1271. };
  1272. /**
  1273. * Should be used to determine if this SolidityType do match given name
  1274. *
  1275. * @method isType
  1276. * @param {String} name
  1277. * @return {Bool} true if type match this SolidityType, otherwise false
  1278. */
  1279. SolidityType.prototype.isType = function (name) {
  1280. throw "this method should be overrwritten for type " + name;
  1281. };
  1282. /**
  1283. * Should be used to determine what is the length of static part in given type
  1284. *
  1285. * @method staticPartLength
  1286. * @param {String} name
  1287. * @return {Number} length of static part in bytes
  1288. */
  1289. SolidityType.prototype.staticPartLength = function (name) {
  1290. // If name isn't an array then treat it like a single element array.
  1291. return (this.nestedTypes(name) || ['[1]'])
  1292. .map(function (type) {
  1293. // the length of the nested array
  1294. return parseInt(type.slice(1, -1), 10) || 1;
  1295. })
  1296. .reduce(function (previous, current) {
  1297. return previous * current;
  1298. // all basic types are 32 bytes long
  1299. }, 32);
  1300. };
  1301. /**
  1302. * Should be used to determine if type is dynamic array
  1303. * eg:
  1304. * "type[]" => true
  1305. * "type[4]" => false
  1306. *
  1307. * @method isDynamicArray
  1308. * @param {String} name
  1309. * @return {Bool} true if the type is dynamic array
  1310. */
  1311. SolidityType.prototype.isDynamicArray = function (name) {
  1312. var nestedTypes = this.nestedTypes(name);
  1313. return !!nestedTypes && !nestedTypes[nestedTypes.length - 1].match(/[0-9]{1,}/g);
  1314. };
  1315. /**
  1316. * Should be used to determine if type is static array
  1317. * eg:
  1318. * "type[]" => false
  1319. * "type[4]" => true
  1320. *
  1321. * @method isStaticArray
  1322. * @param {String} name
  1323. * @return {Bool} true if the type is static array
  1324. */
  1325. SolidityType.prototype.isStaticArray = function (name) {
  1326. var nestedTypes = this.nestedTypes(name);
  1327. return !!nestedTypes && !!nestedTypes[nestedTypes.length - 1].match(/[0-9]{1,}/g);
  1328. };
  1329. /**
  1330. * Should return length of static array
  1331. * eg.
  1332. * "int[32]" => 32
  1333. * "int256[14]" => 14
  1334. * "int[2][3]" => 3
  1335. * "int" => 1
  1336. * "int[1]" => 1
  1337. * "int[]" => 1
  1338. *
  1339. * @method staticArrayLength
  1340. * @param {String} name
  1341. * @return {Number} static array length
  1342. */
  1343. SolidityType.prototype.staticArrayLength = function (name) {
  1344. var nestedTypes = this.nestedTypes(name);
  1345. if (nestedTypes) {
  1346. return parseInt(nestedTypes[nestedTypes.length - 1].match(/[0-9]{1,}/g) || 1);
  1347. }
  1348. return 1;
  1349. };
  1350. /**
  1351. * Should return nested type
  1352. * eg.
  1353. * "int[32]" => "int"
  1354. * "int256[14]" => "int256"
  1355. * "int[2][3]" => "int[2]"
  1356. * "int" => "int"
  1357. * "int[]" => "int"
  1358. *
  1359. * @method nestedName
  1360. * @param {String} name
  1361. * @return {String} nested name
  1362. */
  1363. SolidityType.prototype.nestedName = function (name) {
  1364. // remove last [] in name
  1365. var nestedTypes = this.nestedTypes(name);
  1366. if (!nestedTypes) {
  1367. return name;
  1368. }
  1369. return name.substr(0, name.length - nestedTypes[nestedTypes.length - 1].length);
  1370. };
  1371. /**
  1372. * Should return true if type has dynamic size by default
  1373. * such types are "string", "bytes"
  1374. *
  1375. * @method isDynamicType
  1376. * @param {String} name
  1377. * @return {Bool} true if is dynamic, otherwise false
  1378. */
  1379. SolidityType.prototype.isDynamicType = function () {
  1380. return false;
  1381. };
  1382. /**
  1383. * Should return array of nested types
  1384. * eg.
  1385. * "int[2][3][]" => ["[2]", "[3]", "[]"]
  1386. * "int[] => ["[]"]
  1387. * "int" => null
  1388. *
  1389. * @method nestedTypes
  1390. * @param {String} name
  1391. * @return {Array} array of nested types
  1392. */
  1393. SolidityType.prototype.nestedTypes = function (name) {
  1394. // return list of strings eg. "[]", "[3]", "[]", "[2]"
  1395. return name.match(/(\[[0-9]*\])/g);
  1396. };
  1397. /**
  1398. * Should be used to encode the value
  1399. *
  1400. * @method encode
  1401. * @param {Object} value
  1402. * @param {String} name
  1403. * @return {String} encoded value
  1404. */
  1405. SolidityType.prototype.encode = function (value, name) {
  1406. var self = this;
  1407. if (this.isDynamicArray(name)) {
  1408. return (function () {
  1409. var length = value.length; // in int
  1410. var nestedName = self.nestedName(name);
  1411. var result = [];
  1412. result.push(f.formatInputInt(length).encode());
  1413. value.forEach(function (v) {
  1414. result.push(self.encode(v, nestedName));
  1415. });
  1416. return result;
  1417. })();
  1418. } else if (this.isStaticArray(name)) {
  1419. return (function () {
  1420. var length = self.staticArrayLength(name); // in int
  1421. var nestedName = self.nestedName(name);
  1422. var result = [];
  1423. for (var i = 0; i < length; i++) {
  1424. result.push(self.encode(value[i], nestedName));
  1425. }
  1426. return result;
  1427. })();
  1428. }
  1429. return this._inputFormatter(value, name).encode();
  1430. };
  1431. /**
  1432. * Should be used to decode value from bytes
  1433. *
  1434. * @method decode
  1435. * @param {String} bytes
  1436. * @param {Number} offset in bytes
  1437. * @param {String} name type name
  1438. * @returns {Object} decoded value
  1439. */
  1440. SolidityType.prototype.decode = function (bytes, offset, name) {
  1441. var self = this;
  1442. if (this.isDynamicArray(name)) {
  1443. return (function () {
  1444. var arrayOffset = parseInt('0x' + bytes.substr(offset * 2, 64)); // in bytes
  1445. var length = parseInt('0x' + bytes.substr(arrayOffset * 2, 64)); // in int
  1446. var arrayStart = arrayOffset + 32; // array starts after length; // in bytes
  1447. var nestedName = self.nestedName(name);
  1448. var nestedStaticPartLength = self.staticPartLength(nestedName); // in bytes
  1449. var roundedNestedStaticPartLength = Math.floor((nestedStaticPartLength + 31) / 32) * 32;
  1450. var result = [];
  1451. for (var i = 0; i < length * roundedNestedStaticPartLength; i += roundedNestedStaticPartLength) {
  1452. result.push(self.decode(bytes, arrayStart + i, nestedName));
  1453. }
  1454. return result;
  1455. })();
  1456. } else if (this.isStaticArray(name)) {
  1457. return (function () {
  1458. var length = self.staticArrayLength(name); // in int
  1459. var arrayStart = offset; // in bytes
  1460. var nestedName = self.nestedName(name);
  1461. var nestedStaticPartLength = self.staticPartLength(nestedName); // in bytes
  1462. var roundedNestedStaticPartLength = Math.floor((nestedStaticPartLength + 31) / 32) * 32;
  1463. var result = [];
  1464. for (var i = 0; i < length * roundedNestedStaticPartLength; i += roundedNestedStaticPartLength) {
  1465. result.push(self.decode(bytes, arrayStart + i, nestedName));
  1466. }
  1467. return result;
  1468. })();
  1469. } else if (this.isDynamicType(name)) {
  1470. return (function () {
  1471. var dynamicOffset = parseInt('0x' + bytes.substr(offset * 2, 64)); // in bytes
  1472. var length = parseInt('0x' + bytes.substr(dynamicOffset * 2, 64)); // in bytes
  1473. var roundedLength = Math.floor((length + 31) / 32); // in int
  1474. var param = new SolidityParam(bytes.substr(dynamicOffset * 2, ( 1 + roundedLength) * 64), 0);
  1475. return self._outputFormatter(param, name);
  1476. })();
  1477. }
  1478. var length = this.staticPartLength(name);
  1479. var param = new SolidityParam(bytes.substr(offset * 2, length * 2));
  1480. return this._outputFormatter(param, name);
  1481. };
  1482. module.exports = SolidityType;
  1483. },{"./formatters":9,"./param":11}],15:[function(require,module,exports){
  1484. var f = require('./formatters');
  1485. var SolidityType = require('./type');
  1486. /**
  1487. * SolidityTypeUInt is a prootype that represents uint type
  1488. * It matches:
  1489. * uint
  1490. * uint[]
  1491. * uint[4]
  1492. * uint[][]
  1493. * uint[3][]
  1494. * uint[][6][], ...
  1495. * uint32
  1496. * uint64[]
  1497. * uint8[4]
  1498. * uint256[][]
  1499. * uint[3][]
  1500. * uint64[][6][], ...
  1501. */
  1502. var SolidityTypeUInt = function () {
  1503. this._inputFormatter = f.formatInputInt;
  1504. this._outputFormatter = f.formatOutputUInt;
  1505. };
  1506. SolidityTypeUInt.prototype = new SolidityType({});
  1507. SolidityTypeUInt.prototype.constructor = SolidityTypeUInt;
  1508. SolidityTypeUInt.prototype.isType = function (name) {
  1509. return !!name.match(/^uint([0-9]*)?(\[([0-9]*)\])*$/);
  1510. };
  1511. module.exports = SolidityTypeUInt;
  1512. },{"./formatters":9,"./type":14}],16:[function(require,module,exports){
  1513. var f = require('./formatters');
  1514. var SolidityType = require('./type');
  1515. /**
  1516. * SolidityTypeUReal is a prootype that represents ureal type
  1517. * It matches:
  1518. * ureal
  1519. * ureal[]
  1520. * ureal[4]
  1521. * ureal[][]
  1522. * ureal[3][]
  1523. * ureal[][6][], ...
  1524. * ureal32
  1525. * ureal64[]
  1526. * ureal8[4]
  1527. * ureal256[][]
  1528. * ureal[3][]
  1529. * ureal64[][6][], ...
  1530. */
  1531. var SolidityTypeUReal = function () {
  1532. this._inputFormatter = f.formatInputReal;
  1533. this._outputFormatter = f.formatOutputUReal;
  1534. };
  1535. SolidityTypeUReal.prototype = new SolidityType({});
  1536. SolidityTypeUReal.prototype.constructor = SolidityTypeUReal;
  1537. SolidityTypeUReal.prototype.isType = function (name) {
  1538. return !!name.match(/^ureal([0-9]*)?(\[([0-9]*)\])*$/);
  1539. };
  1540. module.exports = SolidityTypeUReal;
  1541. },{"./formatters":9,"./type":14}],17:[function(require,module,exports){
  1542. 'use strict';
  1543. // go env doesn't have and need XMLHttpRequest
  1544. if (typeof XMLHttpRequest === 'undefined') {
  1545. exports.XMLHttpRequest = {};
  1546. } else {
  1547. exports.XMLHttpRequest = XMLHttpRequest; // jshint ignore:line
  1548. }
  1549. },{}],18:[function(require,module,exports){
  1550. /*
  1551. This file is part of web3.js.
  1552. web3.js is free software: you can redistribute it and/or modify
  1553. it under the terms of the GNU Lesser General Public License as published by
  1554. the Free Software Foundation, either version 3 of the License, or
  1555. (at your option) any later version.
  1556. web3.js is distributed in the hope that it will be useful,
  1557. but WITHOUT ANY WARRANTY; without even the implied warranty of
  1558. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  1559. GNU Lesser General Public License for more details.
  1560. You should have received a copy of the GNU Lesser General Public License
  1561. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  1562. */
  1563. /** @file config.js
  1564. * @authors:
  1565. * Marek Kotewicz <marek@ethdev.com>
  1566. * @date 2015
  1567. */
  1568. /**
  1569. * Utils
  1570. *
  1571. * @module utils
  1572. */
  1573. /**
  1574. * Utility functions
  1575. *
  1576. * @class [utils] config
  1577. * @constructor
  1578. */
  1579. /// required to define ETH_BIGNUMBER_ROUNDING_MODE
  1580. var BigNumber = require('bignumber.js');
  1581. var ETH_UNITS = [
  1582. 'wei',
  1583. 'kwei',
  1584. 'Mwei',
  1585. 'Gwei',
  1586. 'szabo',
  1587. 'finney',
  1588. 'femtoether',
  1589. 'picoether',
  1590. 'nanoether',
  1591. 'microether',
  1592. 'milliether',
  1593. 'nano',
  1594. 'micro',
  1595. 'milli',
  1596. 'ether',
  1597. 'grand',
  1598. 'Mether',
  1599. 'Gether',
  1600. 'Tether',
  1601. 'Pether',
  1602. 'Eether',
  1603. 'Zether',
  1604. 'Yether',
  1605. 'Nether',
  1606. 'Dether',
  1607. 'Vether',
  1608. 'Uether'
  1609. ];
  1610. module.exports = {
  1611. ETH_PADDING: 32,
  1612. ETH_SIGNATURE_LENGTH: 4,
  1613. ETH_UNITS: ETH_UNITS,
  1614. ETH_BIGNUMBER_ROUNDING_MODE: { ROUNDING_MODE: BigNumber.ROUND_DOWN },
  1615. ETH_POLLING_TIMEOUT: 1000/2,
  1616. defaultBlock: 'latest',
  1617. defaultAccount: undefined
  1618. };
  1619. },{"bignumber.js":"bignumber.js"}],19:[function(require,module,exports){
  1620. /*
  1621. This file is part of web3.js.
  1622. web3.js is free software: you can redistribute it and/or modify
  1623. it under the terms of the GNU Lesser General Public License as published by
  1624. the Free Software Foundation, either version 3 of the License, or
  1625. (at your option) any later version.
  1626. web3.js is distributed in the hope that it will be useful,
  1627. but WITHOUT ANY WARRANTY; without even the implied warranty of
  1628. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  1629. GNU Lesser General Public License for more details.
  1630. You should have received a copy of the GNU Lesser General Public License
  1631. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  1632. */
  1633. /**
  1634. * @file sha3.js
  1635. * @author Marek Kotewicz <marek@ethdev.com>
  1636. * @date 2015
  1637. */
  1638. var CryptoJS = require('crypto-js');
  1639. var sha3 = require('crypto-js/sha3');
  1640. module.exports = function (value, options) {
  1641. if (options && options.encoding === 'hex') {
  1642. if (value.length > 2 && value.substr(0, 2) === '0x') {
  1643. value = value.substr(2);
  1644. }
  1645. value = CryptoJS.enc.Hex.parse(value);
  1646. }
  1647. return sha3(value, {
  1648. outputLength: 256
  1649. }).toString();
  1650. };
  1651. },{"crypto-js":59,"crypto-js/sha3":80}],20:[function(require,module,exports){
  1652. /*
  1653. This file is part of web3.js.
  1654. web3.js is free software: you can redistribute it and/or modify
  1655. it under the terms of the GNU Lesser General Public License as published by
  1656. the Free Software Foundation, either version 3 of the License, or
  1657. (at your option) any later version.
  1658. web3.js is distributed in the hope that it will be useful,
  1659. but WITHOUT ANY WARRANTY; without even the implied warranty of
  1660. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  1661. GNU Lesser General Public License for more details.
  1662. You should have received a copy of the GNU Lesser General Public License
  1663. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  1664. */
  1665. /**
  1666. * @file utils.js
  1667. * @author Marek Kotewicz <marek@ethdev.com>
  1668. * @date 2015
  1669. */
  1670. /**
  1671. * Utils
  1672. *
  1673. * @module utils
  1674. */
  1675. /**
  1676. * Utility functions
  1677. *
  1678. * @class [utils] utils
  1679. * @constructor
  1680. */
  1681. var BigNumber = require('bignumber.js');
  1682. var sha3 = require('./sha3.js');
  1683. var utf8 = require('utf8');
  1684. var unitMap = {
  1685. 'noether': '0',
  1686. 'wei': '1',
  1687. 'kwei': '1000',
  1688. 'Kwei': '1000',
  1689. 'babbage': '1000',
  1690. 'femtoether': '1000',
  1691. 'mwei': '1000000',
  1692. 'Mwei': '1000000',
  1693. 'lovelace': '1000000',
  1694. 'picoether': '1000000',
  1695. 'gwei': '1000000000',
  1696. 'Gwei': '1000000000',
  1697. 'shannon': '1000000000',
  1698. 'nanoether': '1000000000',
  1699. 'nano': '1000000000',
  1700. 'szabo': '1000000000000',
  1701. 'microether': '1000000000000',
  1702. 'micro': '1000000000000',
  1703. 'finney': '1000000000000000',
  1704. 'milliether': '1000000000000000',
  1705. 'milli': '1000000000000000',
  1706. 'ether': '1000000000000000000',
  1707. 'kether': '1000000000000000000000',
  1708. 'grand': '1000000000000000000000',
  1709. 'mether': '1000000000000000000000000',
  1710. 'gether': '1000000000000000000000000000',
  1711. 'tether': '1000000000000000000000000000000'
  1712. };
  1713. /**
  1714. * Should be called to pad string to expected length
  1715. *
  1716. * @method padLeft
  1717. * @param {String} string to be padded
  1718. * @param {Number} characters that result string should have
  1719. * @param {String} sign, by default 0
  1720. * @returns {String} right aligned string
  1721. */
  1722. var padLeft = function (string, chars, sign) {
  1723. return new Array(chars - string.length + 1).join(sign ? sign : "0") + string;
  1724. };
  1725. /**
  1726. * Should be called to pad string to expected length
  1727. *
  1728. * @method padRight
  1729. * @param {String} string to be padded
  1730. * @param {Number} characters that result string should have
  1731. * @param {String} sign, by default 0
  1732. * @returns {String} right aligned string
  1733. */
  1734. var padRight = function (string, chars, sign) {
  1735. return string + (new Array(chars - string.length + 1).join(sign ? sign : "0"));
  1736. };
  1737. /**
  1738. * Should be called to get utf8 from it's hex representation
  1739. *
  1740. * @method toUtf8
  1741. * @param {String} string in hex
  1742. * @returns {String} ascii string representation of hex value
  1743. */
  1744. var toUtf8 = function(hex) {
  1745. // Find termination
  1746. var str = "";
  1747. var i = 0, l = hex.length;
  1748. if (hex.substring(0, 2) === '0x') {
  1749. i = 2;
  1750. }
  1751. for (; i < l; i+=2) {
  1752. var code = parseInt(hex.substr(i, 2), 16);
  1753. if (code === 0)
  1754. break;
  1755. str += String.fromCharCode(code);
  1756. }
  1757. return utf8.decode(str);
  1758. };
  1759. /**
  1760. * Should be called to get ascii from it's hex representation
  1761. *
  1762. * @method toAscii
  1763. * @param {String} string in hex
  1764. * @returns {String} ascii string representation of hex value
  1765. */
  1766. var toAscii = function(hex) {
  1767. // Find termination
  1768. var str = "";
  1769. var i = 0, l = hex.length;
  1770. if (hex.substring(0, 2) === '0x') {
  1771. i = 2;
  1772. }
  1773. for (; i < l; i+=2) {
  1774. var code = parseInt(hex.substr(i, 2), 16);
  1775. str += String.fromCharCode(code);
  1776. }
  1777. return str;
  1778. };
  1779. /**
  1780. * Should be called to get hex representation (prefixed by 0x) of utf8 string
  1781. *
  1782. * @method fromUtf8
  1783. * @param {String} string
  1784. * @param {Number} optional padding
  1785. * @returns {String} hex representation of input string
  1786. */
  1787. var fromUtf8 = function(str) {
  1788. str = utf8.encode(str);
  1789. var hex = "";
  1790. for(var i = 0; i < str.length; i++) {
  1791. var code = str.charCodeAt(i);
  1792. if (code === 0)
  1793. break;
  1794. var n = code.toString(16);
  1795. hex += n.length < 2 ? '0' + n : n;
  1796. }
  1797. return "0x" + hex;
  1798. };
  1799. /**
  1800. * Should be called to get hex representation (prefixed by 0x) of ascii string
  1801. *
  1802. * @method fromAscii
  1803. * @param {String} string
  1804. * @param {Number} optional padding
  1805. * @returns {String} hex representation of input string
  1806. */
  1807. var fromAscii = function(str) {
  1808. var hex = "";
  1809. for(var i = 0; i < str.length; i++) {
  1810. var code = str.charCodeAt(i);
  1811. var n = code.toString(16);
  1812. hex += n.length < 2 ? '0' + n : n;
  1813. }
  1814. return "0x" + hex;
  1815. };
  1816. /**
  1817. * Should be used to create full function/event name from json abi
  1818. *
  1819. * @method transformToFullName
  1820. * @param {Object} json-abi
  1821. * @return {String} full fnction/event name
  1822. */
  1823. var transformToFullName = function (json) {
  1824. if (json.name.indexOf('(') !== -1) {
  1825. return json.name;
  1826. }
  1827. var typeName = json.inputs.map(function(i){return i.type; }).join();
  1828. return json.name + '(' + typeName + ')';
  1829. };
  1830. /**
  1831. * Should be called to get display name of contract function
  1832. *
  1833. * @method extractDisplayName
  1834. * @param {String} name of function/event
  1835. * @returns {String} display name for function/event eg. multiply(uint256) -> multiply
  1836. */
  1837. var extractDisplayName = function (name) {
  1838. var length = name.indexOf('(');
  1839. return length !== -1 ? name.substr(0, length) : name;
  1840. };
  1841. /// @returns overloaded part of function/event name
  1842. var extractTypeName = function (name) {
  1843. /// TODO: make it invulnerable
  1844. var length = name.indexOf('(');
  1845. return length !== -1 ? name.substr(length + 1, name.length - 1 - (length + 1)).replace(' ', '') : "";
  1846. };
  1847. /**
  1848. * Converts value to it's decimal representation in string
  1849. *
  1850. * @method toDecimal
  1851. * @param {String|Number|BigNumber}
  1852. * @return {String}
  1853. */
  1854. var toDecimal = function (value) {
  1855. return toBigNumber(value).toNumber();
  1856. };
  1857. /**
  1858. * Converts value to it's hex representation
  1859. *
  1860. * @method fromDecimal
  1861. * @param {String|Number|BigNumber}
  1862. * @return {String}
  1863. */
  1864. var fromDecimal = function (value) {
  1865. var number = toBigNumber(value);
  1866. var result = number.toString(16);
  1867. return number.lessThan(0) ? '-0x' + result.substr(1) : '0x' + result;
  1868. };
  1869. /**
  1870. * Auto converts any given value into it's hex representation.
  1871. *
  1872. * And even stringifys objects before.
  1873. *
  1874. * @method toHex
  1875. * @param {String|Number|BigNumber|Object}
  1876. * @return {String}
  1877. */
  1878. var toHex = function (val) {
  1879. /*jshint maxcomplexity: 8 */
  1880. if (isBoolean(val))
  1881. return fromDecimal(+val);
  1882. if (isBigNumber(val))
  1883. return fromDecimal(val);
  1884. if (typeof val === 'object')
  1885. return fromUtf8(JSON.stringify(val));
  1886. // if its a negative number, pass it through fromDecimal
  1887. if (isString(val)) {
  1888. if (val.indexOf('-0x') === 0)
  1889. return fromDecimal(val);
  1890. else if(val.indexOf('0x') === 0)
  1891. return val;
  1892. else if (!isFinite(val))
  1893. return fromAscii(val);
  1894. }
  1895. return fromDecimal(val);
  1896. };
  1897. /**
  1898. * Returns value of unit in Wei
  1899. *
  1900. * @method getValueOfUnit
  1901. * @param {String} unit the unit to convert to, default ether
  1902. * @returns {BigNumber} value of the unit (in Wei)
  1903. * @throws error if the unit is not correct:w
  1904. */
  1905. var getValueOfUnit = function (unit) {
  1906. unit = unit ? unit.toLowerCase() : 'ether';
  1907. var unitValue = unitMap[unit];
  1908. if (unitValue === undefined) {
  1909. throw new Error('This unit doesn\'t exists, please use the one of the following units' + JSON.stringify(unitMap, null, 2));
  1910. }
  1911. return new BigNumber(unitValue, 10);
  1912. };
  1913. /**
  1914. * Takes a number of wei and converts it to any other ether unit.
  1915. *
  1916. * Possible units are:
  1917. * SI Short SI Full Effigy Other
  1918. * - kwei femtoether babbage
  1919. * - mwei picoether lovelace
  1920. * - gwei nanoether shannon nano
  1921. * - -- microether szabo micro
  1922. * - -- milliether finney milli
  1923. * - ether -- --
  1924. * - kether -- grand
  1925. * - mether
  1926. * - gether
  1927. * - tether
  1928. *
  1929. * @method fromWei
  1930. * @param {Number|String} number can be a number, number string or a HEX of a decimal
  1931. * @param {String} unit the unit to convert to, default ether
  1932. * @return {String|Object} When given a BigNumber object it returns one as well, otherwise a number
  1933. */
  1934. var fromWei = function(number, unit) {
  1935. var returnValue = toBigNumber(number).dividedBy(getValueOfUnit(unit));
  1936. return isBigNumber(number) ? returnValue : returnValue.toString(10);
  1937. };
  1938. /**
  1939. * Takes a number of a unit and converts it to wei.
  1940. *
  1941. * Possible units are:
  1942. * SI Short SI Full Effigy Other
  1943. * - kwei femtoether babbage
  1944. * - mwei picoether lovelace
  1945. * - gwei nanoether shannon nano
  1946. * - -- microether szabo micro
  1947. * - -- microether szabo micro
  1948. * - -- milliether finney milli
  1949. * - ether -- --
  1950. * - kether -- grand
  1951. * - mether
  1952. * - gether
  1953. * - tether
  1954. *
  1955. * @method toWei
  1956. * @param {Number|String|BigNumber} number can be a number, number string or a HEX of a decimal
  1957. * @param {String} unit the unit to convert from, default ether
  1958. * @return {String|Object} When given a BigNumber object it returns one as well, otherwise a number
  1959. */
  1960. var toWei = function(number, unit) {
  1961. var returnValue = toBigNumber(number).times(getValueOfUnit(unit));
  1962. return isBigNumber(number) ? returnValue : returnValue.toString(10);
  1963. };
  1964. /**
  1965. * Takes an input and transforms it into a bignumber
  1966. *
  1967. * @method toBigNumber
  1968. * @param {Number|String|BigNumber} a number, string, HEX string or BigNumber
  1969. * @return {BigNumber} BigNumber
  1970. */
  1971. var toBigNumber = function(number) {
  1972. /*jshint maxcomplexity:5 */
  1973. number = number || 0;
  1974. if (isBigNumber(number))
  1975. return number;
  1976. if (isString(number) && (number.indexOf('0x') === 0 || number.indexOf('-0x') === 0)) {
  1977. return new BigNumber(number.replace('0x',''), 16);
  1978. }
  1979. return new BigNumber(number.toString(10), 10);
  1980. };
  1981. /**
  1982. * Takes and input transforms it into bignumber and if it is negative value, into two's complement
  1983. *
  1984. * @method toTwosComplement
  1985. * @param {Number|String|BigNumber}
  1986. * @return {BigNumber}
  1987. */
  1988. var toTwosComplement = function (number) {
  1989. var bigNumber = toBigNumber(number).round();
  1990. if (bigNumber.lessThan(0)) {
  1991. return new BigNumber("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 16).plus(bigNumber).plus(1);
  1992. }
  1993. return bigNumber;
  1994. };
  1995. /**
  1996. * Checks if the given string is strictly an address
  1997. *
  1998. * @method isStrictAddress
  1999. * @param {String} address the given HEX address
  2000. * @return {Boolean}
  2001. */
  2002. var isStrictAddress = function (address) {
  2003. return /^0x[0-9a-f]{40}$/i.test(address);
  2004. };
  2005. /**
  2006. * Checks if the given string is an address
  2007. *
  2008. * @method isAddress
  2009. * @param {String} address the given HEX address
  2010. * @return {Boolean}
  2011. */
  2012. var isAddress = function (address) {
  2013. if (!/^(0x)?[0-9a-f]{40}$/i.test(address)) {
  2014. // check if it has the basic requirements of an address
  2015. return false;
  2016. } else if (/^(0x)?[0-9a-f]{40}$/.test(address) || /^(0x)?[0-9A-F]{40}$/.test(address)) {
  2017. // If it's all small caps or all caps, return true
  2018. return true;
  2019. } else {
  2020. // Otherwise check each case
  2021. return isChecksumAddress(address);
  2022. }
  2023. };
  2024. /**
  2025. * Checks if the given string is a checksummed address
  2026. *
  2027. * @method isChecksumAddress
  2028. * @param {String} address the given HEX address
  2029. * @return {Boolean}
  2030. */
  2031. var isChecksumAddress = function (address) {
  2032. // Check each case
  2033. address = address.replace('0x','');
  2034. var addressHash = sha3(address.toLowerCase());
  2035. for (var i = 0; i < 40; i++ ) {
  2036. // the nth letter should be uppercase if the nth digit of casemap is 1
  2037. if ((parseInt(addressHash[i], 16) > 7 && address[i].toUpperCase() !== address[i]) || (parseInt(addressHash[i], 16) <= 7 && address[i].toLowerCase() !== address[i])) {
  2038. return false;
  2039. }
  2040. }
  2041. return true;
  2042. };
  2043. /**
  2044. * Makes a checksum address
  2045. *
  2046. * @method toChecksumAddress
  2047. * @param {String} address the given HEX address
  2048. * @return {String}
  2049. */
  2050. var toChecksumAddress = function (address) {
  2051. if (typeof address === 'undefined') return '';
  2052. address = address.toLowerCase().replace('0x','');
  2053. var addressHash = sha3(address);
  2054. var checksumAddress = '0x';
  2055. for (var i = 0; i < address.length; i++ ) {
  2056. // If ith character is 9 to f then make it uppercase
  2057. if (parseInt(addressHash[i], 16) > 7) {
  2058. checksumAddress += address[i].toUpperCase();
  2059. } else {
  2060. checksumAddress += address[i];
  2061. }
  2062. }
  2063. return checksumAddress;
  2064. };
  2065. /**
  2066. * Transforms given string to valid 20 bytes-length addres with 0x prefix
  2067. *
  2068. * @method toAddress
  2069. * @param {String} address
  2070. * @return {String} formatted address
  2071. */
  2072. var toAddress = function (address) {
  2073. if (isStrictAddress(address)) {
  2074. return address;
  2075. }
  2076. if (/^[0-9a-f]{40}$/.test(address)) {
  2077. return '0x' + address;
  2078. }
  2079. return '0x' + padLeft(toHex(address).substr(2), 40);
  2080. };
  2081. /**
  2082. * Returns true if object is BigNumber, otherwise false
  2083. *
  2084. * @method isBigNumber
  2085. * @param {Object}
  2086. * @return {Boolean}
  2087. */
  2088. var isBigNumber = function (object) {
  2089. return object instanceof BigNumber ||
  2090. (object && object.constructor && object.constructor.name === 'BigNumber');
  2091. };
  2092. /**
  2093. * Returns true if object is string, otherwise false
  2094. *
  2095. * @method isString
  2096. * @param {Object}
  2097. * @return {Boolean}
  2098. */
  2099. var isString = function (object) {
  2100. return typeof object === 'string' ||
  2101. (object && object.constructor && object.constructor.name === 'String');
  2102. };
  2103. /**
  2104. * Returns true if object is function, otherwise false
  2105. *
  2106. * @method isFunction
  2107. * @param {Object}
  2108. * @return {Boolean}
  2109. */
  2110. var isFunction = function (object) {
  2111. return typeof object === 'function';
  2112. };
  2113. /**
  2114. * Returns true if object is Objet, otherwise false
  2115. *
  2116. * @method isObject
  2117. * @param {Object}
  2118. * @return {Boolean}
  2119. */
  2120. var isObject = function (object) {
  2121. return object !== null && !(object instanceof Array) && typeof object === 'object';
  2122. };
  2123. /**
  2124. * Returns true if object is boolean, otherwise false
  2125. *
  2126. * @method isBoolean
  2127. * @param {Object}
  2128. * @return {Boolean}
  2129. */
  2130. var isBoolean = function (object) {
  2131. return typeof object === 'boolean';
  2132. };
  2133. /**
  2134. * Returns true if object is array, otherwise false
  2135. *
  2136. * @method isArray
  2137. * @param {Object}
  2138. * @return {Boolean}
  2139. */
  2140. var isArray = function (object) {
  2141. return object instanceof Array;
  2142. };
  2143. /**
  2144. * Returns true if given string is valid json object
  2145. *
  2146. * @method isJson
  2147. * @param {String}
  2148. * @return {Boolean}
  2149. */
  2150. var isJson = function (str) {
  2151. try {
  2152. return !!JSON.parse(str);
  2153. } catch (e) {
  2154. return false;
  2155. }
  2156. };
  2157. /**
  2158. * Returns true if given string is a valid Ethereum block header bloom.
  2159. *
  2160. * @method isBloom
  2161. * @param {String} hex encoded bloom filter
  2162. * @return {Boolean}
  2163. */
  2164. var isBloom = function (bloom) {
  2165. if (!/^(0x)?[0-9a-f]{512}$/i.test(bloom)) {
  2166. return false;
  2167. } else if (/^(0x)?[0-9a-f]{512}$/.test(bloom) || /^(0x)?[0-9A-F]{512}$/.test(bloom)) {
  2168. return true;
  2169. }
  2170. return false;
  2171. };
  2172. /**
  2173. * Returns true if given string is a valid log topic.
  2174. *
  2175. * @method isTopic
  2176. * @param {String} hex encoded topic
  2177. * @return {Boolean}
  2178. */
  2179. var isTopic = function (topic) {
  2180. if (!/^(0x)?[0-9a-f]{64}$/i.test(topic)) {
  2181. return false;
  2182. } else if (/^(0x)?[0-9a-f]{64}$/.test(topic) || /^(0x)?[0-9A-F]{64}$/.test(topic)) {
  2183. return true;
  2184. }
  2185. return false;
  2186. };
  2187. module.exports = {
  2188. padLeft: padLeft,
  2189. padRight: padRight,
  2190. toHex: toHex,
  2191. toDecimal: toDecimal,
  2192. fromDecimal: fromDecimal,
  2193. toUtf8: toUtf8,
  2194. toAscii: toAscii,
  2195. fromUtf8: fromUtf8,
  2196. fromAscii: fromAscii,
  2197. transformToFullName: transformToFullName,
  2198. extractDisplayName: extractDisplayName,
  2199. extractTypeName: extractTypeName,
  2200. toWei: toWei,
  2201. fromWei: fromWei,
  2202. toBigNumber: toBigNumber,
  2203. toTwosComplement: toTwosComplement,
  2204. toAddress: toAddress,
  2205. isBigNumber: isBigNumber,
  2206. isStrictAddress: isStrictAddress,
  2207. isAddress: isAddress,
  2208. isChecksumAddress: isChecksumAddress,
  2209. toChecksumAddress: toChecksumAddress,
  2210. isFunction: isFunction,
  2211. isString: isString,
  2212. isObject: isObject,
  2213. isBoolean: isBoolean,
  2214. isArray: isArray,
  2215. isJson: isJson,
  2216. isBloom: isBloom,
  2217. isTopic: isTopic,
  2218. };
  2219. },{"./sha3.js":19,"bignumber.js":"bignumber.js","utf8":85}],21:[function(require,module,exports){
  2220. module.exports={
  2221. "version": "0.20.1"
  2222. }
  2223. },{}],22:[function(require,module,exports){
  2224. /*
  2225. This file is part of web3.js.
  2226. web3.js is free software: you can redistribute it and/or modify
  2227. it under the terms of the GNU Lesser General Public License as published by
  2228. the Free Software Foundation, either version 3 of the License, or
  2229. (at your option) any later version.
  2230. web3.js is distributed in the hope that it will be useful,
  2231. but WITHOUT ANY WARRANTY; without even the implied warranty of
  2232. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  2233. GNU Lesser General Public License for more details.
  2234. You should have received a copy of the GNU Lesser General Public License
  2235. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  2236. */
  2237. /**
  2238. * @file web3.js
  2239. * @authors:
  2240. * Jeffrey Wilcke <jeff@ethdev.com>
  2241. * Marek Kotewicz <marek@ethdev.com>
  2242. * Marian Oancea <marian@ethdev.com>
  2243. * Fabian Vogelsteller <fabian@ethdev.com>
  2244. * Gav Wood <g@ethdev.com>
  2245. * @date 2014
  2246. */
  2247. var RequestManager = require('./web3/requestmanager');
  2248. var Iban = require('./web3/iban');
  2249. var Eth = require('./web3/methods/eth');
  2250. var DB = require('./web3/methods/db');
  2251. var Shh = require('./web3/methods/shh');
  2252. var Net = require('./web3/methods/net');
  2253. var Personal = require('./web3/methods/personal');
  2254. var Swarm = require('./web3/methods/swarm');
  2255. var Settings = require('./web3/settings');
  2256. var version = require('./version.json');
  2257. var utils = require('./utils/utils');
  2258. var sha3 = require('./utils/sha3');
  2259. var extend = require('./web3/extend');
  2260. var Batch = require('./web3/batch');
  2261. var Property = require('./web3/property');
  2262. var HttpProvider = require('./web3/httpprovider');
  2263. var IpcProvider = require('./web3/ipcprovider');
  2264. var BigNumber = require('bignumber.js');
  2265. function Web3 (provider) {
  2266. this._requestManager = new RequestManager(provider);
  2267. this.currentProvider = provider;
  2268. this.eth = new Eth(this);
  2269. this.db = new DB(this);
  2270. this.shh = new Shh(this);
  2271. this.net = new Net(this);
  2272. this.personal = new Personal(this);
  2273. this.bzz = new Swarm(this);
  2274. this.settings = new Settings();
  2275. this.version = {
  2276. api: version.version
  2277. };
  2278. this.providers = {
  2279. HttpProvider: HttpProvider,
  2280. IpcProvider: IpcProvider
  2281. };
  2282. this._extend = extend(this);
  2283. this._extend({
  2284. properties: properties()
  2285. });
  2286. }
  2287. // expose providers on the class
  2288. Web3.providers = {
  2289. HttpProvider: HttpProvider,
  2290. IpcProvider: IpcProvider
  2291. };
  2292. Web3.prototype.setProvider = function (provider) {
  2293. this._requestManager.setProvider(provider);
  2294. this.currentProvider = provider;
  2295. };
  2296. Web3.prototype.reset = function (keepIsSyncing) {
  2297. this._requestManager.reset(keepIsSyncing);
  2298. this.settings = new Settings();
  2299. };
  2300. Web3.prototype.BigNumber = BigNumber;
  2301. Web3.prototype.toHex = utils.toHex;
  2302. Web3.prototype.toAscii = utils.toAscii;
  2303. Web3.prototype.toUtf8 = utils.toUtf8;
  2304. Web3.prototype.fromAscii = utils.fromAscii;
  2305. Web3.prototype.fromUtf8 = utils.fromUtf8;
  2306. Web3.prototype.toDecimal = utils.toDecimal;
  2307. Web3.prototype.fromDecimal = utils.fromDecimal;
  2308. Web3.prototype.toBigNumber = utils.toBigNumber;
  2309. Web3.prototype.toWei = utils.toWei;
  2310. Web3.prototype.fromWei = utils.fromWei;
  2311. Web3.prototype.isAddress = utils.isAddress;
  2312. Web3.prototype.isChecksumAddress = utils.isChecksumAddress;
  2313. Web3.prototype.toChecksumAddress = utils.toChecksumAddress;
  2314. Web3.prototype.isIBAN = utils.isIBAN;
  2315. Web3.prototype.padLeft = utils.padLeft;
  2316. Web3.prototype.padRight = utils.padRight;
  2317. Web3.prototype.sha3 = function(string, options) {
  2318. return '0x' + sha3(string, options);
  2319. };
  2320. /**
  2321. * Transforms direct icap to address
  2322. */
  2323. Web3.prototype.fromICAP = function (icap) {
  2324. var iban = new Iban(icap);
  2325. return iban.address();
  2326. };
  2327. var properties = function () {
  2328. return [
  2329. new Property({
  2330. name: 'version.node',
  2331. getter: 'web3_clientVersion'
  2332. }),
  2333. new Property({
  2334. name: 'version.network',
  2335. getter: 'net_version',
  2336. inputFormatter: utils.toDecimal
  2337. }),
  2338. new Property({
  2339. name: 'version.ethereum',
  2340. getter: 'eth_protocolVersion',
  2341. inputFormatter: utils.toDecimal
  2342. }),
  2343. new Property({
  2344. name: 'version.whisper',
  2345. getter: 'shh_version',
  2346. inputFormatter: utils.toDecimal
  2347. })
  2348. ];
  2349. };
  2350. Web3.prototype.isConnected = function(){
  2351. return (this.currentProvider && this.currentProvider.isConnected());
  2352. };
  2353. Web3.prototype.createBatch = function () {
  2354. return new Batch(this);
  2355. };
  2356. module.exports = Web3;
  2357. },{"./utils/sha3":19,"./utils/utils":20,"./version.json":21,"./web3/batch":24,"./web3/extend":28,"./web3/httpprovider":32,"./web3/iban":33,"./web3/ipcprovider":34,"./web3/methods/db":37,"./web3/methods/eth":38,"./web3/methods/net":39,"./web3/methods/personal":40,"./web3/methods/shh":41,"./web3/methods/swarm":42,"./web3/property":45,"./web3/requestmanager":46,"./web3/settings":47,"bignumber.js":"bignumber.js"}],23:[function(require,module,exports){
  2358. /*
  2359. This file is part of web3.js.
  2360. web3.js is free software: you can redistribute it and/or modify
  2361. it under the terms of the GNU Lesser General Public License as published by
  2362. the Free Software Foundation, either version 3 of the License, or
  2363. (at your option) any later version.
  2364. web3.js is distributed in the hope that it will be useful,
  2365. but WITHOUT ANY WARRANTY; without even the implied warranty of
  2366. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  2367. GNU Lesser General Public License for more details.
  2368. You should have received a copy of the GNU Lesser General Public License
  2369. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  2370. */
  2371. /**
  2372. * @file allevents.js
  2373. * @author Marek Kotewicz <marek@ethdev.com>
  2374. * @date 2014
  2375. */
  2376. var sha3 = require('../utils/sha3');
  2377. var SolidityEvent = require('./event');
  2378. var formatters = require('./formatters');
  2379. var utils = require('../utils/utils');
  2380. var Filter = require('./filter');
  2381. var watches = require('./methods/watches');
  2382. var AllSolidityEvents = function (requestManager, json, address) {
  2383. this._requestManager = requestManager;
  2384. this._json = json;
  2385. this._address = address;
  2386. };
  2387. AllSolidityEvents.prototype.encode = function (options) {
  2388. options = options || {};
  2389. var result = {};
  2390. ['fromBlock', 'toBlock'].filter(function (f) {
  2391. return options[f] !== undefined;
  2392. }).forEach(function (f) {
  2393. result[f] = formatters.inputBlockNumberFormatter(options[f]);
  2394. });
  2395. result.address = this._address;
  2396. return result;
  2397. };
  2398. AllSolidityEvents.prototype.decode = function (data) {
  2399. data.data = data.data || '';
  2400. data.topics = data.topics || [];
  2401. var eventTopic = data.topics[0].slice(2);
  2402. var match = this._json.filter(function (j) {
  2403. return eventTopic === sha3(utils.transformToFullName(j));
  2404. })[0];
  2405. if (!match) { // cannot find matching event?
  2406. console.warn('cannot find event for log');
  2407. return data;
  2408. }
  2409. var event = new SolidityEvent(this._requestManager, match, this._address);
  2410. return event.decode(data);
  2411. };
  2412. AllSolidityEvents.prototype.execute = function (options, callback) {
  2413. if (utils.isFunction(arguments[arguments.length - 1])) {
  2414. callback = arguments[arguments.length - 1];
  2415. if(arguments.length === 1)
  2416. options = null;
  2417. }
  2418. var o = this.encode(options);
  2419. var formatter = this.decode.bind(this);
  2420. return new Filter(o, 'eth', this._requestManager, watches.eth(), formatter, callback);
  2421. };
  2422. AllSolidityEvents.prototype.attachToContract = function (contract) {
  2423. var execute = this.execute.bind(this);
  2424. contract.allEvents = execute;
  2425. };
  2426. module.exports = AllSolidityEvents;
  2427. },{"../utils/sha3":19,"../utils/utils":20,"./event":27,"./filter":29,"./formatters":30,"./methods/watches":43}],24:[function(require,module,exports){
  2428. /*
  2429. This file is part of web3.js.
  2430. web3.js is free software: you can redistribute it and/or modify
  2431. it under the terms of the GNU Lesser General Public License as published by
  2432. the Free Software Foundation, either version 3 of the License, or
  2433. (at your option) any later version.
  2434. web3.js is distributed in the hope that it will be useful,
  2435. but WITHOUT ANY WARRANTY; without even the implied warranty of
  2436. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  2437. GNU Lesser General Public License for more details.
  2438. You should have received a copy of the GNU Lesser General Public License
  2439. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  2440. */
  2441. /**
  2442. * @file batch.js
  2443. * @author Marek Kotewicz <marek@ethdev.com>
  2444. * @date 2015
  2445. */
  2446. var Jsonrpc = require('./jsonrpc');
  2447. var errors = require('./errors');
  2448. var Batch = function (web3) {
  2449. this.requestManager = web3._requestManager;
  2450. this.requests = [];
  2451. };
  2452. /**
  2453. * Should be called to add create new request to batch request
  2454. *
  2455. * @method add
  2456. * @param {Object} jsonrpc requet object
  2457. */
  2458. Batch.prototype.add = function (request) {
  2459. this.requests.push(request);
  2460. };
  2461. /**
  2462. * Should be called to execute batch request
  2463. *
  2464. * @method execute
  2465. */
  2466. Batch.prototype.execute = function () {
  2467. var requests = this.requests;
  2468. this.requestManager.sendBatch(requests, function (err, results) {
  2469. results = results || [];
  2470. requests.map(function (request, index) {
  2471. return results[index] || {};
  2472. }).forEach(function (result, index) {
  2473. if (requests[index].callback) {
  2474. if (!Jsonrpc.isValidResponse(result)) {
  2475. return requests[index].callback(errors.InvalidResponse(result));
  2476. }
  2477. requests[index].callback(null, (requests[index].format ? requests[index].format(result.result) : result.result));
  2478. }
  2479. });
  2480. });
  2481. };
  2482. module.exports = Batch;
  2483. },{"./errors":26,"./jsonrpc":35}],25:[function(require,module,exports){
  2484. /*
  2485. This file is part of web3.js.
  2486. web3.js is free software: you can redistribute it and/or modify
  2487. it under the terms of the GNU Lesser General Public License as published by
  2488. the Free Software Foundation, either version 3 of the License, or
  2489. (at your option) any later version.
  2490. web3.js is distributed in the hope that it will be useful,
  2491. but WITHOUT ANY WARRANTY; without even the implied warranty of
  2492. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  2493. GNU Lesser General Public License for more details.
  2494. You should have received a copy of the GNU Lesser General Public License
  2495. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  2496. */
  2497. /**
  2498. * @file contract.js
  2499. * @author Marek Kotewicz <marek@ethdev.com>
  2500. * @date 2014
  2501. */
  2502. var utils = require('../utils/utils');
  2503. var coder = require('../solidity/coder');
  2504. var SolidityEvent = require('./event');
  2505. var SolidityFunction = require('./function');
  2506. var AllEvents = require('./allevents');
  2507. /**
  2508. * Should be called to encode constructor params
  2509. *
  2510. * @method encodeConstructorParams
  2511. * @param {Array} abi
  2512. * @param {Array} constructor params
  2513. */
  2514. var encodeConstructorParams = function (abi, params) {
  2515. return abi.filter(function (json) {
  2516. return json.type === 'constructor' && json.inputs.length === params.length;
  2517. }).map(function (json) {
  2518. return json.inputs.map(function (input) {
  2519. return input.type;
  2520. });
  2521. }).map(function (types) {
  2522. return coder.encodeParams(types, params);
  2523. })[0] || '';
  2524. };
  2525. /**
  2526. * Should be called to add functions to contract object
  2527. *
  2528. * @method addFunctionsToContract
  2529. * @param {Contract} contract
  2530. * @param {Array} abi
  2531. */
  2532. var addFunctionsToContract = function (contract) {
  2533. contract.abi.filter(function (json) {
  2534. return json.type === 'function';
  2535. }).map(function (json) {
  2536. return new SolidityFunction(contract._eth, json, contract.address);
  2537. }).forEach(function (f) {
  2538. f.attachToContract(contract);
  2539. });
  2540. };
  2541. /**
  2542. * Should be called to add events to contract object
  2543. *
  2544. * @method addEventsToContract
  2545. * @param {Contract} contract
  2546. * @param {Array} abi
  2547. */
  2548. var addEventsToContract = function (contract) {
  2549. var events = contract.abi.filter(function (json) {
  2550. return json.type === 'event';
  2551. });
  2552. var All = new AllEvents(contract._eth._requestManager, events, contract.address);
  2553. All.attachToContract(contract);
  2554. events.map(function (json) {
  2555. return new SolidityEvent(contract._eth._requestManager, json, contract.address);
  2556. }).forEach(function (e) {
  2557. e.attachToContract(contract);
  2558. });
  2559. };
  2560. /**
  2561. * Should be called to check if the contract gets properly deployed on the blockchain.
  2562. *
  2563. * @method checkForContractAddress
  2564. * @param {Object} contract
  2565. * @param {Function} callback
  2566. * @returns {Undefined}
  2567. */
  2568. var checkForContractAddress = function(contract, callback){
  2569. var count = 0,
  2570. callbackFired = false;
  2571. // wait for receipt
  2572. var filter = contract._eth.filter('latest', function(e){
  2573. if (!e && !callbackFired) {
  2574. count++;
  2575. // stop watching after 50 blocks (timeout)
  2576. if (count > 50) {
  2577. filter.stopWatching(function() {});
  2578. callbackFired = true;
  2579. if (callback)
  2580. callback(new Error('Contract transaction couldn\'t be found after 50 blocks'));
  2581. else
  2582. throw new Error('Contract transaction couldn\'t be found after 50 blocks');
  2583. } else {
  2584. contract._eth.getTransactionReceipt(contract.transactionHash, function(e, receipt){
  2585. if(receipt && !callbackFired) {
  2586. contract._eth.getCode(receipt.contractAddress, function(e, code){
  2587. /*jshint maxcomplexity: 6 */
  2588. if(callbackFired || !code)
  2589. return;
  2590. filter.stopWatching(function() {});
  2591. callbackFired = true;
  2592. if(code.length > 3) {
  2593. // console.log('Contract code deployed!');
  2594. contract.address = receipt.contractAddress;
  2595. // attach events and methods again after we have
  2596. addFunctionsToContract(contract);
  2597. addEventsToContract(contract);
  2598. // call callback for the second time
  2599. if(callback)
  2600. callback(null, contract);
  2601. } else {
  2602. if(callback)
  2603. callback(new Error('The contract code couldn\'t be stored, please check your gas amount.'));
  2604. else
  2605. throw new Error('The contract code couldn\'t be stored, please check your gas amount.');
  2606. }
  2607. });
  2608. }
  2609. });
  2610. }
  2611. }
  2612. });
  2613. };
  2614. /**
  2615. * Should be called to create new ContractFactory instance
  2616. *
  2617. * @method ContractFactory
  2618. * @param {Array} abi
  2619. */
  2620. var ContractFactory = function (eth, abi) {
  2621. this.eth = eth;
  2622. this.abi = abi;
  2623. /**
  2624. * Should be called to create new contract on a blockchain
  2625. *
  2626. * @method new
  2627. * @param {Any} contract constructor param1 (optional)
  2628. * @param {Any} contract constructor param2 (optional)
  2629. * @param {Object} contract transaction object (required)
  2630. * @param {Function} callback
  2631. * @returns {Contract} returns contract instance
  2632. */
  2633. this.new = function () {
  2634. /*jshint maxcomplexity: 7 */
  2635. var contract = new Contract(this.eth, this.abi);
  2636. // parse arguments
  2637. var options = {}; // required!
  2638. var callback;
  2639. var args = Array.prototype.slice.call(arguments);
  2640. if (utils.isFunction(args[args.length - 1])) {
  2641. callback = args.pop();
  2642. }
  2643. var last = args[args.length - 1];
  2644. if (utils.isObject(last) && !utils.isArray(last)) {
  2645. options = args.pop();
  2646. }
  2647. if (options.value > 0) {
  2648. var constructorAbi = abi.filter(function (json) {
  2649. return json.type === 'constructor' && json.inputs.length === args.length;
  2650. })[0] || {};
  2651. if (!constructorAbi.payable) {
  2652. throw new Error('Cannot send value to non-payable constructor');
  2653. }
  2654. }
  2655. var bytes = encodeConstructorParams(this.abi, args);
  2656. options.data += bytes;
  2657. if (callback) {
  2658. // wait for the contract address and check if the code was deployed
  2659. this.eth.sendTransaction(options, function (err, hash) {
  2660. if (err) {
  2661. callback(err);
  2662. } else {
  2663. // add the transaction hash
  2664. contract.transactionHash = hash;
  2665. // call callback for the first time
  2666. callback(null, contract);
  2667. checkForContractAddress(contract, callback);
  2668. }
  2669. });
  2670. } else {
  2671. var hash = this.eth.sendTransaction(options);
  2672. // add the transaction hash
  2673. contract.transactionHash = hash;
  2674. checkForContractAddress(contract);
  2675. }
  2676. return contract;
  2677. };
  2678. this.new.getData = this.getData.bind(this);
  2679. };
  2680. /**
  2681. * Should be called to create new ContractFactory
  2682. *
  2683. * @method contract
  2684. * @param {Array} abi
  2685. * @returns {ContractFactory} new contract factory
  2686. */
  2687. //var contract = function (abi) {
  2688. //return new ContractFactory(abi);
  2689. //};
  2690. /**
  2691. * Should be called to get access to existing contract on a blockchain
  2692. *
  2693. * @method at
  2694. * @param {Address} contract address (required)
  2695. * @param {Function} callback {optional)
  2696. * @returns {Contract} returns contract if no callback was passed,
  2697. * otherwise calls callback function (err, contract)
  2698. */
  2699. ContractFactory.prototype.at = function (address, callback) {
  2700. var contract = new Contract(this.eth, this.abi, address);
  2701. // this functions are not part of prototype,
  2702. // because we don't want to spoil the interface
  2703. addFunctionsToContract(contract);
  2704. addEventsToContract(contract);
  2705. if (callback) {
  2706. callback(null, contract);
  2707. }
  2708. return contract;
  2709. };
  2710. /**
  2711. * Gets the data, which is data to deploy plus constructor params
  2712. *
  2713. * @method getData
  2714. */
  2715. ContractFactory.prototype.getData = function () {
  2716. var options = {}; // required!
  2717. var args = Array.prototype.slice.call(arguments);
  2718. var last = args[args.length - 1];
  2719. if (utils.isObject(last) && !utils.isArray(last)) {
  2720. options = args.pop();
  2721. }
  2722. var bytes = encodeConstructorParams(this.abi, args);
  2723. options.data += bytes;
  2724. return options.data;
  2725. };
  2726. /**
  2727. * Should be called to create new contract instance
  2728. *
  2729. * @method Contract
  2730. * @param {Array} abi
  2731. * @param {Address} contract address
  2732. */
  2733. var Contract = function (eth, abi, address) {
  2734. this._eth = eth;
  2735. this.transactionHash = null;
  2736. this.address = address;
  2737. this.abi = abi;
  2738. };
  2739. module.exports = ContractFactory;
  2740. },{"../solidity/coder":7,"../utils/utils":20,"./allevents":23,"./event":27,"./function":31}],26:[function(require,module,exports){
  2741. /*
  2742. This file is part of web3.js.
  2743. web3.js is free software: you can redistribute it and/or modify
  2744. it under the terms of the GNU Lesser General Public License as published by
  2745. the Free Software Foundation, either version 3 of the License, or
  2746. (at your option) any later version.
  2747. web3.js is distributed in the hope that it will be useful,
  2748. but WITHOUT ANY WARRANTY; without even the implied warranty of
  2749. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  2750. GNU Lesser General Public License for more details.
  2751. You should have received a copy of the GNU Lesser General Public License
  2752. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  2753. */
  2754. /**
  2755. * @file errors.js
  2756. * @author Marek Kotewicz <marek@ethdev.com>
  2757. * @date 2015
  2758. */
  2759. module.exports = {
  2760. InvalidNumberOfSolidityArgs: function () {
  2761. return new Error('Invalid number of arguments to Solidity function');
  2762. },
  2763. InvalidNumberOfRPCParams: function () {
  2764. return new Error('Invalid number of input parameters to RPC method');
  2765. },
  2766. InvalidConnection: function (host){
  2767. return new Error('CONNECTION ERROR: Couldn\'t connect to node '+ host +'.');
  2768. },
  2769. InvalidProvider: function () {
  2770. return new Error('Provider not set or invalid');
  2771. },
  2772. InvalidResponse: function (result){
  2773. var message = !!result && !!result.error && !!result.error.message ? result.error.message : 'Invalid JSON RPC response: ' + JSON.stringify(result);
  2774. return new Error(message);
  2775. },
  2776. ConnectionTimeout: function (ms){
  2777. return new Error('CONNECTION TIMEOUT: timeout of ' + ms + ' ms achived');
  2778. }
  2779. };
  2780. },{}],27:[function(require,module,exports){
  2781. /*
  2782. This file is part of web3.js.
  2783. web3.js is free software: you can redistribute it and/or modify
  2784. it under the terms of the GNU Lesser General Public License as published by
  2785. the Free Software Foundation, either version 3 of the License, or
  2786. (at your option) any later version.
  2787. web3.js is distributed in the hope that it will be useful,
  2788. but WITHOUT ANY WARRANTY; without even the implied warranty of
  2789. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  2790. GNU Lesser General Public License for more details.
  2791. You should have received a copy of the GNU Lesser General Public License
  2792. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  2793. */
  2794. /**
  2795. * @file event.js
  2796. * @author Marek Kotewicz <marek@ethdev.com>
  2797. * @date 2014
  2798. */
  2799. var utils = require('../utils/utils');
  2800. var coder = require('../solidity/coder');
  2801. var formatters = require('./formatters');
  2802. var sha3 = require('../utils/sha3');
  2803. var Filter = require('./filter');
  2804. var watches = require('./methods/watches');
  2805. /**
  2806. * This prototype should be used to create event filters
  2807. */
  2808. var SolidityEvent = function (requestManager, json, address) {
  2809. this._requestManager = requestManager;
  2810. this._params = json.inputs;
  2811. this._name = utils.transformToFullName(json);
  2812. this._address = address;
  2813. this._anonymous = json.anonymous;
  2814. };
  2815. /**
  2816. * Should be used to get filtered param types
  2817. *
  2818. * @method types
  2819. * @param {Bool} decide if returned typed should be indexed
  2820. * @return {Array} array of types
  2821. */
  2822. SolidityEvent.prototype.types = function (indexed) {
  2823. return this._params.filter(function (i) {
  2824. return i.indexed === indexed;
  2825. }).map(function (i) {
  2826. return i.type;
  2827. });
  2828. };
  2829. /**
  2830. * Should be used to get event display name
  2831. *
  2832. * @method displayName
  2833. * @return {String} event display name
  2834. */
  2835. SolidityEvent.prototype.displayName = function () {
  2836. return utils.extractDisplayName(this._name);
  2837. };
  2838. /**
  2839. * Should be used to get event type name
  2840. *
  2841. * @method typeName
  2842. * @return {String} event type name
  2843. */
  2844. SolidityEvent.prototype.typeName = function () {
  2845. return utils.extractTypeName(this._name);
  2846. };
  2847. /**
  2848. * Should be used to get event signature
  2849. *
  2850. * @method signature
  2851. * @return {String} event signature
  2852. */
  2853. SolidityEvent.prototype.signature = function () {
  2854. return sha3(this._name);
  2855. };
  2856. /**
  2857. * Should be used to encode indexed params and options to one final object
  2858. *
  2859. * @method encode
  2860. * @param {Object} indexed
  2861. * @param {Object} options
  2862. * @return {Object} everything combined together and encoded
  2863. */
  2864. SolidityEvent.prototype.encode = function (indexed, options) {
  2865. indexed = indexed || {};
  2866. options = options || {};
  2867. var result = {};
  2868. ['fromBlock', 'toBlock'].filter(function (f) {
  2869. return options[f] !== undefined;
  2870. }).forEach(function (f) {
  2871. result[f] = formatters.inputBlockNumberFormatter(options[f]);
  2872. });
  2873. result.topics = [];
  2874. result.address = this._address;
  2875. if (!this._anonymous) {
  2876. result.topics.push('0x' + this.signature());
  2877. }
  2878. var indexedTopics = this._params.filter(function (i) {
  2879. return i.indexed === true;
  2880. }).map(function (i) {
  2881. var value = indexed[i.name];
  2882. if (value === undefined || value === null) {
  2883. return null;
  2884. }
  2885. if (utils.isArray(value)) {
  2886. return value.map(function (v) {
  2887. return '0x' + coder.encodeParam(i.type, v);
  2888. });
  2889. }
  2890. return '0x' + coder.encodeParam(i.type, value);
  2891. });
  2892. result.topics = result.topics.concat(indexedTopics);
  2893. return result;
  2894. };
  2895. /**
  2896. * Should be used to decode indexed params and options
  2897. *
  2898. * @method decode
  2899. * @param {Object} data
  2900. * @return {Object} result object with decoded indexed && not indexed params
  2901. */
  2902. SolidityEvent.prototype.decode = function (data) {
  2903. data.data = data.data || '';
  2904. data.topics = data.topics || [];
  2905. var argTopics = this._anonymous ? data.topics : data.topics.slice(1);
  2906. var indexedData = argTopics.map(function (topics) { return topics.slice(2); }).join("");
  2907. var indexedParams = coder.decodeParams(this.types(true), indexedData);
  2908. var notIndexedData = data.data.slice(2);
  2909. var notIndexedParams = coder.decodeParams(this.types(false), notIndexedData);
  2910. var result = formatters.outputLogFormatter(data);
  2911. result.event = this.displayName();
  2912. result.address = data.address;
  2913. result.args = this._params.reduce(function (acc, current) {
  2914. acc[current.name] = current.indexed ? indexedParams.shift() : notIndexedParams.shift();
  2915. return acc;
  2916. }, {});
  2917. delete result.data;
  2918. delete result.topics;
  2919. return result;
  2920. };
  2921. /**
  2922. * Should be used to create new filter object from event
  2923. *
  2924. * @method execute
  2925. * @param {Object} indexed
  2926. * @param {Object} options
  2927. * @return {Object} filter object
  2928. */
  2929. SolidityEvent.prototype.execute = function (indexed, options, callback) {
  2930. if (utils.isFunction(arguments[arguments.length - 1])) {
  2931. callback = arguments[arguments.length - 1];
  2932. if(arguments.length === 2)
  2933. options = null;
  2934. if(arguments.length === 1) {
  2935. options = null;
  2936. indexed = {};
  2937. }
  2938. }
  2939. var o = this.encode(indexed, options);
  2940. var formatter = this.decode.bind(this);
  2941. return new Filter(o, 'eth', this._requestManager, watches.eth(), formatter, callback);
  2942. };
  2943. /**
  2944. * Should be used to attach event to contract object
  2945. *
  2946. * @method attachToContract
  2947. * @param {Contract}
  2948. */
  2949. SolidityEvent.prototype.attachToContract = function (contract) {
  2950. var execute = this.execute.bind(this);
  2951. var displayName = this.displayName();
  2952. if (!contract[displayName]) {
  2953. contract[displayName] = execute;
  2954. }
  2955. contract[displayName][this.typeName()] = this.execute.bind(this, contract);
  2956. };
  2957. module.exports = SolidityEvent;
  2958. },{"../solidity/coder":7,"../utils/sha3":19,"../utils/utils":20,"./filter":29,"./formatters":30,"./methods/watches":43}],28:[function(require,module,exports){
  2959. var formatters = require('./formatters');
  2960. var utils = require('./../utils/utils');
  2961. var Method = require('./method');
  2962. var Property = require('./property');
  2963. // TODO: refactor, so the input params are not altered.
  2964. // it's necessary to make same 'extension' work with multiple providers
  2965. var extend = function (web3) {
  2966. /* jshint maxcomplexity:5 */
  2967. var ex = function (extension) {
  2968. var extendedObject;
  2969. if (extension.property) {
  2970. if (!web3[extension.property]) {
  2971. web3[extension.property] = {};
  2972. }
  2973. extendedObject = web3[extension.property];
  2974. } else {
  2975. extendedObject = web3;
  2976. }
  2977. if (extension.methods) {
  2978. extension.methods.forEach(function (method) {
  2979. method.attachToObject(extendedObject);
  2980. method.setRequestManager(web3._requestManager);
  2981. });
  2982. }
  2983. if (extension.properties) {
  2984. extension.properties.forEach(function (property) {
  2985. property.attachToObject(extendedObject);
  2986. property.setRequestManager(web3._requestManager);
  2987. });
  2988. }
  2989. };
  2990. ex.formatters = formatters;
  2991. ex.utils = utils;
  2992. ex.Method = Method;
  2993. ex.Property = Property;
  2994. return ex;
  2995. };
  2996. module.exports = extend;
  2997. },{"./../utils/utils":20,"./formatters":30,"./method":36,"./property":45}],29:[function(require,module,exports){
  2998. /*
  2999. This file is part of web3.js.
  3000. web3.js is free software: you can redistribute it and/or modify
  3001. it under the terms of the GNU Lesser General Public License as published by
  3002. the Free Software Foundation, either version 3 of the License, or
  3003. (at your option) any later version.
  3004. web3.js is distributed in the hope that it will be useful,
  3005. but WITHOUT ANY WARRANTY; without even the implied warranty of
  3006. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  3007. GNU Lesser General Public License for more details.
  3008. You should have received a copy of the GNU Lesser General Public License
  3009. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  3010. */
  3011. /** @file filter.js
  3012. * @authors:
  3013. * Jeffrey Wilcke <jeff@ethdev.com>
  3014. * Marek Kotewicz <marek@ethdev.com>
  3015. * Marian Oancea <marian@ethdev.com>
  3016. * Fabian Vogelsteller <fabian@ethdev.com>
  3017. * Gav Wood <g@ethdev.com>
  3018. * @date 2014
  3019. */
  3020. var formatters = require('./formatters');
  3021. var utils = require('../utils/utils');
  3022. /**
  3023. * Converts a given topic to a hex string, but also allows null values.
  3024. *
  3025. * @param {Mixed} value
  3026. * @return {String}
  3027. */
  3028. var toTopic = function(value){
  3029. if(value === null || typeof value === 'undefined')
  3030. return null;
  3031. value = String(value);
  3032. if(value.indexOf('0x') === 0)
  3033. return value;
  3034. else
  3035. return utils.fromUtf8(value);
  3036. };
  3037. /// This method should be called on options object, to verify deprecated properties && lazy load dynamic ones
  3038. /// @param should be string or object
  3039. /// @returns options string or object
  3040. var getOptions = function (options, type) {
  3041. /*jshint maxcomplexity: 6 */
  3042. if (utils.isString(options)) {
  3043. return options;
  3044. }
  3045. options = options || {};
  3046. switch(type) {
  3047. case 'eth':
  3048. // make sure topics, get converted to hex
  3049. options.topics = options.topics || [];
  3050. options.topics = options.topics.map(function(topic){
  3051. return (utils.isArray(topic)) ? topic.map(toTopic) : toTopic(topic);
  3052. });
  3053. return {
  3054. topics: options.topics,
  3055. from: options.from,
  3056. to: options.to,
  3057. address: options.address,
  3058. fromBlock: formatters.inputBlockNumberFormatter(options.fromBlock),
  3059. toBlock: formatters.inputBlockNumberFormatter(options.toBlock)
  3060. };
  3061. case 'shh':
  3062. return options;
  3063. }
  3064. };
  3065. /**
  3066. Adds the callback and sets up the methods, to iterate over the results.
  3067. @method getLogsAtStart
  3068. @param {Object} self
  3069. @param {function} callback
  3070. */
  3071. var getLogsAtStart = function(self, callback){
  3072. // call getFilterLogs for the first watch callback start
  3073. if (!utils.isString(self.options)) {
  3074. self.get(function (err, messages) {
  3075. // don't send all the responses to all the watches again... just to self one
  3076. if (err) {
  3077. callback(err);
  3078. }
  3079. if(utils.isArray(messages)) {
  3080. messages.forEach(function (message) {
  3081. callback(null, message);
  3082. });
  3083. }
  3084. });
  3085. }
  3086. };
  3087. /**
  3088. Adds the callback and sets up the methods, to iterate over the results.
  3089. @method pollFilter
  3090. @param {Object} self
  3091. */
  3092. var pollFilter = function(self) {
  3093. var onMessage = function (error, messages) {
  3094. if (error) {
  3095. return self.callbacks.forEach(function (callback) {
  3096. callback(error);
  3097. });
  3098. }
  3099. if(utils.isArray(messages)) {
  3100. messages.forEach(function (message) {
  3101. message = self.formatter ? self.formatter(message) : message;
  3102. self.callbacks.forEach(function (callback) {
  3103. callback(null, message);
  3104. });
  3105. });
  3106. }
  3107. };
  3108. self.requestManager.startPolling({
  3109. method: self.implementation.poll.call,
  3110. params: [self.filterId],
  3111. }, self.filterId, onMessage, self.stopWatching.bind(self));
  3112. };
  3113. var Filter = function (options, type, requestManager, methods, formatter, callback, filterCreationErrorCallback) {
  3114. var self = this;
  3115. var implementation = {};
  3116. methods.forEach(function (method) {
  3117. method.setRequestManager(requestManager);
  3118. method.attachToObject(implementation);
  3119. });
  3120. this.requestManager = requestManager;
  3121. this.options = getOptions(options, type);
  3122. this.implementation = implementation;
  3123. this.filterId = null;
  3124. this.callbacks = [];
  3125. this.getLogsCallbacks = [];
  3126. this.pollFilters = [];
  3127. this.formatter = formatter;
  3128. this.implementation.newFilter(this.options, function(error, id){
  3129. if(error) {
  3130. self.callbacks.forEach(function(cb){
  3131. cb(error);
  3132. });
  3133. if (typeof filterCreationErrorCallback === 'function') {
  3134. filterCreationErrorCallback(error);
  3135. }
  3136. } else {
  3137. self.filterId = id;
  3138. // check if there are get pending callbacks as a consequence
  3139. // of calling get() with filterId unassigned.
  3140. self.getLogsCallbacks.forEach(function (cb){
  3141. self.get(cb);
  3142. });
  3143. self.getLogsCallbacks = [];
  3144. // get filter logs for the already existing watch calls
  3145. self.callbacks.forEach(function(cb){
  3146. getLogsAtStart(self, cb);
  3147. });
  3148. if(self.callbacks.length > 0)
  3149. pollFilter(self);
  3150. // start to watch immediately
  3151. if(typeof callback === 'function') {
  3152. return self.watch(callback);
  3153. }
  3154. }
  3155. });
  3156. return this;
  3157. };
  3158. Filter.prototype.watch = function (callback) {
  3159. this.callbacks.push(callback);
  3160. if(this.filterId) {
  3161. getLogsAtStart(this, callback);
  3162. pollFilter(this);
  3163. }
  3164. return this;
  3165. };
  3166. Filter.prototype.stopWatching = function (callback) {
  3167. this.requestManager.stopPolling(this.filterId);
  3168. this.callbacks = [];
  3169. // remove filter async
  3170. if (callback) {
  3171. this.implementation.uninstallFilter(this.filterId, callback);
  3172. } else {
  3173. return this.implementation.uninstallFilter(this.filterId);
  3174. }
  3175. };
  3176. Filter.prototype.get = function (callback) {
  3177. var self = this;
  3178. if (utils.isFunction(callback)) {
  3179. if (this.filterId === null) {
  3180. // If filterId is not set yet, call it back
  3181. // when newFilter() assigns it.
  3182. this.getLogsCallbacks.push(callback);
  3183. } else {
  3184. this.implementation.getLogs(this.filterId, function(err, res){
  3185. if (err) {
  3186. callback(err);
  3187. } else {
  3188. callback(null, res.map(function (log) {
  3189. return self.formatter ? self.formatter(log) : log;
  3190. }));
  3191. }
  3192. });
  3193. }
  3194. } else {
  3195. if (this.filterId === null) {
  3196. throw new Error('Filter ID Error: filter().get() can\'t be chained synchronous, please provide a callback for the get() method.');
  3197. }
  3198. var logs = this.implementation.getLogs(this.filterId);
  3199. return logs.map(function (log) {
  3200. return self.formatter ? self.formatter(log) : log;
  3201. });
  3202. }
  3203. return this;
  3204. };
  3205. module.exports = Filter;
  3206. },{"../utils/utils":20,"./formatters":30}],30:[function(require,module,exports){
  3207. 'use strict'
  3208. /*
  3209. This file is part of web3.js.
  3210. web3.js is free software: you can redistribute it and/or modify
  3211. it under the terms of the GNU Lesser General Public License as published by
  3212. the Free Software Foundation, either version 3 of the License, or
  3213. (at your option) any later version.
  3214. web3.js is distributed in the hope that it will be useful,
  3215. but WITHOUT ANY WARRANTY; without even the implied warranty of
  3216. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  3217. GNU Lesser General Public License for more details.
  3218. You should have received a copy of the GNU Lesser General Public License
  3219. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  3220. */
  3221. /**
  3222. * @file formatters.js
  3223. * @author Marek Kotewicz <marek@ethdev.com>
  3224. * @author Fabian Vogelsteller <fabian@ethdev.com>
  3225. * @date 2015
  3226. */
  3227. var utils = require('../utils/utils');
  3228. var config = require('../utils/config');
  3229. var Iban = require('./iban');
  3230. /**
  3231. * Should the format output to a big number
  3232. *
  3233. * @method outputBigNumberFormatter
  3234. * @param {String|Number|BigNumber}
  3235. * @returns {BigNumber} object
  3236. */
  3237. var outputBigNumberFormatter = function (number) {
  3238. return utils.toBigNumber(number);
  3239. };
  3240. var isPredefinedBlockNumber = function (blockNumber) {
  3241. return blockNumber === 'latest' || blockNumber === 'pending' || blockNumber === 'earliest' || blockNumber === 'finalized' || blockNumber === 'safe';
  3242. };
  3243. var inputDefaultBlockNumberFormatter = function (blockNumber) {
  3244. if (blockNumber === undefined) {
  3245. return config.defaultBlock;
  3246. }
  3247. return inputBlockNumberFormatter(blockNumber);
  3248. };
  3249. var inputBlockNumberFormatter = function (blockNumber) {
  3250. if (blockNumber === undefined) {
  3251. return undefined;
  3252. } else if (isPredefinedBlockNumber(blockNumber)) {
  3253. return blockNumber;
  3254. }
  3255. return utils.toHex(blockNumber);
  3256. };
  3257. /**
  3258. * Formats the input of a transaction and converts all values to HEX
  3259. *
  3260. * @method inputCallFormatter
  3261. * @param {Object} transaction options
  3262. * @returns object
  3263. */
  3264. var inputCallFormatter = function (options){
  3265. options.from = options.from || config.defaultAccount;
  3266. if (options.from) {
  3267. options.from = inputAddressFormatter(options.from);
  3268. }
  3269. if (options.to) { // it might be contract creation
  3270. options.to = inputAddressFormatter(options.to);
  3271. }
  3272. ['maxFeePerGas', 'maxPriorityFeePerGas', 'gasPrice', 'gas', 'value', 'nonce'].filter(function (key) {
  3273. return options[key] !== undefined;
  3274. }).forEach(function(key){
  3275. options[key] = utils.fromDecimal(options[key]);
  3276. });
  3277. return options;
  3278. };
  3279. /**
  3280. * Formats the input of a transaction and converts all values to HEX
  3281. *
  3282. * @method inputTransactionFormatter
  3283. * @param {Object} transaction options
  3284. * @returns object
  3285. */
  3286. var inputTransactionFormatter = function (options){
  3287. options.from = options.from || config.defaultAccount;
  3288. options.from = inputAddressFormatter(options.from);
  3289. if (options.to) { // it might be contract creation
  3290. options.to = inputAddressFormatter(options.to);
  3291. }
  3292. ['maxFeePerGas', 'maxPriorityFeePerGas', 'gasPrice', 'gas', 'value', 'nonce'].filter(function (key) {
  3293. return options[key] !== undefined;
  3294. }).forEach(function(key){
  3295. options[key] = utils.fromDecimal(options[key]);
  3296. });
  3297. return options;
  3298. };
  3299. /**
  3300. * Formats the output of a transaction to its proper values
  3301. *
  3302. * @method outputTransactionFormatter
  3303. * @param {Object} tx
  3304. * @returns {Object}
  3305. */
  3306. var outputTransactionFormatter = function (tx){
  3307. if(tx.blockNumber !== null)
  3308. tx.blockNumber = utils.toDecimal(tx.blockNumber);
  3309. if(tx.transactionIndex !== null)
  3310. tx.transactionIndex = utils.toDecimal(tx.transactionIndex);
  3311. tx.nonce = utils.toDecimal(tx.nonce);
  3312. tx.gas = utils.toDecimal(tx.gas);
  3313. tx.gasPrice = utils.toBigNumber(tx.gasPrice);
  3314. if(tx.maxFeePerGas !== undefined) {
  3315. tx.maxFeePerGas = utils.toBigNumber(tx.maxFeePerGas);
  3316. }
  3317. if(tx.maxPriorityFeePerGas !== undefined) {
  3318. tx.maxPriorityFeePerGas = utils.toBigNumber(tx.maxPriorityFeePerGas);
  3319. }
  3320. tx.value = utils.toBigNumber(tx.value);
  3321. return tx;
  3322. };
  3323. /**
  3324. * Formats the output of a transaction receipt to its proper values
  3325. *
  3326. * @method outputTransactionReceiptFormatter
  3327. * @param {Object} receipt
  3328. * @returns {Object}
  3329. */
  3330. var outputTransactionReceiptFormatter = function (receipt){
  3331. if(receipt.blockNumber !== null)
  3332. receipt.blockNumber = utils.toDecimal(receipt.blockNumber);
  3333. if(receipt.transactionIndex !== null)
  3334. receipt.transactionIndex = utils.toDecimal(receipt.transactionIndex);
  3335. receipt.cumulativeGasUsed = utils.toDecimal(receipt.cumulativeGasUsed);
  3336. receipt.gasUsed = utils.toDecimal(receipt.gasUsed);
  3337. if(receipt.effectiveGasPrice !== undefined) {
  3338. receipt.effectiveGasPrice = utils.toBigNumber(receipt.effectiveGasPrice);
  3339. }
  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. if (block.baseFeePerGas !== undefined) {
  3357. block.baseFeePerGas = utils.toBigNumber(block.baseFeePerGas);
  3358. }
  3359. block.gasLimit = utils.toDecimal(block.gasLimit);
  3360. block.gasUsed = utils.toDecimal(block.gasUsed);
  3361. block.size = utils.toDecimal(block.size);
  3362. block.timestamp = utils.toDecimal(block.timestamp);
  3363. if(block.number !== null)
  3364. block.number = utils.toDecimal(block.number);
  3365. block.difficulty = utils.toBigNumber(block.difficulty);
  3366. block.totalDifficulty = utils.toBigNumber(block.totalDifficulty);
  3367. if (utils.isArray(block.transactions)) {
  3368. block.transactions.forEach(function(item){
  3369. if(!utils.isString(item))
  3370. return outputTransactionFormatter(item);
  3371. });
  3372. }
  3373. return block;
  3374. };
  3375. /**
  3376. * Formats the output of a log
  3377. *
  3378. * @method outputLogFormatter
  3379. * @param {Object} log object
  3380. * @returns {Object} log
  3381. */
  3382. var outputLogFormatter = function(log) {
  3383. if(log.blockNumber)
  3384. log.blockNumber = utils.toDecimal(log.blockNumber);
  3385. if(log.transactionIndex)
  3386. log.transactionIndex = utils.toDecimal(log.transactionIndex);
  3387. if(log.logIndex)
  3388. log.logIndex = utils.toDecimal(log.logIndex);
  3389. return log;
  3390. };
  3391. /**
  3392. * Formats the input of a whisper post and converts all values to HEX
  3393. *
  3394. * @method inputPostFormatter
  3395. * @param {Object} transaction object
  3396. * @returns {Object}
  3397. */
  3398. var inputPostFormatter = function(post) {
  3399. // post.payload = utils.toHex(post.payload);
  3400. post.ttl = utils.fromDecimal(post.ttl);
  3401. post.workToProve = utils.fromDecimal(post.workToProve);
  3402. post.priority = utils.fromDecimal(post.priority);
  3403. // fallback
  3404. if (!utils.isArray(post.topics)) {
  3405. post.topics = post.topics ? [post.topics] : [];
  3406. }
  3407. // format the following options
  3408. post.topics = post.topics.map(function(topic){
  3409. // convert only if not hex
  3410. return (topic.indexOf('0x') === 0) ? topic : utils.fromUtf8(topic);
  3411. });
  3412. return post;
  3413. };
  3414. /**
  3415. * Formats the output of a received post message
  3416. *
  3417. * @method outputPostFormatter
  3418. * @param {Object}
  3419. * @returns {Object}
  3420. */
  3421. var outputPostFormatter = function(post){
  3422. post.expiry = utils.toDecimal(post.expiry);
  3423. post.sent = utils.toDecimal(post.sent);
  3424. post.ttl = utils.toDecimal(post.ttl);
  3425. post.workProved = utils.toDecimal(post.workProved);
  3426. // post.payloadRaw = post.payload;
  3427. // post.payload = utils.toAscii(post.payload);
  3428. // if (utils.isJson(post.payload)) {
  3429. // post.payload = JSON.parse(post.payload);
  3430. // }
  3431. // format the following options
  3432. if (!post.topics) {
  3433. post.topics = [];
  3434. }
  3435. post.topics = post.topics.map(function(topic){
  3436. return utils.toAscii(topic);
  3437. });
  3438. return post;
  3439. };
  3440. var inputAddressFormatter = function (address) {
  3441. var iban = new Iban(address);
  3442. if (iban.isValid() && iban.isDirect()) {
  3443. return '0x' + iban.address();
  3444. } else if (utils.isStrictAddress(address)) {
  3445. return address;
  3446. } else if (utils.isAddress(address)) {
  3447. return '0x' + address;
  3448. }
  3449. throw new Error('invalid address');
  3450. };
  3451. var outputSyncingFormatter = function(result) {
  3452. if (!result) {
  3453. return result;
  3454. }
  3455. result.startingBlock = utils.toDecimal(result.startingBlock);
  3456. result.currentBlock = utils.toDecimal(result.currentBlock);
  3457. result.highestBlock = utils.toDecimal(result.highestBlock);
  3458. result.syncedAccounts = utils.toDecimal(result.syncedAccounts);
  3459. result.syncedAccountBytes = utils.toDecimal(result.syncedAccountBytes);
  3460. result.syncedBytecodes = utils.toDecimal(result.syncedBytecodes);
  3461. result.syncedBytecodeBytes = utils.toDecimal(result.syncedBytecodeBytes);
  3462. result.syncedStorage = utils.toDecimal(result.syncedStorage);
  3463. result.syncedStorageBytes = utils.toDecimal(result.syncedStorageBytes);
  3464. result.healedTrienodes = utils.toDecimal(result.healedTrienodes);
  3465. result.healedTrienodeBytes = utils.toDecimal(result.healedTrienodeBytes);
  3466. result.healedBytecodes = utils.toDecimal(result.healedBytecodes);
  3467. result.healedBytecodeBytes = utils.toDecimal(result.healedBytecodeBytes);
  3468. result.healingTrienodes = utils.toDecimal(result.healingTrienodes);
  3469. result.healingBytecode = utils.toDecimal(result.healingBytecode);
  3470. return result;
  3471. };
  3472. module.exports = {
  3473. inputDefaultBlockNumberFormatter: inputDefaultBlockNumberFormatter,
  3474. inputBlockNumberFormatter: inputBlockNumberFormatter,
  3475. inputCallFormatter: inputCallFormatter,
  3476. inputTransactionFormatter: inputTransactionFormatter,
  3477. inputAddressFormatter: inputAddressFormatter,
  3478. inputPostFormatter: inputPostFormatter,
  3479. outputBigNumberFormatter: outputBigNumberFormatter,
  3480. outputTransactionFormatter: outputTransactionFormatter,
  3481. outputTransactionReceiptFormatter: outputTransactionReceiptFormatter,
  3482. outputBlockFormatter: outputBlockFormatter,
  3483. outputLogFormatter: outputLogFormatter,
  3484. outputPostFormatter: outputPostFormatter,
  3485. outputSyncingFormatter: outputSyncingFormatter
  3486. };
  3487. },{"../utils/config":18,"../utils/utils":20,"./iban":33}],31:[function(require,module,exports){
  3488. /*
  3489. This file is part of web3.js.
  3490. web3.js is free software: you can redistribute it and/or modify
  3491. it under the terms of the GNU Lesser General Public License as published by
  3492. the Free Software Foundation, either version 3 of the License, or
  3493. (at your option) any later version.
  3494. web3.js is distributed in the hope that it will be useful,
  3495. but WITHOUT ANY WARRANTY; without even the implied warranty of
  3496. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  3497. GNU Lesser General Public License for more details.
  3498. You should have received a copy of the GNU Lesser General Public License
  3499. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  3500. */
  3501. /**
  3502. * @file function.js
  3503. * @author Marek Kotewicz <marek@ethdev.com>
  3504. * @date 2015
  3505. */
  3506. var coder = require('../solidity/coder');
  3507. var utils = require('../utils/utils');
  3508. var errors = require('./errors');
  3509. var formatters = require('./formatters');
  3510. var sha3 = require('../utils/sha3');
  3511. /**
  3512. * This prototype should be used to call/sendTransaction to solidity functions
  3513. */
  3514. var SolidityFunction = function (eth, json, address) {
  3515. this._eth = eth;
  3516. this._inputTypes = json.inputs.map(function (i) {
  3517. return i.type;
  3518. });
  3519. this._outputTypes = json.outputs.map(function (i) {
  3520. return i.type;
  3521. });
  3522. this._constant = json.constant;
  3523. this._payable = json.payable;
  3524. this._name = utils.transformToFullName(json);
  3525. this._address = address;
  3526. };
  3527. SolidityFunction.prototype.extractCallback = function (args) {
  3528. if (utils.isFunction(args[args.length - 1])) {
  3529. return args.pop(); // modify the args array!
  3530. }
  3531. };
  3532. SolidityFunction.prototype.extractDefaultBlock = function (args) {
  3533. if (args.length > this._inputTypes.length && !utils.isObject(args[args.length -1])) {
  3534. return formatters.inputDefaultBlockNumberFormatter(args.pop()); // modify the args array!
  3535. }
  3536. };
  3537. /**
  3538. * Should be called to check if the number of arguments is correct
  3539. *
  3540. * @method validateArgs
  3541. * @param {Array} arguments
  3542. * @throws {Error} if it is not
  3543. */
  3544. SolidityFunction.prototype.validateArgs = function (args) {
  3545. var inputArgs = args.filter(function (a) {
  3546. // filter the options object but not arguments that are arrays
  3547. return !( (utils.isObject(a) === true) &&
  3548. (utils.isArray(a) === false) &&
  3549. (utils.isBigNumber(a) === false)
  3550. );
  3551. });
  3552. if (inputArgs.length !== this._inputTypes.length) {
  3553. throw errors.InvalidNumberOfSolidityArgs();
  3554. }
  3555. };
  3556. /**
  3557. * Should be used to create payload from arguments
  3558. *
  3559. * @method toPayload
  3560. * @param {Array} solidity function params
  3561. * @param {Object} optional payload options
  3562. */
  3563. SolidityFunction.prototype.toPayload = function (args) {
  3564. var options = {};
  3565. if (args.length > this._inputTypes.length && utils.isObject(args[args.length -1])) {
  3566. options = args[args.length - 1];
  3567. }
  3568. this.validateArgs(args);
  3569. options.to = this._address;
  3570. options.data = '0x' + this.signature() + coder.encodeParams(this._inputTypes, args);
  3571. return options;
  3572. };
  3573. /**
  3574. * Should be used to get function signature
  3575. *
  3576. * @method signature
  3577. * @return {String} function signature
  3578. */
  3579. SolidityFunction.prototype.signature = function () {
  3580. return sha3(this._name).slice(0, 8);
  3581. };
  3582. SolidityFunction.prototype.unpackOutput = function (output) {
  3583. if (!output) {
  3584. return;
  3585. }
  3586. output = output.length >= 2 ? output.slice(2) : output;
  3587. var result = coder.decodeParams(this._outputTypes, output);
  3588. return result.length === 1 ? result[0] : result;
  3589. };
  3590. /**
  3591. * Calls a contract function.
  3592. *
  3593. * @method call
  3594. * @param {...Object} Contract function arguments
  3595. * @param {function} If the last argument is a function, the contract function
  3596. * call will be asynchronous, and the callback will be passed the
  3597. * error and result.
  3598. * @return {String} output bytes
  3599. */
  3600. SolidityFunction.prototype.call = function () {
  3601. var args = Array.prototype.slice.call(arguments).filter(function (a) {return a !== undefined; });
  3602. var callback = this.extractCallback(args);
  3603. var defaultBlock = this.extractDefaultBlock(args);
  3604. var payload = this.toPayload(args);
  3605. if (!callback) {
  3606. var output = this._eth.call(payload, defaultBlock);
  3607. return this.unpackOutput(output);
  3608. }
  3609. var self = this;
  3610. this._eth.call(payload, defaultBlock, function (error, output) {
  3611. if (error) return callback(error, null);
  3612. var unpacked = null;
  3613. try {
  3614. unpacked = self.unpackOutput(output);
  3615. }
  3616. catch (e) {
  3617. error = e;
  3618. }
  3619. callback(error, unpacked);
  3620. });
  3621. };
  3622. /**
  3623. * Should be used to sendTransaction to solidity function
  3624. *
  3625. * @method sendTransaction
  3626. */
  3627. SolidityFunction.prototype.sendTransaction = function () {
  3628. var args = Array.prototype.slice.call(arguments).filter(function (a) {return a !== undefined; });
  3629. var callback = this.extractCallback(args);
  3630. var payload = this.toPayload(args);
  3631. if (payload.value > 0 && !this._payable) {
  3632. throw new Error('Cannot send value to non-payable function');
  3633. }
  3634. if (!callback) {
  3635. return this._eth.sendTransaction(payload);
  3636. }
  3637. this._eth.sendTransaction(payload, callback);
  3638. };
  3639. /**
  3640. * Should be used to estimateGas of solidity function
  3641. *
  3642. * @method estimateGas
  3643. */
  3644. SolidityFunction.prototype.estimateGas = function () {
  3645. var args = Array.prototype.slice.call(arguments);
  3646. var callback = this.extractCallback(args);
  3647. var payload = this.toPayload(args);
  3648. if (!callback) {
  3649. return this._eth.estimateGas(payload);
  3650. }
  3651. this._eth.estimateGas(payload, callback);
  3652. };
  3653. /**
  3654. * Return the encoded data of the call
  3655. *
  3656. * @method getData
  3657. * @return {String} the encoded data
  3658. */
  3659. SolidityFunction.prototype.getData = function () {
  3660. var args = Array.prototype.slice.call(arguments);
  3661. var payload = this.toPayload(args);
  3662. return payload.data;
  3663. };
  3664. /**
  3665. * Should be used to get function display name
  3666. *
  3667. * @method displayName
  3668. * @return {String} display name of the function
  3669. */
  3670. SolidityFunction.prototype.displayName = function () {
  3671. return utils.extractDisplayName(this._name);
  3672. };
  3673. /**
  3674. * Should be used to get function type name
  3675. *
  3676. * @method typeName
  3677. * @return {String} type name of the function
  3678. */
  3679. SolidityFunction.prototype.typeName = function () {
  3680. return utils.extractTypeName(this._name);
  3681. };
  3682. /**
  3683. * Should be called to get rpc requests from solidity function
  3684. *
  3685. * @method request
  3686. * @returns {Object}
  3687. */
  3688. SolidityFunction.prototype.request = function () {
  3689. var args = Array.prototype.slice.call(arguments);
  3690. var callback = this.extractCallback(args);
  3691. var payload = this.toPayload(args);
  3692. var format = this.unpackOutput.bind(this);
  3693. return {
  3694. method: this._constant ? 'eth_call' : 'eth_sendTransaction',
  3695. callback: callback,
  3696. params: [payload],
  3697. format: format
  3698. };
  3699. };
  3700. /**
  3701. * Should be called to execute function
  3702. *
  3703. * @method execute
  3704. */
  3705. SolidityFunction.prototype.execute = function () {
  3706. var transaction = !this._constant;
  3707. // send transaction
  3708. if (transaction) {
  3709. return this.sendTransaction.apply(this, Array.prototype.slice.call(arguments));
  3710. }
  3711. // call
  3712. return this.call.apply(this, Array.prototype.slice.call(arguments));
  3713. };
  3714. /**
  3715. * Should be called to attach function to contract
  3716. *
  3717. * @method attachToContract
  3718. * @param {Contract}
  3719. */
  3720. SolidityFunction.prototype.attachToContract = function (contract) {
  3721. var execute = this.execute.bind(this);
  3722. execute.request = this.request.bind(this);
  3723. execute.call = this.call.bind(this);
  3724. execute.sendTransaction = this.sendTransaction.bind(this);
  3725. execute.estimateGas = this.estimateGas.bind(this);
  3726. execute.getData = this.getData.bind(this);
  3727. var displayName = this.displayName();
  3728. if (!contract[displayName]) {
  3729. contract[displayName] = execute;
  3730. }
  3731. contract[displayName][this.typeName()] = execute; // circular!!!!
  3732. };
  3733. module.exports = SolidityFunction;
  3734. },{"../solidity/coder":7,"../utils/sha3":19,"../utils/utils":20,"./errors":26,"./formatters":30}],32:[function(require,module,exports){
  3735. /*
  3736. This file is part of web3.js.
  3737. web3.js is free software: you can redistribute it and/or modify
  3738. it under the terms of the GNU Lesser General Public License as published by
  3739. the Free Software Foundation, either version 3 of the License, or
  3740. (at your option) any later version.
  3741. web3.js is distributed in the hope that it will be useful,
  3742. but WITHOUT ANY WARRANTY; without even the implied warranty of
  3743. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  3744. GNU Lesser General Public License for more details.
  3745. You should have received a copy of the GNU Lesser General Public License
  3746. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  3747. */
  3748. /** @file httpprovider.js
  3749. * @authors:
  3750. * Marek Kotewicz <marek@ethdev.com>
  3751. * Marian Oancea <marian@ethdev.com>
  3752. * Fabian Vogelsteller <fabian@ethdev.com>
  3753. * @date 2015
  3754. */
  3755. var errors = require('./errors');
  3756. // workaround to use httpprovider in different envs
  3757. // browser
  3758. if (typeof window !== 'undefined' && window.XMLHttpRequest) {
  3759. XMLHttpRequest = window.XMLHttpRequest; // jshint ignore: line
  3760. // node
  3761. } else {
  3762. XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest; // jshint ignore: line
  3763. }
  3764. var XHR2 = require('xhr2'); // jshint ignore: line
  3765. /**
  3766. * HttpProvider should be used to send rpc calls over http
  3767. */
  3768. var HttpProvider = function (host, timeout, user, password) {
  3769. this.host = host || 'http://localhost:8545';
  3770. this.timeout = timeout || 0;
  3771. this.user = user;
  3772. this.password = password;
  3773. };
  3774. /**
  3775. * Should be called to prepare new XMLHttpRequest
  3776. *
  3777. * @method prepareRequest
  3778. * @param {Boolean} true if request should be async
  3779. * @return {XMLHttpRequest} object
  3780. */
  3781. HttpProvider.prototype.prepareRequest = function (async) {
  3782. var request;
  3783. if (async) {
  3784. request = new XHR2();
  3785. request.timeout = this.timeout;
  3786. } else {
  3787. request = new XMLHttpRequest();
  3788. }
  3789. request.open('POST', this.host, async);
  3790. if (this.user && this.password) {
  3791. var auth = 'Basic ' + new Buffer(this.user + ':' + this.password).toString('base64');
  3792. request.setRequestHeader('Authorization', auth);
  3793. } request.setRequestHeader('Content-Type', 'application/json');
  3794. return request;
  3795. };
  3796. /**
  3797. * Should be called to make sync request
  3798. *
  3799. * @method send
  3800. * @param {Object} payload
  3801. * @return {Object} result
  3802. */
  3803. HttpProvider.prototype.send = function (payload) {
  3804. var request = this.prepareRequest(false);
  3805. try {
  3806. request.send(JSON.stringify(payload));
  3807. } catch (error) {
  3808. throw errors.InvalidConnection(this.host);
  3809. }
  3810. var result = request.responseText;
  3811. try {
  3812. result = JSON.parse(result);
  3813. } catch (e) {
  3814. throw errors.InvalidResponse(request.responseText);
  3815. }
  3816. return result;
  3817. };
  3818. /**
  3819. * Should be used to make async request
  3820. *
  3821. * @method sendAsync
  3822. * @param {Object} payload
  3823. * @param {Function} callback triggered on end with (err, result)
  3824. */
  3825. HttpProvider.prototype.sendAsync = function (payload, callback) {
  3826. var request = this.prepareRequest(true);
  3827. request.onreadystatechange = function () {
  3828. if (request.readyState === 4 && request.timeout !== 1) {
  3829. var result = request.responseText;
  3830. var error = null;
  3831. try {
  3832. result = JSON.parse(result);
  3833. } catch (e) {
  3834. error = errors.InvalidResponse(request.responseText);
  3835. }
  3836. callback(error, result);
  3837. }
  3838. };
  3839. request.ontimeout = function () {
  3840. callback(errors.ConnectionTimeout(this.timeout));
  3841. };
  3842. try {
  3843. request.send(JSON.stringify(payload));
  3844. } catch (error) {
  3845. callback(errors.InvalidConnection(this.host));
  3846. }
  3847. };
  3848. /**
  3849. * Synchronously tries to make Http request
  3850. *
  3851. * @method isConnected
  3852. * @return {Boolean} returns true if request haven't failed. Otherwise false
  3853. */
  3854. HttpProvider.prototype.isConnected = function () {
  3855. try {
  3856. this.send({
  3857. id: 9999999999,
  3858. jsonrpc: '2.0',
  3859. method: 'net_listening',
  3860. params: []
  3861. });
  3862. return true;
  3863. } catch (e) {
  3864. return false;
  3865. }
  3866. };
  3867. module.exports = HttpProvider;
  3868. },{"./errors":26,"xhr2":86,"xmlhttprequest":17}],33:[function(require,module,exports){
  3869. /*
  3870. This file is part of web3.js.
  3871. web3.js is free software: you can redistribute it and/or modify
  3872. it under the terms of the GNU Lesser General Public License as published by
  3873. the Free Software Foundation, either version 3 of the License, or
  3874. (at your option) any later version.
  3875. web3.js is distributed in the hope that it will be useful,
  3876. but WITHOUT ANY WARRANTY; without even the implied warranty of
  3877. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  3878. GNU Lesser General Public License for more details.
  3879. You should have received a copy of the GNU Lesser General Public License
  3880. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  3881. */
  3882. /**
  3883. * @file iban.js
  3884. * @author Marek Kotewicz <marek@ethdev.com>
  3885. * @date 2015
  3886. */
  3887. var BigNumber = require('bignumber.js');
  3888. var padLeft = function (string, bytes) {
  3889. var result = string;
  3890. while (result.length < bytes * 2) {
  3891. result = '0' + result;
  3892. }
  3893. return result;
  3894. };
  3895. /**
  3896. * Prepare an IBAN for mod 97 computation by moving the first 4 chars to the end and transforming the letters to
  3897. * numbers (A = 10, B = 11, ..., Z = 35), as specified in ISO13616.
  3898. *
  3899. * @method iso13616Prepare
  3900. * @param {String} iban the IBAN
  3901. * @returns {String} the prepared IBAN
  3902. */
  3903. var iso13616Prepare = function (iban) {
  3904. var A = 'A'.charCodeAt(0);
  3905. var Z = 'Z'.charCodeAt(0);
  3906. iban = iban.toUpperCase();
  3907. iban = iban.substr(4) + iban.substr(0,4);
  3908. return iban.split('').map(function(n){
  3909. var code = n.charCodeAt(0);
  3910. if (code >= A && code <= Z){
  3911. // A = 10, B = 11, ... Z = 35
  3912. return code - A + 10;
  3913. } else {
  3914. return n;
  3915. }
  3916. }).join('');
  3917. };
  3918. /**
  3919. * Calculates the MOD 97 10 of the passed IBAN as specified in ISO7064.
  3920. *
  3921. * @method mod9710
  3922. * @param {String} iban
  3923. * @returns {Number}
  3924. */
  3925. var mod9710 = function (iban) {
  3926. var remainder = iban,
  3927. block;
  3928. while (remainder.length > 2){
  3929. block = remainder.slice(0, 9);
  3930. remainder = parseInt(block, 10) % 97 + remainder.slice(block.length);
  3931. }
  3932. return parseInt(remainder, 10) % 97;
  3933. };
  3934. /**
  3935. * This prototype should be used to create iban object from iban correct string
  3936. *
  3937. * @param {String} iban
  3938. */
  3939. var Iban = function (iban) {
  3940. this._iban = iban;
  3941. };
  3942. /**
  3943. * This method should be used to create iban object from ethereum address
  3944. *
  3945. * @method fromAddress
  3946. * @param {String} address
  3947. * @return {Iban} the IBAN object
  3948. */
  3949. Iban.fromAddress = function (address) {
  3950. var asBn = new BigNumber(address, 16);
  3951. var base36 = asBn.toString(36);
  3952. var padded = padLeft(base36, 15);
  3953. return Iban.fromBban(padded.toUpperCase());
  3954. };
  3955. /**
  3956. * Convert the passed BBAN to an IBAN for this country specification.
  3957. * Please note that <i>"generation of the IBAN shall be the exclusive responsibility of the bank/branch servicing the account"</i>.
  3958. * This method implements the preferred algorithm described in http://en.wikipedia.org/wiki/International_Bank_Account_Number#Generating_IBAN_check_digits
  3959. *
  3960. * @method fromBban
  3961. * @param {String} bban the BBAN to convert to IBAN
  3962. * @returns {Iban} the IBAN object
  3963. */
  3964. Iban.fromBban = function (bban) {
  3965. var countryCode = 'XE';
  3966. var remainder = mod9710(iso13616Prepare(countryCode + '00' + bban));
  3967. var checkDigit = ('0' + (98 - remainder)).slice(-2);
  3968. return new Iban(countryCode + checkDigit + bban);
  3969. };
  3970. /**
  3971. * Should be used to create IBAN object for given institution and identifier
  3972. *
  3973. * @method createIndirect
  3974. * @param {Object} options, required options are "institution" and "identifier"
  3975. * @return {Iban} the IBAN object
  3976. */
  3977. Iban.createIndirect = function (options) {
  3978. return Iban.fromBban('ETH' + options.institution + options.identifier);
  3979. };
  3980. /**
  3981. * Thos method should be used to check if given string is valid iban object
  3982. *
  3983. * @method isValid
  3984. * @param {String} iban string
  3985. * @return {Boolean} true if it is valid IBAN
  3986. */
  3987. Iban.isValid = function (iban) {
  3988. var i = new Iban(iban);
  3989. return i.isValid();
  3990. };
  3991. /**
  3992. * Should be called to check if iban is correct
  3993. *
  3994. * @method isValid
  3995. * @returns {Boolean} true if it is, otherwise false
  3996. */
  3997. Iban.prototype.isValid = function () {
  3998. return /^XE[0-9]{2}(ETH[0-9A-Z]{13}|[0-9A-Z]{30,31})$/.test(this._iban) &&
  3999. mod9710(iso13616Prepare(this._iban)) === 1;
  4000. };
  4001. /**
  4002. * Should be called to check if iban number is direct
  4003. *
  4004. * @method isDirect
  4005. * @returns {Boolean} true if it is, otherwise false
  4006. */
  4007. Iban.prototype.isDirect = function () {
  4008. return this._iban.length === 34 || this._iban.length === 35;
  4009. };
  4010. /**
  4011. * Should be called to check if iban number if indirect
  4012. *
  4013. * @method isIndirect
  4014. * @returns {Boolean} true if it is, otherwise false
  4015. */
  4016. Iban.prototype.isIndirect = function () {
  4017. return this._iban.length === 20;
  4018. };
  4019. /**
  4020. * Should be called to get iban checksum
  4021. * Uses the mod-97-10 checksumming protocol (ISO/IEC 7064:2003)
  4022. *
  4023. * @method checksum
  4024. * @returns {String} checksum
  4025. */
  4026. Iban.prototype.checksum = function () {
  4027. return this._iban.substr(2, 2);
  4028. };
  4029. /**
  4030. * Should be called to get institution identifier
  4031. * eg. XREG
  4032. *
  4033. * @method institution
  4034. * @returns {String} institution identifier
  4035. */
  4036. Iban.prototype.institution = function () {
  4037. return this.isIndirect() ? this._iban.substr(7, 4) : '';
  4038. };
  4039. /**
  4040. * Should be called to get client identifier within institution
  4041. * eg. GAVOFYORK
  4042. *
  4043. * @method client
  4044. * @returns {String} client identifier
  4045. */
  4046. Iban.prototype.client = function () {
  4047. return this.isIndirect() ? this._iban.substr(11) : '';
  4048. };
  4049. /**
  4050. * Should be called to get client direct address
  4051. *
  4052. * @method address
  4053. * @returns {String} client direct address
  4054. */
  4055. Iban.prototype.address = function () {
  4056. if (this.isDirect()) {
  4057. var base36 = this._iban.substr(4);
  4058. var asBn = new BigNumber(base36, 36);
  4059. return padLeft(asBn.toString(16), 20);
  4060. }
  4061. return '';
  4062. };
  4063. Iban.prototype.toString = function () {
  4064. return this._iban;
  4065. };
  4066. module.exports = Iban;
  4067. },{"bignumber.js":"bignumber.js"}],34:[function(require,module,exports){
  4068. /*
  4069. This file is part of web3.js.
  4070. web3.js is free software: you can redistribute it and/or modify
  4071. it under the terms of the GNU Lesser General Public License as published by
  4072. the Free Software Foundation, either version 3 of the License, or
  4073. (at your option) any later version.
  4074. web3.js is distributed in the hope that it will be useful,
  4075. but WITHOUT ANY WARRANTY; without even the implied warranty of
  4076. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  4077. GNU Lesser General Public License for more details.
  4078. You should have received a copy of the GNU Lesser General Public License
  4079. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  4080. */
  4081. /** @file ipcprovider.js
  4082. * @authors:
  4083. * Fabian Vogelsteller <fabian@ethdev.com>
  4084. * @date 2015
  4085. */
  4086. "use strict";
  4087. var utils = require('../utils/utils');
  4088. var errors = require('./errors');
  4089. var IpcProvider = function (path, net) {
  4090. var _this = this;
  4091. this.responseCallbacks = {};
  4092. this.path = path;
  4093. this.connection = net.connect({path: this.path});
  4094. this.connection.on('error', function(e){
  4095. console.error('IPC Connection Error', e);
  4096. _this._timeout();
  4097. });
  4098. this.connection.on('end', function(){
  4099. _this._timeout();
  4100. });
  4101. // LISTEN FOR CONNECTION RESPONSES
  4102. this.connection.on('data', function(data) {
  4103. /*jshint maxcomplexity: 6 */
  4104. _this._parseResponse(data.toString()).forEach(function(result){
  4105. var id = null;
  4106. // get the id which matches the returned id
  4107. if(utils.isArray(result)) {
  4108. result.forEach(function(load){
  4109. if(_this.responseCallbacks[load.id])
  4110. id = load.id;
  4111. });
  4112. } else {
  4113. id = result.id;
  4114. }
  4115. // fire the callback
  4116. if(_this.responseCallbacks[id]) {
  4117. _this.responseCallbacks[id](null, result);
  4118. delete _this.responseCallbacks[id];
  4119. }
  4120. });
  4121. });
  4122. };
  4123. /**
  4124. Will parse the response and make an array out of it.
  4125. @method _parseResponse
  4126. @param {String} data
  4127. */
  4128. IpcProvider.prototype._parseResponse = function(data) {
  4129. var _this = this,
  4130. returnValues = [];
  4131. // DE-CHUNKER
  4132. var dechunkedData = data
  4133. .replace(/\}[\n\r]?\{/g,'}|--|{') // }{
  4134. .replace(/\}\][\n\r]?\[\{/g,'}]|--|[{') // }][{
  4135. .replace(/\}[\n\r]?\[\{/g,'}|--|[{') // }[{
  4136. .replace(/\}\][\n\r]?\{/g,'}]|--|{') // }]{
  4137. .split('|--|');
  4138. dechunkedData.forEach(function(data){
  4139. // prepend the last chunk
  4140. if(_this.lastChunk)
  4141. data = _this.lastChunk + data;
  4142. var result = null;
  4143. try {
  4144. result = JSON.parse(data);
  4145. } catch(e) {
  4146. _this.lastChunk = data;
  4147. // start timeout to cancel all requests
  4148. clearTimeout(_this.lastChunkTimeout);
  4149. _this.lastChunkTimeout = setTimeout(function(){
  4150. _this._timeout();
  4151. throw errors.InvalidResponse(data);
  4152. }, 1000 * 15);
  4153. return;
  4154. }
  4155. // cancel timeout and set chunk to null
  4156. clearTimeout(_this.lastChunkTimeout);
  4157. _this.lastChunk = null;
  4158. if(result)
  4159. returnValues.push(result);
  4160. });
  4161. return returnValues;
  4162. };
  4163. /**
  4164. Get the adds a callback to the responseCallbacks object,
  4165. which will be called if a response matching the response Id will arrive.
  4166. @method _addResponseCallback
  4167. */
  4168. IpcProvider.prototype._addResponseCallback = function(payload, callback) {
  4169. var id = payload.id || payload[0].id;
  4170. var method = payload.method || payload[0].method;
  4171. this.responseCallbacks[id] = callback;
  4172. this.responseCallbacks[id].method = method;
  4173. };
  4174. /**
  4175. Timeout all requests when the end/error event is fired
  4176. @method _timeout
  4177. */
  4178. IpcProvider.prototype._timeout = function() {
  4179. for(var key in this.responseCallbacks) {
  4180. if(this.responseCallbacks.hasOwnProperty(key)){
  4181. this.responseCallbacks[key](errors.InvalidConnection('on IPC'));
  4182. delete this.responseCallbacks[key];
  4183. }
  4184. }
  4185. };
  4186. /**
  4187. Check if the current connection is still valid.
  4188. @method isConnected
  4189. */
  4190. IpcProvider.prototype.isConnected = function() {
  4191. var _this = this;
  4192. // try reconnect, when connection is gone
  4193. if(!_this.connection.writable)
  4194. _this.connection.connect({path: _this.path});
  4195. return !!this.connection.writable;
  4196. };
  4197. IpcProvider.prototype.send = function (payload) {
  4198. if(this.connection.writeSync) {
  4199. var result;
  4200. // try reconnect, when connection is gone
  4201. if(!this.connection.writable)
  4202. this.connection.connect({path: this.path});
  4203. var data = this.connection.writeSync(JSON.stringify(payload));
  4204. try {
  4205. result = JSON.parse(data);
  4206. } catch(e) {
  4207. throw errors.InvalidResponse(data);
  4208. }
  4209. return result;
  4210. } else {
  4211. throw new Error('You tried to send "'+ payload.method +'" synchronously. Synchronous requests are not supported by the IPC provider.');
  4212. }
  4213. };
  4214. IpcProvider.prototype.sendAsync = function (payload, callback) {
  4215. // try reconnect, when connection is gone
  4216. if(!this.connection.writable)
  4217. this.connection.connect({path: this.path});
  4218. this.connection.write(JSON.stringify(payload));
  4219. this._addResponseCallback(payload, callback);
  4220. };
  4221. module.exports = IpcProvider;
  4222. },{"../utils/utils":20,"./errors":26}],35:[function(require,module,exports){
  4223. /*
  4224. This file is part of web3.js.
  4225. web3.js is free software: you can redistribute it and/or modify
  4226. it under the terms of the GNU Lesser General Public License as published by
  4227. the Free Software Foundation, either version 3 of the License, or
  4228. (at your option) any later version.
  4229. web3.js is distributed in the hope that it will be useful,
  4230. but WITHOUT ANY WARRANTY; without even the implied warranty of
  4231. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  4232. GNU Lesser General Public License for more details.
  4233. You should have received a copy of the GNU Lesser General Public License
  4234. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  4235. */
  4236. /** @file jsonrpc.js
  4237. * @authors:
  4238. * Marek Kotewicz <marek@ethdev.com>
  4239. * Aaron Kumavis <aaron@kumavis.me>
  4240. * @date 2015
  4241. */
  4242. // Initialize Jsonrpc as a simple object with utility functions.
  4243. var Jsonrpc = {
  4244. messageId: 0
  4245. };
  4246. /**
  4247. * Should be called to valid json create payload object
  4248. *
  4249. * @method toPayload
  4250. * @param {Function} method of jsonrpc call, required
  4251. * @param {Array} params, an array of method params, optional
  4252. * @returns {Object} valid jsonrpc payload object
  4253. */
  4254. Jsonrpc.toPayload = function (method, params) {
  4255. if (!method)
  4256. console.error('jsonrpc method should be specified!');
  4257. // advance message ID
  4258. Jsonrpc.messageId++;
  4259. return {
  4260. jsonrpc: '2.0',
  4261. id: Jsonrpc.messageId,
  4262. method: method,
  4263. params: params || []
  4264. };
  4265. };
  4266. /**
  4267. * Should be called to check if jsonrpc response is valid
  4268. *
  4269. * @method isValidResponse
  4270. * @param {Object}
  4271. * @returns {Boolean} true if response is valid, otherwise false
  4272. */
  4273. Jsonrpc.isValidResponse = function (response) {
  4274. return Array.isArray(response) ? response.every(validateSingleMessage) : validateSingleMessage(response);
  4275. function validateSingleMessage(message){
  4276. return !!message &&
  4277. !message.error &&
  4278. message.jsonrpc === '2.0' &&
  4279. typeof message.id === 'number' &&
  4280. message.result !== undefined; // only undefined is not valid json object
  4281. }
  4282. };
  4283. /**
  4284. * Should be called to create batch payload object
  4285. *
  4286. * @method toBatchPayload
  4287. * @param {Array} messages, an array of objects with method (required) and params (optional) fields
  4288. * @returns {Array} batch payload
  4289. */
  4290. Jsonrpc.toBatchPayload = function (messages) {
  4291. return messages.map(function (message) {
  4292. return Jsonrpc.toPayload(message.method, message.params);
  4293. });
  4294. };
  4295. module.exports = Jsonrpc;
  4296. },{}],36:[function(require,module,exports){
  4297. /*
  4298. This file is part of web3.js.
  4299. web3.js is free software: you can redistribute it and/or modify
  4300. it under the terms of the GNU Lesser General Public License as published by
  4301. the Free Software Foundation, either version 3 of the License, or
  4302. (at your option) any later version.
  4303. web3.js is distributed in the hope that it will be useful,
  4304. but WITHOUT ANY WARRANTY; without even the implied warranty of
  4305. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  4306. GNU Lesser General Public License for more details.
  4307. You should have received a copy of the GNU Lesser General Public License
  4308. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  4309. */
  4310. /**
  4311. * @file method.js
  4312. * @author Marek Kotewicz <marek@ethdev.com>
  4313. * @date 2015
  4314. */
  4315. var utils = require('../utils/utils');
  4316. var errors = require('./errors');
  4317. var Method = function (options) {
  4318. this.name = options.name;
  4319. this.call = options.call;
  4320. this.params = options.params || 0;
  4321. this.inputFormatter = options.inputFormatter;
  4322. this.outputFormatter = options.outputFormatter;
  4323. this.requestManager = null;
  4324. };
  4325. Method.prototype.setRequestManager = function (rm) {
  4326. this.requestManager = rm;
  4327. };
  4328. /**
  4329. * Should be used to determine name of the jsonrpc method based on arguments
  4330. *
  4331. * @method getCall
  4332. * @param {Array} arguments
  4333. * @return {String} name of jsonrpc method
  4334. */
  4335. Method.prototype.getCall = function (args) {
  4336. return utils.isFunction(this.call) ? this.call(args) : this.call;
  4337. };
  4338. /**
  4339. * Should be used to extract callback from array of arguments. Modifies input param
  4340. *
  4341. * @method extractCallback
  4342. * @param {Array} arguments
  4343. * @return {Function|Null} callback, if exists
  4344. */
  4345. Method.prototype.extractCallback = function (args) {
  4346. if (utils.isFunction(args[args.length - 1])) {
  4347. return args.pop(); // modify the args array!
  4348. }
  4349. };
  4350. /**
  4351. * Should be called to check if the number of arguments is correct
  4352. *
  4353. * @method validateArgs
  4354. * @param {Array} arguments
  4355. * @throws {Error} if it is not
  4356. */
  4357. Method.prototype.validateArgs = function (args) {
  4358. if (args.length !== this.params) {
  4359. throw errors.InvalidNumberOfRPCParams();
  4360. }
  4361. };
  4362. /**
  4363. * Should be called to format input args of method
  4364. *
  4365. * @method formatInput
  4366. * @param {Array}
  4367. * @return {Array}
  4368. */
  4369. Method.prototype.formatInput = function (args) {
  4370. if (!this.inputFormatter) {
  4371. return args;
  4372. }
  4373. return this.inputFormatter.map(function (formatter, index) {
  4374. return formatter ? formatter(args[index]) : args[index];
  4375. });
  4376. };
  4377. /**
  4378. * Should be called to format output(result) of method
  4379. *
  4380. * @method formatOutput
  4381. * @param {Object}
  4382. * @return {Object}
  4383. */
  4384. Method.prototype.formatOutput = function (result) {
  4385. return this.outputFormatter && result ? this.outputFormatter(result) : result;
  4386. };
  4387. /**
  4388. * Should create payload from given input args
  4389. *
  4390. * @method toPayload
  4391. * @param {Array} args
  4392. * @return {Object}
  4393. */
  4394. Method.prototype.toPayload = function (args) {
  4395. var call = this.getCall(args);
  4396. var callback = this.extractCallback(args);
  4397. var params = this.formatInput(args);
  4398. this.validateArgs(params);
  4399. return {
  4400. method: call,
  4401. params: params,
  4402. callback: callback
  4403. };
  4404. };
  4405. Method.prototype.attachToObject = function (obj) {
  4406. var func = this.buildCall();
  4407. func.call = this.call; // TODO!!! that's ugly. filter.js uses it
  4408. var name = this.name.split('.');
  4409. if (name.length > 1) {
  4410. obj[name[0]] = obj[name[0]] || {};
  4411. obj[name[0]][name[1]] = func;
  4412. } else {
  4413. obj[name[0]] = func;
  4414. }
  4415. };
  4416. Method.prototype.buildCall = function() {
  4417. var method = this;
  4418. var send = function () {
  4419. var payload = method.toPayload(Array.prototype.slice.call(arguments));
  4420. if (payload.callback) {
  4421. return method.requestManager.sendAsync(payload, function (err, result) {
  4422. payload.callback(err, method.formatOutput(result));
  4423. });
  4424. }
  4425. return method.formatOutput(method.requestManager.send(payload));
  4426. };
  4427. send.request = this.request.bind(this);
  4428. return send;
  4429. };
  4430. /**
  4431. * Should be called to create pure JSONRPC request which can be used in batch request
  4432. *
  4433. * @method request
  4434. * @param {...} params
  4435. * @return {Object} jsonrpc request
  4436. */
  4437. Method.prototype.request = function () {
  4438. var payload = this.toPayload(Array.prototype.slice.call(arguments));
  4439. payload.format = this.formatOutput.bind(this);
  4440. return payload;
  4441. };
  4442. module.exports = Method;
  4443. },{"../utils/utils":20,"./errors":26}],37:[function(require,module,exports){
  4444. /*
  4445. This file is part of web3.js.
  4446. web3.js is free software: you can redistribute it and/or modify
  4447. it under the terms of the GNU Lesser General Public License as published by
  4448. the Free Software Foundation, either version 3 of the License, or
  4449. (at your option) any later version.
  4450. web3.js is distributed in the hope that it will be useful,
  4451. but WITHOUT ANY WARRANTY; without even the implied warranty of
  4452. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  4453. GNU Lesser General Public License for more details.
  4454. You should have received a copy of the GNU Lesser General Public License
  4455. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  4456. */
  4457. /** @file db.js
  4458. * @authors:
  4459. * Marek Kotewicz <marek@ethdev.com>
  4460. * @date 2015
  4461. */
  4462. var Method = require('../method');
  4463. var DB = function (web3) {
  4464. this._requestManager = web3._requestManager;
  4465. var self = this;
  4466. methods().forEach(function(method) {
  4467. method.attachToObject(self);
  4468. method.setRequestManager(web3._requestManager);
  4469. });
  4470. };
  4471. var methods = function () {
  4472. var putString = new Method({
  4473. name: 'putString',
  4474. call: 'db_putString',
  4475. params: 3
  4476. });
  4477. var getString = new Method({
  4478. name: 'getString',
  4479. call: 'db_getString',
  4480. params: 2
  4481. });
  4482. var putHex = new Method({
  4483. name: 'putHex',
  4484. call: 'db_putHex',
  4485. params: 3
  4486. });
  4487. var getHex = new Method({
  4488. name: 'getHex',
  4489. call: 'db_getHex',
  4490. params: 2
  4491. });
  4492. return [
  4493. putString, getString, putHex, getHex
  4494. ];
  4495. };
  4496. module.exports = DB;
  4497. },{"../method":36}],38:[function(require,module,exports){
  4498. /*
  4499. This file is part of web3.js.
  4500. web3.js is free software: you can redistribute it and/or modify
  4501. it under the terms of the GNU Lesser General Public License as published by
  4502. the Free Software Foundation, either version 3 of the License, or
  4503. (at your option) any later version.
  4504. web3.js is distributed in the hope that it will be useful,
  4505. but WITHOUT ANY WARRANTY; without even the implied warranty of
  4506. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  4507. GNU Lesser General Public License for more details.
  4508. You should have received a copy of the GNU Lesser General Public License
  4509. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  4510. */
  4511. /**
  4512. * @file eth.js
  4513. * @author Marek Kotewicz <marek@ethdev.com>
  4514. * @author Fabian Vogelsteller <fabian@ethdev.com>
  4515. * @date 2015
  4516. */
  4517. "use strict";
  4518. var formatters = require('../formatters');
  4519. var utils = require('../../utils/utils');
  4520. var Method = require('../method');
  4521. var Property = require('../property');
  4522. var c = require('../../utils/config');
  4523. var Contract = require('../contract');
  4524. var watches = require('./watches');
  4525. var Filter = require('../filter');
  4526. var IsSyncing = require('../syncing');
  4527. var namereg = require('../namereg');
  4528. var Iban = require('../iban');
  4529. var transfer = require('../transfer');
  4530. var blockCall = function (args) {
  4531. return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? "eth_getBlockByHash" : "eth_getBlockByNumber";
  4532. };
  4533. var transactionFromBlockCall = function (args) {
  4534. return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getTransactionByBlockHashAndIndex' : 'eth_getTransactionByBlockNumberAndIndex';
  4535. };
  4536. var uncleCall = function (args) {
  4537. return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getUncleByBlockHashAndIndex' : 'eth_getUncleByBlockNumberAndIndex';
  4538. };
  4539. var getBlockTransactionCountCall = function (args) {
  4540. return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getBlockTransactionCountByHash' : 'eth_getBlockTransactionCountByNumber';
  4541. };
  4542. var uncleCountCall = function (args) {
  4543. return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getUncleCountByBlockHash' : 'eth_getUncleCountByBlockNumber';
  4544. };
  4545. function Eth(web3) {
  4546. this._requestManager = web3._requestManager;
  4547. var self = this;
  4548. methods().forEach(function(method) {
  4549. method.attachToObject(self);
  4550. method.setRequestManager(self._requestManager);
  4551. });
  4552. properties().forEach(function(p) {
  4553. p.attachToObject(self);
  4554. p.setRequestManager(self._requestManager);
  4555. });
  4556. this.iban = Iban;
  4557. this.sendIBANTransaction = transfer.bind(null, this);
  4558. }
  4559. Object.defineProperty(Eth.prototype, 'defaultBlock', {
  4560. get: function () {
  4561. return c.defaultBlock;
  4562. },
  4563. set: function (val) {
  4564. c.defaultBlock = val;
  4565. return val;
  4566. }
  4567. });
  4568. Object.defineProperty(Eth.prototype, 'defaultAccount', {
  4569. get: function () {
  4570. return c.defaultAccount;
  4571. },
  4572. set: function (val) {
  4573. c.defaultAccount = val;
  4574. return val;
  4575. }
  4576. });
  4577. var methods = function () {
  4578. var getBalance = new Method({
  4579. name: 'getBalance',
  4580. call: 'eth_getBalance',
  4581. params: 2,
  4582. inputFormatter: [formatters.inputAddressFormatter, formatters.inputDefaultBlockNumberFormatter],
  4583. outputFormatter: formatters.outputBigNumberFormatter
  4584. });
  4585. var getStorageAt = new Method({
  4586. name: 'getStorageAt',
  4587. call: 'eth_getStorageAt',
  4588. params: 3,
  4589. inputFormatter: [null, utils.toHex, formatters.inputDefaultBlockNumberFormatter]
  4590. });
  4591. var getCode = new Method({
  4592. name: 'getCode',
  4593. call: 'eth_getCode',
  4594. params: 2,
  4595. inputFormatter: [formatters.inputAddressFormatter, formatters.inputDefaultBlockNumberFormatter]
  4596. });
  4597. var getBlock = new Method({
  4598. name: 'getBlock',
  4599. call: blockCall,
  4600. params: 2,
  4601. inputFormatter: [formatters.inputBlockNumberFormatter, function (val) { return !!val; }],
  4602. outputFormatter: formatters.outputBlockFormatter
  4603. });
  4604. var getUncle = new Method({
  4605. name: 'getUncle',
  4606. call: uncleCall,
  4607. params: 2,
  4608. inputFormatter: [formatters.inputBlockNumberFormatter, utils.toHex],
  4609. outputFormatter: formatters.outputBlockFormatter,
  4610. });
  4611. var getCompilers = new Method({
  4612. name: 'getCompilers',
  4613. call: 'eth_getCompilers',
  4614. params: 0
  4615. });
  4616. var getBlockTransactionCount = new Method({
  4617. name: 'getBlockTransactionCount',
  4618. call: getBlockTransactionCountCall,
  4619. params: 1,
  4620. inputFormatter: [formatters.inputBlockNumberFormatter],
  4621. outputFormatter: utils.toDecimal
  4622. });
  4623. var getBlockUncleCount = new Method({
  4624. name: 'getBlockUncleCount',
  4625. call: uncleCountCall,
  4626. params: 1,
  4627. inputFormatter: [formatters.inputBlockNumberFormatter],
  4628. outputFormatter: utils.toDecimal
  4629. });
  4630. var getTransaction = new Method({
  4631. name: 'getTransaction',
  4632. call: 'eth_getTransactionByHash',
  4633. params: 1,
  4634. outputFormatter: formatters.outputTransactionFormatter
  4635. });
  4636. var getTransactionFromBlock = new Method({
  4637. name: 'getTransactionFromBlock',
  4638. call: transactionFromBlockCall,
  4639. params: 2,
  4640. inputFormatter: [formatters.inputBlockNumberFormatter, utils.toHex],
  4641. outputFormatter: formatters.outputTransactionFormatter
  4642. });
  4643. var getTransactionReceipt = new Method({
  4644. name: 'getTransactionReceipt',
  4645. call: 'eth_getTransactionReceipt',
  4646. params: 1,
  4647. outputFormatter: formatters.outputTransactionReceiptFormatter
  4648. });
  4649. var getTransactionCount = new Method({
  4650. name: 'getTransactionCount',
  4651. call: 'eth_getTransactionCount',
  4652. params: 2,
  4653. inputFormatter: [null, formatters.inputDefaultBlockNumberFormatter],
  4654. outputFormatter: utils.toDecimal
  4655. });
  4656. var sendRawTransaction = new Method({
  4657. name: 'sendRawTransaction',
  4658. call: 'eth_sendRawTransaction',
  4659. params: 1,
  4660. inputFormatter: [null]
  4661. });
  4662. var sendTransaction = new Method({
  4663. name: 'sendTransaction',
  4664. call: 'eth_sendTransaction',
  4665. params: 1,
  4666. inputFormatter: [formatters.inputTransactionFormatter]
  4667. });
  4668. var signTransaction = new Method({
  4669. name: 'signTransaction',
  4670. call: 'eth_signTransaction',
  4671. params: 1,
  4672. inputFormatter: [formatters.inputTransactionFormatter]
  4673. });
  4674. var sign = new Method({
  4675. name: 'sign',
  4676. call: 'eth_sign',
  4677. params: 2,
  4678. inputFormatter: [formatters.inputAddressFormatter, null]
  4679. });
  4680. var call = new Method({
  4681. name: 'call',
  4682. call: 'eth_call',
  4683. params: 2,
  4684. inputFormatter: [formatters.inputCallFormatter, formatters.inputDefaultBlockNumberFormatter]
  4685. });
  4686. var estimateGas = new Method({
  4687. name: 'estimateGas',
  4688. call: 'eth_estimateGas',
  4689. params: 1,
  4690. inputFormatter: [formatters.inputCallFormatter],
  4691. outputFormatter: utils.toDecimal
  4692. });
  4693. var compileSolidity = new Method({
  4694. name: 'compile.solidity',
  4695. call: 'eth_compileSolidity',
  4696. params: 1
  4697. });
  4698. var compileLLL = new Method({
  4699. name: 'compile.lll',
  4700. call: 'eth_compileLLL',
  4701. params: 1
  4702. });
  4703. var compileSerpent = new Method({
  4704. name: 'compile.serpent',
  4705. call: 'eth_compileSerpent',
  4706. params: 1
  4707. });
  4708. var submitWork = new Method({
  4709. name: 'submitWork',
  4710. call: 'eth_submitWork',
  4711. params: 3
  4712. });
  4713. var getWork = new Method({
  4714. name: 'getWork',
  4715. call: 'eth_getWork',
  4716. params: 0
  4717. });
  4718. return [
  4719. getBalance,
  4720. getStorageAt,
  4721. getCode,
  4722. getBlock,
  4723. getUncle,
  4724. getCompilers,
  4725. getBlockTransactionCount,
  4726. getBlockUncleCount,
  4727. getTransaction,
  4728. getTransactionFromBlock,
  4729. getTransactionReceipt,
  4730. getTransactionCount,
  4731. call,
  4732. estimateGas,
  4733. sendRawTransaction,
  4734. signTransaction,
  4735. sendTransaction,
  4736. sign,
  4737. compileSolidity,
  4738. compileLLL,
  4739. compileSerpent,
  4740. submitWork,
  4741. getWork
  4742. ];
  4743. };
  4744. var properties = function () {
  4745. return [
  4746. new Property({
  4747. name: 'coinbase',
  4748. getter: 'eth_coinbase'
  4749. }),
  4750. new Property({
  4751. name: 'mining',
  4752. getter: 'eth_mining'
  4753. }),
  4754. new Property({
  4755. name: 'hashrate',
  4756. getter: 'eth_hashrate',
  4757. outputFormatter: utils.toDecimal
  4758. }),
  4759. new Property({
  4760. name: 'syncing',
  4761. getter: 'eth_syncing',
  4762. outputFormatter: formatters.outputSyncingFormatter
  4763. }),
  4764. new Property({
  4765. name: 'gasPrice',
  4766. getter: 'eth_gasPrice',
  4767. outputFormatter: formatters.outputBigNumberFormatter
  4768. }),
  4769. new Property({
  4770. name: 'accounts',
  4771. getter: 'eth_accounts'
  4772. }),
  4773. new Property({
  4774. name: 'blockNumber',
  4775. getter: 'eth_blockNumber',
  4776. outputFormatter: utils.toDecimal
  4777. }),
  4778. new Property({
  4779. name: 'protocolVersion',
  4780. getter: 'eth_protocolVersion'
  4781. })
  4782. ];
  4783. };
  4784. Eth.prototype.contract = function (abi) {
  4785. var factory = new Contract(this, abi);
  4786. return factory;
  4787. };
  4788. Eth.prototype.filter = function (options, callback, filterCreationErrorCallback) {
  4789. return new Filter(options, 'eth', this._requestManager, watches.eth(), formatters.outputLogFormatter, callback, filterCreationErrorCallback);
  4790. };
  4791. Eth.prototype.namereg = function () {
  4792. return this.contract(namereg.global.abi).at(namereg.global.address);
  4793. };
  4794. Eth.prototype.icapNamereg = function () {
  4795. return this.contract(namereg.icap.abi).at(namereg.icap.address);
  4796. };
  4797. Eth.prototype.isSyncing = function (callback) {
  4798. return new IsSyncing(this._requestManager, callback);
  4799. };
  4800. module.exports = Eth;
  4801. },{"../../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){
  4802. /*
  4803. This file is part of web3.js.
  4804. web3.js is free software: you can redistribute it and/or modify
  4805. it under the terms of the GNU Lesser General Public License as published by
  4806. the Free Software Foundation, either version 3 of the License, or
  4807. (at your option) any later version.
  4808. web3.js is distributed in the hope that it will be useful,
  4809. but WITHOUT ANY WARRANTY; without even the implied warranty of
  4810. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  4811. GNU Lesser General Public License for more details.
  4812. You should have received a copy of the GNU Lesser General Public License
  4813. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  4814. */
  4815. /** @file eth.js
  4816. * @authors:
  4817. * Marek Kotewicz <marek@ethdev.com>
  4818. * @date 2015
  4819. */
  4820. var utils = require('../../utils/utils');
  4821. var Property = require('../property');
  4822. var Net = function (web3) {
  4823. this._requestManager = web3._requestManager;
  4824. var self = this;
  4825. properties().forEach(function(p) {
  4826. p.attachToObject(self);
  4827. p.setRequestManager(web3._requestManager);
  4828. });
  4829. };
  4830. /// @returns an array of objects describing web3.eth api properties
  4831. var properties = function () {
  4832. return [
  4833. new Property({
  4834. name: 'listening',
  4835. getter: 'net_listening'
  4836. }),
  4837. new Property({
  4838. name: 'peerCount',
  4839. getter: 'net_peerCount',
  4840. outputFormatter: utils.toDecimal
  4841. })
  4842. ];
  4843. };
  4844. module.exports = Net;
  4845. },{"../../utils/utils":20,"../property":45}],40:[function(require,module,exports){
  4846. /*
  4847. This file is part of web3.js.
  4848. web3.js is free software: you can redistribute it and/or modify
  4849. it under the terms of the GNU Lesser General Public License as published by
  4850. the Free Software Foundation, either version 3 of the License, or
  4851. (at your option) any later version.
  4852. web3.js is distributed in the hope that it will be useful,
  4853. but WITHOUT ANY WARRANTY; without even the implied warranty of
  4854. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  4855. GNU Lesser General Public License for more details.
  4856. You should have received a copy of the GNU Lesser General Public License
  4857. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  4858. */
  4859. /**
  4860. * @file eth.js
  4861. * @author Marek Kotewicz <marek@ethdev.com>
  4862. * @author Fabian Vogelsteller <fabian@ethdev.com>
  4863. * @date 2015
  4864. */
  4865. "use strict";
  4866. var Method = require('../method');
  4867. var Property = require('../property');
  4868. var formatters = require('../formatters');
  4869. function Personal(web3) {
  4870. this._requestManager = web3._requestManager;
  4871. var self = this;
  4872. methods().forEach(function(method) {
  4873. method.attachToObject(self);
  4874. method.setRequestManager(self._requestManager);
  4875. });
  4876. properties().forEach(function(p) {
  4877. p.attachToObject(self);
  4878. p.setRequestManager(self._requestManager);
  4879. });
  4880. }
  4881. var methods = function () {
  4882. var newAccount = new Method({
  4883. name: 'newAccount',
  4884. call: 'personal_newAccount',
  4885. params: 1,
  4886. inputFormatter: [null]
  4887. });
  4888. var importRawKey = new Method({
  4889. name: 'importRawKey',
  4890. call: 'personal_importRawKey',
  4891. params: 2
  4892. });
  4893. var sign = new Method({
  4894. name: 'sign',
  4895. call: 'personal_sign',
  4896. params: 3,
  4897. inputFormatter: [null, formatters.inputAddressFormatter, null]
  4898. });
  4899. var ecRecover = new Method({
  4900. name: 'ecRecover',
  4901. call: 'personal_ecRecover',
  4902. params: 2
  4903. });
  4904. var unlockAccount = new Method({
  4905. name: 'unlockAccount',
  4906. call: 'personal_unlockAccount',
  4907. params: 3,
  4908. inputFormatter: [formatters.inputAddressFormatter, null, null]
  4909. });
  4910. var sendTransaction = new Method({
  4911. name: 'sendTransaction',
  4912. call: 'personal_sendTransaction',
  4913. params: 2,
  4914. inputFormatter: [formatters.inputTransactionFormatter, null]
  4915. });
  4916. var lockAccount = new Method({
  4917. name: 'lockAccount',
  4918. call: 'personal_lockAccount',
  4919. params: 1,
  4920. inputFormatter: [formatters.inputAddressFormatter]
  4921. });
  4922. return [
  4923. newAccount,
  4924. importRawKey,
  4925. unlockAccount,
  4926. ecRecover,
  4927. sign,
  4928. sendTransaction,
  4929. lockAccount
  4930. ];
  4931. };
  4932. var properties = function () {
  4933. return [
  4934. new Property({
  4935. name: 'listAccounts',
  4936. getter: 'personal_listAccounts'
  4937. })
  4938. ];
  4939. };
  4940. module.exports = Personal;
  4941. },{"../formatters":30,"../method":36,"../property":45}],41:[function(require,module,exports){
  4942. /*
  4943. This file is part of web3.js.
  4944. web3.js is free software: you can redistribute it and/or modify
  4945. it under the terms of the GNU Lesser General Public License as published by
  4946. the Free Software Foundation, either version 3 of the License, or
  4947. (at your option) any later version.
  4948. web3.js is distributed in the hope that it will be useful,
  4949. but WITHOUT ANY WARRANTY; without even the implied warranty of
  4950. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  4951. GNU Lesser General Public License for more details.
  4952. You should have received a copy of the GNU Lesser General Public License
  4953. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  4954. */
  4955. /** @file shh.js
  4956. * @authors:
  4957. * Fabian Vogelsteller <fabian@ethereum.org>
  4958. * Marek Kotewicz <marek@ethcore.io>
  4959. * @date 2017
  4960. */
  4961. var Method = require('../method');
  4962. var Filter = require('../filter');
  4963. var watches = require('./watches');
  4964. var Shh = function (web3) {
  4965. this._requestManager = web3._requestManager;
  4966. var self = this;
  4967. methods().forEach(function(method) {
  4968. method.attachToObject(self);
  4969. method.setRequestManager(self._requestManager);
  4970. });
  4971. };
  4972. Shh.prototype.newMessageFilter = function (options, callback, filterCreationErrorCallback) {
  4973. return new Filter(options, 'shh', this._requestManager, watches.shh(), null, callback, filterCreationErrorCallback);
  4974. };
  4975. var methods = function () {
  4976. return [
  4977. new Method({
  4978. name: 'version',
  4979. call: 'shh_version',
  4980. params: 0
  4981. }),
  4982. new Method({
  4983. name: 'info',
  4984. call: 'shh_info',
  4985. params: 0
  4986. }),
  4987. new Method({
  4988. name: 'setMaxMessageSize',
  4989. call: 'shh_setMaxMessageSize',
  4990. params: 1
  4991. }),
  4992. new Method({
  4993. name: 'setMinPoW',
  4994. call: 'shh_setMinPoW',
  4995. params: 1
  4996. }),
  4997. new Method({
  4998. name: 'markTrustedPeer',
  4999. call: 'shh_markTrustedPeer',
  5000. params: 1
  5001. }),
  5002. new Method({
  5003. name: 'newKeyPair',
  5004. call: 'shh_newKeyPair',
  5005. params: 0
  5006. }),
  5007. new Method({
  5008. name: 'addPrivateKey',
  5009. call: 'shh_addPrivateKey',
  5010. params: 1
  5011. }),
  5012. new Method({
  5013. name: 'deleteKeyPair',
  5014. call: 'shh_deleteKeyPair',
  5015. params: 1
  5016. }),
  5017. new Method({
  5018. name: 'hasKeyPair',
  5019. call: 'shh_hasKeyPair',
  5020. params: 1
  5021. }),
  5022. new Method({
  5023. name: 'getPublicKey',
  5024. call: 'shh_getPublicKey',
  5025. params: 1
  5026. }),
  5027. new Method({
  5028. name: 'getPrivateKey',
  5029. call: 'shh_getPrivateKey',
  5030. params: 1
  5031. }),
  5032. new Method({
  5033. name: 'newSymKey',
  5034. call: 'shh_newSymKey',
  5035. params: 0
  5036. }),
  5037. new Method({
  5038. name: 'addSymKey',
  5039. call: 'shh_addSymKey',
  5040. params: 1
  5041. }),
  5042. new Method({
  5043. name: 'generateSymKeyFromPassword',
  5044. call: 'shh_generateSymKeyFromPassword',
  5045. params: 1
  5046. }),
  5047. new Method({
  5048. name: 'hasSymKey',
  5049. call: 'shh_hasSymKey',
  5050. params: 1
  5051. }),
  5052. new Method({
  5053. name: 'getSymKey',
  5054. call: 'shh_getSymKey',
  5055. params: 1
  5056. }),
  5057. new Method({
  5058. name: 'deleteSymKey',
  5059. call: 'shh_deleteSymKey',
  5060. params: 1
  5061. }),
  5062. // subscribe and unsubscribe missing
  5063. new Method({
  5064. name: 'post',
  5065. call: 'shh_post',
  5066. params: 1,
  5067. inputFormatter: [null]
  5068. })
  5069. ];
  5070. };
  5071. module.exports = Shh;
  5072. },{"../filter":29,"../method":36,"./watches":43}],42:[function(require,module,exports){
  5073. /*
  5074. This file is part of web3.js.
  5075. web3.js is free software: you can redistribute it and/or modify
  5076. it under the terms of the GNU Lesser General Public License as published by
  5077. the Free Software Foundation, either version 3 of the License, or
  5078. (at your option) any later version.
  5079. web3.js is distributed in the hope that it will be useful,
  5080. but WITHOUT ANY WARRANTY; without even the implied warranty of
  5081. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  5082. GNU Lesser General Public License for more details.
  5083. You should have received a copy of the GNU Lesser General Public License
  5084. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  5085. */
  5086. /**
  5087. * @file bzz.js
  5088. * @author Alex Beregszaszi <alex@rtfs.hu>
  5089. * @date 2016
  5090. *
  5091. * Reference: https://github.com/ethereum/go-ethereum/blob/swarm/internal/web3ext/web3ext.go#L33
  5092. */
  5093. "use strict";
  5094. var Method = require('../method');
  5095. var Property = require('../property');
  5096. function Swarm(web3) {
  5097. this._requestManager = web3._requestManager;
  5098. var self = this;
  5099. methods().forEach(function(method) {
  5100. method.attachToObject(self);
  5101. method.setRequestManager(self._requestManager);
  5102. });
  5103. properties().forEach(function(p) {
  5104. p.attachToObject(self);
  5105. p.setRequestManager(self._requestManager);
  5106. });
  5107. }
  5108. var methods = function () {
  5109. var blockNetworkRead = new Method({
  5110. name: 'blockNetworkRead',
  5111. call: 'bzz_blockNetworkRead',
  5112. params: 1,
  5113. inputFormatter: [null]
  5114. });
  5115. var syncEnabled = new Method({
  5116. name: 'syncEnabled',
  5117. call: 'bzz_syncEnabled',
  5118. params: 1,
  5119. inputFormatter: [null]
  5120. });
  5121. var swapEnabled = new Method({
  5122. name: 'swapEnabled',
  5123. call: 'bzz_swapEnabled',
  5124. params: 1,
  5125. inputFormatter: [null]
  5126. });
  5127. var download = new Method({
  5128. name: 'download',
  5129. call: 'bzz_download',
  5130. params: 2,
  5131. inputFormatter: [null, null]
  5132. });
  5133. var upload = new Method({
  5134. name: 'upload',
  5135. call: 'bzz_upload',
  5136. params: 2,
  5137. inputFormatter: [null, null]
  5138. });
  5139. var retrieve = new Method({
  5140. name: 'retrieve',
  5141. call: 'bzz_retrieve',
  5142. params: 1,
  5143. inputFormatter: [null]
  5144. });
  5145. var store = new Method({
  5146. name: 'store',
  5147. call: 'bzz_store',
  5148. params: 2,
  5149. inputFormatter: [null, null]
  5150. });
  5151. var get = new Method({
  5152. name: 'get',
  5153. call: 'bzz_get',
  5154. params: 1,
  5155. inputFormatter: [null]
  5156. });
  5157. var put = new Method({
  5158. name: 'put',
  5159. call: 'bzz_put',
  5160. params: 2,
  5161. inputFormatter: [null, null]
  5162. });
  5163. var modify = new Method({
  5164. name: 'modify',
  5165. call: 'bzz_modify',
  5166. params: 4,
  5167. inputFormatter: [null, null, null, null]
  5168. });
  5169. return [
  5170. blockNetworkRead,
  5171. syncEnabled,
  5172. swapEnabled,
  5173. download,
  5174. upload,
  5175. retrieve,
  5176. store,
  5177. get,
  5178. put,
  5179. modify
  5180. ];
  5181. };
  5182. var properties = function () {
  5183. return [
  5184. new Property({
  5185. name: 'hive',
  5186. getter: 'bzz_hive'
  5187. }),
  5188. new Property({
  5189. name: 'info',
  5190. getter: 'bzz_info'
  5191. })
  5192. ];
  5193. };
  5194. module.exports = Swarm;
  5195. },{"../method":36,"../property":45}],43:[function(require,module,exports){
  5196. /*
  5197. This file is part of web3.js.
  5198. web3.js is free software: you can redistribute it and/or modify
  5199. it under the terms of the GNU Lesser General Public License as published by
  5200. the Free Software Foundation, either version 3 of the License, or
  5201. (at your option) any later version.
  5202. web3.js is distributed in the hope that it will be useful,
  5203. but WITHOUT ANY WARRANTY; without even the implied warranty of
  5204. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  5205. GNU Lesser General Public License for more details.
  5206. You should have received a copy of the GNU Lesser General Public License
  5207. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  5208. */
  5209. /** @file watches.js
  5210. * @authors:
  5211. * Marek Kotewicz <marek@ethdev.com>
  5212. * @date 2015
  5213. */
  5214. var Method = require('../method');
  5215. /// @returns an array of objects describing web3.eth.filter api methods
  5216. var eth = function () {
  5217. var newFilterCall = function (args) {
  5218. var type = args[0];
  5219. switch(type) {
  5220. case 'latest':
  5221. args.shift();
  5222. this.params = 0;
  5223. return 'eth_newBlockFilter';
  5224. case 'pending':
  5225. args.shift();
  5226. this.params = 0;
  5227. return 'eth_newPendingTransactionFilter';
  5228. default:
  5229. return 'eth_newFilter';
  5230. }
  5231. };
  5232. var newFilter = new Method({
  5233. name: 'newFilter',
  5234. call: newFilterCall,
  5235. params: 1
  5236. });
  5237. var uninstallFilter = new Method({
  5238. name: 'uninstallFilter',
  5239. call: 'eth_uninstallFilter',
  5240. params: 1
  5241. });
  5242. var getLogs = new Method({
  5243. name: 'getLogs',
  5244. call: 'eth_getFilterLogs',
  5245. params: 1
  5246. });
  5247. var poll = new Method({
  5248. name: 'poll',
  5249. call: 'eth_getFilterChanges',
  5250. params: 1
  5251. });
  5252. return [
  5253. newFilter,
  5254. uninstallFilter,
  5255. getLogs,
  5256. poll
  5257. ];
  5258. };
  5259. /// @returns an array of objects describing web3.shh.watch api methods
  5260. var shh = function () {
  5261. return [
  5262. new Method({
  5263. name: 'newFilter',
  5264. call: 'shh_newMessageFilter',
  5265. params: 1
  5266. }),
  5267. new Method({
  5268. name: 'uninstallFilter',
  5269. call: 'shh_deleteMessageFilter',
  5270. params: 1
  5271. }),
  5272. new Method({
  5273. name: 'getLogs',
  5274. call: 'shh_getFilterMessages',
  5275. params: 1
  5276. }),
  5277. new Method({
  5278. name: 'poll',
  5279. call: 'shh_getFilterMessages',
  5280. params: 1
  5281. })
  5282. ];
  5283. };
  5284. module.exports = {
  5285. eth: eth,
  5286. shh: shh
  5287. };
  5288. },{"../method":36}],44:[function(require,module,exports){
  5289. /*
  5290. This file is part of web3.js.
  5291. web3.js is free software: you can redistribute it and/or modify
  5292. it under the terms of the GNU Lesser General Public License as published by
  5293. the Free Software Foundation, either version 3 of the License, or
  5294. (at your option) any later version.
  5295. web3.js is distributed in the hope that it will be useful,
  5296. but WITHOUT ANY WARRANTY; without even the implied warranty of
  5297. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  5298. GNU Lesser General Public License for more details.
  5299. You should have received a copy of the GNU Lesser General Public License
  5300. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  5301. */
  5302. /**
  5303. * @file namereg.js
  5304. * @author Marek Kotewicz <marek@ethdev.com>
  5305. * @date 2015
  5306. */
  5307. var globalRegistrarAbi = require('../contracts/GlobalRegistrar.json');
  5308. var icapRegistrarAbi= require('../contracts/ICAPRegistrar.json');
  5309. var globalNameregAddress = '0xc6d9d2cd449a754c494264e1809c50e34d64562b';
  5310. var icapNameregAddress = '0xa1a111bc074c9cfa781f0c38e63bd51c91b8af00';
  5311. module.exports = {
  5312. global: {
  5313. abi: globalRegistrarAbi,
  5314. address: globalNameregAddress
  5315. },
  5316. icap: {
  5317. abi: icapRegistrarAbi,
  5318. address: icapNameregAddress
  5319. }
  5320. };
  5321. },{"../contracts/GlobalRegistrar.json":1,"../contracts/ICAPRegistrar.json":2}],45:[function(require,module,exports){
  5322. /*
  5323. This file is part of web3.js.
  5324. web3.js is free software: you can redistribute it and/or modify
  5325. it under the terms of the GNU Lesser General Public License as published by
  5326. the Free Software Foundation, either version 3 of the License, or
  5327. (at your option) any later version.
  5328. web3.js is distributed in the hope that it will be useful,
  5329. but WITHOUT ANY WARRANTY; without even the implied warranty of
  5330. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  5331. GNU Lesser General Public License for more details.
  5332. You should have received a copy of the GNU Lesser General Public License
  5333. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  5334. */
  5335. /**
  5336. * @file property.js
  5337. * @author Fabian Vogelsteller <fabian@frozeman.de>
  5338. * @author Marek Kotewicz <marek@ethdev.com>
  5339. * @date 2015
  5340. */
  5341. var utils = require('../utils/utils');
  5342. var Property = function (options) {
  5343. this.name = options.name;
  5344. this.getter = options.getter;
  5345. this.setter = options.setter;
  5346. this.outputFormatter = options.outputFormatter;
  5347. this.inputFormatter = options.inputFormatter;
  5348. this.requestManager = null;
  5349. };
  5350. Property.prototype.setRequestManager = function (rm) {
  5351. this.requestManager = rm;
  5352. };
  5353. /**
  5354. * Should be called to format input args of method
  5355. *
  5356. * @method formatInput
  5357. * @param {Array}
  5358. * @return {Array}
  5359. */
  5360. Property.prototype.formatInput = function (arg) {
  5361. return this.inputFormatter ? this.inputFormatter(arg) : arg;
  5362. };
  5363. /**
  5364. * Should be called to format output(result) of method
  5365. *
  5366. * @method formatOutput
  5367. * @param {Object}
  5368. * @return {Object}
  5369. */
  5370. Property.prototype.formatOutput = function (result) {
  5371. return this.outputFormatter && result !== null && result !== undefined ? this.outputFormatter(result) : result;
  5372. };
  5373. /**
  5374. * Should be used to extract callback from array of arguments. Modifies input param
  5375. *
  5376. * @method extractCallback
  5377. * @param {Array} arguments
  5378. * @return {Function|Null} callback, if exists
  5379. */
  5380. Property.prototype.extractCallback = function (args) {
  5381. if (utils.isFunction(args[args.length - 1])) {
  5382. return args.pop(); // modify the args array!
  5383. }
  5384. };
  5385. /**
  5386. * Should attach function to method
  5387. *
  5388. * @method attachToObject
  5389. * @param {Object}
  5390. * @param {Function}
  5391. */
  5392. Property.prototype.attachToObject = function (obj) {
  5393. var proto = {
  5394. get: this.buildGet(),
  5395. enumerable: true
  5396. };
  5397. var names = this.name.split('.');
  5398. var name = names[0];
  5399. if (names.length > 1) {
  5400. obj[names[0]] = obj[names[0]] || {};
  5401. obj = obj[names[0]];
  5402. name = names[1];
  5403. }
  5404. Object.defineProperty(obj, name, proto);
  5405. obj[asyncGetterName(name)] = this.buildAsyncGet();
  5406. };
  5407. var asyncGetterName = function (name) {
  5408. return 'get' + name.charAt(0).toUpperCase() + name.slice(1);
  5409. };
  5410. Property.prototype.buildGet = function () {
  5411. var property = this;
  5412. return function get() {
  5413. return property.formatOutput(property.requestManager.send({
  5414. method: property.getter
  5415. }));
  5416. };
  5417. };
  5418. Property.prototype.buildAsyncGet = function () {
  5419. var property = this;
  5420. var get = function (callback) {
  5421. property.requestManager.sendAsync({
  5422. method: property.getter
  5423. }, function (err, result) {
  5424. callback(err, property.formatOutput(result));
  5425. });
  5426. };
  5427. get.request = this.request.bind(this);
  5428. return get;
  5429. };
  5430. /**
  5431. * Should be called to create pure JSONRPC request which can be used in batch request
  5432. *
  5433. * @method request
  5434. * @param {...} params
  5435. * @return {Object} jsonrpc request
  5436. */
  5437. Property.prototype.request = function () {
  5438. var payload = {
  5439. method: this.getter,
  5440. params: [],
  5441. callback: this.extractCallback(Array.prototype.slice.call(arguments))
  5442. };
  5443. payload.format = this.formatOutput.bind(this);
  5444. return payload;
  5445. };
  5446. module.exports = Property;
  5447. },{"../utils/utils":20}],46:[function(require,module,exports){
  5448. /*
  5449. This file is part of web3.js.
  5450. web3.js is free software: you can redistribute it and/or modify
  5451. it under the terms of the GNU Lesser General Public License as published by
  5452. the Free Software Foundation, either version 3 of the License, or
  5453. (at your option) any later version.
  5454. web3.js is distributed in the hope that it will be useful,
  5455. but WITHOUT ANY WARRANTY; without even the implied warranty of
  5456. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  5457. GNU Lesser General Public License for more details.
  5458. You should have received a copy of the GNU Lesser General Public License
  5459. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  5460. */
  5461. /**
  5462. * @file requestmanager.js
  5463. * @author Jeffrey Wilcke <jeff@ethdev.com>
  5464. * @author Marek Kotewicz <marek@ethdev.com>
  5465. * @author Marian Oancea <marian@ethdev.com>
  5466. * @author Fabian Vogelsteller <fabian@ethdev.com>
  5467. * @author Gav Wood <g@ethdev.com>
  5468. * @date 2014
  5469. */
  5470. var Jsonrpc = require('./jsonrpc');
  5471. var utils = require('../utils/utils');
  5472. var c = require('../utils/config');
  5473. var errors = require('./errors');
  5474. /**
  5475. * It's responsible for passing messages to providers
  5476. * It's also responsible for polling the ethereum node for incoming messages
  5477. * Default poll timeout is 1 second
  5478. * Singleton
  5479. */
  5480. var RequestManager = function (provider) {
  5481. this.provider = provider;
  5482. this.polls = {};
  5483. this.timeout = null;
  5484. };
  5485. /**
  5486. * Should be used to synchronously send request
  5487. *
  5488. * @method send
  5489. * @param {Object} data
  5490. * @return {Object}
  5491. */
  5492. RequestManager.prototype.send = function (data) {
  5493. if (!this.provider) {
  5494. console.error(errors.InvalidProvider());
  5495. return null;
  5496. }
  5497. var payload = Jsonrpc.toPayload(data.method, data.params);
  5498. var result = this.provider.send(payload);
  5499. if (!Jsonrpc.isValidResponse(result)) {
  5500. throw errors.InvalidResponse(result);
  5501. }
  5502. return result.result;
  5503. };
  5504. /**
  5505. * Should be used to asynchronously send request
  5506. *
  5507. * @method sendAsync
  5508. * @param {Object} data
  5509. * @param {Function} callback
  5510. */
  5511. RequestManager.prototype.sendAsync = function (data, callback) {
  5512. if (!this.provider) {
  5513. return callback(errors.InvalidProvider());
  5514. }
  5515. var payload = Jsonrpc.toPayload(data.method, data.params);
  5516. this.provider.sendAsync(payload, function (err, result) {
  5517. if (err) {
  5518. return callback(err);
  5519. }
  5520. if (!Jsonrpc.isValidResponse(result)) {
  5521. return callback(errors.InvalidResponse(result));
  5522. }
  5523. callback(null, result.result);
  5524. });
  5525. };
  5526. /**
  5527. * Should be called to asynchronously send batch request
  5528. *
  5529. * @method sendBatch
  5530. * @param {Array} batch data
  5531. * @param {Function} callback
  5532. */
  5533. RequestManager.prototype.sendBatch = function (data, callback) {
  5534. if (!this.provider) {
  5535. return callback(errors.InvalidProvider());
  5536. }
  5537. var payload = Jsonrpc.toBatchPayload(data);
  5538. this.provider.sendAsync(payload, function (err, results) {
  5539. if (err) {
  5540. return callback(err);
  5541. }
  5542. if (!utils.isArray(results)) {
  5543. return callback(errors.InvalidResponse(results));
  5544. }
  5545. callback(err, results);
  5546. });
  5547. };
  5548. /**
  5549. * Should be used to set provider of request manager
  5550. *
  5551. * @method setProvider
  5552. * @param {Object}
  5553. */
  5554. RequestManager.prototype.setProvider = function (p) {
  5555. this.provider = p;
  5556. };
  5557. /**
  5558. * Should be used to start polling
  5559. *
  5560. * @method startPolling
  5561. * @param {Object} data
  5562. * @param {Number} pollId
  5563. * @param {Function} callback
  5564. * @param {Function} uninstall
  5565. *
  5566. * @todo cleanup number of params
  5567. */
  5568. RequestManager.prototype.startPolling = function (data, pollId, callback, uninstall) {
  5569. this.polls[pollId] = {data: data, id: pollId, callback: callback, uninstall: uninstall};
  5570. // start polling
  5571. if (!this.timeout) {
  5572. this.poll();
  5573. }
  5574. };
  5575. /**
  5576. * Should be used to stop polling for filter with given id
  5577. *
  5578. * @method stopPolling
  5579. * @param {Number} pollId
  5580. */
  5581. RequestManager.prototype.stopPolling = function (pollId) {
  5582. delete this.polls[pollId];
  5583. // stop polling
  5584. if(Object.keys(this.polls).length === 0 && this.timeout) {
  5585. clearTimeout(this.timeout);
  5586. this.timeout = null;
  5587. }
  5588. };
  5589. /**
  5590. * Should be called to reset the polling mechanism of the request manager
  5591. *
  5592. * @method reset
  5593. */
  5594. RequestManager.prototype.reset = function (keepIsSyncing) {
  5595. /*jshint maxcomplexity:5 */
  5596. for (var key in this.polls) {
  5597. // remove all polls, except sync polls,
  5598. // they need to be removed manually by calling syncing.stopWatching()
  5599. if(!keepIsSyncing || key.indexOf('syncPoll_') === -1) {
  5600. this.polls[key].uninstall();
  5601. delete this.polls[key];
  5602. }
  5603. }
  5604. // stop polling
  5605. if(Object.keys(this.polls).length === 0 && this.timeout) {
  5606. clearTimeout(this.timeout);
  5607. this.timeout = null;
  5608. }
  5609. };
  5610. /**
  5611. * Should be called to poll for changes on filter with given id
  5612. *
  5613. * @method poll
  5614. */
  5615. RequestManager.prototype.poll = function () {
  5616. /*jshint maxcomplexity: 6 */
  5617. this.timeout = setTimeout(this.poll.bind(this), c.ETH_POLLING_TIMEOUT);
  5618. if (Object.keys(this.polls).length === 0) {
  5619. return;
  5620. }
  5621. if (!this.provider) {
  5622. console.error(errors.InvalidProvider());
  5623. return;
  5624. }
  5625. var pollsData = [];
  5626. var pollsIds = [];
  5627. for (var key in this.polls) {
  5628. pollsData.push(this.polls[key].data);
  5629. pollsIds.push(key);
  5630. }
  5631. if (pollsData.length === 0) {
  5632. return;
  5633. }
  5634. var payload = Jsonrpc.toBatchPayload(pollsData);
  5635. // map the request id to they poll id
  5636. var pollsIdMap = {};
  5637. payload.forEach(function(load, index){
  5638. pollsIdMap[load.id] = pollsIds[index];
  5639. });
  5640. var self = this;
  5641. this.provider.sendAsync(payload, function (error, results) {
  5642. // TODO: console log?
  5643. if (error) {
  5644. return;
  5645. }
  5646. if (!utils.isArray(results)) {
  5647. throw errors.InvalidResponse(results);
  5648. }
  5649. results.map(function (result) {
  5650. var id = pollsIdMap[result.id];
  5651. // make sure the filter is still installed after arrival of the request
  5652. if (self.polls[id]) {
  5653. result.callback = self.polls[id].callback;
  5654. return result;
  5655. } else
  5656. return false;
  5657. }).filter(function (result) {
  5658. return !!result;
  5659. }).filter(function (result) {
  5660. var valid = Jsonrpc.isValidResponse(result);
  5661. if (!valid) {
  5662. result.callback(errors.InvalidResponse(result));
  5663. }
  5664. return valid;
  5665. }).forEach(function (result) {
  5666. result.callback(null, result.result);
  5667. });
  5668. });
  5669. };
  5670. module.exports = RequestManager;
  5671. },{"../utils/config":18,"../utils/utils":20,"./errors":26,"./jsonrpc":35}],47:[function(require,module,exports){
  5672. var Settings = function () {
  5673. this.defaultBlock = 'latest';
  5674. this.defaultAccount = undefined;
  5675. };
  5676. module.exports = Settings;
  5677. },{}],48:[function(require,module,exports){
  5678. /*
  5679. This file is part of web3.js.
  5680. web3.js is free software: you can redistribute it and/or modify
  5681. it under the terms of the GNU Lesser General Public License as published by
  5682. the Free Software Foundation, either version 3 of the License, or
  5683. (at your option) any later version.
  5684. web3.js is distributed in the hope that it will be useful,
  5685. but WITHOUT ANY WARRANTY; without even the implied warranty of
  5686. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  5687. GNU Lesser General Public License for more details.
  5688. You should have received a copy of the GNU Lesser General Public License
  5689. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  5690. */
  5691. /** @file syncing.js
  5692. * @authors:
  5693. * Fabian Vogelsteller <fabian@ethdev.com>
  5694. * @date 2015
  5695. */
  5696. var formatters = require('./formatters');
  5697. var utils = require('../utils/utils');
  5698. var count = 1;
  5699. /**
  5700. Adds the callback and sets up the methods, to iterate over the results.
  5701. @method pollSyncing
  5702. @param {Object} self
  5703. */
  5704. var pollSyncing = function(self) {
  5705. var onMessage = function (error, sync) {
  5706. if (error) {
  5707. return self.callbacks.forEach(function (callback) {
  5708. callback(error);
  5709. });
  5710. }
  5711. if(utils.isObject(sync) && sync.startingBlock)
  5712. sync = formatters.outputSyncingFormatter(sync);
  5713. self.callbacks.forEach(function (callback) {
  5714. if (self.lastSyncState !== sync) {
  5715. // call the callback with true first so the app can stop anything, before receiving the sync data
  5716. if(!self.lastSyncState && utils.isObject(sync))
  5717. callback(null, true);
  5718. // call on the next CPU cycle, so the actions of the sync stop can be processes first
  5719. setTimeout(function() {
  5720. callback(null, sync);
  5721. }, 0);
  5722. self.lastSyncState = sync;
  5723. }
  5724. });
  5725. };
  5726. self.requestManager.startPolling({
  5727. method: 'eth_syncing',
  5728. params: [],
  5729. }, self.pollId, onMessage, self.stopWatching.bind(self));
  5730. };
  5731. var IsSyncing = function (requestManager, callback) {
  5732. this.requestManager = requestManager;
  5733. this.pollId = 'syncPoll_'+ count++;
  5734. this.callbacks = [];
  5735. this.addCallback(callback);
  5736. this.lastSyncState = false;
  5737. pollSyncing(this);
  5738. return this;
  5739. };
  5740. IsSyncing.prototype.addCallback = function (callback) {
  5741. if(callback)
  5742. this.callbacks.push(callback);
  5743. return this;
  5744. };
  5745. IsSyncing.prototype.stopWatching = function () {
  5746. this.requestManager.stopPolling(this.pollId);
  5747. this.callbacks = [];
  5748. };
  5749. module.exports = IsSyncing;
  5750. },{"../utils/utils":20,"./formatters":30}],49:[function(require,module,exports){
  5751. /*
  5752. This file is part of web3.js.
  5753. web3.js is free software: you can redistribute it and/or modify
  5754. it under the terms of the GNU Lesser General Public License as published by
  5755. the Free Software Foundation, either version 3 of the License, or
  5756. (at your option) any later version.
  5757. web3.js is distributed in the hope that it will be useful,
  5758. but WITHOUT ANY WARRANTY; without even the implied warranty of
  5759. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  5760. GNU Lesser General Public License for more details.
  5761. You should have received a copy of the GNU Lesser General Public License
  5762. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  5763. */
  5764. /**
  5765. * @file transfer.js
  5766. * @author Marek Kotewicz <marek@ethdev.com>
  5767. * @date 2015
  5768. */
  5769. var Iban = require('./iban');
  5770. var exchangeAbi = require('../contracts/SmartExchange.json');
  5771. /**
  5772. * Should be used to make Iban transfer
  5773. *
  5774. * @method transfer
  5775. * @param {String} from
  5776. * @param {String} to iban
  5777. * @param {Value} value to be tranfered
  5778. * @param {Function} callback, callback
  5779. */
  5780. var transfer = function (eth, from, to, value, callback) {
  5781. var iban = new Iban(to);
  5782. if (!iban.isValid()) {
  5783. throw new Error('invalid iban address');
  5784. }
  5785. if (iban.isDirect()) {
  5786. return transferToAddress(eth, from, iban.address(), value, callback);
  5787. }
  5788. if (!callback) {
  5789. var address = eth.icapNamereg().addr(iban.institution());
  5790. return deposit(eth, from, address, value, iban.client());
  5791. }
  5792. eth.icapNamereg().addr(iban.institution(), function (err, address) {
  5793. return deposit(eth, from, address, value, iban.client(), callback);
  5794. });
  5795. };
  5796. /**
  5797. * Should be used to transfer funds to certain address
  5798. *
  5799. * @method transferToAddress
  5800. * @param {String} from
  5801. * @param {String} to
  5802. * @param {Value} value to be tranfered
  5803. * @param {Function} callback, callback
  5804. */
  5805. var transferToAddress = function (eth, from, to, value, callback) {
  5806. return eth.sendTransaction({
  5807. address: to,
  5808. from: from,
  5809. value: value
  5810. }, callback);
  5811. };
  5812. /**
  5813. * Should be used to deposit funds to generic Exchange contract (must implement deposit(bytes32) method!)
  5814. *
  5815. * @method deposit
  5816. * @param {String} from
  5817. * @param {String} to
  5818. * @param {Value} value to be transferred
  5819. * @param {String} client unique identifier
  5820. * @param {Function} callback, callback
  5821. */
  5822. var deposit = function (eth, from, to, value, client, callback) {
  5823. var abi = exchangeAbi;
  5824. return eth.contract(abi).at(to).deposit(client, {
  5825. from: from,
  5826. value: value
  5827. }, callback);
  5828. };
  5829. module.exports = transfer;
  5830. },{"../contracts/SmartExchange.json":3,"./iban":33}],50:[function(require,module,exports){
  5831. },{}],51:[function(require,module,exports){
  5832. ;(function (root, factory, undef) {
  5833. if (typeof exports === "object") {
  5834. // CommonJS
  5835. module.exports = exports = factory(require("./core"), require("./enc-base64"), require("./md5"), require("./evpkdf"), require("./cipher-core"));
  5836. }
  5837. else if (typeof define === "function" && define.amd) {
  5838. // AMD
  5839. define(["./core", "./enc-base64", "./md5", "./evpkdf", "./cipher-core"], factory);
  5840. }
  5841. else {
  5842. // Global (browser)
  5843. factory(root.CryptoJS);
  5844. }
  5845. }(this, function (CryptoJS) {
  5846. (function () {
  5847. // Shortcuts
  5848. var C = CryptoJS;
  5849. var C_lib = C.lib;
  5850. var BlockCipher = C_lib.BlockCipher;
  5851. var C_algo = C.algo;
  5852. // Lookup tables
  5853. var SBOX = [];
  5854. var INV_SBOX = [];
  5855. var SUB_MIX_0 = [];
  5856. var SUB_MIX_1 = [];
  5857. var SUB_MIX_2 = [];
  5858. var SUB_MIX_3 = [];
  5859. var INV_SUB_MIX_0 = [];
  5860. var INV_SUB_MIX_1 = [];
  5861. var INV_SUB_MIX_2 = [];
  5862. var INV_SUB_MIX_3 = [];
  5863. // Compute lookup tables
  5864. (function () {
  5865. // Compute double table
  5866. var d = [];
  5867. for (var i = 0; i < 256; i++) {
  5868. if (i < 128) {
  5869. d[i] = i << 1;
  5870. } else {
  5871. d[i] = (i << 1) ^ 0x11b;
  5872. }
  5873. }
  5874. // Walk GF(2^8)
  5875. var x = 0;
  5876. var xi = 0;
  5877. for (var i = 0; i < 256; i++) {
  5878. // Compute sbox
  5879. var sx = xi ^ (xi << 1) ^ (xi << 2) ^ (xi << 3) ^ (xi << 4);
  5880. sx = (sx >>> 8) ^ (sx & 0xff) ^ 0x63;
  5881. SBOX[x] = sx;
  5882. INV_SBOX[sx] = x;
  5883. // Compute multiplication
  5884. var x2 = d[x];
  5885. var x4 = d[x2];
  5886. var x8 = d[x4];
  5887. // Compute sub bytes, mix columns tables
  5888. var t = (d[sx] * 0x101) ^ (sx * 0x1010100);
  5889. SUB_MIX_0[x] = (t << 24) | (t >>> 8);
  5890. SUB_MIX_1[x] = (t << 16) | (t >>> 16);
  5891. SUB_MIX_2[x] = (t << 8) | (t >>> 24);
  5892. SUB_MIX_3[x] = t;
  5893. // Compute inv sub bytes, inv mix columns tables
  5894. var t = (x8 * 0x1010101) ^ (x4 * 0x10001) ^ (x2 * 0x101) ^ (x * 0x1010100);
  5895. INV_SUB_MIX_0[sx] = (t << 24) | (t >>> 8);
  5896. INV_SUB_MIX_1[sx] = (t << 16) | (t >>> 16);
  5897. INV_SUB_MIX_2[sx] = (t << 8) | (t >>> 24);
  5898. INV_SUB_MIX_3[sx] = t;
  5899. // Compute next counter
  5900. if (!x) {
  5901. x = xi = 1;
  5902. } else {
  5903. x = x2 ^ d[d[d[x8 ^ x2]]];
  5904. xi ^= d[d[xi]];
  5905. }
  5906. }
  5907. }());
  5908. // Precomputed Rcon lookup
  5909. var RCON = [0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36];
  5910. /**
  5911. * AES block cipher algorithm.
  5912. */
  5913. var AES = C_algo.AES = BlockCipher.extend({
  5914. _doReset: function () {
  5915. // Skip reset of nRounds has been set before and key did not change
  5916. if (this._nRounds && this._keyPriorReset === this._key) {
  5917. return;
  5918. }
  5919. // Shortcuts
  5920. var key = this._keyPriorReset = this._key;
  5921. var keyWords = key.words;
  5922. var keySize = key.sigBytes / 4;
  5923. // Compute number of rounds
  5924. var nRounds = this._nRounds = keySize + 6;
  5925. // Compute number of key schedule rows
  5926. var ksRows = (nRounds + 1) * 4;
  5927. // Compute key schedule
  5928. var keySchedule = this._keySchedule = [];
  5929. for (var ksRow = 0; ksRow < ksRows; ksRow++) {
  5930. if (ksRow < keySize) {
  5931. keySchedule[ksRow] = keyWords[ksRow];
  5932. } else {
  5933. var t = keySchedule[ksRow - 1];
  5934. if (!(ksRow % keySize)) {
  5935. // Rot word
  5936. t = (t << 8) | (t >>> 24);
  5937. // Sub word
  5938. t = (SBOX[t >>> 24] << 24) | (SBOX[(t >>> 16) & 0xff] << 16) | (SBOX[(t >>> 8) & 0xff] << 8) | SBOX[t & 0xff];
  5939. // Mix Rcon
  5940. t ^= RCON[(ksRow / keySize) | 0] << 24;
  5941. } else if (keySize > 6 && ksRow % keySize == 4) {
  5942. // Sub word
  5943. t = (SBOX[t >>> 24] << 24) | (SBOX[(t >>> 16) & 0xff] << 16) | (SBOX[(t >>> 8) & 0xff] << 8) | SBOX[t & 0xff];
  5944. }
  5945. keySchedule[ksRow] = keySchedule[ksRow - keySize] ^ t;
  5946. }
  5947. }
  5948. // Compute inv key schedule
  5949. var invKeySchedule = this._invKeySchedule = [];
  5950. for (var invKsRow = 0; invKsRow < ksRows; invKsRow++) {
  5951. var ksRow = ksRows - invKsRow;
  5952. if (invKsRow % 4) {
  5953. var t = keySchedule[ksRow];
  5954. } else {
  5955. var t = keySchedule[ksRow - 4];
  5956. }
  5957. if (invKsRow < 4 || ksRow <= 4) {
  5958. invKeySchedule[invKsRow] = t;
  5959. } else {
  5960. invKeySchedule[invKsRow] = INV_SUB_MIX_0[SBOX[t >>> 24]] ^ INV_SUB_MIX_1[SBOX[(t >>> 16) & 0xff]] ^
  5961. INV_SUB_MIX_2[SBOX[(t >>> 8) & 0xff]] ^ INV_SUB_MIX_3[SBOX[t & 0xff]];
  5962. }
  5963. }
  5964. },
  5965. encryptBlock: function (M, offset) {
  5966. this._doCryptBlock(M, offset, this._keySchedule, SUB_MIX_0, SUB_MIX_1, SUB_MIX_2, SUB_MIX_3, SBOX);
  5967. },
  5968. decryptBlock: function (M, offset) {
  5969. // Swap 2nd and 4th rows
  5970. var t = M[offset + 1];
  5971. M[offset + 1] = M[offset + 3];
  5972. M[offset + 3] = t;
  5973. this._doCryptBlock(M, offset, this._invKeySchedule, INV_SUB_MIX_0, INV_SUB_MIX_1, INV_SUB_MIX_2, INV_SUB_MIX_3, INV_SBOX);
  5974. // Inv swap 2nd and 4th rows
  5975. var t = M[offset + 1];
  5976. M[offset + 1] = M[offset + 3];
  5977. M[offset + 3] = t;
  5978. },
  5979. _doCryptBlock: function (M, offset, keySchedule, SUB_MIX_0, SUB_MIX_1, SUB_MIX_2, SUB_MIX_3, SBOX) {
  5980. // Shortcut
  5981. var nRounds = this._nRounds;
  5982. // Get input, add round key
  5983. var s0 = M[offset] ^ keySchedule[0];
  5984. var s1 = M[offset + 1] ^ keySchedule[1];
  5985. var s2 = M[offset + 2] ^ keySchedule[2];
  5986. var s3 = M[offset + 3] ^ keySchedule[3];
  5987. // Key schedule row counter
  5988. var ksRow = 4;
  5989. // Rounds
  5990. for (var round = 1; round < nRounds; round++) {
  5991. // Shift rows, sub bytes, mix columns, add round key
  5992. 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++];
  5993. 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++];
  5994. 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++];
  5995. 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++];
  5996. // Update state
  5997. s0 = t0;
  5998. s1 = t1;
  5999. s2 = t2;
  6000. s3 = t3;
  6001. }
  6002. // Shift rows, sub bytes, add round key
  6003. var t0 = ((SBOX[s0 >>> 24] << 24) | (SBOX[(s1 >>> 16) & 0xff] << 16) | (SBOX[(s2 >>> 8) & 0xff] << 8) | SBOX[s3 & 0xff]) ^ keySchedule[ksRow++];
  6004. var t1 = ((SBOX[s1 >>> 24] << 24) | (SBOX[(s2 >>> 16) & 0xff] << 16) | (SBOX[(s3 >>> 8) & 0xff] << 8) | SBOX[s0 & 0xff]) ^ keySchedule[ksRow++];
  6005. var t2 = ((SBOX[s2 >>> 24] << 24) | (SBOX[(s3 >>> 16) & 0xff] << 16) | (SBOX[(s0 >>> 8) & 0xff] << 8) | SBOX[s1 & 0xff]) ^ keySchedule[ksRow++];
  6006. var t3 = ((SBOX[s3 >>> 24] << 24) | (SBOX[(s0 >>> 16) & 0xff] << 16) | (SBOX[(s1 >>> 8) & 0xff] << 8) | SBOX[s2 & 0xff]) ^ keySchedule[ksRow++];
  6007. // Set output
  6008. M[offset] = t0;
  6009. M[offset + 1] = t1;
  6010. M[offset + 2] = t2;
  6011. M[offset + 3] = t3;
  6012. },
  6013. keySize: 256/32
  6014. });
  6015. /**
  6016. * Shortcut functions to the cipher's object interface.
  6017. *
  6018. * @example
  6019. *
  6020. * var ciphertext = CryptoJS.AES.encrypt(message, key, cfg);
  6021. * var plaintext = CryptoJS.AES.decrypt(ciphertext, key, cfg);
  6022. */
  6023. C.AES = BlockCipher._createHelper(AES);
  6024. }());
  6025. return CryptoJS.AES;
  6026. }));
  6027. },{"./cipher-core":52,"./core":53,"./enc-base64":54,"./evpkdf":56,"./md5":61}],52:[function(require,module,exports){
  6028. ;(function (root, factory) {
  6029. if (typeof exports === "object") {
  6030. // CommonJS
  6031. module.exports = exports = factory(require("./core"));
  6032. }
  6033. else if (typeof define === "function" && define.amd) {
  6034. // AMD
  6035. define(["./core"], factory);
  6036. }
  6037. else {
  6038. // Global (browser)
  6039. factory(root.CryptoJS);
  6040. }
  6041. }(this, function (CryptoJS) {
  6042. /**
  6043. * Cipher core components.
  6044. */
  6045. CryptoJS.lib.Cipher || (function (undefined) {
  6046. // Shortcuts
  6047. var C = CryptoJS;
  6048. var C_lib = C.lib;
  6049. var Base = C_lib.Base;
  6050. var WordArray = C_lib.WordArray;
  6051. var BufferedBlockAlgorithm = C_lib.BufferedBlockAlgorithm;
  6052. var C_enc = C.enc;
  6053. var Utf8 = C_enc.Utf8;
  6054. var Base64 = C_enc.Base64;
  6055. var C_algo = C.algo;
  6056. var EvpKDF = C_algo.EvpKDF;
  6057. /**
  6058. * Abstract base cipher template.
  6059. *
  6060. * @property {number} keySize This cipher's key size. Default: 4 (128 bits)
  6061. * @property {number} ivSize This cipher's IV size. Default: 4 (128 bits)
  6062. * @property {number} _ENC_XFORM_MODE A constant representing encryption mode.
  6063. * @property {number} _DEC_XFORM_MODE A constant representing decryption mode.
  6064. */
  6065. var Cipher = C_lib.Cipher = BufferedBlockAlgorithm.extend({
  6066. /**
  6067. * Configuration options.
  6068. *
  6069. * @property {WordArray} iv The IV to use for this operation.
  6070. */
  6071. cfg: Base.extend(),
  6072. /**
  6073. * Creates this cipher in encryption mode.
  6074. *
  6075. * @param {WordArray} key The key.
  6076. * @param {Object} cfg (Optional) The configuration options to use for this operation.
  6077. *
  6078. * @return {Cipher} A cipher instance.
  6079. *
  6080. * @static
  6081. *
  6082. * @example
  6083. *
  6084. * var cipher = CryptoJS.algo.AES.createEncryptor(keyWordArray, { iv: ivWordArray });
  6085. */
  6086. createEncryptor: function (key, cfg) {
  6087. return this.create(this._ENC_XFORM_MODE, key, cfg);
  6088. },
  6089. /**
  6090. * Creates this cipher in decryption mode.
  6091. *
  6092. * @param {WordArray} key The key.
  6093. * @param {Object} cfg (Optional) The configuration options to use for this operation.
  6094. *
  6095. * @return {Cipher} A cipher instance.
  6096. *
  6097. * @static
  6098. *
  6099. * @example
  6100. *
  6101. * var cipher = CryptoJS.algo.AES.createDecryptor(keyWordArray, { iv: ivWordArray });
  6102. */
  6103. createDecryptor: function (key, cfg) {
  6104. return this.create(this._DEC_XFORM_MODE, key, cfg);
  6105. },
  6106. /**
  6107. * Initializes a newly created cipher.
  6108. *
  6109. * @param {number} xformMode Either the encryption or decryption transormation mode constant.
  6110. * @param {WordArray} key The key.
  6111. * @param {Object} cfg (Optional) The configuration options to use for this operation.
  6112. *
  6113. * @example
  6114. *
  6115. * var cipher = CryptoJS.algo.AES.create(CryptoJS.algo.AES._ENC_XFORM_MODE, keyWordArray, { iv: ivWordArray });
  6116. */
  6117. init: function (xformMode, key, cfg) {
  6118. // Apply config defaults
  6119. this.cfg = this.cfg.extend(cfg);
  6120. // Store transform mode and key
  6121. this._xformMode = xformMode;
  6122. this._key = key;
  6123. // Set initial values
  6124. this.reset();
  6125. },
  6126. /**
  6127. * Resets this cipher to its initial state.
  6128. *
  6129. * @example
  6130. *
  6131. * cipher.reset();
  6132. */
  6133. reset: function () {
  6134. // Reset data buffer
  6135. BufferedBlockAlgorithm.reset.call(this);
  6136. // Perform concrete-cipher logic
  6137. this._doReset();
  6138. },
  6139. /**
  6140. * Adds data to be encrypted or decrypted.
  6141. *
  6142. * @param {WordArray|string} dataUpdate The data to encrypt or decrypt.
  6143. *
  6144. * @return {WordArray} The data after processing.
  6145. *
  6146. * @example
  6147. *
  6148. * var encrypted = cipher.process('data');
  6149. * var encrypted = cipher.process(wordArray);
  6150. */
  6151. process: function (dataUpdate) {
  6152. // Append
  6153. this._append(dataUpdate);
  6154. // Process available blocks
  6155. return this._process();
  6156. },
  6157. /**
  6158. * Finalizes the encryption or decryption process.
  6159. * Note that the finalize operation is effectively a destructive, read-once operation.
  6160. *
  6161. * @param {WordArray|string} dataUpdate The final data to encrypt or decrypt.
  6162. *
  6163. * @return {WordArray} The data after final processing.
  6164. *
  6165. * @example
  6166. *
  6167. * var encrypted = cipher.finalize();
  6168. * var encrypted = cipher.finalize('data');
  6169. * var encrypted = cipher.finalize(wordArray);
  6170. */
  6171. finalize: function (dataUpdate) {
  6172. // Final data update
  6173. if (dataUpdate) {
  6174. this._append(dataUpdate);
  6175. }
  6176. // Perform concrete-cipher logic
  6177. var finalProcessedData = this._doFinalize();
  6178. return finalProcessedData;
  6179. },
  6180. keySize: 128/32,
  6181. ivSize: 128/32,
  6182. _ENC_XFORM_MODE: 1,
  6183. _DEC_XFORM_MODE: 2,
  6184. /**
  6185. * Creates shortcut functions to a cipher's object interface.
  6186. *
  6187. * @param {Cipher} cipher The cipher to create a helper for.
  6188. *
  6189. * @return {Object} An object with encrypt and decrypt shortcut functions.
  6190. *
  6191. * @static
  6192. *
  6193. * @example
  6194. *
  6195. * var AES = CryptoJS.lib.Cipher._createHelper(CryptoJS.algo.AES);
  6196. */
  6197. _createHelper: (function () {
  6198. function selectCipherStrategy(key) {
  6199. if (typeof key == 'string') {
  6200. return PasswordBasedCipher;
  6201. } else {
  6202. return SerializableCipher;
  6203. }
  6204. }
  6205. return function (cipher) {
  6206. return {
  6207. encrypt: function (message, key, cfg) {
  6208. return selectCipherStrategy(key).encrypt(cipher, message, key, cfg);
  6209. },
  6210. decrypt: function (ciphertext, key, cfg) {
  6211. return selectCipherStrategy(key).decrypt(cipher, ciphertext, key, cfg);
  6212. }
  6213. };
  6214. };
  6215. }())
  6216. });
  6217. /**
  6218. * Abstract base stream cipher template.
  6219. *
  6220. * @property {number} blockSize The number of 32-bit words this cipher operates on. Default: 1 (32 bits)
  6221. */
  6222. var StreamCipher = C_lib.StreamCipher = Cipher.extend({
  6223. _doFinalize: function () {
  6224. // Process partial blocks
  6225. var finalProcessedBlocks = this._process(!!'flush');
  6226. return finalProcessedBlocks;
  6227. },
  6228. blockSize: 1
  6229. });
  6230. /**
  6231. * Mode namespace.
  6232. */
  6233. var C_mode = C.mode = {};
  6234. /**
  6235. * Abstract base block cipher mode template.
  6236. */
  6237. var BlockCipherMode = C_lib.BlockCipherMode = Base.extend({
  6238. /**
  6239. * Creates this mode for encryption.
  6240. *
  6241. * @param {Cipher} cipher A block cipher instance.
  6242. * @param {Array} iv The IV words.
  6243. *
  6244. * @static
  6245. *
  6246. * @example
  6247. *
  6248. * var mode = CryptoJS.mode.CBC.createEncryptor(cipher, iv.words);
  6249. */
  6250. createEncryptor: function (cipher, iv) {
  6251. return this.Encryptor.create(cipher, iv);
  6252. },
  6253. /**
  6254. * Creates this mode for decryption.
  6255. *
  6256. * @param {Cipher} cipher A block cipher instance.
  6257. * @param {Array} iv The IV words.
  6258. *
  6259. * @static
  6260. *
  6261. * @example
  6262. *
  6263. * var mode = CryptoJS.mode.CBC.createDecryptor(cipher, iv.words);
  6264. */
  6265. createDecryptor: function (cipher, iv) {
  6266. return this.Decryptor.create(cipher, iv);
  6267. },
  6268. /**
  6269. * Initializes a newly created mode.
  6270. *
  6271. * @param {Cipher} cipher A block cipher instance.
  6272. * @param {Array} iv The IV words.
  6273. *
  6274. * @example
  6275. *
  6276. * var mode = CryptoJS.mode.CBC.Encryptor.create(cipher, iv.words);
  6277. */
  6278. init: function (cipher, iv) {
  6279. this._cipher = cipher;
  6280. this._iv = iv;
  6281. }
  6282. });
  6283. /**
  6284. * Cipher Block Chaining mode.
  6285. */
  6286. var CBC = C_mode.CBC = (function () {
  6287. /**
  6288. * Abstract base CBC mode.
  6289. */
  6290. var CBC = BlockCipherMode.extend();
  6291. /**
  6292. * CBC encryptor.
  6293. */
  6294. CBC.Encryptor = CBC.extend({
  6295. /**
  6296. * Processes the data block at offset.
  6297. *
  6298. * @param {Array} words The data words to operate on.
  6299. * @param {number} offset The offset where the block starts.
  6300. *
  6301. * @example
  6302. *
  6303. * mode.processBlock(data.words, offset);
  6304. */
  6305. processBlock: function (words, offset) {
  6306. // Shortcuts
  6307. var cipher = this._cipher;
  6308. var blockSize = cipher.blockSize;
  6309. // XOR and encrypt
  6310. xorBlock.call(this, words, offset, blockSize);
  6311. cipher.encryptBlock(words, offset);
  6312. // Remember this block to use with next block
  6313. this._prevBlock = words.slice(offset, offset + blockSize);
  6314. }
  6315. });
  6316. /**
  6317. * CBC decryptor.
  6318. */
  6319. CBC.Decryptor = CBC.extend({
  6320. /**
  6321. * Processes the data block at offset.
  6322. *
  6323. * @param {Array} words The data words to operate on.
  6324. * @param {number} offset The offset where the block starts.
  6325. *
  6326. * @example
  6327. *
  6328. * mode.processBlock(data.words, offset);
  6329. */
  6330. processBlock: function (words, offset) {
  6331. // Shortcuts
  6332. var cipher = this._cipher;
  6333. var blockSize = cipher.blockSize;
  6334. // Remember this block to use with next block
  6335. var thisBlock = words.slice(offset, offset + blockSize);
  6336. // Decrypt and XOR
  6337. cipher.decryptBlock(words, offset);
  6338. xorBlock.call(this, words, offset, blockSize);
  6339. // This block becomes the previous block
  6340. this._prevBlock = thisBlock;
  6341. }
  6342. });
  6343. function xorBlock(words, offset, blockSize) {
  6344. // Shortcut
  6345. var iv = this._iv;
  6346. // Choose mixing block
  6347. if (iv) {
  6348. var block = iv;
  6349. // Remove IV for subsequent blocks
  6350. this._iv = undefined;
  6351. } else {
  6352. var block = this._prevBlock;
  6353. }
  6354. // XOR blocks
  6355. for (var i = 0; i < blockSize; i++) {
  6356. words[offset + i] ^= block[i];
  6357. }
  6358. }
  6359. return CBC;
  6360. }());
  6361. /**
  6362. * Padding namespace.
  6363. */
  6364. var C_pad = C.pad = {};
  6365. /**
  6366. * PKCS #5/7 padding strategy.
  6367. */
  6368. var Pkcs7 = C_pad.Pkcs7 = {
  6369. /**
  6370. * Pads data using the algorithm defined in PKCS #5/7.
  6371. *
  6372. * @param {WordArray} data The data to pad.
  6373. * @param {number} blockSize The multiple that the data should be padded to.
  6374. *
  6375. * @static
  6376. *
  6377. * @example
  6378. *
  6379. * CryptoJS.pad.Pkcs7.pad(wordArray, 4);
  6380. */
  6381. pad: function (data, blockSize) {
  6382. // Shortcut
  6383. var blockSizeBytes = blockSize * 4;
  6384. // Count padding bytes
  6385. var nPaddingBytes = blockSizeBytes - data.sigBytes % blockSizeBytes;
  6386. // Create padding word
  6387. var paddingWord = (nPaddingBytes << 24) | (nPaddingBytes << 16) | (nPaddingBytes << 8) | nPaddingBytes;
  6388. // Create padding
  6389. var paddingWords = [];
  6390. for (var i = 0; i < nPaddingBytes; i += 4) {
  6391. paddingWords.push(paddingWord);
  6392. }
  6393. var padding = WordArray.create(paddingWords, nPaddingBytes);
  6394. // Add padding
  6395. data.concat(padding);
  6396. },
  6397. /**
  6398. * Unpads data that had been padded using the algorithm defined in PKCS #5/7.
  6399. *
  6400. * @param {WordArray} data The data to unpad.
  6401. *
  6402. * @static
  6403. *
  6404. * @example
  6405. *
  6406. * CryptoJS.pad.Pkcs7.unpad(wordArray);
  6407. */
  6408. unpad: function (data) {
  6409. // Get number of padding bytes from last byte
  6410. var nPaddingBytes = data.words[(data.sigBytes - 1) >>> 2] & 0xff;
  6411. // Remove padding
  6412. data.sigBytes -= nPaddingBytes;
  6413. }
  6414. };
  6415. /**
  6416. * Abstract base block cipher template.
  6417. *
  6418. * @property {number} blockSize The number of 32-bit words this cipher operates on. Default: 4 (128 bits)
  6419. */
  6420. var BlockCipher = C_lib.BlockCipher = Cipher.extend({
  6421. /**
  6422. * Configuration options.
  6423. *
  6424. * @property {Mode} mode The block mode to use. Default: CBC
  6425. * @property {Padding} padding The padding strategy to use. Default: Pkcs7
  6426. */
  6427. cfg: Cipher.cfg.extend({
  6428. mode: CBC,
  6429. padding: Pkcs7
  6430. }),
  6431. reset: function () {
  6432. // Reset cipher
  6433. Cipher.reset.call(this);
  6434. // Shortcuts
  6435. var cfg = this.cfg;
  6436. var iv = cfg.iv;
  6437. var mode = cfg.mode;
  6438. // Reset block mode
  6439. if (this._xformMode == this._ENC_XFORM_MODE) {
  6440. var modeCreator = mode.createEncryptor;
  6441. } else /* if (this._xformMode == this._DEC_XFORM_MODE) */ {
  6442. var modeCreator = mode.createDecryptor;
  6443. // Keep at least one block in the buffer for unpadding
  6444. this._minBufferSize = 1;
  6445. }
  6446. this._mode = modeCreator.call(mode, this, iv && iv.words);
  6447. },
  6448. _doProcessBlock: function (words, offset) {
  6449. this._mode.processBlock(words, offset);
  6450. },
  6451. _doFinalize: function () {
  6452. // Shortcut
  6453. var padding = this.cfg.padding;
  6454. // Finalize
  6455. if (this._xformMode == this._ENC_XFORM_MODE) {
  6456. // Pad data
  6457. padding.pad(this._data, this.blockSize);
  6458. // Process final blocks
  6459. var finalProcessedBlocks = this._process(!!'flush');
  6460. } else /* if (this._xformMode == this._DEC_XFORM_MODE) */ {
  6461. // Process final blocks
  6462. var finalProcessedBlocks = this._process(!!'flush');
  6463. // Unpad data
  6464. padding.unpad(finalProcessedBlocks);
  6465. }
  6466. return finalProcessedBlocks;
  6467. },
  6468. blockSize: 128/32
  6469. });
  6470. /**
  6471. * A collection of cipher parameters.
  6472. *
  6473. * @property {WordArray} ciphertext The raw ciphertext.
  6474. * @property {WordArray} key The key to this ciphertext.
  6475. * @property {WordArray} iv The IV used in the ciphering operation.
  6476. * @property {WordArray} salt The salt used with a key derivation function.
  6477. * @property {Cipher} algorithm The cipher algorithm.
  6478. * @property {Mode} mode The block mode used in the ciphering operation.
  6479. * @property {Padding} padding The padding scheme used in the ciphering operation.
  6480. * @property {number} blockSize The block size of the cipher.
  6481. * @property {Format} formatter The default formatting strategy to convert this cipher params object to a string.
  6482. */
  6483. var CipherParams = C_lib.CipherParams = Base.extend({
  6484. /**
  6485. * Initializes a newly created cipher params object.
  6486. *
  6487. * @param {Object} cipherParams An object with any of the possible cipher parameters.
  6488. *
  6489. * @example
  6490. *
  6491. * var cipherParams = CryptoJS.lib.CipherParams.create({
  6492. * ciphertext: ciphertextWordArray,
  6493. * key: keyWordArray,
  6494. * iv: ivWordArray,
  6495. * salt: saltWordArray,
  6496. * algorithm: CryptoJS.algo.AES,
  6497. * mode: CryptoJS.mode.CBC,
  6498. * padding: CryptoJS.pad.PKCS7,
  6499. * blockSize: 4,
  6500. * formatter: CryptoJS.format.OpenSSL
  6501. * });
  6502. */
  6503. init: function (cipherParams) {
  6504. this.mixIn(cipherParams);
  6505. },
  6506. /**
  6507. * Converts this cipher params object to a string.
  6508. *
  6509. * @param {Format} formatter (Optional) The formatting strategy to use.
  6510. *
  6511. * @return {string} The stringified cipher params.
  6512. *
  6513. * @throws Error If neither the formatter nor the default formatter is set.
  6514. *
  6515. * @example
  6516. *
  6517. * var string = cipherParams + '';
  6518. * var string = cipherParams.toString();
  6519. * var string = cipherParams.toString(CryptoJS.format.OpenSSL);
  6520. */
  6521. toString: function (formatter) {
  6522. return (formatter || this.formatter).stringify(this);
  6523. }
  6524. });
  6525. /**
  6526. * Format namespace.
  6527. */
  6528. var C_format = C.format = {};
  6529. /**
  6530. * OpenSSL formatting strategy.
  6531. */
  6532. var OpenSSLFormatter = C_format.OpenSSL = {
  6533. /**
  6534. * Converts a cipher params object to an OpenSSL-compatible string.
  6535. *
  6536. * @param {CipherParams} cipherParams The cipher params object.
  6537. *
  6538. * @return {string} The OpenSSL-compatible string.
  6539. *
  6540. * @static
  6541. *
  6542. * @example
  6543. *
  6544. * var openSSLString = CryptoJS.format.OpenSSL.stringify(cipherParams);
  6545. */
  6546. stringify: function (cipherParams) {
  6547. // Shortcuts
  6548. var ciphertext = cipherParams.ciphertext;
  6549. var salt = cipherParams.salt;
  6550. // Format
  6551. if (salt) {
  6552. var wordArray = WordArray.create([0x53616c74, 0x65645f5f]).concat(salt).concat(ciphertext);
  6553. } else {
  6554. var wordArray = ciphertext;
  6555. }
  6556. return wordArray.toString(Base64);
  6557. },
  6558. /**
  6559. * Converts an OpenSSL-compatible string to a cipher params object.
  6560. *
  6561. * @param {string} openSSLStr The OpenSSL-compatible string.
  6562. *
  6563. * @return {CipherParams} The cipher params object.
  6564. *
  6565. * @static
  6566. *
  6567. * @example
  6568. *
  6569. * var cipherParams = CryptoJS.format.OpenSSL.parse(openSSLString);
  6570. */
  6571. parse: function (openSSLStr) {
  6572. // Parse base64
  6573. var ciphertext = Base64.parse(openSSLStr);
  6574. // Shortcut
  6575. var ciphertextWords = ciphertext.words;
  6576. // Test for salt
  6577. if (ciphertextWords[0] == 0x53616c74 && ciphertextWords[1] == 0x65645f5f) {
  6578. // Extract salt
  6579. var salt = WordArray.create(ciphertextWords.slice(2, 4));
  6580. // Remove salt from ciphertext
  6581. ciphertextWords.splice(0, 4);
  6582. ciphertext.sigBytes -= 16;
  6583. }
  6584. return CipherParams.create({ ciphertext: ciphertext, salt: salt });
  6585. }
  6586. };
  6587. /**
  6588. * A cipher wrapper that returns ciphertext as a serializable cipher params object.
  6589. */
  6590. var SerializableCipher = C_lib.SerializableCipher = Base.extend({
  6591. /**
  6592. * Configuration options.
  6593. *
  6594. * @property {Formatter} format The formatting strategy to convert cipher param objects to and from a string. Default: OpenSSL
  6595. */
  6596. cfg: Base.extend({
  6597. format: OpenSSLFormatter
  6598. }),
  6599. /**
  6600. * Encrypts a message.
  6601. *
  6602. * @param {Cipher} cipher The cipher algorithm to use.
  6603. * @param {WordArray|string} message The message to encrypt.
  6604. * @param {WordArray} key The key.
  6605. * @param {Object} cfg (Optional) The configuration options to use for this operation.
  6606. *
  6607. * @return {CipherParams} A cipher params object.
  6608. *
  6609. * @static
  6610. *
  6611. * @example
  6612. *
  6613. * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key);
  6614. * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key, { iv: iv });
  6615. * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key, { iv: iv, format: CryptoJS.format.OpenSSL });
  6616. */
  6617. encrypt: function (cipher, message, key, cfg) {
  6618. // Apply config defaults
  6619. cfg = this.cfg.extend(cfg);
  6620. // Encrypt
  6621. var encryptor = cipher.createEncryptor(key, cfg);
  6622. var ciphertext = encryptor.finalize(message);
  6623. // Shortcut
  6624. var cipherCfg = encryptor.cfg;
  6625. // Create and return serializable cipher params
  6626. return CipherParams.create({
  6627. ciphertext: ciphertext,
  6628. key: key,
  6629. iv: cipherCfg.iv,
  6630. algorithm: cipher,
  6631. mode: cipherCfg.mode,
  6632. padding: cipherCfg.padding,
  6633. blockSize: cipher.blockSize,
  6634. formatter: cfg.format
  6635. });
  6636. },
  6637. /**
  6638. * Decrypts serialized ciphertext.
  6639. *
  6640. * @param {Cipher} cipher The cipher algorithm to use.
  6641. * @param {CipherParams|string} ciphertext The ciphertext to decrypt.
  6642. * @param {WordArray} key The key.
  6643. * @param {Object} cfg (Optional) The configuration options to use for this operation.
  6644. *
  6645. * @return {WordArray} The plaintext.
  6646. *
  6647. * @static
  6648. *
  6649. * @example
  6650. *
  6651. * var plaintext = CryptoJS.lib.SerializableCipher.decrypt(CryptoJS.algo.AES, formattedCiphertext, key, { iv: iv, format: CryptoJS.format.OpenSSL });
  6652. * var plaintext = CryptoJS.lib.SerializableCipher.decrypt(CryptoJS.algo.AES, ciphertextParams, key, { iv: iv, format: CryptoJS.format.OpenSSL });
  6653. */
  6654. decrypt: function (cipher, ciphertext, key, cfg) {
  6655. // Apply config defaults
  6656. cfg = this.cfg.extend(cfg);
  6657. // Convert string to CipherParams
  6658. ciphertext = this._parse(ciphertext, cfg.format);
  6659. // Decrypt
  6660. var plaintext = cipher.createDecryptor(key, cfg).finalize(ciphertext.ciphertext);
  6661. return plaintext;
  6662. },
  6663. /**
  6664. * Converts serialized ciphertext to CipherParams,
  6665. * else assumed CipherParams already and returns ciphertext unchanged.
  6666. *
  6667. * @param {CipherParams|string} ciphertext The ciphertext.
  6668. * @param {Formatter} format The formatting strategy to use to parse serialized ciphertext.
  6669. *
  6670. * @return {CipherParams} The unserialized ciphertext.
  6671. *
  6672. * @static
  6673. *
  6674. * @example
  6675. *
  6676. * var ciphertextParams = CryptoJS.lib.SerializableCipher._parse(ciphertextStringOrParams, format);
  6677. */
  6678. _parse: function (ciphertext, format) {
  6679. if (typeof ciphertext == 'string') {
  6680. return format.parse(ciphertext, this);
  6681. } else {
  6682. return ciphertext;
  6683. }
  6684. }
  6685. });
  6686. /**
  6687. * Key derivation function namespace.
  6688. */
  6689. var C_kdf = C.kdf = {};
  6690. /**
  6691. * OpenSSL key derivation function.
  6692. */
  6693. var OpenSSLKdf = C_kdf.OpenSSL = {
  6694. /**
  6695. * Derives a key and IV from a password.
  6696. *
  6697. * @param {string} password The password to derive from.
  6698. * @param {number} keySize The size in words of the key to generate.
  6699. * @param {number} ivSize The size in words of the IV to generate.
  6700. * @param {WordArray|string} salt (Optional) A 64-bit salt to use. If omitted, a salt will be generated randomly.
  6701. *
  6702. * @return {CipherParams} A cipher params object with the key, IV, and salt.
  6703. *
  6704. * @static
  6705. *
  6706. * @example
  6707. *
  6708. * var derivedParams = CryptoJS.kdf.OpenSSL.execute('Password', 256/32, 128/32);
  6709. * var derivedParams = CryptoJS.kdf.OpenSSL.execute('Password', 256/32, 128/32, 'saltsalt');
  6710. */
  6711. execute: function (password, keySize, ivSize, salt) {
  6712. // Generate random salt
  6713. if (!salt) {
  6714. salt = WordArray.random(64/8);
  6715. }
  6716. // Derive key and IV
  6717. var key = EvpKDF.create({ keySize: keySize + ivSize }).compute(password, salt);
  6718. // Separate key and IV
  6719. var iv = WordArray.create(key.words.slice(keySize), ivSize * 4);
  6720. key.sigBytes = keySize * 4;
  6721. // Return params
  6722. return CipherParams.create({ key: key, iv: iv, salt: salt });
  6723. }
  6724. };
  6725. /**
  6726. * A serializable cipher wrapper that derives the key from a password,
  6727. * and returns ciphertext as a serializable cipher params object.
  6728. */
  6729. var PasswordBasedCipher = C_lib.PasswordBasedCipher = SerializableCipher.extend({
  6730. /**
  6731. * Configuration options.
  6732. *
  6733. * @property {KDF} kdf The key derivation function to use to generate a key and IV from a password. Default: OpenSSL
  6734. */
  6735. cfg: SerializableCipher.cfg.extend({
  6736. kdf: OpenSSLKdf
  6737. }),
  6738. /**
  6739. * Encrypts a message using a password.
  6740. *
  6741. * @param {Cipher} cipher The cipher algorithm to use.
  6742. * @param {WordArray|string} message The message to encrypt.
  6743. * @param {string} password The password.
  6744. * @param {Object} cfg (Optional) The configuration options to use for this operation.
  6745. *
  6746. * @return {CipherParams} A cipher params object.
  6747. *
  6748. * @static
  6749. *
  6750. * @example
  6751. *
  6752. * var ciphertextParams = CryptoJS.lib.PasswordBasedCipher.encrypt(CryptoJS.algo.AES, message, 'password');
  6753. * var ciphertextParams = CryptoJS.lib.PasswordBasedCipher.encrypt(CryptoJS.algo.AES, message, 'password', { format: CryptoJS.format.OpenSSL });
  6754. */
  6755. encrypt: function (cipher, message, password, cfg) {
  6756. // Apply config defaults
  6757. cfg = this.cfg.extend(cfg);
  6758. // Derive key and other params
  6759. var derivedParams = cfg.kdf.execute(password, cipher.keySize, cipher.ivSize);
  6760. // Add IV to config
  6761. cfg.iv = derivedParams.iv;
  6762. // Encrypt
  6763. var ciphertext = SerializableCipher.encrypt.call(this, cipher, message, derivedParams.key, cfg);
  6764. // Mix in derived params
  6765. ciphertext.mixIn(derivedParams);
  6766. return ciphertext;
  6767. },
  6768. /**
  6769. * Decrypts serialized ciphertext using a password.
  6770. *
  6771. * @param {Cipher} cipher The cipher algorithm to use.
  6772. * @param {CipherParams|string} ciphertext The ciphertext to decrypt.
  6773. * @param {string} password The password.
  6774. * @param {Object} cfg (Optional) The configuration options to use for this operation.
  6775. *
  6776. * @return {WordArray} The plaintext.
  6777. *
  6778. * @static
  6779. *
  6780. * @example
  6781. *
  6782. * var plaintext = CryptoJS.lib.PasswordBasedCipher.decrypt(CryptoJS.algo.AES, formattedCiphertext, 'password', { format: CryptoJS.format.OpenSSL });
  6783. * var plaintext = CryptoJS.lib.PasswordBasedCipher.decrypt(CryptoJS.algo.AES, ciphertextParams, 'password', { format: CryptoJS.format.OpenSSL });
  6784. */
  6785. decrypt: function (cipher, ciphertext, password, cfg) {
  6786. // Apply config defaults
  6787. cfg = this.cfg.extend(cfg);
  6788. // Convert string to CipherParams
  6789. ciphertext = this._parse(ciphertext, cfg.format);
  6790. // Derive key and other params
  6791. var derivedParams = cfg.kdf.execute(password, cipher.keySize, cipher.ivSize, ciphertext.salt);
  6792. // Add IV to config
  6793. cfg.iv = derivedParams.iv;
  6794. // Decrypt
  6795. var plaintext = SerializableCipher.decrypt.call(this, cipher, ciphertext, derivedParams.key, cfg);
  6796. return plaintext;
  6797. }
  6798. });
  6799. }());
  6800. }));
  6801. },{"./core":53}],53:[function(require,module,exports){
  6802. ;(function (root, factory) {
  6803. if (typeof exports === "object") {
  6804. // CommonJS
  6805. module.exports = exports = factory();
  6806. }
  6807. else if (typeof define === "function" && define.amd) {
  6808. // AMD
  6809. define([], factory);
  6810. }
  6811. else {
  6812. // Global (browser)
  6813. root.CryptoJS = factory();
  6814. }
  6815. }(this, function () {
  6816. /**
  6817. * CryptoJS core components.
  6818. */
  6819. var CryptoJS = CryptoJS || (function (Math, undefined) {
  6820. /*
  6821. * Local polyfil of Object.create
  6822. */
  6823. var create = Object.create || (function () {
  6824. function F() {};
  6825. return function (obj) {
  6826. var subtype;
  6827. F.prototype = obj;
  6828. subtype = new F();
  6829. F.prototype = null;
  6830. return subtype;
  6831. };
  6832. }())
  6833. /**
  6834. * CryptoJS namespace.
  6835. */
  6836. var C = {};
  6837. /**
  6838. * Library namespace.
  6839. */
  6840. var C_lib = C.lib = {};
  6841. /**
  6842. * Base object for prototypal inheritance.
  6843. */
  6844. var Base = C_lib.Base = (function () {
  6845. return {
  6846. /**
  6847. * Creates a new object that inherits from this object.
  6848. *
  6849. * @param {Object} overrides Properties to copy into the new object.
  6850. *
  6851. * @return {Object} The new object.
  6852. *
  6853. * @static
  6854. *
  6855. * @example
  6856. *
  6857. * var MyType = CryptoJS.lib.Base.extend({
  6858. * field: 'value',
  6859. *
  6860. * method: function () {
  6861. * }
  6862. * });
  6863. */
  6864. extend: function (overrides) {
  6865. // Spawn
  6866. var subtype = create(this);
  6867. // Augment
  6868. if (overrides) {
  6869. subtype.mixIn(overrides);
  6870. }
  6871. // Create default initializer
  6872. if (!subtype.hasOwnProperty('init') || this.init === subtype.init) {
  6873. subtype.init = function () {
  6874. subtype.$super.init.apply(this, arguments);
  6875. };
  6876. }
  6877. // Initializer's prototype is the subtype object
  6878. subtype.init.prototype = subtype;
  6879. // Reference supertype
  6880. subtype.$super = this;
  6881. return subtype;
  6882. },
  6883. /**
  6884. * Extends this object and runs the init method.
  6885. * Arguments to create() will be passed to init().
  6886. *
  6887. * @return {Object} The new object.
  6888. *
  6889. * @static
  6890. *
  6891. * @example
  6892. *
  6893. * var instance = MyType.create();
  6894. */
  6895. create: function () {
  6896. var instance = this.extend();
  6897. instance.init.apply(instance, arguments);
  6898. return instance;
  6899. },
  6900. /**
  6901. * Initializes a newly created object.
  6902. * Override this method to add some logic when your objects are created.
  6903. *
  6904. * @example
  6905. *
  6906. * var MyType = CryptoJS.lib.Base.extend({
  6907. * init: function () {
  6908. * // ...
  6909. * }
  6910. * });
  6911. */
  6912. init: function () {
  6913. },
  6914. /**
  6915. * Copies properties into this object.
  6916. *
  6917. * @param {Object} properties The properties to mix in.
  6918. *
  6919. * @example
  6920. *
  6921. * MyType.mixIn({
  6922. * field: 'value'
  6923. * });
  6924. */
  6925. mixIn: function (properties) {
  6926. for (var propertyName in properties) {
  6927. if (properties.hasOwnProperty(propertyName)) {
  6928. this[propertyName] = properties[propertyName];
  6929. }
  6930. }
  6931. // IE won't copy toString using the loop above
  6932. if (properties.hasOwnProperty('toString')) {
  6933. this.toString = properties.toString;
  6934. }
  6935. },
  6936. /**
  6937. * Creates a copy of this object.
  6938. *
  6939. * @return {Object} The clone.
  6940. *
  6941. * @example
  6942. *
  6943. * var clone = instance.clone();
  6944. */
  6945. clone: function () {
  6946. return this.init.prototype.extend(this);
  6947. }
  6948. };
  6949. }());
  6950. /**
  6951. * An array of 32-bit words.
  6952. *
  6953. * @property {Array} words The array of 32-bit words.
  6954. * @property {number} sigBytes The number of significant bytes in this word array.
  6955. */
  6956. var WordArray = C_lib.WordArray = Base.extend({
  6957. /**
  6958. * Initializes a newly created word array.
  6959. *
  6960. * @param {Array} words (Optional) An array of 32-bit words.
  6961. * @param {number} sigBytes (Optional) The number of significant bytes in the words.
  6962. *
  6963. * @example
  6964. *
  6965. * var wordArray = CryptoJS.lib.WordArray.create();
  6966. * var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607]);
  6967. * var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607], 6);
  6968. */
  6969. init: function (words, sigBytes) {
  6970. words = this.words = words || [];
  6971. if (sigBytes != undefined) {
  6972. this.sigBytes = sigBytes;
  6973. } else {
  6974. this.sigBytes = words.length * 4;
  6975. }
  6976. },
  6977. /**
  6978. * Converts this word array to a string.
  6979. *
  6980. * @param {Encoder} encoder (Optional) The encoding strategy to use. Default: CryptoJS.enc.Hex
  6981. *
  6982. * @return {string} The stringified word array.
  6983. *
  6984. * @example
  6985. *
  6986. * var string = wordArray + '';
  6987. * var string = wordArray.toString();
  6988. * var string = wordArray.toString(CryptoJS.enc.Utf8);
  6989. */
  6990. toString: function (encoder) {
  6991. return (encoder || Hex).stringify(this);
  6992. },
  6993. /**
  6994. * Concatenates a word array to this word array.
  6995. *
  6996. * @param {WordArray} wordArray The word array to append.
  6997. *
  6998. * @return {WordArray} This word array.
  6999. *
  7000. * @example
  7001. *
  7002. * wordArray1.concat(wordArray2);
  7003. */
  7004. concat: function (wordArray) {
  7005. // Shortcuts
  7006. var thisWords = this.words;
  7007. var thatWords = wordArray.words;
  7008. var thisSigBytes = this.sigBytes;
  7009. var thatSigBytes = wordArray.sigBytes;
  7010. // Clamp excess bits
  7011. this.clamp();
  7012. // Concat
  7013. if (thisSigBytes % 4) {
  7014. // Copy one byte at a time
  7015. for (var i = 0; i < thatSigBytes; i++) {
  7016. var thatByte = (thatWords[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff;
  7017. thisWords[(thisSigBytes + i) >>> 2] |= thatByte << (24 - ((thisSigBytes + i) % 4) * 8);
  7018. }
  7019. } else {
  7020. // Copy one word at a time
  7021. for (var i = 0; i < thatSigBytes; i += 4) {
  7022. thisWords[(thisSigBytes + i) >>> 2] = thatWords[i >>> 2];
  7023. }
  7024. }
  7025. this.sigBytes += thatSigBytes;
  7026. // Chainable
  7027. return this;
  7028. },
  7029. /**
  7030. * Removes insignificant bits.
  7031. *
  7032. * @example
  7033. *
  7034. * wordArray.clamp();
  7035. */
  7036. clamp: function () {
  7037. // Shortcuts
  7038. var words = this.words;
  7039. var sigBytes = this.sigBytes;
  7040. // Clamp
  7041. words[sigBytes >>> 2] &= 0xffffffff << (32 - (sigBytes % 4) * 8);
  7042. words.length = Math.ceil(sigBytes / 4);
  7043. },
  7044. /**
  7045. * Creates a copy of this word array.
  7046. *
  7047. * @return {WordArray} The clone.
  7048. *
  7049. * @example
  7050. *
  7051. * var clone = wordArray.clone();
  7052. */
  7053. clone: function () {
  7054. var clone = Base.clone.call(this);
  7055. clone.words = this.words.slice(0);
  7056. return clone;
  7057. },
  7058. /**
  7059. * Creates a word array filled with random bytes.
  7060. *
  7061. * @param {number} nBytes The number of random bytes to generate.
  7062. *
  7063. * @return {WordArray} The random word array.
  7064. *
  7065. * @static
  7066. *
  7067. * @example
  7068. *
  7069. * var wordArray = CryptoJS.lib.WordArray.random(16);
  7070. */
  7071. random: function (nBytes) {
  7072. var words = [];
  7073. var r = (function (m_w) {
  7074. var m_w = m_w;
  7075. var m_z = 0x3ade68b1;
  7076. var mask = 0xffffffff;
  7077. return function () {
  7078. m_z = (0x9069 * (m_z & 0xFFFF) + (m_z >> 0x10)) & mask;
  7079. m_w = (0x4650 * (m_w & 0xFFFF) + (m_w >> 0x10)) & mask;
  7080. var result = ((m_z << 0x10) + m_w) & mask;
  7081. result /= 0x100000000;
  7082. result += 0.5;
  7083. return result * (Math.random() > .5 ? 1 : -1);
  7084. }
  7085. });
  7086. for (var i = 0, rcache; i < nBytes; i += 4) {
  7087. var _r = r((rcache || Math.random()) * 0x100000000);
  7088. rcache = _r() * 0x3ade67b7;
  7089. words.push((_r() * 0x100000000) | 0);
  7090. }
  7091. return new WordArray.init(words, nBytes);
  7092. }
  7093. });
  7094. /**
  7095. * Encoder namespace.
  7096. */
  7097. var C_enc = C.enc = {};
  7098. /**
  7099. * Hex encoding strategy.
  7100. */
  7101. var Hex = C_enc.Hex = {
  7102. /**
  7103. * Converts a word array to a hex string.
  7104. *
  7105. * @param {WordArray} wordArray The word array.
  7106. *
  7107. * @return {string} The hex string.
  7108. *
  7109. * @static
  7110. *
  7111. * @example
  7112. *
  7113. * var hexString = CryptoJS.enc.Hex.stringify(wordArray);
  7114. */
  7115. stringify: function (wordArray) {
  7116. // Shortcuts
  7117. var words = wordArray.words;
  7118. var sigBytes = wordArray.sigBytes;
  7119. // Convert
  7120. var hexChars = [];
  7121. for (var i = 0; i < sigBytes; i++) {
  7122. var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff;
  7123. hexChars.push((bite >>> 4).toString(16));
  7124. hexChars.push((bite & 0x0f).toString(16));
  7125. }
  7126. return hexChars.join('');
  7127. },
  7128. /**
  7129. * Converts a hex string to a word array.
  7130. *
  7131. * @param {string} hexStr The hex string.
  7132. *
  7133. * @return {WordArray} The word array.
  7134. *
  7135. * @static
  7136. *
  7137. * @example
  7138. *
  7139. * var wordArray = CryptoJS.enc.Hex.parse(hexString);
  7140. */
  7141. parse: function (hexStr) {
  7142. // Shortcut
  7143. var hexStrLength = hexStr.length;
  7144. // Convert
  7145. var words = [];
  7146. for (var i = 0; i < hexStrLength; i += 2) {
  7147. words[i >>> 3] |= parseInt(hexStr.substr(i, 2), 16) << (24 - (i % 8) * 4);
  7148. }
  7149. return new WordArray.init(words, hexStrLength / 2);
  7150. }
  7151. };
  7152. /**
  7153. * Latin1 encoding strategy.
  7154. */
  7155. var Latin1 = C_enc.Latin1 = {
  7156. /**
  7157. * Converts a word array to a Latin1 string.
  7158. *
  7159. * @param {WordArray} wordArray The word array.
  7160. *
  7161. * @return {string} The Latin1 string.
  7162. *
  7163. * @static
  7164. *
  7165. * @example
  7166. *
  7167. * var latin1String = CryptoJS.enc.Latin1.stringify(wordArray);
  7168. */
  7169. stringify: function (wordArray) {
  7170. // Shortcuts
  7171. var words = wordArray.words;
  7172. var sigBytes = wordArray.sigBytes;
  7173. // Convert
  7174. var latin1Chars = [];
  7175. for (var i = 0; i < sigBytes; i++) {
  7176. var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff;
  7177. latin1Chars.push(String.fromCharCode(bite));
  7178. }
  7179. return latin1Chars.join('');
  7180. },
  7181. /**
  7182. * Converts a Latin1 string to a word array.
  7183. *
  7184. * @param {string} latin1Str The Latin1 string.
  7185. *
  7186. * @return {WordArray} The word array.
  7187. *
  7188. * @static
  7189. *
  7190. * @example
  7191. *
  7192. * var wordArray = CryptoJS.enc.Latin1.parse(latin1String);
  7193. */
  7194. parse: function (latin1Str) {
  7195. // Shortcut
  7196. var latin1StrLength = latin1Str.length;
  7197. // Convert
  7198. var words = [];
  7199. for (var i = 0; i < latin1StrLength; i++) {
  7200. words[i >>> 2] |= (latin1Str.charCodeAt(i) & 0xff) << (24 - (i % 4) * 8);
  7201. }
  7202. return new WordArray.init(words, latin1StrLength);
  7203. }
  7204. };
  7205. /**
  7206. * UTF-8 encoding strategy.
  7207. */
  7208. var Utf8 = C_enc.Utf8 = {
  7209. /**
  7210. * Converts a word array to a UTF-8 string.
  7211. *
  7212. * @param {WordArray} wordArray The word array.
  7213. *
  7214. * @return {string} The UTF-8 string.
  7215. *
  7216. * @static
  7217. *
  7218. * @example
  7219. *
  7220. * var utf8String = CryptoJS.enc.Utf8.stringify(wordArray);
  7221. */
  7222. stringify: function (wordArray) {
  7223. try {
  7224. return decodeURIComponent(escape(Latin1.stringify(wordArray)));
  7225. } catch (e) {
  7226. throw new Error('Malformed UTF-8 data');
  7227. }
  7228. },
  7229. /**
  7230. * Converts a UTF-8 string to a word array.
  7231. *
  7232. * @param {string} utf8Str The UTF-8 string.
  7233. *
  7234. * @return {WordArray} The word array.
  7235. *
  7236. * @static
  7237. *
  7238. * @example
  7239. *
  7240. * var wordArray = CryptoJS.enc.Utf8.parse(utf8String);
  7241. */
  7242. parse: function (utf8Str) {
  7243. return Latin1.parse(unescape(encodeURIComponent(utf8Str)));
  7244. }
  7245. };
  7246. /**
  7247. * Abstract buffered block algorithm template.
  7248. *
  7249. * The property blockSize must be implemented in a concrete subtype.
  7250. *
  7251. * @property {number} _minBufferSize The number of blocks that should be kept unprocessed in the buffer. Default: 0
  7252. */
  7253. var BufferedBlockAlgorithm = C_lib.BufferedBlockAlgorithm = Base.extend({
  7254. /**
  7255. * Resets this block algorithm's data buffer to its initial state.
  7256. *
  7257. * @example
  7258. *
  7259. * bufferedBlockAlgorithm.reset();
  7260. */
  7261. reset: function () {
  7262. // Initial values
  7263. this._data = new WordArray.init();
  7264. this._nDataBytes = 0;
  7265. },
  7266. /**
  7267. * Adds new data to this block algorithm's buffer.
  7268. *
  7269. * @param {WordArray|string} data The data to append. Strings are converted to a WordArray using UTF-8.
  7270. *
  7271. * @example
  7272. *
  7273. * bufferedBlockAlgorithm._append('data');
  7274. * bufferedBlockAlgorithm._append(wordArray);
  7275. */
  7276. _append: function (data) {
  7277. // Convert string to WordArray, else assume WordArray already
  7278. if (typeof data == 'string') {
  7279. data = Utf8.parse(data);
  7280. }
  7281. // Append
  7282. this._data.concat(data);
  7283. this._nDataBytes += data.sigBytes;
  7284. },
  7285. /**
  7286. * Processes available data blocks.
  7287. *
  7288. * This method invokes _doProcessBlock(offset), which must be implemented by a concrete subtype.
  7289. *
  7290. * @param {boolean} doFlush Whether all blocks and partial blocks should be processed.
  7291. *
  7292. * @return {WordArray} The processed data.
  7293. *
  7294. * @example
  7295. *
  7296. * var processedData = bufferedBlockAlgorithm._process();
  7297. * var processedData = bufferedBlockAlgorithm._process(!!'flush');
  7298. */
  7299. _process: function (doFlush) {
  7300. // Shortcuts
  7301. var data = this._data;
  7302. var dataWords = data.words;
  7303. var dataSigBytes = data.sigBytes;
  7304. var blockSize = this.blockSize;
  7305. var blockSizeBytes = blockSize * 4;
  7306. // Count blocks ready
  7307. var nBlocksReady = dataSigBytes / blockSizeBytes;
  7308. if (doFlush) {
  7309. // Round up to include partial blocks
  7310. nBlocksReady = Math.ceil(nBlocksReady);
  7311. } else {
  7312. // Round down to include only full blocks,
  7313. // less the number of blocks that must remain in the buffer
  7314. nBlocksReady = Math.max((nBlocksReady | 0) - this._minBufferSize, 0);
  7315. }
  7316. // Count words ready
  7317. var nWordsReady = nBlocksReady * blockSize;
  7318. // Count bytes ready
  7319. var nBytesReady = Math.min(nWordsReady * 4, dataSigBytes);
  7320. // Process blocks
  7321. if (nWordsReady) {
  7322. for (var offset = 0; offset < nWordsReady; offset += blockSize) {
  7323. // Perform concrete-algorithm logic
  7324. this._doProcessBlock(dataWords, offset);
  7325. }
  7326. // Remove processed words
  7327. var processedWords = dataWords.splice(0, nWordsReady);
  7328. data.sigBytes -= nBytesReady;
  7329. }
  7330. // Return processed words
  7331. return new WordArray.init(processedWords, nBytesReady);
  7332. },
  7333. /**
  7334. * Creates a copy of this object.
  7335. *
  7336. * @return {Object} The clone.
  7337. *
  7338. * @example
  7339. *
  7340. * var clone = bufferedBlockAlgorithm.clone();
  7341. */
  7342. clone: function () {
  7343. var clone = Base.clone.call(this);
  7344. clone._data = this._data.clone();
  7345. return clone;
  7346. },
  7347. _minBufferSize: 0
  7348. });
  7349. /**
  7350. * Abstract hasher template.
  7351. *
  7352. * @property {number} blockSize The number of 32-bit words this hasher operates on. Default: 16 (512 bits)
  7353. */
  7354. var Hasher = C_lib.Hasher = BufferedBlockAlgorithm.extend({
  7355. /**
  7356. * Configuration options.
  7357. */
  7358. cfg: Base.extend(),
  7359. /**
  7360. * Initializes a newly created hasher.
  7361. *
  7362. * @param {Object} cfg (Optional) The configuration options to use for this hash computation.
  7363. *
  7364. * @example
  7365. *
  7366. * var hasher = CryptoJS.algo.SHA256.create();
  7367. */
  7368. init: function (cfg) {
  7369. // Apply config defaults
  7370. this.cfg = this.cfg.extend(cfg);
  7371. // Set initial values
  7372. this.reset();
  7373. },
  7374. /**
  7375. * Resets this hasher to its initial state.
  7376. *
  7377. * @example
  7378. *
  7379. * hasher.reset();
  7380. */
  7381. reset: function () {
  7382. // Reset data buffer
  7383. BufferedBlockAlgorithm.reset.call(this);
  7384. // Perform concrete-hasher logic
  7385. this._doReset();
  7386. },
  7387. /**
  7388. * Updates this hasher with a message.
  7389. *
  7390. * @param {WordArray|string} messageUpdate The message to append.
  7391. *
  7392. * @return {Hasher} This hasher.
  7393. *
  7394. * @example
  7395. *
  7396. * hasher.update('message');
  7397. * hasher.update(wordArray);
  7398. */
  7399. update: function (messageUpdate) {
  7400. // Append
  7401. this._append(messageUpdate);
  7402. // Update the hash
  7403. this._process();
  7404. // Chainable
  7405. return this;
  7406. },
  7407. /**
  7408. * Finalizes the hash computation.
  7409. * Note that the finalize operation is effectively a destructive, read-once operation.
  7410. *
  7411. * @param {WordArray|string} messageUpdate (Optional) A final message update.
  7412. *
  7413. * @return {WordArray} The hash.
  7414. *
  7415. * @example
  7416. *
  7417. * var hash = hasher.finalize();
  7418. * var hash = hasher.finalize('message');
  7419. * var hash = hasher.finalize(wordArray);
  7420. */
  7421. finalize: function (messageUpdate) {
  7422. // Final message update
  7423. if (messageUpdate) {
  7424. this._append(messageUpdate);
  7425. }
  7426. // Perform concrete-hasher logic
  7427. var hash = this._doFinalize();
  7428. return hash;
  7429. },
  7430. blockSize: 512/32,
  7431. /**
  7432. * Creates a shortcut function to a hasher's object interface.
  7433. *
  7434. * @param {Hasher} hasher The hasher to create a helper for.
  7435. *
  7436. * @return {Function} The shortcut function.
  7437. *
  7438. * @static
  7439. *
  7440. * @example
  7441. *
  7442. * var SHA256 = CryptoJS.lib.Hasher._createHelper(CryptoJS.algo.SHA256);
  7443. */
  7444. _createHelper: function (hasher) {
  7445. return function (message, cfg) {
  7446. return new hasher.init(cfg).finalize(message);
  7447. };
  7448. },
  7449. /**
  7450. * Creates a shortcut function to the HMAC's object interface.
  7451. *
  7452. * @param {Hasher} hasher The hasher to use in this HMAC helper.
  7453. *
  7454. * @return {Function} The shortcut function.
  7455. *
  7456. * @static
  7457. *
  7458. * @example
  7459. *
  7460. * var HmacSHA256 = CryptoJS.lib.Hasher._createHmacHelper(CryptoJS.algo.SHA256);
  7461. */
  7462. _createHmacHelper: function (hasher) {
  7463. return function (message, key) {
  7464. return new C_algo.HMAC.init(hasher, key).finalize(message);
  7465. };
  7466. }
  7467. });
  7468. /**
  7469. * Algorithm namespace.
  7470. */
  7471. var C_algo = C.algo = {};
  7472. return C;
  7473. }(Math));
  7474. return CryptoJS;
  7475. }));
  7476. },{}],54:[function(require,module,exports){
  7477. ;(function (root, factory) {
  7478. if (typeof exports === "object") {
  7479. // CommonJS
  7480. module.exports = exports = factory(require("./core"));
  7481. }
  7482. else if (typeof define === "function" && define.amd) {
  7483. // AMD
  7484. define(["./core"], factory);
  7485. }
  7486. else {
  7487. // Global (browser)
  7488. factory(root.CryptoJS);
  7489. }
  7490. }(this, function (CryptoJS) {
  7491. (function () {
  7492. // Shortcuts
  7493. var C = CryptoJS;
  7494. var C_lib = C.lib;
  7495. var WordArray = C_lib.WordArray;
  7496. var C_enc = C.enc;
  7497. /**
  7498. * Base64 encoding strategy.
  7499. */
  7500. var Base64 = C_enc.Base64 = {
  7501. /**
  7502. * Converts a word array to a Base64 string.
  7503. *
  7504. * @param {WordArray} wordArray The word array.
  7505. *
  7506. * @return {string} The Base64 string.
  7507. *
  7508. * @static
  7509. *
  7510. * @example
  7511. *
  7512. * var base64String = CryptoJS.enc.Base64.stringify(wordArray);
  7513. */
  7514. stringify: function (wordArray) {
  7515. // Shortcuts
  7516. var words = wordArray.words;
  7517. var sigBytes = wordArray.sigBytes;
  7518. var map = this._map;
  7519. // Clamp excess bits
  7520. wordArray.clamp();
  7521. // Convert
  7522. var base64Chars = [];
  7523. for (var i = 0; i < sigBytes; i += 3) {
  7524. var byte1 = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff;
  7525. var byte2 = (words[(i + 1) >>> 2] >>> (24 - ((i + 1) % 4) * 8)) & 0xff;
  7526. var byte3 = (words[(i + 2) >>> 2] >>> (24 - ((i + 2) % 4) * 8)) & 0xff;
  7527. var triplet = (byte1 << 16) | (byte2 << 8) | byte3;
  7528. for (var j = 0; (j < 4) && (i + j * 0.75 < sigBytes); j++) {
  7529. base64Chars.push(map.charAt((triplet >>> (6 * (3 - j))) & 0x3f));
  7530. }
  7531. }
  7532. // Add padding
  7533. var paddingChar = map.charAt(64);
  7534. if (paddingChar) {
  7535. while (base64Chars.length % 4) {
  7536. base64Chars.push(paddingChar);
  7537. }
  7538. }
  7539. return base64Chars.join('');
  7540. },
  7541. /**
  7542. * Converts a Base64 string to a word array.
  7543. *
  7544. * @param {string} base64Str The Base64 string.
  7545. *
  7546. * @return {WordArray} The word array.
  7547. *
  7548. * @static
  7549. *
  7550. * @example
  7551. *
  7552. * var wordArray = CryptoJS.enc.Base64.parse(base64String);
  7553. */
  7554. parse: function (base64Str) {
  7555. // Shortcuts
  7556. var base64StrLength = base64Str.length;
  7557. var map = this._map;
  7558. var reverseMap = this._reverseMap;
  7559. if (!reverseMap) {
  7560. reverseMap = this._reverseMap = [];
  7561. for (var j = 0; j < map.length; j++) {
  7562. reverseMap[map.charCodeAt(j)] = j;
  7563. }
  7564. }
  7565. // Ignore padding
  7566. var paddingChar = map.charAt(64);
  7567. if (paddingChar) {
  7568. var paddingIndex = base64Str.indexOf(paddingChar);
  7569. if (paddingIndex !== -1) {
  7570. base64StrLength = paddingIndex;
  7571. }
  7572. }
  7573. // Convert
  7574. return parseLoop(base64Str, base64StrLength, reverseMap);
  7575. },
  7576. _map: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='
  7577. };
  7578. function parseLoop(base64Str, base64StrLength, reverseMap) {
  7579. var words = [];
  7580. var nBytes = 0;
  7581. for (var i = 0; i < base64StrLength; i++) {
  7582. if (i % 4) {
  7583. var bits1 = reverseMap[base64Str.charCodeAt(i - 1)] << ((i % 4) * 2);
  7584. var bits2 = reverseMap[base64Str.charCodeAt(i)] >>> (6 - (i % 4) * 2);
  7585. words[nBytes >>> 2] |= (bits1 | bits2) << (24 - (nBytes % 4) * 8);
  7586. nBytes++;
  7587. }
  7588. }
  7589. return WordArray.create(words, nBytes);
  7590. }
  7591. }());
  7592. return CryptoJS.enc.Base64;
  7593. }));
  7594. },{"./core":53}],55:[function(require,module,exports){
  7595. ;(function (root, factory) {
  7596. if (typeof exports === "object") {
  7597. // CommonJS
  7598. module.exports = exports = factory(require("./core"));
  7599. }
  7600. else if (typeof define === "function" && define.amd) {
  7601. // AMD
  7602. define(["./core"], factory);
  7603. }
  7604. else {
  7605. // Global (browser)
  7606. factory(root.CryptoJS);
  7607. }
  7608. }(this, function (CryptoJS) {
  7609. (function () {
  7610. // Shortcuts
  7611. var C = CryptoJS;
  7612. var C_lib = C.lib;
  7613. var WordArray = C_lib.WordArray;
  7614. var C_enc = C.enc;
  7615. /**
  7616. * UTF-16 BE encoding strategy.
  7617. */
  7618. var Utf16BE = C_enc.Utf16 = C_enc.Utf16BE = {
  7619. /**
  7620. * Converts a word array to a UTF-16 BE string.
  7621. *
  7622. * @param {WordArray} wordArray The word array.
  7623. *
  7624. * @return {string} The UTF-16 BE string.
  7625. *
  7626. * @static
  7627. *
  7628. * @example
  7629. *
  7630. * var utf16String = CryptoJS.enc.Utf16.stringify(wordArray);
  7631. */
  7632. stringify: function (wordArray) {
  7633. // Shortcuts
  7634. var words = wordArray.words;
  7635. var sigBytes = wordArray.sigBytes;
  7636. // Convert
  7637. var utf16Chars = [];
  7638. for (var i = 0; i < sigBytes; i += 2) {
  7639. var codePoint = (words[i >>> 2] >>> (16 - (i % 4) * 8)) & 0xffff;
  7640. utf16Chars.push(String.fromCharCode(codePoint));
  7641. }
  7642. return utf16Chars.join('');
  7643. },
  7644. /**
  7645. * Converts a UTF-16 BE string to a word array.
  7646. *
  7647. * @param {string} utf16Str The UTF-16 BE string.
  7648. *
  7649. * @return {WordArray} The word array.
  7650. *
  7651. * @static
  7652. *
  7653. * @example
  7654. *
  7655. * var wordArray = CryptoJS.enc.Utf16.parse(utf16String);
  7656. */
  7657. parse: function (utf16Str) {
  7658. // Shortcut
  7659. var utf16StrLength = utf16Str.length;
  7660. // Convert
  7661. var words = [];
  7662. for (var i = 0; i < utf16StrLength; i++) {
  7663. words[i >>> 1] |= utf16Str.charCodeAt(i) << (16 - (i % 2) * 16);
  7664. }
  7665. return WordArray.create(words, utf16StrLength * 2);
  7666. }
  7667. };
  7668. /**
  7669. * UTF-16 LE encoding strategy.
  7670. */
  7671. C_enc.Utf16LE = {
  7672. /**
  7673. * Converts a word array to a UTF-16 LE string.
  7674. *
  7675. * @param {WordArray} wordArray The word array.
  7676. *
  7677. * @return {string} The UTF-16 LE string.
  7678. *
  7679. * @static
  7680. *
  7681. * @example
  7682. *
  7683. * var utf16Str = CryptoJS.enc.Utf16LE.stringify(wordArray);
  7684. */
  7685. stringify: function (wordArray) {
  7686. // Shortcuts
  7687. var words = wordArray.words;
  7688. var sigBytes = wordArray.sigBytes;
  7689. // Convert
  7690. var utf16Chars = [];
  7691. for (var i = 0; i < sigBytes; i += 2) {
  7692. var codePoint = swapEndian((words[i >>> 2] >>> (16 - (i % 4) * 8)) & 0xffff);
  7693. utf16Chars.push(String.fromCharCode(codePoint));
  7694. }
  7695. return utf16Chars.join('');
  7696. },
  7697. /**
  7698. * Converts a UTF-16 LE string to a word array.
  7699. *
  7700. * @param {string} utf16Str The UTF-16 LE string.
  7701. *
  7702. * @return {WordArray} The word array.
  7703. *
  7704. * @static
  7705. *
  7706. * @example
  7707. *
  7708. * var wordArray = CryptoJS.enc.Utf16LE.parse(utf16Str);
  7709. */
  7710. parse: function (utf16Str) {
  7711. // Shortcut
  7712. var utf16StrLength = utf16Str.length;
  7713. // Convert
  7714. var words = [];
  7715. for (var i = 0; i < utf16StrLength; i++) {
  7716. words[i >>> 1] |= swapEndian(utf16Str.charCodeAt(i) << (16 - (i % 2) * 16));
  7717. }
  7718. return WordArray.create(words, utf16StrLength * 2);
  7719. }
  7720. };
  7721. function swapEndian(word) {
  7722. return ((word << 8) & 0xff00ff00) | ((word >>> 8) & 0x00ff00ff);
  7723. }
  7724. }());
  7725. return CryptoJS.enc.Utf16;
  7726. }));
  7727. },{"./core":53}],56:[function(require,module,exports){
  7728. ;(function (root, factory, undef) {
  7729. if (typeof exports === "object") {
  7730. // CommonJS
  7731. module.exports = exports = factory(require("./core"), require("./sha1"), require("./hmac"));
  7732. }
  7733. else if (typeof define === "function" && define.amd) {
  7734. // AMD
  7735. define(["./core", "./sha1", "./hmac"], factory);
  7736. }
  7737. else {
  7738. // Global (browser)
  7739. factory(root.CryptoJS);
  7740. }
  7741. }(this, function (CryptoJS) {
  7742. (function () {
  7743. // Shortcuts
  7744. var C = CryptoJS;
  7745. var C_lib = C.lib;
  7746. var Base = C_lib.Base;
  7747. var WordArray = C_lib.WordArray;
  7748. var C_algo = C.algo;
  7749. var MD5 = C_algo.MD5;
  7750. /**
  7751. * This key derivation function is meant to conform with EVP_BytesToKey.
  7752. * www.openssl.org/docs/crypto/EVP_BytesToKey.html
  7753. */
  7754. var EvpKDF = C_algo.EvpKDF = Base.extend({
  7755. /**
  7756. * Configuration options.
  7757. *
  7758. * @property {number} keySize The key size in words to generate. Default: 4 (128 bits)
  7759. * @property {Hasher} hasher The hash algorithm to use. Default: MD5
  7760. * @property {number} iterations The number of iterations to perform. Default: 1
  7761. */
  7762. cfg: Base.extend({
  7763. keySize: 128/32,
  7764. hasher: MD5,
  7765. iterations: 1
  7766. }),
  7767. /**
  7768. * Initializes a newly created key derivation function.
  7769. *
  7770. * @param {Object} cfg (Optional) The configuration options to use for the derivation.
  7771. *
  7772. * @example
  7773. *
  7774. * var kdf = CryptoJS.algo.EvpKDF.create();
  7775. * var kdf = CryptoJS.algo.EvpKDF.create({ keySize: 8 });
  7776. * var kdf = CryptoJS.algo.EvpKDF.create({ keySize: 8, iterations: 1000 });
  7777. */
  7778. init: function (cfg) {
  7779. this.cfg = this.cfg.extend(cfg);
  7780. },
  7781. /**
  7782. * Derives a key from a password.
  7783. *
  7784. * @param {WordArray|string} password The password.
  7785. * @param {WordArray|string} salt A salt.
  7786. *
  7787. * @return {WordArray} The derived key.
  7788. *
  7789. * @example
  7790. *
  7791. * var key = kdf.compute(password, salt);
  7792. */
  7793. compute: function (password, salt) {
  7794. // Shortcut
  7795. var cfg = this.cfg;
  7796. // Init hasher
  7797. var hasher = cfg.hasher.create();
  7798. // Initial values
  7799. var derivedKey = WordArray.create();
  7800. // Shortcuts
  7801. var derivedKeyWords = derivedKey.words;
  7802. var keySize = cfg.keySize;
  7803. var iterations = cfg.iterations;
  7804. // Generate key
  7805. while (derivedKeyWords.length < keySize) {
  7806. if (block) {
  7807. hasher.update(block);
  7808. }
  7809. var block = hasher.update(password).finalize(salt);
  7810. hasher.reset();
  7811. // Iterations
  7812. for (var i = 1; i < iterations; i++) {
  7813. block = hasher.finalize(block);
  7814. hasher.reset();
  7815. }
  7816. derivedKey.concat(block);
  7817. }
  7818. derivedKey.sigBytes = keySize * 4;
  7819. return derivedKey;
  7820. }
  7821. });
  7822. /**
  7823. * Derives a key from a password.
  7824. *
  7825. * @param {WordArray|string} password The password.
  7826. * @param {WordArray|string} salt A salt.
  7827. * @param {Object} cfg (Optional) The configuration options to use for this computation.
  7828. *
  7829. * @return {WordArray} The derived key.
  7830. *
  7831. * @static
  7832. *
  7833. * @example
  7834. *
  7835. * var key = CryptoJS.EvpKDF(password, salt);
  7836. * var key = CryptoJS.EvpKDF(password, salt, { keySize: 8 });
  7837. * var key = CryptoJS.EvpKDF(password, salt, { keySize: 8, iterations: 1000 });
  7838. */
  7839. C.EvpKDF = function (password, salt, cfg) {
  7840. return EvpKDF.create(cfg).compute(password, salt);
  7841. };
  7842. }());
  7843. return CryptoJS.EvpKDF;
  7844. }));
  7845. },{"./core":53,"./hmac":58,"./sha1":77}],57:[function(require,module,exports){
  7846. ;(function (root, factory, undef) {
  7847. if (typeof exports === "object") {
  7848. // CommonJS
  7849. module.exports = exports = factory(require("./core"), require("./cipher-core"));
  7850. }
  7851. else if (typeof define === "function" && define.amd) {
  7852. // AMD
  7853. define(["./core", "./cipher-core"], factory);
  7854. }
  7855. else {
  7856. // Global (browser)
  7857. factory(root.CryptoJS);
  7858. }
  7859. }(this, function (CryptoJS) {
  7860. (function (undefined) {
  7861. // Shortcuts
  7862. var C = CryptoJS;
  7863. var C_lib = C.lib;
  7864. var CipherParams = C_lib.CipherParams;
  7865. var C_enc = C.enc;
  7866. var Hex = C_enc.Hex;
  7867. var C_format = C.format;
  7868. var HexFormatter = C_format.Hex = {
  7869. /**
  7870. * Converts the ciphertext of a cipher params object to a hexadecimally encoded string.
  7871. *
  7872. * @param {CipherParams} cipherParams The cipher params object.
  7873. *
  7874. * @return {string} The hexadecimally encoded string.
  7875. *
  7876. * @static
  7877. *
  7878. * @example
  7879. *
  7880. * var hexString = CryptoJS.format.Hex.stringify(cipherParams);
  7881. */
  7882. stringify: function (cipherParams) {
  7883. return cipherParams.ciphertext.toString(Hex);
  7884. },
  7885. /**
  7886. * Converts a hexadecimally encoded ciphertext string to a cipher params object.
  7887. *
  7888. * @param {string} input The hexadecimally encoded string.
  7889. *
  7890. * @return {CipherParams} The cipher params object.
  7891. *
  7892. * @static
  7893. *
  7894. * @example
  7895. *
  7896. * var cipherParams = CryptoJS.format.Hex.parse(hexString);
  7897. */
  7898. parse: function (input) {
  7899. var ciphertext = Hex.parse(input);
  7900. return CipherParams.create({ ciphertext: ciphertext });
  7901. }
  7902. };
  7903. }());
  7904. return CryptoJS.format.Hex;
  7905. }));
  7906. },{"./cipher-core":52,"./core":53}],58:[function(require,module,exports){
  7907. ;(function (root, factory) {
  7908. if (typeof exports === "object") {
  7909. // CommonJS
  7910. module.exports = exports = factory(require("./core"));
  7911. }
  7912. else if (typeof define === "function" && define.amd) {
  7913. // AMD
  7914. define(["./core"], factory);
  7915. }
  7916. else {
  7917. // Global (browser)
  7918. factory(root.CryptoJS);
  7919. }
  7920. }(this, function (CryptoJS) {
  7921. (function () {
  7922. // Shortcuts
  7923. var C = CryptoJS;
  7924. var C_lib = C.lib;
  7925. var Base = C_lib.Base;
  7926. var C_enc = C.enc;
  7927. var Utf8 = C_enc.Utf8;
  7928. var C_algo = C.algo;
  7929. /**
  7930. * HMAC algorithm.
  7931. */
  7932. var HMAC = C_algo.HMAC = Base.extend({
  7933. /**
  7934. * Initializes a newly created HMAC.
  7935. *
  7936. * @param {Hasher} hasher The hash algorithm to use.
  7937. * @param {WordArray|string} key The secret key.
  7938. *
  7939. * @example
  7940. *
  7941. * var hmacHasher = CryptoJS.algo.HMAC.create(CryptoJS.algo.SHA256, key);
  7942. */
  7943. init: function (hasher, key) {
  7944. // Init hasher
  7945. hasher = this._hasher = new hasher.init();
  7946. // Convert string to WordArray, else assume WordArray already
  7947. if (typeof key == 'string') {
  7948. key = Utf8.parse(key);
  7949. }
  7950. // Shortcuts
  7951. var hasherBlockSize = hasher.blockSize;
  7952. var hasherBlockSizeBytes = hasherBlockSize * 4;
  7953. // Allow arbitrary length keys
  7954. if (key.sigBytes > hasherBlockSizeBytes) {
  7955. key = hasher.finalize(key);
  7956. }
  7957. // Clamp excess bits
  7958. key.clamp();
  7959. // Clone key for inner and outer pads
  7960. var oKey = this._oKey = key.clone();
  7961. var iKey = this._iKey = key.clone();
  7962. // Shortcuts
  7963. var oKeyWords = oKey.words;
  7964. var iKeyWords = iKey.words;
  7965. // XOR keys with pad constants
  7966. for (var i = 0; i < hasherBlockSize; i++) {
  7967. oKeyWords[i] ^= 0x5c5c5c5c;
  7968. iKeyWords[i] ^= 0x36363636;
  7969. }
  7970. oKey.sigBytes = iKey.sigBytes = hasherBlockSizeBytes;
  7971. // Set initial values
  7972. this.reset();
  7973. },
  7974. /**
  7975. * Resets this HMAC to its initial state.
  7976. *
  7977. * @example
  7978. *
  7979. * hmacHasher.reset();
  7980. */
  7981. reset: function () {
  7982. // Shortcut
  7983. var hasher = this._hasher;
  7984. // Reset
  7985. hasher.reset();
  7986. hasher.update(this._iKey);
  7987. },
  7988. /**
  7989. * Updates this HMAC with a message.
  7990. *
  7991. * @param {WordArray|string} messageUpdate The message to append.
  7992. *
  7993. * @return {HMAC} This HMAC instance.
  7994. *
  7995. * @example
  7996. *
  7997. * hmacHasher.update('message');
  7998. * hmacHasher.update(wordArray);
  7999. */
  8000. update: function (messageUpdate) {
  8001. this._hasher.update(messageUpdate);
  8002. // Chainable
  8003. return this;
  8004. },
  8005. /**
  8006. * Finalizes the HMAC computation.
  8007. * Note that the finalize operation is effectively a destructive, read-once operation.
  8008. *
  8009. * @param {WordArray|string} messageUpdate (Optional) A final message update.
  8010. *
  8011. * @return {WordArray} The HMAC.
  8012. *
  8013. * @example
  8014. *
  8015. * var hmac = hmacHasher.finalize();
  8016. * var hmac = hmacHasher.finalize('message');
  8017. * var hmac = hmacHasher.finalize(wordArray);
  8018. */
  8019. finalize: function (messageUpdate) {
  8020. // Shortcut
  8021. var hasher = this._hasher;
  8022. // Compute HMAC
  8023. var innerHash = hasher.finalize(messageUpdate);
  8024. hasher.reset();
  8025. var hmac = hasher.finalize(this._oKey.clone().concat(innerHash));
  8026. return hmac;
  8027. }
  8028. });
  8029. }());
  8030. }));
  8031. },{"./core":53}],59:[function(require,module,exports){
  8032. ;(function (root, factory, undef) {
  8033. if (typeof exports === "object") {
  8034. // CommonJS
  8035. 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"));
  8036. }
  8037. else if (typeof define === "function" && define.amd) {
  8038. // AMD
  8039. 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);
  8040. }
  8041. else {
  8042. // Global (browser)
  8043. root.CryptoJS = factory(root.CryptoJS);
  8044. }
  8045. }(this, function (CryptoJS) {
  8046. return CryptoJS;
  8047. }));
  8048. },{"./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){
  8049. ;(function (root, factory) {
  8050. if (typeof exports === "object") {
  8051. // CommonJS
  8052. module.exports = exports = factory(require("./core"));
  8053. }
  8054. else if (typeof define === "function" && define.amd) {
  8055. // AMD
  8056. define(["./core"], factory);
  8057. }
  8058. else {
  8059. // Global (browser)
  8060. factory(root.CryptoJS);
  8061. }
  8062. }(this, function (CryptoJS) {
  8063. (function () {
  8064. // Check if typed arrays are supported
  8065. if (typeof ArrayBuffer != 'function') {
  8066. return;
  8067. }
  8068. // Shortcuts
  8069. var C = CryptoJS;
  8070. var C_lib = C.lib;
  8071. var WordArray = C_lib.WordArray;
  8072. // Reference original init
  8073. var superInit = WordArray.init;
  8074. // Augment WordArray.init to handle typed arrays
  8075. var subInit = WordArray.init = function (typedArray) {
  8076. // Convert buffers to uint8
  8077. if (typedArray instanceof ArrayBuffer) {
  8078. typedArray = new Uint8Array(typedArray);
  8079. }
  8080. // Convert other array views to uint8
  8081. if (
  8082. typedArray instanceof Int8Array ||
  8083. (typeof Uint8ClampedArray !== "undefined" && typedArray instanceof Uint8ClampedArray) ||
  8084. typedArray instanceof Int16Array ||
  8085. typedArray instanceof Uint16Array ||
  8086. typedArray instanceof Int32Array ||
  8087. typedArray instanceof Uint32Array ||
  8088. typedArray instanceof Float32Array ||
  8089. typedArray instanceof Float64Array
  8090. ) {
  8091. typedArray = new Uint8Array(typedArray.buffer, typedArray.byteOffset, typedArray.byteLength);
  8092. }
  8093. // Handle Uint8Array
  8094. if (typedArray instanceof Uint8Array) {
  8095. // Shortcut
  8096. var typedArrayByteLength = typedArray.byteLength;
  8097. // Extract bytes
  8098. var words = [];
  8099. for (var i = 0; i < typedArrayByteLength; i++) {
  8100. words[i >>> 2] |= typedArray[i] << (24 - (i % 4) * 8);
  8101. }
  8102. // Initialize this word array
  8103. superInit.call(this, words, typedArrayByteLength);
  8104. } else {
  8105. // Else call normal init
  8106. superInit.apply(this, arguments);
  8107. }
  8108. };
  8109. subInit.prototype = WordArray;
  8110. }());
  8111. return CryptoJS.lib.WordArray;
  8112. }));
  8113. },{"./core":53}],61:[function(require,module,exports){
  8114. ;(function (root, factory) {
  8115. if (typeof exports === "object") {
  8116. // CommonJS
  8117. module.exports = exports = factory(require("./core"));
  8118. }
  8119. else if (typeof define === "function" && define.amd) {
  8120. // AMD
  8121. define(["./core"], factory);
  8122. }
  8123. else {
  8124. // Global (browser)
  8125. factory(root.CryptoJS);
  8126. }
  8127. }(this, function (CryptoJS) {
  8128. (function (Math) {
  8129. // Shortcuts
  8130. var C = CryptoJS;
  8131. var C_lib = C.lib;
  8132. var WordArray = C_lib.WordArray;
  8133. var Hasher = C_lib.Hasher;
  8134. var C_algo = C.algo;
  8135. // Constants table
  8136. var T = [];
  8137. // Compute constants
  8138. (function () {
  8139. for (var i = 0; i < 64; i++) {
  8140. T[i] = (Math.abs(Math.sin(i + 1)) * 0x100000000) | 0;
  8141. }
  8142. }());
  8143. /**
  8144. * MD5 hash algorithm.
  8145. */
  8146. var MD5 = C_algo.MD5 = Hasher.extend({
  8147. _doReset: function () {
  8148. this._hash = new WordArray.init([
  8149. 0x67452301, 0xefcdab89,
  8150. 0x98badcfe, 0x10325476
  8151. ]);
  8152. },
  8153. _doProcessBlock: function (M, offset) {
  8154. // Swap endian
  8155. for (var i = 0; i < 16; i++) {
  8156. // Shortcuts
  8157. var offset_i = offset + i;
  8158. var M_offset_i = M[offset_i];
  8159. M[offset_i] = (
  8160. (((M_offset_i << 8) | (M_offset_i >>> 24)) & 0x00ff00ff) |
  8161. (((M_offset_i << 24) | (M_offset_i >>> 8)) & 0xff00ff00)
  8162. );
  8163. }
  8164. // Shortcuts
  8165. var H = this._hash.words;
  8166. var M_offset_0 = M[offset + 0];
  8167. var M_offset_1 = M[offset + 1];
  8168. var M_offset_2 = M[offset + 2];
  8169. var M_offset_3 = M[offset + 3];
  8170. var M_offset_4 = M[offset + 4];
  8171. var M_offset_5 = M[offset + 5];
  8172. var M_offset_6 = M[offset + 6];
  8173. var M_offset_7 = M[offset + 7];
  8174. var M_offset_8 = M[offset + 8];
  8175. var M_offset_9 = M[offset + 9];
  8176. var M_offset_10 = M[offset + 10];
  8177. var M_offset_11 = M[offset + 11];
  8178. var M_offset_12 = M[offset + 12];
  8179. var M_offset_13 = M[offset + 13];
  8180. var M_offset_14 = M[offset + 14];
  8181. var M_offset_15 = M[offset + 15];
  8182. // Working varialbes
  8183. var a = H[0];
  8184. var b = H[1];
  8185. var c = H[2];
  8186. var d = H[3];
  8187. // Computation
  8188. a = FF(a, b, c, d, M_offset_0, 7, T[0]);
  8189. d = FF(d, a, b, c, M_offset_1, 12, T[1]);
  8190. c = FF(c, d, a, b, M_offset_2, 17, T[2]);
  8191. b = FF(b, c, d, a, M_offset_3, 22, T[3]);
  8192. a = FF(a, b, c, d, M_offset_4, 7, T[4]);
  8193. d = FF(d, a, b, c, M_offset_5, 12, T[5]);
  8194. c = FF(c, d, a, b, M_offset_6, 17, T[6]);
  8195. b = FF(b, c, d, a, M_offset_7, 22, T[7]);
  8196. a = FF(a, b, c, d, M_offset_8, 7, T[8]);
  8197. d = FF(d, a, b, c, M_offset_9, 12, T[9]);
  8198. c = FF(c, d, a, b, M_offset_10, 17, T[10]);
  8199. b = FF(b, c, d, a, M_offset_11, 22, T[11]);
  8200. a = FF(a, b, c, d, M_offset_12, 7, T[12]);
  8201. d = FF(d, a, b, c, M_offset_13, 12, T[13]);
  8202. c = FF(c, d, a, b, M_offset_14, 17, T[14]);
  8203. b = FF(b, c, d, a, M_offset_15, 22, T[15]);
  8204. a = GG(a, b, c, d, M_offset_1, 5, T[16]);
  8205. d = GG(d, a, b, c, M_offset_6, 9, T[17]);
  8206. c = GG(c, d, a, b, M_offset_11, 14, T[18]);
  8207. b = GG(b, c, d, a, M_offset_0, 20, T[19]);
  8208. a = GG(a, b, c, d, M_offset_5, 5, T[20]);
  8209. d = GG(d, a, b, c, M_offset_10, 9, T[21]);
  8210. c = GG(c, d, a, b, M_offset_15, 14, T[22]);
  8211. b = GG(b, c, d, a, M_offset_4, 20, T[23]);
  8212. a = GG(a, b, c, d, M_offset_9, 5, T[24]);
  8213. d = GG(d, a, b, c, M_offset_14, 9, T[25]);
  8214. c = GG(c, d, a, b, M_offset_3, 14, T[26]);
  8215. b = GG(b, c, d, a, M_offset_8, 20, T[27]);
  8216. a = GG(a, b, c, d, M_offset_13, 5, T[28]);
  8217. d = GG(d, a, b, c, M_offset_2, 9, T[29]);
  8218. c = GG(c, d, a, b, M_offset_7, 14, T[30]);
  8219. b = GG(b, c, d, a, M_offset_12, 20, T[31]);
  8220. a = HH(a, b, c, d, M_offset_5, 4, T[32]);
  8221. d = HH(d, a, b, c, M_offset_8, 11, T[33]);
  8222. c = HH(c, d, a, b, M_offset_11, 16, T[34]);
  8223. b = HH(b, c, d, a, M_offset_14, 23, T[35]);
  8224. a = HH(a, b, c, d, M_offset_1, 4, T[36]);
  8225. d = HH(d, a, b, c, M_offset_4, 11, T[37]);
  8226. c = HH(c, d, a, b, M_offset_7, 16, T[38]);
  8227. b = HH(b, c, d, a, M_offset_10, 23, T[39]);
  8228. a = HH(a, b, c, d, M_offset_13, 4, T[40]);
  8229. d = HH(d, a, b, c, M_offset_0, 11, T[41]);
  8230. c = HH(c, d, a, b, M_offset_3, 16, T[42]);
  8231. b = HH(b, c, d, a, M_offset_6, 23, T[43]);
  8232. a = HH(a, b, c, d, M_offset_9, 4, T[44]);
  8233. d = HH(d, a, b, c, M_offset_12, 11, T[45]);
  8234. c = HH(c, d, a, b, M_offset_15, 16, T[46]);
  8235. b = HH(b, c, d, a, M_offset_2, 23, T[47]);
  8236. a = II(a, b, c, d, M_offset_0, 6, T[48]);
  8237. d = II(d, a, b, c, M_offset_7, 10, T[49]);
  8238. c = II(c, d, a, b, M_offset_14, 15, T[50]);
  8239. b = II(b, c, d, a, M_offset_5, 21, T[51]);
  8240. a = II(a, b, c, d, M_offset_12, 6, T[52]);
  8241. d = II(d, a, b, c, M_offset_3, 10, T[53]);
  8242. c = II(c, d, a, b, M_offset_10, 15, T[54]);
  8243. b = II(b, c, d, a, M_offset_1, 21, T[55]);
  8244. a = II(a, b, c, d, M_offset_8, 6, T[56]);
  8245. d = II(d, a, b, c, M_offset_15, 10, T[57]);
  8246. c = II(c, d, a, b, M_offset_6, 15, T[58]);
  8247. b = II(b, c, d, a, M_offset_13, 21, T[59]);
  8248. a = II(a, b, c, d, M_offset_4, 6, T[60]);
  8249. d = II(d, a, b, c, M_offset_11, 10, T[61]);
  8250. c = II(c, d, a, b, M_offset_2, 15, T[62]);
  8251. b = II(b, c, d, a, M_offset_9, 21, T[63]);
  8252. // Intermediate hash value
  8253. H[0] = (H[0] + a) | 0;
  8254. H[1] = (H[1] + b) | 0;
  8255. H[2] = (H[2] + c) | 0;
  8256. H[3] = (H[3] + d) | 0;
  8257. },
  8258. _doFinalize: function () {
  8259. // Shortcuts
  8260. var data = this._data;
  8261. var dataWords = data.words;
  8262. var nBitsTotal = this._nDataBytes * 8;
  8263. var nBitsLeft = data.sigBytes * 8;
  8264. // Add padding
  8265. dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32);
  8266. var nBitsTotalH = Math.floor(nBitsTotal / 0x100000000);
  8267. var nBitsTotalL = nBitsTotal;
  8268. dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = (
  8269. (((nBitsTotalH << 8) | (nBitsTotalH >>> 24)) & 0x00ff00ff) |
  8270. (((nBitsTotalH << 24) | (nBitsTotalH >>> 8)) & 0xff00ff00)
  8271. );
  8272. dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = (
  8273. (((nBitsTotalL << 8) | (nBitsTotalL >>> 24)) & 0x00ff00ff) |
  8274. (((nBitsTotalL << 24) | (nBitsTotalL >>> 8)) & 0xff00ff00)
  8275. );
  8276. data.sigBytes = (dataWords.length + 1) * 4;
  8277. // Hash final blocks
  8278. this._process();
  8279. // Shortcuts
  8280. var hash = this._hash;
  8281. var H = hash.words;
  8282. // Swap endian
  8283. for (var i = 0; i < 4; i++) {
  8284. // Shortcut
  8285. var H_i = H[i];
  8286. H[i] = (((H_i << 8) | (H_i >>> 24)) & 0x00ff00ff) |
  8287. (((H_i << 24) | (H_i >>> 8)) & 0xff00ff00);
  8288. }
  8289. // Return final computed hash
  8290. return hash;
  8291. },
  8292. clone: function () {
  8293. var clone = Hasher.clone.call(this);
  8294. clone._hash = this._hash.clone();
  8295. return clone;
  8296. }
  8297. });
  8298. function FF(a, b, c, d, x, s, t) {
  8299. var n = a + ((b & c) | (~b & d)) + x + t;
  8300. return ((n << s) | (n >>> (32 - s))) + b;
  8301. }
  8302. function GG(a, b, c, d, x, s, t) {
  8303. var n = a + ((b & d) | (c & ~d)) + x + t;
  8304. return ((n << s) | (n >>> (32 - s))) + b;
  8305. }
  8306. function HH(a, b, c, d, x, s, t) {
  8307. var n = a + (b ^ c ^ d) + x + t;
  8308. return ((n << s) | (n >>> (32 - s))) + b;
  8309. }
  8310. function II(a, b, c, d, x, s, t) {
  8311. var n = a + (c ^ (b | ~d)) + x + t;
  8312. return ((n << s) | (n >>> (32 - s))) + b;
  8313. }
  8314. /**
  8315. * Shortcut function to the hasher's object interface.
  8316. *
  8317. * @param {WordArray|string} message The message to hash.
  8318. *
  8319. * @return {WordArray} The hash.
  8320. *
  8321. * @static
  8322. *
  8323. * @example
  8324. *
  8325. * var hash = CryptoJS.MD5('message');
  8326. * var hash = CryptoJS.MD5(wordArray);
  8327. */
  8328. C.MD5 = Hasher._createHelper(MD5);
  8329. /**
  8330. * Shortcut function to the HMAC's object interface.
  8331. *
  8332. * @param {WordArray|string} message The message to hash.
  8333. * @param {WordArray|string} key The secret key.
  8334. *
  8335. * @return {WordArray} The HMAC.
  8336. *
  8337. * @static
  8338. *
  8339. * @example
  8340. *
  8341. * var hmac = CryptoJS.HmacMD5(message, key);
  8342. */
  8343. C.HmacMD5 = Hasher._createHmacHelper(MD5);
  8344. }(Math));
  8345. return CryptoJS.MD5;
  8346. }));
  8347. },{"./core":53}],62:[function(require,module,exports){
  8348. ;(function (root, factory, undef) {
  8349. if (typeof exports === "object") {
  8350. // CommonJS
  8351. module.exports = exports = factory(require("./core"), require("./cipher-core"));
  8352. }
  8353. else if (typeof define === "function" && define.amd) {
  8354. // AMD
  8355. define(["./core", "./cipher-core"], factory);
  8356. }
  8357. else {
  8358. // Global (browser)
  8359. factory(root.CryptoJS);
  8360. }
  8361. }(this, function (CryptoJS) {
  8362. /**
  8363. * Cipher Feedback block mode.
  8364. */
  8365. CryptoJS.mode.CFB = (function () {
  8366. var CFB = CryptoJS.lib.BlockCipherMode.extend();
  8367. CFB.Encryptor = CFB.extend({
  8368. processBlock: function (words, offset) {
  8369. // Shortcuts
  8370. var cipher = this._cipher;
  8371. var blockSize = cipher.blockSize;
  8372. generateKeystreamAndEncrypt.call(this, words, offset, blockSize, cipher);
  8373. // Remember this block to use with next block
  8374. this._prevBlock = words.slice(offset, offset + blockSize);
  8375. }
  8376. });
  8377. CFB.Decryptor = CFB.extend({
  8378. processBlock: function (words, offset) {
  8379. // Shortcuts
  8380. var cipher = this._cipher;
  8381. var blockSize = cipher.blockSize;
  8382. // Remember this block to use with next block
  8383. var thisBlock = words.slice(offset, offset + blockSize);
  8384. generateKeystreamAndEncrypt.call(this, words, offset, blockSize, cipher);
  8385. // This block becomes the previous block
  8386. this._prevBlock = thisBlock;
  8387. }
  8388. });
  8389. function generateKeystreamAndEncrypt(words, offset, blockSize, cipher) {
  8390. // Shortcut
  8391. var iv = this._iv;
  8392. // Generate keystream
  8393. if (iv) {
  8394. var keystream = iv.slice(0);
  8395. // Remove IV for subsequent blocks
  8396. this._iv = undefined;
  8397. } else {
  8398. var keystream = this._prevBlock;
  8399. }
  8400. cipher.encryptBlock(keystream, 0);
  8401. // Encrypt
  8402. for (var i = 0; i < blockSize; i++) {
  8403. words[offset + i] ^= keystream[i];
  8404. }
  8405. }
  8406. return CFB;
  8407. }());
  8408. return CryptoJS.mode.CFB;
  8409. }));
  8410. },{"./cipher-core":52,"./core":53}],63:[function(require,module,exports){
  8411. ;(function (root, factory, undef) {
  8412. if (typeof exports === "object") {
  8413. // CommonJS
  8414. module.exports = exports = factory(require("./core"), require("./cipher-core"));
  8415. }
  8416. else if (typeof define === "function" && define.amd) {
  8417. // AMD
  8418. define(["./core", "./cipher-core"], factory);
  8419. }
  8420. else {
  8421. // Global (browser)
  8422. factory(root.CryptoJS);
  8423. }
  8424. }(this, function (CryptoJS) {
  8425. /** @preserve
  8426. * Counter block mode compatible with Dr Brian Gladman fileenc.c
  8427. * derived from CryptoJS.mode.CTR
  8428. * Jan Hruby jhruby.web@gmail.com
  8429. */
  8430. CryptoJS.mode.CTRGladman = (function () {
  8431. var CTRGladman = CryptoJS.lib.BlockCipherMode.extend();
  8432. function incWord(word)
  8433. {
  8434. if (((word >> 24) & 0xff) === 0xff) { //overflow
  8435. var b1 = (word >> 16)&0xff;
  8436. var b2 = (word >> 8)&0xff;
  8437. var b3 = word & 0xff;
  8438. if (b1 === 0xff) // overflow b1
  8439. {
  8440. b1 = 0;
  8441. if (b2 === 0xff)
  8442. {
  8443. b2 = 0;
  8444. if (b3 === 0xff)
  8445. {
  8446. b3 = 0;
  8447. }
  8448. else
  8449. {
  8450. ++b3;
  8451. }
  8452. }
  8453. else
  8454. {
  8455. ++b2;
  8456. }
  8457. }
  8458. else
  8459. {
  8460. ++b1;
  8461. }
  8462. word = 0;
  8463. word += (b1 << 16);
  8464. word += (b2 << 8);
  8465. word += b3;
  8466. }
  8467. else
  8468. {
  8469. word += (0x01 << 24);
  8470. }
  8471. return word;
  8472. }
  8473. function incCounter(counter)
  8474. {
  8475. if ((counter[0] = incWord(counter[0])) === 0)
  8476. {
  8477. // encr_data in fileenc.c from Dr Brian Gladman's counts only with DWORD j < 8
  8478. counter[1] = incWord(counter[1]);
  8479. }
  8480. return counter;
  8481. }
  8482. var Encryptor = CTRGladman.Encryptor = CTRGladman.extend({
  8483. processBlock: function (words, offset) {
  8484. // Shortcuts
  8485. var cipher = this._cipher
  8486. var blockSize = cipher.blockSize;
  8487. var iv = this._iv;
  8488. var counter = this._counter;
  8489. // Generate keystream
  8490. if (iv) {
  8491. counter = this._counter = iv.slice(0);
  8492. // Remove IV for subsequent blocks
  8493. this._iv = undefined;
  8494. }
  8495. incCounter(counter);
  8496. var keystream = counter.slice(0);
  8497. cipher.encryptBlock(keystream, 0);
  8498. // Encrypt
  8499. for (var i = 0; i < blockSize; i++) {
  8500. words[offset + i] ^= keystream[i];
  8501. }
  8502. }
  8503. });
  8504. CTRGladman.Decryptor = Encryptor;
  8505. return CTRGladman;
  8506. }());
  8507. return CryptoJS.mode.CTRGladman;
  8508. }));
  8509. },{"./cipher-core":52,"./core":53}],64:[function(require,module,exports){
  8510. ;(function (root, factory, undef) {
  8511. if (typeof exports === "object") {
  8512. // CommonJS
  8513. module.exports = exports = factory(require("./core"), require("./cipher-core"));
  8514. }
  8515. else if (typeof define === "function" && define.amd) {
  8516. // AMD
  8517. define(["./core", "./cipher-core"], factory);
  8518. }
  8519. else {
  8520. // Global (browser)
  8521. factory(root.CryptoJS);
  8522. }
  8523. }(this, function (CryptoJS) {
  8524. /**
  8525. * Counter block mode.
  8526. */
  8527. CryptoJS.mode.CTR = (function () {
  8528. var CTR = CryptoJS.lib.BlockCipherMode.extend();
  8529. var Encryptor = CTR.Encryptor = CTR.extend({
  8530. processBlock: function (words, offset) {
  8531. // Shortcuts
  8532. var cipher = this._cipher
  8533. var blockSize = cipher.blockSize;
  8534. var iv = this._iv;
  8535. var counter = this._counter;
  8536. // Generate keystream
  8537. if (iv) {
  8538. counter = this._counter = iv.slice(0);
  8539. // Remove IV for subsequent blocks
  8540. this._iv = undefined;
  8541. }
  8542. var keystream = counter.slice(0);
  8543. cipher.encryptBlock(keystream, 0);
  8544. // Increment counter
  8545. counter[blockSize - 1] = (counter[blockSize - 1] + 1) | 0
  8546. // Encrypt
  8547. for (var i = 0; i < blockSize; i++) {
  8548. words[offset + i] ^= keystream[i];
  8549. }
  8550. }
  8551. });
  8552. CTR.Decryptor = Encryptor;
  8553. return CTR;
  8554. }());
  8555. return CryptoJS.mode.CTR;
  8556. }));
  8557. },{"./cipher-core":52,"./core":53}],65:[function(require,module,exports){
  8558. ;(function (root, factory, undef) {
  8559. if (typeof exports === "object") {
  8560. // CommonJS
  8561. module.exports = exports = factory(require("./core"), require("./cipher-core"));
  8562. }
  8563. else if (typeof define === "function" && define.amd) {
  8564. // AMD
  8565. define(["./core", "./cipher-core"], factory);
  8566. }
  8567. else {
  8568. // Global (browser)
  8569. factory(root.CryptoJS);
  8570. }
  8571. }(this, function (CryptoJS) {
  8572. /**
  8573. * Electronic Codebook block mode.
  8574. */
  8575. CryptoJS.mode.ECB = (function () {
  8576. var ECB = CryptoJS.lib.BlockCipherMode.extend();
  8577. ECB.Encryptor = ECB.extend({
  8578. processBlock: function (words, offset) {
  8579. this._cipher.encryptBlock(words, offset);
  8580. }
  8581. });
  8582. ECB.Decryptor = ECB.extend({
  8583. processBlock: function (words, offset) {
  8584. this._cipher.decryptBlock(words, offset);
  8585. }
  8586. });
  8587. return ECB;
  8588. }());
  8589. return CryptoJS.mode.ECB;
  8590. }));
  8591. },{"./cipher-core":52,"./core":53}],66:[function(require,module,exports){
  8592. ;(function (root, factory, undef) {
  8593. if (typeof exports === "object") {
  8594. // CommonJS
  8595. module.exports = exports = factory(require("./core"), require("./cipher-core"));
  8596. }
  8597. else if (typeof define === "function" && define.amd) {
  8598. // AMD
  8599. define(["./core", "./cipher-core"], factory);
  8600. }
  8601. else {
  8602. // Global (browser)
  8603. factory(root.CryptoJS);
  8604. }
  8605. }(this, function (CryptoJS) {
  8606. /**
  8607. * Output Feedback block mode.
  8608. */
  8609. CryptoJS.mode.OFB = (function () {
  8610. var OFB = CryptoJS.lib.BlockCipherMode.extend();
  8611. var Encryptor = OFB.Encryptor = OFB.extend({
  8612. processBlock: function (words, offset) {
  8613. // Shortcuts
  8614. var cipher = this._cipher
  8615. var blockSize = cipher.blockSize;
  8616. var iv = this._iv;
  8617. var keystream = this._keystream;
  8618. // Generate keystream
  8619. if (iv) {
  8620. keystream = this._keystream = iv.slice(0);
  8621. // Remove IV for subsequent blocks
  8622. this._iv = undefined;
  8623. }
  8624. cipher.encryptBlock(keystream, 0);
  8625. // Encrypt
  8626. for (var i = 0; i < blockSize; i++) {
  8627. words[offset + i] ^= keystream[i];
  8628. }
  8629. }
  8630. });
  8631. OFB.Decryptor = Encryptor;
  8632. return OFB;
  8633. }());
  8634. return CryptoJS.mode.OFB;
  8635. }));
  8636. },{"./cipher-core":52,"./core":53}],67:[function(require,module,exports){
  8637. ;(function (root, factory, undef) {
  8638. if (typeof exports === "object") {
  8639. // CommonJS
  8640. module.exports = exports = factory(require("./core"), require("./cipher-core"));
  8641. }
  8642. else if (typeof define === "function" && define.amd) {
  8643. // AMD
  8644. define(["./core", "./cipher-core"], factory);
  8645. }
  8646. else {
  8647. // Global (browser)
  8648. factory(root.CryptoJS);
  8649. }
  8650. }(this, function (CryptoJS) {
  8651. /**
  8652. * ANSI X.923 padding strategy.
  8653. */
  8654. CryptoJS.pad.AnsiX923 = {
  8655. pad: function (data, blockSize) {
  8656. // Shortcuts
  8657. var dataSigBytes = data.sigBytes;
  8658. var blockSizeBytes = blockSize * 4;
  8659. // Count padding bytes
  8660. var nPaddingBytes = blockSizeBytes - dataSigBytes % blockSizeBytes;
  8661. // Compute last byte position
  8662. var lastBytePos = dataSigBytes + nPaddingBytes - 1;
  8663. // Pad
  8664. data.clamp();
  8665. data.words[lastBytePos >>> 2] |= nPaddingBytes << (24 - (lastBytePos % 4) * 8);
  8666. data.sigBytes += nPaddingBytes;
  8667. },
  8668. unpad: function (data) {
  8669. // Get number of padding bytes from last byte
  8670. var nPaddingBytes = data.words[(data.sigBytes - 1) >>> 2] & 0xff;
  8671. // Remove padding
  8672. data.sigBytes -= nPaddingBytes;
  8673. }
  8674. };
  8675. return CryptoJS.pad.Ansix923;
  8676. }));
  8677. },{"./cipher-core":52,"./core":53}],68:[function(require,module,exports){
  8678. ;(function (root, factory, undef) {
  8679. if (typeof exports === "object") {
  8680. // CommonJS
  8681. module.exports = exports = factory(require("./core"), require("./cipher-core"));
  8682. }
  8683. else if (typeof define === "function" && define.amd) {
  8684. // AMD
  8685. define(["./core", "./cipher-core"], factory);
  8686. }
  8687. else {
  8688. // Global (browser)
  8689. factory(root.CryptoJS);
  8690. }
  8691. }(this, function (CryptoJS) {
  8692. /**
  8693. * ISO 10126 padding strategy.
  8694. */
  8695. CryptoJS.pad.Iso10126 = {
  8696. pad: function (data, blockSize) {
  8697. // Shortcut
  8698. var blockSizeBytes = blockSize * 4;
  8699. // Count padding bytes
  8700. var nPaddingBytes = blockSizeBytes - data.sigBytes % blockSizeBytes;
  8701. // Pad
  8702. data.concat(CryptoJS.lib.WordArray.random(nPaddingBytes - 1)).
  8703. concat(CryptoJS.lib.WordArray.create([nPaddingBytes << 24], 1));
  8704. },
  8705. unpad: function (data) {
  8706. // Get number of padding bytes from last byte
  8707. var nPaddingBytes = data.words[(data.sigBytes - 1) >>> 2] & 0xff;
  8708. // Remove padding
  8709. data.sigBytes -= nPaddingBytes;
  8710. }
  8711. };
  8712. return CryptoJS.pad.Iso10126;
  8713. }));
  8714. },{"./cipher-core":52,"./core":53}],69:[function(require,module,exports){
  8715. ;(function (root, factory, undef) {
  8716. if (typeof exports === "object") {
  8717. // CommonJS
  8718. module.exports = exports = factory(require("./core"), require("./cipher-core"));
  8719. }
  8720. else if (typeof define === "function" && define.amd) {
  8721. // AMD
  8722. define(["./core", "./cipher-core"], factory);
  8723. }
  8724. else {
  8725. // Global (browser)
  8726. factory(root.CryptoJS);
  8727. }
  8728. }(this, function (CryptoJS) {
  8729. /**
  8730. * ISO/IEC 9797-1 Padding Method 2.
  8731. */
  8732. CryptoJS.pad.Iso97971 = {
  8733. pad: function (data, blockSize) {
  8734. // Add 0x80 byte
  8735. data.concat(CryptoJS.lib.WordArray.create([0x80000000], 1));
  8736. // Zero pad the rest
  8737. CryptoJS.pad.ZeroPadding.pad(data, blockSize);
  8738. },
  8739. unpad: function (data) {
  8740. // Remove zero padding
  8741. CryptoJS.pad.ZeroPadding.unpad(data);
  8742. // Remove one more byte -- the 0x80 byte
  8743. data.sigBytes--;
  8744. }
  8745. };
  8746. return CryptoJS.pad.Iso97971;
  8747. }));
  8748. },{"./cipher-core":52,"./core":53}],70:[function(require,module,exports){
  8749. ;(function (root, factory, undef) {
  8750. if (typeof exports === "object") {
  8751. // CommonJS
  8752. module.exports = exports = factory(require("./core"), require("./cipher-core"));
  8753. }
  8754. else if (typeof define === "function" && define.amd) {
  8755. // AMD
  8756. define(["./core", "./cipher-core"], factory);
  8757. }
  8758. else {
  8759. // Global (browser)
  8760. factory(root.CryptoJS);
  8761. }
  8762. }(this, function (CryptoJS) {
  8763. /**
  8764. * A noop padding strategy.
  8765. */
  8766. CryptoJS.pad.NoPadding = {
  8767. pad: function () {
  8768. },
  8769. unpad: function () {
  8770. }
  8771. };
  8772. return CryptoJS.pad.NoPadding;
  8773. }));
  8774. },{"./cipher-core":52,"./core":53}],71:[function(require,module,exports){
  8775. ;(function (root, factory, undef) {
  8776. if (typeof exports === "object") {
  8777. // CommonJS
  8778. module.exports = exports = factory(require("./core"), require("./cipher-core"));
  8779. }
  8780. else if (typeof define === "function" && define.amd) {
  8781. // AMD
  8782. define(["./core", "./cipher-core"], factory);
  8783. }
  8784. else {
  8785. // Global (browser)
  8786. factory(root.CryptoJS);
  8787. }
  8788. }(this, function (CryptoJS) {
  8789. /**
  8790. * Zero padding strategy.
  8791. */
  8792. CryptoJS.pad.ZeroPadding = {
  8793. pad: function (data, blockSize) {
  8794. // Shortcut
  8795. var blockSizeBytes = blockSize * 4;
  8796. // Pad
  8797. data.clamp();
  8798. data.sigBytes += blockSizeBytes - ((data.sigBytes % blockSizeBytes) || blockSizeBytes);
  8799. },
  8800. unpad: function (data) {
  8801. // Shortcut
  8802. var dataWords = data.words;
  8803. // Unpad
  8804. var i = data.sigBytes - 1;
  8805. while (!((dataWords[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff)) {
  8806. i--;
  8807. }
  8808. data.sigBytes = i + 1;
  8809. }
  8810. };
  8811. return CryptoJS.pad.ZeroPadding;
  8812. }));
  8813. },{"./cipher-core":52,"./core":53}],72:[function(require,module,exports){
  8814. ;(function (root, factory, undef) {
  8815. if (typeof exports === "object") {
  8816. // CommonJS
  8817. module.exports = exports = factory(require("./core"), require("./sha1"), require("./hmac"));
  8818. }
  8819. else if (typeof define === "function" && define.amd) {
  8820. // AMD
  8821. define(["./core", "./sha1", "./hmac"], factory);
  8822. }
  8823. else {
  8824. // Global (browser)
  8825. factory(root.CryptoJS);
  8826. }
  8827. }(this, function (CryptoJS) {
  8828. (function () {
  8829. // Shortcuts
  8830. var C = CryptoJS;
  8831. var C_lib = C.lib;
  8832. var Base = C_lib.Base;
  8833. var WordArray = C_lib.WordArray;
  8834. var C_algo = C.algo;
  8835. var SHA1 = C_algo.SHA1;
  8836. var HMAC = C_algo.HMAC;
  8837. /**
  8838. * Password-Based Key Derivation Function 2 algorithm.
  8839. */
  8840. var PBKDF2 = C_algo.PBKDF2 = Base.extend({
  8841. /**
  8842. * Configuration options.
  8843. *
  8844. * @property {number} keySize The key size in words to generate. Default: 4 (128 bits)
  8845. * @property {Hasher} hasher The hasher to use. Default: SHA1
  8846. * @property {number} iterations The number of iterations to perform. Default: 1
  8847. */
  8848. cfg: Base.extend({
  8849. keySize: 128/32,
  8850. hasher: SHA1,
  8851. iterations: 1
  8852. }),
  8853. /**
  8854. * Initializes a newly created key derivation function.
  8855. *
  8856. * @param {Object} cfg (Optional) The configuration options to use for the derivation.
  8857. *
  8858. * @example
  8859. *
  8860. * var kdf = CryptoJS.algo.PBKDF2.create();
  8861. * var kdf = CryptoJS.algo.PBKDF2.create({ keySize: 8 });
  8862. * var kdf = CryptoJS.algo.PBKDF2.create({ keySize: 8, iterations: 1000 });
  8863. */
  8864. init: function (cfg) {
  8865. this.cfg = this.cfg.extend(cfg);
  8866. },
  8867. /**
  8868. * Computes the Password-Based Key Derivation Function 2.
  8869. *
  8870. * @param {WordArray|string} password The password.
  8871. * @param {WordArray|string} salt A salt.
  8872. *
  8873. * @return {WordArray} The derived key.
  8874. *
  8875. * @example
  8876. *
  8877. * var key = kdf.compute(password, salt);
  8878. */
  8879. compute: function (password, salt) {
  8880. // Shortcut
  8881. var cfg = this.cfg;
  8882. // Init HMAC
  8883. var hmac = HMAC.create(cfg.hasher, password);
  8884. // Initial values
  8885. var derivedKey = WordArray.create();
  8886. var blockIndex = WordArray.create([0x00000001]);
  8887. // Shortcuts
  8888. var derivedKeyWords = derivedKey.words;
  8889. var blockIndexWords = blockIndex.words;
  8890. var keySize = cfg.keySize;
  8891. var iterations = cfg.iterations;
  8892. // Generate key
  8893. while (derivedKeyWords.length < keySize) {
  8894. var block = hmac.update(salt).finalize(blockIndex);
  8895. hmac.reset();
  8896. // Shortcuts
  8897. var blockWords = block.words;
  8898. var blockWordsLength = blockWords.length;
  8899. // Iterations
  8900. var intermediate = block;
  8901. for (var i = 1; i < iterations; i++) {
  8902. intermediate = hmac.finalize(intermediate);
  8903. hmac.reset();
  8904. // Shortcut
  8905. var intermediateWords = intermediate.words;
  8906. // XOR intermediate with block
  8907. for (var j = 0; j < blockWordsLength; j++) {
  8908. blockWords[j] ^= intermediateWords[j];
  8909. }
  8910. }
  8911. derivedKey.concat(block);
  8912. blockIndexWords[0]++;
  8913. }
  8914. derivedKey.sigBytes = keySize * 4;
  8915. return derivedKey;
  8916. }
  8917. });
  8918. /**
  8919. * Computes the Password-Based Key Derivation Function 2.
  8920. *
  8921. * @param {WordArray|string} password The password.
  8922. * @param {WordArray|string} salt A salt.
  8923. * @param {Object} cfg (Optional) The configuration options to use for this computation.
  8924. *
  8925. * @return {WordArray} The derived key.
  8926. *
  8927. * @static
  8928. *
  8929. * @example
  8930. *
  8931. * var key = CryptoJS.PBKDF2(password, salt);
  8932. * var key = CryptoJS.PBKDF2(password, salt, { keySize: 8 });
  8933. * var key = CryptoJS.PBKDF2(password, salt, { keySize: 8, iterations: 1000 });
  8934. */
  8935. C.PBKDF2 = function (password, salt, cfg) {
  8936. return PBKDF2.create(cfg).compute(password, salt);
  8937. };
  8938. }());
  8939. return CryptoJS.PBKDF2;
  8940. }));
  8941. },{"./core":53,"./hmac":58,"./sha1":77}],73:[function(require,module,exports){
  8942. ;(function (root, factory, undef) {
  8943. if (typeof exports === "object") {
  8944. // CommonJS
  8945. module.exports = exports = factory(require("./core"), require("./enc-base64"), require("./md5"), require("./evpkdf"), require("./cipher-core"));
  8946. }
  8947. else if (typeof define === "function" && define.amd) {
  8948. // AMD
  8949. define(["./core", "./enc-base64", "./md5", "./evpkdf", "./cipher-core"], factory);
  8950. }
  8951. else {
  8952. // Global (browser)
  8953. factory(root.CryptoJS);
  8954. }
  8955. }(this, function (CryptoJS) {
  8956. (function () {
  8957. // Shortcuts
  8958. var C = CryptoJS;
  8959. var C_lib = C.lib;
  8960. var StreamCipher = C_lib.StreamCipher;
  8961. var C_algo = C.algo;
  8962. // Reusable objects
  8963. var S = [];
  8964. var C_ = [];
  8965. var G = [];
  8966. /**
  8967. * Rabbit stream cipher algorithm.
  8968. *
  8969. * This is a legacy version that neglected to convert the key to little-endian.
  8970. * This error doesn't affect the cipher's security,
  8971. * but it does affect its compatibility with other implementations.
  8972. */
  8973. var RabbitLegacy = C_algo.RabbitLegacy = StreamCipher.extend({
  8974. _doReset: function () {
  8975. // Shortcuts
  8976. var K = this._key.words;
  8977. var iv = this.cfg.iv;
  8978. // Generate initial state values
  8979. var X = this._X = [
  8980. K[0], (K[3] << 16) | (K[2] >>> 16),
  8981. K[1], (K[0] << 16) | (K[3] >>> 16),
  8982. K[2], (K[1] << 16) | (K[0] >>> 16),
  8983. K[3], (K[2] << 16) | (K[1] >>> 16)
  8984. ];
  8985. // Generate initial counter values
  8986. var C = this._C = [
  8987. (K[2] << 16) | (K[2] >>> 16), (K[0] & 0xffff0000) | (K[1] & 0x0000ffff),
  8988. (K[3] << 16) | (K[3] >>> 16), (K[1] & 0xffff0000) | (K[2] & 0x0000ffff),
  8989. (K[0] << 16) | (K[0] >>> 16), (K[2] & 0xffff0000) | (K[3] & 0x0000ffff),
  8990. (K[1] << 16) | (K[1] >>> 16), (K[3] & 0xffff0000) | (K[0] & 0x0000ffff)
  8991. ];
  8992. // Carry bit
  8993. this._b = 0;
  8994. // Iterate the system four times
  8995. for (var i = 0; i < 4; i++) {
  8996. nextState.call(this);
  8997. }
  8998. // Modify the counters
  8999. for (var i = 0; i < 8; i++) {
  9000. C[i] ^= X[(i + 4) & 7];
  9001. }
  9002. // IV setup
  9003. if (iv) {
  9004. // Shortcuts
  9005. var IV = iv.words;
  9006. var IV_0 = IV[0];
  9007. var IV_1 = IV[1];
  9008. // Generate four subvectors
  9009. var i0 = (((IV_0 << 8) | (IV_0 >>> 24)) & 0x00ff00ff) | (((IV_0 << 24) | (IV_0 >>> 8)) & 0xff00ff00);
  9010. var i2 = (((IV_1 << 8) | (IV_1 >>> 24)) & 0x00ff00ff) | (((IV_1 << 24) | (IV_1 >>> 8)) & 0xff00ff00);
  9011. var i1 = (i0 >>> 16) | (i2 & 0xffff0000);
  9012. var i3 = (i2 << 16) | (i0 & 0x0000ffff);
  9013. // Modify counter values
  9014. C[0] ^= i0;
  9015. C[1] ^= i1;
  9016. C[2] ^= i2;
  9017. C[3] ^= i3;
  9018. C[4] ^= i0;
  9019. C[5] ^= i1;
  9020. C[6] ^= i2;
  9021. C[7] ^= i3;
  9022. // Iterate the system four times
  9023. for (var i = 0; i < 4; i++) {
  9024. nextState.call(this);
  9025. }
  9026. }
  9027. },
  9028. _doProcessBlock: function (M, offset) {
  9029. // Shortcut
  9030. var X = this._X;
  9031. // Iterate the system
  9032. nextState.call(this);
  9033. // Generate four keystream words
  9034. S[0] = X[0] ^ (X[5] >>> 16) ^ (X[3] << 16);
  9035. S[1] = X[2] ^ (X[7] >>> 16) ^ (X[5] << 16);
  9036. S[2] = X[4] ^ (X[1] >>> 16) ^ (X[7] << 16);
  9037. S[3] = X[6] ^ (X[3] >>> 16) ^ (X[1] << 16);
  9038. for (var i = 0; i < 4; i++) {
  9039. // Swap endian
  9040. S[i] = (((S[i] << 8) | (S[i] >>> 24)) & 0x00ff00ff) |
  9041. (((S[i] << 24) | (S[i] >>> 8)) & 0xff00ff00);
  9042. // Encrypt
  9043. M[offset + i] ^= S[i];
  9044. }
  9045. },
  9046. blockSize: 128/32,
  9047. ivSize: 64/32
  9048. });
  9049. function nextState() {
  9050. // Shortcuts
  9051. var X = this._X;
  9052. var C = this._C;
  9053. // Save old counter values
  9054. for (var i = 0; i < 8; i++) {
  9055. C_[i] = C[i];
  9056. }
  9057. // Calculate new counter values
  9058. C[0] = (C[0] + 0x4d34d34d + this._b) | 0;
  9059. C[1] = (C[1] + 0xd34d34d3 + ((C[0] >>> 0) < (C_[0] >>> 0) ? 1 : 0)) | 0;
  9060. C[2] = (C[2] + 0x34d34d34 + ((C[1] >>> 0) < (C_[1] >>> 0) ? 1 : 0)) | 0;
  9061. C[3] = (C[3] + 0x4d34d34d + ((C[2] >>> 0) < (C_[2] >>> 0) ? 1 : 0)) | 0;
  9062. C[4] = (C[4] + 0xd34d34d3 + ((C[3] >>> 0) < (C_[3] >>> 0) ? 1 : 0)) | 0;
  9063. C[5] = (C[5] + 0x34d34d34 + ((C[4] >>> 0) < (C_[4] >>> 0) ? 1 : 0)) | 0;
  9064. C[6] = (C[6] + 0x4d34d34d + ((C[5] >>> 0) < (C_[5] >>> 0) ? 1 : 0)) | 0;
  9065. C[7] = (C[7] + 0xd34d34d3 + ((C[6] >>> 0) < (C_[6] >>> 0) ? 1 : 0)) | 0;
  9066. this._b = (C[7] >>> 0) < (C_[7] >>> 0) ? 1 : 0;
  9067. // Calculate the g-values
  9068. for (var i = 0; i < 8; i++) {
  9069. var gx = X[i] + C[i];
  9070. // Construct high and low argument for squaring
  9071. var ga = gx & 0xffff;
  9072. var gb = gx >>> 16;
  9073. // Calculate high and low result of squaring
  9074. var gh = ((((ga * ga) >>> 17) + ga * gb) >>> 15) + gb * gb;
  9075. var gl = (((gx & 0xffff0000) * gx) | 0) + (((gx & 0x0000ffff) * gx) | 0);
  9076. // High XOR low
  9077. G[i] = gh ^ gl;
  9078. }
  9079. // Calculate new state values
  9080. X[0] = (G[0] + ((G[7] << 16) | (G[7] >>> 16)) + ((G[6] << 16) | (G[6] >>> 16))) | 0;
  9081. X[1] = (G[1] + ((G[0] << 8) | (G[0] >>> 24)) + G[7]) | 0;
  9082. X[2] = (G[2] + ((G[1] << 16) | (G[1] >>> 16)) + ((G[0] << 16) | (G[0] >>> 16))) | 0;
  9083. X[3] = (G[3] + ((G[2] << 8) | (G[2] >>> 24)) + G[1]) | 0;
  9084. X[4] = (G[4] + ((G[3] << 16) | (G[3] >>> 16)) + ((G[2] << 16) | (G[2] >>> 16))) | 0;
  9085. X[5] = (G[5] + ((G[4] << 8) | (G[4] >>> 24)) + G[3]) | 0;
  9086. X[6] = (G[6] + ((G[5] << 16) | (G[5] >>> 16)) + ((G[4] << 16) | (G[4] >>> 16))) | 0;
  9087. X[7] = (G[7] + ((G[6] << 8) | (G[6] >>> 24)) + G[5]) | 0;
  9088. }
  9089. /**
  9090. * Shortcut functions to the cipher's object interface.
  9091. *
  9092. * @example
  9093. *
  9094. * var ciphertext = CryptoJS.RabbitLegacy.encrypt(message, key, cfg);
  9095. * var plaintext = CryptoJS.RabbitLegacy.decrypt(ciphertext, key, cfg);
  9096. */
  9097. C.RabbitLegacy = StreamCipher._createHelper(RabbitLegacy);
  9098. }());
  9099. return CryptoJS.RabbitLegacy;
  9100. }));
  9101. },{"./cipher-core":52,"./core":53,"./enc-base64":54,"./evpkdf":56,"./md5":61}],74:[function(require,module,exports){
  9102. ;(function (root, factory, undef) {
  9103. if (typeof exports === "object") {
  9104. // CommonJS
  9105. module.exports = exports = factory(require("./core"), require("./enc-base64"), require("./md5"), require("./evpkdf"), require("./cipher-core"));
  9106. }
  9107. else if (typeof define === "function" && define.amd) {
  9108. // AMD
  9109. define(["./core", "./enc-base64", "./md5", "./evpkdf", "./cipher-core"], factory);
  9110. }
  9111. else {
  9112. // Global (browser)
  9113. factory(root.CryptoJS);
  9114. }
  9115. }(this, function (CryptoJS) {
  9116. (function () {
  9117. // Shortcuts
  9118. var C = CryptoJS;
  9119. var C_lib = C.lib;
  9120. var StreamCipher = C_lib.StreamCipher;
  9121. var C_algo = C.algo;
  9122. // Reusable objects
  9123. var S = [];
  9124. var C_ = [];
  9125. var G = [];
  9126. /**
  9127. * Rabbit stream cipher algorithm
  9128. */
  9129. var Rabbit = C_algo.Rabbit = StreamCipher.extend({
  9130. _doReset: function () {
  9131. // Shortcuts
  9132. var K = this._key.words;
  9133. var iv = this.cfg.iv;
  9134. // Swap endian
  9135. for (var i = 0; i < 4; i++) {
  9136. K[i] = (((K[i] << 8) | (K[i] >>> 24)) & 0x00ff00ff) |
  9137. (((K[i] << 24) | (K[i] >>> 8)) & 0xff00ff00);
  9138. }
  9139. // Generate initial state values
  9140. var X = this._X = [
  9141. K[0], (K[3] << 16) | (K[2] >>> 16),
  9142. K[1], (K[0] << 16) | (K[3] >>> 16),
  9143. K[2], (K[1] << 16) | (K[0] >>> 16),
  9144. K[3], (K[2] << 16) | (K[1] >>> 16)
  9145. ];
  9146. // Generate initial counter values
  9147. var C = this._C = [
  9148. (K[2] << 16) | (K[2] >>> 16), (K[0] & 0xffff0000) | (K[1] & 0x0000ffff),
  9149. (K[3] << 16) | (K[3] >>> 16), (K[1] & 0xffff0000) | (K[2] & 0x0000ffff),
  9150. (K[0] << 16) | (K[0] >>> 16), (K[2] & 0xffff0000) | (K[3] & 0x0000ffff),
  9151. (K[1] << 16) | (K[1] >>> 16), (K[3] & 0xffff0000) | (K[0] & 0x0000ffff)
  9152. ];
  9153. // Carry bit
  9154. this._b = 0;
  9155. // Iterate the system four times
  9156. for (var i = 0; i < 4; i++) {
  9157. nextState.call(this);
  9158. }
  9159. // Modify the counters
  9160. for (var i = 0; i < 8; i++) {
  9161. C[i] ^= X[(i + 4) & 7];
  9162. }
  9163. // IV setup
  9164. if (iv) {
  9165. // Shortcuts
  9166. var IV = iv.words;
  9167. var IV_0 = IV[0];
  9168. var IV_1 = IV[1];
  9169. // Generate four subvectors
  9170. var i0 = (((IV_0 << 8) | (IV_0 >>> 24)) & 0x00ff00ff) | (((IV_0 << 24) | (IV_0 >>> 8)) & 0xff00ff00);
  9171. var i2 = (((IV_1 << 8) | (IV_1 >>> 24)) & 0x00ff00ff) | (((IV_1 << 24) | (IV_1 >>> 8)) & 0xff00ff00);
  9172. var i1 = (i0 >>> 16) | (i2 & 0xffff0000);
  9173. var i3 = (i2 << 16) | (i0 & 0x0000ffff);
  9174. // Modify counter values
  9175. C[0] ^= i0;
  9176. C[1] ^= i1;
  9177. C[2] ^= i2;
  9178. C[3] ^= i3;
  9179. C[4] ^= i0;
  9180. C[5] ^= i1;
  9181. C[6] ^= i2;
  9182. C[7] ^= i3;
  9183. // Iterate the system four times
  9184. for (var i = 0; i < 4; i++) {
  9185. nextState.call(this);
  9186. }
  9187. }
  9188. },
  9189. _doProcessBlock: function (M, offset) {
  9190. // Shortcut
  9191. var X = this._X;
  9192. // Iterate the system
  9193. nextState.call(this);
  9194. // Generate four keystream words
  9195. S[0] = X[0] ^ (X[5] >>> 16) ^ (X[3] << 16);
  9196. S[1] = X[2] ^ (X[7] >>> 16) ^ (X[5] << 16);
  9197. S[2] = X[4] ^ (X[1] >>> 16) ^ (X[7] << 16);
  9198. S[3] = X[6] ^ (X[3] >>> 16) ^ (X[1] << 16);
  9199. for (var i = 0; i < 4; i++) {
  9200. // Swap endian
  9201. S[i] = (((S[i] << 8) | (S[i] >>> 24)) & 0x00ff00ff) |
  9202. (((S[i] << 24) | (S[i] >>> 8)) & 0xff00ff00);
  9203. // Encrypt
  9204. M[offset + i] ^= S[i];
  9205. }
  9206. },
  9207. blockSize: 128/32,
  9208. ivSize: 64/32
  9209. });
  9210. function nextState() {
  9211. // Shortcuts
  9212. var X = this._X;
  9213. var C = this._C;
  9214. // Save old counter values
  9215. for (var i = 0; i < 8; i++) {
  9216. C_[i] = C[i];
  9217. }
  9218. // Calculate new counter values
  9219. C[0] = (C[0] + 0x4d34d34d + this._b) | 0;
  9220. C[1] = (C[1] + 0xd34d34d3 + ((C[0] >>> 0) < (C_[0] >>> 0) ? 1 : 0)) | 0;
  9221. C[2] = (C[2] + 0x34d34d34 + ((C[1] >>> 0) < (C_[1] >>> 0) ? 1 : 0)) | 0;
  9222. C[3] = (C[3] + 0x4d34d34d + ((C[2] >>> 0) < (C_[2] >>> 0) ? 1 : 0)) | 0;
  9223. C[4] = (C[4] + 0xd34d34d3 + ((C[3] >>> 0) < (C_[3] >>> 0) ? 1 : 0)) | 0;
  9224. C[5] = (C[5] + 0x34d34d34 + ((C[4] >>> 0) < (C_[4] >>> 0) ? 1 : 0)) | 0;
  9225. C[6] = (C[6] + 0x4d34d34d + ((C[5] >>> 0) < (C_[5] >>> 0) ? 1 : 0)) | 0;
  9226. C[7] = (C[7] + 0xd34d34d3 + ((C[6] >>> 0) < (C_[6] >>> 0) ? 1 : 0)) | 0;
  9227. this._b = (C[7] >>> 0) < (C_[7] >>> 0) ? 1 : 0;
  9228. // Calculate the g-values
  9229. for (var i = 0; i < 8; i++) {
  9230. var gx = X[i] + C[i];
  9231. // Construct high and low argument for squaring
  9232. var ga = gx & 0xffff;
  9233. var gb = gx >>> 16;
  9234. // Calculate high and low result of squaring
  9235. var gh = ((((ga * ga) >>> 17) + ga * gb) >>> 15) + gb * gb;
  9236. var gl = (((gx & 0xffff0000) * gx) | 0) + (((gx & 0x0000ffff) * gx) | 0);
  9237. // High XOR low
  9238. G[i] = gh ^ gl;
  9239. }
  9240. // Calculate new state values
  9241. X[0] = (G[0] + ((G[7] << 16) | (G[7] >>> 16)) + ((G[6] << 16) | (G[6] >>> 16))) | 0;
  9242. X[1] = (G[1] + ((G[0] << 8) | (G[0] >>> 24)) + G[7]) | 0;
  9243. X[2] = (G[2] + ((G[1] << 16) | (G[1] >>> 16)) + ((G[0] << 16) | (G[0] >>> 16))) | 0;
  9244. X[3] = (G[3] + ((G[2] << 8) | (G[2] >>> 24)) + G[1]) | 0;
  9245. X[4] = (G[4] + ((G[3] << 16) | (G[3] >>> 16)) + ((G[2] << 16) | (G[2] >>> 16))) | 0;
  9246. X[5] = (G[5] + ((G[4] << 8) | (G[4] >>> 24)) + G[3]) | 0;
  9247. X[6] = (G[6] + ((G[5] << 16) | (G[5] >>> 16)) + ((G[4] << 16) | (G[4] >>> 16))) | 0;
  9248. X[7] = (G[7] + ((G[6] << 8) | (G[6] >>> 24)) + G[5]) | 0;
  9249. }
  9250. /**
  9251. * Shortcut functions to the cipher's object interface.
  9252. *
  9253. * @example
  9254. *
  9255. * var ciphertext = CryptoJS.Rabbit.encrypt(message, key, cfg);
  9256. * var plaintext = CryptoJS.Rabbit.decrypt(ciphertext, key, cfg);
  9257. */
  9258. C.Rabbit = StreamCipher._createHelper(Rabbit);
  9259. }());
  9260. return CryptoJS.Rabbit;
  9261. }));
  9262. },{"./cipher-core":52,"./core":53,"./enc-base64":54,"./evpkdf":56,"./md5":61}],75:[function(require,module,exports){
  9263. ;(function (root, factory, undef) {
  9264. if (typeof exports === "object") {
  9265. // CommonJS
  9266. module.exports = exports = factory(require("./core"), require("./enc-base64"), require("./md5"), require("./evpkdf"), require("./cipher-core"));
  9267. }
  9268. else if (typeof define === "function" && define.amd) {
  9269. // AMD
  9270. define(["./core", "./enc-base64", "./md5", "./evpkdf", "./cipher-core"], factory);
  9271. }
  9272. else {
  9273. // Global (browser)
  9274. factory(root.CryptoJS);
  9275. }
  9276. }(this, function (CryptoJS) {
  9277. (function () {
  9278. // Shortcuts
  9279. var C = CryptoJS;
  9280. var C_lib = C.lib;
  9281. var StreamCipher = C_lib.StreamCipher;
  9282. var C_algo = C.algo;
  9283. /**
  9284. * RC4 stream cipher algorithm.
  9285. */
  9286. var RC4 = C_algo.RC4 = StreamCipher.extend({
  9287. _doReset: function () {
  9288. // Shortcuts
  9289. var key = this._key;
  9290. var keyWords = key.words;
  9291. var keySigBytes = key.sigBytes;
  9292. // Init sbox
  9293. var S = this._S = [];
  9294. for (var i = 0; i < 256; i++) {
  9295. S[i] = i;
  9296. }
  9297. // Key setup
  9298. for (var i = 0, j = 0; i < 256; i++) {
  9299. var keyByteIndex = i % keySigBytes;
  9300. var keyByte = (keyWords[keyByteIndex >>> 2] >>> (24 - (keyByteIndex % 4) * 8)) & 0xff;
  9301. j = (j + S[i] + keyByte) % 256;
  9302. // Swap
  9303. var t = S[i];
  9304. S[i] = S[j];
  9305. S[j] = t;
  9306. }
  9307. // Counters
  9308. this._i = this._j = 0;
  9309. },
  9310. _doProcessBlock: function (M, offset) {
  9311. M[offset] ^= generateKeystreamWord.call(this);
  9312. },
  9313. keySize: 256/32,
  9314. ivSize: 0
  9315. });
  9316. function generateKeystreamWord() {
  9317. // Shortcuts
  9318. var S = this._S;
  9319. var i = this._i;
  9320. var j = this._j;
  9321. // Generate keystream word
  9322. var keystreamWord = 0;
  9323. for (var n = 0; n < 4; n++) {
  9324. i = (i + 1) % 256;
  9325. j = (j + S[i]) % 256;
  9326. // Swap
  9327. var t = S[i];
  9328. S[i] = S[j];
  9329. S[j] = t;
  9330. keystreamWord |= S[(S[i] + S[j]) % 256] << (24 - n * 8);
  9331. }
  9332. // Update counters
  9333. this._i = i;
  9334. this._j = j;
  9335. return keystreamWord;
  9336. }
  9337. /**
  9338. * Shortcut functions to the cipher's object interface.
  9339. *
  9340. * @example
  9341. *
  9342. * var ciphertext = CryptoJS.RC4.encrypt(message, key, cfg);
  9343. * var plaintext = CryptoJS.RC4.decrypt(ciphertext, key, cfg);
  9344. */
  9345. C.RC4 = StreamCipher._createHelper(RC4);
  9346. /**
  9347. * Modified RC4 stream cipher algorithm.
  9348. */
  9349. var RC4Drop = C_algo.RC4Drop = RC4.extend({
  9350. /**
  9351. * Configuration options.
  9352. *
  9353. * @property {number} drop The number of keystream words to drop. Default 192
  9354. */
  9355. cfg: RC4.cfg.extend({
  9356. drop: 192
  9357. }),
  9358. _doReset: function () {
  9359. RC4._doReset.call(this);
  9360. // Drop
  9361. for (var i = this.cfg.drop; i > 0; i--) {
  9362. generateKeystreamWord.call(this);
  9363. }
  9364. }
  9365. });
  9366. /**
  9367. * Shortcut functions to the cipher's object interface.
  9368. *
  9369. * @example
  9370. *
  9371. * var ciphertext = CryptoJS.RC4Drop.encrypt(message, key, cfg);
  9372. * var plaintext = CryptoJS.RC4Drop.decrypt(ciphertext, key, cfg);
  9373. */
  9374. C.RC4Drop = StreamCipher._createHelper(RC4Drop);
  9375. }());
  9376. return CryptoJS.RC4;
  9377. }));
  9378. },{"./cipher-core":52,"./core":53,"./enc-base64":54,"./evpkdf":56,"./md5":61}],76:[function(require,module,exports){
  9379. ;(function (root, factory) {
  9380. if (typeof exports === "object") {
  9381. // CommonJS
  9382. module.exports = exports = factory(require("./core"));
  9383. }
  9384. else if (typeof define === "function" && define.amd) {
  9385. // AMD
  9386. define(["./core"], factory);
  9387. }
  9388. else {
  9389. // Global (browser)
  9390. factory(root.CryptoJS);
  9391. }
  9392. }(this, function (CryptoJS) {
  9393. /** @preserve
  9394. (c) 2012 by Cédric Mesnil. All rights reserved.
  9395. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
  9396. - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  9397. - 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.
  9398. 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.
  9399. */
  9400. (function (Math) {
  9401. // Shortcuts
  9402. var C = CryptoJS;
  9403. var C_lib = C.lib;
  9404. var WordArray = C_lib.WordArray;
  9405. var Hasher = C_lib.Hasher;
  9406. var C_algo = C.algo;
  9407. // Constants table
  9408. var _zl = WordArray.create([
  9409. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
  9410. 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8,
  9411. 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12,
  9412. 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2,
  9413. 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13]);
  9414. var _zr = WordArray.create([
  9415. 5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12,
  9416. 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2,
  9417. 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13,
  9418. 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14,
  9419. 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11]);
  9420. var _sl = WordArray.create([
  9421. 11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8,
  9422. 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12,
  9423. 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5,
  9424. 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12,
  9425. 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6 ]);
  9426. var _sr = WordArray.create([
  9427. 8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6,
  9428. 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11,
  9429. 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5,
  9430. 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8,
  9431. 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11 ]);
  9432. var _hl = WordArray.create([ 0x00000000, 0x5A827999, 0x6ED9EBA1, 0x8F1BBCDC, 0xA953FD4E]);
  9433. var _hr = WordArray.create([ 0x50A28BE6, 0x5C4DD124, 0x6D703EF3, 0x7A6D76E9, 0x00000000]);
  9434. /**
  9435. * RIPEMD160 hash algorithm.
  9436. */
  9437. var RIPEMD160 = C_algo.RIPEMD160 = Hasher.extend({
  9438. _doReset: function () {
  9439. this._hash = WordArray.create([0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0]);
  9440. },
  9441. _doProcessBlock: function (M, offset) {
  9442. // Swap endian
  9443. for (var i = 0; i < 16; i++) {
  9444. // Shortcuts
  9445. var offset_i = offset + i;
  9446. var M_offset_i = M[offset_i];
  9447. // Swap
  9448. M[offset_i] = (
  9449. (((M_offset_i << 8) | (M_offset_i >>> 24)) & 0x00ff00ff) |
  9450. (((M_offset_i << 24) | (M_offset_i >>> 8)) & 0xff00ff00)
  9451. );
  9452. }
  9453. // Shortcut
  9454. var H = this._hash.words;
  9455. var hl = _hl.words;
  9456. var hr = _hr.words;
  9457. var zl = _zl.words;
  9458. var zr = _zr.words;
  9459. var sl = _sl.words;
  9460. var sr = _sr.words;
  9461. // Working variables
  9462. var al, bl, cl, dl, el;
  9463. var ar, br, cr, dr, er;
  9464. ar = al = H[0];
  9465. br = bl = H[1];
  9466. cr = cl = H[2];
  9467. dr = dl = H[3];
  9468. er = el = H[4];
  9469. // Computation
  9470. var t;
  9471. for (var i = 0; i < 80; i += 1) {
  9472. t = (al + M[offset+zl[i]])|0;
  9473. if (i<16){
  9474. t += f1(bl,cl,dl) + hl[0];
  9475. } else if (i<32) {
  9476. t += f2(bl,cl,dl) + hl[1];
  9477. } else if (i<48) {
  9478. t += f3(bl,cl,dl) + hl[2];
  9479. } else if (i<64) {
  9480. t += f4(bl,cl,dl) + hl[3];
  9481. } else {// if (i<80) {
  9482. t += f5(bl,cl,dl) + hl[4];
  9483. }
  9484. t = t|0;
  9485. t = rotl(t,sl[i]);
  9486. t = (t+el)|0;
  9487. al = el;
  9488. el = dl;
  9489. dl = rotl(cl, 10);
  9490. cl = bl;
  9491. bl = t;
  9492. t = (ar + M[offset+zr[i]])|0;
  9493. if (i<16){
  9494. t += f5(br,cr,dr) + hr[0];
  9495. } else if (i<32) {
  9496. t += f4(br,cr,dr) + hr[1];
  9497. } else if (i<48) {
  9498. t += f3(br,cr,dr) + hr[2];
  9499. } else if (i<64) {
  9500. t += f2(br,cr,dr) + hr[3];
  9501. } else {// if (i<80) {
  9502. t += f1(br,cr,dr) + hr[4];
  9503. }
  9504. t = t|0;
  9505. t = rotl(t,sr[i]) ;
  9506. t = (t+er)|0;
  9507. ar = er;
  9508. er = dr;
  9509. dr = rotl(cr, 10);
  9510. cr = br;
  9511. br = t;
  9512. }
  9513. // Intermediate hash value
  9514. t = (H[1] + cl + dr)|0;
  9515. H[1] = (H[2] + dl + er)|0;
  9516. H[2] = (H[3] + el + ar)|0;
  9517. H[3] = (H[4] + al + br)|0;
  9518. H[4] = (H[0] + bl + cr)|0;
  9519. H[0] = t;
  9520. },
  9521. _doFinalize: function () {
  9522. // Shortcuts
  9523. var data = this._data;
  9524. var dataWords = data.words;
  9525. var nBitsTotal = this._nDataBytes * 8;
  9526. var nBitsLeft = data.sigBytes * 8;
  9527. // Add padding
  9528. dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32);
  9529. dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = (
  9530. (((nBitsTotal << 8) | (nBitsTotal >>> 24)) & 0x00ff00ff) |
  9531. (((nBitsTotal << 24) | (nBitsTotal >>> 8)) & 0xff00ff00)
  9532. );
  9533. data.sigBytes = (dataWords.length + 1) * 4;
  9534. // Hash final blocks
  9535. this._process();
  9536. // Shortcuts
  9537. var hash = this._hash;
  9538. var H = hash.words;
  9539. // Swap endian
  9540. for (var i = 0; i < 5; i++) {
  9541. // Shortcut
  9542. var H_i = H[i];
  9543. // Swap
  9544. H[i] = (((H_i << 8) | (H_i >>> 24)) & 0x00ff00ff) |
  9545. (((H_i << 24) | (H_i >>> 8)) & 0xff00ff00);
  9546. }
  9547. // Return final computed hash
  9548. return hash;
  9549. },
  9550. clone: function () {
  9551. var clone = Hasher.clone.call(this);
  9552. clone._hash = this._hash.clone();
  9553. return clone;
  9554. }
  9555. });
  9556. function f1(x, y, z) {
  9557. return ((x) ^ (y) ^ (z));
  9558. }
  9559. function f2(x, y, z) {
  9560. return (((x)&(y)) | ((~x)&(z)));
  9561. }
  9562. function f3(x, y, z) {
  9563. return (((x) | (~(y))) ^ (z));
  9564. }
  9565. function f4(x, y, z) {
  9566. return (((x) & (z)) | ((y)&(~(z))));
  9567. }
  9568. function f5(x, y, z) {
  9569. return ((x) ^ ((y) |(~(z))));
  9570. }
  9571. function rotl(x,n) {
  9572. return (x<<n) | (x>>>(32-n));
  9573. }
  9574. /**
  9575. * Shortcut function to the hasher's object interface.
  9576. *
  9577. * @param {WordArray|string} message The message to hash.
  9578. *
  9579. * @return {WordArray} The hash.
  9580. *
  9581. * @static
  9582. *
  9583. * @example
  9584. *
  9585. * var hash = CryptoJS.RIPEMD160('message');
  9586. * var hash = CryptoJS.RIPEMD160(wordArray);
  9587. */
  9588. C.RIPEMD160 = Hasher._createHelper(RIPEMD160);
  9589. /**
  9590. * Shortcut function to the HMAC's object interface.
  9591. *
  9592. * @param {WordArray|string} message The message to hash.
  9593. * @param {WordArray|string} key The secret key.
  9594. *
  9595. * @return {WordArray} The HMAC.
  9596. *
  9597. * @static
  9598. *
  9599. * @example
  9600. *
  9601. * var hmac = CryptoJS.HmacRIPEMD160(message, key);
  9602. */
  9603. C.HmacRIPEMD160 = Hasher._createHmacHelper(RIPEMD160);
  9604. }(Math));
  9605. return CryptoJS.RIPEMD160;
  9606. }));
  9607. },{"./core":53}],77:[function(require,module,exports){
  9608. ;(function (root, factory) {
  9609. if (typeof exports === "object") {
  9610. // CommonJS
  9611. module.exports = exports = factory(require("./core"));
  9612. }
  9613. else if (typeof define === "function" && define.amd) {
  9614. // AMD
  9615. define(["./core"], factory);
  9616. }
  9617. else {
  9618. // Global (browser)
  9619. factory(root.CryptoJS);
  9620. }
  9621. }(this, function (CryptoJS) {
  9622. (function () {
  9623. // Shortcuts
  9624. var C = CryptoJS;
  9625. var C_lib = C.lib;
  9626. var WordArray = C_lib.WordArray;
  9627. var Hasher = C_lib.Hasher;
  9628. var C_algo = C.algo;
  9629. // Reusable object
  9630. var W = [];
  9631. /**
  9632. * SHA-1 hash algorithm.
  9633. */
  9634. var SHA1 = C_algo.SHA1 = Hasher.extend({
  9635. _doReset: function () {
  9636. this._hash = new WordArray.init([
  9637. 0x67452301, 0xefcdab89,
  9638. 0x98badcfe, 0x10325476,
  9639. 0xc3d2e1f0
  9640. ]);
  9641. },
  9642. _doProcessBlock: function (M, offset) {
  9643. // Shortcut
  9644. var H = this._hash.words;
  9645. // Working variables
  9646. var a = H[0];
  9647. var b = H[1];
  9648. var c = H[2];
  9649. var d = H[3];
  9650. var e = H[4];
  9651. // Computation
  9652. for (var i = 0; i < 80; i++) {
  9653. if (i < 16) {
  9654. W[i] = M[offset + i] | 0;
  9655. } else {
  9656. var n = W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16];
  9657. W[i] = (n << 1) | (n >>> 31);
  9658. }
  9659. var t = ((a << 5) | (a >>> 27)) + e + W[i];
  9660. if (i < 20) {
  9661. t += ((b & c) | (~b & d)) + 0x5a827999;
  9662. } else if (i < 40) {
  9663. t += (b ^ c ^ d) + 0x6ed9eba1;
  9664. } else if (i < 60) {
  9665. t += ((b & c) | (b & d) | (c & d)) - 0x70e44324;
  9666. } else /* if (i < 80) */ {
  9667. t += (b ^ c ^ d) - 0x359d3e2a;
  9668. }
  9669. e = d;
  9670. d = c;
  9671. c = (b << 30) | (b >>> 2);
  9672. b = a;
  9673. a = t;
  9674. }
  9675. // Intermediate hash value
  9676. H[0] = (H[0] + a) | 0;
  9677. H[1] = (H[1] + b) | 0;
  9678. H[2] = (H[2] + c) | 0;
  9679. H[3] = (H[3] + d) | 0;
  9680. H[4] = (H[4] + e) | 0;
  9681. },
  9682. _doFinalize: function () {
  9683. // Shortcuts
  9684. var data = this._data;
  9685. var dataWords = data.words;
  9686. var nBitsTotal = this._nDataBytes * 8;
  9687. var nBitsLeft = data.sigBytes * 8;
  9688. // Add padding
  9689. dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32);
  9690. dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = Math.floor(nBitsTotal / 0x100000000);
  9691. dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = nBitsTotal;
  9692. data.sigBytes = dataWords.length * 4;
  9693. // Hash final blocks
  9694. this._process();
  9695. // Return final computed hash
  9696. return this._hash;
  9697. },
  9698. clone: function () {
  9699. var clone = Hasher.clone.call(this);
  9700. clone._hash = this._hash.clone();
  9701. return clone;
  9702. }
  9703. });
  9704. /**
  9705. * Shortcut function to the hasher's object interface.
  9706. *
  9707. * @param {WordArray|string} message The message to hash.
  9708. *
  9709. * @return {WordArray} The hash.
  9710. *
  9711. * @static
  9712. *
  9713. * @example
  9714. *
  9715. * var hash = CryptoJS.SHA1('message');
  9716. * var hash = CryptoJS.SHA1(wordArray);
  9717. */
  9718. C.SHA1 = Hasher._createHelper(SHA1);
  9719. /**
  9720. * Shortcut function to the HMAC's object interface.
  9721. *
  9722. * @param {WordArray|string} message The message to hash.
  9723. * @param {WordArray|string} key The secret key.
  9724. *
  9725. * @return {WordArray} The HMAC.
  9726. *
  9727. * @static
  9728. *
  9729. * @example
  9730. *
  9731. * var hmac = CryptoJS.HmacSHA1(message, key);
  9732. */
  9733. C.HmacSHA1 = Hasher._createHmacHelper(SHA1);
  9734. }());
  9735. return CryptoJS.SHA1;
  9736. }));
  9737. },{"./core":53}],78:[function(require,module,exports){
  9738. ;(function (root, factory, undef) {
  9739. if (typeof exports === "object") {
  9740. // CommonJS
  9741. module.exports = exports = factory(require("./core"), require("./sha256"));
  9742. }
  9743. else if (typeof define === "function" && define.amd) {
  9744. // AMD
  9745. define(["./core", "./sha256"], factory);
  9746. }
  9747. else {
  9748. // Global (browser)
  9749. factory(root.CryptoJS);
  9750. }
  9751. }(this, function (CryptoJS) {
  9752. (function () {
  9753. // Shortcuts
  9754. var C = CryptoJS;
  9755. var C_lib = C.lib;
  9756. var WordArray = C_lib.WordArray;
  9757. var C_algo = C.algo;
  9758. var SHA256 = C_algo.SHA256;
  9759. /**
  9760. * SHA-224 hash algorithm.
  9761. */
  9762. var SHA224 = C_algo.SHA224 = SHA256.extend({
  9763. _doReset: function () {
  9764. this._hash = new WordArray.init([
  9765. 0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939,
  9766. 0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4
  9767. ]);
  9768. },
  9769. _doFinalize: function () {
  9770. var hash = SHA256._doFinalize.call(this);
  9771. hash.sigBytes -= 4;
  9772. return hash;
  9773. }
  9774. });
  9775. /**
  9776. * Shortcut function to the hasher's object interface.
  9777. *
  9778. * @param {WordArray|string} message The message to hash.
  9779. *
  9780. * @return {WordArray} The hash.
  9781. *
  9782. * @static
  9783. *
  9784. * @example
  9785. *
  9786. * var hash = CryptoJS.SHA224('message');
  9787. * var hash = CryptoJS.SHA224(wordArray);
  9788. */
  9789. C.SHA224 = SHA256._createHelper(SHA224);
  9790. /**
  9791. * Shortcut function to the HMAC's object interface.
  9792. *
  9793. * @param {WordArray|string} message The message to hash.
  9794. * @param {WordArray|string} key The secret key.
  9795. *
  9796. * @return {WordArray} The HMAC.
  9797. *
  9798. * @static
  9799. *
  9800. * @example
  9801. *
  9802. * var hmac = CryptoJS.HmacSHA224(message, key);
  9803. */
  9804. C.HmacSHA224 = SHA256._createHmacHelper(SHA224);
  9805. }());
  9806. return CryptoJS.SHA224;
  9807. }));
  9808. },{"./core":53,"./sha256":79}],79:[function(require,module,exports){
  9809. ;(function (root, factory) {
  9810. if (typeof exports === "object") {
  9811. // CommonJS
  9812. module.exports = exports = factory(require("./core"));
  9813. }
  9814. else if (typeof define === "function" && define.amd) {
  9815. // AMD
  9816. define(["./core"], factory);
  9817. }
  9818. else {
  9819. // Global (browser)
  9820. factory(root.CryptoJS);
  9821. }
  9822. }(this, function (CryptoJS) {
  9823. (function (Math) {
  9824. // Shortcuts
  9825. var C = CryptoJS;
  9826. var C_lib = C.lib;
  9827. var WordArray = C_lib.WordArray;
  9828. var Hasher = C_lib.Hasher;
  9829. var C_algo = C.algo;
  9830. // Initialization and round constants tables
  9831. var H = [];
  9832. var K = [];
  9833. // Compute constants
  9834. (function () {
  9835. function isPrime(n) {
  9836. var sqrtN = Math.sqrt(n);
  9837. for (var factor = 2; factor <= sqrtN; factor++) {
  9838. if (!(n % factor)) {
  9839. return false;
  9840. }
  9841. }
  9842. return true;
  9843. }
  9844. function getFractionalBits(n) {
  9845. return ((n - (n | 0)) * 0x100000000) | 0;
  9846. }
  9847. var n = 2;
  9848. var nPrime = 0;
  9849. while (nPrime < 64) {
  9850. if (isPrime(n)) {
  9851. if (nPrime < 8) {
  9852. H[nPrime] = getFractionalBits(Math.pow(n, 1 / 2));
  9853. }
  9854. K[nPrime] = getFractionalBits(Math.pow(n, 1 / 3));
  9855. nPrime++;
  9856. }
  9857. n++;
  9858. }
  9859. }());
  9860. // Reusable object
  9861. var W = [];
  9862. /**
  9863. * SHA-256 hash algorithm.
  9864. */
  9865. var SHA256 = C_algo.SHA256 = Hasher.extend({
  9866. _doReset: function () {
  9867. this._hash = new WordArray.init(H.slice(0));
  9868. },
  9869. _doProcessBlock: function (M, offset) {
  9870. // Shortcut
  9871. var H = this._hash.words;
  9872. // Working variables
  9873. var a = H[0];
  9874. var b = H[1];
  9875. var c = H[2];
  9876. var d = H[3];
  9877. var e = H[4];
  9878. var f = H[5];
  9879. var g = H[6];
  9880. var h = H[7];
  9881. // Computation
  9882. for (var i = 0; i < 64; i++) {
  9883. if (i < 16) {
  9884. W[i] = M[offset + i] | 0;
  9885. } else {
  9886. var gamma0x = W[i - 15];
  9887. var gamma0 = ((gamma0x << 25) | (gamma0x >>> 7)) ^
  9888. ((gamma0x << 14) | (gamma0x >>> 18)) ^
  9889. (gamma0x >>> 3);
  9890. var gamma1x = W[i - 2];
  9891. var gamma1 = ((gamma1x << 15) | (gamma1x >>> 17)) ^
  9892. ((gamma1x << 13) | (gamma1x >>> 19)) ^
  9893. (gamma1x >>> 10);
  9894. W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16];
  9895. }
  9896. var ch = (e & f) ^ (~e & g);
  9897. var maj = (a & b) ^ (a & c) ^ (b & c);
  9898. var sigma0 = ((a << 30) | (a >>> 2)) ^ ((a << 19) | (a >>> 13)) ^ ((a << 10) | (a >>> 22));
  9899. var sigma1 = ((e << 26) | (e >>> 6)) ^ ((e << 21) | (e >>> 11)) ^ ((e << 7) | (e >>> 25));
  9900. var t1 = h + sigma1 + ch + K[i] + W[i];
  9901. var t2 = sigma0 + maj;
  9902. h = g;
  9903. g = f;
  9904. f = e;
  9905. e = (d + t1) | 0;
  9906. d = c;
  9907. c = b;
  9908. b = a;
  9909. a = (t1 + t2) | 0;
  9910. }
  9911. // Intermediate hash value
  9912. H[0] = (H[0] + a) | 0;
  9913. H[1] = (H[1] + b) | 0;
  9914. H[2] = (H[2] + c) | 0;
  9915. H[3] = (H[3] + d) | 0;
  9916. H[4] = (H[4] + e) | 0;
  9917. H[5] = (H[5] + f) | 0;
  9918. H[6] = (H[6] + g) | 0;
  9919. H[7] = (H[7] + h) | 0;
  9920. },
  9921. _doFinalize: function () {
  9922. // Shortcuts
  9923. var data = this._data;
  9924. var dataWords = data.words;
  9925. var nBitsTotal = this._nDataBytes * 8;
  9926. var nBitsLeft = data.sigBytes * 8;
  9927. // Add padding
  9928. dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32);
  9929. dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = Math.floor(nBitsTotal / 0x100000000);
  9930. dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = nBitsTotal;
  9931. data.sigBytes = dataWords.length * 4;
  9932. // Hash final blocks
  9933. this._process();
  9934. // Return final computed hash
  9935. return this._hash;
  9936. },
  9937. clone: function () {
  9938. var clone = Hasher.clone.call(this);
  9939. clone._hash = this._hash.clone();
  9940. return clone;
  9941. }
  9942. });
  9943. /**
  9944. * Shortcut function to the hasher's object interface.
  9945. *
  9946. * @param {WordArray|string} message The message to hash.
  9947. *
  9948. * @return {WordArray} The hash.
  9949. *
  9950. * @static
  9951. *
  9952. * @example
  9953. *
  9954. * var hash = CryptoJS.SHA256('message');
  9955. * var hash = CryptoJS.SHA256(wordArray);
  9956. */
  9957. C.SHA256 = Hasher._createHelper(SHA256);
  9958. /**
  9959. * Shortcut function to the HMAC's object interface.
  9960. *
  9961. * @param {WordArray|string} message The message to hash.
  9962. * @param {WordArray|string} key The secret key.
  9963. *
  9964. * @return {WordArray} The HMAC.
  9965. *
  9966. * @static
  9967. *
  9968. * @example
  9969. *
  9970. * var hmac = CryptoJS.HmacSHA256(message, key);
  9971. */
  9972. C.HmacSHA256 = Hasher._createHmacHelper(SHA256);
  9973. }(Math));
  9974. return CryptoJS.SHA256;
  9975. }));
  9976. },{"./core":53}],80:[function(require,module,exports){
  9977. ;(function (root, factory, undef) {
  9978. if (typeof exports === "object") {
  9979. // CommonJS
  9980. module.exports = exports = factory(require("./core"), require("./x64-core"));
  9981. }
  9982. else if (typeof define === "function" && define.amd) {
  9983. // AMD
  9984. define(["./core", "./x64-core"], factory);
  9985. }
  9986. else {
  9987. // Global (browser)
  9988. factory(root.CryptoJS);
  9989. }
  9990. }(this, function (CryptoJS) {
  9991. (function (Math) {
  9992. // Shortcuts
  9993. var C = CryptoJS;
  9994. var C_lib = C.lib;
  9995. var WordArray = C_lib.WordArray;
  9996. var Hasher = C_lib.Hasher;
  9997. var C_x64 = C.x64;
  9998. var X64Word = C_x64.Word;
  9999. var C_algo = C.algo;
  10000. // Constants tables
  10001. var RHO_OFFSETS = [];
  10002. var PI_INDEXES = [];
  10003. var ROUND_CONSTANTS = [];
  10004. // Compute Constants
  10005. (function () {
  10006. // Compute rho offset constants
  10007. var x = 1, y = 0;
  10008. for (var t = 0; t < 24; t++) {
  10009. RHO_OFFSETS[x + 5 * y] = ((t + 1) * (t + 2) / 2) % 64;
  10010. var newX = y % 5;
  10011. var newY = (2 * x + 3 * y) % 5;
  10012. x = newX;
  10013. y = newY;
  10014. }
  10015. // Compute pi index constants
  10016. for (var x = 0; x < 5; x++) {
  10017. for (var y = 0; y < 5; y++) {
  10018. PI_INDEXES[x + 5 * y] = y + ((2 * x + 3 * y) % 5) * 5;
  10019. }
  10020. }
  10021. // Compute round constants
  10022. var LFSR = 0x01;
  10023. for (var i = 0; i < 24; i++) {
  10024. var roundConstantMsw = 0;
  10025. var roundConstantLsw = 0;
  10026. for (var j = 0; j < 7; j++) {
  10027. if (LFSR & 0x01) {
  10028. var bitPosition = (1 << j) - 1;
  10029. if (bitPosition < 32) {
  10030. roundConstantLsw ^= 1 << bitPosition;
  10031. } else /* if (bitPosition >= 32) */ {
  10032. roundConstantMsw ^= 1 << (bitPosition - 32);
  10033. }
  10034. }
  10035. // Compute next LFSR
  10036. if (LFSR & 0x80) {
  10037. // Primitive polynomial over GF(2): x^8 + x^6 + x^5 + x^4 + 1
  10038. LFSR = (LFSR << 1) ^ 0x71;
  10039. } else {
  10040. LFSR <<= 1;
  10041. }
  10042. }
  10043. ROUND_CONSTANTS[i] = X64Word.create(roundConstantMsw, roundConstantLsw);
  10044. }
  10045. }());
  10046. // Reusable objects for temporary values
  10047. var T = [];
  10048. (function () {
  10049. for (var i = 0; i < 25; i++) {
  10050. T[i] = X64Word.create();
  10051. }
  10052. }());
  10053. /**
  10054. * SHA-3 hash algorithm.
  10055. */
  10056. var SHA3 = C_algo.SHA3 = Hasher.extend({
  10057. /**
  10058. * Configuration options.
  10059. *
  10060. * @property {number} outputLength
  10061. * The desired number of bits in the output hash.
  10062. * Only values permitted are: 224, 256, 384, 512.
  10063. * Default: 512
  10064. */
  10065. cfg: Hasher.cfg.extend({
  10066. outputLength: 512
  10067. }),
  10068. _doReset: function () {
  10069. var state = this._state = []
  10070. for (var i = 0; i < 25; i++) {
  10071. state[i] = new X64Word.init();
  10072. }
  10073. this.blockSize = (1600 - 2 * this.cfg.outputLength) / 32;
  10074. },
  10075. _doProcessBlock: function (M, offset) {
  10076. // Shortcuts
  10077. var state = this._state;
  10078. var nBlockSizeLanes = this.blockSize / 2;
  10079. // Absorb
  10080. for (var i = 0; i < nBlockSizeLanes; i++) {
  10081. // Shortcuts
  10082. var M2i = M[offset + 2 * i];
  10083. var M2i1 = M[offset + 2 * i + 1];
  10084. // Swap endian
  10085. M2i = (
  10086. (((M2i << 8) | (M2i >>> 24)) & 0x00ff00ff) |
  10087. (((M2i << 24) | (M2i >>> 8)) & 0xff00ff00)
  10088. );
  10089. M2i1 = (
  10090. (((M2i1 << 8) | (M2i1 >>> 24)) & 0x00ff00ff) |
  10091. (((M2i1 << 24) | (M2i1 >>> 8)) & 0xff00ff00)
  10092. );
  10093. // Absorb message into state
  10094. var lane = state[i];
  10095. lane.high ^= M2i1;
  10096. lane.low ^= M2i;
  10097. }
  10098. // Rounds
  10099. for (var round = 0; round < 24; round++) {
  10100. // Theta
  10101. for (var x = 0; x < 5; x++) {
  10102. // Mix column lanes
  10103. var tMsw = 0, tLsw = 0;
  10104. for (var y = 0; y < 5; y++) {
  10105. var lane = state[x + 5 * y];
  10106. tMsw ^= lane.high;
  10107. tLsw ^= lane.low;
  10108. }
  10109. // Temporary values
  10110. var Tx = T[x];
  10111. Tx.high = tMsw;
  10112. Tx.low = tLsw;
  10113. }
  10114. for (var x = 0; x < 5; x++) {
  10115. // Shortcuts
  10116. var Tx4 = T[(x + 4) % 5];
  10117. var Tx1 = T[(x + 1) % 5];
  10118. var Tx1Msw = Tx1.high;
  10119. var Tx1Lsw = Tx1.low;
  10120. // Mix surrounding columns
  10121. var tMsw = Tx4.high ^ ((Tx1Msw << 1) | (Tx1Lsw >>> 31));
  10122. var tLsw = Tx4.low ^ ((Tx1Lsw << 1) | (Tx1Msw >>> 31));
  10123. for (var y = 0; y < 5; y++) {
  10124. var lane = state[x + 5 * y];
  10125. lane.high ^= tMsw;
  10126. lane.low ^= tLsw;
  10127. }
  10128. }
  10129. // Rho Pi
  10130. for (var laneIndex = 1; laneIndex < 25; laneIndex++) {
  10131. // Shortcuts
  10132. var lane = state[laneIndex];
  10133. var laneMsw = lane.high;
  10134. var laneLsw = lane.low;
  10135. var rhoOffset = RHO_OFFSETS[laneIndex];
  10136. // Rotate lanes
  10137. if (rhoOffset < 32) {
  10138. var tMsw = (laneMsw << rhoOffset) | (laneLsw >>> (32 - rhoOffset));
  10139. var tLsw = (laneLsw << rhoOffset) | (laneMsw >>> (32 - rhoOffset));
  10140. } else /* if (rhoOffset >= 32) */ {
  10141. var tMsw = (laneLsw << (rhoOffset - 32)) | (laneMsw >>> (64 - rhoOffset));
  10142. var tLsw = (laneMsw << (rhoOffset - 32)) | (laneLsw >>> (64 - rhoOffset));
  10143. }
  10144. // Transpose lanes
  10145. var TPiLane = T[PI_INDEXES[laneIndex]];
  10146. TPiLane.high = tMsw;
  10147. TPiLane.low = tLsw;
  10148. }
  10149. // Rho pi at x = y = 0
  10150. var T0 = T[0];
  10151. var state0 = state[0];
  10152. T0.high = state0.high;
  10153. T0.low = state0.low;
  10154. // Chi
  10155. for (var x = 0; x < 5; x++) {
  10156. for (var y = 0; y < 5; y++) {
  10157. // Shortcuts
  10158. var laneIndex = x + 5 * y;
  10159. var lane = state[laneIndex];
  10160. var TLane = T[laneIndex];
  10161. var Tx1Lane = T[((x + 1) % 5) + 5 * y];
  10162. var Tx2Lane = T[((x + 2) % 5) + 5 * y];
  10163. // Mix rows
  10164. lane.high = TLane.high ^ (~Tx1Lane.high & Tx2Lane.high);
  10165. lane.low = TLane.low ^ (~Tx1Lane.low & Tx2Lane.low);
  10166. }
  10167. }
  10168. // Iota
  10169. var lane = state[0];
  10170. var roundConstant = ROUND_CONSTANTS[round];
  10171. lane.high ^= roundConstant.high;
  10172. lane.low ^= roundConstant.low;;
  10173. }
  10174. },
  10175. _doFinalize: function () {
  10176. // Shortcuts
  10177. var data = this._data;
  10178. var dataWords = data.words;
  10179. var nBitsTotal = this._nDataBytes * 8;
  10180. var nBitsLeft = data.sigBytes * 8;
  10181. var blockSizeBits = this.blockSize * 32;
  10182. // Add padding
  10183. dataWords[nBitsLeft >>> 5] |= 0x1 << (24 - nBitsLeft % 32);
  10184. dataWords[((Math.ceil((nBitsLeft + 1) / blockSizeBits) * blockSizeBits) >>> 5) - 1] |= 0x80;
  10185. data.sigBytes = dataWords.length * 4;
  10186. // Hash final blocks
  10187. this._process();
  10188. // Shortcuts
  10189. var state = this._state;
  10190. var outputLengthBytes = this.cfg.outputLength / 8;
  10191. var outputLengthLanes = outputLengthBytes / 8;
  10192. // Squeeze
  10193. var hashWords = [];
  10194. for (var i = 0; i < outputLengthLanes; i++) {
  10195. // Shortcuts
  10196. var lane = state[i];
  10197. var laneMsw = lane.high;
  10198. var laneLsw = lane.low;
  10199. // Swap endian
  10200. laneMsw = (
  10201. (((laneMsw << 8) | (laneMsw >>> 24)) & 0x00ff00ff) |
  10202. (((laneMsw << 24) | (laneMsw >>> 8)) & 0xff00ff00)
  10203. );
  10204. laneLsw = (
  10205. (((laneLsw << 8) | (laneLsw >>> 24)) & 0x00ff00ff) |
  10206. (((laneLsw << 24) | (laneLsw >>> 8)) & 0xff00ff00)
  10207. );
  10208. // Squeeze state to retrieve hash
  10209. hashWords.push(laneLsw);
  10210. hashWords.push(laneMsw);
  10211. }
  10212. // Return final computed hash
  10213. return new WordArray.init(hashWords, outputLengthBytes);
  10214. },
  10215. clone: function () {
  10216. var clone = Hasher.clone.call(this);
  10217. var state = clone._state = this._state.slice(0);
  10218. for (var i = 0; i < 25; i++) {
  10219. state[i] = state[i].clone();
  10220. }
  10221. return clone;
  10222. }
  10223. });
  10224. /**
  10225. * Shortcut function to the hasher's object interface.
  10226. *
  10227. * @param {WordArray|string} message The message to hash.
  10228. *
  10229. * @return {WordArray} The hash.
  10230. *
  10231. * @static
  10232. *
  10233. * @example
  10234. *
  10235. * var hash = CryptoJS.SHA3('message');
  10236. * var hash = CryptoJS.SHA3(wordArray);
  10237. */
  10238. C.SHA3 = Hasher._createHelper(SHA3);
  10239. /**
  10240. * Shortcut function to the HMAC's object interface.
  10241. *
  10242. * @param {WordArray|string} message The message to hash.
  10243. * @param {WordArray|string} key The secret key.
  10244. *
  10245. * @return {WordArray} The HMAC.
  10246. *
  10247. * @static
  10248. *
  10249. * @example
  10250. *
  10251. * var hmac = CryptoJS.HmacSHA3(message, key);
  10252. */
  10253. C.HmacSHA3 = Hasher._createHmacHelper(SHA3);
  10254. }(Math));
  10255. return CryptoJS.SHA3;
  10256. }));
  10257. },{"./core":53,"./x64-core":84}],81:[function(require,module,exports){
  10258. ;(function (root, factory, undef) {
  10259. if (typeof exports === "object") {
  10260. // CommonJS
  10261. module.exports = exports = factory(require("./core"), require("./x64-core"), require("./sha512"));
  10262. }
  10263. else if (typeof define === "function" && define.amd) {
  10264. // AMD
  10265. define(["./core", "./x64-core", "./sha512"], factory);
  10266. }
  10267. else {
  10268. // Global (browser)
  10269. factory(root.CryptoJS);
  10270. }
  10271. }(this, function (CryptoJS) {
  10272. (function () {
  10273. // Shortcuts
  10274. var C = CryptoJS;
  10275. var C_x64 = C.x64;
  10276. var X64Word = C_x64.Word;
  10277. var X64WordArray = C_x64.WordArray;
  10278. var C_algo = C.algo;
  10279. var SHA512 = C_algo.SHA512;
  10280. /**
  10281. * SHA-384 hash algorithm.
  10282. */
  10283. var SHA384 = C_algo.SHA384 = SHA512.extend({
  10284. _doReset: function () {
  10285. this._hash = new X64WordArray.init([
  10286. new X64Word.init(0xcbbb9d5d, 0xc1059ed8), new X64Word.init(0x629a292a, 0x367cd507),
  10287. new X64Word.init(0x9159015a, 0x3070dd17), new X64Word.init(0x152fecd8, 0xf70e5939),
  10288. new X64Word.init(0x67332667, 0xffc00b31), new X64Word.init(0x8eb44a87, 0x68581511),
  10289. new X64Word.init(0xdb0c2e0d, 0x64f98fa7), new X64Word.init(0x47b5481d, 0xbefa4fa4)
  10290. ]);
  10291. },
  10292. _doFinalize: function () {
  10293. var hash = SHA512._doFinalize.call(this);
  10294. hash.sigBytes -= 16;
  10295. return hash;
  10296. }
  10297. });
  10298. /**
  10299. * Shortcut function to the hasher's object interface.
  10300. *
  10301. * @param {WordArray|string} message The message to hash.
  10302. *
  10303. * @return {WordArray} The hash.
  10304. *
  10305. * @static
  10306. *
  10307. * @example
  10308. *
  10309. * var hash = CryptoJS.SHA384('message');
  10310. * var hash = CryptoJS.SHA384(wordArray);
  10311. */
  10312. C.SHA384 = SHA512._createHelper(SHA384);
  10313. /**
  10314. * Shortcut function to the HMAC's object interface.
  10315. *
  10316. * @param {WordArray|string} message The message to hash.
  10317. * @param {WordArray|string} key The secret key.
  10318. *
  10319. * @return {WordArray} The HMAC.
  10320. *
  10321. * @static
  10322. *
  10323. * @example
  10324. *
  10325. * var hmac = CryptoJS.HmacSHA384(message, key);
  10326. */
  10327. C.HmacSHA384 = SHA512._createHmacHelper(SHA384);
  10328. }());
  10329. return CryptoJS.SHA384;
  10330. }));
  10331. },{"./core":53,"./sha512":82,"./x64-core":84}],82:[function(require,module,exports){
  10332. ;(function (root, factory, undef) {
  10333. if (typeof exports === "object") {
  10334. // CommonJS
  10335. module.exports = exports = factory(require("./core"), require("./x64-core"));
  10336. }
  10337. else if (typeof define === "function" && define.amd) {
  10338. // AMD
  10339. define(["./core", "./x64-core"], factory);
  10340. }
  10341. else {
  10342. // Global (browser)
  10343. factory(root.CryptoJS);
  10344. }
  10345. }(this, function (CryptoJS) {
  10346. (function () {
  10347. // Shortcuts
  10348. var C = CryptoJS;
  10349. var C_lib = C.lib;
  10350. var Hasher = C_lib.Hasher;
  10351. var C_x64 = C.x64;
  10352. var X64Word = C_x64.Word;
  10353. var X64WordArray = C_x64.WordArray;
  10354. var C_algo = C.algo;
  10355. function X64Word_create() {
  10356. return X64Word.create.apply(X64Word, arguments);
  10357. }
  10358. // Constants
  10359. var K = [
  10360. X64Word_create(0x428a2f98, 0xd728ae22), X64Word_create(0x71374491, 0x23ef65cd),
  10361. X64Word_create(0xb5c0fbcf, 0xec4d3b2f), X64Word_create(0xe9b5dba5, 0x8189dbbc),
  10362. X64Word_create(0x3956c25b, 0xf348b538), X64Word_create(0x59f111f1, 0xb605d019),
  10363. X64Word_create(0x923f82a4, 0xaf194f9b), X64Word_create(0xab1c5ed5, 0xda6d8118),
  10364. X64Word_create(0xd807aa98, 0xa3030242), X64Word_create(0x12835b01, 0x45706fbe),
  10365. X64Word_create(0x243185be, 0x4ee4b28c), X64Word_create(0x550c7dc3, 0xd5ffb4e2),
  10366. X64Word_create(0x72be5d74, 0xf27b896f), X64Word_create(0x80deb1fe, 0x3b1696b1),
  10367. X64Word_create(0x9bdc06a7, 0x25c71235), X64Word_create(0xc19bf174, 0xcf692694),
  10368. X64Word_create(0xe49b69c1, 0x9ef14ad2), X64Word_create(0xefbe4786, 0x384f25e3),
  10369. X64Word_create(0x0fc19dc6, 0x8b8cd5b5), X64Word_create(0x240ca1cc, 0x77ac9c65),
  10370. X64Word_create(0x2de92c6f, 0x592b0275), X64Word_create(0x4a7484aa, 0x6ea6e483),
  10371. X64Word_create(0x5cb0a9dc, 0xbd41fbd4), X64Word_create(0x76f988da, 0x831153b5),
  10372. X64Word_create(0x983e5152, 0xee66dfab), X64Word_create(0xa831c66d, 0x2db43210),
  10373. X64Word_create(0xb00327c8, 0x98fb213f), X64Word_create(0xbf597fc7, 0xbeef0ee4),
  10374. X64Word_create(0xc6e00bf3, 0x3da88fc2), X64Word_create(0xd5a79147, 0x930aa725),
  10375. X64Word_create(0x06ca6351, 0xe003826f), X64Word_create(0x14292967, 0x0a0e6e70),
  10376. X64Word_create(0x27b70a85, 0x46d22ffc), X64Word_create(0x2e1b2138, 0x5c26c926),
  10377. X64Word_create(0x4d2c6dfc, 0x5ac42aed), X64Word_create(0x53380d13, 0x9d95b3df),
  10378. X64Word_create(0x650a7354, 0x8baf63de), X64Word_create(0x766a0abb, 0x3c77b2a8),
  10379. X64Word_create(0x81c2c92e, 0x47edaee6), X64Word_create(0x92722c85, 0x1482353b),
  10380. X64Word_create(0xa2bfe8a1, 0x4cf10364), X64Word_create(0xa81a664b, 0xbc423001),
  10381. X64Word_create(0xc24b8b70, 0xd0f89791), X64Word_create(0xc76c51a3, 0x0654be30),
  10382. X64Word_create(0xd192e819, 0xd6ef5218), X64Word_create(0xd6990624, 0x5565a910),
  10383. X64Word_create(0xf40e3585, 0x5771202a), X64Word_create(0x106aa070, 0x32bbd1b8),
  10384. X64Word_create(0x19a4c116, 0xb8d2d0c8), X64Word_create(0x1e376c08, 0x5141ab53),
  10385. X64Word_create(0x2748774c, 0xdf8eeb99), X64Word_create(0x34b0bcb5, 0xe19b48a8),
  10386. X64Word_create(0x391c0cb3, 0xc5c95a63), X64Word_create(0x4ed8aa4a, 0xe3418acb),
  10387. X64Word_create(0x5b9cca4f, 0x7763e373), X64Word_create(0x682e6ff3, 0xd6b2b8a3),
  10388. X64Word_create(0x748f82ee, 0x5defb2fc), X64Word_create(0x78a5636f, 0x43172f60),
  10389. X64Word_create(0x84c87814, 0xa1f0ab72), X64Word_create(0x8cc70208, 0x1a6439ec),
  10390. X64Word_create(0x90befffa, 0x23631e28), X64Word_create(0xa4506ceb, 0xde82bde9),
  10391. X64Word_create(0xbef9a3f7, 0xb2c67915), X64Word_create(0xc67178f2, 0xe372532b),
  10392. X64Word_create(0xca273ece, 0xea26619c), X64Word_create(0xd186b8c7, 0x21c0c207),
  10393. X64Word_create(0xeada7dd6, 0xcde0eb1e), X64Word_create(0xf57d4f7f, 0xee6ed178),
  10394. X64Word_create(0x06f067aa, 0x72176fba), X64Word_create(0x0a637dc5, 0xa2c898a6),
  10395. X64Word_create(0x113f9804, 0xbef90dae), X64Word_create(0x1b710b35, 0x131c471b),
  10396. X64Word_create(0x28db77f5, 0x23047d84), X64Word_create(0x32caab7b, 0x40c72493),
  10397. X64Word_create(0x3c9ebe0a, 0x15c9bebc), X64Word_create(0x431d67c4, 0x9c100d4c),
  10398. X64Word_create(0x4cc5d4be, 0xcb3e42b6), X64Word_create(0x597f299c, 0xfc657e2a),
  10399. X64Word_create(0x5fcb6fab, 0x3ad6faec), X64Word_create(0x6c44198c, 0x4a475817)
  10400. ];
  10401. // Reusable objects
  10402. var W = [];
  10403. (function () {
  10404. for (var i = 0; i < 80; i++) {
  10405. W[i] = X64Word_create();
  10406. }
  10407. }());
  10408. /**
  10409. * SHA-512 hash algorithm.
  10410. */
  10411. var SHA512 = C_algo.SHA512 = Hasher.extend({
  10412. _doReset: function () {
  10413. this._hash = new X64WordArray.init([
  10414. new X64Word.init(0x6a09e667, 0xf3bcc908), new X64Word.init(0xbb67ae85, 0x84caa73b),
  10415. new X64Word.init(0x3c6ef372, 0xfe94f82b), new X64Word.init(0xa54ff53a, 0x5f1d36f1),
  10416. new X64Word.init(0x510e527f, 0xade682d1), new X64Word.init(0x9b05688c, 0x2b3e6c1f),
  10417. new X64Word.init(0x1f83d9ab, 0xfb41bd6b), new X64Word.init(0x5be0cd19, 0x137e2179)
  10418. ]);
  10419. },
  10420. _doProcessBlock: function (M, offset) {
  10421. // Shortcuts
  10422. var H = this._hash.words;
  10423. var H0 = H[0];
  10424. var H1 = H[1];
  10425. var H2 = H[2];
  10426. var H3 = H[3];
  10427. var H4 = H[4];
  10428. var H5 = H[5];
  10429. var H6 = H[6];
  10430. var H7 = H[7];
  10431. var H0h = H0.high;
  10432. var H0l = H0.low;
  10433. var H1h = H1.high;
  10434. var H1l = H1.low;
  10435. var H2h = H2.high;
  10436. var H2l = H2.low;
  10437. var H3h = H3.high;
  10438. var H3l = H3.low;
  10439. var H4h = H4.high;
  10440. var H4l = H4.low;
  10441. var H5h = H5.high;
  10442. var H5l = H5.low;
  10443. var H6h = H6.high;
  10444. var H6l = H6.low;
  10445. var H7h = H7.high;
  10446. var H7l = H7.low;
  10447. // Working variables
  10448. var ah = H0h;
  10449. var al = H0l;
  10450. var bh = H1h;
  10451. var bl = H1l;
  10452. var ch = H2h;
  10453. var cl = H2l;
  10454. var dh = H3h;
  10455. var dl = H3l;
  10456. var eh = H4h;
  10457. var el = H4l;
  10458. var fh = H5h;
  10459. var fl = H5l;
  10460. var gh = H6h;
  10461. var gl = H6l;
  10462. var hh = H7h;
  10463. var hl = H7l;
  10464. // Rounds
  10465. for (var i = 0; i < 80; i++) {
  10466. // Shortcut
  10467. var Wi = W[i];
  10468. // Extend message
  10469. if (i < 16) {
  10470. var Wih = Wi.high = M[offset + i * 2] | 0;
  10471. var Wil = Wi.low = M[offset + i * 2 + 1] | 0;
  10472. } else {
  10473. // Gamma0
  10474. var gamma0x = W[i - 15];
  10475. var gamma0xh = gamma0x.high;
  10476. var gamma0xl = gamma0x.low;
  10477. var gamma0h = ((gamma0xh >>> 1) | (gamma0xl << 31)) ^ ((gamma0xh >>> 8) | (gamma0xl << 24)) ^ (gamma0xh >>> 7);
  10478. var gamma0l = ((gamma0xl >>> 1) | (gamma0xh << 31)) ^ ((gamma0xl >>> 8) | (gamma0xh << 24)) ^ ((gamma0xl >>> 7) | (gamma0xh << 25));
  10479. // Gamma1
  10480. var gamma1x = W[i - 2];
  10481. var gamma1xh = gamma1x.high;
  10482. var gamma1xl = gamma1x.low;
  10483. var gamma1h = ((gamma1xh >>> 19) | (gamma1xl << 13)) ^ ((gamma1xh << 3) | (gamma1xl >>> 29)) ^ (gamma1xh >>> 6);
  10484. var gamma1l = ((gamma1xl >>> 19) | (gamma1xh << 13)) ^ ((gamma1xl << 3) | (gamma1xh >>> 29)) ^ ((gamma1xl >>> 6) | (gamma1xh << 26));
  10485. // W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16]
  10486. var Wi7 = W[i - 7];
  10487. var Wi7h = Wi7.high;
  10488. var Wi7l = Wi7.low;
  10489. var Wi16 = W[i - 16];
  10490. var Wi16h = Wi16.high;
  10491. var Wi16l = Wi16.low;
  10492. var Wil = gamma0l + Wi7l;
  10493. var Wih = gamma0h + Wi7h + ((Wil >>> 0) < (gamma0l >>> 0) ? 1 : 0);
  10494. var Wil = Wil + gamma1l;
  10495. var Wih = Wih + gamma1h + ((Wil >>> 0) < (gamma1l >>> 0) ? 1 : 0);
  10496. var Wil = Wil + Wi16l;
  10497. var Wih = Wih + Wi16h + ((Wil >>> 0) < (Wi16l >>> 0) ? 1 : 0);
  10498. Wi.high = Wih;
  10499. Wi.low = Wil;
  10500. }
  10501. var chh = (eh & fh) ^ (~eh & gh);
  10502. var chl = (el & fl) ^ (~el & gl);
  10503. var majh = (ah & bh) ^ (ah & ch) ^ (bh & ch);
  10504. var majl = (al & bl) ^ (al & cl) ^ (bl & cl);
  10505. var sigma0h = ((ah >>> 28) | (al << 4)) ^ ((ah << 30) | (al >>> 2)) ^ ((ah << 25) | (al >>> 7));
  10506. var sigma0l = ((al >>> 28) | (ah << 4)) ^ ((al << 30) | (ah >>> 2)) ^ ((al << 25) | (ah >>> 7));
  10507. var sigma1h = ((eh >>> 14) | (el << 18)) ^ ((eh >>> 18) | (el << 14)) ^ ((eh << 23) | (el >>> 9));
  10508. var sigma1l = ((el >>> 14) | (eh << 18)) ^ ((el >>> 18) | (eh << 14)) ^ ((el << 23) | (eh >>> 9));
  10509. // t1 = h + sigma1 + ch + K[i] + W[i]
  10510. var Ki = K[i];
  10511. var Kih = Ki.high;
  10512. var Kil = Ki.low;
  10513. var t1l = hl + sigma1l;
  10514. var t1h = hh + sigma1h + ((t1l >>> 0) < (hl >>> 0) ? 1 : 0);
  10515. var t1l = t1l + chl;
  10516. var t1h = t1h + chh + ((t1l >>> 0) < (chl >>> 0) ? 1 : 0);
  10517. var t1l = t1l + Kil;
  10518. var t1h = t1h + Kih + ((t1l >>> 0) < (Kil >>> 0) ? 1 : 0);
  10519. var t1l = t1l + Wil;
  10520. var t1h = t1h + Wih + ((t1l >>> 0) < (Wil >>> 0) ? 1 : 0);
  10521. // t2 = sigma0 + maj
  10522. var t2l = sigma0l + majl;
  10523. var t2h = sigma0h + majh + ((t2l >>> 0) < (sigma0l >>> 0) ? 1 : 0);
  10524. // Update working variables
  10525. hh = gh;
  10526. hl = gl;
  10527. gh = fh;
  10528. gl = fl;
  10529. fh = eh;
  10530. fl = el;
  10531. el = (dl + t1l) | 0;
  10532. eh = (dh + t1h + ((el >>> 0) < (dl >>> 0) ? 1 : 0)) | 0;
  10533. dh = ch;
  10534. dl = cl;
  10535. ch = bh;
  10536. cl = bl;
  10537. bh = ah;
  10538. bl = al;
  10539. al = (t1l + t2l) | 0;
  10540. ah = (t1h + t2h + ((al >>> 0) < (t1l >>> 0) ? 1 : 0)) | 0;
  10541. }
  10542. // Intermediate hash value
  10543. H0l = H0.low = (H0l + al);
  10544. H0.high = (H0h + ah + ((H0l >>> 0) < (al >>> 0) ? 1 : 0));
  10545. H1l = H1.low = (H1l + bl);
  10546. H1.high = (H1h + bh + ((H1l >>> 0) < (bl >>> 0) ? 1 : 0));
  10547. H2l = H2.low = (H2l + cl);
  10548. H2.high = (H2h + ch + ((H2l >>> 0) < (cl >>> 0) ? 1 : 0));
  10549. H3l = H3.low = (H3l + dl);
  10550. H3.high = (H3h + dh + ((H3l >>> 0) < (dl >>> 0) ? 1 : 0));
  10551. H4l = H4.low = (H4l + el);
  10552. H4.high = (H4h + eh + ((H4l >>> 0) < (el >>> 0) ? 1 : 0));
  10553. H5l = H5.low = (H5l + fl);
  10554. H5.high = (H5h + fh + ((H5l >>> 0) < (fl >>> 0) ? 1 : 0));
  10555. H6l = H6.low = (H6l + gl);
  10556. H6.high = (H6h + gh + ((H6l >>> 0) < (gl >>> 0) ? 1 : 0));
  10557. H7l = H7.low = (H7l + hl);
  10558. H7.high = (H7h + hh + ((H7l >>> 0) < (hl >>> 0) ? 1 : 0));
  10559. },
  10560. _doFinalize: function () {
  10561. // Shortcuts
  10562. var data = this._data;
  10563. var dataWords = data.words;
  10564. var nBitsTotal = this._nDataBytes * 8;
  10565. var nBitsLeft = data.sigBytes * 8;
  10566. // Add padding
  10567. dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32);
  10568. dataWords[(((nBitsLeft + 128) >>> 10) << 5) + 30] = Math.floor(nBitsTotal / 0x100000000);
  10569. dataWords[(((nBitsLeft + 128) >>> 10) << 5) + 31] = nBitsTotal;
  10570. data.sigBytes = dataWords.length * 4;
  10571. // Hash final blocks
  10572. this._process();
  10573. // Convert hash to 32-bit word array before returning
  10574. var hash = this._hash.toX32();
  10575. // Return final computed hash
  10576. return hash;
  10577. },
  10578. clone: function () {
  10579. var clone = Hasher.clone.call(this);
  10580. clone._hash = this._hash.clone();
  10581. return clone;
  10582. },
  10583. blockSize: 1024/32
  10584. });
  10585. /**
  10586. * Shortcut function to the hasher's object interface.
  10587. *
  10588. * @param {WordArray|string} message The message to hash.
  10589. *
  10590. * @return {WordArray} The hash.
  10591. *
  10592. * @static
  10593. *
  10594. * @example
  10595. *
  10596. * var hash = CryptoJS.SHA512('message');
  10597. * var hash = CryptoJS.SHA512(wordArray);
  10598. */
  10599. C.SHA512 = Hasher._createHelper(SHA512);
  10600. /**
  10601. * Shortcut function to the HMAC's object interface.
  10602. *
  10603. * @param {WordArray|string} message The message to hash.
  10604. * @param {WordArray|string} key The secret key.
  10605. *
  10606. * @return {WordArray} The HMAC.
  10607. *
  10608. * @static
  10609. *
  10610. * @example
  10611. *
  10612. * var hmac = CryptoJS.HmacSHA512(message, key);
  10613. */
  10614. C.HmacSHA512 = Hasher._createHmacHelper(SHA512);
  10615. }());
  10616. return CryptoJS.SHA512;
  10617. }));
  10618. },{"./core":53,"./x64-core":84}],83:[function(require,module,exports){
  10619. ;(function (root, factory, undef) {
  10620. if (typeof exports === "object") {
  10621. // CommonJS
  10622. module.exports = exports = factory(require("./core"), require("./enc-base64"), require("./md5"), require("./evpkdf"), require("./cipher-core"));
  10623. }
  10624. else if (typeof define === "function" && define.amd) {
  10625. // AMD
  10626. define(["./core", "./enc-base64", "./md5", "./evpkdf", "./cipher-core"], factory);
  10627. }
  10628. else {
  10629. // Global (browser)
  10630. factory(root.CryptoJS);
  10631. }
  10632. }(this, function (CryptoJS) {
  10633. (function () {
  10634. // Shortcuts
  10635. var C = CryptoJS;
  10636. var C_lib = C.lib;
  10637. var WordArray = C_lib.WordArray;
  10638. var BlockCipher = C_lib.BlockCipher;
  10639. var C_algo = C.algo;
  10640. // Permuted Choice 1 constants
  10641. var PC1 = [
  10642. 57, 49, 41, 33, 25, 17, 9, 1,
  10643. 58, 50, 42, 34, 26, 18, 10, 2,
  10644. 59, 51, 43, 35, 27, 19, 11, 3,
  10645. 60, 52, 44, 36, 63, 55, 47, 39,
  10646. 31, 23, 15, 7, 62, 54, 46, 38,
  10647. 30, 22, 14, 6, 61, 53, 45, 37,
  10648. 29, 21, 13, 5, 28, 20, 12, 4
  10649. ];
  10650. // Permuted Choice 2 constants
  10651. var PC2 = [
  10652. 14, 17, 11, 24, 1, 5,
  10653. 3, 28, 15, 6, 21, 10,
  10654. 23, 19, 12, 4, 26, 8,
  10655. 16, 7, 27, 20, 13, 2,
  10656. 41, 52, 31, 37, 47, 55,
  10657. 30, 40, 51, 45, 33, 48,
  10658. 44, 49, 39, 56, 34, 53,
  10659. 46, 42, 50, 36, 29, 32
  10660. ];
  10661. // Cumulative bit shift constants
  10662. var BIT_SHIFTS = [1, 2, 4, 6, 8, 10, 12, 14, 15, 17, 19, 21, 23, 25, 27, 28];
  10663. // SBOXes and round permutation constants
  10664. var SBOX_P = [
  10665. {
  10666. 0x0: 0x808200,
  10667. 0x10000000: 0x8000,
  10668. 0x20000000: 0x808002,
  10669. 0x30000000: 0x2,
  10670. 0x40000000: 0x200,
  10671. 0x50000000: 0x808202,
  10672. 0x60000000: 0x800202,
  10673. 0x70000000: 0x800000,
  10674. 0x80000000: 0x202,
  10675. 0x90000000: 0x800200,
  10676. 0xa0000000: 0x8200,
  10677. 0xb0000000: 0x808000,
  10678. 0xc0000000: 0x8002,
  10679. 0xd0000000: 0x800002,
  10680. 0xe0000000: 0x0,
  10681. 0xf0000000: 0x8202,
  10682. 0x8000000: 0x0,
  10683. 0x18000000: 0x808202,
  10684. 0x28000000: 0x8202,
  10685. 0x38000000: 0x8000,
  10686. 0x48000000: 0x808200,
  10687. 0x58000000: 0x200,
  10688. 0x68000000: 0x808002,
  10689. 0x78000000: 0x2,
  10690. 0x88000000: 0x800200,
  10691. 0x98000000: 0x8200,
  10692. 0xa8000000: 0x808000,
  10693. 0xb8000000: 0x800202,
  10694. 0xc8000000: 0x800002,
  10695. 0xd8000000: 0x8002,
  10696. 0xe8000000: 0x202,
  10697. 0xf8000000: 0x800000,
  10698. 0x1: 0x8000,
  10699. 0x10000001: 0x2,
  10700. 0x20000001: 0x808200,
  10701. 0x30000001: 0x800000,
  10702. 0x40000001: 0x808002,
  10703. 0x50000001: 0x8200,
  10704. 0x60000001: 0x200,
  10705. 0x70000001: 0x800202,
  10706. 0x80000001: 0x808202,
  10707. 0x90000001: 0x808000,
  10708. 0xa0000001: 0x800002,
  10709. 0xb0000001: 0x8202,
  10710. 0xc0000001: 0x202,
  10711. 0xd0000001: 0x800200,
  10712. 0xe0000001: 0x8002,
  10713. 0xf0000001: 0x0,
  10714. 0x8000001: 0x808202,
  10715. 0x18000001: 0x808000,
  10716. 0x28000001: 0x800000,
  10717. 0x38000001: 0x200,
  10718. 0x48000001: 0x8000,
  10719. 0x58000001: 0x800002,
  10720. 0x68000001: 0x2,
  10721. 0x78000001: 0x8202,
  10722. 0x88000001: 0x8002,
  10723. 0x98000001: 0x800202,
  10724. 0xa8000001: 0x202,
  10725. 0xb8000001: 0x808200,
  10726. 0xc8000001: 0x800200,
  10727. 0xd8000001: 0x0,
  10728. 0xe8000001: 0x8200,
  10729. 0xf8000001: 0x808002
  10730. },
  10731. {
  10732. 0x0: 0x40084010,
  10733. 0x1000000: 0x4000,
  10734. 0x2000000: 0x80000,
  10735. 0x3000000: 0x40080010,
  10736. 0x4000000: 0x40000010,
  10737. 0x5000000: 0x40084000,
  10738. 0x6000000: 0x40004000,
  10739. 0x7000000: 0x10,
  10740. 0x8000000: 0x84000,
  10741. 0x9000000: 0x40004010,
  10742. 0xa000000: 0x40000000,
  10743. 0xb000000: 0x84010,
  10744. 0xc000000: 0x80010,
  10745. 0xd000000: 0x0,
  10746. 0xe000000: 0x4010,
  10747. 0xf000000: 0x40080000,
  10748. 0x800000: 0x40004000,
  10749. 0x1800000: 0x84010,
  10750. 0x2800000: 0x10,
  10751. 0x3800000: 0x40004010,
  10752. 0x4800000: 0x40084010,
  10753. 0x5800000: 0x40000000,
  10754. 0x6800000: 0x80000,
  10755. 0x7800000: 0x40080010,
  10756. 0x8800000: 0x80010,
  10757. 0x9800000: 0x0,
  10758. 0xa800000: 0x4000,
  10759. 0xb800000: 0x40080000,
  10760. 0xc800000: 0x40000010,
  10761. 0xd800000: 0x84000,
  10762. 0xe800000: 0x40084000,
  10763. 0xf800000: 0x4010,
  10764. 0x10000000: 0x0,
  10765. 0x11000000: 0x40080010,
  10766. 0x12000000: 0x40004010,
  10767. 0x13000000: 0x40084000,
  10768. 0x14000000: 0x40080000,
  10769. 0x15000000: 0x10,
  10770. 0x16000000: 0x84010,
  10771. 0x17000000: 0x4000,
  10772. 0x18000000: 0x4010,
  10773. 0x19000000: 0x80000,
  10774. 0x1a000000: 0x80010,
  10775. 0x1b000000: 0x40000010,
  10776. 0x1c000000: 0x84000,
  10777. 0x1d000000: 0x40004000,
  10778. 0x1e000000: 0x40000000,
  10779. 0x1f000000: 0x40084010,
  10780. 0x10800000: 0x84010,
  10781. 0x11800000: 0x80000,
  10782. 0x12800000: 0x40080000,
  10783. 0x13800000: 0x4000,
  10784. 0x14800000: 0x40004000,
  10785. 0x15800000: 0x40084010,
  10786. 0x16800000: 0x10,
  10787. 0x17800000: 0x40000000,
  10788. 0x18800000: 0x40084000,
  10789. 0x19800000: 0x40000010,
  10790. 0x1a800000: 0x40004010,
  10791. 0x1b800000: 0x80010,
  10792. 0x1c800000: 0x0,
  10793. 0x1d800000: 0x4010,
  10794. 0x1e800000: 0x40080010,
  10795. 0x1f800000: 0x84000
  10796. },
  10797. {
  10798. 0x0: 0x104,
  10799. 0x100000: 0x0,
  10800. 0x200000: 0x4000100,
  10801. 0x300000: 0x10104,
  10802. 0x400000: 0x10004,
  10803. 0x500000: 0x4000004,
  10804. 0x600000: 0x4010104,
  10805. 0x700000: 0x4010000,
  10806. 0x800000: 0x4000000,
  10807. 0x900000: 0x4010100,
  10808. 0xa00000: 0x10100,
  10809. 0xb00000: 0x4010004,
  10810. 0xc00000: 0x4000104,
  10811. 0xd00000: 0x10000,
  10812. 0xe00000: 0x4,
  10813. 0xf00000: 0x100,
  10814. 0x80000: 0x4010100,
  10815. 0x180000: 0x4010004,
  10816. 0x280000: 0x0,
  10817. 0x380000: 0x4000100,
  10818. 0x480000: 0x4000004,
  10819. 0x580000: 0x10000,
  10820. 0x680000: 0x10004,
  10821. 0x780000: 0x104,
  10822. 0x880000: 0x4,
  10823. 0x980000: 0x100,
  10824. 0xa80000: 0x4010000,
  10825. 0xb80000: 0x10104,
  10826. 0xc80000: 0x10100,
  10827. 0xd80000: 0x4000104,
  10828. 0xe80000: 0x4010104,
  10829. 0xf80000: 0x4000000,
  10830. 0x1000000: 0x4010100,
  10831. 0x1100000: 0x10004,
  10832. 0x1200000: 0x10000,
  10833. 0x1300000: 0x4000100,
  10834. 0x1400000: 0x100,
  10835. 0x1500000: 0x4010104,
  10836. 0x1600000: 0x4000004,
  10837. 0x1700000: 0x0,
  10838. 0x1800000: 0x4000104,
  10839. 0x1900000: 0x4000000,
  10840. 0x1a00000: 0x4,
  10841. 0x1b00000: 0x10100,
  10842. 0x1c00000: 0x4010000,
  10843. 0x1d00000: 0x104,
  10844. 0x1e00000: 0x10104,
  10845. 0x1f00000: 0x4010004,
  10846. 0x1080000: 0x4000000,
  10847. 0x1180000: 0x104,
  10848. 0x1280000: 0x4010100,
  10849. 0x1380000: 0x0,
  10850. 0x1480000: 0x10004,
  10851. 0x1580000: 0x4000100,
  10852. 0x1680000: 0x100,
  10853. 0x1780000: 0x4010004,
  10854. 0x1880000: 0x10000,
  10855. 0x1980000: 0x4010104,
  10856. 0x1a80000: 0x10104,
  10857. 0x1b80000: 0x4000004,
  10858. 0x1c80000: 0x4000104,
  10859. 0x1d80000: 0x4010000,
  10860. 0x1e80000: 0x4,
  10861. 0x1f80000: 0x10100
  10862. },
  10863. {
  10864. 0x0: 0x80401000,
  10865. 0x10000: 0x80001040,
  10866. 0x20000: 0x401040,
  10867. 0x30000: 0x80400000,
  10868. 0x40000: 0x0,
  10869. 0x50000: 0x401000,
  10870. 0x60000: 0x80000040,
  10871. 0x70000: 0x400040,
  10872. 0x80000: 0x80000000,
  10873. 0x90000: 0x400000,
  10874. 0xa0000: 0x40,
  10875. 0xb0000: 0x80001000,
  10876. 0xc0000: 0x80400040,
  10877. 0xd0000: 0x1040,
  10878. 0xe0000: 0x1000,
  10879. 0xf0000: 0x80401040,
  10880. 0x8000: 0x80001040,
  10881. 0x18000: 0x40,
  10882. 0x28000: 0x80400040,
  10883. 0x38000: 0x80001000,
  10884. 0x48000: 0x401000,
  10885. 0x58000: 0x80401040,
  10886. 0x68000: 0x0,
  10887. 0x78000: 0x80400000,
  10888. 0x88000: 0x1000,
  10889. 0x98000: 0x80401000,
  10890. 0xa8000: 0x400000,
  10891. 0xb8000: 0x1040,
  10892. 0xc8000: 0x80000000,
  10893. 0xd8000: 0x400040,
  10894. 0xe8000: 0x401040,
  10895. 0xf8000: 0x80000040,
  10896. 0x100000: 0x400040,
  10897. 0x110000: 0x401000,
  10898. 0x120000: 0x80000040,
  10899. 0x130000: 0x0,
  10900. 0x140000: 0x1040,
  10901. 0x150000: 0x80400040,
  10902. 0x160000: 0x80401000,
  10903. 0x170000: 0x80001040,
  10904. 0x180000: 0x80401040,
  10905. 0x190000: 0x80000000,
  10906. 0x1a0000: 0x80400000,
  10907. 0x1b0000: 0x401040,
  10908. 0x1c0000: 0x80001000,
  10909. 0x1d0000: 0x400000,
  10910. 0x1e0000: 0x40,
  10911. 0x1f0000: 0x1000,
  10912. 0x108000: 0x80400000,
  10913. 0x118000: 0x80401040,
  10914. 0x128000: 0x0,
  10915. 0x138000: 0x401000,
  10916. 0x148000: 0x400040,
  10917. 0x158000: 0x80000000,
  10918. 0x168000: 0x80001040,
  10919. 0x178000: 0x40,
  10920. 0x188000: 0x80000040,
  10921. 0x198000: 0x1000,
  10922. 0x1a8000: 0x80001000,
  10923. 0x1b8000: 0x80400040,
  10924. 0x1c8000: 0x1040,
  10925. 0x1d8000: 0x80401000,
  10926. 0x1e8000: 0x400000,
  10927. 0x1f8000: 0x401040
  10928. },
  10929. {
  10930. 0x0: 0x80,
  10931. 0x1000: 0x1040000,
  10932. 0x2000: 0x40000,
  10933. 0x3000: 0x20000000,
  10934. 0x4000: 0x20040080,
  10935. 0x5000: 0x1000080,
  10936. 0x6000: 0x21000080,
  10937. 0x7000: 0x40080,
  10938. 0x8000: 0x1000000,
  10939. 0x9000: 0x20040000,
  10940. 0xa000: 0x20000080,
  10941. 0xb000: 0x21040080,
  10942. 0xc000: 0x21040000,
  10943. 0xd000: 0x0,
  10944. 0xe000: 0x1040080,
  10945. 0xf000: 0x21000000,
  10946. 0x800: 0x1040080,
  10947. 0x1800: 0x21000080,
  10948. 0x2800: 0x80,
  10949. 0x3800: 0x1040000,
  10950. 0x4800: 0x40000,
  10951. 0x5800: 0x20040080,
  10952. 0x6800: 0x21040000,
  10953. 0x7800: 0x20000000,
  10954. 0x8800: 0x20040000,
  10955. 0x9800: 0x0,
  10956. 0xa800: 0x21040080,
  10957. 0xb800: 0x1000080,
  10958. 0xc800: 0x20000080,
  10959. 0xd800: 0x21000000,
  10960. 0xe800: 0x1000000,
  10961. 0xf800: 0x40080,
  10962. 0x10000: 0x40000,
  10963. 0x11000: 0x80,
  10964. 0x12000: 0x20000000,
  10965. 0x13000: 0x21000080,
  10966. 0x14000: 0x1000080,
  10967. 0x15000: 0x21040000,
  10968. 0x16000: 0x20040080,
  10969. 0x17000: 0x1000000,
  10970. 0x18000: 0x21040080,
  10971. 0x19000: 0x21000000,
  10972. 0x1a000: 0x1040000,
  10973. 0x1b000: 0x20040000,
  10974. 0x1c000: 0x40080,
  10975. 0x1d000: 0x20000080,
  10976. 0x1e000: 0x0,
  10977. 0x1f000: 0x1040080,
  10978. 0x10800: 0x21000080,
  10979. 0x11800: 0x1000000,
  10980. 0x12800: 0x1040000,
  10981. 0x13800: 0x20040080,
  10982. 0x14800: 0x20000000,
  10983. 0x15800: 0x1040080,
  10984. 0x16800: 0x80,
  10985. 0x17800: 0x21040000,
  10986. 0x18800: 0x40080,
  10987. 0x19800: 0x21040080,
  10988. 0x1a800: 0x0,
  10989. 0x1b800: 0x21000000,
  10990. 0x1c800: 0x1000080,
  10991. 0x1d800: 0x40000,
  10992. 0x1e800: 0x20040000,
  10993. 0x1f800: 0x20000080
  10994. },
  10995. {
  10996. 0x0: 0x10000008,
  10997. 0x100: 0x2000,
  10998. 0x200: 0x10200000,
  10999. 0x300: 0x10202008,
  11000. 0x400: 0x10002000,
  11001. 0x500: 0x200000,
  11002. 0x600: 0x200008,
  11003. 0x700: 0x10000000,
  11004. 0x800: 0x0,
  11005. 0x900: 0x10002008,
  11006. 0xa00: 0x202000,
  11007. 0xb00: 0x8,
  11008. 0xc00: 0x10200008,
  11009. 0xd00: 0x202008,
  11010. 0xe00: 0x2008,
  11011. 0xf00: 0x10202000,
  11012. 0x80: 0x10200000,
  11013. 0x180: 0x10202008,
  11014. 0x280: 0x8,
  11015. 0x380: 0x200000,
  11016. 0x480: 0x202008,
  11017. 0x580: 0x10000008,
  11018. 0x680: 0x10002000,
  11019. 0x780: 0x2008,
  11020. 0x880: 0x200008,
  11021. 0x980: 0x2000,
  11022. 0xa80: 0x10002008,
  11023. 0xb80: 0x10200008,
  11024. 0xc80: 0x0,
  11025. 0xd80: 0x10202000,
  11026. 0xe80: 0x202000,
  11027. 0xf80: 0x10000000,
  11028. 0x1000: 0x10002000,
  11029. 0x1100: 0x10200008,
  11030. 0x1200: 0x10202008,
  11031. 0x1300: 0x2008,
  11032. 0x1400: 0x200000,
  11033. 0x1500: 0x10000000,
  11034. 0x1600: 0x10000008,
  11035. 0x1700: 0x202000,
  11036. 0x1800: 0x202008,
  11037. 0x1900: 0x0,
  11038. 0x1a00: 0x8,
  11039. 0x1b00: 0x10200000,
  11040. 0x1c00: 0x2000,
  11041. 0x1d00: 0x10002008,
  11042. 0x1e00: 0x10202000,
  11043. 0x1f00: 0x200008,
  11044. 0x1080: 0x8,
  11045. 0x1180: 0x202000,
  11046. 0x1280: 0x200000,
  11047. 0x1380: 0x10000008,
  11048. 0x1480: 0x10002000,
  11049. 0x1580: 0x2008,
  11050. 0x1680: 0x10202008,
  11051. 0x1780: 0x10200000,
  11052. 0x1880: 0x10202000,
  11053. 0x1980: 0x10200008,
  11054. 0x1a80: 0x2000,
  11055. 0x1b80: 0x202008,
  11056. 0x1c80: 0x200008,
  11057. 0x1d80: 0x0,
  11058. 0x1e80: 0x10000000,
  11059. 0x1f80: 0x10002008
  11060. },
  11061. {
  11062. 0x0: 0x100000,
  11063. 0x10: 0x2000401,
  11064. 0x20: 0x400,
  11065. 0x30: 0x100401,
  11066. 0x40: 0x2100401,
  11067. 0x50: 0x0,
  11068. 0x60: 0x1,
  11069. 0x70: 0x2100001,
  11070. 0x80: 0x2000400,
  11071. 0x90: 0x100001,
  11072. 0xa0: 0x2000001,
  11073. 0xb0: 0x2100400,
  11074. 0xc0: 0x2100000,
  11075. 0xd0: 0x401,
  11076. 0xe0: 0x100400,
  11077. 0xf0: 0x2000000,
  11078. 0x8: 0x2100001,
  11079. 0x18: 0x0,
  11080. 0x28: 0x2000401,
  11081. 0x38: 0x2100400,
  11082. 0x48: 0x100000,
  11083. 0x58: 0x2000001,
  11084. 0x68: 0x2000000,
  11085. 0x78: 0x401,
  11086. 0x88: 0x100401,
  11087. 0x98: 0x2000400,
  11088. 0xa8: 0x2100000,
  11089. 0xb8: 0x100001,
  11090. 0xc8: 0x400,
  11091. 0xd8: 0x2100401,
  11092. 0xe8: 0x1,
  11093. 0xf8: 0x100400,
  11094. 0x100: 0x2000000,
  11095. 0x110: 0x100000,
  11096. 0x120: 0x2000401,
  11097. 0x130: 0x2100001,
  11098. 0x140: 0x100001,
  11099. 0x150: 0x2000400,
  11100. 0x160: 0x2100400,
  11101. 0x170: 0x100401,
  11102. 0x180: 0x401,
  11103. 0x190: 0x2100401,
  11104. 0x1a0: 0x100400,
  11105. 0x1b0: 0x1,
  11106. 0x1c0: 0x0,
  11107. 0x1d0: 0x2100000,
  11108. 0x1e0: 0x2000001,
  11109. 0x1f0: 0x400,
  11110. 0x108: 0x100400,
  11111. 0x118: 0x2000401,
  11112. 0x128: 0x2100001,
  11113. 0x138: 0x1,
  11114. 0x148: 0x2000000,
  11115. 0x158: 0x100000,
  11116. 0x168: 0x401,
  11117. 0x178: 0x2100400,
  11118. 0x188: 0x2000001,
  11119. 0x198: 0x2100000,
  11120. 0x1a8: 0x0,
  11121. 0x1b8: 0x2100401,
  11122. 0x1c8: 0x100401,
  11123. 0x1d8: 0x400,
  11124. 0x1e8: 0x2000400,
  11125. 0x1f8: 0x100001
  11126. },
  11127. {
  11128. 0x0: 0x8000820,
  11129. 0x1: 0x20000,
  11130. 0x2: 0x8000000,
  11131. 0x3: 0x20,
  11132. 0x4: 0x20020,
  11133. 0x5: 0x8020820,
  11134. 0x6: 0x8020800,
  11135. 0x7: 0x800,
  11136. 0x8: 0x8020000,
  11137. 0x9: 0x8000800,
  11138. 0xa: 0x20800,
  11139. 0xb: 0x8020020,
  11140. 0xc: 0x820,
  11141. 0xd: 0x0,
  11142. 0xe: 0x8000020,
  11143. 0xf: 0x20820,
  11144. 0x80000000: 0x800,
  11145. 0x80000001: 0x8020820,
  11146. 0x80000002: 0x8000820,
  11147. 0x80000003: 0x8000000,
  11148. 0x80000004: 0x8020000,
  11149. 0x80000005: 0x20800,
  11150. 0x80000006: 0x20820,
  11151. 0x80000007: 0x20,
  11152. 0x80000008: 0x8000020,
  11153. 0x80000009: 0x820,
  11154. 0x8000000a: 0x20020,
  11155. 0x8000000b: 0x8020800,
  11156. 0x8000000c: 0x0,
  11157. 0x8000000d: 0x8020020,
  11158. 0x8000000e: 0x8000800,
  11159. 0x8000000f: 0x20000,
  11160. 0x10: 0x20820,
  11161. 0x11: 0x8020800,
  11162. 0x12: 0x20,
  11163. 0x13: 0x800,
  11164. 0x14: 0x8000800,
  11165. 0x15: 0x8000020,
  11166. 0x16: 0x8020020,
  11167. 0x17: 0x20000,
  11168. 0x18: 0x0,
  11169. 0x19: 0x20020,
  11170. 0x1a: 0x8020000,
  11171. 0x1b: 0x8000820,
  11172. 0x1c: 0x8020820,
  11173. 0x1d: 0x20800,
  11174. 0x1e: 0x820,
  11175. 0x1f: 0x8000000,
  11176. 0x80000010: 0x20000,
  11177. 0x80000011: 0x800,
  11178. 0x80000012: 0x8020020,
  11179. 0x80000013: 0x20820,
  11180. 0x80000014: 0x20,
  11181. 0x80000015: 0x8020000,
  11182. 0x80000016: 0x8000000,
  11183. 0x80000017: 0x8000820,
  11184. 0x80000018: 0x8020820,
  11185. 0x80000019: 0x8000020,
  11186. 0x8000001a: 0x8000800,
  11187. 0x8000001b: 0x0,
  11188. 0x8000001c: 0x20800,
  11189. 0x8000001d: 0x820,
  11190. 0x8000001e: 0x20020,
  11191. 0x8000001f: 0x8020800
  11192. }
  11193. ];
  11194. // Masks that select the SBOX input
  11195. var SBOX_MASK = [
  11196. 0xf8000001, 0x1f800000, 0x01f80000, 0x001f8000,
  11197. 0x0001f800, 0x00001f80, 0x000001f8, 0x8000001f
  11198. ];
  11199. /**
  11200. * DES block cipher algorithm.
  11201. */
  11202. var DES = C_algo.DES = BlockCipher.extend({
  11203. _doReset: function () {
  11204. // Shortcuts
  11205. var key = this._key;
  11206. var keyWords = key.words;
  11207. // Select 56 bits according to PC1
  11208. var keyBits = [];
  11209. for (var i = 0; i < 56; i++) {
  11210. var keyBitPos = PC1[i] - 1;
  11211. keyBits[i] = (keyWords[keyBitPos >>> 5] >>> (31 - keyBitPos % 32)) & 1;
  11212. }
  11213. // Assemble 16 subkeys
  11214. var subKeys = this._subKeys = [];
  11215. for (var nSubKey = 0; nSubKey < 16; nSubKey++) {
  11216. // Create subkey
  11217. var subKey = subKeys[nSubKey] = [];
  11218. // Shortcut
  11219. var bitShift = BIT_SHIFTS[nSubKey];
  11220. // Select 48 bits according to PC2
  11221. for (var i = 0; i < 24; i++) {
  11222. // Select from the left 28 key bits
  11223. subKey[(i / 6) | 0] |= keyBits[((PC2[i] - 1) + bitShift) % 28] << (31 - i % 6);
  11224. // Select from the right 28 key bits
  11225. subKey[4 + ((i / 6) | 0)] |= keyBits[28 + (((PC2[i + 24] - 1) + bitShift) % 28)] << (31 - i % 6);
  11226. }
  11227. // Since each subkey is applied to an expanded 32-bit input,
  11228. // the subkey can be broken into 8 values scaled to 32-bits,
  11229. // which allows the key to be used without expansion
  11230. subKey[0] = (subKey[0] << 1) | (subKey[0] >>> 31);
  11231. for (var i = 1; i < 7; i++) {
  11232. subKey[i] = subKey[i] >>> ((i - 1) * 4 + 3);
  11233. }
  11234. subKey[7] = (subKey[7] << 5) | (subKey[7] >>> 27);
  11235. }
  11236. // Compute inverse subkeys
  11237. var invSubKeys = this._invSubKeys = [];
  11238. for (var i = 0; i < 16; i++) {
  11239. invSubKeys[i] = subKeys[15 - i];
  11240. }
  11241. },
  11242. encryptBlock: function (M, offset) {
  11243. this._doCryptBlock(M, offset, this._subKeys);
  11244. },
  11245. decryptBlock: function (M, offset) {
  11246. this._doCryptBlock(M, offset, this._invSubKeys);
  11247. },
  11248. _doCryptBlock: function (M, offset, subKeys) {
  11249. // Get input
  11250. this._lBlock = M[offset];
  11251. this._rBlock = M[offset + 1];
  11252. // Initial permutation
  11253. exchangeLR.call(this, 4, 0x0f0f0f0f);
  11254. exchangeLR.call(this, 16, 0x0000ffff);
  11255. exchangeRL.call(this, 2, 0x33333333);
  11256. exchangeRL.call(this, 8, 0x00ff00ff);
  11257. exchangeLR.call(this, 1, 0x55555555);
  11258. // Rounds
  11259. for (var round = 0; round < 16; round++) {
  11260. // Shortcuts
  11261. var subKey = subKeys[round];
  11262. var lBlock = this._lBlock;
  11263. var rBlock = this._rBlock;
  11264. // Feistel function
  11265. var f = 0;
  11266. for (var i = 0; i < 8; i++) {
  11267. f |= SBOX_P[i][((rBlock ^ subKey[i]) & SBOX_MASK[i]) >>> 0];
  11268. }
  11269. this._lBlock = rBlock;
  11270. this._rBlock = lBlock ^ f;
  11271. }
  11272. // Undo swap from last round
  11273. var t = this._lBlock;
  11274. this._lBlock = this._rBlock;
  11275. this._rBlock = t;
  11276. // Final permutation
  11277. exchangeLR.call(this, 1, 0x55555555);
  11278. exchangeRL.call(this, 8, 0x00ff00ff);
  11279. exchangeRL.call(this, 2, 0x33333333);
  11280. exchangeLR.call(this, 16, 0x0000ffff);
  11281. exchangeLR.call(this, 4, 0x0f0f0f0f);
  11282. // Set output
  11283. M[offset] = this._lBlock;
  11284. M[offset + 1] = this._rBlock;
  11285. },
  11286. keySize: 64/32,
  11287. ivSize: 64/32,
  11288. blockSize: 64/32
  11289. });
  11290. // Swap bits across the left and right words
  11291. function exchangeLR(offset, mask) {
  11292. var t = ((this._lBlock >>> offset) ^ this._rBlock) & mask;
  11293. this._rBlock ^= t;
  11294. this._lBlock ^= t << offset;
  11295. }
  11296. function exchangeRL(offset, mask) {
  11297. var t = ((this._rBlock >>> offset) ^ this._lBlock) & mask;
  11298. this._lBlock ^= t;
  11299. this._rBlock ^= t << offset;
  11300. }
  11301. /**
  11302. * Shortcut functions to the cipher's object interface.
  11303. *
  11304. * @example
  11305. *
  11306. * var ciphertext = CryptoJS.DES.encrypt(message, key, cfg);
  11307. * var plaintext = CryptoJS.DES.decrypt(ciphertext, key, cfg);
  11308. */
  11309. C.DES = BlockCipher._createHelper(DES);
  11310. /**
  11311. * Triple-DES block cipher algorithm.
  11312. */
  11313. var TripleDES = C_algo.TripleDES = BlockCipher.extend({
  11314. _doReset: function () {
  11315. // Shortcuts
  11316. var key = this._key;
  11317. var keyWords = key.words;
  11318. // Create DES instances
  11319. this._des1 = DES.createEncryptor(WordArray.create(keyWords.slice(0, 2)));
  11320. this._des2 = DES.createEncryptor(WordArray.create(keyWords.slice(2, 4)));
  11321. this._des3 = DES.createEncryptor(WordArray.create(keyWords.slice(4, 6)));
  11322. },
  11323. encryptBlock: function (M, offset) {
  11324. this._des1.encryptBlock(M, offset);
  11325. this._des2.decryptBlock(M, offset);
  11326. this._des3.encryptBlock(M, offset);
  11327. },
  11328. decryptBlock: function (M, offset) {
  11329. this._des3.decryptBlock(M, offset);
  11330. this._des2.encryptBlock(M, offset);
  11331. this._des1.decryptBlock(M, offset);
  11332. },
  11333. keySize: 192/32,
  11334. ivSize: 64/32,
  11335. blockSize: 64/32
  11336. });
  11337. /**
  11338. * Shortcut functions to the cipher's object interface.
  11339. *
  11340. * @example
  11341. *
  11342. * var ciphertext = CryptoJS.TripleDES.encrypt(message, key, cfg);
  11343. * var plaintext = CryptoJS.TripleDES.decrypt(ciphertext, key, cfg);
  11344. */
  11345. C.TripleDES = BlockCipher._createHelper(TripleDES);
  11346. }());
  11347. return CryptoJS.TripleDES;
  11348. }));
  11349. },{"./cipher-core":52,"./core":53,"./enc-base64":54,"./evpkdf":56,"./md5":61}],84:[function(require,module,exports){
  11350. ;(function (root, factory) {
  11351. if (typeof exports === "object") {
  11352. // CommonJS
  11353. module.exports = exports = factory(require("./core"));
  11354. }
  11355. else if (typeof define === "function" && define.amd) {
  11356. // AMD
  11357. define(["./core"], factory);
  11358. }
  11359. else {
  11360. // Global (browser)
  11361. factory(root.CryptoJS);
  11362. }
  11363. }(this, function (CryptoJS) {
  11364. (function (undefined) {
  11365. // Shortcuts
  11366. var C = CryptoJS;
  11367. var C_lib = C.lib;
  11368. var Base = C_lib.Base;
  11369. var X32WordArray = C_lib.WordArray;
  11370. /**
  11371. * x64 namespace.
  11372. */
  11373. var C_x64 = C.x64 = {};
  11374. /**
  11375. * A 64-bit word.
  11376. */
  11377. var X64Word = C_x64.Word = Base.extend({
  11378. /**
  11379. * Initializes a newly created 64-bit word.
  11380. *
  11381. * @param {number} high The high 32 bits.
  11382. * @param {number} low The low 32 bits.
  11383. *
  11384. * @example
  11385. *
  11386. * var x64Word = CryptoJS.x64.Word.create(0x00010203, 0x04050607);
  11387. */
  11388. init: function (high, low) {
  11389. this.high = high;
  11390. this.low = low;
  11391. }
  11392. /**
  11393. * Bitwise NOTs this word.
  11394. *
  11395. * @return {X64Word} A new x64-Word object after negating.
  11396. *
  11397. * @example
  11398. *
  11399. * var negated = x64Word.not();
  11400. */
  11401. // not: function () {
  11402. // var high = ~this.high;
  11403. // var low = ~this.low;
  11404. // return X64Word.create(high, low);
  11405. // },
  11406. /**
  11407. * Bitwise ANDs this word with the passed word.
  11408. *
  11409. * @param {X64Word} word The x64-Word to AND with this word.
  11410. *
  11411. * @return {X64Word} A new x64-Word object after ANDing.
  11412. *
  11413. * @example
  11414. *
  11415. * var anded = x64Word.and(anotherX64Word);
  11416. */
  11417. // and: function (word) {
  11418. // var high = this.high & word.high;
  11419. // var low = this.low & word.low;
  11420. // return X64Word.create(high, low);
  11421. // },
  11422. /**
  11423. * Bitwise ORs this word with the passed word.
  11424. *
  11425. * @param {X64Word} word The x64-Word to OR with this word.
  11426. *
  11427. * @return {X64Word} A new x64-Word object after ORing.
  11428. *
  11429. * @example
  11430. *
  11431. * var ored = x64Word.or(anotherX64Word);
  11432. */
  11433. // or: function (word) {
  11434. // var high = this.high | word.high;
  11435. // var low = this.low | word.low;
  11436. // return X64Word.create(high, low);
  11437. // },
  11438. /**
  11439. * Bitwise XORs this word with the passed word.
  11440. *
  11441. * @param {X64Word} word The x64-Word to XOR with this word.
  11442. *
  11443. * @return {X64Word} A new x64-Word object after XORing.
  11444. *
  11445. * @example
  11446. *
  11447. * var xored = x64Word.xor(anotherX64Word);
  11448. */
  11449. // xor: function (word) {
  11450. // var high = this.high ^ word.high;
  11451. // var low = this.low ^ word.low;
  11452. // return X64Word.create(high, low);
  11453. // },
  11454. /**
  11455. * Shifts this word n bits to the left.
  11456. *
  11457. * @param {number} n The number of bits to shift.
  11458. *
  11459. * @return {X64Word} A new x64-Word object after shifting.
  11460. *
  11461. * @example
  11462. *
  11463. * var shifted = x64Word.shiftL(25);
  11464. */
  11465. // shiftL: function (n) {
  11466. // if (n < 32) {
  11467. // var high = (this.high << n) | (this.low >>> (32 - n));
  11468. // var low = this.low << n;
  11469. // } else {
  11470. // var high = this.low << (n - 32);
  11471. // var low = 0;
  11472. // }
  11473. // return X64Word.create(high, low);
  11474. // },
  11475. /**
  11476. * Shifts this word n bits to the right.
  11477. *
  11478. * @param {number} n The number of bits to shift.
  11479. *
  11480. * @return {X64Word} A new x64-Word object after shifting.
  11481. *
  11482. * @example
  11483. *
  11484. * var shifted = x64Word.shiftR(7);
  11485. */
  11486. // shiftR: function (n) {
  11487. // if (n < 32) {
  11488. // var low = (this.low >>> n) | (this.high << (32 - n));
  11489. // var high = this.high >>> n;
  11490. // } else {
  11491. // var low = this.high >>> (n - 32);
  11492. // var high = 0;
  11493. // }
  11494. // return X64Word.create(high, low);
  11495. // },
  11496. /**
  11497. * Rotates this word n bits to the left.
  11498. *
  11499. * @param {number} n The number of bits to rotate.
  11500. *
  11501. * @return {X64Word} A new x64-Word object after rotating.
  11502. *
  11503. * @example
  11504. *
  11505. * var rotated = x64Word.rotL(25);
  11506. */
  11507. // rotL: function (n) {
  11508. // return this.shiftL(n).or(this.shiftR(64 - n));
  11509. // },
  11510. /**
  11511. * Rotates this word n bits to the right.
  11512. *
  11513. * @param {number} n The number of bits to rotate.
  11514. *
  11515. * @return {X64Word} A new x64-Word object after rotating.
  11516. *
  11517. * @example
  11518. *
  11519. * var rotated = x64Word.rotR(7);
  11520. */
  11521. // rotR: function (n) {
  11522. // return this.shiftR(n).or(this.shiftL(64 - n));
  11523. // },
  11524. /**
  11525. * Adds this word with the passed word.
  11526. *
  11527. * @param {X64Word} word The x64-Word to add with this word.
  11528. *
  11529. * @return {X64Word} A new x64-Word object after adding.
  11530. *
  11531. * @example
  11532. *
  11533. * var added = x64Word.add(anotherX64Word);
  11534. */
  11535. // add: function (word) {
  11536. // var low = (this.low + word.low) | 0;
  11537. // var carry = (low >>> 0) < (this.low >>> 0) ? 1 : 0;
  11538. // var high = (this.high + word.high + carry) | 0;
  11539. // return X64Word.create(high, low);
  11540. // }
  11541. });
  11542. /**
  11543. * An array of 64-bit words.
  11544. *
  11545. * @property {Array} words The array of CryptoJS.x64.Word objects.
  11546. * @property {number} sigBytes The number of significant bytes in this word array.
  11547. */
  11548. var X64WordArray = C_x64.WordArray = Base.extend({
  11549. /**
  11550. * Initializes a newly created word array.
  11551. *
  11552. * @param {Array} words (Optional) An array of CryptoJS.x64.Word objects.
  11553. * @param {number} sigBytes (Optional) The number of significant bytes in the words.
  11554. *
  11555. * @example
  11556. *
  11557. * var wordArray = CryptoJS.x64.WordArray.create();
  11558. *
  11559. * var wordArray = CryptoJS.x64.WordArray.create([
  11560. * CryptoJS.x64.Word.create(0x00010203, 0x04050607),
  11561. * CryptoJS.x64.Word.create(0x18191a1b, 0x1c1d1e1f)
  11562. * ]);
  11563. *
  11564. * var wordArray = CryptoJS.x64.WordArray.create([
  11565. * CryptoJS.x64.Word.create(0x00010203, 0x04050607),
  11566. * CryptoJS.x64.Word.create(0x18191a1b, 0x1c1d1e1f)
  11567. * ], 10);
  11568. */
  11569. init: function (words, sigBytes) {
  11570. words = this.words = words || [];
  11571. if (sigBytes != undefined) {
  11572. this.sigBytes = sigBytes;
  11573. } else {
  11574. this.sigBytes = words.length * 8;
  11575. }
  11576. },
  11577. /**
  11578. * Converts this 64-bit word array to a 32-bit word array.
  11579. *
  11580. * @return {CryptoJS.lib.WordArray} This word array's data as a 32-bit word array.
  11581. *
  11582. * @example
  11583. *
  11584. * var x32WordArray = x64WordArray.toX32();
  11585. */
  11586. toX32: function () {
  11587. // Shortcuts
  11588. var x64Words = this.words;
  11589. var x64WordsLength = x64Words.length;
  11590. // Convert
  11591. var x32Words = [];
  11592. for (var i = 0; i < x64WordsLength; i++) {
  11593. var x64Word = x64Words[i];
  11594. x32Words.push(x64Word.high);
  11595. x32Words.push(x64Word.low);
  11596. }
  11597. return X32WordArray.create(x32Words, this.sigBytes);
  11598. },
  11599. /**
  11600. * Creates a copy of this word array.
  11601. *
  11602. * @return {X64WordArray} The clone.
  11603. *
  11604. * @example
  11605. *
  11606. * var clone = x64WordArray.clone();
  11607. */
  11608. clone: function () {
  11609. var clone = Base.clone.call(this);
  11610. // Clone "words" array
  11611. var words = clone.words = this.words.slice(0);
  11612. // Clone each X64Word object
  11613. var wordsLength = words.length;
  11614. for (var i = 0; i < wordsLength; i++) {
  11615. words[i] = words[i].clone();
  11616. }
  11617. return clone;
  11618. }
  11619. });
  11620. }());
  11621. return CryptoJS;
  11622. }));
  11623. },{"./core":53}],85:[function(require,module,exports){
  11624. /*! https://mths.be/utf8js v2.1.2 by @mathias */
  11625. ;(function(root) {
  11626. // Detect free variables `exports`
  11627. var freeExports = typeof exports == 'object' && exports;
  11628. // Detect free variable `module`
  11629. var freeModule = typeof module == 'object' && module &&
  11630. module.exports == freeExports && module;
  11631. // Detect free variable `global`, from Node.js or Browserified code,
  11632. // and use it as `root`
  11633. var freeGlobal = typeof global == 'object' && global;
  11634. if (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal) {
  11635. root = freeGlobal;
  11636. }
  11637. /*--------------------------------------------------------------------------*/
  11638. var stringFromCharCode = String.fromCharCode;
  11639. // Taken from https://mths.be/punycode
  11640. function ucs2decode(string) {
  11641. var output = [];
  11642. var counter = 0;
  11643. var length = string.length;
  11644. var value;
  11645. var extra;
  11646. while (counter < length) {
  11647. value = string.charCodeAt(counter++);
  11648. if (value >= 0xD800 && value <= 0xDBFF && counter < length) {
  11649. // high surrogate, and there is a next character
  11650. extra = string.charCodeAt(counter++);
  11651. if ((extra & 0xFC00) == 0xDC00) { // low surrogate
  11652. output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000);
  11653. } else {
  11654. // unmatched surrogate; only append this code unit, in case the next
  11655. // code unit is the high surrogate of a surrogate pair
  11656. output.push(value);
  11657. counter--;
  11658. }
  11659. } else {
  11660. output.push(value);
  11661. }
  11662. }
  11663. return output;
  11664. }
  11665. // Taken from https://mths.be/punycode
  11666. function ucs2encode(array) {
  11667. var length = array.length;
  11668. var index = -1;
  11669. var value;
  11670. var output = '';
  11671. while (++index < length) {
  11672. value = array[index];
  11673. if (value > 0xFFFF) {
  11674. value -= 0x10000;
  11675. output += stringFromCharCode(value >>> 10 & 0x3FF | 0xD800);
  11676. value = 0xDC00 | value & 0x3FF;
  11677. }
  11678. output += stringFromCharCode(value);
  11679. }
  11680. return output;
  11681. }
  11682. function checkScalarValue(codePoint) {
  11683. if (codePoint >= 0xD800 && codePoint <= 0xDFFF) {
  11684. throw Error(
  11685. 'Lone surrogate U+' + codePoint.toString(16).toUpperCase() +
  11686. ' is not a scalar value'
  11687. );
  11688. }
  11689. }
  11690. /*--------------------------------------------------------------------------*/
  11691. function createByte(codePoint, shift) {
  11692. return stringFromCharCode(((codePoint >> shift) & 0x3F) | 0x80);
  11693. }
  11694. function encodeCodePoint(codePoint) {
  11695. if ((codePoint & 0xFFFFFF80) == 0) { // 1-byte sequence
  11696. return stringFromCharCode(codePoint);
  11697. }
  11698. var symbol = '';
  11699. if ((codePoint & 0xFFFFF800) == 0) { // 2-byte sequence
  11700. symbol = stringFromCharCode(((codePoint >> 6) & 0x1F) | 0xC0);
  11701. }
  11702. else if ((codePoint & 0xFFFF0000) == 0) { // 3-byte sequence
  11703. checkScalarValue(codePoint);
  11704. symbol = stringFromCharCode(((codePoint >> 12) & 0x0F) | 0xE0);
  11705. symbol += createByte(codePoint, 6);
  11706. }
  11707. else if ((codePoint & 0xFFE00000) == 0) { // 4-byte sequence
  11708. symbol = stringFromCharCode(((codePoint >> 18) & 0x07) | 0xF0);
  11709. symbol += createByte(codePoint, 12);
  11710. symbol += createByte(codePoint, 6);
  11711. }
  11712. symbol += stringFromCharCode((codePoint & 0x3F) | 0x80);
  11713. return symbol;
  11714. }
  11715. function utf8encode(string) {
  11716. var codePoints = ucs2decode(string);
  11717. var length = codePoints.length;
  11718. var index = -1;
  11719. var codePoint;
  11720. var byteString = '';
  11721. while (++index < length) {
  11722. codePoint = codePoints[index];
  11723. byteString += encodeCodePoint(codePoint);
  11724. }
  11725. return byteString;
  11726. }
  11727. /*--------------------------------------------------------------------------*/
  11728. function readContinuationByte() {
  11729. if (byteIndex >= byteCount) {
  11730. throw Error('Invalid byte index');
  11731. }
  11732. var continuationByte = byteArray[byteIndex] & 0xFF;
  11733. byteIndex++;
  11734. if ((continuationByte & 0xC0) == 0x80) {
  11735. return continuationByte & 0x3F;
  11736. }
  11737. // If we end up here, it’s not a continuation byte
  11738. throw Error('Invalid continuation byte');
  11739. }
  11740. function decodeSymbol() {
  11741. var byte1;
  11742. var byte2;
  11743. var byte3;
  11744. var byte4;
  11745. var codePoint;
  11746. if (byteIndex > byteCount) {
  11747. throw Error('Invalid byte index');
  11748. }
  11749. if (byteIndex == byteCount) {
  11750. return false;
  11751. }
  11752. // Read first byte
  11753. byte1 = byteArray[byteIndex] & 0xFF;
  11754. byteIndex++;
  11755. // 1-byte sequence (no continuation bytes)
  11756. if ((byte1 & 0x80) == 0) {
  11757. return byte1;
  11758. }
  11759. // 2-byte sequence
  11760. if ((byte1 & 0xE0) == 0xC0) {
  11761. byte2 = readContinuationByte();
  11762. codePoint = ((byte1 & 0x1F) << 6) | byte2;
  11763. if (codePoint >= 0x80) {
  11764. return codePoint;
  11765. } else {
  11766. throw Error('Invalid continuation byte');
  11767. }
  11768. }
  11769. // 3-byte sequence (may include unpaired surrogates)
  11770. if ((byte1 & 0xF0) == 0xE0) {
  11771. byte2 = readContinuationByte();
  11772. byte3 = readContinuationByte();
  11773. codePoint = ((byte1 & 0x0F) << 12) | (byte2 << 6) | byte3;
  11774. if (codePoint >= 0x0800) {
  11775. checkScalarValue(codePoint);
  11776. return codePoint;
  11777. } else {
  11778. throw Error('Invalid continuation byte');
  11779. }
  11780. }
  11781. // 4-byte sequence
  11782. if ((byte1 & 0xF8) == 0xF0) {
  11783. byte2 = readContinuationByte();
  11784. byte3 = readContinuationByte();
  11785. byte4 = readContinuationByte();
  11786. codePoint = ((byte1 & 0x07) << 0x12) | (byte2 << 0x0C) |
  11787. (byte3 << 0x06) | byte4;
  11788. if (codePoint >= 0x010000 && codePoint <= 0x10FFFF) {
  11789. return codePoint;
  11790. }
  11791. }
  11792. throw Error('Invalid UTF-8 detected');
  11793. }
  11794. var byteArray;
  11795. var byteCount;
  11796. var byteIndex;
  11797. function utf8decode(byteString) {
  11798. byteArray = ucs2decode(byteString);
  11799. byteCount = byteArray.length;
  11800. byteIndex = 0;
  11801. var codePoints = [];
  11802. var tmp;
  11803. while ((tmp = decodeSymbol()) !== false) {
  11804. codePoints.push(tmp);
  11805. }
  11806. return ucs2encode(codePoints);
  11807. }
  11808. /*--------------------------------------------------------------------------*/
  11809. var utf8 = {
  11810. 'version': '2.1.2',
  11811. 'encode': utf8encode,
  11812. 'decode': utf8decode
  11813. };
  11814. // Some AMD build optimizers, like r.js, check for specific condition patterns
  11815. // like the following:
  11816. if (
  11817. typeof define == 'function' &&
  11818. typeof define.amd == 'object' &&
  11819. define.amd
  11820. ) {
  11821. define(function() {
  11822. return utf8;
  11823. });
  11824. } else if (freeExports && !freeExports.nodeType) {
  11825. if (freeModule) { // in Node.js or RingoJS v0.8.0+
  11826. freeModule.exports = utf8;
  11827. } else { // in Narwhal or RingoJS v0.7.0-
  11828. var object = {};
  11829. var hasOwnProperty = object.hasOwnProperty;
  11830. for (var key in utf8) {
  11831. hasOwnProperty.call(utf8, key) && (freeExports[key] = utf8[key]);
  11832. }
  11833. }
  11834. } else { // in Rhino or a web browser
  11835. root.utf8 = utf8;
  11836. }
  11837. }(this));
  11838. },{}],86:[function(require,module,exports){
  11839. module.exports = XMLHttpRequest;
  11840. },{}],"bignumber.js":[function(require,module,exports){
  11841. 'use strict';
  11842. module.exports = BigNumber; // jshint ignore:line
  11843. },{}],"web3":[function(require,module,exports){
  11844. var Web3 = require('./lib/web3');
  11845. // don't override global variable
  11846. if (typeof window !== 'undefined' && typeof window.Web3 === 'undefined') {
  11847. window.Web3 = Web3;
  11848. }
  11849. module.exports = Web3;
  11850. },{"./lib/web3":22}]},{},["web3"])