web3.js 392 KB

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