ethereum_js.go 378 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109
  1. // Copyright 2015 The go-ethereum Authors
  2. // This file is part of the go-ethereum library.
  3. //
  4. // The go-ethereum library is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Lesser General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // The go-ethereum library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Lesser General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Lesser General Public License
  15. // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
  16. package jsre
  17. const Web3_JS = `
  18. 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){
  19. module.exports=[
  20. {
  21. "constant": true,
  22. "inputs": [
  23. {
  24. "name": "_owner",
  25. "type": "address"
  26. }
  27. ],
  28. "name": "name",
  29. "outputs": [
  30. {
  31. "name": "o_name",
  32. "type": "bytes32"
  33. }
  34. ],
  35. "type": "function"
  36. },
  37. {
  38. "constant": true,
  39. "inputs": [
  40. {
  41. "name": "_name",
  42. "type": "bytes32"
  43. }
  44. ],
  45. "name": "owner",
  46. "outputs": [
  47. {
  48. "name": "",
  49. "type": "address"
  50. }
  51. ],
  52. "type": "function"
  53. },
  54. {
  55. "constant": true,
  56. "inputs": [
  57. {
  58. "name": "_name",
  59. "type": "bytes32"
  60. }
  61. ],
  62. "name": "content",
  63. "outputs": [
  64. {
  65. "name": "",
  66. "type": "bytes32"
  67. }
  68. ],
  69. "type": "function"
  70. },
  71. {
  72. "constant": true,
  73. "inputs": [
  74. {
  75. "name": "_name",
  76. "type": "bytes32"
  77. }
  78. ],
  79. "name": "addr",
  80. "outputs": [
  81. {
  82. "name": "",
  83. "type": "address"
  84. }
  85. ],
  86. "type": "function"
  87. },
  88. {
  89. "constant": false,
  90. "inputs": [
  91. {
  92. "name": "_name",
  93. "type": "bytes32"
  94. }
  95. ],
  96. "name": "reserve",
  97. "outputs": [],
  98. "type": "function"
  99. },
  100. {
  101. "constant": true,
  102. "inputs": [
  103. {
  104. "name": "_name",
  105. "type": "bytes32"
  106. }
  107. ],
  108. "name": "subRegistrar",
  109. "outputs": [
  110. {
  111. "name": "",
  112. "type": "address"
  113. }
  114. ],
  115. "type": "function"
  116. },
  117. {
  118. "constant": false,
  119. "inputs": [
  120. {
  121. "name": "_name",
  122. "type": "bytes32"
  123. },
  124. {
  125. "name": "_newOwner",
  126. "type": "address"
  127. }
  128. ],
  129. "name": "transfer",
  130. "outputs": [],
  131. "type": "function"
  132. },
  133. {
  134. "constant": false,
  135. "inputs": [
  136. {
  137. "name": "_name",
  138. "type": "bytes32"
  139. },
  140. {
  141. "name": "_registrar",
  142. "type": "address"
  143. }
  144. ],
  145. "name": "setSubRegistrar",
  146. "outputs": [],
  147. "type": "function"
  148. },
  149. {
  150. "constant": false,
  151. "inputs": [],
  152. "name": "Registrar",
  153. "outputs": [],
  154. "type": "function"
  155. },
  156. {
  157. "constant": false,
  158. "inputs": [
  159. {
  160. "name": "_name",
  161. "type": "bytes32"
  162. },
  163. {
  164. "name": "_a",
  165. "type": "address"
  166. },
  167. {
  168. "name": "_primary",
  169. "type": "bool"
  170. }
  171. ],
  172. "name": "setAddress",
  173. "outputs": [],
  174. "type": "function"
  175. },
  176. {
  177. "constant": false,
  178. "inputs": [
  179. {
  180. "name": "_name",
  181. "type": "bytes32"
  182. },
  183. {
  184. "name": "_content",
  185. "type": "bytes32"
  186. }
  187. ],
  188. "name": "setContent",
  189. "outputs": [],
  190. "type": "function"
  191. },
  192. {
  193. "constant": false,
  194. "inputs": [
  195. {
  196. "name": "_name",
  197. "type": "bytes32"
  198. }
  199. ],
  200. "name": "disown",
  201. "outputs": [],
  202. "type": "function"
  203. },
  204. {
  205. "anonymous": false,
  206. "inputs": [
  207. {
  208. "indexed": true,
  209. "name": "_name",
  210. "type": "bytes32"
  211. },
  212. {
  213. "indexed": false,
  214. "name": "_winner",
  215. "type": "address"
  216. }
  217. ],
  218. "name": "AuctionEnded",
  219. "type": "event"
  220. },
  221. {
  222. "anonymous": false,
  223. "inputs": [
  224. {
  225. "indexed": true,
  226. "name": "_name",
  227. "type": "bytes32"
  228. },
  229. {
  230. "indexed": false,
  231. "name": "_bidder",
  232. "type": "address"
  233. },
  234. {
  235. "indexed": false,
  236. "name": "_value",
  237. "type": "uint256"
  238. }
  239. ],
  240. "name": "NewBid",
  241. "type": "event"
  242. },
  243. {
  244. "anonymous": false,
  245. "inputs": [
  246. {
  247. "indexed": true,
  248. "name": "name",
  249. "type": "bytes32"
  250. }
  251. ],
  252. "name": "Changed",
  253. "type": "event"
  254. },
  255. {
  256. "anonymous": false,
  257. "inputs": [
  258. {
  259. "indexed": true,
  260. "name": "name",
  261. "type": "bytes32"
  262. },
  263. {
  264. "indexed": true,
  265. "name": "addr",
  266. "type": "address"
  267. }
  268. ],
  269. "name": "PrimaryChanged",
  270. "type": "event"
  271. }
  272. ]
  273. },{}],2:[function(require,module,exports){
  274. module.exports=[
  275. {
  276. "constant": true,
  277. "inputs": [
  278. {
  279. "name": "_name",
  280. "type": "bytes32"
  281. }
  282. ],
  283. "name": "owner",
  284. "outputs": [
  285. {
  286. "name": "",
  287. "type": "address"
  288. }
  289. ],
  290. "type": "function"
  291. },
  292. {
  293. "constant": false,
  294. "inputs": [
  295. {
  296. "name": "_name",
  297. "type": "bytes32"
  298. },
  299. {
  300. "name": "_refund",
  301. "type": "address"
  302. }
  303. ],
  304. "name": "disown",
  305. "outputs": [],
  306. "type": "function"
  307. },
  308. {
  309. "constant": true,
  310. "inputs": [
  311. {
  312. "name": "_name",
  313. "type": "bytes32"
  314. }
  315. ],
  316. "name": "addr",
  317. "outputs": [
  318. {
  319. "name": "",
  320. "type": "address"
  321. }
  322. ],
  323. "type": "function"
  324. },
  325. {
  326. "constant": false,
  327. "inputs": [
  328. {
  329. "name": "_name",
  330. "type": "bytes32"
  331. }
  332. ],
  333. "name": "reserve",
  334. "outputs": [],
  335. "type": "function"
  336. },
  337. {
  338. "constant": false,
  339. "inputs": [
  340. {
  341. "name": "_name",
  342. "type": "bytes32"
  343. },
  344. {
  345. "name": "_newOwner",
  346. "type": "address"
  347. }
  348. ],
  349. "name": "transfer",
  350. "outputs": [],
  351. "type": "function"
  352. },
  353. {
  354. "constant": false,
  355. "inputs": [
  356. {
  357. "name": "_name",
  358. "type": "bytes32"
  359. },
  360. {
  361. "name": "_a",
  362. "type": "address"
  363. }
  364. ],
  365. "name": "setAddr",
  366. "outputs": [],
  367. "type": "function"
  368. },
  369. {
  370. "anonymous": false,
  371. "inputs": [
  372. {
  373. "indexed": true,
  374. "name": "name",
  375. "type": "bytes32"
  376. }
  377. ],
  378. "name": "Changed",
  379. "type": "event"
  380. }
  381. ]
  382. },{}],3:[function(require,module,exports){
  383. module.exports=[
  384. {
  385. "constant": false,
  386. "inputs": [
  387. {
  388. "name": "from",
  389. "type": "bytes32"
  390. },
  391. {
  392. "name": "to",
  393. "type": "address"
  394. },
  395. {
  396. "name": "value",
  397. "type": "uint256"
  398. }
  399. ],
  400. "name": "transfer",
  401. "outputs": [],
  402. "type": "function"
  403. },
  404. {
  405. "constant": false,
  406. "inputs": [
  407. {
  408. "name": "from",
  409. "type": "bytes32"
  410. },
  411. {
  412. "name": "to",
  413. "type": "address"
  414. },
  415. {
  416. "name": "indirectId",
  417. "type": "bytes32"
  418. },
  419. {
  420. "name": "value",
  421. "type": "uint256"
  422. }
  423. ],
  424. "name": "icapTransfer",
  425. "outputs": [],
  426. "type": "function"
  427. },
  428. {
  429. "constant": false,
  430. "inputs": [
  431. {
  432. "name": "to",
  433. "type": "bytes32"
  434. }
  435. ],
  436. "name": "deposit",
  437. "outputs": [],
  438. "type": "function"
  439. },
  440. {
  441. "anonymous": false,
  442. "inputs": [
  443. {
  444. "indexed": true,
  445. "name": "from",
  446. "type": "address"
  447. },
  448. {
  449. "indexed": false,
  450. "name": "value",
  451. "type": "uint256"
  452. }
  453. ],
  454. "name": "AnonymousDeposit",
  455. "type": "event"
  456. },
  457. {
  458. "anonymous": false,
  459. "inputs": [
  460. {
  461. "indexed": true,
  462. "name": "from",
  463. "type": "address"
  464. },
  465. {
  466. "indexed": true,
  467. "name": "to",
  468. "type": "bytes32"
  469. },
  470. {
  471. "indexed": false,
  472. "name": "value",
  473. "type": "uint256"
  474. }
  475. ],
  476. "name": "Deposit",
  477. "type": "event"
  478. },
  479. {
  480. "anonymous": false,
  481. "inputs": [
  482. {
  483. "indexed": true,
  484. "name": "from",
  485. "type": "bytes32"
  486. },
  487. {
  488. "indexed": true,
  489. "name": "to",
  490. "type": "address"
  491. },
  492. {
  493. "indexed": false,
  494. "name": "value",
  495. "type": "uint256"
  496. }
  497. ],
  498. "name": "Transfer",
  499. "type": "event"
  500. },
  501. {
  502. "anonymous": false,
  503. "inputs": [
  504. {
  505. "indexed": true,
  506. "name": "from",
  507. "type": "bytes32"
  508. },
  509. {
  510. "indexed": true,
  511. "name": "to",
  512. "type": "address"
  513. },
  514. {
  515. "indexed": false,
  516. "name": "indirectId",
  517. "type": "bytes32"
  518. },
  519. {
  520. "indexed": false,
  521. "name": "value",
  522. "type": "uint256"
  523. }
  524. ],
  525. "name": "IcapTransfer",
  526. "type": "event"
  527. }
  528. ]
  529. },{}],4:[function(require,module,exports){
  530. var f = require('./formatters');
  531. var SolidityType = require('./type');
  532. /**
  533. * SolidityTypeAddress is a prootype that represents address type
  534. * It matches:
  535. * address
  536. * address[]
  537. * address[4]
  538. * address[][]
  539. * address[3][]
  540. * address[][6][], ...
  541. */
  542. var SolidityTypeAddress = function () {
  543. this._inputFormatter = f.formatInputInt;
  544. this._outputFormatter = f.formatOutputAddress;
  545. };
  546. SolidityTypeAddress.prototype = new SolidityType({});
  547. SolidityTypeAddress.prototype.constructor = SolidityTypeAddress;
  548. SolidityTypeAddress.prototype.isType = function (name) {
  549. return !!name.match(/address(\[([0-9]*)\])?/);
  550. };
  551. SolidityTypeAddress.prototype.staticPartLength = function (name) {
  552. return 32 * this.staticArrayLength(name);
  553. };
  554. module.exports = SolidityTypeAddress;
  555. },{"./formatters":9,"./type":14}],5:[function(require,module,exports){
  556. var f = require('./formatters');
  557. var SolidityType = require('./type');
  558. /**
  559. * SolidityTypeBool is a prootype that represents bool type
  560. * It matches:
  561. * bool
  562. * bool[]
  563. * bool[4]
  564. * bool[][]
  565. * bool[3][]
  566. * bool[][6][], ...
  567. */
  568. var SolidityTypeBool = function () {
  569. this._inputFormatter = f.formatInputBool;
  570. this._outputFormatter = f.formatOutputBool;
  571. };
  572. SolidityTypeBool.prototype = new SolidityType({});
  573. SolidityTypeBool.prototype.constructor = SolidityTypeBool;
  574. SolidityTypeBool.prototype.isType = function (name) {
  575. return !!name.match(/^bool(\[([0-9]*)\])*$/);
  576. };
  577. SolidityTypeBool.prototype.staticPartLength = function (name) {
  578. return 32 * this.staticArrayLength(name);
  579. };
  580. module.exports = SolidityTypeBool;
  581. },{"./formatters":9,"./type":14}],6:[function(require,module,exports){
  582. var f = require('./formatters');
  583. var SolidityType = require('./type');
  584. /**
  585. * SolidityTypeBytes is a prootype that represents bytes type
  586. * It matches:
  587. * bytes
  588. * bytes[]
  589. * bytes[4]
  590. * bytes[][]
  591. * bytes[3][]
  592. * bytes[][6][], ...
  593. * bytes32
  594. * bytes64[]
  595. * bytes8[4]
  596. * bytes256[][]
  597. * bytes[3][]
  598. * bytes64[][6][], ...
  599. */
  600. var SolidityTypeBytes = function () {
  601. this._inputFormatter = f.formatInputBytes;
  602. this._outputFormatter = f.formatOutputBytes;
  603. };
  604. SolidityTypeBytes.prototype = new SolidityType({});
  605. SolidityTypeBytes.prototype.constructor = SolidityTypeBytes;
  606. SolidityTypeBytes.prototype.isType = function (name) {
  607. return !!name.match(/^bytes([0-9]{1,})(\[([0-9]*)\])*$/);
  608. };
  609. SolidityTypeBytes.prototype.staticPartLength = function (name) {
  610. var matches = name.match(/^bytes([0-9]*)/);
  611. var size = parseInt(matches[1]);
  612. return size * this.staticArrayLength(name);
  613. };
  614. module.exports = SolidityTypeBytes;
  615. },{"./formatters":9,"./type":14}],7:[function(require,module,exports){
  616. /*
  617. This file is part of web3.js.
  618. web3.js is free software: you can redistribute it and/or modify
  619. it under the terms of the GNU Lesser General Public License as published by
  620. the Free Software Foundation, either version 3 of the License, or
  621. (at your option) any later version.
  622. web3.js is distributed in the hope that it will be useful,
  623. but WITHOUT ANY WARRANTY; without even the implied warranty of
  624. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  625. GNU Lesser General Public License for more details.
  626. You should have received a copy of the GNU Lesser General Public License
  627. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  628. */
  629. /**
  630. * @file coder.js
  631. * @author Marek Kotewicz <marek@ethdev.com>
  632. * @date 2015
  633. */
  634. var f = require('./formatters');
  635. var SolidityTypeAddress = require('./address');
  636. var SolidityTypeBool = require('./bool');
  637. var SolidityTypeInt = require('./int');
  638. var SolidityTypeUInt = require('./uint');
  639. var SolidityTypeDynamicBytes = require('./dynamicbytes');
  640. var SolidityTypeString = require('./string');
  641. var SolidityTypeReal = require('./real');
  642. var SolidityTypeUReal = require('./ureal');
  643. var SolidityTypeBytes = require('./bytes');
  644. /**
  645. * SolidityCoder prototype should be used to encode/decode solidity params of any type
  646. */
  647. var SolidityCoder = function (types) {
  648. this._types = types;
  649. };
  650. /**
  651. * This method should be used to transform type to SolidityType
  652. *
  653. * @method _requireType
  654. * @param {String} type
  655. * @returns {SolidityType}
  656. * @throws {Error} throws if no matching type is found
  657. */
  658. SolidityCoder.prototype._requireType = function (type) {
  659. var solidityType = this._types.filter(function (t) {
  660. return t.isType(type);
  661. })[0];
  662. if (!solidityType) {
  663. throw Error('invalid solidity type!: ' + type);
  664. }
  665. return solidityType;
  666. };
  667. /**
  668. * Should be used to encode plain param
  669. *
  670. * @method encodeParam
  671. * @param {String} type
  672. * @param {Object} plain param
  673. * @return {String} encoded plain param
  674. */
  675. SolidityCoder.prototype.encodeParam = function (type, param) {
  676. return this.encodeParams([type], [param]);
  677. };
  678. /**
  679. * Should be used to encode list of params
  680. *
  681. * @method encodeParams
  682. * @param {Array} types
  683. * @param {Array} params
  684. * @return {String} encoded list of params
  685. */
  686. SolidityCoder.prototype.encodeParams = function (types, params) {
  687. var solidityTypes = this.getSolidityTypes(types);
  688. var encodeds = solidityTypes.map(function (solidityType, index) {
  689. return solidityType.encode(params[index], types[index]);
  690. });
  691. var dynamicOffset = solidityTypes.reduce(function (acc, solidityType, index) {
  692. var staticPartLength = solidityType.staticPartLength(types[index]);
  693. var roundedStaticPartLength = Math.floor((staticPartLength + 31) / 32) * 32;
  694. return acc + roundedStaticPartLength;
  695. }, 0);
  696. var result = this.encodeMultiWithOffset(types, solidityTypes, encodeds, dynamicOffset);
  697. return result;
  698. };
  699. SolidityCoder.prototype.encodeMultiWithOffset = function (types, solidityTypes, encodeds, dynamicOffset) {
  700. var result = "";
  701. var self = this;
  702. var isDynamic = function (i) {
  703. return solidityTypes[i].isDynamicArray(types[i]) || solidityTypes[i].isDynamicType(types[i]);
  704. };
  705. types.forEach(function (type, i) {
  706. if (isDynamic(i)) {
  707. result += f.formatInputInt(dynamicOffset).encode();
  708. var e = self.encodeWithOffset(types[i], solidityTypes[i], encodeds[i], dynamicOffset);
  709. dynamicOffset += e.length / 2;
  710. } else {
  711. // don't add length to dynamicOffset. it's already counted
  712. result += self.encodeWithOffset(types[i], solidityTypes[i], encodeds[i], dynamicOffset);
  713. }
  714. // TODO: figure out nested arrays
  715. });
  716. types.forEach(function (type, i) {
  717. if (isDynamic(i)) {
  718. var e = self.encodeWithOffset(types[i], solidityTypes[i], encodeds[i], dynamicOffset);
  719. dynamicOffset += e.length / 2;
  720. result += e;
  721. }
  722. });
  723. return result;
  724. };
  725. // TODO: refactor whole encoding!
  726. SolidityCoder.prototype.encodeWithOffset = function (type, solidityType, encoded, offset) {
  727. var self = this;
  728. if (solidityType.isDynamicArray(type)) {
  729. return (function () {
  730. // offset was already set
  731. var nestedName = solidityType.nestedName(type);
  732. var nestedStaticPartLength = solidityType.staticPartLength(nestedName);
  733. var result = encoded[0];
  734. (function () {
  735. var previousLength = 2; // in int
  736. if (solidityType.isDynamicArray(nestedName)) {
  737. for (var i = 1; i < encoded.length; i++) {
  738. previousLength += +(encoded[i - 1])[0] || 0;
  739. result += f.formatInputInt(offset + i * nestedStaticPartLength + previousLength * 32).encode();
  740. }
  741. }
  742. })();
  743. // first element is length, skip it
  744. (function () {
  745. for (var i = 0; i < encoded.length - 1; i++) {
  746. var additionalOffset = result / 2;
  747. result += self.encodeWithOffset(nestedName, solidityType, encoded[i + 1], offset + additionalOffset);
  748. }
  749. })();
  750. return result;
  751. })();
  752. } else if (solidityType.isStaticArray(type)) {
  753. return (function () {
  754. var nestedName = solidityType.nestedName(type);
  755. var nestedStaticPartLength = solidityType.staticPartLength(nestedName);
  756. var result = "";
  757. if (solidityType.isDynamicArray(nestedName)) {
  758. (function () {
  759. var previousLength = 0; // in int
  760. for (var i = 0; i < encoded.length; i++) {
  761. // calculate length of previous item
  762. previousLength += +(encoded[i - 1] || [])[0] || 0;
  763. result += f.formatInputInt(offset + i * nestedStaticPartLength + previousLength * 32).encode();
  764. }
  765. })();
  766. }
  767. (function () {
  768. for (var i = 0; i < encoded.length; i++) {
  769. var additionalOffset = result / 2;
  770. result += self.encodeWithOffset(nestedName, solidityType, encoded[i], offset + additionalOffset);
  771. }
  772. })();
  773. return result;
  774. })();
  775. }
  776. return encoded;
  777. };
  778. /**
  779. * Should be used to decode bytes to plain param
  780. *
  781. * @method decodeParam
  782. * @param {String} type
  783. * @param {String} bytes
  784. * @return {Object} plain param
  785. */
  786. SolidityCoder.prototype.decodeParam = function (type, bytes) {
  787. return this.decodeParams([type], bytes)[0];
  788. };
  789. /**
  790. * Should be used to decode list of params
  791. *
  792. * @method decodeParam
  793. * @param {Array} types
  794. * @param {String} bytes
  795. * @return {Array} array of plain params
  796. */
  797. SolidityCoder.prototype.decodeParams = function (types, bytes) {
  798. var solidityTypes = this.getSolidityTypes(types);
  799. var offsets = this.getOffsets(types, solidityTypes);
  800. return solidityTypes.map(function (solidityType, index) {
  801. return solidityType.decode(bytes, offsets[index], types[index], index);
  802. });
  803. };
  804. SolidityCoder.prototype.getOffsets = function (types, solidityTypes) {
  805. var lengths = solidityTypes.map(function (solidityType, index) {
  806. return solidityType.staticPartLength(types[index]);
  807. });
  808. for (var i = 1; i < lengths.length; i++) {
  809. // sum with length of previous element
  810. lengths[i] += lengths[i - 1];
  811. }
  812. return lengths.map(function (length, index) {
  813. // remove the current length, so the length is sum of previous elements
  814. var staticPartLength = solidityTypes[index].staticPartLength(types[index]);
  815. return length - staticPartLength;
  816. });
  817. };
  818. SolidityCoder.prototype.getSolidityTypes = function (types) {
  819. var self = this;
  820. return types.map(function (type) {
  821. return self._requireType(type);
  822. });
  823. };
  824. var coder = new SolidityCoder([
  825. new SolidityTypeAddress(),
  826. new SolidityTypeBool(),
  827. new SolidityTypeInt(),
  828. new SolidityTypeUInt(),
  829. new SolidityTypeDynamicBytes(),
  830. new SolidityTypeBytes(),
  831. new SolidityTypeString(),
  832. new SolidityTypeReal(),
  833. new SolidityTypeUReal()
  834. ]);
  835. module.exports = coder;
  836. },{"./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){
  837. var f = require('./formatters');
  838. var SolidityType = require('./type');
  839. var SolidityTypeDynamicBytes = function () {
  840. this._inputFormatter = f.formatInputDynamicBytes;
  841. this._outputFormatter = f.formatOutputDynamicBytes;
  842. };
  843. SolidityTypeDynamicBytes.prototype = new SolidityType({});
  844. SolidityTypeDynamicBytes.prototype.constructor = SolidityTypeDynamicBytes;
  845. SolidityTypeDynamicBytes.prototype.isType = function (name) {
  846. return !!name.match(/^bytes(\[([0-9]*)\])*$/);
  847. };
  848. SolidityTypeDynamicBytes.prototype.staticPartLength = function (name) {
  849. return 32 * this.staticArrayLength(name);
  850. };
  851. SolidityTypeDynamicBytes.prototype.isDynamicType = function () {
  852. return true;
  853. };
  854. module.exports = SolidityTypeDynamicBytes;
  855. },{"./formatters":9,"./type":14}],9:[function(require,module,exports){
  856. /*
  857. This file is part of web3.js.
  858. web3.js is free software: you can redistribute it and/or modify
  859. it under the terms of the GNU Lesser General Public License as published by
  860. the Free Software Foundation, either version 3 of the License, or
  861. (at your option) any later version.
  862. web3.js is distributed in the hope that it will be useful,
  863. but WITHOUT ANY WARRANTY; without even the implied warranty of
  864. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  865. GNU Lesser General Public License for more details.
  866. You should have received a copy of the GNU Lesser General Public License
  867. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  868. */
  869. /**
  870. * @file formatters.js
  871. * @author Marek Kotewicz <marek@ethdev.com>
  872. * @date 2015
  873. */
  874. var BigNumber = require('bignumber.js');
  875. var utils = require('../utils/utils');
  876. var c = require('../utils/config');
  877. var SolidityParam = require('./param');
  878. /**
  879. * Formats input value to byte representation of int
  880. * If value is negative, return it's two's complement
  881. * If the value is floating point, round it down
  882. *
  883. * @method formatInputInt
  884. * @param {String|Number|BigNumber} value that needs to be formatted
  885. * @returns {SolidityParam}
  886. */
  887. var formatInputInt = function (value) {
  888. BigNumber.config(c.ETH_BIGNUMBER_ROUNDING_MODE);
  889. var result = utils.padLeft(utils.toTwosComplement(value).round().toString(16), 64);
  890. return new SolidityParam(result);
  891. };
  892. /**
  893. * Formats input bytes
  894. *
  895. * @method formatInputBytes
  896. * @param {String}
  897. * @returns {SolidityParam}
  898. */
  899. var formatInputBytes = function (value) {
  900. var result = utils.toHex(value).substr(2);
  901. var l = Math.floor((result.length + 63) / 64);
  902. result = utils.padRight(result, l * 64);
  903. return new SolidityParam(result);
  904. };
  905. /**
  906. * Formats input bytes
  907. *
  908. * @method formatDynamicInputBytes
  909. * @param {String}
  910. * @returns {SolidityParam}
  911. */
  912. var formatInputDynamicBytes = function (value) {
  913. var result = utils.toHex(value).substr(2);
  914. var length = result.length / 2;
  915. var l = Math.floor((result.length + 63) / 64);
  916. result = utils.padRight(result, l * 64);
  917. return new SolidityParam(formatInputInt(length).value + result);
  918. };
  919. /**
  920. * Formats input value to byte representation of string
  921. *
  922. * @method formatInputString
  923. * @param {String}
  924. * @returns {SolidityParam}
  925. */
  926. var formatInputString = function (value) {
  927. var result = utils.fromUtf8(value).substr(2);
  928. var length = result.length / 2;
  929. var l = Math.floor((result.length + 63) / 64);
  930. result = utils.padRight(result, l * 64);
  931. return new SolidityParam(formatInputInt(length).value + result);
  932. };
  933. /**
  934. * Formats input value to byte representation of bool
  935. *
  936. * @method formatInputBool
  937. * @param {Boolean}
  938. * @returns {SolidityParam}
  939. */
  940. var formatInputBool = function (value) {
  941. var result = '000000000000000000000000000000000000000000000000000000000000000' + (value ? '1' : '0');
  942. return new SolidityParam(result);
  943. };
  944. /**
  945. * Formats input value to byte representation of real
  946. * Values are multiplied by 2^m and encoded as integers
  947. *
  948. * @method formatInputReal
  949. * @param {String|Number|BigNumber}
  950. * @returns {SolidityParam}
  951. */
  952. var formatInputReal = function (value) {
  953. return formatInputInt(new BigNumber(value).times(new BigNumber(2).pow(128)));
  954. };
  955. /**
  956. * Check if input value is negative
  957. *
  958. * @method signedIsNegative
  959. * @param {String} value is hex format
  960. * @returns {Boolean} true if it is negative, otherwise false
  961. */
  962. var signedIsNegative = function (value) {
  963. return (new BigNumber(value.substr(0, 1), 16).toString(2).substr(0, 1)) === '1';
  964. };
  965. /**
  966. * Formats right-aligned output bytes to int
  967. *
  968. * @method formatOutputInt
  969. * @param {SolidityParam} param
  970. * @returns {BigNumber} right-aligned output bytes formatted to big number
  971. */
  972. var formatOutputInt = function (param) {
  973. var value = param.staticPart() || "0";
  974. // check if it's negative number
  975. // it it is, return two's complement
  976. if (signedIsNegative(value)) {
  977. return new BigNumber(value, 16).minus(new BigNumber('ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', 16)).minus(1);
  978. }
  979. return new BigNumber(value, 16);
  980. };
  981. /**
  982. * Formats right-aligned output bytes to uint
  983. *
  984. * @method formatOutputUInt
  985. * @param {SolidityParam}
  986. * @returns {BigNumeber} right-aligned output bytes formatted to uint
  987. */
  988. var formatOutputUInt = function (param) {
  989. var value = param.staticPart() || "0";
  990. return new BigNumber(value, 16);
  991. };
  992. /**
  993. * Formats right-aligned output bytes to real
  994. *
  995. * @method formatOutputReal
  996. * @param {SolidityParam}
  997. * @returns {BigNumber} input bytes formatted to real
  998. */
  999. var formatOutputReal = function (param) {
  1000. return formatOutputInt(param).dividedBy(new BigNumber(2).pow(128));
  1001. };
  1002. /**
  1003. * Formats right-aligned output bytes to ureal
  1004. *
  1005. * @method formatOutputUReal
  1006. * @param {SolidityParam}
  1007. * @returns {BigNumber} input bytes formatted to ureal
  1008. */
  1009. var formatOutputUReal = function (param) {
  1010. return formatOutputUInt(param).dividedBy(new BigNumber(2).pow(128));
  1011. };
  1012. /**
  1013. * Should be used to format output bool
  1014. *
  1015. * @method formatOutputBool
  1016. * @param {SolidityParam}
  1017. * @returns {Boolean} right-aligned input bytes formatted to bool
  1018. */
  1019. var formatOutputBool = function (param) {
  1020. return param.staticPart() === '0000000000000000000000000000000000000000000000000000000000000001' ? true : false;
  1021. };
  1022. /**
  1023. * Should be used to format output bytes
  1024. *
  1025. * @method formatOutputBytes
  1026. * @param {SolidityParam} left-aligned hex representation of string
  1027. * @returns {String} hex string
  1028. */
  1029. var formatOutputBytes = function (param) {
  1030. return '0x' + param.staticPart();
  1031. };
  1032. /**
  1033. * Should be used to format output bytes
  1034. *
  1035. * @method formatOutputDynamicBytes
  1036. * @param {SolidityParam} left-aligned hex representation of string
  1037. * @returns {String} hex string
  1038. */
  1039. var formatOutputDynamicBytes = function (param) {
  1040. var length = (new BigNumber(param.dynamicPart().slice(0, 64), 16)).toNumber() * 2;
  1041. return '0x' + param.dynamicPart().substr(64, length);
  1042. };
  1043. /**
  1044. * Should be used to format output string
  1045. *
  1046. * @method formatOutputString
  1047. * @param {SolidityParam} left-aligned hex representation of string
  1048. * @returns {String} ascii string
  1049. */
  1050. var formatOutputString = function (param) {
  1051. var length = (new BigNumber(param.dynamicPart().slice(0, 64), 16)).toNumber() * 2;
  1052. return utils.toUtf8(param.dynamicPart().substr(64, length));
  1053. };
  1054. /**
  1055. * Should be used to format output address
  1056. *
  1057. * @method formatOutputAddress
  1058. * @param {SolidityParam} right-aligned input bytes
  1059. * @returns {String} address
  1060. */
  1061. var formatOutputAddress = function (param) {
  1062. var value = param.staticPart();
  1063. return "0x" + value.slice(value.length - 40, value.length);
  1064. };
  1065. module.exports = {
  1066. formatInputInt: formatInputInt,
  1067. formatInputBytes: formatInputBytes,
  1068. formatInputDynamicBytes: formatInputDynamicBytes,
  1069. formatInputString: formatInputString,
  1070. formatInputBool: formatInputBool,
  1071. formatInputReal: formatInputReal,
  1072. formatOutputInt: formatOutputInt,
  1073. formatOutputUInt: formatOutputUInt,
  1074. formatOutputReal: formatOutputReal,
  1075. formatOutputUReal: formatOutputUReal,
  1076. formatOutputBool: formatOutputBool,
  1077. formatOutputBytes: formatOutputBytes,
  1078. formatOutputDynamicBytes: formatOutputDynamicBytes,
  1079. formatOutputString: formatOutputString,
  1080. formatOutputAddress: formatOutputAddress
  1081. };
  1082. },{"../utils/config":18,"../utils/utils":20,"./param":11,"bignumber.js":"bignumber.js"}],10:[function(require,module,exports){
  1083. var f = require('./formatters');
  1084. var SolidityType = require('./type');
  1085. /**
  1086. * SolidityTypeInt is a prootype that represents int type
  1087. * It matches:
  1088. * int
  1089. * int[]
  1090. * int[4]
  1091. * int[][]
  1092. * int[3][]
  1093. * int[][6][], ...
  1094. * int32
  1095. * int64[]
  1096. * int8[4]
  1097. * int256[][]
  1098. * int[3][]
  1099. * int64[][6][], ...
  1100. */
  1101. var SolidityTypeInt = function () {
  1102. this._inputFormatter = f.formatInputInt;
  1103. this._outputFormatter = f.formatOutputInt;
  1104. };
  1105. SolidityTypeInt.prototype = new SolidityType({});
  1106. SolidityTypeInt.prototype.constructor = SolidityTypeInt;
  1107. SolidityTypeInt.prototype.isType = function (name) {
  1108. return !!name.match(/^int([0-9]*)?(\[([0-9]*)\])*$/);
  1109. };
  1110. SolidityTypeInt.prototype.staticPartLength = function (name) {
  1111. return 32 * this.staticArrayLength(name);
  1112. };
  1113. module.exports = SolidityTypeInt;
  1114. },{"./formatters":9,"./type":14}],11:[function(require,module,exports){
  1115. /*
  1116. This file is part of web3.js.
  1117. web3.js is free software: you can redistribute it and/or modify
  1118. it under the terms of the GNU Lesser General Public License as published by
  1119. the Free Software Foundation, either version 3 of the License, or
  1120. (at your option) any later version.
  1121. web3.js is distributed in the hope that it will be useful,
  1122. but WITHOUT ANY WARRANTY; without even the implied warranty of
  1123. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  1124. GNU Lesser General Public License for more details.
  1125. You should have received a copy of the GNU Lesser General Public License
  1126. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  1127. */
  1128. /**
  1129. * @file param.js
  1130. * @author Marek Kotewicz <marek@ethdev.com>
  1131. * @date 2015
  1132. */
  1133. var utils = require('../utils/utils');
  1134. /**
  1135. * SolidityParam object prototype.
  1136. * Should be used when encoding, decoding solidity bytes
  1137. */
  1138. var SolidityParam = function (value, offset) {
  1139. this.value = value || '';
  1140. this.offset = offset; // offset in bytes
  1141. };
  1142. /**
  1143. * This method should be used to get length of params's dynamic part
  1144. *
  1145. * @method dynamicPartLength
  1146. * @returns {Number} length of dynamic part (in bytes)
  1147. */
  1148. SolidityParam.prototype.dynamicPartLength = function () {
  1149. return this.dynamicPart().length / 2;
  1150. };
  1151. /**
  1152. * This method should be used to create copy of solidity param with different offset
  1153. *
  1154. * @method withOffset
  1155. * @param {Number} offset length in bytes
  1156. * @returns {SolidityParam} new solidity param with applied offset
  1157. */
  1158. SolidityParam.prototype.withOffset = function (offset) {
  1159. return new SolidityParam(this.value, offset);
  1160. };
  1161. /**
  1162. * This method should be used to combine solidity params together
  1163. * eg. when appending an array
  1164. *
  1165. * @method combine
  1166. * @param {SolidityParam} param with which we should combine
  1167. * @param {SolidityParam} result of combination
  1168. */
  1169. SolidityParam.prototype.combine = function (param) {
  1170. return new SolidityParam(this.value + param.value);
  1171. };
  1172. /**
  1173. * This method should be called to check if param has dynamic size.
  1174. * If it has, it returns true, otherwise false
  1175. *
  1176. * @method isDynamic
  1177. * @returns {Boolean}
  1178. */
  1179. SolidityParam.prototype.isDynamic = function () {
  1180. return this.offset !== undefined;
  1181. };
  1182. /**
  1183. * This method should be called to transform offset to bytes
  1184. *
  1185. * @method offsetAsBytes
  1186. * @returns {String} bytes representation of offset
  1187. */
  1188. SolidityParam.prototype.offsetAsBytes = function () {
  1189. return !this.isDynamic() ? '' : utils.padLeft(utils.toTwosComplement(this.offset).toString(16), 64);
  1190. };
  1191. /**
  1192. * This method should be called to get static part of param
  1193. *
  1194. * @method staticPart
  1195. * @returns {String} offset if it is a dynamic param, otherwise value
  1196. */
  1197. SolidityParam.prototype.staticPart = function () {
  1198. if (!this.isDynamic()) {
  1199. return this.value;
  1200. }
  1201. return this.offsetAsBytes();
  1202. };
  1203. /**
  1204. * This method should be called to get dynamic part of param
  1205. *
  1206. * @method dynamicPart
  1207. * @returns {String} returns a value if it is a dynamic param, otherwise empty string
  1208. */
  1209. SolidityParam.prototype.dynamicPart = function () {
  1210. return this.isDynamic() ? this.value : '';
  1211. };
  1212. /**
  1213. * This method should be called to encode param
  1214. *
  1215. * @method encode
  1216. * @returns {String}
  1217. */
  1218. SolidityParam.prototype.encode = function () {
  1219. return this.staticPart() + this.dynamicPart();
  1220. };
  1221. /**
  1222. * This method should be called to encode array of params
  1223. *
  1224. * @method encodeList
  1225. * @param {Array[SolidityParam]} params
  1226. * @returns {String}
  1227. */
  1228. SolidityParam.encodeList = function (params) {
  1229. // updating offsets
  1230. var totalOffset = params.length * 32;
  1231. var offsetParams = params.map(function (param) {
  1232. if (!param.isDynamic()) {
  1233. return param;
  1234. }
  1235. var offset = totalOffset;
  1236. totalOffset += param.dynamicPartLength();
  1237. return param.withOffset(offset);
  1238. });
  1239. // encode everything!
  1240. return offsetParams.reduce(function (result, param) {
  1241. return result + param.dynamicPart();
  1242. }, offsetParams.reduce(function (result, param) {
  1243. return result + param.staticPart();
  1244. }, ''));
  1245. };
  1246. module.exports = SolidityParam;
  1247. },{"../utils/utils":20}],12:[function(require,module,exports){
  1248. var f = require('./formatters');
  1249. var SolidityType = require('./type');
  1250. /**
  1251. * SolidityTypeReal is a prootype that represents real type
  1252. * It matches:
  1253. * real
  1254. * real[]
  1255. * real[4]
  1256. * real[][]
  1257. * real[3][]
  1258. * real[][6][], ...
  1259. * real32
  1260. * real64[]
  1261. * real8[4]
  1262. * real256[][]
  1263. * real[3][]
  1264. * real64[][6][], ...
  1265. */
  1266. var SolidityTypeReal = function () {
  1267. this._inputFormatter = f.formatInputReal;
  1268. this._outputFormatter = f.formatOutputReal;
  1269. };
  1270. SolidityTypeReal.prototype = new SolidityType({});
  1271. SolidityTypeReal.prototype.constructor = SolidityTypeReal;
  1272. SolidityTypeReal.prototype.isType = function (name) {
  1273. return !!name.match(/real([0-9]*)?(\[([0-9]*)\])?/);
  1274. };
  1275. SolidityTypeReal.prototype.staticPartLength = function (name) {
  1276. return 32 * this.staticArrayLength(name);
  1277. };
  1278. module.exports = SolidityTypeReal;
  1279. },{"./formatters":9,"./type":14}],13:[function(require,module,exports){
  1280. var f = require('./formatters');
  1281. var SolidityType = require('./type');
  1282. var SolidityTypeString = function () {
  1283. this._inputFormatter = f.formatInputString;
  1284. this._outputFormatter = f.formatOutputString;
  1285. };
  1286. SolidityTypeString.prototype = new SolidityType({});
  1287. SolidityTypeString.prototype.constructor = SolidityTypeString;
  1288. SolidityTypeString.prototype.isType = function (name) {
  1289. return !!name.match(/^string(\[([0-9]*)\])*$/);
  1290. };
  1291. SolidityTypeString.prototype.staticPartLength = function (name) {
  1292. return 32 * this.staticArrayLength(name);
  1293. };
  1294. SolidityTypeString.prototype.isDynamicType = function () {
  1295. return true;
  1296. };
  1297. module.exports = SolidityTypeString;
  1298. },{"./formatters":9,"./type":14}],14:[function(require,module,exports){
  1299. var f = require('./formatters');
  1300. var SolidityParam = require('./param');
  1301. /**
  1302. * SolidityType prototype is used to encode/decode solidity params of certain type
  1303. */
  1304. var SolidityType = function (config) {
  1305. this._inputFormatter = config.inputFormatter;
  1306. this._outputFormatter = config.outputFormatter;
  1307. };
  1308. /**
  1309. * Should be used to determine if this SolidityType do match given name
  1310. *
  1311. * @method isType
  1312. * @param {String} name
  1313. * @return {Bool} true if type match this SolidityType, otherwise false
  1314. */
  1315. SolidityType.prototype.isType = function (name) {
  1316. throw "this method should be overrwritten for type " + name;
  1317. };
  1318. /**
  1319. * Should be used to determine what is the length of static part in given type
  1320. *
  1321. * @method staticPartLength
  1322. * @param {String} name
  1323. * @return {Number} length of static part in bytes
  1324. */
  1325. SolidityType.prototype.staticPartLength = function (name) {
  1326. throw "this method should be overrwritten for type: " + name;
  1327. };
  1328. /**
  1329. * Should be used to determine if type is dynamic array
  1330. * eg:
  1331. * "type[]" => true
  1332. * "type[4]" => false
  1333. *
  1334. * @method isDynamicArray
  1335. * @param {String} name
  1336. * @return {Bool} true if the type is dynamic array
  1337. */
  1338. SolidityType.prototype.isDynamicArray = function (name) {
  1339. var nestedTypes = this.nestedTypes(name);
  1340. return !!nestedTypes && !nestedTypes[nestedTypes.length - 1].match(/[0-9]{1,}/g);
  1341. };
  1342. /**
  1343. * Should be used to determine if type is static array
  1344. * eg:
  1345. * "type[]" => false
  1346. * "type[4]" => true
  1347. *
  1348. * @method isStaticArray
  1349. * @param {String} name
  1350. * @return {Bool} true if the type is static array
  1351. */
  1352. SolidityType.prototype.isStaticArray = function (name) {
  1353. var nestedTypes = this.nestedTypes(name);
  1354. return !!nestedTypes && !!nestedTypes[nestedTypes.length - 1].match(/[0-9]{1,}/g);
  1355. };
  1356. /**
  1357. * Should return length of static array
  1358. * eg.
  1359. * "int[32]" => 32
  1360. * "int256[14]" => 14
  1361. * "int[2][3]" => 3
  1362. * "int" => 1
  1363. * "int[1]" => 1
  1364. * "int[]" => 1
  1365. *
  1366. * @method staticArrayLength
  1367. * @param {String} name
  1368. * @return {Number} static array length
  1369. */
  1370. SolidityType.prototype.staticArrayLength = function (name) {
  1371. var nestedTypes = this.nestedTypes(name);
  1372. if (nestedTypes) {
  1373. return parseInt(nestedTypes[nestedTypes.length - 1].match(/[0-9]{1,}/g) || 1);
  1374. }
  1375. return 1;
  1376. };
  1377. /**
  1378. * Should return nested type
  1379. * eg.
  1380. * "int[32]" => "int"
  1381. * "int256[14]" => "int256"
  1382. * "int[2][3]" => "int[2]"
  1383. * "int" => "int"
  1384. * "int[]" => "int"
  1385. *
  1386. * @method nestedName
  1387. * @param {String} name
  1388. * @return {String} nested name
  1389. */
  1390. SolidityType.prototype.nestedName = function (name) {
  1391. // remove last [] in name
  1392. var nestedTypes = this.nestedTypes(name);
  1393. if (!nestedTypes) {
  1394. return name;
  1395. }
  1396. return name.substr(0, name.length - nestedTypes[nestedTypes.length - 1].length);
  1397. };
  1398. /**
  1399. * Should return true if type has dynamic size by default
  1400. * such types are "string", "bytes"
  1401. *
  1402. * @method isDynamicType
  1403. * @param {String} name
  1404. * @return {Bool} true if is dynamic, otherwise false
  1405. */
  1406. SolidityType.prototype.isDynamicType = function () {
  1407. return false;
  1408. };
  1409. /**
  1410. * Should return array of nested types
  1411. * eg.
  1412. * "int[2][3][]" => ["[2]", "[3]", "[]"]
  1413. * "int[] => ["[]"]
  1414. * "int" => null
  1415. *
  1416. * @method nestedTypes
  1417. * @param {String} name
  1418. * @return {Array} array of nested types
  1419. */
  1420. SolidityType.prototype.nestedTypes = function (name) {
  1421. // return list of strings eg. "[]", "[3]", "[]", "[2]"
  1422. return name.match(/(\[[0-9]*\])/g);
  1423. };
  1424. /**
  1425. * Should be used to encode the value
  1426. *
  1427. * @method encode
  1428. * @param {Object} value
  1429. * @param {String} name
  1430. * @return {String} encoded value
  1431. */
  1432. SolidityType.prototype.encode = function (value, name) {
  1433. var self = this;
  1434. if (this.isDynamicArray(name)) {
  1435. return (function () {
  1436. var length = value.length; // in int
  1437. var nestedName = self.nestedName(name);
  1438. var result = [];
  1439. result.push(f.formatInputInt(length).encode());
  1440. value.forEach(function (v) {
  1441. result.push(self.encode(v, nestedName));
  1442. });
  1443. return result;
  1444. })();
  1445. } else if (this.isStaticArray(name)) {
  1446. return (function () {
  1447. var length = self.staticArrayLength(name); // in int
  1448. var nestedName = self.nestedName(name);
  1449. var result = [];
  1450. for (var i = 0; i < length; i++) {
  1451. result.push(self.encode(value[i], nestedName));
  1452. }
  1453. return result;
  1454. })();
  1455. }
  1456. return this._inputFormatter(value, name).encode();
  1457. };
  1458. /**
  1459. * Should be used to decode value from bytes
  1460. *
  1461. * @method decode
  1462. * @param {String} bytes
  1463. * @param {Number} offset in bytes
  1464. * @param {String} name type name
  1465. * @returns {Object} decoded value
  1466. */
  1467. SolidityType.prototype.decode = function (bytes, offset, name) {
  1468. var self = this;
  1469. if (this.isDynamicArray(name)) {
  1470. return (function () {
  1471. var arrayOffset = parseInt('0x' + bytes.substr(offset * 2, 64)); // in bytes
  1472. var length = parseInt('0x' + bytes.substr(arrayOffset * 2, 64)); // in int
  1473. var arrayStart = arrayOffset + 32; // array starts after length; // in bytes
  1474. var nestedName = self.nestedName(name);
  1475. var nestedStaticPartLength = self.staticPartLength(nestedName); // in bytes
  1476. var roundedNestedStaticPartLength = Math.floor((nestedStaticPartLength + 31) / 32) * 32;
  1477. var result = [];
  1478. for (var i = 0; i < length * roundedNestedStaticPartLength; i += roundedNestedStaticPartLength) {
  1479. result.push(self.decode(bytes, arrayStart + i, nestedName));
  1480. }
  1481. return result;
  1482. })();
  1483. } else if (this.isStaticArray(name)) {
  1484. return (function () {
  1485. var length = self.staticArrayLength(name); // in int
  1486. var arrayStart = offset; // in bytes
  1487. var nestedName = self.nestedName(name);
  1488. var nestedStaticPartLength = self.staticPartLength(nestedName); // in bytes
  1489. var roundedNestedStaticPartLength = Math.floor((nestedStaticPartLength + 31) / 32) * 32;
  1490. var result = [];
  1491. for (var i = 0; i < length * roundedNestedStaticPartLength; i += roundedNestedStaticPartLength) {
  1492. result.push(self.decode(bytes, arrayStart + i, nestedName));
  1493. }
  1494. return result;
  1495. })();
  1496. } else if (this.isDynamicType(name)) {
  1497. return (function () {
  1498. var dynamicOffset = parseInt('0x' + bytes.substr(offset * 2, 64)); // in bytes
  1499. var length = parseInt('0x' + bytes.substr(dynamicOffset * 2, 64)); // in bytes
  1500. var roundedLength = Math.floor((length + 31) / 32); // in int
  1501. return self._outputFormatter(new SolidityParam(bytes.substr(dynamicOffset * 2, ( 1 + roundedLength) * 64), 0));
  1502. })();
  1503. }
  1504. var length = this.staticPartLength(name);
  1505. return this._outputFormatter(new SolidityParam(bytes.substr(offset * 2, length * 2)));
  1506. };
  1507. module.exports = SolidityType;
  1508. },{"./formatters":9,"./param":11}],15:[function(require,module,exports){
  1509. var f = require('./formatters');
  1510. var SolidityType = require('./type');
  1511. /**
  1512. * SolidityTypeUInt is a prootype that represents uint type
  1513. * It matches:
  1514. * uint
  1515. * uint[]
  1516. * uint[4]
  1517. * uint[][]
  1518. * uint[3][]
  1519. * uint[][6][], ...
  1520. * uint32
  1521. * uint64[]
  1522. * uint8[4]
  1523. * uint256[][]
  1524. * uint[3][]
  1525. * uint64[][6][], ...
  1526. */
  1527. var SolidityTypeUInt = function () {
  1528. this._inputFormatter = f.formatInputInt;
  1529. this._outputFormatter = f.formatOutputUInt;
  1530. };
  1531. SolidityTypeUInt.prototype = new SolidityType({});
  1532. SolidityTypeUInt.prototype.constructor = SolidityTypeUInt;
  1533. SolidityTypeUInt.prototype.isType = function (name) {
  1534. return !!name.match(/^uint([0-9]*)?(\[([0-9]*)\])*$/);
  1535. };
  1536. SolidityTypeUInt.prototype.staticPartLength = function (name) {
  1537. return 32 * this.staticArrayLength(name);
  1538. };
  1539. module.exports = SolidityTypeUInt;
  1540. },{"./formatters":9,"./type":14}],16:[function(require,module,exports){
  1541. var f = require('./formatters');
  1542. var SolidityType = require('./type');
  1543. /**
  1544. * SolidityTypeUReal is a prootype that represents ureal type
  1545. * It matches:
  1546. * ureal
  1547. * ureal[]
  1548. * ureal[4]
  1549. * ureal[][]
  1550. * ureal[3][]
  1551. * ureal[][6][], ...
  1552. * ureal32
  1553. * ureal64[]
  1554. * ureal8[4]
  1555. * ureal256[][]
  1556. * ureal[3][]
  1557. * ureal64[][6][], ...
  1558. */
  1559. var SolidityTypeUReal = function () {
  1560. this._inputFormatter = f.formatInputReal;
  1561. this._outputFormatter = f.formatOutputUReal;
  1562. };
  1563. SolidityTypeUReal.prototype = new SolidityType({});
  1564. SolidityTypeUReal.prototype.constructor = SolidityTypeUReal;
  1565. SolidityTypeUReal.prototype.isType = function (name) {
  1566. return !!name.match(/^ureal([0-9]*)?(\[([0-9]*)\])*$/);
  1567. };
  1568. SolidityTypeUReal.prototype.staticPartLength = function (name) {
  1569. return 32 * this.staticArrayLength(name);
  1570. };
  1571. module.exports = SolidityTypeUReal;
  1572. },{"./formatters":9,"./type":14}],17:[function(require,module,exports){
  1573. 'use strict';
  1574. // go env doesn't have and need XMLHttpRequest
  1575. if (typeof XMLHttpRequest === 'undefined') {
  1576. exports.XMLHttpRequest = {};
  1577. } else {
  1578. exports.XMLHttpRequest = XMLHttpRequest; // jshint ignore:line
  1579. }
  1580. },{}],18:[function(require,module,exports){
  1581. /*
  1582. This file is part of web3.js.
  1583. web3.js is free software: you can redistribute it and/or modify
  1584. it under the terms of the GNU Lesser General Public License as published by
  1585. the Free Software Foundation, either version 3 of the License, or
  1586. (at your option) any later version.
  1587. web3.js is distributed in the hope that it will be useful,
  1588. but WITHOUT ANY WARRANTY; without even the implied warranty of
  1589. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  1590. GNU Lesser General Public License for more details.
  1591. You should have received a copy of the GNU Lesser General Public License
  1592. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  1593. */
  1594. /** @file config.js
  1595. * @authors:
  1596. * Marek Kotewicz <marek@ethdev.com>
  1597. * @date 2015
  1598. */
  1599. /**
  1600. * Utils
  1601. *
  1602. * @module utils
  1603. */
  1604. /**
  1605. * Utility functions
  1606. *
  1607. * @class [utils] config
  1608. * @constructor
  1609. */
  1610. /// required to define ETH_BIGNUMBER_ROUNDING_MODE
  1611. var BigNumber = require('bignumber.js');
  1612. var ETH_UNITS = [
  1613. 'wei',
  1614. 'kwei',
  1615. 'Mwei',
  1616. 'Gwei',
  1617. 'szabo',
  1618. 'finney',
  1619. 'femtoether',
  1620. 'picoether',
  1621. 'nanoether',
  1622. 'microether',
  1623. 'milliether',
  1624. 'nano',
  1625. 'micro',
  1626. 'milli',
  1627. 'ether',
  1628. 'grand',
  1629. 'Mether',
  1630. 'Gether',
  1631. 'Tether',
  1632. 'Pether',
  1633. 'Eether',
  1634. 'Zether',
  1635. 'Yether',
  1636. 'Nether',
  1637. 'Dether',
  1638. 'Vether',
  1639. 'Uether'
  1640. ];
  1641. module.exports = {
  1642. ETH_PADDING: 32,
  1643. ETH_SIGNATURE_LENGTH: 4,
  1644. ETH_UNITS: ETH_UNITS,
  1645. ETH_BIGNUMBER_ROUNDING_MODE: { ROUNDING_MODE: BigNumber.ROUND_DOWN },
  1646. ETH_POLLING_TIMEOUT: 1000/2,
  1647. defaultBlock: 'latest',
  1648. defaultAccount: undefined
  1649. };
  1650. },{"bignumber.js":"bignumber.js"}],19:[function(require,module,exports){
  1651. /*
  1652. This file is part of web3.js.
  1653. web3.js is free software: you can redistribute it and/or modify
  1654. it under the terms of the GNU Lesser General Public License as published by
  1655. the Free Software Foundation, either version 3 of the License, or
  1656. (at your option) any later version.
  1657. web3.js is distributed in the hope that it will be useful,
  1658. but WITHOUT ANY WARRANTY; without even the implied warranty of
  1659. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  1660. GNU Lesser General Public License for more details.
  1661. You should have received a copy of the GNU Lesser General Public License
  1662. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  1663. */
  1664. /**
  1665. * @file sha3.js
  1666. * @author Marek Kotewicz <marek@ethdev.com>
  1667. * @date 2015
  1668. */
  1669. var CryptoJS = require('crypto-js');
  1670. var sha3 = require('crypto-js/sha3');
  1671. module.exports = function (value, options) {
  1672. if (options && options.encoding === 'hex') {
  1673. if (value.length > 2 && value.substr(0, 2) === '0x') {
  1674. value = value.substr(2);
  1675. }
  1676. value = CryptoJS.enc.Hex.parse(value);
  1677. }
  1678. return sha3(value, {
  1679. outputLength: 256
  1680. }).toString();
  1681. };
  1682. },{"crypto-js":57,"crypto-js/sha3":78}],20:[function(require,module,exports){
  1683. /*
  1684. This file is part of web3.js.
  1685. web3.js is free software: you can redistribute it and/or modify
  1686. it under the terms of the GNU Lesser General Public License as published by
  1687. the Free Software Foundation, either version 3 of the License, or
  1688. (at your option) any later version.
  1689. web3.js is distributed in the hope that it will be useful,
  1690. but WITHOUT ANY WARRANTY; without even the implied warranty of
  1691. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  1692. GNU Lesser General Public License for more details.
  1693. You should have received a copy of the GNU Lesser General Public License
  1694. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  1695. */
  1696. /**
  1697. * @file utils.js
  1698. * @author Marek Kotewicz <marek@ethdev.com>
  1699. * @date 2015
  1700. */
  1701. /**
  1702. * Utils
  1703. *
  1704. * @module utils
  1705. */
  1706. /**
  1707. * Utility functions
  1708. *
  1709. * @class [utils] utils
  1710. * @constructor
  1711. */
  1712. var BigNumber = require('bignumber.js');
  1713. var utf8 = require('utf8');
  1714. var unitMap = {
  1715. 'wei': '1',
  1716. 'kwei': '1000',
  1717. 'ada': '1000',
  1718. 'femtoether': '1000',
  1719. 'mwei': '1000000',
  1720. 'babbage': '1000000',
  1721. 'picoether': '1000000',
  1722. 'gwei': '1000000000',
  1723. 'shannon': '1000000000',
  1724. 'nanoether': '1000000000',
  1725. 'nano': '1000000000',
  1726. 'szabo': '1000000000000',
  1727. 'microether': '1000000000000',
  1728. 'micro': '1000000000000',
  1729. 'finney': '1000000000000000',
  1730. 'milliether': '1000000000000000',
  1731. 'milli': '1000000000000000',
  1732. 'ether': '1000000000000000000',
  1733. 'kether': '1000000000000000000000',
  1734. 'grand': '1000000000000000000000',
  1735. 'einstein': '1000000000000000000000',
  1736. 'mether': '1000000000000000000000000',
  1737. 'gether': '1000000000000000000000000000',
  1738. 'tether': '1000000000000000000000000000000'
  1739. };
  1740. /**
  1741. * Should be called to pad string to expected length
  1742. *
  1743. * @method padLeft
  1744. * @param {String} string to be padded
  1745. * @param {Number} characters that result string should have
  1746. * @param {String} sign, by default 0
  1747. * @returns {String} right aligned string
  1748. */
  1749. var padLeft = function (string, chars, sign) {
  1750. return new Array(chars - string.length + 1).join(sign ? sign : "0") + string;
  1751. };
  1752. /**
  1753. * Should be called to pad string to expected length
  1754. *
  1755. * @method padRight
  1756. * @param {String} string to be padded
  1757. * @param {Number} characters that result string should have
  1758. * @param {String} sign, by default 0
  1759. * @returns {String} right aligned string
  1760. */
  1761. var padRight = function (string, chars, sign) {
  1762. return string + (new Array(chars - string.length + 1).join(sign ? sign : "0"));
  1763. };
  1764. /**
  1765. * Should be called to get utf8 from it's hex representation
  1766. *
  1767. * @method toUtf8
  1768. * @param {String} string in hex
  1769. * @returns {String} ascii string representation of hex value
  1770. */
  1771. var toUtf8 = function(hex) {
  1772. // Find termination
  1773. var str = "";
  1774. var i = 0, l = hex.length;
  1775. if (hex.substring(0, 2) === '0x') {
  1776. i = 2;
  1777. }
  1778. for (; i < l; i+=2) {
  1779. var code = parseInt(hex.substr(i, 2), 16);
  1780. if (code === 0)
  1781. break;
  1782. str += String.fromCharCode(code);
  1783. }
  1784. return utf8.decode(str);
  1785. };
  1786. /**
  1787. * Should be called to get ascii from it's hex representation
  1788. *
  1789. * @method toAscii
  1790. * @param {String} string in hex
  1791. * @returns {String} ascii string representation of hex value
  1792. */
  1793. var toAscii = function(hex) {
  1794. // Find termination
  1795. var str = "";
  1796. var i = 0, l = hex.length;
  1797. if (hex.substring(0, 2) === '0x') {
  1798. i = 2;
  1799. }
  1800. for (; i < l; i+=2) {
  1801. var code = parseInt(hex.substr(i, 2), 16);
  1802. str += String.fromCharCode(code);
  1803. }
  1804. return str;
  1805. };
  1806. /**
  1807. * Should be called to get hex representation (prefixed by 0x) of utf8 a string
  1808. *
  1809. * @method fromUtf8
  1810. * @param {String} string
  1811. * @param {Number} optional padding
  1812. * @returns {String} hex representation of input string
  1813. */
  1814. var fromUtf8 = function(str) {
  1815. str = utf8.encode(str);
  1816. var hex = "";
  1817. for(var i = 0; i < str.length; i++) {
  1818. var code = str.charCodeAt(i);
  1819. if (code === 0)
  1820. break;
  1821. var n = code.toString(16);
  1822. hex += n.length < 2 ? '0' + n : n;
  1823. }
  1824. return "0x" + hex;
  1825. };
  1826. /**
  1827. * Should be called to get hex representation (prefixed by 0x) of ascii string
  1828. *
  1829. * @method fromAscii
  1830. * @param {String} string
  1831. * @param {Number} optional padding
  1832. * @returns {String} hex representation of input string
  1833. */
  1834. var fromAscii = function(str) {
  1835. var hex = "";
  1836. for(var i = 0; i < str.length; i++) {
  1837. var code = str.charCodeAt(i);
  1838. var n = code.toString(16);
  1839. hex += n.length < 2 ? '0' + n : n;
  1840. }
  1841. return "0x" + hex;
  1842. };
  1843. /**
  1844. * Should be used to create full function/event name from json abi
  1845. *
  1846. * @method transformToFullName
  1847. * @param {Object} json-abi
  1848. * @return {String} full fnction/event name
  1849. */
  1850. var transformToFullName = function (json) {
  1851. if (json.name.indexOf('(') !== -1) {
  1852. return json.name;
  1853. }
  1854. var typeName = json.inputs.map(function(i){return i.type; }).join();
  1855. return json.name + '(' + typeName + ')';
  1856. };
  1857. /**
  1858. * Should be called to get display name of contract function
  1859. *
  1860. * @method extractDisplayName
  1861. * @param {String} name of function/event
  1862. * @returns {String} display name for function/event eg. multiply(uint256) -> multiply
  1863. */
  1864. var extractDisplayName = function (name) {
  1865. var length = name.indexOf('(');
  1866. return length !== -1 ? name.substr(0, length) : name;
  1867. };
  1868. /// @returns overloaded part of function/event name
  1869. var extractTypeName = function (name) {
  1870. /// TODO: make it invulnerable
  1871. var length = name.indexOf('(');
  1872. return length !== -1 ? name.substr(length + 1, name.length - 1 - (length + 1)).replace(' ', '') : "";
  1873. };
  1874. /**
  1875. * Converts value to it's decimal representation in string
  1876. *
  1877. * @method toDecimal
  1878. * @param {String|Number|BigNumber}
  1879. * @return {String}
  1880. */
  1881. var toDecimal = function (value) {
  1882. return toBigNumber(value).toNumber();
  1883. };
  1884. /**
  1885. * Converts value to it's hex representation
  1886. *
  1887. * @method fromDecimal
  1888. * @param {String|Number|BigNumber}
  1889. * @return {String}
  1890. */
  1891. var fromDecimal = function (value) {
  1892. var number = toBigNumber(value);
  1893. var result = number.toString(16);
  1894. return number.lessThan(0) ? '-0x' + result.substr(1) : '0x' + result;
  1895. };
  1896. /**
  1897. * Auto converts any given value into it's hex representation.
  1898. *
  1899. * And even stringifys objects before.
  1900. *
  1901. * @method toHex
  1902. * @param {String|Number|BigNumber|Object}
  1903. * @return {String}
  1904. */
  1905. var toHex = function (val) {
  1906. /*jshint maxcomplexity: 8 */
  1907. if (isBoolean(val))
  1908. return fromDecimal(+val);
  1909. if (isBigNumber(val))
  1910. return fromDecimal(val);
  1911. if (isObject(val))
  1912. return fromUtf8(JSON.stringify(val));
  1913. // if its a negative number, pass it through fromDecimal
  1914. if (isString(val)) {
  1915. if (val.indexOf('-0x') === 0)
  1916. return fromDecimal(val);
  1917. else if(val.indexOf('0x') === 0)
  1918. return val;
  1919. else if (!isFinite(val))
  1920. return fromAscii(val);
  1921. }
  1922. return fromDecimal(val);
  1923. };
  1924. /**
  1925. * Returns value of unit in Wei
  1926. *
  1927. * @method getValueOfUnit
  1928. * @param {String} unit the unit to convert to, default ether
  1929. * @returns {BigNumber} value of the unit (in Wei)
  1930. * @throws error if the unit is not correct:w
  1931. */
  1932. var getValueOfUnit = function (unit) {
  1933. unit = unit ? unit.toLowerCase() : 'ether';
  1934. var unitValue = unitMap[unit];
  1935. if (unitValue === undefined) {
  1936. throw new Error('This unit doesn\'t exists, please use the one of the following units' + JSON.stringify(unitMap, null, 2));
  1937. }
  1938. return new BigNumber(unitValue, 10);
  1939. };
  1940. /**
  1941. * Takes a number of wei and converts it to any other ether unit.
  1942. *
  1943. * Possible units are:
  1944. * SI Short SI Full Effigy Other
  1945. * - kwei femtoether ada
  1946. * - mwei picoether babbage
  1947. * - gwei nanoether shannon nano
  1948. * - -- microether szabo micro
  1949. * - -- milliether finney milli
  1950. * - ether -- --
  1951. * - kether einstein grand
  1952. * - mether
  1953. * - gether
  1954. * - tether
  1955. *
  1956. * @method fromWei
  1957. * @param {Number|String} number can be a number, number string or a HEX of a decimal
  1958. * @param {String} unit the unit to convert to, default ether
  1959. * @return {String|Object} When given a BigNumber object it returns one as well, otherwise a number
  1960. */
  1961. var fromWei = function(number, unit) {
  1962. var returnValue = toBigNumber(number).dividedBy(getValueOfUnit(unit));
  1963. return isBigNumber(number) ? returnValue : returnValue.toString(10);
  1964. };
  1965. /**
  1966. * Takes a number of a unit and converts it to wei.
  1967. *
  1968. * Possible units are:
  1969. * SI Short SI Full Effigy Other
  1970. * - kwei femtoether ada
  1971. * - mwei picoether babbage
  1972. * - gwei nanoether shannon nano
  1973. * - -- microether szabo micro
  1974. * - -- milliether finney milli
  1975. * - ether -- --
  1976. * - kether einstein grand
  1977. * - mether
  1978. * - gether
  1979. * - tether
  1980. *
  1981. * @method toWei
  1982. * @param {Number|String|BigNumber} number can be a number, number string or a HEX of a decimal
  1983. * @param {String} unit the unit to convert from, default ether
  1984. * @return {String|Object} When given a BigNumber object it returns one as well, otherwise a number
  1985. */
  1986. var toWei = function(number, unit) {
  1987. var returnValue = toBigNumber(number).times(getValueOfUnit(unit));
  1988. return isBigNumber(number) ? returnValue : returnValue.toString(10);
  1989. };
  1990. /**
  1991. * Takes an input and transforms it into an bignumber
  1992. *
  1993. * @method toBigNumber
  1994. * @param {Number|String|BigNumber} a number, string, HEX string or BigNumber
  1995. * @return {BigNumber} BigNumber
  1996. */
  1997. var toBigNumber = function(number) {
  1998. /*jshint maxcomplexity:5 */
  1999. number = number || 0;
  2000. if (isBigNumber(number))
  2001. return number;
  2002. if (isString(number) && (number.indexOf('0x') === 0 || number.indexOf('-0x') === 0)) {
  2003. return new BigNumber(number.replace('0x',''), 16);
  2004. }
  2005. return new BigNumber(number.toString(10), 10);
  2006. };
  2007. /**
  2008. * Takes and input transforms it into bignumber and if it is negative value, into two's complement
  2009. *
  2010. * @method toTwosComplement
  2011. * @param {Number|String|BigNumber}
  2012. * @return {BigNumber}
  2013. */
  2014. var toTwosComplement = function (number) {
  2015. var bigNumber = toBigNumber(number);
  2016. if (bigNumber.lessThan(0)) {
  2017. return new BigNumber("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 16).plus(bigNumber).plus(1);
  2018. }
  2019. return bigNumber;
  2020. };
  2021. /**
  2022. * Checks if the given string is strictly an address
  2023. *
  2024. * @method isStrictAddress
  2025. * @param {String} address the given HEX adress
  2026. * @return {Boolean}
  2027. */
  2028. var isStrictAddress = function (address) {
  2029. return /^0x[0-9a-f]{40}$/i.test(address);
  2030. };
  2031. /**
  2032. * Checks if the given string is an address
  2033. *
  2034. * @method isAddress
  2035. * @param {String} address the given HEX adress
  2036. * @return {Boolean}
  2037. */
  2038. var isAddress = function (address) {
  2039. return /^(0x)?[0-9a-f]{40}$/i.test(address);
  2040. };
  2041. /**
  2042. * Transforms given string to valid 20 bytes-length addres with 0x prefix
  2043. *
  2044. * @method toAddress
  2045. * @param {String} address
  2046. * @return {String} formatted address
  2047. */
  2048. var toAddress = function (address) {
  2049. if (isStrictAddress(address)) {
  2050. return address;
  2051. }
  2052. if (/^[0-9a-f]{40}$/.test(address)) {
  2053. return '0x' + address;
  2054. }
  2055. return '0x' + padLeft(toHex(address).substr(2), 40);
  2056. };
  2057. /**
  2058. * Returns true if object is BigNumber, otherwise false
  2059. *
  2060. * @method isBigNumber
  2061. * @param {Object}
  2062. * @return {Boolean}
  2063. */
  2064. var isBigNumber = function (object) {
  2065. return object instanceof BigNumber ||
  2066. (object && object.constructor && object.constructor.name === 'BigNumber');
  2067. };
  2068. /**
  2069. * Returns true if object is string, otherwise false
  2070. *
  2071. * @method isString
  2072. * @param {Object}
  2073. * @return {Boolean}
  2074. */
  2075. var isString = function (object) {
  2076. return typeof object === 'string' ||
  2077. (object && object.constructor && object.constructor.name === 'String');
  2078. };
  2079. /**
  2080. * Returns true if object is function, otherwise false
  2081. *
  2082. * @method isFunction
  2083. * @param {Object}
  2084. * @return {Boolean}
  2085. */
  2086. var isFunction = function (object) {
  2087. return typeof object === 'function';
  2088. };
  2089. /**
  2090. * Returns true if object is Objet, otherwise false
  2091. *
  2092. * @method isObject
  2093. * @param {Object}
  2094. * @return {Boolean}
  2095. */
  2096. var isObject = function (object) {
  2097. return typeof object === 'object';
  2098. };
  2099. /**
  2100. * Returns true if object is boolean, otherwise false
  2101. *
  2102. * @method isBoolean
  2103. * @param {Object}
  2104. * @return {Boolean}
  2105. */
  2106. var isBoolean = function (object) {
  2107. return typeof object === 'boolean';
  2108. };
  2109. /**
  2110. * Returns true if object is array, otherwise false
  2111. *
  2112. * @method isArray
  2113. * @param {Object}
  2114. * @return {Boolean}
  2115. */
  2116. var isArray = function (object) {
  2117. return object instanceof Array;
  2118. };
  2119. /**
  2120. * Returns true if given string is valid json object
  2121. *
  2122. * @method isJson
  2123. * @param {String}
  2124. * @return {Boolean}
  2125. */
  2126. var isJson = function (str) {
  2127. try {
  2128. return !!JSON.parse(str);
  2129. } catch (e) {
  2130. return false;
  2131. }
  2132. };
  2133. module.exports = {
  2134. padLeft: padLeft,
  2135. padRight: padRight,
  2136. toHex: toHex,
  2137. toDecimal: toDecimal,
  2138. fromDecimal: fromDecimal,
  2139. toUtf8: toUtf8,
  2140. toAscii: toAscii,
  2141. fromUtf8: fromUtf8,
  2142. fromAscii: fromAscii,
  2143. transformToFullName: transformToFullName,
  2144. extractDisplayName: extractDisplayName,
  2145. extractTypeName: extractTypeName,
  2146. toWei: toWei,
  2147. fromWei: fromWei,
  2148. toBigNumber: toBigNumber,
  2149. toTwosComplement: toTwosComplement,
  2150. toAddress: toAddress,
  2151. isBigNumber: isBigNumber,
  2152. isStrictAddress: isStrictAddress,
  2153. isAddress: isAddress,
  2154. isFunction: isFunction,
  2155. isString: isString,
  2156. isObject: isObject,
  2157. isBoolean: isBoolean,
  2158. isArray: isArray,
  2159. isJson: isJson
  2160. };
  2161. },{"bignumber.js":"bignumber.js","utf8":83}],21:[function(require,module,exports){
  2162. module.exports={
  2163. "version": "0.15.1"
  2164. }
  2165. },{}],22:[function(require,module,exports){
  2166. /*
  2167. This file is part of web3.js.
  2168. web3.js is free software: you can redistribute it and/or modify
  2169. it under the terms of the GNU Lesser General Public License as published by
  2170. the Free Software Foundation, either version 3 of the License, or
  2171. (at your option) any later version.
  2172. web3.js is distributed in the hope that it will be useful,
  2173. but WITHOUT ANY WARRANTY; without even the implied warranty of
  2174. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  2175. GNU Lesser General Public License for more details.
  2176. You should have received a copy of the GNU Lesser General Public License
  2177. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  2178. */
  2179. /**
  2180. * @file web3.js
  2181. * @authors:
  2182. * Jeffrey Wilcke <jeff@ethdev.com>
  2183. * Marek Kotewicz <marek@ethdev.com>
  2184. * Marian Oancea <marian@ethdev.com>
  2185. * Fabian Vogelsteller <fabian@ethdev.com>
  2186. * Gav Wood <g@ethdev.com>
  2187. * @date 2014
  2188. */
  2189. var RequestManager = require('./web3/requestmanager');
  2190. var Iban = require('./web3/iban');
  2191. var Eth = require('./web3/methods/eth');
  2192. var DB = require('./web3/methods/db');
  2193. var Shh = require('./web3/methods/shh');
  2194. var Net = require('./web3/methods/net');
  2195. var Settings = require('./web3/settings');
  2196. var version = require('./version.json');
  2197. var utils = require('./utils/utils');
  2198. var sha3 = require('./utils/sha3');
  2199. var extend = require('./web3/extend');
  2200. var Batch = require('./web3/batch');
  2201. var Property = require('./web3/property');
  2202. var HttpProvider = require('./web3/httpprovider');
  2203. var IpcProvider = require('./web3/ipcprovider');
  2204. function Web3 (provider) {
  2205. this._requestManager = new RequestManager(provider);
  2206. this.currentProvider = provider;
  2207. this.eth = new Eth(this);
  2208. this.db = new DB(this);
  2209. this.shh = new Shh(this);
  2210. this.net = new Net(this);
  2211. this.settings = new Settings();
  2212. this.version = {
  2213. api: version.version
  2214. };
  2215. this.providers = {
  2216. HttpProvider: HttpProvider,
  2217. IpcProvider: IpcProvider
  2218. };
  2219. this._extend = extend(this);
  2220. this._extend({
  2221. properties: properties()
  2222. });
  2223. }
  2224. // expose providers on the class
  2225. Web3.providers = {
  2226. HttpProvider: HttpProvider,
  2227. IpcProvider: IpcProvider
  2228. };
  2229. Web3.prototype.setProvider = function (provider) {
  2230. this._requestManager.setProvider(provider);
  2231. this.currentProvider = provider;
  2232. };
  2233. Web3.prototype.reset = function (keepIsSyncing) {
  2234. this._requestManager.reset(keepIsSyncing);
  2235. this.settings = new Settings();
  2236. };
  2237. Web3.prototype.toHex = utils.toHex;
  2238. Web3.prototype.toAscii = utils.toAscii;
  2239. Web3.prototype.toUtf8 = utils.toUtf8;
  2240. Web3.prototype.fromAscii = utils.fromAscii;
  2241. Web3.prototype.fromUtf8 = utils.fromUtf8;
  2242. Web3.prototype.toDecimal = utils.toDecimal;
  2243. Web3.prototype.fromDecimal = utils.fromDecimal;
  2244. Web3.prototype.toBigNumber = utils.toBigNumber;
  2245. Web3.prototype.toWei = utils.toWei;
  2246. Web3.prototype.fromWei = utils.fromWei;
  2247. Web3.prototype.isAddress = utils.isAddress;
  2248. Web3.prototype.isIBAN = utils.isIBAN;
  2249. Web3.prototype.sha3 = sha3;
  2250. /**
  2251. * Transforms direct icap to address
  2252. */
  2253. Web3.prototype.fromICAP = function (icap) {
  2254. var iban = new Iban(icap);
  2255. return iban.address();
  2256. };
  2257. var properties = function () {
  2258. return [
  2259. new Property({
  2260. name: 'version.node',
  2261. getter: 'web3_clientVersion'
  2262. }),
  2263. new Property({
  2264. name: 'version.network',
  2265. getter: 'net_version',
  2266. inputFormatter: utils.toDecimal
  2267. }),
  2268. new Property({
  2269. name: 'version.ethereum',
  2270. getter: 'eth_protocolVersion',
  2271. inputFormatter: utils.toDecimal
  2272. }),
  2273. new Property({
  2274. name: 'version.whisper',
  2275. getter: 'shh_version',
  2276. inputFormatter: utils.toDecimal
  2277. })
  2278. ];
  2279. };
  2280. Web3.prototype.isConnected = function(){
  2281. return (this.currentProvider && this.currentProvider.isConnected());
  2282. };
  2283. Web3.prototype.createBatch = function () {
  2284. return new Batch(this);
  2285. };
  2286. module.exports = Web3;
  2287. },{"./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/shh":40,"./web3/property":43,"./web3/requestmanager":44,"./web3/settings":45}],23:[function(require,module,exports){
  2288. /*
  2289. This file is part of web3.js.
  2290. web3.js is free software: you can redistribute it and/or modify
  2291. it under the terms of the GNU Lesser General Public License as published by
  2292. the Free Software Foundation, either version 3 of the License, or
  2293. (at your option) any later version.
  2294. web3.js is distributed in the hope that it will be useful,
  2295. but WITHOUT ANY WARRANTY; without even the implied warranty of
  2296. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  2297. GNU Lesser General Public License for more details.
  2298. You should have received a copy of the GNU Lesser General Public License
  2299. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  2300. */
  2301. /**
  2302. * @file allevents.js
  2303. * @author Marek Kotewicz <marek@ethdev.com>
  2304. * @date 2014
  2305. */
  2306. var sha3 = require('../utils/sha3');
  2307. var SolidityEvent = require('./event');
  2308. var formatters = require('./formatters');
  2309. var utils = require('../utils/utils');
  2310. var Filter = require('./filter');
  2311. var watches = require('./methods/watches');
  2312. var AllSolidityEvents = function (requestManager, json, address) {
  2313. this._requestManager = requestManager;
  2314. this._json = json;
  2315. this._address = address;
  2316. };
  2317. AllSolidityEvents.prototype.encode = function (options) {
  2318. options = options || {};
  2319. var result = {};
  2320. ['fromBlock', 'toBlock'].filter(function (f) {
  2321. return options[f] !== undefined;
  2322. }).forEach(function (f) {
  2323. result[f] = formatters.inputBlockNumberFormatter(options[f]);
  2324. });
  2325. result.address = this._address;
  2326. return result;
  2327. };
  2328. AllSolidityEvents.prototype.decode = function (data) {
  2329. data.data = data.data || '';
  2330. data.topics = data.topics || [];
  2331. var eventTopic = data.topics[0].slice(2);
  2332. var match = this._json.filter(function (j) {
  2333. return eventTopic === sha3(utils.transformToFullName(j));
  2334. })[0];
  2335. if (!match) { // cannot find matching event?
  2336. console.warn('cannot find event for log');
  2337. return data;
  2338. }
  2339. var event = new SolidityEvent(this._requestManager, match, this._address);
  2340. return event.decode(data);
  2341. };
  2342. AllSolidityEvents.prototype.execute = function (options, callback) {
  2343. if (utils.isFunction(arguments[arguments.length - 1])) {
  2344. callback = arguments[arguments.length - 1];
  2345. if(arguments.length === 1)
  2346. options = null;
  2347. }
  2348. var o = this.encode(options);
  2349. var formatter = this.decode.bind(this);
  2350. return new Filter(this._requestManager, o, watches.eth(), formatter, callback);
  2351. };
  2352. AllSolidityEvents.prototype.attachToContract = function (contract) {
  2353. var execute = this.execute.bind(this);
  2354. contract.allEvents = execute;
  2355. };
  2356. module.exports = AllSolidityEvents;
  2357. },{"../utils/sha3":19,"../utils/utils":20,"./event":27,"./filter":29,"./formatters":30,"./methods/watches":41}],24:[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 batch.js
  2373. * @author Marek Kotewicz <marek@ethdev.com>
  2374. * @date 2015
  2375. */
  2376. var Jsonrpc = require('./jsonrpc');
  2377. var errors = require('./errors');
  2378. var Batch = function (web3) {
  2379. this.requestManager = web3._requestManager;
  2380. this.requests = [];
  2381. };
  2382. /**
  2383. * Should be called to add create new request to batch request
  2384. *
  2385. * @method add
  2386. * @param {Object} jsonrpc requet object
  2387. */
  2388. Batch.prototype.add = function (request) {
  2389. this.requests.push(request);
  2390. };
  2391. /**
  2392. * Should be called to execute batch request
  2393. *
  2394. * @method execute
  2395. */
  2396. Batch.prototype.execute = function () {
  2397. var requests = this.requests;
  2398. this.requestManager.sendBatch(requests, function (err, results) {
  2399. results = results || [];
  2400. requests.map(function (request, index) {
  2401. return results[index] || {};
  2402. }).forEach(function (result, index) {
  2403. if (requests[index].callback) {
  2404. if (!Jsonrpc.getInstance().isValidResponse(result)) {
  2405. return requests[index].callback(errors.InvalidResponse(result));
  2406. }
  2407. requests[index].callback(null, (requests[index].format ? requests[index].format(result.result) : result.result));
  2408. }
  2409. });
  2410. });
  2411. };
  2412. module.exports = Batch;
  2413. },{"./errors":26,"./jsonrpc":35}],25:[function(require,module,exports){
  2414. /*
  2415. This file is part of web3.js.
  2416. web3.js is free software: you can redistribute it and/or modify
  2417. it under the terms of the GNU Lesser General Public License as published by
  2418. the Free Software Foundation, either version 3 of the License, or
  2419. (at your option) any later version.
  2420. web3.js is distributed in the hope that it will be useful,
  2421. but WITHOUT ANY WARRANTY; without even the implied warranty of
  2422. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  2423. GNU Lesser General Public License for more details.
  2424. You should have received a copy of the GNU Lesser General Public License
  2425. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  2426. */
  2427. /**
  2428. * @file contract.js
  2429. * @author Marek Kotewicz <marek@ethdev.com>
  2430. * @date 2014
  2431. */
  2432. var utils = require('../utils/utils');
  2433. var coder = require('../solidity/coder');
  2434. var SolidityEvent = require('./event');
  2435. var SolidityFunction = require('./function');
  2436. var AllEvents = require('./allevents');
  2437. /**
  2438. * Should be called to encode constructor params
  2439. *
  2440. * @method encodeConstructorParams
  2441. * @param {Array} abi
  2442. * @param {Array} constructor params
  2443. */
  2444. var encodeConstructorParams = function (abi, params) {
  2445. return abi.filter(function (json) {
  2446. return json.type === 'constructor' && json.inputs.length === params.length;
  2447. }).map(function (json) {
  2448. return json.inputs.map(function (input) {
  2449. return input.type;
  2450. });
  2451. }).map(function (types) {
  2452. return coder.encodeParams(types, params);
  2453. })[0] || '';
  2454. };
  2455. /**
  2456. * Should be called to add functions to contract object
  2457. *
  2458. * @method addFunctionsToContract
  2459. * @param {Contract} contract
  2460. * @param {Array} abi
  2461. */
  2462. var addFunctionsToContract = function (contract) {
  2463. contract.abi.filter(function (json) {
  2464. return json.type === 'function';
  2465. }).map(function (json) {
  2466. return new SolidityFunction(contract._eth, json, contract.address);
  2467. }).forEach(function (f) {
  2468. f.attachToContract(contract);
  2469. });
  2470. };
  2471. /**
  2472. * Should be called to add events to contract object
  2473. *
  2474. * @method addEventsToContract
  2475. * @param {Contract} contract
  2476. * @param {Array} abi
  2477. */
  2478. var addEventsToContract = function (contract) {
  2479. var events = contract.abi.filter(function (json) {
  2480. return json.type === 'event';
  2481. });
  2482. var All = new AllEvents(contract._eth._requestManager, events, contract.address);
  2483. All.attachToContract(contract);
  2484. events.map(function (json) {
  2485. return new SolidityEvent(contract._eth._requestManager, json, contract.address);
  2486. }).forEach(function (e) {
  2487. e.attachToContract(contract);
  2488. });
  2489. };
  2490. /**
  2491. * Should be called to check if the contract gets properly deployed on the blockchain.
  2492. *
  2493. * @method checkForContractAddress
  2494. * @param {Object} contract
  2495. * @param {Function} callback
  2496. * @returns {Undefined}
  2497. */
  2498. var checkForContractAddress = function(contract, callback){
  2499. var count = 0,
  2500. callbackFired = false;
  2501. // wait for receipt
  2502. var filter = contract._eth.filter('latest', function(e){
  2503. if (!e && !callbackFired) {
  2504. count++;
  2505. // stop watching after 50 blocks (timeout)
  2506. if (count > 50) {
  2507. filter.stopWatching();
  2508. callbackFired = true;
  2509. if (callback)
  2510. callback(new Error('Contract transaction couldn\'t be found after 50 blocks'));
  2511. else
  2512. throw new Error('Contract transaction couldn\'t be found after 50 blocks');
  2513. } else {
  2514. contract._eth.getTransactionReceipt(contract.transactionHash, function(e, receipt){
  2515. if(receipt && !callbackFired) {
  2516. contract._eth.getCode(receipt.contractAddress, function(e, code){
  2517. /*jshint maxcomplexity: 6 */
  2518. if(callbackFired || !code)
  2519. return;
  2520. filter.stopWatching();
  2521. callbackFired = true;
  2522. if(code.length > 2) {
  2523. // console.log('Contract code deployed!');
  2524. contract.address = receipt.contractAddress;
  2525. // attach events and methods again after we have
  2526. addFunctionsToContract(contract);
  2527. addEventsToContract(contract);
  2528. // call callback for the second time
  2529. if(callback)
  2530. callback(null, contract);
  2531. } else {
  2532. if(callback)
  2533. callback(new Error('The contract code couldn\'t be stored, please check your gas amount.'));
  2534. else
  2535. throw new Error('The contract code couldn\'t be stored, please check your gas amount.');
  2536. }
  2537. });
  2538. }
  2539. });
  2540. }
  2541. }
  2542. });
  2543. };
  2544. /**
  2545. * Should be called to create new ContractFactory instance
  2546. *
  2547. * @method ContractFactory
  2548. * @param {Array} abi
  2549. */
  2550. var ContractFactory = function (eth, abi) {
  2551. this.eth = eth;
  2552. this.abi = abi;
  2553. this.new.getData = this.getData.bind(this);
  2554. };
  2555. /**
  2556. * Should be called to create new ContractFactory
  2557. *
  2558. * @method contract
  2559. * @param {Array} abi
  2560. * @returns {ContractFactory} new contract factory
  2561. */
  2562. //var contract = function (abi) {
  2563. //return new ContractFactory(abi);
  2564. //};
  2565. /**
  2566. * Should be called to create new contract on a blockchain
  2567. *
  2568. * @method new
  2569. * @param {Any} contract constructor param1 (optional)
  2570. * @param {Any} contract constructor param2 (optional)
  2571. * @param {Object} contract transaction object (required)
  2572. * @param {Function} callback
  2573. * @returns {Contract} returns contract instance
  2574. */
  2575. ContractFactory.prototype.new = function () {
  2576. var contract = new Contract(this.eth, this.abi);
  2577. // parse arguments
  2578. var options = {}; // required!
  2579. var callback;
  2580. var args = Array.prototype.slice.call(arguments);
  2581. if (utils.isFunction(args[args.length - 1])) {
  2582. callback = args.pop();
  2583. }
  2584. var last = args[args.length - 1];
  2585. if (utils.isObject(last) && !utils.isArray(last)) {
  2586. options = args.pop();
  2587. }
  2588. var bytes = encodeConstructorParams(this.abi, args);
  2589. options.data += bytes;
  2590. if (callback) {
  2591. // wait for the contract address adn check if the code was deployed
  2592. this.eth.sendTransaction(options, function (err, hash) {
  2593. if (err) {
  2594. callback(err);
  2595. } else {
  2596. // add the transaction hash
  2597. contract.transactionHash = hash;
  2598. // call callback for the first time
  2599. callback(null, contract);
  2600. checkForContractAddress(contract, callback);
  2601. }
  2602. });
  2603. } else {
  2604. var hash = this.eth.sendTransaction(options);
  2605. // add the transaction hash
  2606. contract.transactionHash = hash;
  2607. checkForContractAddress(contract);
  2608. }
  2609. return contract;
  2610. };
  2611. /**
  2612. * Should be called to get access to existing contract on a blockchain
  2613. *
  2614. * @method at
  2615. * @param {Address} contract address (required)
  2616. * @param {Function} callback {optional)
  2617. * @returns {Contract} returns contract if no callback was passed,
  2618. * otherwise calls callback function (err, contract)
  2619. */
  2620. ContractFactory.prototype.at = function (address, callback) {
  2621. var contract = new Contract(this.eth, this.abi, address);
  2622. // this functions are not part of prototype,
  2623. // because we dont want to spoil the interface
  2624. addFunctionsToContract(contract);
  2625. addEventsToContract(contract);
  2626. if (callback) {
  2627. callback(null, contract);
  2628. }
  2629. return contract;
  2630. };
  2631. /**
  2632. * Gets the data, which is data to deploy plus constructor params
  2633. *
  2634. * @method getData
  2635. */
  2636. ContractFactory.prototype.getData = function () {
  2637. var options = {}; // required!
  2638. var args = Array.prototype.slice.call(arguments);
  2639. var last = args[args.length - 1];
  2640. if (utils.isObject(last) && !utils.isArray(last)) {
  2641. options = args.pop();
  2642. }
  2643. var bytes = encodeConstructorParams(this.abi, args);
  2644. options.data += bytes;
  2645. return options.data;
  2646. };
  2647. /**
  2648. * Should be called to create new contract instance
  2649. *
  2650. * @method Contract
  2651. * @param {Array} abi
  2652. * @param {Address} contract address
  2653. */
  2654. var Contract = function (eth, abi, address) {
  2655. this._eth = eth;
  2656. this.transactionHash = null;
  2657. this.address = address;
  2658. this.abi = abi;
  2659. };
  2660. module.exports = ContractFactory;
  2661. },{"../solidity/coder":7,"../utils/utils":20,"./allevents":23,"./event":27,"./function":31}],26:[function(require,module,exports){
  2662. /*
  2663. This file is part of web3.js.
  2664. web3.js is free software: you can redistribute it and/or modify
  2665. it under the terms of the GNU Lesser General Public License as published by
  2666. the Free Software Foundation, either version 3 of the License, or
  2667. (at your option) any later version.
  2668. web3.js is distributed in the hope that it will be useful,
  2669. but WITHOUT ANY WARRANTY; without even the implied warranty of
  2670. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  2671. GNU Lesser General Public License for more details.
  2672. You should have received a copy of the GNU Lesser General Public License
  2673. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  2674. */
  2675. /**
  2676. * @file errors.js
  2677. * @author Marek Kotewicz <marek@ethdev.com>
  2678. * @date 2015
  2679. */
  2680. module.exports = {
  2681. InvalidNumberOfParams: function () {
  2682. return new Error('Invalid number of input parameters');
  2683. },
  2684. InvalidConnection: function (host){
  2685. return new Error('CONNECTION ERROR: Couldn\'t connect to node '+ host +'.');
  2686. },
  2687. InvalidProvider: function () {
  2688. return new Error('Provider not set or invalid');
  2689. },
  2690. InvalidResponse: function (result){
  2691. var message = !!result && !!result.error && !!result.error.message ? result.error.message : 'Invalid JSON RPC response: ' + JSON.stringify(result);
  2692. return new Error(message);
  2693. }
  2694. };
  2695. },{}],27:[function(require,module,exports){
  2696. /*
  2697. This file is part of web3.js.
  2698. web3.js is free software: you can redistribute it and/or modify
  2699. it under the terms of the GNU Lesser General Public License as published by
  2700. the Free Software Foundation, either version 3 of the License, or
  2701. (at your option) any later version.
  2702. web3.js is distributed in the hope that it will be useful,
  2703. but WITHOUT ANY WARRANTY; without even the implied warranty of
  2704. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  2705. GNU Lesser General Public License for more details.
  2706. You should have received a copy of the GNU Lesser General Public License
  2707. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  2708. */
  2709. /**
  2710. * @file event.js
  2711. * @author Marek Kotewicz <marek@ethdev.com>
  2712. * @date 2014
  2713. */
  2714. var utils = require('../utils/utils');
  2715. var coder = require('../solidity/coder');
  2716. var formatters = require('./formatters');
  2717. var sha3 = require('../utils/sha3');
  2718. var Filter = require('./filter');
  2719. var watches = require('./methods/watches');
  2720. /**
  2721. * This prototype should be used to create event filters
  2722. */
  2723. var SolidityEvent = function (requestManager, json, address) {
  2724. this._requestManager = requestManager;
  2725. this._params = json.inputs;
  2726. this._name = utils.transformToFullName(json);
  2727. this._address = address;
  2728. this._anonymous = json.anonymous;
  2729. };
  2730. /**
  2731. * Should be used to get filtered param types
  2732. *
  2733. * @method types
  2734. * @param {Bool} decide if returned typed should be indexed
  2735. * @return {Array} array of types
  2736. */
  2737. SolidityEvent.prototype.types = function (indexed) {
  2738. return this._params.filter(function (i) {
  2739. return i.indexed === indexed;
  2740. }).map(function (i) {
  2741. return i.type;
  2742. });
  2743. };
  2744. /**
  2745. * Should be used to get event display name
  2746. *
  2747. * @method displayName
  2748. * @return {String} event display name
  2749. */
  2750. SolidityEvent.prototype.displayName = function () {
  2751. return utils.extractDisplayName(this._name);
  2752. };
  2753. /**
  2754. * Should be used to get event type name
  2755. *
  2756. * @method typeName
  2757. * @return {String} event type name
  2758. */
  2759. SolidityEvent.prototype.typeName = function () {
  2760. return utils.extractTypeName(this._name);
  2761. };
  2762. /**
  2763. * Should be used to get event signature
  2764. *
  2765. * @method signature
  2766. * @return {String} event signature
  2767. */
  2768. SolidityEvent.prototype.signature = function () {
  2769. return sha3(this._name);
  2770. };
  2771. /**
  2772. * Should be used to encode indexed params and options to one final object
  2773. *
  2774. * @method encode
  2775. * @param {Object} indexed
  2776. * @param {Object} options
  2777. * @return {Object} everything combined together and encoded
  2778. */
  2779. SolidityEvent.prototype.encode = function (indexed, options) {
  2780. indexed = indexed || {};
  2781. options = options || {};
  2782. var result = {};
  2783. ['fromBlock', 'toBlock'].filter(function (f) {
  2784. return options[f] !== undefined;
  2785. }).forEach(function (f) {
  2786. result[f] = formatters.inputBlockNumberFormatter(options[f]);
  2787. });
  2788. result.topics = [];
  2789. result.address = this._address;
  2790. if (!this._anonymous) {
  2791. result.topics.push('0x' + this.signature());
  2792. }
  2793. var indexedTopics = this._params.filter(function (i) {
  2794. return i.indexed === true;
  2795. }).map(function (i) {
  2796. var value = indexed[i.name];
  2797. if (value === undefined || value === null) {
  2798. return null;
  2799. }
  2800. if (utils.isArray(value)) {
  2801. return value.map(function (v) {
  2802. return '0x' + coder.encodeParam(i.type, v);
  2803. });
  2804. }
  2805. return '0x' + coder.encodeParam(i.type, value);
  2806. });
  2807. result.topics = result.topics.concat(indexedTopics);
  2808. return result;
  2809. };
  2810. /**
  2811. * Should be used to decode indexed params and options
  2812. *
  2813. * @method decode
  2814. * @param {Object} data
  2815. * @return {Object} result object with decoded indexed && not indexed params
  2816. */
  2817. SolidityEvent.prototype.decode = function (data) {
  2818. data.data = data.data || '';
  2819. data.topics = data.topics || [];
  2820. var argTopics = this._anonymous ? data.topics : data.topics.slice(1);
  2821. var indexedData = argTopics.map(function (topics) { return topics.slice(2); }).join("");
  2822. var indexedParams = coder.decodeParams(this.types(true), indexedData);
  2823. var notIndexedData = data.data.slice(2);
  2824. var notIndexedParams = coder.decodeParams(this.types(false), notIndexedData);
  2825. var result = formatters.outputLogFormatter(data);
  2826. result.event = this.displayName();
  2827. result.address = data.address;
  2828. result.args = this._params.reduce(function (acc, current) {
  2829. acc[current.name] = current.indexed ? indexedParams.shift() : notIndexedParams.shift();
  2830. return acc;
  2831. }, {});
  2832. delete result.data;
  2833. delete result.topics;
  2834. return result;
  2835. };
  2836. /**
  2837. * Should be used to create new filter object from event
  2838. *
  2839. * @method execute
  2840. * @param {Object} indexed
  2841. * @param {Object} options
  2842. * @return {Object} filter object
  2843. */
  2844. SolidityEvent.prototype.execute = function (indexed, options, callback) {
  2845. if (utils.isFunction(arguments[arguments.length - 1])) {
  2846. callback = arguments[arguments.length - 1];
  2847. if(arguments.length === 2)
  2848. options = null;
  2849. if(arguments.length === 1) {
  2850. options = null;
  2851. indexed = {};
  2852. }
  2853. }
  2854. var o = this.encode(indexed, options);
  2855. var formatter = this.decode.bind(this);
  2856. return new Filter(this._requestManager, o, watches.eth(), formatter, callback);
  2857. };
  2858. /**
  2859. * Should be used to attach event to contract object
  2860. *
  2861. * @method attachToContract
  2862. * @param {Contract}
  2863. */
  2864. SolidityEvent.prototype.attachToContract = function (contract) {
  2865. var execute = this.execute.bind(this);
  2866. var displayName = this.displayName();
  2867. if (!contract[displayName]) {
  2868. contract[displayName] = execute;
  2869. }
  2870. contract[displayName][this.typeName()] = this.execute.bind(this, contract);
  2871. };
  2872. module.exports = SolidityEvent;
  2873. },{"../solidity/coder":7,"../utils/sha3":19,"../utils/utils":20,"./filter":29,"./formatters":30,"./methods/watches":41}],28:[function(require,module,exports){
  2874. var formatters = require('./formatters');
  2875. var utils = require('./../utils/utils');
  2876. var Method = require('./method');
  2877. var Property = require('./property');
  2878. // TODO: refactor, so the input params are not altered.
  2879. // it's necessary to make same 'extension' work with multiple providers
  2880. var extend = function (web3) {
  2881. /* jshint maxcomplexity:5 */
  2882. var ex = function (extension) {
  2883. var extendedObject;
  2884. if (extension.property) {
  2885. if (!web3[extension.property]) {
  2886. web3[extension.property] = {};
  2887. }
  2888. extendedObject = web3[extension.property];
  2889. } else {
  2890. extendedObject = web3;
  2891. }
  2892. if (extension.methods) {
  2893. extension.methods.forEach(function (method) {
  2894. method.attachToObject(extendedObject);
  2895. method.setRequestManager(web3._requestManager);
  2896. });
  2897. }
  2898. if (extension.properties) {
  2899. extension.properties.forEach(function (property) {
  2900. property.attachToObject(extendedObject);
  2901. property.setRequestManager(web3._requestManager);
  2902. });
  2903. }
  2904. };
  2905. ex.formatters = formatters;
  2906. ex.utils = utils;
  2907. ex.Method = Method;
  2908. ex.Property = Property;
  2909. return ex;
  2910. };
  2911. module.exports = extend;
  2912. },{"./../utils/utils":20,"./formatters":30,"./method":36,"./property":43}],29:[function(require,module,exports){
  2913. /*
  2914. This file is part of web3.js.
  2915. web3.js is free software: you can redistribute it and/or modify
  2916. it under the terms of the GNU Lesser General Public License as published by
  2917. the Free Software Foundation, either version 3 of the License, or
  2918. (at your option) any later version.
  2919. web3.js is distributed in the hope that it will be useful,
  2920. but WITHOUT ANY WARRANTY; without even the implied warranty of
  2921. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  2922. GNU Lesser General Public License for more details.
  2923. You should have received a copy of the GNU Lesser General Public License
  2924. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  2925. */
  2926. /** @file filter.js
  2927. * @authors:
  2928. * Jeffrey Wilcke <jeff@ethdev.com>
  2929. * Marek Kotewicz <marek@ethdev.com>
  2930. * Marian Oancea <marian@ethdev.com>
  2931. * Fabian Vogelsteller <fabian@ethdev.com>
  2932. * Gav Wood <g@ethdev.com>
  2933. * @date 2014
  2934. */
  2935. var formatters = require('./formatters');
  2936. var utils = require('../utils/utils');
  2937. /**
  2938. * Converts a given topic to a hex string, but also allows null values.
  2939. *
  2940. * @param {Mixed} value
  2941. * @return {String}
  2942. */
  2943. var toTopic = function(value){
  2944. if(value === null || typeof value === 'undefined')
  2945. return null;
  2946. value = String(value);
  2947. if(value.indexOf('0x') === 0)
  2948. return value;
  2949. else
  2950. return utils.fromUtf8(value);
  2951. };
  2952. /// This method should be called on options object, to verify deprecated properties && lazy load dynamic ones
  2953. /// @param should be string or object
  2954. /// @returns options string or object
  2955. var getOptions = function (options) {
  2956. if (utils.isString(options)) {
  2957. return options;
  2958. }
  2959. options = options || {};
  2960. // make sure topics, get converted to hex
  2961. options.topics = options.topics || [];
  2962. options.topics = options.topics.map(function(topic){
  2963. return (utils.isArray(topic)) ? topic.map(toTopic) : toTopic(topic);
  2964. });
  2965. return {
  2966. topics: options.topics,
  2967. from: options.from,
  2968. to: options.to,
  2969. address: options.address,
  2970. fromBlock: formatters.inputBlockNumberFormatter(options.fromBlock),
  2971. toBlock: formatters.inputBlockNumberFormatter(options.toBlock)
  2972. };
  2973. };
  2974. /**
  2975. Adds the callback and sets up the methods, to iterate over the results.
  2976. @method getLogsAtStart
  2977. @param {Object} self
  2978. @param {funciton}
  2979. */
  2980. var getLogsAtStart = function(self, callback){
  2981. // call getFilterLogs for the first watch callback start
  2982. if (!utils.isString(self.options)) {
  2983. self.get(function (err, messages) {
  2984. // don't send all the responses to all the watches again... just to self one
  2985. if (err) {
  2986. callback(err);
  2987. }
  2988. if(utils.isArray(messages)) {
  2989. messages.forEach(function (message) {
  2990. callback(null, message);
  2991. });
  2992. }
  2993. });
  2994. }
  2995. };
  2996. /**
  2997. Adds the callback and sets up the methods, to iterate over the results.
  2998. @method pollFilter
  2999. @param {Object} self
  3000. */
  3001. var pollFilter = function(self) {
  3002. var onMessage = function (error, messages) {
  3003. if (error) {
  3004. return self.callbacks.forEach(function (callback) {
  3005. callback(error);
  3006. });
  3007. }
  3008. if(utils.isArray(messages)) {
  3009. messages.forEach(function (message) {
  3010. message = self.formatter ? self.formatter(message) : message;
  3011. self.callbacks.forEach(function (callback) {
  3012. callback(null, message);
  3013. });
  3014. });
  3015. }
  3016. };
  3017. self.requestManager.startPolling({
  3018. method: self.implementation.poll.call,
  3019. params: [self.filterId],
  3020. }, self.filterId, onMessage, self.stopWatching.bind(self));
  3021. };
  3022. var Filter = function (requestManager, options, methods, formatter, callback) {
  3023. var self = this;
  3024. var implementation = {};
  3025. methods.forEach(function (method) {
  3026. method.setRequestManager(requestManager);
  3027. method.attachToObject(implementation);
  3028. });
  3029. this.requestManager = requestManager;
  3030. this.options = getOptions(options);
  3031. this.implementation = implementation;
  3032. this.filterId = null;
  3033. this.callbacks = [];
  3034. this.getLogsCallbacks = [];
  3035. this.pollFilters = [];
  3036. this.formatter = formatter;
  3037. this.implementation.newFilter(this.options, function(error, id){
  3038. if(error) {
  3039. self.callbacks.forEach(function(cb){
  3040. cb(error);
  3041. });
  3042. } else {
  3043. self.filterId = id;
  3044. // check if there are get pending callbacks as a consequence
  3045. // of calling get() with filterId unassigned.
  3046. self.getLogsCallbacks.forEach(function (cb){
  3047. self.get(cb);
  3048. });
  3049. self.getLogsCallbacks = [];
  3050. // get filter logs for the already existing watch calls
  3051. self.callbacks.forEach(function(cb){
  3052. getLogsAtStart(self, cb);
  3053. });
  3054. if(self.callbacks.length > 0)
  3055. pollFilter(self);
  3056. // start to watch immediately
  3057. if(callback) {
  3058. return self.watch(callback);
  3059. }
  3060. }
  3061. });
  3062. return this;
  3063. };
  3064. Filter.prototype.watch = function (callback) {
  3065. this.callbacks.push(callback);
  3066. if(this.filterId) {
  3067. getLogsAtStart(this, callback);
  3068. pollFilter(this);
  3069. }
  3070. return this;
  3071. };
  3072. Filter.prototype.stopWatching = function () {
  3073. this.requestManager.stopPolling(this.filterId);
  3074. // remove filter async
  3075. this.implementation.uninstallFilter(this.filterId, function(){});
  3076. this.callbacks = [];
  3077. };
  3078. Filter.prototype.get = function (callback) {
  3079. var self = this;
  3080. if (utils.isFunction(callback)) {
  3081. if (this.filterId === null) {
  3082. // If filterId is not set yet, call it back
  3083. // when newFilter() assigns it.
  3084. this.getLogsCallbacks.push(callback);
  3085. } else {
  3086. this.implementation.getLogs(this.filterId, function(err, res){
  3087. if (err) {
  3088. callback(err);
  3089. } else {
  3090. callback(null, res.map(function (log) {
  3091. return self.formatter ? self.formatter(log) : log;
  3092. }));
  3093. }
  3094. });
  3095. }
  3096. } else {
  3097. if (this.filterId === null) {
  3098. throw new Error('Filter ID Error: filter().get() can\'t be chained synchronous, please provide a callback for the get() method.');
  3099. }
  3100. var logs = this.implementation.getLogs(this.filterId);
  3101. return logs.map(function (log) {
  3102. return self.formatter ? self.formatter(log) : log;
  3103. });
  3104. }
  3105. return this;
  3106. };
  3107. module.exports = Filter;
  3108. },{"../utils/utils":20,"./formatters":30}],30:[function(require,module,exports){
  3109. /*
  3110. This file is part of web3.js.
  3111. web3.js is free software: you can redistribute it and/or modify
  3112. it under the terms of the GNU Lesser General Public License as published by
  3113. the Free Software Foundation, either version 3 of the License, or
  3114. (at your option) any later version.
  3115. web3.js is distributed in the hope that it will be useful,
  3116. but WITHOUT ANY WARRANTY; without even the implied warranty of
  3117. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  3118. GNU Lesser General Public License for more details.
  3119. You should have received a copy of the GNU Lesser General Public License
  3120. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  3121. */
  3122. /**
  3123. * @file formatters.js
  3124. * @author Marek Kotewicz <marek@ethdev.com>
  3125. * @author Fabian Vogelsteller <fabian@ethdev.com>
  3126. * @date 2015
  3127. */
  3128. var utils = require('../utils/utils');
  3129. var config = require('../utils/config');
  3130. var Iban = require('./iban');
  3131. /**
  3132. * Should the format output to a big number
  3133. *
  3134. * @method outputBigNumberFormatter
  3135. * @param {String|Number|BigNumber}
  3136. * @returns {BigNumber} object
  3137. */
  3138. var outputBigNumberFormatter = function (number) {
  3139. return utils.toBigNumber(number);
  3140. };
  3141. var isPredefinedBlockNumber = function (blockNumber) {
  3142. return blockNumber === 'latest' || blockNumber === 'pending' || blockNumber === 'earliest';
  3143. };
  3144. var inputDefaultBlockNumberFormatter = function (blockNumber) {
  3145. if (blockNumber === undefined) {
  3146. return config.defaultBlock;
  3147. }
  3148. return inputBlockNumberFormatter(blockNumber);
  3149. };
  3150. var inputBlockNumberFormatter = function (blockNumber) {
  3151. if (blockNumber === undefined) {
  3152. return undefined;
  3153. } else if (isPredefinedBlockNumber(blockNumber)) {
  3154. return blockNumber;
  3155. }
  3156. return utils.toHex(blockNumber);
  3157. };
  3158. /**
  3159. * Formats the input of a transaction and converts all values to HEX
  3160. *
  3161. * @method inputCallFormatter
  3162. * @param {Object} transaction options
  3163. * @returns object
  3164. */
  3165. var inputCallFormatter = function (options){
  3166. options.from = options.from || config.defaultAccount;
  3167. if (options.from) {
  3168. options.from = inputAddressFormatter(options.from);
  3169. }
  3170. if (options.to) { // it might be contract creation
  3171. options.to = inputAddressFormatter(options.to);
  3172. }
  3173. ['gasPrice', 'gas', 'value', 'nonce'].filter(function (key) {
  3174. return options[key] !== undefined;
  3175. }).forEach(function(key){
  3176. options[key] = utils.fromDecimal(options[key]);
  3177. });
  3178. return options;
  3179. };
  3180. /**
  3181. * Formats the input of a transaction and converts all values to HEX
  3182. *
  3183. * @method inputTransactionFormatter
  3184. * @param {Object} transaction options
  3185. * @returns object
  3186. */
  3187. var inputTransactionFormatter = function (options){
  3188. options.from = options.from || config.defaultAccount;
  3189. options.from = inputAddressFormatter(options.from);
  3190. if (options.to) { // it might be contract creation
  3191. options.to = inputAddressFormatter(options.to);
  3192. }
  3193. ['gasPrice', 'gas', 'value', 'nonce'].filter(function (key) {
  3194. return options[key] !== undefined;
  3195. }).forEach(function(key){
  3196. options[key] = utils.fromDecimal(options[key]);
  3197. });
  3198. return options;
  3199. };
  3200. /**
  3201. * Formats the output of a transaction to its proper values
  3202. *
  3203. * @method outputTransactionFormatter
  3204. * @param {Object} tx
  3205. * @returns {Object}
  3206. */
  3207. var outputTransactionFormatter = function (tx){
  3208. if(tx.blockNumber !== null)
  3209. tx.blockNumber = utils.toDecimal(tx.blockNumber);
  3210. if(tx.transactionIndex !== null)
  3211. tx.transactionIndex = utils.toDecimal(tx.transactionIndex);
  3212. tx.nonce = utils.toDecimal(tx.nonce);
  3213. tx.gas = utils.toDecimal(tx.gas);
  3214. tx.gasPrice = utils.toBigNumber(tx.gasPrice);
  3215. tx.value = utils.toBigNumber(tx.value);
  3216. return tx;
  3217. };
  3218. /**
  3219. * Formats the output of a transaction receipt to its proper values
  3220. *
  3221. * @method outputTransactionReceiptFormatter
  3222. * @param {Object} receipt
  3223. * @returns {Object}
  3224. */
  3225. var outputTransactionReceiptFormatter = function (receipt){
  3226. if(receipt.blockNumber !== null)
  3227. receipt.blockNumber = utils.toDecimal(receipt.blockNumber);
  3228. if(receipt.transactionIndex !== null)
  3229. receipt.transactionIndex = utils.toDecimal(receipt.transactionIndex);
  3230. receipt.cumulativeGasUsed = utils.toDecimal(receipt.cumulativeGasUsed);
  3231. receipt.gasUsed = utils.toDecimal(receipt.gasUsed);
  3232. if(utils.isArray(receipt.logs)) {
  3233. receipt.logs = receipt.logs.map(function(log){
  3234. return outputLogFormatter(log);
  3235. });
  3236. }
  3237. return receipt;
  3238. };
  3239. /**
  3240. * Formats the output of a block to its proper values
  3241. *
  3242. * @method outputBlockFormatter
  3243. * @param {Object} block
  3244. * @returns {Object}
  3245. */
  3246. var outputBlockFormatter = function(block) {
  3247. // transform to number
  3248. block.gasLimit = utils.toDecimal(block.gasLimit);
  3249. block.gasUsed = utils.toDecimal(block.gasUsed);
  3250. block.size = utils.toDecimal(block.size);
  3251. block.timestamp = utils.toDecimal(block.timestamp);
  3252. if(block.number !== null)
  3253. block.number = utils.toDecimal(block.number);
  3254. block.difficulty = utils.toBigNumber(block.difficulty);
  3255. block.totalDifficulty = utils.toBigNumber(block.totalDifficulty);
  3256. if (utils.isArray(block.transactions)) {
  3257. block.transactions.forEach(function(item){
  3258. if(!utils.isString(item))
  3259. return outputTransactionFormatter(item);
  3260. });
  3261. }
  3262. return block;
  3263. };
  3264. /**
  3265. * Formats the output of a log
  3266. *
  3267. * @method outputLogFormatter
  3268. * @param {Object} log object
  3269. * @returns {Object} log
  3270. */
  3271. var outputLogFormatter = function(log) {
  3272. if(log.blockNumber !== null)
  3273. log.blockNumber = utils.toDecimal(log.blockNumber);
  3274. if(log.transactionIndex !== null)
  3275. log.transactionIndex = utils.toDecimal(log.transactionIndex);
  3276. if(log.logIndex !== null)
  3277. log.logIndex = utils.toDecimal(log.logIndex);
  3278. return log;
  3279. };
  3280. /**
  3281. * Formats the input of a whisper post and converts all values to HEX
  3282. *
  3283. * @method inputPostFormatter
  3284. * @param {Object} transaction object
  3285. * @returns {Object}
  3286. */
  3287. var inputPostFormatter = function(post) {
  3288. // post.payload = utils.toHex(post.payload);
  3289. post.ttl = utils.fromDecimal(post.ttl);
  3290. post.workToProve = utils.fromDecimal(post.workToProve);
  3291. post.priority = utils.fromDecimal(post.priority);
  3292. // fallback
  3293. if (!utils.isArray(post.topics)) {
  3294. post.topics = post.topics ? [post.topics] : [];
  3295. }
  3296. // format the following options
  3297. post.topics = post.topics.map(function(topic){
  3298. // convert only if not hex
  3299. return (topic.indexOf('0x') === 0) ? topic : utils.fromUtf8(topic);
  3300. });
  3301. return post;
  3302. };
  3303. /**
  3304. * Formats the output of a received post message
  3305. *
  3306. * @method outputPostFormatter
  3307. * @param {Object}
  3308. * @returns {Object}
  3309. */
  3310. var outputPostFormatter = function(post){
  3311. post.expiry = utils.toDecimal(post.expiry);
  3312. post.sent = utils.toDecimal(post.sent);
  3313. post.ttl = utils.toDecimal(post.ttl);
  3314. post.workProved = utils.toDecimal(post.workProved);
  3315. // post.payloadRaw = post.payload;
  3316. // post.payload = utils.toAscii(post.payload);
  3317. // if (utils.isJson(post.payload)) {
  3318. // post.payload = JSON.parse(post.payload);
  3319. // }
  3320. // format the following options
  3321. if (!post.topics) {
  3322. post.topics = [];
  3323. }
  3324. post.topics = post.topics.map(function(topic){
  3325. return utils.toAscii(topic);
  3326. });
  3327. return post;
  3328. };
  3329. var inputAddressFormatter = function (address) {
  3330. var iban = new Iban(address);
  3331. if (iban.isValid() && iban.isDirect()) {
  3332. return '0x' + iban.address();
  3333. } else if (utils.isStrictAddress(address)) {
  3334. return address;
  3335. } else if (utils.isAddress(address)) {
  3336. return '0x' + address;
  3337. }
  3338. throw 'invalid address';
  3339. };
  3340. var outputSyncingFormatter = function(result) {
  3341. result.startingBlock = utils.toDecimal(result.startingBlock);
  3342. result.currentBlock = utils.toDecimal(result.currentBlock);
  3343. result.highestBlock = utils.toDecimal(result.highestBlock);
  3344. result.pulledStates = utils.toDecimal(result.pulledStates);
  3345. result.knownStates = utils.toDecimal(result.knownStates);
  3346. return result;
  3347. };
  3348. module.exports = {
  3349. inputDefaultBlockNumberFormatter: inputDefaultBlockNumberFormatter,
  3350. inputBlockNumberFormatter: inputBlockNumberFormatter,
  3351. inputCallFormatter: inputCallFormatter,
  3352. inputTransactionFormatter: inputTransactionFormatter,
  3353. inputAddressFormatter: inputAddressFormatter,
  3354. inputPostFormatter: inputPostFormatter,
  3355. outputBigNumberFormatter: outputBigNumberFormatter,
  3356. outputTransactionFormatter: outputTransactionFormatter,
  3357. outputTransactionReceiptFormatter: outputTransactionReceiptFormatter,
  3358. outputBlockFormatter: outputBlockFormatter,
  3359. outputLogFormatter: outputLogFormatter,
  3360. outputPostFormatter: outputPostFormatter,
  3361. outputSyncingFormatter: outputSyncingFormatter
  3362. };
  3363. },{"../utils/config":18,"../utils/utils":20,"./iban":33}],31:[function(require,module,exports){
  3364. /*
  3365. This file is part of web3.js.
  3366. web3.js is free software: you can redistribute it and/or modify
  3367. it under the terms of the GNU Lesser General Public License as published by
  3368. the Free Software Foundation, either version 3 of the License, or
  3369. (at your option) any later version.
  3370. web3.js is distributed in the hope that it will be useful,
  3371. but WITHOUT ANY WARRANTY; without even the implied warranty of
  3372. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  3373. GNU Lesser General Public License for more details.
  3374. You should have received a copy of the GNU Lesser General Public License
  3375. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  3376. */
  3377. /**
  3378. * @file function.js
  3379. * @author Marek Kotewicz <marek@ethdev.com>
  3380. * @date 2015
  3381. */
  3382. var coder = require('../solidity/coder');
  3383. var utils = require('../utils/utils');
  3384. var formatters = require('./formatters');
  3385. var sha3 = require('../utils/sha3');
  3386. /**
  3387. * This prototype should be used to call/sendTransaction to solidity functions
  3388. */
  3389. var SolidityFunction = function (eth, json, address) {
  3390. this._eth = eth;
  3391. this._inputTypes = json.inputs.map(function (i) {
  3392. return i.type;
  3393. });
  3394. this._outputTypes = json.outputs.map(function (i) {
  3395. return i.type;
  3396. });
  3397. this._constant = json.constant;
  3398. this._name = utils.transformToFullName(json);
  3399. this._address = address;
  3400. };
  3401. SolidityFunction.prototype.extractCallback = function (args) {
  3402. if (utils.isFunction(args[args.length - 1])) {
  3403. return args.pop(); // modify the args array!
  3404. }
  3405. };
  3406. SolidityFunction.prototype.extractDefaultBlock = function (args) {
  3407. if (args.length > this._inputTypes.length && !utils.isObject(args[args.length -1])) {
  3408. return formatters.inputDefaultBlockNumberFormatter(args.pop()); // modify the args array!
  3409. }
  3410. };
  3411. /**
  3412. * Should be used to create payload from arguments
  3413. *
  3414. * @method toPayload
  3415. * @param {Array} solidity function params
  3416. * @param {Object} optional payload options
  3417. */
  3418. SolidityFunction.prototype.toPayload = function (args) {
  3419. var options = {};
  3420. if (args.length > this._inputTypes.length && utils.isObject(args[args.length -1])) {
  3421. options = args[args.length - 1];
  3422. }
  3423. options.to = this._address;
  3424. options.data = '0x' + this.signature() + coder.encodeParams(this._inputTypes, args);
  3425. return options;
  3426. };
  3427. /**
  3428. * Should be used to get function signature
  3429. *
  3430. * @method signature
  3431. * @return {String} function signature
  3432. */
  3433. SolidityFunction.prototype.signature = function () {
  3434. return sha3(this._name).slice(0, 8);
  3435. };
  3436. SolidityFunction.prototype.unpackOutput = function (output) {
  3437. if (!output) {
  3438. return;
  3439. }
  3440. output = output.length >= 2 ? output.slice(2) : output;
  3441. var result = coder.decodeParams(this._outputTypes, output);
  3442. return result.length === 1 ? result[0] : result;
  3443. };
  3444. /**
  3445. * Calls a contract function.
  3446. *
  3447. * @method call
  3448. * @param {...Object} Contract function arguments
  3449. * @param {function} If the last argument is a function, the contract function
  3450. * call will be asynchronous, and the callback will be passed the
  3451. * error and result.
  3452. * @return {String} output bytes
  3453. */
  3454. SolidityFunction.prototype.call = function () {
  3455. var args = Array.prototype.slice.call(arguments).filter(function (a) {return a !== undefined; });
  3456. var callback = this.extractCallback(args);
  3457. var defaultBlock = this.extractDefaultBlock(args);
  3458. var payload = this.toPayload(args);
  3459. if (!callback) {
  3460. var output = this._eth.call(payload, defaultBlock);
  3461. return this.unpackOutput(output);
  3462. }
  3463. var self = this;
  3464. this._eth.call(payload, defaultBlock, function (error, output) {
  3465. callback(error, self.unpackOutput(output));
  3466. });
  3467. };
  3468. /**
  3469. * Should be used to sendTransaction to solidity function
  3470. *
  3471. * @method sendTransaction
  3472. */
  3473. SolidityFunction.prototype.sendTransaction = function () {
  3474. var args = Array.prototype.slice.call(arguments).filter(function (a) {return a !== undefined; });
  3475. var callback = this.extractCallback(args);
  3476. var payload = this.toPayload(args);
  3477. if (!callback) {
  3478. return this._eth.sendTransaction(payload);
  3479. }
  3480. this._eth.sendTransaction(payload, callback);
  3481. };
  3482. /**
  3483. * Should be used to estimateGas of solidity function
  3484. *
  3485. * @method estimateGas
  3486. */
  3487. SolidityFunction.prototype.estimateGas = function () {
  3488. var args = Array.prototype.slice.call(arguments);
  3489. var callback = this.extractCallback(args);
  3490. var payload = this.toPayload(args);
  3491. if (!callback) {
  3492. return this._eth.estimateGas(payload);
  3493. }
  3494. this._eth.estimateGas(payload, callback);
  3495. };
  3496. /**
  3497. * Return the encoded data of the call
  3498. *
  3499. * @method getData
  3500. * @return {String} the encoded data
  3501. */
  3502. SolidityFunction.prototype.getData = function () {
  3503. var args = Array.prototype.slice.call(arguments);
  3504. var payload = this.toPayload(args);
  3505. return payload.data;
  3506. };
  3507. /**
  3508. * Should be used to get function display name
  3509. *
  3510. * @method displayName
  3511. * @return {String} display name of the function
  3512. */
  3513. SolidityFunction.prototype.displayName = function () {
  3514. return utils.extractDisplayName(this._name);
  3515. };
  3516. /**
  3517. * Should be used to get function type name
  3518. *
  3519. * @method typeName
  3520. * @return {String} type name of the function
  3521. */
  3522. SolidityFunction.prototype.typeName = function () {
  3523. return utils.extractTypeName(this._name);
  3524. };
  3525. /**
  3526. * Should be called to get rpc requests from solidity function
  3527. *
  3528. * @method request
  3529. * @returns {Object}
  3530. */
  3531. SolidityFunction.prototype.request = function () {
  3532. var args = Array.prototype.slice.call(arguments);
  3533. var callback = this.extractCallback(args);
  3534. var payload = this.toPayload(args);
  3535. var format = this.unpackOutput.bind(this);
  3536. return {
  3537. method: this._constant ? 'eth_call' : 'eth_sendTransaction',
  3538. callback: callback,
  3539. params: [payload],
  3540. format: format
  3541. };
  3542. };
  3543. /**
  3544. * Should be called to execute function
  3545. *
  3546. * @method execute
  3547. */
  3548. SolidityFunction.prototype.execute = function () {
  3549. var transaction = !this._constant;
  3550. // send transaction
  3551. if (transaction) {
  3552. return this.sendTransaction.apply(this, Array.prototype.slice.call(arguments));
  3553. }
  3554. // call
  3555. return this.call.apply(this, Array.prototype.slice.call(arguments));
  3556. };
  3557. /**
  3558. * Should be called to attach function to contract
  3559. *
  3560. * @method attachToContract
  3561. * @param {Contract}
  3562. */
  3563. SolidityFunction.prototype.attachToContract = function (contract) {
  3564. var execute = this.execute.bind(this);
  3565. execute.request = this.request.bind(this);
  3566. execute.call = this.call.bind(this);
  3567. execute.sendTransaction = this.sendTransaction.bind(this);
  3568. execute.estimateGas = this.estimateGas.bind(this);
  3569. execute.getData = this.getData.bind(this);
  3570. var displayName = this.displayName();
  3571. if (!contract[displayName]) {
  3572. contract[displayName] = execute;
  3573. }
  3574. contract[displayName][this.typeName()] = execute; // circular!!!!
  3575. };
  3576. module.exports = SolidityFunction;
  3577. },{"../solidity/coder":7,"../utils/sha3":19,"../utils/utils":20,"./formatters":30}],32:[function(require,module,exports){
  3578. /*
  3579. This file is part of web3.js.
  3580. web3.js is free software: you can redistribute it and/or modify
  3581. it under the terms of the GNU Lesser General Public License as published by
  3582. the Free Software Foundation, either version 3 of the License, or
  3583. (at your option) any later version.
  3584. web3.js is distributed in the hope that it will be useful,
  3585. but WITHOUT ANY WARRANTY; without even the implied warranty of
  3586. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  3587. GNU Lesser General Public License for more details.
  3588. You should have received a copy of the GNU Lesser General Public License
  3589. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  3590. */
  3591. /** @file httpprovider.js
  3592. * @authors:
  3593. * Marek Kotewicz <marek@ethdev.com>
  3594. * Marian Oancea <marian@ethdev.com>
  3595. * Fabian Vogelsteller <fabian@ethdev.com>
  3596. * @date 2015
  3597. */
  3598. "use strict";
  3599. var errors = require('./errors');
  3600. // workaround to use httpprovider in different envs
  3601. var XMLHttpRequest; // jshint ignore: line
  3602. // meteor server environment
  3603. if (typeof Meteor !== 'undefined' && Meteor.isServer) { // jshint ignore: line
  3604. XMLHttpRequest = Npm.require('xmlhttprequest').XMLHttpRequest; // jshint ignore: line
  3605. // browser
  3606. } else if (typeof window !== 'undefined' && window.XMLHttpRequest) {
  3607. XMLHttpRequest = window.XMLHttpRequest; // jshint ignore: line
  3608. // node
  3609. } else {
  3610. XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest; // jshint ignore: line
  3611. }
  3612. /**
  3613. * HttpProvider should be used to send rpc calls over http
  3614. */
  3615. var HttpProvider = function (host) {
  3616. this.host = host || 'http://localhost:8545';
  3617. };
  3618. /**
  3619. * Should be called to prepare new XMLHttpRequest
  3620. *
  3621. * @method prepareRequest
  3622. * @param {Boolean} true if request should be async
  3623. * @return {XMLHttpRequest} object
  3624. */
  3625. HttpProvider.prototype.prepareRequest = function (async) {
  3626. var request = new XMLHttpRequest();
  3627. request.open('POST', this.host, async);
  3628. request.setRequestHeader('Content-Type','application/json');
  3629. return request;
  3630. };
  3631. /**
  3632. * Should be called to make sync request
  3633. *
  3634. * @method send
  3635. * @param {Object} payload
  3636. * @return {Object} result
  3637. */
  3638. HttpProvider.prototype.send = function (payload) {
  3639. var request = this.prepareRequest(false);
  3640. try {
  3641. request.send(JSON.stringify(payload));
  3642. } catch(error) {
  3643. throw errors.InvalidConnection(this.host);
  3644. }
  3645. var result = request.responseText;
  3646. try {
  3647. result = JSON.parse(result);
  3648. } catch(e) {
  3649. throw errors.InvalidResponse(request.responseText);
  3650. }
  3651. return result;
  3652. };
  3653. /**
  3654. * Should be used to make async request
  3655. *
  3656. * @method sendAsync
  3657. * @param {Object} payload
  3658. * @param {Function} callback triggered on end with (err, result)
  3659. */
  3660. HttpProvider.prototype.sendAsync = function (payload, callback) {
  3661. var request = this.prepareRequest(true);
  3662. request.onreadystatechange = function() {
  3663. if (request.readyState === 4) {
  3664. var result = request.responseText;
  3665. var error = null;
  3666. try {
  3667. result = JSON.parse(result);
  3668. } catch(e) {
  3669. error = errors.InvalidResponse(request.responseText);
  3670. }
  3671. callback(error, result);
  3672. }
  3673. };
  3674. try {
  3675. request.send(JSON.stringify(payload));
  3676. } catch(error) {
  3677. callback(errors.InvalidConnection(this.host));
  3678. }
  3679. };
  3680. /**
  3681. * Synchronously tries to make Http request
  3682. *
  3683. * @method isConnected
  3684. * @return {Boolean} returns true if request haven't failed. Otherwise false
  3685. */
  3686. HttpProvider.prototype.isConnected = function() {
  3687. try {
  3688. this.send({
  3689. id: 9999999999,
  3690. jsonrpc: '2.0',
  3691. method: 'net_listening',
  3692. params: []
  3693. });
  3694. return true;
  3695. } catch(e) {
  3696. return false;
  3697. }
  3698. };
  3699. module.exports = HttpProvider;
  3700. },{"./errors":26,"xmlhttprequest":17}],33:[function(require,module,exports){
  3701. /*
  3702. This file is part of web3.js.
  3703. web3.js is free software: you can redistribute it and/or modify
  3704. it under the terms of the GNU Lesser General Public License as published by
  3705. the Free Software Foundation, either version 3 of the License, or
  3706. (at your option) any later version.
  3707. web3.js is distributed in the hope that it will be useful,
  3708. but WITHOUT ANY WARRANTY; without even the implied warranty of
  3709. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  3710. GNU Lesser General Public License for more details.
  3711. You should have received a copy of the GNU Lesser General Public License
  3712. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  3713. */
  3714. /**
  3715. * @file iban.js
  3716. * @author Marek Kotewicz <marek@ethdev.com>
  3717. * @date 2015
  3718. */
  3719. var BigNumber = require('bignumber.js');
  3720. var padLeft = function (string, bytes) {
  3721. var result = string;
  3722. while (result.length < bytes * 2) {
  3723. result = '00' + result;
  3724. }
  3725. return result;
  3726. };
  3727. /**
  3728. * Prepare an IBAN for mod 97 computation by moving the first 4 chars to the end and transforming the letters to
  3729. * numbers (A = 10, B = 11, ..., Z = 35), as specified in ISO13616.
  3730. *
  3731. * @method iso13616Prepare
  3732. * @param {String} iban the IBAN
  3733. * @returns {String} the prepared IBAN
  3734. */
  3735. var iso13616Prepare = function (iban) {
  3736. var A = 'A'.charCodeAt(0);
  3737. var Z = 'Z'.charCodeAt(0);
  3738. iban = iban.toUpperCase();
  3739. iban = iban.substr(4) + iban.substr(0,4);
  3740. return iban.split('').map(function(n){
  3741. var code = n.charCodeAt(0);
  3742. if (code >= A && code <= Z){
  3743. // A = 10, B = 11, ... Z = 35
  3744. return code - A + 10;
  3745. } else {
  3746. return n;
  3747. }
  3748. }).join('');
  3749. };
  3750. /**
  3751. * Calculates the MOD 97 10 of the passed IBAN as specified in ISO7064.
  3752. *
  3753. * @method mod9710
  3754. * @param {String} iban
  3755. * @returns {Number}
  3756. */
  3757. var mod9710 = function (iban) {
  3758. var remainder = iban,
  3759. block;
  3760. while (remainder.length > 2){
  3761. block = remainder.slice(0, 9);
  3762. remainder = parseInt(block, 10) % 97 + remainder.slice(block.length);
  3763. }
  3764. return parseInt(remainder, 10) % 97;
  3765. };
  3766. /**
  3767. * This prototype should be used to create iban object from iban correct string
  3768. *
  3769. * @param {String} iban
  3770. */
  3771. var Iban = function (iban) {
  3772. this._iban = iban;
  3773. };
  3774. /**
  3775. * This method should be used to create iban object from ethereum address
  3776. *
  3777. * @method fromAddress
  3778. * @param {String} address
  3779. * @return {Iban} the IBAN object
  3780. */
  3781. Iban.fromAddress = function (address) {
  3782. var asBn = new BigNumber(address, 16);
  3783. var base36 = asBn.toString(36);
  3784. var padded = padLeft(base36, 15);
  3785. return Iban.fromBban(padded.toUpperCase());
  3786. };
  3787. /**
  3788. * Convert the passed BBAN to an IBAN for this country specification.
  3789. * Please note that <i>"generation of the IBAN shall be the exclusive responsibility of the bank/branch servicing the account"</i>.
  3790. * This method implements the preferred algorithm described in http://en.wikipedia.org/wiki/International_Bank_Account_Number#Generating_IBAN_check_digits
  3791. *
  3792. * @method fromBban
  3793. * @param {String} bban the BBAN to convert to IBAN
  3794. * @returns {Iban} the IBAN object
  3795. */
  3796. Iban.fromBban = function (bban) {
  3797. var countryCode = 'XE';
  3798. var remainder = mod9710(iso13616Prepare(countryCode + '00' + bban));
  3799. var checkDigit = ('0' + (98 - remainder)).slice(-2);
  3800. return new Iban(countryCode + checkDigit + bban);
  3801. };
  3802. /**
  3803. * Should be used to create IBAN object for given institution and identifier
  3804. *
  3805. * @method createIndirect
  3806. * @param {Object} options, required options are "institution" and "identifier"
  3807. * @return {Iban} the IBAN object
  3808. */
  3809. Iban.createIndirect = function (options) {
  3810. return Iban.fromBban('ETH' + options.institution + options.identifier);
  3811. };
  3812. /**
  3813. * Thos method should be used to check if given string is valid iban object
  3814. *
  3815. * @method isValid
  3816. * @param {String} iban string
  3817. * @return {Boolean} true if it is valid IBAN
  3818. */
  3819. Iban.isValid = function (iban) {
  3820. var i = new Iban(iban);
  3821. return i.isValid();
  3822. };
  3823. /**
  3824. * Should be called to check if iban is correct
  3825. *
  3826. * @method isValid
  3827. * @returns {Boolean} true if it is, otherwise false
  3828. */
  3829. Iban.prototype.isValid = function () {
  3830. return /^XE[0-9]{2}(ETH[0-9A-Z]{13}|[0-9A-Z]{30,31})$/.test(this._iban) &&
  3831. mod9710(iso13616Prepare(this._iban)) === 1;
  3832. };
  3833. /**
  3834. * Should be called to check if iban number is direct
  3835. *
  3836. * @method isDirect
  3837. * @returns {Boolean} true if it is, otherwise false
  3838. */
  3839. Iban.prototype.isDirect = function () {
  3840. return this._iban.length === 34 || this._iban.length === 35;
  3841. };
  3842. /**
  3843. * Should be called to check if iban number if indirect
  3844. *
  3845. * @method isIndirect
  3846. * @returns {Boolean} true if it is, otherwise false
  3847. */
  3848. Iban.prototype.isIndirect = function () {
  3849. return this._iban.length === 20;
  3850. };
  3851. /**
  3852. * Should be called to get iban checksum
  3853. * Uses the mod-97-10 checksumming protocol (ISO/IEC 7064:2003)
  3854. *
  3855. * @method checksum
  3856. * @returns {String} checksum
  3857. */
  3858. Iban.prototype.checksum = function () {
  3859. return this._iban.substr(2, 2);
  3860. };
  3861. /**
  3862. * Should be called to get institution identifier
  3863. * eg. XREG
  3864. *
  3865. * @method institution
  3866. * @returns {String} institution identifier
  3867. */
  3868. Iban.prototype.institution = function () {
  3869. return this.isIndirect() ? this._iban.substr(7, 4) : '';
  3870. };
  3871. /**
  3872. * Should be called to get client identifier within institution
  3873. * eg. GAVOFYORK
  3874. *
  3875. * @method client
  3876. * @returns {String} client identifier
  3877. */
  3878. Iban.prototype.client = function () {
  3879. return this.isIndirect() ? this._iban.substr(11) : '';
  3880. };
  3881. /**
  3882. * Should be called to get client direct address
  3883. *
  3884. * @method address
  3885. * @returns {String} client direct address
  3886. */
  3887. Iban.prototype.address = function () {
  3888. if (this.isDirect()) {
  3889. var base36 = this._iban.substr(4);
  3890. var asBn = new BigNumber(base36, 36);
  3891. return padLeft(asBn.toString(16), 20);
  3892. }
  3893. return '';
  3894. };
  3895. Iban.prototype.toString = function () {
  3896. return this._iban;
  3897. };
  3898. module.exports = Iban;
  3899. },{"bignumber.js":"bignumber.js"}],34:[function(require,module,exports){
  3900. /*
  3901. This file is part of web3.js.
  3902. web3.js is free software: you can redistribute it and/or modify
  3903. it under the terms of the GNU Lesser General Public License as published by
  3904. the Free Software Foundation, either version 3 of the License, or
  3905. (at your option) any later version.
  3906. web3.js is distributed in the hope that it will be useful,
  3907. but WITHOUT ANY WARRANTY; without even the implied warranty of
  3908. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  3909. GNU Lesser General Public License for more details.
  3910. You should have received a copy of the GNU Lesser General Public License
  3911. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  3912. */
  3913. /** @file ipcprovider.js
  3914. * @authors:
  3915. * Fabian Vogelsteller <fabian@ethdev.com>
  3916. * @date 2015
  3917. */
  3918. "use strict";
  3919. var utils = require('../utils/utils');
  3920. var errors = require('./errors');
  3921. var IpcProvider = function (path, net) {
  3922. var _this = this;
  3923. this.responseCallbacks = {};
  3924. this.path = path;
  3925. this.connection = net.connect({path: this.path});
  3926. this.connection.on('error', function(e){
  3927. console.error('IPC Connection Error', e);
  3928. _this._timeout();
  3929. });
  3930. this.connection.on('end', function(){
  3931. _this._timeout();
  3932. });
  3933. // LISTEN FOR CONNECTION RESPONSES
  3934. this.connection.on('data', function(data) {
  3935. /*jshint maxcomplexity: 6 */
  3936. _this._parseResponse(data.toString()).forEach(function(result){
  3937. var id = null;
  3938. // get the id which matches the returned id
  3939. if(utils.isArray(result)) {
  3940. result.forEach(function(load){
  3941. if(_this.responseCallbacks[load.id])
  3942. id = load.id;
  3943. });
  3944. } else {
  3945. id = result.id;
  3946. }
  3947. // fire the callback
  3948. if(_this.responseCallbacks[id]) {
  3949. _this.responseCallbacks[id](null, result);
  3950. delete _this.responseCallbacks[id];
  3951. }
  3952. });
  3953. });
  3954. };
  3955. /**
  3956. Will parse the response and make an array out of it.
  3957. @method _parseResponse
  3958. @param {String} data
  3959. */
  3960. IpcProvider.prototype._parseResponse = function(data) {
  3961. var _this = this,
  3962. returnValues = [];
  3963. // DE-CHUNKER
  3964. var dechunkedData = data
  3965. .replace(/\}\{/g,'}|--|{') // }{
  3966. .replace(/\}\]\[\{/g,'}]|--|[{') // }][{
  3967. .replace(/\}\[\{/g,'}|--|[{') // }[{
  3968. .replace(/\}\]\{/g,'}]|--|{') // }]{
  3969. .split('|--|');
  3970. dechunkedData.forEach(function(data){
  3971. // prepend the last chunk
  3972. if(_this.lastChunk)
  3973. data = _this.lastChunk + data;
  3974. var result = null;
  3975. try {
  3976. result = JSON.parse(data);
  3977. } catch(e) {
  3978. _this.lastChunk = data;
  3979. // start timeout to cancel all requests
  3980. clearTimeout(_this.lastChunkTimeout);
  3981. _this.lastChunkTimeout = setTimeout(function(){
  3982. _this.timeout();
  3983. throw errors.InvalidResponse(data);
  3984. }, 1000 * 15);
  3985. return;
  3986. }
  3987. // cancel timeout and set chunk to null
  3988. clearTimeout(_this.lastChunkTimeout);
  3989. _this.lastChunk = null;
  3990. if(result)
  3991. returnValues.push(result);
  3992. });
  3993. return returnValues;
  3994. };
  3995. /**
  3996. Get the adds a callback to the responseCallbacks object,
  3997. which will be called if a response matching the response Id will arrive.
  3998. @method _addResponseCallback
  3999. */
  4000. IpcProvider.prototype._addResponseCallback = function(payload, callback) {
  4001. var id = payload.id || payload[0].id;
  4002. var method = payload.method || payload[0].method;
  4003. this.responseCallbacks[id] = callback;
  4004. this.responseCallbacks[id].method = method;
  4005. };
  4006. /**
  4007. Timeout all requests when the end/error event is fired
  4008. @method _timeout
  4009. */
  4010. IpcProvider.prototype._timeout = function() {
  4011. for(var key in this.responseCallbacks) {
  4012. if(this.responseCallbacks.hasOwnProperty(key)){
  4013. this.responseCallbacks[key](errors.InvalidConnection('on IPC'));
  4014. delete this.responseCallbacks[key];
  4015. }
  4016. }
  4017. };
  4018. /**
  4019. Check if the current connection is still valid.
  4020. @method isConnected
  4021. */
  4022. IpcProvider.prototype.isConnected = function() {
  4023. var _this = this;
  4024. // try reconnect, when connection is gone
  4025. if(!_this.connection.writable)
  4026. _this.connection.connect({path: _this.path});
  4027. return !!this.connection.writable;
  4028. };
  4029. IpcProvider.prototype.send = function (payload) {
  4030. if(this.connection.writeSync) {
  4031. var result;
  4032. // try reconnect, when connection is gone
  4033. if(!this.connection.writable)
  4034. this.connection.connect({path: this.path});
  4035. var data = this.connection.writeSync(JSON.stringify(payload));
  4036. try {
  4037. result = JSON.parse(data);
  4038. } catch(e) {
  4039. throw errors.InvalidResponse(data);
  4040. }
  4041. return result;
  4042. } else {
  4043. throw new Error('You tried to send "'+ payload.method +'" synchronously. Synchronous requests are not supported by the IPC provider.');
  4044. }
  4045. };
  4046. IpcProvider.prototype.sendAsync = function (payload, callback) {
  4047. // try reconnect, when connection is gone
  4048. if(!this.connection.writable)
  4049. this.connection.connect({path: this.path});
  4050. this.connection.write(JSON.stringify(payload));
  4051. this._addResponseCallback(payload, callback);
  4052. };
  4053. module.exports = IpcProvider;
  4054. },{"../utils/utils":20,"./errors":26}],35:[function(require,module,exports){
  4055. /*
  4056. This file is part of web3.js.
  4057. web3.js is free software: you can redistribute it and/or modify
  4058. it under the terms of the GNU Lesser General Public License as published by
  4059. the Free Software Foundation, either version 3 of the License, or
  4060. (at your option) any later version.
  4061. web3.js is distributed in the hope that it will be useful,
  4062. but WITHOUT ANY WARRANTY; without even the implied warranty of
  4063. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  4064. GNU Lesser General Public License for more details.
  4065. You should have received a copy of the GNU Lesser General Public License
  4066. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  4067. */
  4068. /** @file jsonrpc.js
  4069. * @authors:
  4070. * Marek Kotewicz <marek@ethdev.com>
  4071. * @date 2015
  4072. */
  4073. var Jsonrpc = function () {
  4074. // singleton pattern
  4075. if (arguments.callee._singletonInstance) {
  4076. return arguments.callee._singletonInstance;
  4077. }
  4078. arguments.callee._singletonInstance = this;
  4079. this.messageId = 1;
  4080. };
  4081. /**
  4082. * @return {Jsonrpc} singleton
  4083. */
  4084. Jsonrpc.getInstance = function () {
  4085. var instance = new Jsonrpc();
  4086. return instance;
  4087. };
  4088. /**
  4089. * Should be called to valid json create payload object
  4090. *
  4091. * @method toPayload
  4092. * @param {Function} method of jsonrpc call, required
  4093. * @param {Array} params, an array of method params, optional
  4094. * @returns {Object} valid jsonrpc payload object
  4095. */
  4096. Jsonrpc.prototype.toPayload = function (method, params) {
  4097. if (!method)
  4098. console.error('jsonrpc method should be specified!');
  4099. return {
  4100. jsonrpc: '2.0',
  4101. method: method,
  4102. params: params || [],
  4103. id: this.messageId++
  4104. };
  4105. };
  4106. /**
  4107. * Should be called to check if jsonrpc response is valid
  4108. *
  4109. * @method isValidResponse
  4110. * @param {Object}
  4111. * @returns {Boolean} true if response is valid, otherwise false
  4112. */
  4113. Jsonrpc.prototype.isValidResponse = function (response) {
  4114. return !!response &&
  4115. !response.error &&
  4116. response.jsonrpc === '2.0' &&
  4117. typeof response.id === 'number' &&
  4118. response.result !== undefined; // only undefined is not valid json object
  4119. };
  4120. /**
  4121. * Should be called to create batch payload object
  4122. *
  4123. * @method toBatchPayload
  4124. * @param {Array} messages, an array of objects with method (required) and params (optional) fields
  4125. * @returns {Array} batch payload
  4126. */
  4127. Jsonrpc.prototype.toBatchPayload = function (messages) {
  4128. var self = this;
  4129. return messages.map(function (message) {
  4130. return self.toPayload(message.method, message.params);
  4131. });
  4132. };
  4133. module.exports = Jsonrpc;
  4134. },{}],36:[function(require,module,exports){
  4135. /*
  4136. This file is part of web3.js.
  4137. web3.js is free software: you can redistribute it and/or modify
  4138. it under the terms of the GNU Lesser General Public License as published by
  4139. the Free Software Foundation, either version 3 of the License, or
  4140. (at your option) any later version.
  4141. web3.js is distributed in the hope that it will be useful,
  4142. but WITHOUT ANY WARRANTY; without even the implied warranty of
  4143. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  4144. GNU Lesser General Public License for more details.
  4145. You should have received a copy of the GNU Lesser General Public License
  4146. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  4147. */
  4148. /**
  4149. * @file method.js
  4150. * @author Marek Kotewicz <marek@ethdev.com>
  4151. * @date 2015
  4152. */
  4153. var utils = require('../utils/utils');
  4154. var errors = require('./errors');
  4155. var Method = function (options) {
  4156. this.name = options.name;
  4157. this.call = options.call;
  4158. this.params = options.params || 0;
  4159. this.inputFormatter = options.inputFormatter;
  4160. this.outputFormatter = options.outputFormatter;
  4161. this.requestManager = null;
  4162. };
  4163. Method.prototype.setRequestManager = function (rm) {
  4164. this.requestManager = rm;
  4165. };
  4166. /**
  4167. * Should be used to determine name of the jsonrpc method based on arguments
  4168. *
  4169. * @method getCall
  4170. * @param {Array} arguments
  4171. * @return {String} name of jsonrpc method
  4172. */
  4173. Method.prototype.getCall = function (args) {
  4174. return utils.isFunction(this.call) ? this.call(args) : this.call;
  4175. };
  4176. /**
  4177. * Should be used to extract callback from array of arguments. Modifies input param
  4178. *
  4179. * @method extractCallback
  4180. * @param {Array} arguments
  4181. * @return {Function|Null} callback, if exists
  4182. */
  4183. Method.prototype.extractCallback = function (args) {
  4184. if (utils.isFunction(args[args.length - 1])) {
  4185. return args.pop(); // modify the args array!
  4186. }
  4187. };
  4188. /**
  4189. * Should be called to check if the number of arguments is correct
  4190. *
  4191. * @method validateArgs
  4192. * @param {Array} arguments
  4193. * @throws {Error} if it is not
  4194. */
  4195. Method.prototype.validateArgs = function (args) {
  4196. if (args.length !== this.params) {
  4197. throw errors.InvalidNumberOfParams();
  4198. }
  4199. };
  4200. /**
  4201. * Should be called to format input args of method
  4202. *
  4203. * @method formatInput
  4204. * @param {Array}
  4205. * @return {Array}
  4206. */
  4207. Method.prototype.formatInput = function (args) {
  4208. if (!this.inputFormatter) {
  4209. return args;
  4210. }
  4211. return this.inputFormatter.map(function (formatter, index) {
  4212. return formatter ? formatter(args[index]) : args[index];
  4213. });
  4214. };
  4215. /**
  4216. * Should be called to format output(result) of method
  4217. *
  4218. * @method formatOutput
  4219. * @param {Object}
  4220. * @return {Object}
  4221. */
  4222. Method.prototype.formatOutput = function (result) {
  4223. return this.outputFormatter && result ? this.outputFormatter(result) : result;
  4224. };
  4225. /**
  4226. * Should create payload from given input args
  4227. *
  4228. * @method toPayload
  4229. * @param {Array} args
  4230. * @return {Object}
  4231. */
  4232. Method.prototype.toPayload = function (args) {
  4233. var call = this.getCall(args);
  4234. var callback = this.extractCallback(args);
  4235. var params = this.formatInput(args);
  4236. this.validateArgs(params);
  4237. return {
  4238. method: call,
  4239. params: params,
  4240. callback: callback
  4241. };
  4242. };
  4243. Method.prototype.attachToObject = function (obj) {
  4244. var func = this.buildCall();
  4245. func.call = this.call; // TODO!!! that's ugly. filter.js uses it
  4246. var name = this.name.split('.');
  4247. if (name.length > 1) {
  4248. obj[name[0]] = obj[name[0]] || {};
  4249. obj[name[0]][name[1]] = func;
  4250. } else {
  4251. obj[name[0]] = func;
  4252. }
  4253. };
  4254. Method.prototype.buildCall = function() {
  4255. var method = this;
  4256. var send = function () {
  4257. var payload = method.toPayload(Array.prototype.slice.call(arguments));
  4258. if (payload.callback) {
  4259. return method.requestManager.sendAsync(payload, function (err, result) {
  4260. payload.callback(err, method.formatOutput(result));
  4261. });
  4262. }
  4263. return method.formatOutput(method.requestManager.send(payload));
  4264. };
  4265. send.request = this.request.bind(this);
  4266. return send;
  4267. };
  4268. /**
  4269. * Should be called to create pure JSONRPC request which can be used in batch request
  4270. *
  4271. * @method request
  4272. * @param {...} params
  4273. * @return {Object} jsonrpc request
  4274. */
  4275. Method.prototype.request = function () {
  4276. var payload = this.toPayload(Array.prototype.slice.call(arguments));
  4277. payload.format = this.formatOutput.bind(this);
  4278. return payload;
  4279. };
  4280. module.exports = Method;
  4281. },{"../utils/utils":20,"./errors":26}],37:[function(require,module,exports){
  4282. /*
  4283. This file is part of web3.js.
  4284. web3.js is free software: you can redistribute it and/or modify
  4285. it under the terms of the GNU Lesser General Public License as published by
  4286. the Free Software Foundation, either version 3 of the License, or
  4287. (at your option) any later version.
  4288. web3.js is distributed in the hope that it will be useful,
  4289. but WITHOUT ANY WARRANTY; without even the implied warranty of
  4290. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  4291. GNU Lesser General Public License for more details.
  4292. You should have received a copy of the GNU Lesser General Public License
  4293. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  4294. */
  4295. /** @file db.js
  4296. * @authors:
  4297. * Marek Kotewicz <marek@ethdev.com>
  4298. * @date 2015
  4299. */
  4300. var Method = require('../method');
  4301. var DB = function (web3) {
  4302. this._requestManager = web3._requestManager;
  4303. var self = this;
  4304. methods().forEach(function(method) {
  4305. method.attachToObject(self);
  4306. method.setRequestManager(web3._requestManager);
  4307. });
  4308. };
  4309. var methods = function () {
  4310. var putString = new Method({
  4311. name: 'putString',
  4312. call: 'db_putString',
  4313. params: 3
  4314. });
  4315. var getString = new Method({
  4316. name: 'getString',
  4317. call: 'db_getString',
  4318. params: 2
  4319. });
  4320. var putHex = new Method({
  4321. name: 'putHex',
  4322. call: 'db_putHex',
  4323. params: 3
  4324. });
  4325. var getHex = new Method({
  4326. name: 'getHex',
  4327. call: 'db_getHex',
  4328. params: 2
  4329. });
  4330. return [
  4331. putString, getString, putHex, getHex
  4332. ];
  4333. };
  4334. module.exports = DB;
  4335. },{"../method":36}],38:[function(require,module,exports){
  4336. /*
  4337. This file is part of web3.js.
  4338. web3.js is free software: you can redistribute it and/or modify
  4339. it under the terms of the GNU Lesser General Public License as published by
  4340. the Free Software Foundation, either version 3 of the License, or
  4341. (at your option) any later version.
  4342. web3.js is distributed in the hope that it will be useful,
  4343. but WITHOUT ANY WARRANTY; without even the implied warranty of
  4344. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  4345. GNU Lesser General Public License for more details.
  4346. You should have received a copy of the GNU Lesser General Public License
  4347. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  4348. */
  4349. /**
  4350. * @file eth.js
  4351. * @author Marek Kotewicz <marek@ethdev.com>
  4352. * @author Fabian Vogelsteller <fabian@ethdev.com>
  4353. * @date 2015
  4354. */
  4355. "use strict";
  4356. var formatters = require('../formatters');
  4357. var utils = require('../../utils/utils');
  4358. var Method = require('../method');
  4359. var Property = require('../property');
  4360. var c = require('../../utils/config');
  4361. var Contract = require('../contract');
  4362. var watches = require('./watches');
  4363. var Filter = require('../filter');
  4364. var IsSyncing = require('../syncing');
  4365. var namereg = require('../namereg');
  4366. var Iban = require('../iban');
  4367. var transfer = require('../transfer');
  4368. var blockCall = function (args) {
  4369. return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? "eth_getBlockByHash" : "eth_getBlockByNumber";
  4370. };
  4371. var transactionFromBlockCall = function (args) {
  4372. return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getTransactionByBlockHashAndIndex' : 'eth_getTransactionByBlockNumberAndIndex';
  4373. };
  4374. var uncleCall = function (args) {
  4375. return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getUncleByBlockHashAndIndex' : 'eth_getUncleByBlockNumberAndIndex';
  4376. };
  4377. var getBlockTransactionCountCall = function (args) {
  4378. return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getBlockTransactionCountByHash' : 'eth_getBlockTransactionCountByNumber';
  4379. };
  4380. var uncleCountCall = function (args) {
  4381. return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getUncleCountByBlockHash' : 'eth_getUncleCountByBlockNumber';
  4382. };
  4383. function Eth(web3) {
  4384. this._requestManager = web3._requestManager;
  4385. var self = this;
  4386. methods().forEach(function(method) {
  4387. method.attachToObject(self);
  4388. method.setRequestManager(self._requestManager);
  4389. });
  4390. properties().forEach(function(p) {
  4391. p.attachToObject(self);
  4392. p.setRequestManager(self._requestManager);
  4393. });
  4394. this.iban = Iban;
  4395. this.sendIBANTransaction = transfer.bind(null, this);
  4396. }
  4397. Object.defineProperty(Eth.prototype, 'defaultBlock', {
  4398. get: function () {
  4399. return c.defaultBlock;
  4400. },
  4401. set: function (val) {
  4402. c.defaultBlock = val;
  4403. return val;
  4404. }
  4405. });
  4406. Object.defineProperty(Eth.prototype, 'defaultAccount', {
  4407. get: function () {
  4408. return c.defaultAccount;
  4409. },
  4410. set: function (val) {
  4411. c.defaultAccount = val;
  4412. return val;
  4413. }
  4414. });
  4415. var methods = function () {
  4416. var getBalance = new Method({
  4417. name: 'getBalance',
  4418. call: 'eth_getBalance',
  4419. params: 2,
  4420. inputFormatter: [formatters.inputAddressFormatter, formatters.inputDefaultBlockNumberFormatter],
  4421. outputFormatter: formatters.outputBigNumberFormatter
  4422. });
  4423. var getStorageAt = new Method({
  4424. name: 'getStorageAt',
  4425. call: 'eth_getStorageAt',
  4426. params: 3,
  4427. inputFormatter: [null, utils.toHex, formatters.inputDefaultBlockNumberFormatter]
  4428. });
  4429. var getCode = new Method({
  4430. name: 'getCode',
  4431. call: 'eth_getCode',
  4432. params: 2,
  4433. inputFormatter: [formatters.inputAddressFormatter, formatters.inputDefaultBlockNumberFormatter]
  4434. });
  4435. var getBlock = new Method({
  4436. name: 'getBlock',
  4437. call: blockCall,
  4438. params: 2,
  4439. inputFormatter: [formatters.inputBlockNumberFormatter, function (val) { return !!val; }],
  4440. outputFormatter: formatters.outputBlockFormatter
  4441. });
  4442. var getUncle = new Method({
  4443. name: 'getUncle',
  4444. call: uncleCall,
  4445. params: 2,
  4446. inputFormatter: [formatters.inputBlockNumberFormatter, utils.toHex],
  4447. outputFormatter: formatters.outputBlockFormatter,
  4448. });
  4449. var getCompilers = new Method({
  4450. name: 'getCompilers',
  4451. call: 'eth_getCompilers',
  4452. params: 0
  4453. });
  4454. var getBlockTransactionCount = new Method({
  4455. name: 'getBlockTransactionCount',
  4456. call: getBlockTransactionCountCall,
  4457. params: 1,
  4458. inputFormatter: [formatters.inputBlockNumberFormatter],
  4459. outputFormatter: utils.toDecimal
  4460. });
  4461. var getBlockUncleCount = new Method({
  4462. name: 'getBlockUncleCount',
  4463. call: uncleCountCall,
  4464. params: 1,
  4465. inputFormatter: [formatters.inputBlockNumberFormatter],
  4466. outputFormatter: utils.toDecimal
  4467. });
  4468. var getTransaction = new Method({
  4469. name: 'getTransaction',
  4470. call: 'eth_getTransactionByHash',
  4471. params: 1,
  4472. outputFormatter: formatters.outputTransactionFormatter
  4473. });
  4474. var getTransactionFromBlock = new Method({
  4475. name: 'getTransactionFromBlock',
  4476. call: transactionFromBlockCall,
  4477. params: 2,
  4478. inputFormatter: [formatters.inputBlockNumberFormatter, utils.toHex],
  4479. outputFormatter: formatters.outputTransactionFormatter
  4480. });
  4481. var getTransactionReceipt = new Method({
  4482. name: 'getTransactionReceipt',
  4483. call: 'eth_getTransactionReceipt',
  4484. params: 1,
  4485. outputFormatter: formatters.outputTransactionReceiptFormatter
  4486. });
  4487. var getTransactionCount = new Method({
  4488. name: 'getTransactionCount',
  4489. call: 'eth_getTransactionCount',
  4490. params: 2,
  4491. inputFormatter: [null, formatters.inputDefaultBlockNumberFormatter],
  4492. outputFormatter: utils.toDecimal
  4493. });
  4494. var sendRawTransaction = new Method({
  4495. name: 'sendRawTransaction',
  4496. call: 'eth_sendRawTransaction',
  4497. params: 1,
  4498. inputFormatter: [null]
  4499. });
  4500. var sendTransaction = new Method({
  4501. name: 'sendTransaction',
  4502. call: 'eth_sendTransaction',
  4503. params: 1,
  4504. inputFormatter: [formatters.inputTransactionFormatter]
  4505. });
  4506. var call = new Method({
  4507. name: 'call',
  4508. call: 'eth_call',
  4509. params: 2,
  4510. inputFormatter: [formatters.inputCallFormatter, formatters.inputDefaultBlockNumberFormatter]
  4511. });
  4512. var estimateGas = new Method({
  4513. name: 'estimateGas',
  4514. call: 'eth_estimateGas',
  4515. params: 1,
  4516. inputFormatter: [formatters.inputCallFormatter],
  4517. outputFormatter: utils.toDecimal
  4518. });
  4519. var compileSolidity = new Method({
  4520. name: 'compile.solidity',
  4521. call: 'eth_compileSolidity',
  4522. params: 1
  4523. });
  4524. var compileLLL = new Method({
  4525. name: 'compile.lll',
  4526. call: 'eth_compileLLL',
  4527. params: 1
  4528. });
  4529. var compileSerpent = new Method({
  4530. name: 'compile.serpent',
  4531. call: 'eth_compileSerpent',
  4532. params: 1
  4533. });
  4534. var submitWork = new Method({
  4535. name: 'submitWork',
  4536. call: 'eth_submitWork',
  4537. params: 3
  4538. });
  4539. var getWork = new Method({
  4540. name: 'getWork',
  4541. call: 'eth_getWork',
  4542. params: 0
  4543. });
  4544. return [
  4545. getBalance,
  4546. getStorageAt,
  4547. getCode,
  4548. getBlock,
  4549. getUncle,
  4550. getCompilers,
  4551. getBlockTransactionCount,
  4552. getBlockUncleCount,
  4553. getTransaction,
  4554. getTransactionFromBlock,
  4555. getTransactionReceipt,
  4556. getTransactionCount,
  4557. call,
  4558. estimateGas,
  4559. sendRawTransaction,
  4560. sendTransaction,
  4561. compileSolidity,
  4562. compileLLL,
  4563. compileSerpent,
  4564. submitWork,
  4565. getWork
  4566. ];
  4567. };
  4568. var properties = function () {
  4569. return [
  4570. new Property({
  4571. name: 'coinbase',
  4572. getter: 'eth_coinbase'
  4573. }),
  4574. new Property({
  4575. name: 'mining',
  4576. getter: 'eth_mining'
  4577. }),
  4578. new Property({
  4579. name: 'hashrate',
  4580. getter: 'eth_hashrate',
  4581. outputFormatter: utils.toDecimal
  4582. }),
  4583. new Property({
  4584. name: 'syncing',
  4585. getter: 'eth_syncing',
  4586. outputFormatter: formatters.outputSyncingFormatter
  4587. }),
  4588. new Property({
  4589. name: 'gasPrice',
  4590. getter: 'eth_gasPrice',
  4591. outputFormatter: formatters.outputBigNumberFormatter
  4592. }),
  4593. new Property({
  4594. name: 'accounts',
  4595. getter: 'eth_accounts'
  4596. }),
  4597. new Property({
  4598. name: 'blockNumber',
  4599. getter: 'eth_blockNumber',
  4600. outputFormatter: utils.toDecimal
  4601. })
  4602. ];
  4603. };
  4604. Eth.prototype.contract = function (abi) {
  4605. var factory = new Contract(this, abi);
  4606. return factory;
  4607. };
  4608. Eth.prototype.filter = function (fil, callback) {
  4609. return new Filter(this._requestManager, fil, watches.eth(), formatters.outputLogFormatter, callback);
  4610. };
  4611. Eth.prototype.namereg = function () {
  4612. return this.contract(namereg.global.abi).at(namereg.global.address);
  4613. };
  4614. Eth.prototype.icapNamereg = function () {
  4615. return this.contract(namereg.icap.abi).at(namereg.icap.address);
  4616. };
  4617. Eth.prototype.isSyncing = function (callback) {
  4618. return new IsSyncing(this._requestManager, callback);
  4619. };
  4620. module.exports = Eth;
  4621. },{"../../utils/config":18,"../../utils/utils":20,"../contract":25,"../filter":29,"../formatters":30,"../iban":33,"../method":36,"../namereg":42,"../property":43,"../syncing":46,"../transfer":47,"./watches":41}],39:[function(require,module,exports){
  4622. /*
  4623. This file is part of web3.js.
  4624. web3.js is free software: you can redistribute it and/or modify
  4625. it under the terms of the GNU Lesser General Public License as published by
  4626. the Free Software Foundation, either version 3 of the License, or
  4627. (at your option) any later version.
  4628. web3.js is distributed in the hope that it will be useful,
  4629. but WITHOUT ANY WARRANTY; without even the implied warranty of
  4630. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  4631. GNU Lesser General Public License for more details.
  4632. You should have received a copy of the GNU Lesser General Public License
  4633. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  4634. */
  4635. /** @file eth.js
  4636. * @authors:
  4637. * Marek Kotewicz <marek@ethdev.com>
  4638. * @date 2015
  4639. */
  4640. var utils = require('../../utils/utils');
  4641. var Property = require('../property');
  4642. var Net = function (web3) {
  4643. this._requestManager = web3._requestManager;
  4644. var self = this;
  4645. properties().forEach(function(p) {
  4646. p.attachToObject(self);
  4647. p.setRequestManager(web3._requestManager);
  4648. });
  4649. };
  4650. /// @returns an array of objects describing web3.eth api properties
  4651. var properties = function () {
  4652. return [
  4653. new Property({
  4654. name: 'listening',
  4655. getter: 'net_listening'
  4656. }),
  4657. new Property({
  4658. name: 'peerCount',
  4659. getter: 'net_peerCount',
  4660. outputFormatter: utils.toDecimal
  4661. })
  4662. ];
  4663. };
  4664. module.exports = Net;
  4665. },{"../../utils/utils":20,"../property":43}],40:[function(require,module,exports){
  4666. /*
  4667. This file is part of web3.js.
  4668. web3.js is free software: you can redistribute it and/or modify
  4669. it under the terms of the GNU Lesser General Public License as published by
  4670. the Free Software Foundation, either version 3 of the License, or
  4671. (at your option) any later version.
  4672. web3.js is distributed in the hope that it will be useful,
  4673. but WITHOUT ANY WARRANTY; without even the implied warranty of
  4674. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  4675. GNU Lesser General Public License for more details.
  4676. You should have received a copy of the GNU Lesser General Public License
  4677. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  4678. */
  4679. /** @file shh.js
  4680. * @authors:
  4681. * Marek Kotewicz <marek@ethdev.com>
  4682. * @date 2015
  4683. */
  4684. var Method = require('../method');
  4685. var formatters = require('../formatters');
  4686. var Filter = require('../filter');
  4687. var watches = require('./watches');
  4688. var Shh = function (web3) {
  4689. this._requestManager = web3._requestManager;
  4690. var self = this;
  4691. methods().forEach(function(method) {
  4692. method.attachToObject(self);
  4693. method.setRequestManager(self._requestManager);
  4694. });
  4695. };
  4696. Shh.prototype.filter = function (fil, callback) {
  4697. return new Filter(this._requestManager, fil, watches.shh(), formatters.outputPostFormatter, callback);
  4698. };
  4699. var methods = function () {
  4700. var post = new Method({
  4701. name: 'post',
  4702. call: 'shh_post',
  4703. params: 1,
  4704. inputFormatter: [formatters.inputPostFormatter]
  4705. });
  4706. var newIdentity = new Method({
  4707. name: 'newIdentity',
  4708. call: 'shh_newIdentity',
  4709. params: 0
  4710. });
  4711. var hasIdentity = new Method({
  4712. name: 'hasIdentity',
  4713. call: 'shh_hasIdentity',
  4714. params: 1
  4715. });
  4716. var newGroup = new Method({
  4717. name: 'newGroup',
  4718. call: 'shh_newGroup',
  4719. params: 0
  4720. });
  4721. var addToGroup = new Method({
  4722. name: 'addToGroup',
  4723. call: 'shh_addToGroup',
  4724. params: 0
  4725. });
  4726. return [
  4727. post,
  4728. newIdentity,
  4729. hasIdentity,
  4730. newGroup,
  4731. addToGroup
  4732. ];
  4733. };
  4734. module.exports = Shh;
  4735. },{"../filter":29,"../formatters":30,"../method":36,"./watches":41}],41:[function(require,module,exports){
  4736. /*
  4737. This file is part of web3.js.
  4738. web3.js is free software: you can redistribute it and/or modify
  4739. it under the terms of the GNU Lesser General Public License as published by
  4740. the Free Software Foundation, either version 3 of the License, or
  4741. (at your option) any later version.
  4742. web3.js is distributed in the hope that it will be useful,
  4743. but WITHOUT ANY WARRANTY; without even the implied warranty of
  4744. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  4745. GNU Lesser General Public License for more details.
  4746. You should have received a copy of the GNU Lesser General Public License
  4747. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  4748. */
  4749. /** @file watches.js
  4750. * @authors:
  4751. * Marek Kotewicz <marek@ethdev.com>
  4752. * @date 2015
  4753. */
  4754. var Method = require('../method');
  4755. /// @returns an array of objects describing web3.eth.filter api methods
  4756. var eth = function () {
  4757. var newFilterCall = function (args) {
  4758. var type = args[0];
  4759. switch(type) {
  4760. case 'latest':
  4761. args.shift();
  4762. this.params = 0;
  4763. return 'eth_newBlockFilter';
  4764. case 'pending':
  4765. args.shift();
  4766. this.params = 0;
  4767. return 'eth_newPendingTransactionFilter';
  4768. default:
  4769. return 'eth_newFilter';
  4770. }
  4771. };
  4772. var newFilter = new Method({
  4773. name: 'newFilter',
  4774. call: newFilterCall,
  4775. params: 1
  4776. });
  4777. var uninstallFilter = new Method({
  4778. name: 'uninstallFilter',
  4779. call: 'eth_uninstallFilter',
  4780. params: 1
  4781. });
  4782. var getLogs = new Method({
  4783. name: 'getLogs',
  4784. call: 'eth_getFilterLogs',
  4785. params: 1
  4786. });
  4787. var poll = new Method({
  4788. name: 'poll',
  4789. call: 'eth_getFilterChanges',
  4790. params: 1
  4791. });
  4792. return [
  4793. newFilter,
  4794. uninstallFilter,
  4795. getLogs,
  4796. poll
  4797. ];
  4798. };
  4799. /// @returns an array of objects describing web3.shh.watch api methods
  4800. var shh = function () {
  4801. var newFilter = new Method({
  4802. name: 'newFilter',
  4803. call: 'shh_newFilter',
  4804. params: 1
  4805. });
  4806. var uninstallFilter = new Method({
  4807. name: 'uninstallFilter',
  4808. call: 'shh_uninstallFilter',
  4809. params: 1
  4810. });
  4811. var getLogs = new Method({
  4812. name: 'getLogs',
  4813. call: 'shh_getMessages',
  4814. params: 1
  4815. });
  4816. var poll = new Method({
  4817. name: 'poll',
  4818. call: 'shh_getFilterChanges',
  4819. params: 1
  4820. });
  4821. return [
  4822. newFilter,
  4823. uninstallFilter,
  4824. getLogs,
  4825. poll
  4826. ];
  4827. };
  4828. module.exports = {
  4829. eth: eth,
  4830. shh: shh
  4831. };
  4832. },{"../method":36}],42:[function(require,module,exports){
  4833. /*
  4834. This file is part of web3.js.
  4835. web3.js is free software: you can redistribute it and/or modify
  4836. it under the terms of the GNU Lesser General Public License as published by
  4837. the Free Software Foundation, either version 3 of the License, or
  4838. (at your option) any later version.
  4839. web3.js is distributed in the hope that it will be useful,
  4840. but WITHOUT ANY WARRANTY; without even the implied warranty of
  4841. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  4842. GNU Lesser General Public License for more details.
  4843. You should have received a copy of the GNU Lesser General Public License
  4844. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  4845. */
  4846. /**
  4847. * @file namereg.js
  4848. * @author Marek Kotewicz <marek@ethdev.com>
  4849. * @date 2015
  4850. */
  4851. var globalRegistrarAbi = require('../contracts/GlobalRegistrar.json');
  4852. var icapRegistrarAbi= require('../contracts/ICAPRegistrar.json');
  4853. var globalNameregAddress = '0xc6d9d2cd449a754c494264e1809c50e34d64562b';
  4854. var icapNameregAddress = '0xa1a111bc074c9cfa781f0c38e63bd51c91b8af00';
  4855. module.exports = {
  4856. global: {
  4857. abi: globalRegistrarAbi,
  4858. address: globalNameregAddress
  4859. },
  4860. icap: {
  4861. abi: icapRegistrarAbi,
  4862. address: icapNameregAddress
  4863. }
  4864. };
  4865. },{"../contracts/GlobalRegistrar.json":1,"../contracts/ICAPRegistrar.json":2}],43:[function(require,module,exports){
  4866. /*
  4867. This file is part of web3.js.
  4868. web3.js is free software: you can redistribute it and/or modify
  4869. it under the terms of the GNU Lesser General Public License as published by
  4870. the Free Software Foundation, either version 3 of the License, or
  4871. (at your option) any later version.
  4872. web3.js is distributed in the hope that it will be useful,
  4873. but WITHOUT ANY WARRANTY; without even the implied warranty of
  4874. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  4875. GNU Lesser General Public License for more details.
  4876. You should have received a copy of the GNU Lesser General Public License
  4877. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  4878. */
  4879. /**
  4880. * @file property.js
  4881. * @author Fabian Vogelsteller <fabian@frozeman.de>
  4882. * @author Marek Kotewicz <marek@ethdev.com>
  4883. * @date 2015
  4884. */
  4885. var utils = require('../utils/utils');
  4886. var Property = function (options) {
  4887. this.name = options.name;
  4888. this.getter = options.getter;
  4889. this.setter = options.setter;
  4890. this.outputFormatter = options.outputFormatter;
  4891. this.inputFormatter = options.inputFormatter;
  4892. this.requestManager = null;
  4893. };
  4894. Property.prototype.setRequestManager = function (rm) {
  4895. this.requestManager = rm;
  4896. };
  4897. /**
  4898. * Should be called to format input args of method
  4899. *
  4900. * @method formatInput
  4901. * @param {Array}
  4902. * @return {Array}
  4903. */
  4904. Property.prototype.formatInput = function (arg) {
  4905. return this.inputFormatter ? this.inputFormatter(arg) : arg;
  4906. };
  4907. /**
  4908. * Should be called to format output(result) of method
  4909. *
  4910. * @method formatOutput
  4911. * @param {Object}
  4912. * @return {Object}
  4913. */
  4914. Property.prototype.formatOutput = function (result) {
  4915. return this.outputFormatter && result !== null ? this.outputFormatter(result) : result;
  4916. };
  4917. /**
  4918. * Should be used to extract callback from array of arguments. Modifies input param
  4919. *
  4920. * @method extractCallback
  4921. * @param {Array} arguments
  4922. * @return {Function|Null} callback, if exists
  4923. */
  4924. Property.prototype.extractCallback = function (args) {
  4925. if (utils.isFunction(args[args.length - 1])) {
  4926. return args.pop(); // modify the args array!
  4927. }
  4928. };
  4929. /**
  4930. * Should attach function to method
  4931. *
  4932. * @method attachToObject
  4933. * @param {Object}
  4934. * @param {Function}
  4935. */
  4936. Property.prototype.attachToObject = function (obj) {
  4937. var proto = {
  4938. //get: this.buildGet()
  4939. get: this.buildGet(),
  4940. enumerable: true
  4941. };
  4942. var names = this.name.split('.');
  4943. var name = names[0];
  4944. if (names.length > 1) {
  4945. obj[names[0]] = obj[names[0]] || {};
  4946. obj = obj[names[0]];
  4947. name = names[1];
  4948. }
  4949. Object.defineProperty(obj, name, proto);
  4950. obj[asyncGetterName(name)] = this.buildAsyncGet();
  4951. };
  4952. var asyncGetterName = function (name) {
  4953. return 'get' + name.charAt(0).toUpperCase() + name.slice(1);
  4954. };
  4955. Property.prototype.buildGet = function () {
  4956. var property = this;
  4957. return function get() {
  4958. return property.formatOutput(property.requestManager.send({
  4959. method: property.getter
  4960. }));
  4961. };
  4962. };
  4963. Property.prototype.buildAsyncGet = function () {
  4964. var property = this;
  4965. var get = function (callback) {
  4966. property.requestManager.sendAsync({
  4967. method: property.getter
  4968. }, function (err, result) {
  4969. callback(err, property.formatOutput(result));
  4970. });
  4971. };
  4972. get.request = this.request.bind(this);
  4973. return get;
  4974. };
  4975. /**
  4976. * Should be called to create pure JSONRPC request which can be used in batch request
  4977. *
  4978. * @method request
  4979. * @param {...} params
  4980. * @return {Object} jsonrpc request
  4981. */
  4982. Property.prototype.request = function () {
  4983. var payload = {
  4984. method: this.getter,
  4985. params: [],
  4986. callback: this.extractCallback(Array.prototype.slice.call(arguments))
  4987. };
  4988. payload.format = this.formatOutput.bind(this);
  4989. return payload;
  4990. };
  4991. module.exports = Property;
  4992. },{"../utils/utils":20}],44:[function(require,module,exports){
  4993. /*
  4994. This file is part of web3.js.
  4995. web3.js is free software: you can redistribute it and/or modify
  4996. it under the terms of the GNU Lesser General Public License as published by
  4997. the Free Software Foundation, either version 3 of the License, or
  4998. (at your option) any later version.
  4999. web3.js is distributed in the hope that it will be useful,
  5000. but WITHOUT ANY WARRANTY; without even the implied warranty of
  5001. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  5002. GNU Lesser General Public License for more details.
  5003. You should have received a copy of the GNU Lesser General Public License
  5004. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  5005. */
  5006. /**
  5007. * @file requestmanager.js
  5008. * @author Jeffrey Wilcke <jeff@ethdev.com>
  5009. * @author Marek Kotewicz <marek@ethdev.com>
  5010. * @author Marian Oancea <marian@ethdev.com>
  5011. * @author Fabian Vogelsteller <fabian@ethdev.com>
  5012. * @author Gav Wood <g@ethdev.com>
  5013. * @date 2014
  5014. */
  5015. var Jsonrpc = require('./jsonrpc');
  5016. var utils = require('../utils/utils');
  5017. var c = require('../utils/config');
  5018. var errors = require('./errors');
  5019. /**
  5020. * It's responsible for passing messages to providers
  5021. * It's also responsible for polling the ethereum node for incoming messages
  5022. * Default poll timeout is 1 second
  5023. * Singleton
  5024. */
  5025. var RequestManager = function (provider) {
  5026. this.provider = provider;
  5027. this.polls = {};
  5028. this.timeout = null;
  5029. };
  5030. /**
  5031. * Should be used to synchronously send request
  5032. *
  5033. * @method send
  5034. * @param {Object} data
  5035. * @return {Object}
  5036. */
  5037. RequestManager.prototype.send = function (data) {
  5038. if (!this.provider) {
  5039. console.error(errors.InvalidProvider());
  5040. return null;
  5041. }
  5042. var payload = Jsonrpc.getInstance().toPayload(data.method, data.params);
  5043. var result = this.provider.send(payload);
  5044. if (!Jsonrpc.getInstance().isValidResponse(result)) {
  5045. throw errors.InvalidResponse(result);
  5046. }
  5047. return result.result;
  5048. };
  5049. /**
  5050. * Should be used to asynchronously send request
  5051. *
  5052. * @method sendAsync
  5053. * @param {Object} data
  5054. * @param {Function} callback
  5055. */
  5056. RequestManager.prototype.sendAsync = function (data, callback) {
  5057. if (!this.provider) {
  5058. return callback(errors.InvalidProvider());
  5059. }
  5060. var payload = Jsonrpc.getInstance().toPayload(data.method, data.params);
  5061. this.provider.sendAsync(payload, function (err, result) {
  5062. if (err) {
  5063. return callback(err);
  5064. }
  5065. if (!Jsonrpc.getInstance().isValidResponse(result)) {
  5066. return callback(errors.InvalidResponse(result));
  5067. }
  5068. callback(null, result.result);
  5069. });
  5070. };
  5071. /**
  5072. * Should be called to asynchronously send batch request
  5073. *
  5074. * @method sendBatch
  5075. * @param {Array} batch data
  5076. * @param {Function} callback
  5077. */
  5078. RequestManager.prototype.sendBatch = function (data, callback) {
  5079. if (!this.provider) {
  5080. return callback(errors.InvalidProvider());
  5081. }
  5082. var payload = Jsonrpc.getInstance().toBatchPayload(data);
  5083. this.provider.sendAsync(payload, function (err, results) {
  5084. if (err) {
  5085. return callback(err);
  5086. }
  5087. if (!utils.isArray(results)) {
  5088. return callback(errors.InvalidResponse(results));
  5089. }
  5090. callback(err, results);
  5091. });
  5092. };
  5093. /**
  5094. * Should be used to set provider of request manager
  5095. *
  5096. * @method setProvider
  5097. * @param {Object}
  5098. */
  5099. RequestManager.prototype.setProvider = function (p) {
  5100. this.provider = p;
  5101. };
  5102. /**
  5103. * Should be used to start polling
  5104. *
  5105. * @method startPolling
  5106. * @param {Object} data
  5107. * @param {Number} pollId
  5108. * @param {Function} callback
  5109. * @param {Function} uninstall
  5110. *
  5111. * @todo cleanup number of params
  5112. */
  5113. RequestManager.prototype.startPolling = function (data, pollId, callback, uninstall) {
  5114. this.polls[pollId] = {data: data, id: pollId, callback: callback, uninstall: uninstall};
  5115. // start polling
  5116. if (!this.timeout) {
  5117. this.poll();
  5118. }
  5119. };
  5120. /**
  5121. * Should be used to stop polling for filter with given id
  5122. *
  5123. * @method stopPolling
  5124. * @param {Number} pollId
  5125. */
  5126. RequestManager.prototype.stopPolling = function (pollId) {
  5127. delete this.polls[pollId];
  5128. // stop polling
  5129. if(Object.keys(this.polls).length === 0 && this.timeout) {
  5130. clearTimeout(this.timeout);
  5131. this.timeout = null;
  5132. }
  5133. };
  5134. /**
  5135. * Should be called to reset the polling mechanism of the request manager
  5136. *
  5137. * @method reset
  5138. */
  5139. RequestManager.prototype.reset = function (keepIsSyncing) {
  5140. /*jshint maxcomplexity:5 */
  5141. for (var key in this.polls) {
  5142. // remove all polls, except sync polls,
  5143. // they need to be removed manually by calling syncing.stopWatching()
  5144. if(!keepIsSyncing || key.indexOf('syncPoll_') === -1) {
  5145. this.polls[key].uninstall();
  5146. delete this.polls[key];
  5147. }
  5148. }
  5149. // stop polling
  5150. if(Object.keys(this.polls).length === 0 && this.timeout) {
  5151. clearTimeout(this.timeout);
  5152. this.timeout = null;
  5153. }
  5154. };
  5155. /**
  5156. * Should be called to poll for changes on filter with given id
  5157. *
  5158. * @method poll
  5159. */
  5160. RequestManager.prototype.poll = function () {
  5161. /*jshint maxcomplexity: 6 */
  5162. this.timeout = setTimeout(this.poll.bind(this), c.ETH_POLLING_TIMEOUT);
  5163. if (Object.keys(this.polls).length === 0) {
  5164. return;
  5165. }
  5166. if (!this.provider) {
  5167. console.error(errors.InvalidProvider());
  5168. return;
  5169. }
  5170. var pollsData = [];
  5171. var pollsIds = [];
  5172. for (var key in this.polls) {
  5173. pollsData.push(this.polls[key].data);
  5174. pollsIds.push(key);
  5175. }
  5176. if (pollsData.length === 0) {
  5177. return;
  5178. }
  5179. var payload = Jsonrpc.getInstance().toBatchPayload(pollsData);
  5180. // map the request id to they poll id
  5181. var pollsIdMap = {};
  5182. payload.forEach(function(load, index){
  5183. pollsIdMap[load.id] = pollsIds[index];
  5184. });
  5185. var self = this;
  5186. this.provider.sendAsync(payload, function (error, results) {
  5187. // TODO: console log?
  5188. if (error) {
  5189. return;
  5190. }
  5191. if (!utils.isArray(results)) {
  5192. throw errors.InvalidResponse(results);
  5193. }
  5194. results.map(function (result) {
  5195. var id = pollsIdMap[result.id];
  5196. // make sure the filter is still installed after arrival of the request
  5197. if (self.polls[id]) {
  5198. result.callback = self.polls[id].callback;
  5199. return result;
  5200. } else
  5201. return false;
  5202. }).filter(function (result) {
  5203. return !!result;
  5204. }).filter(function (result) {
  5205. var valid = Jsonrpc.getInstance().isValidResponse(result);
  5206. if (!valid) {
  5207. result.callback(errors.InvalidResponse(result));
  5208. }
  5209. return valid;
  5210. }).forEach(function (result) {
  5211. result.callback(null, result.result);
  5212. });
  5213. });
  5214. };
  5215. module.exports = RequestManager;
  5216. },{"../utils/config":18,"../utils/utils":20,"./errors":26,"./jsonrpc":35}],45:[function(require,module,exports){
  5217. var Settings = function () {
  5218. this.defaultBlock = 'latest';
  5219. this.defaultAccount = undefined;
  5220. };
  5221. module.exports = Settings;
  5222. },{}],46:[function(require,module,exports){
  5223. /*
  5224. This file is part of web3.js.
  5225. web3.js is free software: you can redistribute it and/or modify
  5226. it under the terms of the GNU Lesser General Public License as published by
  5227. the Free Software Foundation, either version 3 of the License, or
  5228. (at your option) any later version.
  5229. web3.js is distributed in the hope that it will be useful,
  5230. but WITHOUT ANY WARRANTY; without even the implied warranty of
  5231. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  5232. GNU Lesser General Public License for more details.
  5233. You should have received a copy of the GNU Lesser General Public License
  5234. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  5235. */
  5236. /** @file syncing.js
  5237. * @authors:
  5238. * Fabian Vogelsteller <fabian@ethdev.com>
  5239. * @date 2015
  5240. */
  5241. var formatters = require('./formatters');
  5242. var utils = require('../utils/utils');
  5243. var count = 1;
  5244. /**
  5245. Adds the callback and sets up the methods, to iterate over the results.
  5246. @method pollSyncing
  5247. @param {Object} self
  5248. */
  5249. var pollSyncing = function(self) {
  5250. var onMessage = function (error, sync) {
  5251. if (error) {
  5252. return self.callbacks.forEach(function (callback) {
  5253. callback(error);
  5254. });
  5255. }
  5256. if(utils.isObject(sync) && sync.startingBlock)
  5257. sync = formatters.outputSyncingFormatter(sync);
  5258. self.callbacks.forEach(function (callback) {
  5259. if (self.lastSyncState !== sync) {
  5260. // call the callback with true first so the app can stop anything, before receiving the sync data
  5261. if(!self.lastSyncState && utils.isObject(sync))
  5262. callback(null, true);
  5263. // call on the next CPU cycle, so the actions of the sync stop can be processes first
  5264. setTimeout(function() {
  5265. callback(null, sync);
  5266. }, 0);
  5267. self.lastSyncState = sync;
  5268. }
  5269. });
  5270. };
  5271. self.requestManager.startPolling({
  5272. method: 'eth_syncing',
  5273. params: [],
  5274. }, self.pollId, onMessage, self.stopWatching.bind(self));
  5275. };
  5276. var IsSyncing = function (requestManager, callback) {
  5277. this.requestManager = requestManager;
  5278. this.pollId = 'syncPoll_'+ count++;
  5279. this.callbacks = [];
  5280. this.addCallback(callback);
  5281. this.lastSyncState = false;
  5282. pollSyncing(this);
  5283. return this;
  5284. };
  5285. IsSyncing.prototype.addCallback = function (callback) {
  5286. if(callback)
  5287. this.callbacks.push(callback);
  5288. return this;
  5289. };
  5290. IsSyncing.prototype.stopWatching = function () {
  5291. this.requestManager.stopPolling(this.pollId);
  5292. this.callbacks = [];
  5293. };
  5294. module.exports = IsSyncing;
  5295. },{"../utils/utils":20,"./formatters":30}],47:[function(require,module,exports){
  5296. /*
  5297. This file is part of web3.js.
  5298. web3.js is free software: you can redistribute it and/or modify
  5299. it under the terms of the GNU Lesser General Public License as published by
  5300. the Free Software Foundation, either version 3 of the License, or
  5301. (at your option) any later version.
  5302. web3.js is distributed in the hope that it will be useful,
  5303. but WITHOUT ANY WARRANTY; without even the implied warranty of
  5304. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  5305. GNU Lesser General Public License for more details.
  5306. You should have received a copy of the GNU Lesser General Public License
  5307. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  5308. */
  5309. /**
  5310. * @file transfer.js
  5311. * @author Marek Kotewicz <marek@ethdev.com>
  5312. * @date 2015
  5313. */
  5314. var Iban = require('./iban');
  5315. var exchangeAbi = require('../contracts/SmartExchange.json');
  5316. /**
  5317. * Should be used to make Iban transfer
  5318. *
  5319. * @method transfer
  5320. * @param {String} from
  5321. * @param {String} to iban
  5322. * @param {Value} value to be tranfered
  5323. * @param {Function} callback, callback
  5324. */
  5325. var transfer = function (eth, from, to, value, callback) {
  5326. var iban = new Iban(to);
  5327. if (!iban.isValid()) {
  5328. throw new Error('invalid iban address');
  5329. }
  5330. if (iban.isDirect()) {
  5331. return transferToAddress(eth, from, iban.address(), value, callback);
  5332. }
  5333. if (!callback) {
  5334. var address = eth.icapNamereg().addr(iban.institution());
  5335. return deposit(eth, from, address, value, iban.client());
  5336. }
  5337. eth.icapNamereg().addr(iban.institution(), function (err, address) {
  5338. return deposit(eth, from, address, value, iban.client(), callback);
  5339. });
  5340. };
  5341. /**
  5342. * Should be used to transfer funds to certain address
  5343. *
  5344. * @method transferToAddress
  5345. * @param {String} from
  5346. * @param {String} to
  5347. * @param {Value} value to be tranfered
  5348. * @param {Function} callback, callback
  5349. */
  5350. var transferToAddress = function (eth, from, to, value, callback) {
  5351. return eth.sendTransaction({
  5352. address: to,
  5353. from: from,
  5354. value: value
  5355. }, callback);
  5356. };
  5357. /**
  5358. * Should be used to deposit funds to generic Exchange contract (must implement deposit(bytes32) method!)
  5359. *
  5360. * @method deposit
  5361. * @param {String} from
  5362. * @param {String} to
  5363. * @param {Value} value to be transfered
  5364. * @param {String} client unique identifier
  5365. * @param {Function} callback, callback
  5366. */
  5367. var deposit = function (eth, from, to, value, client, callback) {
  5368. var abi = exchangeAbi;
  5369. return eth.contract(abi).at(to).deposit(client, {
  5370. from: from,
  5371. value: value
  5372. }, callback);
  5373. };
  5374. module.exports = transfer;
  5375. },{"../contracts/SmartExchange.json":3,"./iban":33}],48:[function(require,module,exports){
  5376. },{}],49:[function(require,module,exports){
  5377. ;(function (root, factory, undef) {
  5378. if (typeof exports === "object") {
  5379. // CommonJS
  5380. module.exports = exports = factory(require("./core"), require("./enc-base64"), require("./md5"), require("./evpkdf"), require("./cipher-core"));
  5381. }
  5382. else if (typeof define === "function" && define.amd) {
  5383. // AMD
  5384. define(["./core", "./enc-base64", "./md5", "./evpkdf", "./cipher-core"], factory);
  5385. }
  5386. else {
  5387. // Global (browser)
  5388. factory(root.CryptoJS);
  5389. }
  5390. }(this, function (CryptoJS) {
  5391. (function () {
  5392. // Shortcuts
  5393. var C = CryptoJS;
  5394. var C_lib = C.lib;
  5395. var BlockCipher = C_lib.BlockCipher;
  5396. var C_algo = C.algo;
  5397. // Lookup tables
  5398. var SBOX = [];
  5399. var INV_SBOX = [];
  5400. var SUB_MIX_0 = [];
  5401. var SUB_MIX_1 = [];
  5402. var SUB_MIX_2 = [];
  5403. var SUB_MIX_3 = [];
  5404. var INV_SUB_MIX_0 = [];
  5405. var INV_SUB_MIX_1 = [];
  5406. var INV_SUB_MIX_2 = [];
  5407. var INV_SUB_MIX_3 = [];
  5408. // Compute lookup tables
  5409. (function () {
  5410. // Compute double table
  5411. var d = [];
  5412. for (var i = 0; i < 256; i++) {
  5413. if (i < 128) {
  5414. d[i] = i << 1;
  5415. } else {
  5416. d[i] = (i << 1) ^ 0x11b;
  5417. }
  5418. }
  5419. // Walk GF(2^8)
  5420. var x = 0;
  5421. var xi = 0;
  5422. for (var i = 0; i < 256; i++) {
  5423. // Compute sbox
  5424. var sx = xi ^ (xi << 1) ^ (xi << 2) ^ (xi << 3) ^ (xi << 4);
  5425. sx = (sx >>> 8) ^ (sx & 0xff) ^ 0x63;
  5426. SBOX[x] = sx;
  5427. INV_SBOX[sx] = x;
  5428. // Compute multiplication
  5429. var x2 = d[x];
  5430. var x4 = d[x2];
  5431. var x8 = d[x4];
  5432. // Compute sub bytes, mix columns tables
  5433. var t = (d[sx] * 0x101) ^ (sx * 0x1010100);
  5434. SUB_MIX_0[x] = (t << 24) | (t >>> 8);
  5435. SUB_MIX_1[x] = (t << 16) | (t >>> 16);
  5436. SUB_MIX_2[x] = (t << 8) | (t >>> 24);
  5437. SUB_MIX_3[x] = t;
  5438. // Compute inv sub bytes, inv mix columns tables
  5439. var t = (x8 * 0x1010101) ^ (x4 * 0x10001) ^ (x2 * 0x101) ^ (x * 0x1010100);
  5440. INV_SUB_MIX_0[sx] = (t << 24) | (t >>> 8);
  5441. INV_SUB_MIX_1[sx] = (t << 16) | (t >>> 16);
  5442. INV_SUB_MIX_2[sx] = (t << 8) | (t >>> 24);
  5443. INV_SUB_MIX_3[sx] = t;
  5444. // Compute next counter
  5445. if (!x) {
  5446. x = xi = 1;
  5447. } else {
  5448. x = x2 ^ d[d[d[x8 ^ x2]]];
  5449. xi ^= d[d[xi]];
  5450. }
  5451. }
  5452. }());
  5453. // Precomputed Rcon lookup
  5454. var RCON = [0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36];
  5455. /**
  5456. * AES block cipher algorithm.
  5457. */
  5458. var AES = C_algo.AES = BlockCipher.extend({
  5459. _doReset: function () {
  5460. // Shortcuts
  5461. var key = this._key;
  5462. var keyWords = key.words;
  5463. var keySize = key.sigBytes / 4;
  5464. // Compute number of rounds
  5465. var nRounds = this._nRounds = keySize + 6
  5466. // Compute number of key schedule rows
  5467. var ksRows = (nRounds + 1) * 4;
  5468. // Compute key schedule
  5469. var keySchedule = this._keySchedule = [];
  5470. for (var ksRow = 0; ksRow < ksRows; ksRow++) {
  5471. if (ksRow < keySize) {
  5472. keySchedule[ksRow] = keyWords[ksRow];
  5473. } else {
  5474. var t = keySchedule[ksRow - 1];
  5475. if (!(ksRow % keySize)) {
  5476. // Rot word
  5477. t = (t << 8) | (t >>> 24);
  5478. // Sub word
  5479. t = (SBOX[t >>> 24] << 24) | (SBOX[(t >>> 16) & 0xff] << 16) | (SBOX[(t >>> 8) & 0xff] << 8) | SBOX[t & 0xff];
  5480. // Mix Rcon
  5481. t ^= RCON[(ksRow / keySize) | 0] << 24;
  5482. } else if (keySize > 6 && ksRow % keySize == 4) {
  5483. // Sub word
  5484. t = (SBOX[t >>> 24] << 24) | (SBOX[(t >>> 16) & 0xff] << 16) | (SBOX[(t >>> 8) & 0xff] << 8) | SBOX[t & 0xff];
  5485. }
  5486. keySchedule[ksRow] = keySchedule[ksRow - keySize] ^ t;
  5487. }
  5488. }
  5489. // Compute inv key schedule
  5490. var invKeySchedule = this._invKeySchedule = [];
  5491. for (var invKsRow = 0; invKsRow < ksRows; invKsRow++) {
  5492. var ksRow = ksRows - invKsRow;
  5493. if (invKsRow % 4) {
  5494. var t = keySchedule[ksRow];
  5495. } else {
  5496. var t = keySchedule[ksRow - 4];
  5497. }
  5498. if (invKsRow < 4 || ksRow <= 4) {
  5499. invKeySchedule[invKsRow] = t;
  5500. } else {
  5501. invKeySchedule[invKsRow] = INV_SUB_MIX_0[SBOX[t >>> 24]] ^ INV_SUB_MIX_1[SBOX[(t >>> 16) & 0xff]] ^
  5502. INV_SUB_MIX_2[SBOX[(t >>> 8) & 0xff]] ^ INV_SUB_MIX_3[SBOX[t & 0xff]];
  5503. }
  5504. }
  5505. },
  5506. encryptBlock: function (M, offset) {
  5507. this._doCryptBlock(M, offset, this._keySchedule, SUB_MIX_0, SUB_MIX_1, SUB_MIX_2, SUB_MIX_3, SBOX);
  5508. },
  5509. decryptBlock: function (M, offset) {
  5510. // Swap 2nd and 4th rows
  5511. var t = M[offset + 1];
  5512. M[offset + 1] = M[offset + 3];
  5513. M[offset + 3] = t;
  5514. this._doCryptBlock(M, offset, this._invKeySchedule, INV_SUB_MIX_0, INV_SUB_MIX_1, INV_SUB_MIX_2, INV_SUB_MIX_3, INV_SBOX);
  5515. // Inv swap 2nd and 4th rows
  5516. var t = M[offset + 1];
  5517. M[offset + 1] = M[offset + 3];
  5518. M[offset + 3] = t;
  5519. },
  5520. _doCryptBlock: function (M, offset, keySchedule, SUB_MIX_0, SUB_MIX_1, SUB_MIX_2, SUB_MIX_3, SBOX) {
  5521. // Shortcut
  5522. var nRounds = this._nRounds;
  5523. // Get input, add round key
  5524. var s0 = M[offset] ^ keySchedule[0];
  5525. var s1 = M[offset + 1] ^ keySchedule[1];
  5526. var s2 = M[offset + 2] ^ keySchedule[2];
  5527. var s3 = M[offset + 3] ^ keySchedule[3];
  5528. // Key schedule row counter
  5529. var ksRow = 4;
  5530. // Rounds
  5531. for (var round = 1; round < nRounds; round++) {
  5532. // Shift rows, sub bytes, mix columns, add round key
  5533. 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++];
  5534. 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++];
  5535. 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++];
  5536. 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++];
  5537. // Update state
  5538. s0 = t0;
  5539. s1 = t1;
  5540. s2 = t2;
  5541. s3 = t3;
  5542. }
  5543. // Shift rows, sub bytes, add round key
  5544. var t0 = ((SBOX[s0 >>> 24] << 24) | (SBOX[(s1 >>> 16) & 0xff] << 16) | (SBOX[(s2 >>> 8) & 0xff] << 8) | SBOX[s3 & 0xff]) ^ keySchedule[ksRow++];
  5545. var t1 = ((SBOX[s1 >>> 24] << 24) | (SBOX[(s2 >>> 16) & 0xff] << 16) | (SBOX[(s3 >>> 8) & 0xff] << 8) | SBOX[s0 & 0xff]) ^ keySchedule[ksRow++];
  5546. var t2 = ((SBOX[s2 >>> 24] << 24) | (SBOX[(s3 >>> 16) & 0xff] << 16) | (SBOX[(s0 >>> 8) & 0xff] << 8) | SBOX[s1 & 0xff]) ^ keySchedule[ksRow++];
  5547. var t3 = ((SBOX[s3 >>> 24] << 24) | (SBOX[(s0 >>> 16) & 0xff] << 16) | (SBOX[(s1 >>> 8) & 0xff] << 8) | SBOX[s2 & 0xff]) ^ keySchedule[ksRow++];
  5548. // Set output
  5549. M[offset] = t0;
  5550. M[offset + 1] = t1;
  5551. M[offset + 2] = t2;
  5552. M[offset + 3] = t3;
  5553. },
  5554. keySize: 256/32
  5555. });
  5556. /**
  5557. * Shortcut functions to the cipher's object interface.
  5558. *
  5559. * @example
  5560. *
  5561. * var ciphertext = CryptoJS.AES.encrypt(message, key, cfg);
  5562. * var plaintext = CryptoJS.AES.decrypt(ciphertext, key, cfg);
  5563. */
  5564. C.AES = BlockCipher._createHelper(AES);
  5565. }());
  5566. return CryptoJS.AES;
  5567. }));
  5568. },{"./cipher-core":50,"./core":51,"./enc-base64":52,"./evpkdf":54,"./md5":59}],50:[function(require,module,exports){
  5569. ;(function (root, factory) {
  5570. if (typeof exports === "object") {
  5571. // CommonJS
  5572. module.exports = exports = factory(require("./core"));
  5573. }
  5574. else if (typeof define === "function" && define.amd) {
  5575. // AMD
  5576. define(["./core"], factory);
  5577. }
  5578. else {
  5579. // Global (browser)
  5580. factory(root.CryptoJS);
  5581. }
  5582. }(this, function (CryptoJS) {
  5583. /**
  5584. * Cipher core components.
  5585. */
  5586. CryptoJS.lib.Cipher || (function (undefined) {
  5587. // Shortcuts
  5588. var C = CryptoJS;
  5589. var C_lib = C.lib;
  5590. var Base = C_lib.Base;
  5591. var WordArray = C_lib.WordArray;
  5592. var BufferedBlockAlgorithm = C_lib.BufferedBlockAlgorithm;
  5593. var C_enc = C.enc;
  5594. var Utf8 = C_enc.Utf8;
  5595. var Base64 = C_enc.Base64;
  5596. var C_algo = C.algo;
  5597. var EvpKDF = C_algo.EvpKDF;
  5598. /**
  5599. * Abstract base cipher template.
  5600. *
  5601. * @property {number} keySize This cipher's key size. Default: 4 (128 bits)
  5602. * @property {number} ivSize This cipher's IV size. Default: 4 (128 bits)
  5603. * @property {number} _ENC_XFORM_MODE A constant representing encryption mode.
  5604. * @property {number} _DEC_XFORM_MODE A constant representing decryption mode.
  5605. */
  5606. var Cipher = C_lib.Cipher = BufferedBlockAlgorithm.extend({
  5607. /**
  5608. * Configuration options.
  5609. *
  5610. * @property {WordArray} iv The IV to use for this operation.
  5611. */
  5612. cfg: Base.extend(),
  5613. /**
  5614. * Creates this cipher in encryption mode.
  5615. *
  5616. * @param {WordArray} key The key.
  5617. * @param {Object} cfg (Optional) The configuration options to use for this operation.
  5618. *
  5619. * @return {Cipher} A cipher instance.
  5620. *
  5621. * @static
  5622. *
  5623. * @example
  5624. *
  5625. * var cipher = CryptoJS.algo.AES.createEncryptor(keyWordArray, { iv: ivWordArray });
  5626. */
  5627. createEncryptor: function (key, cfg) {
  5628. return this.create(this._ENC_XFORM_MODE, key, cfg);
  5629. },
  5630. /**
  5631. * Creates this cipher in decryption mode.
  5632. *
  5633. * @param {WordArray} key The key.
  5634. * @param {Object} cfg (Optional) The configuration options to use for this operation.
  5635. *
  5636. * @return {Cipher} A cipher instance.
  5637. *
  5638. * @static
  5639. *
  5640. * @example
  5641. *
  5642. * var cipher = CryptoJS.algo.AES.createDecryptor(keyWordArray, { iv: ivWordArray });
  5643. */
  5644. createDecryptor: function (key, cfg) {
  5645. return this.create(this._DEC_XFORM_MODE, key, cfg);
  5646. },
  5647. /**
  5648. * Initializes a newly created cipher.
  5649. *
  5650. * @param {number} xformMode Either the encryption or decryption transormation mode constant.
  5651. * @param {WordArray} key The key.
  5652. * @param {Object} cfg (Optional) The configuration options to use for this operation.
  5653. *
  5654. * @example
  5655. *
  5656. * var cipher = CryptoJS.algo.AES.create(CryptoJS.algo.AES._ENC_XFORM_MODE, keyWordArray, { iv: ivWordArray });
  5657. */
  5658. init: function (xformMode, key, cfg) {
  5659. // Apply config defaults
  5660. this.cfg = this.cfg.extend(cfg);
  5661. // Store transform mode and key
  5662. this._xformMode = xformMode;
  5663. this._key = key;
  5664. // Set initial values
  5665. this.reset();
  5666. },
  5667. /**
  5668. * Resets this cipher to its initial state.
  5669. *
  5670. * @example
  5671. *
  5672. * cipher.reset();
  5673. */
  5674. reset: function () {
  5675. // Reset data buffer
  5676. BufferedBlockAlgorithm.reset.call(this);
  5677. // Perform concrete-cipher logic
  5678. this._doReset();
  5679. },
  5680. /**
  5681. * Adds data to be encrypted or decrypted.
  5682. *
  5683. * @param {WordArray|string} dataUpdate The data to encrypt or decrypt.
  5684. *
  5685. * @return {WordArray} The data after processing.
  5686. *
  5687. * @example
  5688. *
  5689. * var encrypted = cipher.process('data');
  5690. * var encrypted = cipher.process(wordArray);
  5691. */
  5692. process: function (dataUpdate) {
  5693. // Append
  5694. this._append(dataUpdate);
  5695. // Process available blocks
  5696. return this._process();
  5697. },
  5698. /**
  5699. * Finalizes the encryption or decryption process.
  5700. * Note that the finalize operation is effectively a destructive, read-once operation.
  5701. *
  5702. * @param {WordArray|string} dataUpdate The final data to encrypt or decrypt.
  5703. *
  5704. * @return {WordArray} The data after final processing.
  5705. *
  5706. * @example
  5707. *
  5708. * var encrypted = cipher.finalize();
  5709. * var encrypted = cipher.finalize('data');
  5710. * var encrypted = cipher.finalize(wordArray);
  5711. */
  5712. finalize: function (dataUpdate) {
  5713. // Final data update
  5714. if (dataUpdate) {
  5715. this._append(dataUpdate);
  5716. }
  5717. // Perform concrete-cipher logic
  5718. var finalProcessedData = this._doFinalize();
  5719. return finalProcessedData;
  5720. },
  5721. keySize: 128/32,
  5722. ivSize: 128/32,
  5723. _ENC_XFORM_MODE: 1,
  5724. _DEC_XFORM_MODE: 2,
  5725. /**
  5726. * Creates shortcut functions to a cipher's object interface.
  5727. *
  5728. * @param {Cipher} cipher The cipher to create a helper for.
  5729. *
  5730. * @return {Object} An object with encrypt and decrypt shortcut functions.
  5731. *
  5732. * @static
  5733. *
  5734. * @example
  5735. *
  5736. * var AES = CryptoJS.lib.Cipher._createHelper(CryptoJS.algo.AES);
  5737. */
  5738. _createHelper: (function () {
  5739. function selectCipherStrategy(key) {
  5740. if (typeof key == 'string') {
  5741. return PasswordBasedCipher;
  5742. } else {
  5743. return SerializableCipher;
  5744. }
  5745. }
  5746. return function (cipher) {
  5747. return {
  5748. encrypt: function (message, key, cfg) {
  5749. return selectCipherStrategy(key).encrypt(cipher, message, key, cfg);
  5750. },
  5751. decrypt: function (ciphertext, key, cfg) {
  5752. return selectCipherStrategy(key).decrypt(cipher, ciphertext, key, cfg);
  5753. }
  5754. };
  5755. };
  5756. }())
  5757. });
  5758. /**
  5759. * Abstract base stream cipher template.
  5760. *
  5761. * @property {number} blockSize The number of 32-bit words this cipher operates on. Default: 1 (32 bits)
  5762. */
  5763. var StreamCipher = C_lib.StreamCipher = Cipher.extend({
  5764. _doFinalize: function () {
  5765. // Process partial blocks
  5766. var finalProcessedBlocks = this._process(!!'flush');
  5767. return finalProcessedBlocks;
  5768. },
  5769. blockSize: 1
  5770. });
  5771. /**
  5772. * Mode namespace.
  5773. */
  5774. var C_mode = C.mode = {};
  5775. /**
  5776. * Abstract base block cipher mode template.
  5777. */
  5778. var BlockCipherMode = C_lib.BlockCipherMode = Base.extend({
  5779. /**
  5780. * Creates this mode for encryption.
  5781. *
  5782. * @param {Cipher} cipher A block cipher instance.
  5783. * @param {Array} iv The IV words.
  5784. *
  5785. * @static
  5786. *
  5787. * @example
  5788. *
  5789. * var mode = CryptoJS.mode.CBC.createEncryptor(cipher, iv.words);
  5790. */
  5791. createEncryptor: function (cipher, iv) {
  5792. return this.Encryptor.create(cipher, iv);
  5793. },
  5794. /**
  5795. * Creates this mode for decryption.
  5796. *
  5797. * @param {Cipher} cipher A block cipher instance.
  5798. * @param {Array} iv The IV words.
  5799. *
  5800. * @static
  5801. *
  5802. * @example
  5803. *
  5804. * var mode = CryptoJS.mode.CBC.createDecryptor(cipher, iv.words);
  5805. */
  5806. createDecryptor: function (cipher, iv) {
  5807. return this.Decryptor.create(cipher, iv);
  5808. },
  5809. /**
  5810. * Initializes a newly created mode.
  5811. *
  5812. * @param {Cipher} cipher A block cipher instance.
  5813. * @param {Array} iv The IV words.
  5814. *
  5815. * @example
  5816. *
  5817. * var mode = CryptoJS.mode.CBC.Encryptor.create(cipher, iv.words);
  5818. */
  5819. init: function (cipher, iv) {
  5820. this._cipher = cipher;
  5821. this._iv = iv;
  5822. }
  5823. });
  5824. /**
  5825. * Cipher Block Chaining mode.
  5826. */
  5827. var CBC = C_mode.CBC = (function () {
  5828. /**
  5829. * Abstract base CBC mode.
  5830. */
  5831. var CBC = BlockCipherMode.extend();
  5832. /**
  5833. * CBC encryptor.
  5834. */
  5835. CBC.Encryptor = CBC.extend({
  5836. /**
  5837. * Processes the data block at offset.
  5838. *
  5839. * @param {Array} words The data words to operate on.
  5840. * @param {number} offset The offset where the block starts.
  5841. *
  5842. * @example
  5843. *
  5844. * mode.processBlock(data.words, offset);
  5845. */
  5846. processBlock: function (words, offset) {
  5847. // Shortcuts
  5848. var cipher = this._cipher;
  5849. var blockSize = cipher.blockSize;
  5850. // XOR and encrypt
  5851. xorBlock.call(this, words, offset, blockSize);
  5852. cipher.encryptBlock(words, offset);
  5853. // Remember this block to use with next block
  5854. this._prevBlock = words.slice(offset, offset + blockSize);
  5855. }
  5856. });
  5857. /**
  5858. * CBC decryptor.
  5859. */
  5860. CBC.Decryptor = CBC.extend({
  5861. /**
  5862. * Processes the data block at offset.
  5863. *
  5864. * @param {Array} words The data words to operate on.
  5865. * @param {number} offset The offset where the block starts.
  5866. *
  5867. * @example
  5868. *
  5869. * mode.processBlock(data.words, offset);
  5870. */
  5871. processBlock: function (words, offset) {
  5872. // Shortcuts
  5873. var cipher = this._cipher;
  5874. var blockSize = cipher.blockSize;
  5875. // Remember this block to use with next block
  5876. var thisBlock = words.slice(offset, offset + blockSize);
  5877. // Decrypt and XOR
  5878. cipher.decryptBlock(words, offset);
  5879. xorBlock.call(this, words, offset, blockSize);
  5880. // This block becomes the previous block
  5881. this._prevBlock = thisBlock;
  5882. }
  5883. });
  5884. function xorBlock(words, offset, blockSize) {
  5885. // Shortcut
  5886. var iv = this._iv;
  5887. // Choose mixing block
  5888. if (iv) {
  5889. var block = iv;
  5890. // Remove IV for subsequent blocks
  5891. this._iv = undefined;
  5892. } else {
  5893. var block = this._prevBlock;
  5894. }
  5895. // XOR blocks
  5896. for (var i = 0; i < blockSize; i++) {
  5897. words[offset + i] ^= block[i];
  5898. }
  5899. }
  5900. return CBC;
  5901. }());
  5902. /**
  5903. * Padding namespace.
  5904. */
  5905. var C_pad = C.pad = {};
  5906. /**
  5907. * PKCS #5/7 padding strategy.
  5908. */
  5909. var Pkcs7 = C_pad.Pkcs7 = {
  5910. /**
  5911. * Pads data using the algorithm defined in PKCS #5/7.
  5912. *
  5913. * @param {WordArray} data The data to pad.
  5914. * @param {number} blockSize The multiple that the data should be padded to.
  5915. *
  5916. * @static
  5917. *
  5918. * @example
  5919. *
  5920. * CryptoJS.pad.Pkcs7.pad(wordArray, 4);
  5921. */
  5922. pad: function (data, blockSize) {
  5923. // Shortcut
  5924. var blockSizeBytes = blockSize * 4;
  5925. // Count padding bytes
  5926. var nPaddingBytes = blockSizeBytes - data.sigBytes % blockSizeBytes;
  5927. // Create padding word
  5928. var paddingWord = (nPaddingBytes << 24) | (nPaddingBytes << 16) | (nPaddingBytes << 8) | nPaddingBytes;
  5929. // Create padding
  5930. var paddingWords = [];
  5931. for (var i = 0; i < nPaddingBytes; i += 4) {
  5932. paddingWords.push(paddingWord);
  5933. }
  5934. var padding = WordArray.create(paddingWords, nPaddingBytes);
  5935. // Add padding
  5936. data.concat(padding);
  5937. },
  5938. /**
  5939. * Unpads data that had been padded using the algorithm defined in PKCS #5/7.
  5940. *
  5941. * @param {WordArray} data The data to unpad.
  5942. *
  5943. * @static
  5944. *
  5945. * @example
  5946. *
  5947. * CryptoJS.pad.Pkcs7.unpad(wordArray);
  5948. */
  5949. unpad: function (data) {
  5950. // Get number of padding bytes from last byte
  5951. var nPaddingBytes = data.words[(data.sigBytes - 1) >>> 2] & 0xff;
  5952. // Remove padding
  5953. data.sigBytes -= nPaddingBytes;
  5954. }
  5955. };
  5956. /**
  5957. * Abstract base block cipher template.
  5958. *
  5959. * @property {number} blockSize The number of 32-bit words this cipher operates on. Default: 4 (128 bits)
  5960. */
  5961. var BlockCipher = C_lib.BlockCipher = Cipher.extend({
  5962. /**
  5963. * Configuration options.
  5964. *
  5965. * @property {Mode} mode The block mode to use. Default: CBC
  5966. * @property {Padding} padding The padding strategy to use. Default: Pkcs7
  5967. */
  5968. cfg: Cipher.cfg.extend({
  5969. mode: CBC,
  5970. padding: Pkcs7
  5971. }),
  5972. reset: function () {
  5973. // Reset cipher
  5974. Cipher.reset.call(this);
  5975. // Shortcuts
  5976. var cfg = this.cfg;
  5977. var iv = cfg.iv;
  5978. var mode = cfg.mode;
  5979. // Reset block mode
  5980. if (this._xformMode == this._ENC_XFORM_MODE) {
  5981. var modeCreator = mode.createEncryptor;
  5982. } else /* if (this._xformMode == this._DEC_XFORM_MODE) */ {
  5983. var modeCreator = mode.createDecryptor;
  5984. // Keep at least one block in the buffer for unpadding
  5985. this._minBufferSize = 1;
  5986. }
  5987. this._mode = modeCreator.call(mode, this, iv && iv.words);
  5988. },
  5989. _doProcessBlock: function (words, offset) {
  5990. this._mode.processBlock(words, offset);
  5991. },
  5992. _doFinalize: function () {
  5993. // Shortcut
  5994. var padding = this.cfg.padding;
  5995. // Finalize
  5996. if (this._xformMode == this._ENC_XFORM_MODE) {
  5997. // Pad data
  5998. padding.pad(this._data, this.blockSize);
  5999. // Process final blocks
  6000. var finalProcessedBlocks = this._process(!!'flush');
  6001. } else /* if (this._xformMode == this._DEC_XFORM_MODE) */ {
  6002. // Process final blocks
  6003. var finalProcessedBlocks = this._process(!!'flush');
  6004. // Unpad data
  6005. padding.unpad(finalProcessedBlocks);
  6006. }
  6007. return finalProcessedBlocks;
  6008. },
  6009. blockSize: 128/32
  6010. });
  6011. /**
  6012. * A collection of cipher parameters.
  6013. *
  6014. * @property {WordArray} ciphertext The raw ciphertext.
  6015. * @property {WordArray} key The key to this ciphertext.
  6016. * @property {WordArray} iv The IV used in the ciphering operation.
  6017. * @property {WordArray} salt The salt used with a key derivation function.
  6018. * @property {Cipher} algorithm The cipher algorithm.
  6019. * @property {Mode} mode The block mode used in the ciphering operation.
  6020. * @property {Padding} padding The padding scheme used in the ciphering operation.
  6021. * @property {number} blockSize The block size of the cipher.
  6022. * @property {Format} formatter The default formatting strategy to convert this cipher params object to a string.
  6023. */
  6024. var CipherParams = C_lib.CipherParams = Base.extend({
  6025. /**
  6026. * Initializes a newly created cipher params object.
  6027. *
  6028. * @param {Object} cipherParams An object with any of the possible cipher parameters.
  6029. *
  6030. * @example
  6031. *
  6032. * var cipherParams = CryptoJS.lib.CipherParams.create({
  6033. * ciphertext: ciphertextWordArray,
  6034. * key: keyWordArray,
  6035. * iv: ivWordArray,
  6036. * salt: saltWordArray,
  6037. * algorithm: CryptoJS.algo.AES,
  6038. * mode: CryptoJS.mode.CBC,
  6039. * padding: CryptoJS.pad.PKCS7,
  6040. * blockSize: 4,
  6041. * formatter: CryptoJS.format.OpenSSL
  6042. * });
  6043. */
  6044. init: function (cipherParams) {
  6045. this.mixIn(cipherParams);
  6046. },
  6047. /**
  6048. * Converts this cipher params object to a string.
  6049. *
  6050. * @param {Format} formatter (Optional) The formatting strategy to use.
  6051. *
  6052. * @return {string} The stringified cipher params.
  6053. *
  6054. * @throws Error If neither the formatter nor the default formatter is set.
  6055. *
  6056. * @example
  6057. *
  6058. * var string = cipherParams + '';
  6059. * var string = cipherParams.toString();
  6060. * var string = cipherParams.toString(CryptoJS.format.OpenSSL);
  6061. */
  6062. toString: function (formatter) {
  6063. return (formatter || this.formatter).stringify(this);
  6064. }
  6065. });
  6066. /**
  6067. * Format namespace.
  6068. */
  6069. var C_format = C.format = {};
  6070. /**
  6071. * OpenSSL formatting strategy.
  6072. */
  6073. var OpenSSLFormatter = C_format.OpenSSL = {
  6074. /**
  6075. * Converts a cipher params object to an OpenSSL-compatible string.
  6076. *
  6077. * @param {CipherParams} cipherParams The cipher params object.
  6078. *
  6079. * @return {string} The OpenSSL-compatible string.
  6080. *
  6081. * @static
  6082. *
  6083. * @example
  6084. *
  6085. * var openSSLString = CryptoJS.format.OpenSSL.stringify(cipherParams);
  6086. */
  6087. stringify: function (cipherParams) {
  6088. // Shortcuts
  6089. var ciphertext = cipherParams.ciphertext;
  6090. var salt = cipherParams.salt;
  6091. // Format
  6092. if (salt) {
  6093. var wordArray = WordArray.create([0x53616c74, 0x65645f5f]).concat(salt).concat(ciphertext);
  6094. } else {
  6095. var wordArray = ciphertext;
  6096. }
  6097. return wordArray.toString(Base64);
  6098. },
  6099. /**
  6100. * Converts an OpenSSL-compatible string to a cipher params object.
  6101. *
  6102. * @param {string} openSSLStr The OpenSSL-compatible string.
  6103. *
  6104. * @return {CipherParams} The cipher params object.
  6105. *
  6106. * @static
  6107. *
  6108. * @example
  6109. *
  6110. * var cipherParams = CryptoJS.format.OpenSSL.parse(openSSLString);
  6111. */
  6112. parse: function (openSSLStr) {
  6113. // Parse base64
  6114. var ciphertext = Base64.parse(openSSLStr);
  6115. // Shortcut
  6116. var ciphertextWords = ciphertext.words;
  6117. // Test for salt
  6118. if (ciphertextWords[0] == 0x53616c74 && ciphertextWords[1] == 0x65645f5f) {
  6119. // Extract salt
  6120. var salt = WordArray.create(ciphertextWords.slice(2, 4));
  6121. // Remove salt from ciphertext
  6122. ciphertextWords.splice(0, 4);
  6123. ciphertext.sigBytes -= 16;
  6124. }
  6125. return CipherParams.create({ ciphertext: ciphertext, salt: salt });
  6126. }
  6127. };
  6128. /**
  6129. * A cipher wrapper that returns ciphertext as a serializable cipher params object.
  6130. */
  6131. var SerializableCipher = C_lib.SerializableCipher = Base.extend({
  6132. /**
  6133. * Configuration options.
  6134. *
  6135. * @property {Formatter} format The formatting strategy to convert cipher param objects to and from a string. Default: OpenSSL
  6136. */
  6137. cfg: Base.extend({
  6138. format: OpenSSLFormatter
  6139. }),
  6140. /**
  6141. * Encrypts a message.
  6142. *
  6143. * @param {Cipher} cipher The cipher algorithm to use.
  6144. * @param {WordArray|string} message The message to encrypt.
  6145. * @param {WordArray} key The key.
  6146. * @param {Object} cfg (Optional) The configuration options to use for this operation.
  6147. *
  6148. * @return {CipherParams} A cipher params object.
  6149. *
  6150. * @static
  6151. *
  6152. * @example
  6153. *
  6154. * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key);
  6155. * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key, { iv: iv });
  6156. * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key, { iv: iv, format: CryptoJS.format.OpenSSL });
  6157. */
  6158. encrypt: function (cipher, message, key, cfg) {
  6159. // Apply config defaults
  6160. cfg = this.cfg.extend(cfg);
  6161. // Encrypt
  6162. var encryptor = cipher.createEncryptor(key, cfg);
  6163. var ciphertext = encryptor.finalize(message);
  6164. // Shortcut
  6165. var cipherCfg = encryptor.cfg;
  6166. // Create and return serializable cipher params
  6167. return CipherParams.create({
  6168. ciphertext: ciphertext,
  6169. key: key,
  6170. iv: cipherCfg.iv,
  6171. algorithm: cipher,
  6172. mode: cipherCfg.mode,
  6173. padding: cipherCfg.padding,
  6174. blockSize: cipher.blockSize,
  6175. formatter: cfg.format
  6176. });
  6177. },
  6178. /**
  6179. * Decrypts serialized ciphertext.
  6180. *
  6181. * @param {Cipher} cipher The cipher algorithm to use.
  6182. * @param {CipherParams|string} ciphertext The ciphertext to decrypt.
  6183. * @param {WordArray} key The key.
  6184. * @param {Object} cfg (Optional) The configuration options to use for this operation.
  6185. *
  6186. * @return {WordArray} The plaintext.
  6187. *
  6188. * @static
  6189. *
  6190. * @example
  6191. *
  6192. * var plaintext = CryptoJS.lib.SerializableCipher.decrypt(CryptoJS.algo.AES, formattedCiphertext, key, { iv: iv, format: CryptoJS.format.OpenSSL });
  6193. * var plaintext = CryptoJS.lib.SerializableCipher.decrypt(CryptoJS.algo.AES, ciphertextParams, key, { iv: iv, format: CryptoJS.format.OpenSSL });
  6194. */
  6195. decrypt: function (cipher, ciphertext, key, cfg) {
  6196. // Apply config defaults
  6197. cfg = this.cfg.extend(cfg);
  6198. // Convert string to CipherParams
  6199. ciphertext = this._parse(ciphertext, cfg.format);
  6200. // Decrypt
  6201. var plaintext = cipher.createDecryptor(key, cfg).finalize(ciphertext.ciphertext);
  6202. return plaintext;
  6203. },
  6204. /**
  6205. * Converts serialized ciphertext to CipherParams,
  6206. * else assumed CipherParams already and returns ciphertext unchanged.
  6207. *
  6208. * @param {CipherParams|string} ciphertext The ciphertext.
  6209. * @param {Formatter} format The formatting strategy to use to parse serialized ciphertext.
  6210. *
  6211. * @return {CipherParams} The unserialized ciphertext.
  6212. *
  6213. * @static
  6214. *
  6215. * @example
  6216. *
  6217. * var ciphertextParams = CryptoJS.lib.SerializableCipher._parse(ciphertextStringOrParams, format);
  6218. */
  6219. _parse: function (ciphertext, format) {
  6220. if (typeof ciphertext == 'string') {
  6221. return format.parse(ciphertext, this);
  6222. } else {
  6223. return ciphertext;
  6224. }
  6225. }
  6226. });
  6227. /**
  6228. * Key derivation function namespace.
  6229. */
  6230. var C_kdf = C.kdf = {};
  6231. /**
  6232. * OpenSSL key derivation function.
  6233. */
  6234. var OpenSSLKdf = C_kdf.OpenSSL = {
  6235. /**
  6236. * Derives a key and IV from a password.
  6237. *
  6238. * @param {string} password The password to derive from.
  6239. * @param {number} keySize The size in words of the key to generate.
  6240. * @param {number} ivSize The size in words of the IV to generate.
  6241. * @param {WordArray|string} salt (Optional) A 64-bit salt to use. If omitted, a salt will be generated randomly.
  6242. *
  6243. * @return {CipherParams} A cipher params object with the key, IV, and salt.
  6244. *
  6245. * @static
  6246. *
  6247. * @example
  6248. *
  6249. * var derivedParams = CryptoJS.kdf.OpenSSL.execute('Password', 256/32, 128/32);
  6250. * var derivedParams = CryptoJS.kdf.OpenSSL.execute('Password', 256/32, 128/32, 'saltsalt');
  6251. */
  6252. execute: function (password, keySize, ivSize, salt) {
  6253. // Generate random salt
  6254. if (!salt) {
  6255. salt = WordArray.random(64/8);
  6256. }
  6257. // Derive key and IV
  6258. var key = EvpKDF.create({ keySize: keySize + ivSize }).compute(password, salt);
  6259. // Separate key and IV
  6260. var iv = WordArray.create(key.words.slice(keySize), ivSize * 4);
  6261. key.sigBytes = keySize * 4;
  6262. // Return params
  6263. return CipherParams.create({ key: key, iv: iv, salt: salt });
  6264. }
  6265. };
  6266. /**
  6267. * A serializable cipher wrapper that derives the key from a password,
  6268. * and returns ciphertext as a serializable cipher params object.
  6269. */
  6270. var PasswordBasedCipher = C_lib.PasswordBasedCipher = SerializableCipher.extend({
  6271. /**
  6272. * Configuration options.
  6273. *
  6274. * @property {KDF} kdf The key derivation function to use to generate a key and IV from a password. Default: OpenSSL
  6275. */
  6276. cfg: SerializableCipher.cfg.extend({
  6277. kdf: OpenSSLKdf
  6278. }),
  6279. /**
  6280. * Encrypts a message using a password.
  6281. *
  6282. * @param {Cipher} cipher The cipher algorithm to use.
  6283. * @param {WordArray|string} message The message to encrypt.
  6284. * @param {string} password The password.
  6285. * @param {Object} cfg (Optional) The configuration options to use for this operation.
  6286. *
  6287. * @return {CipherParams} A cipher params object.
  6288. *
  6289. * @static
  6290. *
  6291. * @example
  6292. *
  6293. * var ciphertextParams = CryptoJS.lib.PasswordBasedCipher.encrypt(CryptoJS.algo.AES, message, 'password');
  6294. * var ciphertextParams = CryptoJS.lib.PasswordBasedCipher.encrypt(CryptoJS.algo.AES, message, 'password', { format: CryptoJS.format.OpenSSL });
  6295. */
  6296. encrypt: function (cipher, message, password, cfg) {
  6297. // Apply config defaults
  6298. cfg = this.cfg.extend(cfg);
  6299. // Derive key and other params
  6300. var derivedParams = cfg.kdf.execute(password, cipher.keySize, cipher.ivSize);
  6301. // Add IV to config
  6302. cfg.iv = derivedParams.iv;
  6303. // Encrypt
  6304. var ciphertext = SerializableCipher.encrypt.call(this, cipher, message, derivedParams.key, cfg);
  6305. // Mix in derived params
  6306. ciphertext.mixIn(derivedParams);
  6307. return ciphertext;
  6308. },
  6309. /**
  6310. * Decrypts serialized ciphertext using a password.
  6311. *
  6312. * @param {Cipher} cipher The cipher algorithm to use.
  6313. * @param {CipherParams|string} ciphertext The ciphertext to decrypt.
  6314. * @param {string} password The password.
  6315. * @param {Object} cfg (Optional) The configuration options to use for this operation.
  6316. *
  6317. * @return {WordArray} The plaintext.
  6318. *
  6319. * @static
  6320. *
  6321. * @example
  6322. *
  6323. * var plaintext = CryptoJS.lib.PasswordBasedCipher.decrypt(CryptoJS.algo.AES, formattedCiphertext, 'password', { format: CryptoJS.format.OpenSSL });
  6324. * var plaintext = CryptoJS.lib.PasswordBasedCipher.decrypt(CryptoJS.algo.AES, ciphertextParams, 'password', { format: CryptoJS.format.OpenSSL });
  6325. */
  6326. decrypt: function (cipher, ciphertext, password, cfg) {
  6327. // Apply config defaults
  6328. cfg = this.cfg.extend(cfg);
  6329. // Convert string to CipherParams
  6330. ciphertext = this._parse(ciphertext, cfg.format);
  6331. // Derive key and other params
  6332. var derivedParams = cfg.kdf.execute(password, cipher.keySize, cipher.ivSize, ciphertext.salt);
  6333. // Add IV to config
  6334. cfg.iv = derivedParams.iv;
  6335. // Decrypt
  6336. var plaintext = SerializableCipher.decrypt.call(this, cipher, ciphertext, derivedParams.key, cfg);
  6337. return plaintext;
  6338. }
  6339. });
  6340. }());
  6341. }));
  6342. },{"./core":51}],51:[function(require,module,exports){
  6343. ;(function (root, factory) {
  6344. if (typeof exports === "object") {
  6345. // CommonJS
  6346. module.exports = exports = factory();
  6347. }
  6348. else if (typeof define === "function" && define.amd) {
  6349. // AMD
  6350. define([], factory);
  6351. }
  6352. else {
  6353. // Global (browser)
  6354. root.CryptoJS = factory();
  6355. }
  6356. }(this, function () {
  6357. /**
  6358. * CryptoJS core components.
  6359. */
  6360. var CryptoJS = CryptoJS || (function (Math, undefined) {
  6361. /**
  6362. * CryptoJS namespace.
  6363. */
  6364. var C = {};
  6365. /**
  6366. * Library namespace.
  6367. */
  6368. var C_lib = C.lib = {};
  6369. /**
  6370. * Base object for prototypal inheritance.
  6371. */
  6372. var Base = C_lib.Base = (function () {
  6373. function F() {}
  6374. return {
  6375. /**
  6376. * Creates a new object that inherits from this object.
  6377. *
  6378. * @param {Object} overrides Properties to copy into the new object.
  6379. *
  6380. * @return {Object} The new object.
  6381. *
  6382. * @static
  6383. *
  6384. * @example
  6385. *
  6386. * var MyType = CryptoJS.lib.Base.extend({
  6387. * field: 'value',
  6388. *
  6389. * method: function () {
  6390. * }
  6391. * });
  6392. */
  6393. extend: function (overrides) {
  6394. // Spawn
  6395. F.prototype = this;
  6396. var subtype = new F();
  6397. // Augment
  6398. if (overrides) {
  6399. subtype.mixIn(overrides);
  6400. }
  6401. // Create default initializer
  6402. if (!subtype.hasOwnProperty('init')) {
  6403. subtype.init = function () {
  6404. subtype.$super.init.apply(this, arguments);
  6405. };
  6406. }
  6407. // Initializer's prototype is the subtype object
  6408. subtype.init.prototype = subtype;
  6409. // Reference supertype
  6410. subtype.$super = this;
  6411. return subtype;
  6412. },
  6413. /**
  6414. * Extends this object and runs the init method.
  6415. * Arguments to create() will be passed to init().
  6416. *
  6417. * @return {Object} The new object.
  6418. *
  6419. * @static
  6420. *
  6421. * @example
  6422. *
  6423. * var instance = MyType.create();
  6424. */
  6425. create: function () {
  6426. var instance = this.extend();
  6427. instance.init.apply(instance, arguments);
  6428. return instance;
  6429. },
  6430. /**
  6431. * Initializes a newly created object.
  6432. * Override this method to add some logic when your objects are created.
  6433. *
  6434. * @example
  6435. *
  6436. * var MyType = CryptoJS.lib.Base.extend({
  6437. * init: function () {
  6438. * // ...
  6439. * }
  6440. * });
  6441. */
  6442. init: function () {
  6443. },
  6444. /**
  6445. * Copies properties into this object.
  6446. *
  6447. * @param {Object} properties The properties to mix in.
  6448. *
  6449. * @example
  6450. *
  6451. * MyType.mixIn({
  6452. * field: 'value'
  6453. * });
  6454. */
  6455. mixIn: function (properties) {
  6456. for (var propertyName in properties) {
  6457. if (properties.hasOwnProperty(propertyName)) {
  6458. this[propertyName] = properties[propertyName];
  6459. }
  6460. }
  6461. // IE won't copy toString using the loop above
  6462. if (properties.hasOwnProperty('toString')) {
  6463. this.toString = properties.toString;
  6464. }
  6465. },
  6466. /**
  6467. * Creates a copy of this object.
  6468. *
  6469. * @return {Object} The clone.
  6470. *
  6471. * @example
  6472. *
  6473. * var clone = instance.clone();
  6474. */
  6475. clone: function () {
  6476. return this.init.prototype.extend(this);
  6477. }
  6478. };
  6479. }());
  6480. /**
  6481. * An array of 32-bit words.
  6482. *
  6483. * @property {Array} words The array of 32-bit words.
  6484. * @property {number} sigBytes The number of significant bytes in this word array.
  6485. */
  6486. var WordArray = C_lib.WordArray = Base.extend({
  6487. /**
  6488. * Initializes a newly created word array.
  6489. *
  6490. * @param {Array} words (Optional) An array of 32-bit words.
  6491. * @param {number} sigBytes (Optional) The number of significant bytes in the words.
  6492. *
  6493. * @example
  6494. *
  6495. * var wordArray = CryptoJS.lib.WordArray.create();
  6496. * var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607]);
  6497. * var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607], 6);
  6498. */
  6499. init: function (words, sigBytes) {
  6500. words = this.words = words || [];
  6501. if (sigBytes != undefined) {
  6502. this.sigBytes = sigBytes;
  6503. } else {
  6504. this.sigBytes = words.length * 4;
  6505. }
  6506. },
  6507. /**
  6508. * Converts this word array to a string.
  6509. *
  6510. * @param {Encoder} encoder (Optional) The encoding strategy to use. Default: CryptoJS.enc.Hex
  6511. *
  6512. * @return {string} The stringified word array.
  6513. *
  6514. * @example
  6515. *
  6516. * var string = wordArray + '';
  6517. * var string = wordArray.toString();
  6518. * var string = wordArray.toString(CryptoJS.enc.Utf8);
  6519. */
  6520. toString: function (encoder) {
  6521. return (encoder || Hex).stringify(this);
  6522. },
  6523. /**
  6524. * Concatenates a word array to this word array.
  6525. *
  6526. * @param {WordArray} wordArray The word array to append.
  6527. *
  6528. * @return {WordArray} This word array.
  6529. *
  6530. * @example
  6531. *
  6532. * wordArray1.concat(wordArray2);
  6533. */
  6534. concat: function (wordArray) {
  6535. // Shortcuts
  6536. var thisWords = this.words;
  6537. var thatWords = wordArray.words;
  6538. var thisSigBytes = this.sigBytes;
  6539. var thatSigBytes = wordArray.sigBytes;
  6540. // Clamp excess bits
  6541. this.clamp();
  6542. // Concat
  6543. if (thisSigBytes % 4) {
  6544. // Copy one byte at a time
  6545. for (var i = 0; i < thatSigBytes; i++) {
  6546. var thatByte = (thatWords[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff;
  6547. thisWords[(thisSigBytes + i) >>> 2] |= thatByte << (24 - ((thisSigBytes + i) % 4) * 8);
  6548. }
  6549. } else {
  6550. // Copy one word at a time
  6551. for (var i = 0; i < thatSigBytes; i += 4) {
  6552. thisWords[(thisSigBytes + i) >>> 2] = thatWords[i >>> 2];
  6553. }
  6554. }
  6555. this.sigBytes += thatSigBytes;
  6556. // Chainable
  6557. return this;
  6558. },
  6559. /**
  6560. * Removes insignificant bits.
  6561. *
  6562. * @example
  6563. *
  6564. * wordArray.clamp();
  6565. */
  6566. clamp: function () {
  6567. // Shortcuts
  6568. var words = this.words;
  6569. var sigBytes = this.sigBytes;
  6570. // Clamp
  6571. words[sigBytes >>> 2] &= 0xffffffff << (32 - (sigBytes % 4) * 8);
  6572. words.length = Math.ceil(sigBytes / 4);
  6573. },
  6574. /**
  6575. * Creates a copy of this word array.
  6576. *
  6577. * @return {WordArray} The clone.
  6578. *
  6579. * @example
  6580. *
  6581. * var clone = wordArray.clone();
  6582. */
  6583. clone: function () {
  6584. var clone = Base.clone.call(this);
  6585. clone.words = this.words.slice(0);
  6586. return clone;
  6587. },
  6588. /**
  6589. * Creates a word array filled with random bytes.
  6590. *
  6591. * @param {number} nBytes The number of random bytes to generate.
  6592. *
  6593. * @return {WordArray} The random word array.
  6594. *
  6595. * @static
  6596. *
  6597. * @example
  6598. *
  6599. * var wordArray = CryptoJS.lib.WordArray.random(16);
  6600. */
  6601. random: function (nBytes) {
  6602. var words = [];
  6603. var r = (function (m_w) {
  6604. var m_w = m_w;
  6605. var m_z = 0x3ade68b1;
  6606. var mask = 0xffffffff;
  6607. return function () {
  6608. m_z = (0x9069 * (m_z & 0xFFFF) + (m_z >> 0x10)) & mask;
  6609. m_w = (0x4650 * (m_w & 0xFFFF) + (m_w >> 0x10)) & mask;
  6610. var result = ((m_z << 0x10) + m_w) & mask;
  6611. result /= 0x100000000;
  6612. result += 0.5;
  6613. return result * (Math.random() > .5 ? 1 : -1);
  6614. }
  6615. });
  6616. for (var i = 0, rcache; i < nBytes; i += 4) {
  6617. var _r = r((rcache || Math.random()) * 0x100000000);
  6618. rcache = _r() * 0x3ade67b7;
  6619. words.push((_r() * 0x100000000) | 0);
  6620. }
  6621. return new WordArray.init(words, nBytes);
  6622. }
  6623. });
  6624. /**
  6625. * Encoder namespace.
  6626. */
  6627. var C_enc = C.enc = {};
  6628. /**
  6629. * Hex encoding strategy.
  6630. */
  6631. var Hex = C_enc.Hex = {
  6632. /**
  6633. * Converts a word array to a hex string.
  6634. *
  6635. * @param {WordArray} wordArray The word array.
  6636. *
  6637. * @return {string} The hex string.
  6638. *
  6639. * @static
  6640. *
  6641. * @example
  6642. *
  6643. * var hexString = CryptoJS.enc.Hex.stringify(wordArray);
  6644. */
  6645. stringify: function (wordArray) {
  6646. // Shortcuts
  6647. var words = wordArray.words;
  6648. var sigBytes = wordArray.sigBytes;
  6649. // Convert
  6650. var hexChars = [];
  6651. for (var i = 0; i < sigBytes; i++) {
  6652. var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff;
  6653. hexChars.push((bite >>> 4).toString(16));
  6654. hexChars.push((bite & 0x0f).toString(16));
  6655. }
  6656. return hexChars.join('');
  6657. },
  6658. /**
  6659. * Converts a hex string to a word array.
  6660. *
  6661. * @param {string} hexStr The hex string.
  6662. *
  6663. * @return {WordArray} The word array.
  6664. *
  6665. * @static
  6666. *
  6667. * @example
  6668. *
  6669. * var wordArray = CryptoJS.enc.Hex.parse(hexString);
  6670. */
  6671. parse: function (hexStr) {
  6672. // Shortcut
  6673. var hexStrLength = hexStr.length;
  6674. // Convert
  6675. var words = [];
  6676. for (var i = 0; i < hexStrLength; i += 2) {
  6677. words[i >>> 3] |= parseInt(hexStr.substr(i, 2), 16) << (24 - (i % 8) * 4);
  6678. }
  6679. return new WordArray.init(words, hexStrLength / 2);
  6680. }
  6681. };
  6682. /**
  6683. * Latin1 encoding strategy.
  6684. */
  6685. var Latin1 = C_enc.Latin1 = {
  6686. /**
  6687. * Converts a word array to a Latin1 string.
  6688. *
  6689. * @param {WordArray} wordArray The word array.
  6690. *
  6691. * @return {string} The Latin1 string.
  6692. *
  6693. * @static
  6694. *
  6695. * @example
  6696. *
  6697. * var latin1String = CryptoJS.enc.Latin1.stringify(wordArray);
  6698. */
  6699. stringify: function (wordArray) {
  6700. // Shortcuts
  6701. var words = wordArray.words;
  6702. var sigBytes = wordArray.sigBytes;
  6703. // Convert
  6704. var latin1Chars = [];
  6705. for (var i = 0; i < sigBytes; i++) {
  6706. var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff;
  6707. latin1Chars.push(String.fromCharCode(bite));
  6708. }
  6709. return latin1Chars.join('');
  6710. },
  6711. /**
  6712. * Converts a Latin1 string to a word array.
  6713. *
  6714. * @param {string} latin1Str The Latin1 string.
  6715. *
  6716. * @return {WordArray} The word array.
  6717. *
  6718. * @static
  6719. *
  6720. * @example
  6721. *
  6722. * var wordArray = CryptoJS.enc.Latin1.parse(latin1String);
  6723. */
  6724. parse: function (latin1Str) {
  6725. // Shortcut
  6726. var latin1StrLength = latin1Str.length;
  6727. // Convert
  6728. var words = [];
  6729. for (var i = 0; i < latin1StrLength; i++) {
  6730. words[i >>> 2] |= (latin1Str.charCodeAt(i) & 0xff) << (24 - (i % 4) * 8);
  6731. }
  6732. return new WordArray.init(words, latin1StrLength);
  6733. }
  6734. };
  6735. /**
  6736. * UTF-8 encoding strategy.
  6737. */
  6738. var Utf8 = C_enc.Utf8 = {
  6739. /**
  6740. * Converts a word array to a UTF-8 string.
  6741. *
  6742. * @param {WordArray} wordArray The word array.
  6743. *
  6744. * @return {string} The UTF-8 string.
  6745. *
  6746. * @static
  6747. *
  6748. * @example
  6749. *
  6750. * var utf8String = CryptoJS.enc.Utf8.stringify(wordArray);
  6751. */
  6752. stringify: function (wordArray) {
  6753. try {
  6754. return decodeURIComponent(escape(Latin1.stringify(wordArray)));
  6755. } catch (e) {
  6756. throw new Error('Malformed UTF-8 data');
  6757. }
  6758. },
  6759. /**
  6760. * Converts a UTF-8 string to a word array.
  6761. *
  6762. * @param {string} utf8Str The UTF-8 string.
  6763. *
  6764. * @return {WordArray} The word array.
  6765. *
  6766. * @static
  6767. *
  6768. * @example
  6769. *
  6770. * var wordArray = CryptoJS.enc.Utf8.parse(utf8String);
  6771. */
  6772. parse: function (utf8Str) {
  6773. return Latin1.parse(unescape(encodeURIComponent(utf8Str)));
  6774. }
  6775. };
  6776. /**
  6777. * Abstract buffered block algorithm template.
  6778. *
  6779. * The property blockSize must be implemented in a concrete subtype.
  6780. *
  6781. * @property {number} _minBufferSize The number of blocks that should be kept unprocessed in the buffer. Default: 0
  6782. */
  6783. var BufferedBlockAlgorithm = C_lib.BufferedBlockAlgorithm = Base.extend({
  6784. /**
  6785. * Resets this block algorithm's data buffer to its initial state.
  6786. *
  6787. * @example
  6788. *
  6789. * bufferedBlockAlgorithm.reset();
  6790. */
  6791. reset: function () {
  6792. // Initial values
  6793. this._data = new WordArray.init();
  6794. this._nDataBytes = 0;
  6795. },
  6796. /**
  6797. * Adds new data to this block algorithm's buffer.
  6798. *
  6799. * @param {WordArray|string} data The data to append. Strings are converted to a WordArray using UTF-8.
  6800. *
  6801. * @example
  6802. *
  6803. * bufferedBlockAlgorithm._append('data');
  6804. * bufferedBlockAlgorithm._append(wordArray);
  6805. */
  6806. _append: function (data) {
  6807. // Convert string to WordArray, else assume WordArray already
  6808. if (typeof data == 'string') {
  6809. data = Utf8.parse(data);
  6810. }
  6811. // Append
  6812. this._data.concat(data);
  6813. this._nDataBytes += data.sigBytes;
  6814. },
  6815. /**
  6816. * Processes available data blocks.
  6817. *
  6818. * This method invokes _doProcessBlock(offset), which must be implemented by a concrete subtype.
  6819. *
  6820. * @param {boolean} doFlush Whether all blocks and partial blocks should be processed.
  6821. *
  6822. * @return {WordArray} The processed data.
  6823. *
  6824. * @example
  6825. *
  6826. * var processedData = bufferedBlockAlgorithm._process();
  6827. * var processedData = bufferedBlockAlgorithm._process(!!'flush');
  6828. */
  6829. _process: function (doFlush) {
  6830. // Shortcuts
  6831. var data = this._data;
  6832. var dataWords = data.words;
  6833. var dataSigBytes = data.sigBytes;
  6834. var blockSize = this.blockSize;
  6835. var blockSizeBytes = blockSize * 4;
  6836. // Count blocks ready
  6837. var nBlocksReady = dataSigBytes / blockSizeBytes;
  6838. if (doFlush) {
  6839. // Round up to include partial blocks
  6840. nBlocksReady = Math.ceil(nBlocksReady);
  6841. } else {
  6842. // Round down to include only full blocks,
  6843. // less the number of blocks that must remain in the buffer
  6844. nBlocksReady = Math.max((nBlocksReady | 0) - this._minBufferSize, 0);
  6845. }
  6846. // Count words ready
  6847. var nWordsReady = nBlocksReady * blockSize;
  6848. // Count bytes ready
  6849. var nBytesReady = Math.min(nWordsReady * 4, dataSigBytes);
  6850. // Process blocks
  6851. if (nWordsReady) {
  6852. for (var offset = 0; offset < nWordsReady; offset += blockSize) {
  6853. // Perform concrete-algorithm logic
  6854. this._doProcessBlock(dataWords, offset);
  6855. }
  6856. // Remove processed words
  6857. var processedWords = dataWords.splice(0, nWordsReady);
  6858. data.sigBytes -= nBytesReady;
  6859. }
  6860. // Return processed words
  6861. return new WordArray.init(processedWords, nBytesReady);
  6862. },
  6863. /**
  6864. * Creates a copy of this object.
  6865. *
  6866. * @return {Object} The clone.
  6867. *
  6868. * @example
  6869. *
  6870. * var clone = bufferedBlockAlgorithm.clone();
  6871. */
  6872. clone: function () {
  6873. var clone = Base.clone.call(this);
  6874. clone._data = this._data.clone();
  6875. return clone;
  6876. },
  6877. _minBufferSize: 0
  6878. });
  6879. /**
  6880. * Abstract hasher template.
  6881. *
  6882. * @property {number} blockSize The number of 32-bit words this hasher operates on. Default: 16 (512 bits)
  6883. */
  6884. var Hasher = C_lib.Hasher = BufferedBlockAlgorithm.extend({
  6885. /**
  6886. * Configuration options.
  6887. */
  6888. cfg: Base.extend(),
  6889. /**
  6890. * Initializes a newly created hasher.
  6891. *
  6892. * @param {Object} cfg (Optional) The configuration options to use for this hash computation.
  6893. *
  6894. * @example
  6895. *
  6896. * var hasher = CryptoJS.algo.SHA256.create();
  6897. */
  6898. init: function (cfg) {
  6899. // Apply config defaults
  6900. this.cfg = this.cfg.extend(cfg);
  6901. // Set initial values
  6902. this.reset();
  6903. },
  6904. /**
  6905. * Resets this hasher to its initial state.
  6906. *
  6907. * @example
  6908. *
  6909. * hasher.reset();
  6910. */
  6911. reset: function () {
  6912. // Reset data buffer
  6913. BufferedBlockAlgorithm.reset.call(this);
  6914. // Perform concrete-hasher logic
  6915. this._doReset();
  6916. },
  6917. /**
  6918. * Updates this hasher with a message.
  6919. *
  6920. * @param {WordArray|string} messageUpdate The message to append.
  6921. *
  6922. * @return {Hasher} This hasher.
  6923. *
  6924. * @example
  6925. *
  6926. * hasher.update('message');
  6927. * hasher.update(wordArray);
  6928. */
  6929. update: function (messageUpdate) {
  6930. // Append
  6931. this._append(messageUpdate);
  6932. // Update the hash
  6933. this._process();
  6934. // Chainable
  6935. return this;
  6936. },
  6937. /**
  6938. * Finalizes the hash computation.
  6939. * Note that the finalize operation is effectively a destructive, read-once operation.
  6940. *
  6941. * @param {WordArray|string} messageUpdate (Optional) A final message update.
  6942. *
  6943. * @return {WordArray} The hash.
  6944. *
  6945. * @example
  6946. *
  6947. * var hash = hasher.finalize();
  6948. * var hash = hasher.finalize('message');
  6949. * var hash = hasher.finalize(wordArray);
  6950. */
  6951. finalize: function (messageUpdate) {
  6952. // Final message update
  6953. if (messageUpdate) {
  6954. this._append(messageUpdate);
  6955. }
  6956. // Perform concrete-hasher logic
  6957. var hash = this._doFinalize();
  6958. return hash;
  6959. },
  6960. blockSize: 512/32,
  6961. /**
  6962. * Creates a shortcut function to a hasher's object interface.
  6963. *
  6964. * @param {Hasher} hasher The hasher to create a helper for.
  6965. *
  6966. * @return {Function} The shortcut function.
  6967. *
  6968. * @static
  6969. *
  6970. * @example
  6971. *
  6972. * var SHA256 = CryptoJS.lib.Hasher._createHelper(CryptoJS.algo.SHA256);
  6973. */
  6974. _createHelper: function (hasher) {
  6975. return function (message, cfg) {
  6976. return new hasher.init(cfg).finalize(message);
  6977. };
  6978. },
  6979. /**
  6980. * Creates a shortcut function to the HMAC's object interface.
  6981. *
  6982. * @param {Hasher} hasher The hasher to use in this HMAC helper.
  6983. *
  6984. * @return {Function} The shortcut function.
  6985. *
  6986. * @static
  6987. *
  6988. * @example
  6989. *
  6990. * var HmacSHA256 = CryptoJS.lib.Hasher._createHmacHelper(CryptoJS.algo.SHA256);
  6991. */
  6992. _createHmacHelper: function (hasher) {
  6993. return function (message, key) {
  6994. return new C_algo.HMAC.init(hasher, key).finalize(message);
  6995. };
  6996. }
  6997. });
  6998. /**
  6999. * Algorithm namespace.
  7000. */
  7001. var C_algo = C.algo = {};
  7002. return C;
  7003. }(Math));
  7004. return CryptoJS;
  7005. }));
  7006. },{}],52:[function(require,module,exports){
  7007. ;(function (root, factory) {
  7008. if (typeof exports === "object") {
  7009. // CommonJS
  7010. module.exports = exports = factory(require("./core"));
  7011. }
  7012. else if (typeof define === "function" && define.amd) {
  7013. // AMD
  7014. define(["./core"], factory);
  7015. }
  7016. else {
  7017. // Global (browser)
  7018. factory(root.CryptoJS);
  7019. }
  7020. }(this, function (CryptoJS) {
  7021. (function () {
  7022. // Shortcuts
  7023. var C = CryptoJS;
  7024. var C_lib = C.lib;
  7025. var WordArray = C_lib.WordArray;
  7026. var C_enc = C.enc;
  7027. /**
  7028. * Base64 encoding strategy.
  7029. */
  7030. var Base64 = C_enc.Base64 = {
  7031. /**
  7032. * Converts a word array to a Base64 string.
  7033. *
  7034. * @param {WordArray} wordArray The word array.
  7035. *
  7036. * @return {string} The Base64 string.
  7037. *
  7038. * @static
  7039. *
  7040. * @example
  7041. *
  7042. * var base64String = CryptoJS.enc.Base64.stringify(wordArray);
  7043. */
  7044. stringify: function (wordArray) {
  7045. // Shortcuts
  7046. var words = wordArray.words;
  7047. var sigBytes = wordArray.sigBytes;
  7048. var map = this._map;
  7049. // Clamp excess bits
  7050. wordArray.clamp();
  7051. // Convert
  7052. var base64Chars = [];
  7053. for (var i = 0; i < sigBytes; i += 3) {
  7054. var byte1 = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff;
  7055. var byte2 = (words[(i + 1) >>> 2] >>> (24 - ((i + 1) % 4) * 8)) & 0xff;
  7056. var byte3 = (words[(i + 2) >>> 2] >>> (24 - ((i + 2) % 4) * 8)) & 0xff;
  7057. var triplet = (byte1 << 16) | (byte2 << 8) | byte3;
  7058. for (var j = 0; (j < 4) && (i + j * 0.75 < sigBytes); j++) {
  7059. base64Chars.push(map.charAt((triplet >>> (6 * (3 - j))) & 0x3f));
  7060. }
  7061. }
  7062. // Add padding
  7063. var paddingChar = map.charAt(64);
  7064. if (paddingChar) {
  7065. while (base64Chars.length % 4) {
  7066. base64Chars.push(paddingChar);
  7067. }
  7068. }
  7069. return base64Chars.join('');
  7070. },
  7071. /**
  7072. * Converts a Base64 string to a word array.
  7073. *
  7074. * @param {string} base64Str The Base64 string.
  7075. *
  7076. * @return {WordArray} The word array.
  7077. *
  7078. * @static
  7079. *
  7080. * @example
  7081. *
  7082. * var wordArray = CryptoJS.enc.Base64.parse(base64String);
  7083. */
  7084. parse: function (base64Str) {
  7085. // Shortcuts
  7086. var base64StrLength = base64Str.length;
  7087. var map = this._map;
  7088. // Ignore padding
  7089. var paddingChar = map.charAt(64);
  7090. if (paddingChar) {
  7091. var paddingIndex = base64Str.indexOf(paddingChar);
  7092. if (paddingIndex != -1) {
  7093. base64StrLength = paddingIndex;
  7094. }
  7095. }
  7096. // Convert
  7097. var words = [];
  7098. var nBytes = 0;
  7099. for (var i = 0; i < base64StrLength; i++) {
  7100. if (i % 4) {
  7101. var bits1 = map.indexOf(base64Str.charAt(i - 1)) << ((i % 4) * 2);
  7102. var bits2 = map.indexOf(base64Str.charAt(i)) >>> (6 - (i % 4) * 2);
  7103. words[nBytes >>> 2] |= (bits1 | bits2) << (24 - (nBytes % 4) * 8);
  7104. nBytes++;
  7105. }
  7106. }
  7107. return WordArray.create(words, nBytes);
  7108. },
  7109. _map: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='
  7110. };
  7111. }());
  7112. return CryptoJS.enc.Base64;
  7113. }));
  7114. },{"./core":51}],53:[function(require,module,exports){
  7115. ;(function (root, factory) {
  7116. if (typeof exports === "object") {
  7117. // CommonJS
  7118. module.exports = exports = factory(require("./core"));
  7119. }
  7120. else if (typeof define === "function" && define.amd) {
  7121. // AMD
  7122. define(["./core"], factory);
  7123. }
  7124. else {
  7125. // Global (browser)
  7126. factory(root.CryptoJS);
  7127. }
  7128. }(this, function (CryptoJS) {
  7129. (function () {
  7130. // Shortcuts
  7131. var C = CryptoJS;
  7132. var C_lib = C.lib;
  7133. var WordArray = C_lib.WordArray;
  7134. var C_enc = C.enc;
  7135. /**
  7136. * UTF-16 BE encoding strategy.
  7137. */
  7138. var Utf16BE = C_enc.Utf16 = C_enc.Utf16BE = {
  7139. /**
  7140. * Converts a word array to a UTF-16 BE string.
  7141. *
  7142. * @param {WordArray} wordArray The word array.
  7143. *
  7144. * @return {string} The UTF-16 BE string.
  7145. *
  7146. * @static
  7147. *
  7148. * @example
  7149. *
  7150. * var utf16String = CryptoJS.enc.Utf16.stringify(wordArray);
  7151. */
  7152. stringify: function (wordArray) {
  7153. // Shortcuts
  7154. var words = wordArray.words;
  7155. var sigBytes = wordArray.sigBytes;
  7156. // Convert
  7157. var utf16Chars = [];
  7158. for (var i = 0; i < sigBytes; i += 2) {
  7159. var codePoint = (words[i >>> 2] >>> (16 - (i % 4) * 8)) & 0xffff;
  7160. utf16Chars.push(String.fromCharCode(codePoint));
  7161. }
  7162. return utf16Chars.join('');
  7163. },
  7164. /**
  7165. * Converts a UTF-16 BE string to a word array.
  7166. *
  7167. * @param {string} utf16Str The UTF-16 BE string.
  7168. *
  7169. * @return {WordArray} The word array.
  7170. *
  7171. * @static
  7172. *
  7173. * @example
  7174. *
  7175. * var wordArray = CryptoJS.enc.Utf16.parse(utf16String);
  7176. */
  7177. parse: function (utf16Str) {
  7178. // Shortcut
  7179. var utf16StrLength = utf16Str.length;
  7180. // Convert
  7181. var words = [];
  7182. for (var i = 0; i < utf16StrLength; i++) {
  7183. words[i >>> 1] |= utf16Str.charCodeAt(i) << (16 - (i % 2) * 16);
  7184. }
  7185. return WordArray.create(words, utf16StrLength * 2);
  7186. }
  7187. };
  7188. /**
  7189. * UTF-16 LE encoding strategy.
  7190. */
  7191. C_enc.Utf16LE = {
  7192. /**
  7193. * Converts a word array to a UTF-16 LE string.
  7194. *
  7195. * @param {WordArray} wordArray The word array.
  7196. *
  7197. * @return {string} The UTF-16 LE string.
  7198. *
  7199. * @static
  7200. *
  7201. * @example
  7202. *
  7203. * var utf16Str = CryptoJS.enc.Utf16LE.stringify(wordArray);
  7204. */
  7205. stringify: function (wordArray) {
  7206. // Shortcuts
  7207. var words = wordArray.words;
  7208. var sigBytes = wordArray.sigBytes;
  7209. // Convert
  7210. var utf16Chars = [];
  7211. for (var i = 0; i < sigBytes; i += 2) {
  7212. var codePoint = swapEndian((words[i >>> 2] >>> (16 - (i % 4) * 8)) & 0xffff);
  7213. utf16Chars.push(String.fromCharCode(codePoint));
  7214. }
  7215. return utf16Chars.join('');
  7216. },
  7217. /**
  7218. * Converts a UTF-16 LE string to a word array.
  7219. *
  7220. * @param {string} utf16Str The UTF-16 LE string.
  7221. *
  7222. * @return {WordArray} The word array.
  7223. *
  7224. * @static
  7225. *
  7226. * @example
  7227. *
  7228. * var wordArray = CryptoJS.enc.Utf16LE.parse(utf16Str);
  7229. */
  7230. parse: function (utf16Str) {
  7231. // Shortcut
  7232. var utf16StrLength = utf16Str.length;
  7233. // Convert
  7234. var words = [];
  7235. for (var i = 0; i < utf16StrLength; i++) {
  7236. words[i >>> 1] |= swapEndian(utf16Str.charCodeAt(i) << (16 - (i % 2) * 16));
  7237. }
  7238. return WordArray.create(words, utf16StrLength * 2);
  7239. }
  7240. };
  7241. function swapEndian(word) {
  7242. return ((word << 8) & 0xff00ff00) | ((word >>> 8) & 0x00ff00ff);
  7243. }
  7244. }());
  7245. return CryptoJS.enc.Utf16;
  7246. }));
  7247. },{"./core":51}],54:[function(require,module,exports){
  7248. ;(function (root, factory, undef) {
  7249. if (typeof exports === "object") {
  7250. // CommonJS
  7251. module.exports = exports = factory(require("./core"), require("./sha1"), require("./hmac"));
  7252. }
  7253. else if (typeof define === "function" && define.amd) {
  7254. // AMD
  7255. define(["./core", "./sha1", "./hmac"], factory);
  7256. }
  7257. else {
  7258. // Global (browser)
  7259. factory(root.CryptoJS);
  7260. }
  7261. }(this, function (CryptoJS) {
  7262. (function () {
  7263. // Shortcuts
  7264. var C = CryptoJS;
  7265. var C_lib = C.lib;
  7266. var Base = C_lib.Base;
  7267. var WordArray = C_lib.WordArray;
  7268. var C_algo = C.algo;
  7269. var MD5 = C_algo.MD5;
  7270. /**
  7271. * This key derivation function is meant to conform with EVP_BytesToKey.
  7272. * www.openssl.org/docs/crypto/EVP_BytesToKey.html
  7273. */
  7274. var EvpKDF = C_algo.EvpKDF = Base.extend({
  7275. /**
  7276. * Configuration options.
  7277. *
  7278. * @property {number} keySize The key size in words to generate. Default: 4 (128 bits)
  7279. * @property {Hasher} hasher The hash algorithm to use. Default: MD5
  7280. * @property {number} iterations The number of iterations to perform. Default: 1
  7281. */
  7282. cfg: Base.extend({
  7283. keySize: 128/32,
  7284. hasher: MD5,
  7285. iterations: 1
  7286. }),
  7287. /**
  7288. * Initializes a newly created key derivation function.
  7289. *
  7290. * @param {Object} cfg (Optional) The configuration options to use for the derivation.
  7291. *
  7292. * @example
  7293. *
  7294. * var kdf = CryptoJS.algo.EvpKDF.create();
  7295. * var kdf = CryptoJS.algo.EvpKDF.create({ keySize: 8 });
  7296. * var kdf = CryptoJS.algo.EvpKDF.create({ keySize: 8, iterations: 1000 });
  7297. */
  7298. init: function (cfg) {
  7299. this.cfg = this.cfg.extend(cfg);
  7300. },
  7301. /**
  7302. * Derives a key from a password.
  7303. *
  7304. * @param {WordArray|string} password The password.
  7305. * @param {WordArray|string} salt A salt.
  7306. *
  7307. * @return {WordArray} The derived key.
  7308. *
  7309. * @example
  7310. *
  7311. * var key = kdf.compute(password, salt);
  7312. */
  7313. compute: function (password, salt) {
  7314. // Shortcut
  7315. var cfg = this.cfg;
  7316. // Init hasher
  7317. var hasher = cfg.hasher.create();
  7318. // Initial values
  7319. var derivedKey = WordArray.create();
  7320. // Shortcuts
  7321. var derivedKeyWords = derivedKey.words;
  7322. var keySize = cfg.keySize;
  7323. var iterations = cfg.iterations;
  7324. // Generate key
  7325. while (derivedKeyWords.length < keySize) {
  7326. if (block) {
  7327. hasher.update(block);
  7328. }
  7329. var block = hasher.update(password).finalize(salt);
  7330. hasher.reset();
  7331. // Iterations
  7332. for (var i = 1; i < iterations; i++) {
  7333. block = hasher.finalize(block);
  7334. hasher.reset();
  7335. }
  7336. derivedKey.concat(block);
  7337. }
  7338. derivedKey.sigBytes = keySize * 4;
  7339. return derivedKey;
  7340. }
  7341. });
  7342. /**
  7343. * Derives a key from a password.
  7344. *
  7345. * @param {WordArray|string} password The password.
  7346. * @param {WordArray|string} salt A salt.
  7347. * @param {Object} cfg (Optional) The configuration options to use for this computation.
  7348. *
  7349. * @return {WordArray} The derived key.
  7350. *
  7351. * @static
  7352. *
  7353. * @example
  7354. *
  7355. * var key = CryptoJS.EvpKDF(password, salt);
  7356. * var key = CryptoJS.EvpKDF(password, salt, { keySize: 8 });
  7357. * var key = CryptoJS.EvpKDF(password, salt, { keySize: 8, iterations: 1000 });
  7358. */
  7359. C.EvpKDF = function (password, salt, cfg) {
  7360. return EvpKDF.create(cfg).compute(password, salt);
  7361. };
  7362. }());
  7363. return CryptoJS.EvpKDF;
  7364. }));
  7365. },{"./core":51,"./hmac":56,"./sha1":75}],55:[function(require,module,exports){
  7366. ;(function (root, factory, undef) {
  7367. if (typeof exports === "object") {
  7368. // CommonJS
  7369. module.exports = exports = factory(require("./core"), require("./cipher-core"));
  7370. }
  7371. else if (typeof define === "function" && define.amd) {
  7372. // AMD
  7373. define(["./core", "./cipher-core"], factory);
  7374. }
  7375. else {
  7376. // Global (browser)
  7377. factory(root.CryptoJS);
  7378. }
  7379. }(this, function (CryptoJS) {
  7380. (function (undefined) {
  7381. // Shortcuts
  7382. var C = CryptoJS;
  7383. var C_lib = C.lib;
  7384. var CipherParams = C_lib.CipherParams;
  7385. var C_enc = C.enc;
  7386. var Hex = C_enc.Hex;
  7387. var C_format = C.format;
  7388. var HexFormatter = C_format.Hex = {
  7389. /**
  7390. * Converts the ciphertext of a cipher params object to a hexadecimally encoded string.
  7391. *
  7392. * @param {CipherParams} cipherParams The cipher params object.
  7393. *
  7394. * @return {string} The hexadecimally encoded string.
  7395. *
  7396. * @static
  7397. *
  7398. * @example
  7399. *
  7400. * var hexString = CryptoJS.format.Hex.stringify(cipherParams);
  7401. */
  7402. stringify: function (cipherParams) {
  7403. return cipherParams.ciphertext.toString(Hex);
  7404. },
  7405. /**
  7406. * Converts a hexadecimally encoded ciphertext string to a cipher params object.
  7407. *
  7408. * @param {string} input The hexadecimally encoded string.
  7409. *
  7410. * @return {CipherParams} The cipher params object.
  7411. *
  7412. * @static
  7413. *
  7414. * @example
  7415. *
  7416. * var cipherParams = CryptoJS.format.Hex.parse(hexString);
  7417. */
  7418. parse: function (input) {
  7419. var ciphertext = Hex.parse(input);
  7420. return CipherParams.create({ ciphertext: ciphertext });
  7421. }
  7422. };
  7423. }());
  7424. return CryptoJS.format.Hex;
  7425. }));
  7426. },{"./cipher-core":50,"./core":51}],56:[function(require,module,exports){
  7427. ;(function (root, factory) {
  7428. if (typeof exports === "object") {
  7429. // CommonJS
  7430. module.exports = exports = factory(require("./core"));
  7431. }
  7432. else if (typeof define === "function" && define.amd) {
  7433. // AMD
  7434. define(["./core"], factory);
  7435. }
  7436. else {
  7437. // Global (browser)
  7438. factory(root.CryptoJS);
  7439. }
  7440. }(this, function (CryptoJS) {
  7441. (function () {
  7442. // Shortcuts
  7443. var C = CryptoJS;
  7444. var C_lib = C.lib;
  7445. var Base = C_lib.Base;
  7446. var C_enc = C.enc;
  7447. var Utf8 = C_enc.Utf8;
  7448. var C_algo = C.algo;
  7449. /**
  7450. * HMAC algorithm.
  7451. */
  7452. var HMAC = C_algo.HMAC = Base.extend({
  7453. /**
  7454. * Initializes a newly created HMAC.
  7455. *
  7456. * @param {Hasher} hasher The hash algorithm to use.
  7457. * @param {WordArray|string} key The secret key.
  7458. *
  7459. * @example
  7460. *
  7461. * var hmacHasher = CryptoJS.algo.HMAC.create(CryptoJS.algo.SHA256, key);
  7462. */
  7463. init: function (hasher, key) {
  7464. // Init hasher
  7465. hasher = this._hasher = new hasher.init();
  7466. // Convert string to WordArray, else assume WordArray already
  7467. if (typeof key == 'string') {
  7468. key = Utf8.parse(key);
  7469. }
  7470. // Shortcuts
  7471. var hasherBlockSize = hasher.blockSize;
  7472. var hasherBlockSizeBytes = hasherBlockSize * 4;
  7473. // Allow arbitrary length keys
  7474. if (key.sigBytes > hasherBlockSizeBytes) {
  7475. key = hasher.finalize(key);
  7476. }
  7477. // Clamp excess bits
  7478. key.clamp();
  7479. // Clone key for inner and outer pads
  7480. var oKey = this._oKey = key.clone();
  7481. var iKey = this._iKey = key.clone();
  7482. // Shortcuts
  7483. var oKeyWords = oKey.words;
  7484. var iKeyWords = iKey.words;
  7485. // XOR keys with pad constants
  7486. for (var i = 0; i < hasherBlockSize; i++) {
  7487. oKeyWords[i] ^= 0x5c5c5c5c;
  7488. iKeyWords[i] ^= 0x36363636;
  7489. }
  7490. oKey.sigBytes = iKey.sigBytes = hasherBlockSizeBytes;
  7491. // Set initial values
  7492. this.reset();
  7493. },
  7494. /**
  7495. * Resets this HMAC to its initial state.
  7496. *
  7497. * @example
  7498. *
  7499. * hmacHasher.reset();
  7500. */
  7501. reset: function () {
  7502. // Shortcut
  7503. var hasher = this._hasher;
  7504. // Reset
  7505. hasher.reset();
  7506. hasher.update(this._iKey);
  7507. },
  7508. /**
  7509. * Updates this HMAC with a message.
  7510. *
  7511. * @param {WordArray|string} messageUpdate The message to append.
  7512. *
  7513. * @return {HMAC} This HMAC instance.
  7514. *
  7515. * @example
  7516. *
  7517. * hmacHasher.update('message');
  7518. * hmacHasher.update(wordArray);
  7519. */
  7520. update: function (messageUpdate) {
  7521. this._hasher.update(messageUpdate);
  7522. // Chainable
  7523. return this;
  7524. },
  7525. /**
  7526. * Finalizes the HMAC computation.
  7527. * Note that the finalize operation is effectively a destructive, read-once operation.
  7528. *
  7529. * @param {WordArray|string} messageUpdate (Optional) A final message update.
  7530. *
  7531. * @return {WordArray} The HMAC.
  7532. *
  7533. * @example
  7534. *
  7535. * var hmac = hmacHasher.finalize();
  7536. * var hmac = hmacHasher.finalize('message');
  7537. * var hmac = hmacHasher.finalize(wordArray);
  7538. */
  7539. finalize: function (messageUpdate) {
  7540. // Shortcut
  7541. var hasher = this._hasher;
  7542. // Compute HMAC
  7543. var innerHash = hasher.finalize(messageUpdate);
  7544. hasher.reset();
  7545. var hmac = hasher.finalize(this._oKey.clone().concat(innerHash));
  7546. return hmac;
  7547. }
  7548. });
  7549. }());
  7550. }));
  7551. },{"./core":51}],57:[function(require,module,exports){
  7552. ;(function (root, factory, undef) {
  7553. if (typeof exports === "object") {
  7554. // CommonJS
  7555. 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"));
  7556. }
  7557. else if (typeof define === "function" && define.amd) {
  7558. // AMD
  7559. 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);
  7560. }
  7561. else {
  7562. // Global (browser)
  7563. root.CryptoJS = factory(root.CryptoJS);
  7564. }
  7565. }(this, function (CryptoJS) {
  7566. return CryptoJS;
  7567. }));
  7568. },{"./aes":49,"./cipher-core":50,"./core":51,"./enc-base64":52,"./enc-utf16":53,"./evpkdf":54,"./format-hex":55,"./hmac":56,"./lib-typedarrays":58,"./md5":59,"./mode-cfb":60,"./mode-ctr":62,"./mode-ctr-gladman":61,"./mode-ecb":63,"./mode-ofb":64,"./pad-ansix923":65,"./pad-iso10126":66,"./pad-iso97971":67,"./pad-nopadding":68,"./pad-zeropadding":69,"./pbkdf2":70,"./rabbit":72,"./rabbit-legacy":71,"./rc4":73,"./ripemd160":74,"./sha1":75,"./sha224":76,"./sha256":77,"./sha3":78,"./sha384":79,"./sha512":80,"./tripledes":81,"./x64-core":82}],58:[function(require,module,exports){
  7569. ;(function (root, factory) {
  7570. if (typeof exports === "object") {
  7571. // CommonJS
  7572. module.exports = exports = factory(require("./core"));
  7573. }
  7574. else if (typeof define === "function" && define.amd) {
  7575. // AMD
  7576. define(["./core"], factory);
  7577. }
  7578. else {
  7579. // Global (browser)
  7580. factory(root.CryptoJS);
  7581. }
  7582. }(this, function (CryptoJS) {
  7583. (function () {
  7584. // Check if typed arrays are supported
  7585. if (typeof ArrayBuffer != 'function') {
  7586. return;
  7587. }
  7588. // Shortcuts
  7589. var C = CryptoJS;
  7590. var C_lib = C.lib;
  7591. var WordArray = C_lib.WordArray;
  7592. // Reference original init
  7593. var superInit = WordArray.init;
  7594. // Augment WordArray.init to handle typed arrays
  7595. var subInit = WordArray.init = function (typedArray) {
  7596. // Convert buffers to uint8
  7597. if (typedArray instanceof ArrayBuffer) {
  7598. typedArray = new Uint8Array(typedArray);
  7599. }
  7600. // Convert other array views to uint8
  7601. if (
  7602. typedArray instanceof Int8Array ||
  7603. (typeof Uint8ClampedArray !== "undefined" && typedArray instanceof Uint8ClampedArray) ||
  7604. typedArray instanceof Int16Array ||
  7605. typedArray instanceof Uint16Array ||
  7606. typedArray instanceof Int32Array ||
  7607. typedArray instanceof Uint32Array ||
  7608. typedArray instanceof Float32Array ||
  7609. typedArray instanceof Float64Array
  7610. ) {
  7611. typedArray = new Uint8Array(typedArray.buffer, typedArray.byteOffset, typedArray.byteLength);
  7612. }
  7613. // Handle Uint8Array
  7614. if (typedArray instanceof Uint8Array) {
  7615. // Shortcut
  7616. var typedArrayByteLength = typedArray.byteLength;
  7617. // Extract bytes
  7618. var words = [];
  7619. for (var i = 0; i < typedArrayByteLength; i++) {
  7620. words[i >>> 2] |= typedArray[i] << (24 - (i % 4) * 8);
  7621. }
  7622. // Initialize this word array
  7623. superInit.call(this, words, typedArrayByteLength);
  7624. } else {
  7625. // Else call normal init
  7626. superInit.apply(this, arguments);
  7627. }
  7628. };
  7629. subInit.prototype = WordArray;
  7630. }());
  7631. return CryptoJS.lib.WordArray;
  7632. }));
  7633. },{"./core":51}],59:[function(require,module,exports){
  7634. ;(function (root, factory) {
  7635. if (typeof exports === "object") {
  7636. // CommonJS
  7637. module.exports = exports = factory(require("./core"));
  7638. }
  7639. else if (typeof define === "function" && define.amd) {
  7640. // AMD
  7641. define(["./core"], factory);
  7642. }
  7643. else {
  7644. // Global (browser)
  7645. factory(root.CryptoJS);
  7646. }
  7647. }(this, function (CryptoJS) {
  7648. (function (Math) {
  7649. // Shortcuts
  7650. var C = CryptoJS;
  7651. var C_lib = C.lib;
  7652. var WordArray = C_lib.WordArray;
  7653. var Hasher = C_lib.Hasher;
  7654. var C_algo = C.algo;
  7655. // Constants table
  7656. var T = [];
  7657. // Compute constants
  7658. (function () {
  7659. for (var i = 0; i < 64; i++) {
  7660. T[i] = (Math.abs(Math.sin(i + 1)) * 0x100000000) | 0;
  7661. }
  7662. }());
  7663. /**
  7664. * MD5 hash algorithm.
  7665. */
  7666. var MD5 = C_algo.MD5 = Hasher.extend({
  7667. _doReset: function () {
  7668. this._hash = new WordArray.init([
  7669. 0x67452301, 0xefcdab89,
  7670. 0x98badcfe, 0x10325476
  7671. ]);
  7672. },
  7673. _doProcessBlock: function (M, offset) {
  7674. // Swap endian
  7675. for (var i = 0; i < 16; i++) {
  7676. // Shortcuts
  7677. var offset_i = offset + i;
  7678. var M_offset_i = M[offset_i];
  7679. M[offset_i] = (
  7680. (((M_offset_i << 8) | (M_offset_i >>> 24)) & 0x00ff00ff) |
  7681. (((M_offset_i << 24) | (M_offset_i >>> 8)) & 0xff00ff00)
  7682. );
  7683. }
  7684. // Shortcuts
  7685. var H = this._hash.words;
  7686. var M_offset_0 = M[offset + 0];
  7687. var M_offset_1 = M[offset + 1];
  7688. var M_offset_2 = M[offset + 2];
  7689. var M_offset_3 = M[offset + 3];
  7690. var M_offset_4 = M[offset + 4];
  7691. var M_offset_5 = M[offset + 5];
  7692. var M_offset_6 = M[offset + 6];
  7693. var M_offset_7 = M[offset + 7];
  7694. var M_offset_8 = M[offset + 8];
  7695. var M_offset_9 = M[offset + 9];
  7696. var M_offset_10 = M[offset + 10];
  7697. var M_offset_11 = M[offset + 11];
  7698. var M_offset_12 = M[offset + 12];
  7699. var M_offset_13 = M[offset + 13];
  7700. var M_offset_14 = M[offset + 14];
  7701. var M_offset_15 = M[offset + 15];
  7702. // Working varialbes
  7703. var a = H[0];
  7704. var b = H[1];
  7705. var c = H[2];
  7706. var d = H[3];
  7707. // Computation
  7708. a = FF(a, b, c, d, M_offset_0, 7, T[0]);
  7709. d = FF(d, a, b, c, M_offset_1, 12, T[1]);
  7710. c = FF(c, d, a, b, M_offset_2, 17, T[2]);
  7711. b = FF(b, c, d, a, M_offset_3, 22, T[3]);
  7712. a = FF(a, b, c, d, M_offset_4, 7, T[4]);
  7713. d = FF(d, a, b, c, M_offset_5, 12, T[5]);
  7714. c = FF(c, d, a, b, M_offset_6, 17, T[6]);
  7715. b = FF(b, c, d, a, M_offset_7, 22, T[7]);
  7716. a = FF(a, b, c, d, M_offset_8, 7, T[8]);
  7717. d = FF(d, a, b, c, M_offset_9, 12, T[9]);
  7718. c = FF(c, d, a, b, M_offset_10, 17, T[10]);
  7719. b = FF(b, c, d, a, M_offset_11, 22, T[11]);
  7720. a = FF(a, b, c, d, M_offset_12, 7, T[12]);
  7721. d = FF(d, a, b, c, M_offset_13, 12, T[13]);
  7722. c = FF(c, d, a, b, M_offset_14, 17, T[14]);
  7723. b = FF(b, c, d, a, M_offset_15, 22, T[15]);
  7724. a = GG(a, b, c, d, M_offset_1, 5, T[16]);
  7725. d = GG(d, a, b, c, M_offset_6, 9, T[17]);
  7726. c = GG(c, d, a, b, M_offset_11, 14, T[18]);
  7727. b = GG(b, c, d, a, M_offset_0, 20, T[19]);
  7728. a = GG(a, b, c, d, M_offset_5, 5, T[20]);
  7729. d = GG(d, a, b, c, M_offset_10, 9, T[21]);
  7730. c = GG(c, d, a, b, M_offset_15, 14, T[22]);
  7731. b = GG(b, c, d, a, M_offset_4, 20, T[23]);
  7732. a = GG(a, b, c, d, M_offset_9, 5, T[24]);
  7733. d = GG(d, a, b, c, M_offset_14, 9, T[25]);
  7734. c = GG(c, d, a, b, M_offset_3, 14, T[26]);
  7735. b = GG(b, c, d, a, M_offset_8, 20, T[27]);
  7736. a = GG(a, b, c, d, M_offset_13, 5, T[28]);
  7737. d = GG(d, a, b, c, M_offset_2, 9, T[29]);
  7738. c = GG(c, d, a, b, M_offset_7, 14, T[30]);
  7739. b = GG(b, c, d, a, M_offset_12, 20, T[31]);
  7740. a = HH(a, b, c, d, M_offset_5, 4, T[32]);
  7741. d = HH(d, a, b, c, M_offset_8, 11, T[33]);
  7742. c = HH(c, d, a, b, M_offset_11, 16, T[34]);
  7743. b = HH(b, c, d, a, M_offset_14, 23, T[35]);
  7744. a = HH(a, b, c, d, M_offset_1, 4, T[36]);
  7745. d = HH(d, a, b, c, M_offset_4, 11, T[37]);
  7746. c = HH(c, d, a, b, M_offset_7, 16, T[38]);
  7747. b = HH(b, c, d, a, M_offset_10, 23, T[39]);
  7748. a = HH(a, b, c, d, M_offset_13, 4, T[40]);
  7749. d = HH(d, a, b, c, M_offset_0, 11, T[41]);
  7750. c = HH(c, d, a, b, M_offset_3, 16, T[42]);
  7751. b = HH(b, c, d, a, M_offset_6, 23, T[43]);
  7752. a = HH(a, b, c, d, M_offset_9, 4, T[44]);
  7753. d = HH(d, a, b, c, M_offset_12, 11, T[45]);
  7754. c = HH(c, d, a, b, M_offset_15, 16, T[46]);
  7755. b = HH(b, c, d, a, M_offset_2, 23, T[47]);
  7756. a = II(a, b, c, d, M_offset_0, 6, T[48]);
  7757. d = II(d, a, b, c, M_offset_7, 10, T[49]);
  7758. c = II(c, d, a, b, M_offset_14, 15, T[50]);
  7759. b = II(b, c, d, a, M_offset_5, 21, T[51]);
  7760. a = II(a, b, c, d, M_offset_12, 6, T[52]);
  7761. d = II(d, a, b, c, M_offset_3, 10, T[53]);
  7762. c = II(c, d, a, b, M_offset_10, 15, T[54]);
  7763. b = II(b, c, d, a, M_offset_1, 21, T[55]);
  7764. a = II(a, b, c, d, M_offset_8, 6, T[56]);
  7765. d = II(d, a, b, c, M_offset_15, 10, T[57]);
  7766. c = II(c, d, a, b, M_offset_6, 15, T[58]);
  7767. b = II(b, c, d, a, M_offset_13, 21, T[59]);
  7768. a = II(a, b, c, d, M_offset_4, 6, T[60]);
  7769. d = II(d, a, b, c, M_offset_11, 10, T[61]);
  7770. c = II(c, d, a, b, M_offset_2, 15, T[62]);
  7771. b = II(b, c, d, a, M_offset_9, 21, T[63]);
  7772. // Intermediate hash value
  7773. H[0] = (H[0] + a) | 0;
  7774. H[1] = (H[1] + b) | 0;
  7775. H[2] = (H[2] + c) | 0;
  7776. H[3] = (H[3] + d) | 0;
  7777. },
  7778. _doFinalize: function () {
  7779. // Shortcuts
  7780. var data = this._data;
  7781. var dataWords = data.words;
  7782. var nBitsTotal = this._nDataBytes * 8;
  7783. var nBitsLeft = data.sigBytes * 8;
  7784. // Add padding
  7785. dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32);
  7786. var nBitsTotalH = Math.floor(nBitsTotal / 0x100000000);
  7787. var nBitsTotalL = nBitsTotal;
  7788. dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = (
  7789. (((nBitsTotalH << 8) | (nBitsTotalH >>> 24)) & 0x00ff00ff) |
  7790. (((nBitsTotalH << 24) | (nBitsTotalH >>> 8)) & 0xff00ff00)
  7791. );
  7792. dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = (
  7793. (((nBitsTotalL << 8) | (nBitsTotalL >>> 24)) & 0x00ff00ff) |
  7794. (((nBitsTotalL << 24) | (nBitsTotalL >>> 8)) & 0xff00ff00)
  7795. );
  7796. data.sigBytes = (dataWords.length + 1) * 4;
  7797. // Hash final blocks
  7798. this._process();
  7799. // Shortcuts
  7800. var hash = this._hash;
  7801. var H = hash.words;
  7802. // Swap endian
  7803. for (var i = 0; i < 4; i++) {
  7804. // Shortcut
  7805. var H_i = H[i];
  7806. H[i] = (((H_i << 8) | (H_i >>> 24)) & 0x00ff00ff) |
  7807. (((H_i << 24) | (H_i >>> 8)) & 0xff00ff00);
  7808. }
  7809. // Return final computed hash
  7810. return hash;
  7811. },
  7812. clone: function () {
  7813. var clone = Hasher.clone.call(this);
  7814. clone._hash = this._hash.clone();
  7815. return clone;
  7816. }
  7817. });
  7818. function FF(a, b, c, d, x, s, t) {
  7819. var n = a + ((b & c) | (~b & d)) + x + t;
  7820. return ((n << s) | (n >>> (32 - s))) + b;
  7821. }
  7822. function GG(a, b, c, d, x, s, t) {
  7823. var n = a + ((b & d) | (c & ~d)) + x + t;
  7824. return ((n << s) | (n >>> (32 - s))) + b;
  7825. }
  7826. function HH(a, b, c, d, x, s, t) {
  7827. var n = a + (b ^ c ^ d) + x + t;
  7828. return ((n << s) | (n >>> (32 - s))) + b;
  7829. }
  7830. function II(a, b, c, d, x, s, t) {
  7831. var n = a + (c ^ (b | ~d)) + x + t;
  7832. return ((n << s) | (n >>> (32 - s))) + b;
  7833. }
  7834. /**
  7835. * Shortcut function to the hasher's object interface.
  7836. *
  7837. * @param {WordArray|string} message The message to hash.
  7838. *
  7839. * @return {WordArray} The hash.
  7840. *
  7841. * @static
  7842. *
  7843. * @example
  7844. *
  7845. * var hash = CryptoJS.MD5('message');
  7846. * var hash = CryptoJS.MD5(wordArray);
  7847. */
  7848. C.MD5 = Hasher._createHelper(MD5);
  7849. /**
  7850. * Shortcut function to the HMAC's object interface.
  7851. *
  7852. * @param {WordArray|string} message The message to hash.
  7853. * @param {WordArray|string} key The secret key.
  7854. *
  7855. * @return {WordArray} The HMAC.
  7856. *
  7857. * @static
  7858. *
  7859. * @example
  7860. *
  7861. * var hmac = CryptoJS.HmacMD5(message, key);
  7862. */
  7863. C.HmacMD5 = Hasher._createHmacHelper(MD5);
  7864. }(Math));
  7865. return CryptoJS.MD5;
  7866. }));
  7867. },{"./core":51}],60:[function(require,module,exports){
  7868. ;(function (root, factory, undef) {
  7869. if (typeof exports === "object") {
  7870. // CommonJS
  7871. module.exports = exports = factory(require("./core"), require("./cipher-core"));
  7872. }
  7873. else if (typeof define === "function" && define.amd) {
  7874. // AMD
  7875. define(["./core", "./cipher-core"], factory);
  7876. }
  7877. else {
  7878. // Global (browser)
  7879. factory(root.CryptoJS);
  7880. }
  7881. }(this, function (CryptoJS) {
  7882. /**
  7883. * Cipher Feedback block mode.
  7884. */
  7885. CryptoJS.mode.CFB = (function () {
  7886. var CFB = CryptoJS.lib.BlockCipherMode.extend();
  7887. CFB.Encryptor = CFB.extend({
  7888. processBlock: function (words, offset) {
  7889. // Shortcuts
  7890. var cipher = this._cipher;
  7891. var blockSize = cipher.blockSize;
  7892. generateKeystreamAndEncrypt.call(this, words, offset, blockSize, cipher);
  7893. // Remember this block to use with next block
  7894. this._prevBlock = words.slice(offset, offset + blockSize);
  7895. }
  7896. });
  7897. CFB.Decryptor = CFB.extend({
  7898. processBlock: function (words, offset) {
  7899. // Shortcuts
  7900. var cipher = this._cipher;
  7901. var blockSize = cipher.blockSize;
  7902. // Remember this block to use with next block
  7903. var thisBlock = words.slice(offset, offset + blockSize);
  7904. generateKeystreamAndEncrypt.call(this, words, offset, blockSize, cipher);
  7905. // This block becomes the previous block
  7906. this._prevBlock = thisBlock;
  7907. }
  7908. });
  7909. function generateKeystreamAndEncrypt(words, offset, blockSize, cipher) {
  7910. // Shortcut
  7911. var iv = this._iv;
  7912. // Generate keystream
  7913. if (iv) {
  7914. var keystream = iv.slice(0);
  7915. // Remove IV for subsequent blocks
  7916. this._iv = undefined;
  7917. } else {
  7918. var keystream = this._prevBlock;
  7919. }
  7920. cipher.encryptBlock(keystream, 0);
  7921. // Encrypt
  7922. for (var i = 0; i < blockSize; i++) {
  7923. words[offset + i] ^= keystream[i];
  7924. }
  7925. }
  7926. return CFB;
  7927. }());
  7928. return CryptoJS.mode.CFB;
  7929. }));
  7930. },{"./cipher-core":50,"./core":51}],61:[function(require,module,exports){
  7931. ;(function (root, factory, undef) {
  7932. if (typeof exports === "object") {
  7933. // CommonJS
  7934. module.exports = exports = factory(require("./core"), require("./cipher-core"));
  7935. }
  7936. else if (typeof define === "function" && define.amd) {
  7937. // AMD
  7938. define(["./core", "./cipher-core"], factory);
  7939. }
  7940. else {
  7941. // Global (browser)
  7942. factory(root.CryptoJS);
  7943. }
  7944. }(this, function (CryptoJS) {
  7945. /** @preserve
  7946. * Counter block mode compatible with Dr Brian Gladman fileenc.c
  7947. * derived from CryptoJS.mode.CTR
  7948. * Jan Hruby jhruby.web@gmail.com
  7949. */
  7950. CryptoJS.mode.CTRGladman = (function () {
  7951. var CTRGladman = CryptoJS.lib.BlockCipherMode.extend();
  7952. function incWord(word)
  7953. {
  7954. if (((word >> 24) & 0xff) === 0xff) { //overflow
  7955. var b1 = (word >> 16)&0xff;
  7956. var b2 = (word >> 8)&0xff;
  7957. var b3 = word & 0xff;
  7958. if (b1 === 0xff) // overflow b1
  7959. {
  7960. b1 = 0;
  7961. if (b2 === 0xff)
  7962. {
  7963. b2 = 0;
  7964. if (b3 === 0xff)
  7965. {
  7966. b3 = 0;
  7967. }
  7968. else
  7969. {
  7970. ++b3;
  7971. }
  7972. }
  7973. else
  7974. {
  7975. ++b2;
  7976. }
  7977. }
  7978. else
  7979. {
  7980. ++b1;
  7981. }
  7982. word = 0;
  7983. word += (b1 << 16);
  7984. word += (b2 << 8);
  7985. word += b3;
  7986. }
  7987. else
  7988. {
  7989. word += (0x01 << 24);
  7990. }
  7991. return word;
  7992. }
  7993. function incCounter(counter)
  7994. {
  7995. if ((counter[0] = incWord(counter[0])) === 0)
  7996. {
  7997. // encr_data in fileenc.c from Dr Brian Gladman's counts only with DWORD j < 8
  7998. counter[1] = incWord(counter[1]);
  7999. }
  8000. return counter;
  8001. }
  8002. var Encryptor = CTRGladman.Encryptor = CTRGladman.extend({
  8003. processBlock: function (words, offset) {
  8004. // Shortcuts
  8005. var cipher = this._cipher
  8006. var blockSize = cipher.blockSize;
  8007. var iv = this._iv;
  8008. var counter = this._counter;
  8009. // Generate keystream
  8010. if (iv) {
  8011. counter = this._counter = iv.slice(0);
  8012. // Remove IV for subsequent blocks
  8013. this._iv = undefined;
  8014. }
  8015. incCounter(counter);
  8016. var keystream = counter.slice(0);
  8017. cipher.encryptBlock(keystream, 0);
  8018. // Encrypt
  8019. for (var i = 0; i < blockSize; i++) {
  8020. words[offset + i] ^= keystream[i];
  8021. }
  8022. }
  8023. });
  8024. CTRGladman.Decryptor = Encryptor;
  8025. return CTRGladman;
  8026. }());
  8027. return CryptoJS.mode.CTRGladman;
  8028. }));
  8029. },{"./cipher-core":50,"./core":51}],62:[function(require,module,exports){
  8030. ;(function (root, factory, undef) {
  8031. if (typeof exports === "object") {
  8032. // CommonJS
  8033. module.exports = exports = factory(require("./core"), require("./cipher-core"));
  8034. }
  8035. else if (typeof define === "function" && define.amd) {
  8036. // AMD
  8037. define(["./core", "./cipher-core"], factory);
  8038. }
  8039. else {
  8040. // Global (browser)
  8041. factory(root.CryptoJS);
  8042. }
  8043. }(this, function (CryptoJS) {
  8044. /**
  8045. * Counter block mode.
  8046. */
  8047. CryptoJS.mode.CTR = (function () {
  8048. var CTR = CryptoJS.lib.BlockCipherMode.extend();
  8049. var Encryptor = CTR.Encryptor = CTR.extend({
  8050. processBlock: function (words, offset) {
  8051. // Shortcuts
  8052. var cipher = this._cipher
  8053. var blockSize = cipher.blockSize;
  8054. var iv = this._iv;
  8055. var counter = this._counter;
  8056. // Generate keystream
  8057. if (iv) {
  8058. counter = this._counter = iv.slice(0);
  8059. // Remove IV for subsequent blocks
  8060. this._iv = undefined;
  8061. }
  8062. var keystream = counter.slice(0);
  8063. cipher.encryptBlock(keystream, 0);
  8064. // Increment counter
  8065. counter[blockSize - 1] = (counter[blockSize - 1] + 1) | 0
  8066. // Encrypt
  8067. for (var i = 0; i < blockSize; i++) {
  8068. words[offset + i] ^= keystream[i];
  8069. }
  8070. }
  8071. });
  8072. CTR.Decryptor = Encryptor;
  8073. return CTR;
  8074. }());
  8075. return CryptoJS.mode.CTR;
  8076. }));
  8077. },{"./cipher-core":50,"./core":51}],63:[function(require,module,exports){
  8078. ;(function (root, factory, undef) {
  8079. if (typeof exports === "object") {
  8080. // CommonJS
  8081. module.exports = exports = factory(require("./core"), require("./cipher-core"));
  8082. }
  8083. else if (typeof define === "function" && define.amd) {
  8084. // AMD
  8085. define(["./core", "./cipher-core"], factory);
  8086. }
  8087. else {
  8088. // Global (browser)
  8089. factory(root.CryptoJS);
  8090. }
  8091. }(this, function (CryptoJS) {
  8092. /**
  8093. * Electronic Codebook block mode.
  8094. */
  8095. CryptoJS.mode.ECB = (function () {
  8096. var ECB = CryptoJS.lib.BlockCipherMode.extend();
  8097. ECB.Encryptor = ECB.extend({
  8098. processBlock: function (words, offset) {
  8099. this._cipher.encryptBlock(words, offset);
  8100. }
  8101. });
  8102. ECB.Decryptor = ECB.extend({
  8103. processBlock: function (words, offset) {
  8104. this._cipher.decryptBlock(words, offset);
  8105. }
  8106. });
  8107. return ECB;
  8108. }());
  8109. return CryptoJS.mode.ECB;
  8110. }));
  8111. },{"./cipher-core":50,"./core":51}],64:[function(require,module,exports){
  8112. ;(function (root, factory, undef) {
  8113. if (typeof exports === "object") {
  8114. // CommonJS
  8115. module.exports = exports = factory(require("./core"), require("./cipher-core"));
  8116. }
  8117. else if (typeof define === "function" && define.amd) {
  8118. // AMD
  8119. define(["./core", "./cipher-core"], factory);
  8120. }
  8121. else {
  8122. // Global (browser)
  8123. factory(root.CryptoJS);
  8124. }
  8125. }(this, function (CryptoJS) {
  8126. /**
  8127. * Output Feedback block mode.
  8128. */
  8129. CryptoJS.mode.OFB = (function () {
  8130. var OFB = CryptoJS.lib.BlockCipherMode.extend();
  8131. var Encryptor = OFB.Encryptor = OFB.extend({
  8132. processBlock: function (words, offset) {
  8133. // Shortcuts
  8134. var cipher = this._cipher
  8135. var blockSize = cipher.blockSize;
  8136. var iv = this._iv;
  8137. var keystream = this._keystream;
  8138. // Generate keystream
  8139. if (iv) {
  8140. keystream = this._keystream = iv.slice(0);
  8141. // Remove IV for subsequent blocks
  8142. this._iv = undefined;
  8143. }
  8144. cipher.encryptBlock(keystream, 0);
  8145. // Encrypt
  8146. for (var i = 0; i < blockSize; i++) {
  8147. words[offset + i] ^= keystream[i];
  8148. }
  8149. }
  8150. });
  8151. OFB.Decryptor = Encryptor;
  8152. return OFB;
  8153. }());
  8154. return CryptoJS.mode.OFB;
  8155. }));
  8156. },{"./cipher-core":50,"./core":51}],65:[function(require,module,exports){
  8157. ;(function (root, factory, undef) {
  8158. if (typeof exports === "object") {
  8159. // CommonJS
  8160. module.exports = exports = factory(require("./core"), require("./cipher-core"));
  8161. }
  8162. else if (typeof define === "function" && define.amd) {
  8163. // AMD
  8164. define(["./core", "./cipher-core"], factory);
  8165. }
  8166. else {
  8167. // Global (browser)
  8168. factory(root.CryptoJS);
  8169. }
  8170. }(this, function (CryptoJS) {
  8171. /**
  8172. * ANSI X.923 padding strategy.
  8173. */
  8174. CryptoJS.pad.AnsiX923 = {
  8175. pad: function (data, blockSize) {
  8176. // Shortcuts
  8177. var dataSigBytes = data.sigBytes;
  8178. var blockSizeBytes = blockSize * 4;
  8179. // Count padding bytes
  8180. var nPaddingBytes = blockSizeBytes - dataSigBytes % blockSizeBytes;
  8181. // Compute last byte position
  8182. var lastBytePos = dataSigBytes + nPaddingBytes - 1;
  8183. // Pad
  8184. data.clamp();
  8185. data.words[lastBytePos >>> 2] |= nPaddingBytes << (24 - (lastBytePos % 4) * 8);
  8186. data.sigBytes += nPaddingBytes;
  8187. },
  8188. unpad: function (data) {
  8189. // Get number of padding bytes from last byte
  8190. var nPaddingBytes = data.words[(data.sigBytes - 1) >>> 2] & 0xff;
  8191. // Remove padding
  8192. data.sigBytes -= nPaddingBytes;
  8193. }
  8194. };
  8195. return CryptoJS.pad.Ansix923;
  8196. }));
  8197. },{"./cipher-core":50,"./core":51}],66:[function(require,module,exports){
  8198. ;(function (root, factory, undef) {
  8199. if (typeof exports === "object") {
  8200. // CommonJS
  8201. module.exports = exports = factory(require("./core"), require("./cipher-core"));
  8202. }
  8203. else if (typeof define === "function" && define.amd) {
  8204. // AMD
  8205. define(["./core", "./cipher-core"], factory);
  8206. }
  8207. else {
  8208. // Global (browser)
  8209. factory(root.CryptoJS);
  8210. }
  8211. }(this, function (CryptoJS) {
  8212. /**
  8213. * ISO 10126 padding strategy.
  8214. */
  8215. CryptoJS.pad.Iso10126 = {
  8216. pad: function (data, blockSize) {
  8217. // Shortcut
  8218. var blockSizeBytes = blockSize * 4;
  8219. // Count padding bytes
  8220. var nPaddingBytes = blockSizeBytes - data.sigBytes % blockSizeBytes;
  8221. // Pad
  8222. data.concat(CryptoJS.lib.WordArray.random(nPaddingBytes - 1)).
  8223. concat(CryptoJS.lib.WordArray.create([nPaddingBytes << 24], 1));
  8224. },
  8225. unpad: function (data) {
  8226. // Get number of padding bytes from last byte
  8227. var nPaddingBytes = data.words[(data.sigBytes - 1) >>> 2] & 0xff;
  8228. // Remove padding
  8229. data.sigBytes -= nPaddingBytes;
  8230. }
  8231. };
  8232. return CryptoJS.pad.Iso10126;
  8233. }));
  8234. },{"./cipher-core":50,"./core":51}],67:[function(require,module,exports){
  8235. ;(function (root, factory, undef) {
  8236. if (typeof exports === "object") {
  8237. // CommonJS
  8238. module.exports = exports = factory(require("./core"), require("./cipher-core"));
  8239. }
  8240. else if (typeof define === "function" && define.amd) {
  8241. // AMD
  8242. define(["./core", "./cipher-core"], factory);
  8243. }
  8244. else {
  8245. // Global (browser)
  8246. factory(root.CryptoJS);
  8247. }
  8248. }(this, function (CryptoJS) {
  8249. /**
  8250. * ISO/IEC 9797-1 Padding Method 2.
  8251. */
  8252. CryptoJS.pad.Iso97971 = {
  8253. pad: function (data, blockSize) {
  8254. // Add 0x80 byte
  8255. data.concat(CryptoJS.lib.WordArray.create([0x80000000], 1));
  8256. // Zero pad the rest
  8257. CryptoJS.pad.ZeroPadding.pad(data, blockSize);
  8258. },
  8259. unpad: function (data) {
  8260. // Remove zero padding
  8261. CryptoJS.pad.ZeroPadding.unpad(data);
  8262. // Remove one more byte -- the 0x80 byte
  8263. data.sigBytes--;
  8264. }
  8265. };
  8266. return CryptoJS.pad.Iso97971;
  8267. }));
  8268. },{"./cipher-core":50,"./core":51}],68:[function(require,module,exports){
  8269. ;(function (root, factory, undef) {
  8270. if (typeof exports === "object") {
  8271. // CommonJS
  8272. module.exports = exports = factory(require("./core"), require("./cipher-core"));
  8273. }
  8274. else if (typeof define === "function" && define.amd) {
  8275. // AMD
  8276. define(["./core", "./cipher-core"], factory);
  8277. }
  8278. else {
  8279. // Global (browser)
  8280. factory(root.CryptoJS);
  8281. }
  8282. }(this, function (CryptoJS) {
  8283. /**
  8284. * A noop padding strategy.
  8285. */
  8286. CryptoJS.pad.NoPadding = {
  8287. pad: function () {
  8288. },
  8289. unpad: function () {
  8290. }
  8291. };
  8292. return CryptoJS.pad.NoPadding;
  8293. }));
  8294. },{"./cipher-core":50,"./core":51}],69:[function(require,module,exports){
  8295. ;(function (root, factory, undef) {
  8296. if (typeof exports === "object") {
  8297. // CommonJS
  8298. module.exports = exports = factory(require("./core"), require("./cipher-core"));
  8299. }
  8300. else if (typeof define === "function" && define.amd) {
  8301. // AMD
  8302. define(["./core", "./cipher-core"], factory);
  8303. }
  8304. else {
  8305. // Global (browser)
  8306. factory(root.CryptoJS);
  8307. }
  8308. }(this, function (CryptoJS) {
  8309. /**
  8310. * Zero padding strategy.
  8311. */
  8312. CryptoJS.pad.ZeroPadding = {
  8313. pad: function (data, blockSize) {
  8314. // Shortcut
  8315. var blockSizeBytes = blockSize * 4;
  8316. // Pad
  8317. data.clamp();
  8318. data.sigBytes += blockSizeBytes - ((data.sigBytes % blockSizeBytes) || blockSizeBytes);
  8319. },
  8320. unpad: function (data) {
  8321. // Shortcut
  8322. var dataWords = data.words;
  8323. // Unpad
  8324. var i = data.sigBytes - 1;
  8325. while (!((dataWords[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff)) {
  8326. i--;
  8327. }
  8328. data.sigBytes = i + 1;
  8329. }
  8330. };
  8331. return CryptoJS.pad.ZeroPadding;
  8332. }));
  8333. },{"./cipher-core":50,"./core":51}],70:[function(require,module,exports){
  8334. ;(function (root, factory, undef) {
  8335. if (typeof exports === "object") {
  8336. // CommonJS
  8337. module.exports = exports = factory(require("./core"), require("./sha1"), require("./hmac"));
  8338. }
  8339. else if (typeof define === "function" && define.amd) {
  8340. // AMD
  8341. define(["./core", "./sha1", "./hmac"], factory);
  8342. }
  8343. else {
  8344. // Global (browser)
  8345. factory(root.CryptoJS);
  8346. }
  8347. }(this, function (CryptoJS) {
  8348. (function () {
  8349. // Shortcuts
  8350. var C = CryptoJS;
  8351. var C_lib = C.lib;
  8352. var Base = C_lib.Base;
  8353. var WordArray = C_lib.WordArray;
  8354. var C_algo = C.algo;
  8355. var SHA1 = C_algo.SHA1;
  8356. var HMAC = C_algo.HMAC;
  8357. /**
  8358. * Password-Based Key Derivation Function 2 algorithm.
  8359. */
  8360. var PBKDF2 = C_algo.PBKDF2 = Base.extend({
  8361. /**
  8362. * Configuration options.
  8363. *
  8364. * @property {number} keySize The key size in words to generate. Default: 4 (128 bits)
  8365. * @property {Hasher} hasher The hasher to use. Default: SHA1
  8366. * @property {number} iterations The number of iterations to perform. Default: 1
  8367. */
  8368. cfg: Base.extend({
  8369. keySize: 128/32,
  8370. hasher: SHA1,
  8371. iterations: 1
  8372. }),
  8373. /**
  8374. * Initializes a newly created key derivation function.
  8375. *
  8376. * @param {Object} cfg (Optional) The configuration options to use for the derivation.
  8377. *
  8378. * @example
  8379. *
  8380. * var kdf = CryptoJS.algo.PBKDF2.create();
  8381. * var kdf = CryptoJS.algo.PBKDF2.create({ keySize: 8 });
  8382. * var kdf = CryptoJS.algo.PBKDF2.create({ keySize: 8, iterations: 1000 });
  8383. */
  8384. init: function (cfg) {
  8385. this.cfg = this.cfg.extend(cfg);
  8386. },
  8387. /**
  8388. * Computes the Password-Based Key Derivation Function 2.
  8389. *
  8390. * @param {WordArray|string} password The password.
  8391. * @param {WordArray|string} salt A salt.
  8392. *
  8393. * @return {WordArray} The derived key.
  8394. *
  8395. * @example
  8396. *
  8397. * var key = kdf.compute(password, salt);
  8398. */
  8399. compute: function (password, salt) {
  8400. // Shortcut
  8401. var cfg = this.cfg;
  8402. // Init HMAC
  8403. var hmac = HMAC.create(cfg.hasher, password);
  8404. // Initial values
  8405. var derivedKey = WordArray.create();
  8406. var blockIndex = WordArray.create([0x00000001]);
  8407. // Shortcuts
  8408. var derivedKeyWords = derivedKey.words;
  8409. var blockIndexWords = blockIndex.words;
  8410. var keySize = cfg.keySize;
  8411. var iterations = cfg.iterations;
  8412. // Generate key
  8413. while (derivedKeyWords.length < keySize) {
  8414. var block = hmac.update(salt).finalize(blockIndex);
  8415. hmac.reset();
  8416. // Shortcuts
  8417. var blockWords = block.words;
  8418. var blockWordsLength = blockWords.length;
  8419. // Iterations
  8420. var intermediate = block;
  8421. for (var i = 1; i < iterations; i++) {
  8422. intermediate = hmac.finalize(intermediate);
  8423. hmac.reset();
  8424. // Shortcut
  8425. var intermediateWords = intermediate.words;
  8426. // XOR intermediate with block
  8427. for (var j = 0; j < blockWordsLength; j++) {
  8428. blockWords[j] ^= intermediateWords[j];
  8429. }
  8430. }
  8431. derivedKey.concat(block);
  8432. blockIndexWords[0]++;
  8433. }
  8434. derivedKey.sigBytes = keySize * 4;
  8435. return derivedKey;
  8436. }
  8437. });
  8438. /**
  8439. * Computes the Password-Based Key Derivation Function 2.
  8440. *
  8441. * @param {WordArray|string} password The password.
  8442. * @param {WordArray|string} salt A salt.
  8443. * @param {Object} cfg (Optional) The configuration options to use for this computation.
  8444. *
  8445. * @return {WordArray} The derived key.
  8446. *
  8447. * @static
  8448. *
  8449. * @example
  8450. *
  8451. * var key = CryptoJS.PBKDF2(password, salt);
  8452. * var key = CryptoJS.PBKDF2(password, salt, { keySize: 8 });
  8453. * var key = CryptoJS.PBKDF2(password, salt, { keySize: 8, iterations: 1000 });
  8454. */
  8455. C.PBKDF2 = function (password, salt, cfg) {
  8456. return PBKDF2.create(cfg).compute(password, salt);
  8457. };
  8458. }());
  8459. return CryptoJS.PBKDF2;
  8460. }));
  8461. },{"./core":51,"./hmac":56,"./sha1":75}],71:[function(require,module,exports){
  8462. ;(function (root, factory, undef) {
  8463. if (typeof exports === "object") {
  8464. // CommonJS
  8465. module.exports = exports = factory(require("./core"), require("./enc-base64"), require("./md5"), require("./evpkdf"), require("./cipher-core"));
  8466. }
  8467. else if (typeof define === "function" && define.amd) {
  8468. // AMD
  8469. define(["./core", "./enc-base64", "./md5", "./evpkdf", "./cipher-core"], factory);
  8470. }
  8471. else {
  8472. // Global (browser)
  8473. factory(root.CryptoJS);
  8474. }
  8475. }(this, function (CryptoJS) {
  8476. (function () {
  8477. // Shortcuts
  8478. var C = CryptoJS;
  8479. var C_lib = C.lib;
  8480. var StreamCipher = C_lib.StreamCipher;
  8481. var C_algo = C.algo;
  8482. // Reusable objects
  8483. var S = [];
  8484. var C_ = [];
  8485. var G = [];
  8486. /**
  8487. * Rabbit stream cipher algorithm.
  8488. *
  8489. * This is a legacy version that neglected to convert the key to little-endian.
  8490. * This error doesn't affect the cipher's security,
  8491. * but it does affect its compatibility with other implementations.
  8492. */
  8493. var RabbitLegacy = C_algo.RabbitLegacy = StreamCipher.extend({
  8494. _doReset: function () {
  8495. // Shortcuts
  8496. var K = this._key.words;
  8497. var iv = this.cfg.iv;
  8498. // Generate initial state values
  8499. var X = this._X = [
  8500. K[0], (K[3] << 16) | (K[2] >>> 16),
  8501. K[1], (K[0] << 16) | (K[3] >>> 16),
  8502. K[2], (K[1] << 16) | (K[0] >>> 16),
  8503. K[3], (K[2] << 16) | (K[1] >>> 16)
  8504. ];
  8505. // Generate initial counter values
  8506. var C = this._C = [
  8507. (K[2] << 16) | (K[2] >>> 16), (K[0] & 0xffff0000) | (K[1] & 0x0000ffff),
  8508. (K[3] << 16) | (K[3] >>> 16), (K[1] & 0xffff0000) | (K[2] & 0x0000ffff),
  8509. (K[0] << 16) | (K[0] >>> 16), (K[2] & 0xffff0000) | (K[3] & 0x0000ffff),
  8510. (K[1] << 16) | (K[1] >>> 16), (K[3] & 0xffff0000) | (K[0] & 0x0000ffff)
  8511. ];
  8512. // Carry bit
  8513. this._b = 0;
  8514. // Iterate the system four times
  8515. for (var i = 0; i < 4; i++) {
  8516. nextState.call(this);
  8517. }
  8518. // Modify the counters
  8519. for (var i = 0; i < 8; i++) {
  8520. C[i] ^= X[(i + 4) & 7];
  8521. }
  8522. // IV setup
  8523. if (iv) {
  8524. // Shortcuts
  8525. var IV = iv.words;
  8526. var IV_0 = IV[0];
  8527. var IV_1 = IV[1];
  8528. // Generate four subvectors
  8529. var i0 = (((IV_0 << 8) | (IV_0 >>> 24)) & 0x00ff00ff) | (((IV_0 << 24) | (IV_0 >>> 8)) & 0xff00ff00);
  8530. var i2 = (((IV_1 << 8) | (IV_1 >>> 24)) & 0x00ff00ff) | (((IV_1 << 24) | (IV_1 >>> 8)) & 0xff00ff00);
  8531. var i1 = (i0 >>> 16) | (i2 & 0xffff0000);
  8532. var i3 = (i2 << 16) | (i0 & 0x0000ffff);
  8533. // Modify counter values
  8534. C[0] ^= i0;
  8535. C[1] ^= i1;
  8536. C[2] ^= i2;
  8537. C[3] ^= i3;
  8538. C[4] ^= i0;
  8539. C[5] ^= i1;
  8540. C[6] ^= i2;
  8541. C[7] ^= i3;
  8542. // Iterate the system four times
  8543. for (var i = 0; i < 4; i++) {
  8544. nextState.call(this);
  8545. }
  8546. }
  8547. },
  8548. _doProcessBlock: function (M, offset) {
  8549. // Shortcut
  8550. var X = this._X;
  8551. // Iterate the system
  8552. nextState.call(this);
  8553. // Generate four keystream words
  8554. S[0] = X[0] ^ (X[5] >>> 16) ^ (X[3] << 16);
  8555. S[1] = X[2] ^ (X[7] >>> 16) ^ (X[5] << 16);
  8556. S[2] = X[4] ^ (X[1] >>> 16) ^ (X[7] << 16);
  8557. S[3] = X[6] ^ (X[3] >>> 16) ^ (X[1] << 16);
  8558. for (var i = 0; i < 4; i++) {
  8559. // Swap endian
  8560. S[i] = (((S[i] << 8) | (S[i] >>> 24)) & 0x00ff00ff) |
  8561. (((S[i] << 24) | (S[i] >>> 8)) & 0xff00ff00);
  8562. // Encrypt
  8563. M[offset + i] ^= S[i];
  8564. }
  8565. },
  8566. blockSize: 128/32,
  8567. ivSize: 64/32
  8568. });
  8569. function nextState() {
  8570. // Shortcuts
  8571. var X = this._X;
  8572. var C = this._C;
  8573. // Save old counter values
  8574. for (var i = 0; i < 8; i++) {
  8575. C_[i] = C[i];
  8576. }
  8577. // Calculate new counter values
  8578. C[0] = (C[0] + 0x4d34d34d + this._b) | 0;
  8579. C[1] = (C[1] + 0xd34d34d3 + ((C[0] >>> 0) < (C_[0] >>> 0) ? 1 : 0)) | 0;
  8580. C[2] = (C[2] + 0x34d34d34 + ((C[1] >>> 0) < (C_[1] >>> 0) ? 1 : 0)) | 0;
  8581. C[3] = (C[3] + 0x4d34d34d + ((C[2] >>> 0) < (C_[2] >>> 0) ? 1 : 0)) | 0;
  8582. C[4] = (C[4] + 0xd34d34d3 + ((C[3] >>> 0) < (C_[3] >>> 0) ? 1 : 0)) | 0;
  8583. C[5] = (C[5] + 0x34d34d34 + ((C[4] >>> 0) < (C_[4] >>> 0) ? 1 : 0)) | 0;
  8584. C[6] = (C[6] + 0x4d34d34d + ((C[5] >>> 0) < (C_[5] >>> 0) ? 1 : 0)) | 0;
  8585. C[7] = (C[7] + 0xd34d34d3 + ((C[6] >>> 0) < (C_[6] >>> 0) ? 1 : 0)) | 0;
  8586. this._b = (C[7] >>> 0) < (C_[7] >>> 0) ? 1 : 0;
  8587. // Calculate the g-values
  8588. for (var i = 0; i < 8; i++) {
  8589. var gx = X[i] + C[i];
  8590. // Construct high and low argument for squaring
  8591. var ga = gx & 0xffff;
  8592. var gb = gx >>> 16;
  8593. // Calculate high and low result of squaring
  8594. var gh = ((((ga * ga) >>> 17) + ga * gb) >>> 15) + gb * gb;
  8595. var gl = (((gx & 0xffff0000) * gx) | 0) + (((gx & 0x0000ffff) * gx) | 0);
  8596. // High XOR low
  8597. G[i] = gh ^ gl;
  8598. }
  8599. // Calculate new state values
  8600. X[0] = (G[0] + ((G[7] << 16) | (G[7] >>> 16)) + ((G[6] << 16) | (G[6] >>> 16))) | 0;
  8601. X[1] = (G[1] + ((G[0] << 8) | (G[0] >>> 24)) + G[7]) | 0;
  8602. X[2] = (G[2] + ((G[1] << 16) | (G[1] >>> 16)) + ((G[0] << 16) | (G[0] >>> 16))) | 0;
  8603. X[3] = (G[3] + ((G[2] << 8) | (G[2] >>> 24)) + G[1]) | 0;
  8604. X[4] = (G[4] + ((G[3] << 16) | (G[3] >>> 16)) + ((G[2] << 16) | (G[2] >>> 16))) | 0;
  8605. X[5] = (G[5] + ((G[4] << 8) | (G[4] >>> 24)) + G[3]) | 0;
  8606. X[6] = (G[6] + ((G[5] << 16) | (G[5] >>> 16)) + ((G[4] << 16) | (G[4] >>> 16))) | 0;
  8607. X[7] = (G[7] + ((G[6] << 8) | (G[6] >>> 24)) + G[5]) | 0;
  8608. }
  8609. /**
  8610. * Shortcut functions to the cipher's object interface.
  8611. *
  8612. * @example
  8613. *
  8614. * var ciphertext = CryptoJS.RabbitLegacy.encrypt(message, key, cfg);
  8615. * var plaintext = CryptoJS.RabbitLegacy.decrypt(ciphertext, key, cfg);
  8616. */
  8617. C.RabbitLegacy = StreamCipher._createHelper(RabbitLegacy);
  8618. }());
  8619. return CryptoJS.RabbitLegacy;
  8620. }));
  8621. },{"./cipher-core":50,"./core":51,"./enc-base64":52,"./evpkdf":54,"./md5":59}],72:[function(require,module,exports){
  8622. ;(function (root, factory, undef) {
  8623. if (typeof exports === "object") {
  8624. // CommonJS
  8625. module.exports = exports = factory(require("./core"), require("./enc-base64"), require("./md5"), require("./evpkdf"), require("./cipher-core"));
  8626. }
  8627. else if (typeof define === "function" && define.amd) {
  8628. // AMD
  8629. define(["./core", "./enc-base64", "./md5", "./evpkdf", "./cipher-core"], factory);
  8630. }
  8631. else {
  8632. // Global (browser)
  8633. factory(root.CryptoJS);
  8634. }
  8635. }(this, function (CryptoJS) {
  8636. (function () {
  8637. // Shortcuts
  8638. var C = CryptoJS;
  8639. var C_lib = C.lib;
  8640. var StreamCipher = C_lib.StreamCipher;
  8641. var C_algo = C.algo;
  8642. // Reusable objects
  8643. var S = [];
  8644. var C_ = [];
  8645. var G = [];
  8646. /**
  8647. * Rabbit stream cipher algorithm
  8648. */
  8649. var Rabbit = C_algo.Rabbit = StreamCipher.extend({
  8650. _doReset: function () {
  8651. // Shortcuts
  8652. var K = this._key.words;
  8653. var iv = this.cfg.iv;
  8654. // Swap endian
  8655. for (var i = 0; i < 4; i++) {
  8656. K[i] = (((K[i] << 8) | (K[i] >>> 24)) & 0x00ff00ff) |
  8657. (((K[i] << 24) | (K[i] >>> 8)) & 0xff00ff00);
  8658. }
  8659. // Generate initial state values
  8660. var X = this._X = [
  8661. K[0], (K[3] << 16) | (K[2] >>> 16),
  8662. K[1], (K[0] << 16) | (K[3] >>> 16),
  8663. K[2], (K[1] << 16) | (K[0] >>> 16),
  8664. K[3], (K[2] << 16) | (K[1] >>> 16)
  8665. ];
  8666. // Generate initial counter values
  8667. var C = this._C = [
  8668. (K[2] << 16) | (K[2] >>> 16), (K[0] & 0xffff0000) | (K[1] & 0x0000ffff),
  8669. (K[3] << 16) | (K[3] >>> 16), (K[1] & 0xffff0000) | (K[2] & 0x0000ffff),
  8670. (K[0] << 16) | (K[0] >>> 16), (K[2] & 0xffff0000) | (K[3] & 0x0000ffff),
  8671. (K[1] << 16) | (K[1] >>> 16), (K[3] & 0xffff0000) | (K[0] & 0x0000ffff)
  8672. ];
  8673. // Carry bit
  8674. this._b = 0;
  8675. // Iterate the system four times
  8676. for (var i = 0; i < 4; i++) {
  8677. nextState.call(this);
  8678. }
  8679. // Modify the counters
  8680. for (var i = 0; i < 8; i++) {
  8681. C[i] ^= X[(i + 4) & 7];
  8682. }
  8683. // IV setup
  8684. if (iv) {
  8685. // Shortcuts
  8686. var IV = iv.words;
  8687. var IV_0 = IV[0];
  8688. var IV_1 = IV[1];
  8689. // Generate four subvectors
  8690. var i0 = (((IV_0 << 8) | (IV_0 >>> 24)) & 0x00ff00ff) | (((IV_0 << 24) | (IV_0 >>> 8)) & 0xff00ff00);
  8691. var i2 = (((IV_1 << 8) | (IV_1 >>> 24)) & 0x00ff00ff) | (((IV_1 << 24) | (IV_1 >>> 8)) & 0xff00ff00);
  8692. var i1 = (i0 >>> 16) | (i2 & 0xffff0000);
  8693. var i3 = (i2 << 16) | (i0 & 0x0000ffff);
  8694. // Modify counter values
  8695. C[0] ^= i0;
  8696. C[1] ^= i1;
  8697. C[2] ^= i2;
  8698. C[3] ^= i3;
  8699. C[4] ^= i0;
  8700. C[5] ^= i1;
  8701. C[6] ^= i2;
  8702. C[7] ^= i3;
  8703. // Iterate the system four times
  8704. for (var i = 0; i < 4; i++) {
  8705. nextState.call(this);
  8706. }
  8707. }
  8708. },
  8709. _doProcessBlock: function (M, offset) {
  8710. // Shortcut
  8711. var X = this._X;
  8712. // Iterate the system
  8713. nextState.call(this);
  8714. // Generate four keystream words
  8715. S[0] = X[0] ^ (X[5] >>> 16) ^ (X[3] << 16);
  8716. S[1] = X[2] ^ (X[7] >>> 16) ^ (X[5] << 16);
  8717. S[2] = X[4] ^ (X[1] >>> 16) ^ (X[7] << 16);
  8718. S[3] = X[6] ^ (X[3] >>> 16) ^ (X[1] << 16);
  8719. for (var i = 0; i < 4; i++) {
  8720. // Swap endian
  8721. S[i] = (((S[i] << 8) | (S[i] >>> 24)) & 0x00ff00ff) |
  8722. (((S[i] << 24) | (S[i] >>> 8)) & 0xff00ff00);
  8723. // Encrypt
  8724. M[offset + i] ^= S[i];
  8725. }
  8726. },
  8727. blockSize: 128/32,
  8728. ivSize: 64/32
  8729. });
  8730. function nextState() {
  8731. // Shortcuts
  8732. var X = this._X;
  8733. var C = this._C;
  8734. // Save old counter values
  8735. for (var i = 0; i < 8; i++) {
  8736. C_[i] = C[i];
  8737. }
  8738. // Calculate new counter values
  8739. C[0] = (C[0] + 0x4d34d34d + this._b) | 0;
  8740. C[1] = (C[1] + 0xd34d34d3 + ((C[0] >>> 0) < (C_[0] >>> 0) ? 1 : 0)) | 0;
  8741. C[2] = (C[2] + 0x34d34d34 + ((C[1] >>> 0) < (C_[1] >>> 0) ? 1 : 0)) | 0;
  8742. C[3] = (C[3] + 0x4d34d34d + ((C[2] >>> 0) < (C_[2] >>> 0) ? 1 : 0)) | 0;
  8743. C[4] = (C[4] + 0xd34d34d3 + ((C[3] >>> 0) < (C_[3] >>> 0) ? 1 : 0)) | 0;
  8744. C[5] = (C[5] + 0x34d34d34 + ((C[4] >>> 0) < (C_[4] >>> 0) ? 1 : 0)) | 0;
  8745. C[6] = (C[6] + 0x4d34d34d + ((C[5] >>> 0) < (C_[5] >>> 0) ? 1 : 0)) | 0;
  8746. C[7] = (C[7] + 0xd34d34d3 + ((C[6] >>> 0) < (C_[6] >>> 0) ? 1 : 0)) | 0;
  8747. this._b = (C[7] >>> 0) < (C_[7] >>> 0) ? 1 : 0;
  8748. // Calculate the g-values
  8749. for (var i = 0; i < 8; i++) {
  8750. var gx = X[i] + C[i];
  8751. // Construct high and low argument for squaring
  8752. var ga = gx & 0xffff;
  8753. var gb = gx >>> 16;
  8754. // Calculate high and low result of squaring
  8755. var gh = ((((ga * ga) >>> 17) + ga * gb) >>> 15) + gb * gb;
  8756. var gl = (((gx & 0xffff0000) * gx) | 0) + (((gx & 0x0000ffff) * gx) | 0);
  8757. // High XOR low
  8758. G[i] = gh ^ gl;
  8759. }
  8760. // Calculate new state values
  8761. X[0] = (G[0] + ((G[7] << 16) | (G[7] >>> 16)) + ((G[6] << 16) | (G[6] >>> 16))) | 0;
  8762. X[1] = (G[1] + ((G[0] << 8) | (G[0] >>> 24)) + G[7]) | 0;
  8763. X[2] = (G[2] + ((G[1] << 16) | (G[1] >>> 16)) + ((G[0] << 16) | (G[0] >>> 16))) | 0;
  8764. X[3] = (G[3] + ((G[2] << 8) | (G[2] >>> 24)) + G[1]) | 0;
  8765. X[4] = (G[4] + ((G[3] << 16) | (G[3] >>> 16)) + ((G[2] << 16) | (G[2] >>> 16))) | 0;
  8766. X[5] = (G[5] + ((G[4] << 8) | (G[4] >>> 24)) + G[3]) | 0;
  8767. X[6] = (G[6] + ((G[5] << 16) | (G[5] >>> 16)) + ((G[4] << 16) | (G[4] >>> 16))) | 0;
  8768. X[7] = (G[7] + ((G[6] << 8) | (G[6] >>> 24)) + G[5]) | 0;
  8769. }
  8770. /**
  8771. * Shortcut functions to the cipher's object interface.
  8772. *
  8773. * @example
  8774. *
  8775. * var ciphertext = CryptoJS.Rabbit.encrypt(message, key, cfg);
  8776. * var plaintext = CryptoJS.Rabbit.decrypt(ciphertext, key, cfg);
  8777. */
  8778. C.Rabbit = StreamCipher._createHelper(Rabbit);
  8779. }());
  8780. return CryptoJS.Rabbit;
  8781. }));
  8782. },{"./cipher-core":50,"./core":51,"./enc-base64":52,"./evpkdf":54,"./md5":59}],73:[function(require,module,exports){
  8783. ;(function (root, factory, undef) {
  8784. if (typeof exports === "object") {
  8785. // CommonJS
  8786. module.exports = exports = factory(require("./core"), require("./enc-base64"), require("./md5"), require("./evpkdf"), require("./cipher-core"));
  8787. }
  8788. else if (typeof define === "function" && define.amd) {
  8789. // AMD
  8790. define(["./core", "./enc-base64", "./md5", "./evpkdf", "./cipher-core"], factory);
  8791. }
  8792. else {
  8793. // Global (browser)
  8794. factory(root.CryptoJS);
  8795. }
  8796. }(this, function (CryptoJS) {
  8797. (function () {
  8798. // Shortcuts
  8799. var C = CryptoJS;
  8800. var C_lib = C.lib;
  8801. var StreamCipher = C_lib.StreamCipher;
  8802. var C_algo = C.algo;
  8803. /**
  8804. * RC4 stream cipher algorithm.
  8805. */
  8806. var RC4 = C_algo.RC4 = StreamCipher.extend({
  8807. _doReset: function () {
  8808. // Shortcuts
  8809. var key = this._key;
  8810. var keyWords = key.words;
  8811. var keySigBytes = key.sigBytes;
  8812. // Init sbox
  8813. var S = this._S = [];
  8814. for (var i = 0; i < 256; i++) {
  8815. S[i] = i;
  8816. }
  8817. // Key setup
  8818. for (var i = 0, j = 0; i < 256; i++) {
  8819. var keyByteIndex = i % keySigBytes;
  8820. var keyByte = (keyWords[keyByteIndex >>> 2] >>> (24 - (keyByteIndex % 4) * 8)) & 0xff;
  8821. j = (j + S[i] + keyByte) % 256;
  8822. // Swap
  8823. var t = S[i];
  8824. S[i] = S[j];
  8825. S[j] = t;
  8826. }
  8827. // Counters
  8828. this._i = this._j = 0;
  8829. },
  8830. _doProcessBlock: function (M, offset) {
  8831. M[offset] ^= generateKeystreamWord.call(this);
  8832. },
  8833. keySize: 256/32,
  8834. ivSize: 0
  8835. });
  8836. function generateKeystreamWord() {
  8837. // Shortcuts
  8838. var S = this._S;
  8839. var i = this._i;
  8840. var j = this._j;
  8841. // Generate keystream word
  8842. var keystreamWord = 0;
  8843. for (var n = 0; n < 4; n++) {
  8844. i = (i + 1) % 256;
  8845. j = (j + S[i]) % 256;
  8846. // Swap
  8847. var t = S[i];
  8848. S[i] = S[j];
  8849. S[j] = t;
  8850. keystreamWord |= S[(S[i] + S[j]) % 256] << (24 - n * 8);
  8851. }
  8852. // Update counters
  8853. this._i = i;
  8854. this._j = j;
  8855. return keystreamWord;
  8856. }
  8857. /**
  8858. * Shortcut functions to the cipher's object interface.
  8859. *
  8860. * @example
  8861. *
  8862. * var ciphertext = CryptoJS.RC4.encrypt(message, key, cfg);
  8863. * var plaintext = CryptoJS.RC4.decrypt(ciphertext, key, cfg);
  8864. */
  8865. C.RC4 = StreamCipher._createHelper(RC4);
  8866. /**
  8867. * Modified RC4 stream cipher algorithm.
  8868. */
  8869. var RC4Drop = C_algo.RC4Drop = RC4.extend({
  8870. /**
  8871. * Configuration options.
  8872. *
  8873. * @property {number} drop The number of keystream words to drop. Default 192
  8874. */
  8875. cfg: RC4.cfg.extend({
  8876. drop: 192
  8877. }),
  8878. _doReset: function () {
  8879. RC4._doReset.call(this);
  8880. // Drop
  8881. for (var i = this.cfg.drop; i > 0; i--) {
  8882. generateKeystreamWord.call(this);
  8883. }
  8884. }
  8885. });
  8886. /**
  8887. * Shortcut functions to the cipher's object interface.
  8888. *
  8889. * @example
  8890. *
  8891. * var ciphertext = CryptoJS.RC4Drop.encrypt(message, key, cfg);
  8892. * var plaintext = CryptoJS.RC4Drop.decrypt(ciphertext, key, cfg);
  8893. */
  8894. C.RC4Drop = StreamCipher._createHelper(RC4Drop);
  8895. }());
  8896. return CryptoJS.RC4;
  8897. }));
  8898. },{"./cipher-core":50,"./core":51,"./enc-base64":52,"./evpkdf":54,"./md5":59}],74:[function(require,module,exports){
  8899. ;(function (root, factory) {
  8900. if (typeof exports === "object") {
  8901. // CommonJS
  8902. module.exports = exports = factory(require("./core"));
  8903. }
  8904. else if (typeof define === "function" && define.amd) {
  8905. // AMD
  8906. define(["./core"], factory);
  8907. }
  8908. else {
  8909. // Global (browser)
  8910. factory(root.CryptoJS);
  8911. }
  8912. }(this, function (CryptoJS) {
  8913. /** @preserve
  8914. (c) 2012 by Cédric Mesnil. All rights reserved.
  8915. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
  8916. - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  8917. - 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.
  8918. 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.
  8919. */
  8920. (function (Math) {
  8921. // Shortcuts
  8922. var C = CryptoJS;
  8923. var C_lib = C.lib;
  8924. var WordArray = C_lib.WordArray;
  8925. var Hasher = C_lib.Hasher;
  8926. var C_algo = C.algo;
  8927. // Constants table
  8928. var _zl = WordArray.create([
  8929. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
  8930. 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8,
  8931. 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12,
  8932. 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2,
  8933. 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13]);
  8934. var _zr = WordArray.create([
  8935. 5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12,
  8936. 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2,
  8937. 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13,
  8938. 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14,
  8939. 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11]);
  8940. var _sl = WordArray.create([
  8941. 11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8,
  8942. 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12,
  8943. 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5,
  8944. 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12,
  8945. 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6 ]);
  8946. var _sr = WordArray.create([
  8947. 8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6,
  8948. 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11,
  8949. 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5,
  8950. 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8,
  8951. 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11 ]);
  8952. var _hl = WordArray.create([ 0x00000000, 0x5A827999, 0x6ED9EBA1, 0x8F1BBCDC, 0xA953FD4E]);
  8953. var _hr = WordArray.create([ 0x50A28BE6, 0x5C4DD124, 0x6D703EF3, 0x7A6D76E9, 0x00000000]);
  8954. /**
  8955. * RIPEMD160 hash algorithm.
  8956. */
  8957. var RIPEMD160 = C_algo.RIPEMD160 = Hasher.extend({
  8958. _doReset: function () {
  8959. this._hash = WordArray.create([0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0]);
  8960. },
  8961. _doProcessBlock: function (M, offset) {
  8962. // Swap endian
  8963. for (var i = 0; i < 16; i++) {
  8964. // Shortcuts
  8965. var offset_i = offset + i;
  8966. var M_offset_i = M[offset_i];
  8967. // Swap
  8968. M[offset_i] = (
  8969. (((M_offset_i << 8) | (M_offset_i >>> 24)) & 0x00ff00ff) |
  8970. (((M_offset_i << 24) | (M_offset_i >>> 8)) & 0xff00ff00)
  8971. );
  8972. }
  8973. // Shortcut
  8974. var H = this._hash.words;
  8975. var hl = _hl.words;
  8976. var hr = _hr.words;
  8977. var zl = _zl.words;
  8978. var zr = _zr.words;
  8979. var sl = _sl.words;
  8980. var sr = _sr.words;
  8981. // Working variables
  8982. var al, bl, cl, dl, el;
  8983. var ar, br, cr, dr, er;
  8984. ar = al = H[0];
  8985. br = bl = H[1];
  8986. cr = cl = H[2];
  8987. dr = dl = H[3];
  8988. er = el = H[4];
  8989. // Computation
  8990. var t;
  8991. for (var i = 0; i < 80; i += 1) {
  8992. t = (al + M[offset+zl[i]])|0;
  8993. if (i<16){
  8994. t += f1(bl,cl,dl) + hl[0];
  8995. } else if (i<32) {
  8996. t += f2(bl,cl,dl) + hl[1];
  8997. } else if (i<48) {
  8998. t += f3(bl,cl,dl) + hl[2];
  8999. } else if (i<64) {
  9000. t += f4(bl,cl,dl) + hl[3];
  9001. } else {// if (i<80) {
  9002. t += f5(bl,cl,dl) + hl[4];
  9003. }
  9004. t = t|0;
  9005. t = rotl(t,sl[i]);
  9006. t = (t+el)|0;
  9007. al = el;
  9008. el = dl;
  9009. dl = rotl(cl, 10);
  9010. cl = bl;
  9011. bl = t;
  9012. t = (ar + M[offset+zr[i]])|0;
  9013. if (i<16){
  9014. t += f5(br,cr,dr) + hr[0];
  9015. } else if (i<32) {
  9016. t += f4(br,cr,dr) + hr[1];
  9017. } else if (i<48) {
  9018. t += f3(br,cr,dr) + hr[2];
  9019. } else if (i<64) {
  9020. t += f2(br,cr,dr) + hr[3];
  9021. } else {// if (i<80) {
  9022. t += f1(br,cr,dr) + hr[4];
  9023. }
  9024. t = t|0;
  9025. t = rotl(t,sr[i]) ;
  9026. t = (t+er)|0;
  9027. ar = er;
  9028. er = dr;
  9029. dr = rotl(cr, 10);
  9030. cr = br;
  9031. br = t;
  9032. }
  9033. // Intermediate hash value
  9034. t = (H[1] + cl + dr)|0;
  9035. H[1] = (H[2] + dl + er)|0;
  9036. H[2] = (H[3] + el + ar)|0;
  9037. H[3] = (H[4] + al + br)|0;
  9038. H[4] = (H[0] + bl + cr)|0;
  9039. H[0] = t;
  9040. },
  9041. _doFinalize: function () {
  9042. // Shortcuts
  9043. var data = this._data;
  9044. var dataWords = data.words;
  9045. var nBitsTotal = this._nDataBytes * 8;
  9046. var nBitsLeft = data.sigBytes * 8;
  9047. // Add padding
  9048. dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32);
  9049. dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = (
  9050. (((nBitsTotal << 8) | (nBitsTotal >>> 24)) & 0x00ff00ff) |
  9051. (((nBitsTotal << 24) | (nBitsTotal >>> 8)) & 0xff00ff00)
  9052. );
  9053. data.sigBytes = (dataWords.length + 1) * 4;
  9054. // Hash final blocks
  9055. this._process();
  9056. // Shortcuts
  9057. var hash = this._hash;
  9058. var H = hash.words;
  9059. // Swap endian
  9060. for (var i = 0; i < 5; i++) {
  9061. // Shortcut
  9062. var H_i = H[i];
  9063. // Swap
  9064. H[i] = (((H_i << 8) | (H_i >>> 24)) & 0x00ff00ff) |
  9065. (((H_i << 24) | (H_i >>> 8)) & 0xff00ff00);
  9066. }
  9067. // Return final computed hash
  9068. return hash;
  9069. },
  9070. clone: function () {
  9071. var clone = Hasher.clone.call(this);
  9072. clone._hash = this._hash.clone();
  9073. return clone;
  9074. }
  9075. });
  9076. function f1(x, y, z) {
  9077. return ((x) ^ (y) ^ (z));
  9078. }
  9079. function f2(x, y, z) {
  9080. return (((x)&(y)) | ((~x)&(z)));
  9081. }
  9082. function f3(x, y, z) {
  9083. return (((x) | (~(y))) ^ (z));
  9084. }
  9085. function f4(x, y, z) {
  9086. return (((x) & (z)) | ((y)&(~(z))));
  9087. }
  9088. function f5(x, y, z) {
  9089. return ((x) ^ ((y) |(~(z))));
  9090. }
  9091. function rotl(x,n) {
  9092. return (x<<n) | (x>>>(32-n));
  9093. }
  9094. /**
  9095. * Shortcut function to the hasher's object interface.
  9096. *
  9097. * @param {WordArray|string} message The message to hash.
  9098. *
  9099. * @return {WordArray} The hash.
  9100. *
  9101. * @static
  9102. *
  9103. * @example
  9104. *
  9105. * var hash = CryptoJS.RIPEMD160('message');
  9106. * var hash = CryptoJS.RIPEMD160(wordArray);
  9107. */
  9108. C.RIPEMD160 = Hasher._createHelper(RIPEMD160);
  9109. /**
  9110. * Shortcut function to the HMAC's object interface.
  9111. *
  9112. * @param {WordArray|string} message The message to hash.
  9113. * @param {WordArray|string} key The secret key.
  9114. *
  9115. * @return {WordArray} The HMAC.
  9116. *
  9117. * @static
  9118. *
  9119. * @example
  9120. *
  9121. * var hmac = CryptoJS.HmacRIPEMD160(message, key);
  9122. */
  9123. C.HmacRIPEMD160 = Hasher._createHmacHelper(RIPEMD160);
  9124. }(Math));
  9125. return CryptoJS.RIPEMD160;
  9126. }));
  9127. },{"./core":51}],75:[function(require,module,exports){
  9128. ;(function (root, factory) {
  9129. if (typeof exports === "object") {
  9130. // CommonJS
  9131. module.exports = exports = factory(require("./core"));
  9132. }
  9133. else if (typeof define === "function" && define.amd) {
  9134. // AMD
  9135. define(["./core"], factory);
  9136. }
  9137. else {
  9138. // Global (browser)
  9139. factory(root.CryptoJS);
  9140. }
  9141. }(this, function (CryptoJS) {
  9142. (function () {
  9143. // Shortcuts
  9144. var C = CryptoJS;
  9145. var C_lib = C.lib;
  9146. var WordArray = C_lib.WordArray;
  9147. var Hasher = C_lib.Hasher;
  9148. var C_algo = C.algo;
  9149. // Reusable object
  9150. var W = [];
  9151. /**
  9152. * SHA-1 hash algorithm.
  9153. */
  9154. var SHA1 = C_algo.SHA1 = Hasher.extend({
  9155. _doReset: function () {
  9156. this._hash = new WordArray.init([
  9157. 0x67452301, 0xefcdab89,
  9158. 0x98badcfe, 0x10325476,
  9159. 0xc3d2e1f0
  9160. ]);
  9161. },
  9162. _doProcessBlock: function (M, offset) {
  9163. // Shortcut
  9164. var H = this._hash.words;
  9165. // Working variables
  9166. var a = H[0];
  9167. var b = H[1];
  9168. var c = H[2];
  9169. var d = H[3];
  9170. var e = H[4];
  9171. // Computation
  9172. for (var i = 0; i < 80; i++) {
  9173. if (i < 16) {
  9174. W[i] = M[offset + i] | 0;
  9175. } else {
  9176. var n = W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16];
  9177. W[i] = (n << 1) | (n >>> 31);
  9178. }
  9179. var t = ((a << 5) | (a >>> 27)) + e + W[i];
  9180. if (i < 20) {
  9181. t += ((b & c) | (~b & d)) + 0x5a827999;
  9182. } else if (i < 40) {
  9183. t += (b ^ c ^ d) + 0x6ed9eba1;
  9184. } else if (i < 60) {
  9185. t += ((b & c) | (b & d) | (c & d)) - 0x70e44324;
  9186. } else /* if (i < 80) */ {
  9187. t += (b ^ c ^ d) - 0x359d3e2a;
  9188. }
  9189. e = d;
  9190. d = c;
  9191. c = (b << 30) | (b >>> 2);
  9192. b = a;
  9193. a = t;
  9194. }
  9195. // Intermediate hash value
  9196. H[0] = (H[0] + a) | 0;
  9197. H[1] = (H[1] + b) | 0;
  9198. H[2] = (H[2] + c) | 0;
  9199. H[3] = (H[3] + d) | 0;
  9200. H[4] = (H[4] + e) | 0;
  9201. },
  9202. _doFinalize: function () {
  9203. // Shortcuts
  9204. var data = this._data;
  9205. var dataWords = data.words;
  9206. var nBitsTotal = this._nDataBytes * 8;
  9207. var nBitsLeft = data.sigBytes * 8;
  9208. // Add padding
  9209. dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32);
  9210. dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = Math.floor(nBitsTotal / 0x100000000);
  9211. dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = nBitsTotal;
  9212. data.sigBytes = dataWords.length * 4;
  9213. // Hash final blocks
  9214. this._process();
  9215. // Return final computed hash
  9216. return this._hash;
  9217. },
  9218. clone: function () {
  9219. var clone = Hasher.clone.call(this);
  9220. clone._hash = this._hash.clone();
  9221. return clone;
  9222. }
  9223. });
  9224. /**
  9225. * Shortcut function to the hasher's object interface.
  9226. *
  9227. * @param {WordArray|string} message The message to hash.
  9228. *
  9229. * @return {WordArray} The hash.
  9230. *
  9231. * @static
  9232. *
  9233. * @example
  9234. *
  9235. * var hash = CryptoJS.SHA1('message');
  9236. * var hash = CryptoJS.SHA1(wordArray);
  9237. */
  9238. C.SHA1 = Hasher._createHelper(SHA1);
  9239. /**
  9240. * Shortcut function to the HMAC's object interface.
  9241. *
  9242. * @param {WordArray|string} message The message to hash.
  9243. * @param {WordArray|string} key The secret key.
  9244. *
  9245. * @return {WordArray} The HMAC.
  9246. *
  9247. * @static
  9248. *
  9249. * @example
  9250. *
  9251. * var hmac = CryptoJS.HmacSHA1(message, key);
  9252. */
  9253. C.HmacSHA1 = Hasher._createHmacHelper(SHA1);
  9254. }());
  9255. return CryptoJS.SHA1;
  9256. }));
  9257. },{"./core":51}],76:[function(require,module,exports){
  9258. ;(function (root, factory, undef) {
  9259. if (typeof exports === "object") {
  9260. // CommonJS
  9261. module.exports = exports = factory(require("./core"), require("./sha256"));
  9262. }
  9263. else if (typeof define === "function" && define.amd) {
  9264. // AMD
  9265. define(["./core", "./sha256"], factory);
  9266. }
  9267. else {
  9268. // Global (browser)
  9269. factory(root.CryptoJS);
  9270. }
  9271. }(this, function (CryptoJS) {
  9272. (function () {
  9273. // Shortcuts
  9274. var C = CryptoJS;
  9275. var C_lib = C.lib;
  9276. var WordArray = C_lib.WordArray;
  9277. var C_algo = C.algo;
  9278. var SHA256 = C_algo.SHA256;
  9279. /**
  9280. * SHA-224 hash algorithm.
  9281. */
  9282. var SHA224 = C_algo.SHA224 = SHA256.extend({
  9283. _doReset: function () {
  9284. this._hash = new WordArray.init([
  9285. 0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939,
  9286. 0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4
  9287. ]);
  9288. },
  9289. _doFinalize: function () {
  9290. var hash = SHA256._doFinalize.call(this);
  9291. hash.sigBytes -= 4;
  9292. return hash;
  9293. }
  9294. });
  9295. /**
  9296. * Shortcut function to the hasher's object interface.
  9297. *
  9298. * @param {WordArray|string} message The message to hash.
  9299. *
  9300. * @return {WordArray} The hash.
  9301. *
  9302. * @static
  9303. *
  9304. * @example
  9305. *
  9306. * var hash = CryptoJS.SHA224('message');
  9307. * var hash = CryptoJS.SHA224(wordArray);
  9308. */
  9309. C.SHA224 = SHA256._createHelper(SHA224);
  9310. /**
  9311. * Shortcut function to the HMAC's object interface.
  9312. *
  9313. * @param {WordArray|string} message The message to hash.
  9314. * @param {WordArray|string} key The secret key.
  9315. *
  9316. * @return {WordArray} The HMAC.
  9317. *
  9318. * @static
  9319. *
  9320. * @example
  9321. *
  9322. * var hmac = CryptoJS.HmacSHA224(message, key);
  9323. */
  9324. C.HmacSHA224 = SHA256._createHmacHelper(SHA224);
  9325. }());
  9326. return CryptoJS.SHA224;
  9327. }));
  9328. },{"./core":51,"./sha256":77}],77:[function(require,module,exports){
  9329. ;(function (root, factory) {
  9330. if (typeof exports === "object") {
  9331. // CommonJS
  9332. module.exports = exports = factory(require("./core"));
  9333. }
  9334. else if (typeof define === "function" && define.amd) {
  9335. // AMD
  9336. define(["./core"], factory);
  9337. }
  9338. else {
  9339. // Global (browser)
  9340. factory(root.CryptoJS);
  9341. }
  9342. }(this, function (CryptoJS) {
  9343. (function (Math) {
  9344. // Shortcuts
  9345. var C = CryptoJS;
  9346. var C_lib = C.lib;
  9347. var WordArray = C_lib.WordArray;
  9348. var Hasher = C_lib.Hasher;
  9349. var C_algo = C.algo;
  9350. // Initialization and round constants tables
  9351. var H = [];
  9352. var K = [];
  9353. // Compute constants
  9354. (function () {
  9355. function isPrime(n) {
  9356. var sqrtN = Math.sqrt(n);
  9357. for (var factor = 2; factor <= sqrtN; factor++) {
  9358. if (!(n % factor)) {
  9359. return false;
  9360. }
  9361. }
  9362. return true;
  9363. }
  9364. function getFractionalBits(n) {
  9365. return ((n - (n | 0)) * 0x100000000) | 0;
  9366. }
  9367. var n = 2;
  9368. var nPrime = 0;
  9369. while (nPrime < 64) {
  9370. if (isPrime(n)) {
  9371. if (nPrime < 8) {
  9372. H[nPrime] = getFractionalBits(Math.pow(n, 1 / 2));
  9373. }
  9374. K[nPrime] = getFractionalBits(Math.pow(n, 1 / 3));
  9375. nPrime++;
  9376. }
  9377. n++;
  9378. }
  9379. }());
  9380. // Reusable object
  9381. var W = [];
  9382. /**
  9383. * SHA-256 hash algorithm.
  9384. */
  9385. var SHA256 = C_algo.SHA256 = Hasher.extend({
  9386. _doReset: function () {
  9387. this._hash = new WordArray.init(H.slice(0));
  9388. },
  9389. _doProcessBlock: function (M, offset) {
  9390. // Shortcut
  9391. var H = this._hash.words;
  9392. // Working variables
  9393. var a = H[0];
  9394. var b = H[1];
  9395. var c = H[2];
  9396. var d = H[3];
  9397. var e = H[4];
  9398. var f = H[5];
  9399. var g = H[6];
  9400. var h = H[7];
  9401. // Computation
  9402. for (var i = 0; i < 64; i++) {
  9403. if (i < 16) {
  9404. W[i] = M[offset + i] | 0;
  9405. } else {
  9406. var gamma0x = W[i - 15];
  9407. var gamma0 = ((gamma0x << 25) | (gamma0x >>> 7)) ^
  9408. ((gamma0x << 14) | (gamma0x >>> 18)) ^
  9409. (gamma0x >>> 3);
  9410. var gamma1x = W[i - 2];
  9411. var gamma1 = ((gamma1x << 15) | (gamma1x >>> 17)) ^
  9412. ((gamma1x << 13) | (gamma1x >>> 19)) ^
  9413. (gamma1x >>> 10);
  9414. W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16];
  9415. }
  9416. var ch = (e & f) ^ (~e & g);
  9417. var maj = (a & b) ^ (a & c) ^ (b & c);
  9418. var sigma0 = ((a << 30) | (a >>> 2)) ^ ((a << 19) | (a >>> 13)) ^ ((a << 10) | (a >>> 22));
  9419. var sigma1 = ((e << 26) | (e >>> 6)) ^ ((e << 21) | (e >>> 11)) ^ ((e << 7) | (e >>> 25));
  9420. var t1 = h + sigma1 + ch + K[i] + W[i];
  9421. var t2 = sigma0 + maj;
  9422. h = g;
  9423. g = f;
  9424. f = e;
  9425. e = (d + t1) | 0;
  9426. d = c;
  9427. c = b;
  9428. b = a;
  9429. a = (t1 + t2) | 0;
  9430. }
  9431. // Intermediate hash value
  9432. H[0] = (H[0] + a) | 0;
  9433. H[1] = (H[1] + b) | 0;
  9434. H[2] = (H[2] + c) | 0;
  9435. H[3] = (H[3] + d) | 0;
  9436. H[4] = (H[4] + e) | 0;
  9437. H[5] = (H[5] + f) | 0;
  9438. H[6] = (H[6] + g) | 0;
  9439. H[7] = (H[7] + h) | 0;
  9440. },
  9441. _doFinalize: function () {
  9442. // Shortcuts
  9443. var data = this._data;
  9444. var dataWords = data.words;
  9445. var nBitsTotal = this._nDataBytes * 8;
  9446. var nBitsLeft = data.sigBytes * 8;
  9447. // Add padding
  9448. dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32);
  9449. dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = Math.floor(nBitsTotal / 0x100000000);
  9450. dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = nBitsTotal;
  9451. data.sigBytes = dataWords.length * 4;
  9452. // Hash final blocks
  9453. this._process();
  9454. // Return final computed hash
  9455. return this._hash;
  9456. },
  9457. clone: function () {
  9458. var clone = Hasher.clone.call(this);
  9459. clone._hash = this._hash.clone();
  9460. return clone;
  9461. }
  9462. });
  9463. /**
  9464. * Shortcut function to the hasher's object interface.
  9465. *
  9466. * @param {WordArray|string} message The message to hash.
  9467. *
  9468. * @return {WordArray} The hash.
  9469. *
  9470. * @static
  9471. *
  9472. * @example
  9473. *
  9474. * var hash = CryptoJS.SHA256('message');
  9475. * var hash = CryptoJS.SHA256(wordArray);
  9476. */
  9477. C.SHA256 = Hasher._createHelper(SHA256);
  9478. /**
  9479. * Shortcut function to the HMAC's object interface.
  9480. *
  9481. * @param {WordArray|string} message The message to hash.
  9482. * @param {WordArray|string} key The secret key.
  9483. *
  9484. * @return {WordArray} The HMAC.
  9485. *
  9486. * @static
  9487. *
  9488. * @example
  9489. *
  9490. * var hmac = CryptoJS.HmacSHA256(message, key);
  9491. */
  9492. C.HmacSHA256 = Hasher._createHmacHelper(SHA256);
  9493. }(Math));
  9494. return CryptoJS.SHA256;
  9495. }));
  9496. },{"./core":51}],78:[function(require,module,exports){
  9497. ;(function (root, factory, undef) {
  9498. if (typeof exports === "object") {
  9499. // CommonJS
  9500. module.exports = exports = factory(require("./core"), require("./x64-core"));
  9501. }
  9502. else if (typeof define === "function" && define.amd) {
  9503. // AMD
  9504. define(["./core", "./x64-core"], factory);
  9505. }
  9506. else {
  9507. // Global (browser)
  9508. factory(root.CryptoJS);
  9509. }
  9510. }(this, function (CryptoJS) {
  9511. (function (Math) {
  9512. // Shortcuts
  9513. var C = CryptoJS;
  9514. var C_lib = C.lib;
  9515. var WordArray = C_lib.WordArray;
  9516. var Hasher = C_lib.Hasher;
  9517. var C_x64 = C.x64;
  9518. var X64Word = C_x64.Word;
  9519. var C_algo = C.algo;
  9520. // Constants tables
  9521. var RHO_OFFSETS = [];
  9522. var PI_INDEXES = [];
  9523. var ROUND_CONSTANTS = [];
  9524. // Compute Constants
  9525. (function () {
  9526. // Compute rho offset constants
  9527. var x = 1, y = 0;
  9528. for (var t = 0; t < 24; t++) {
  9529. RHO_OFFSETS[x + 5 * y] = ((t + 1) * (t + 2) / 2) % 64;
  9530. var newX = y % 5;
  9531. var newY = (2 * x + 3 * y) % 5;
  9532. x = newX;
  9533. y = newY;
  9534. }
  9535. // Compute pi index constants
  9536. for (var x = 0; x < 5; x++) {
  9537. for (var y = 0; y < 5; y++) {
  9538. PI_INDEXES[x + 5 * y] = y + ((2 * x + 3 * y) % 5) * 5;
  9539. }
  9540. }
  9541. // Compute round constants
  9542. var LFSR = 0x01;
  9543. for (var i = 0; i < 24; i++) {
  9544. var roundConstantMsw = 0;
  9545. var roundConstantLsw = 0;
  9546. for (var j = 0; j < 7; j++) {
  9547. if (LFSR & 0x01) {
  9548. var bitPosition = (1 << j) - 1;
  9549. if (bitPosition < 32) {
  9550. roundConstantLsw ^= 1 << bitPosition;
  9551. } else /* if (bitPosition >= 32) */ {
  9552. roundConstantMsw ^= 1 << (bitPosition - 32);
  9553. }
  9554. }
  9555. // Compute next LFSR
  9556. if (LFSR & 0x80) {
  9557. // Primitive polynomial over GF(2): x^8 + x^6 + x^5 + x^4 + 1
  9558. LFSR = (LFSR << 1) ^ 0x71;
  9559. } else {
  9560. LFSR <<= 1;
  9561. }
  9562. }
  9563. ROUND_CONSTANTS[i] = X64Word.create(roundConstantMsw, roundConstantLsw);
  9564. }
  9565. }());
  9566. // Reusable objects for temporary values
  9567. var T = [];
  9568. (function () {
  9569. for (var i = 0; i < 25; i++) {
  9570. T[i] = X64Word.create();
  9571. }
  9572. }());
  9573. /**
  9574. * SHA-3 hash algorithm.
  9575. */
  9576. var SHA3 = C_algo.SHA3 = Hasher.extend({
  9577. /**
  9578. * Configuration options.
  9579. *
  9580. * @property {number} outputLength
  9581. * The desired number of bits in the output hash.
  9582. * Only values permitted are: 224, 256, 384, 512.
  9583. * Default: 512
  9584. */
  9585. cfg: Hasher.cfg.extend({
  9586. outputLength: 512
  9587. }),
  9588. _doReset: function () {
  9589. var state = this._state = []
  9590. for (var i = 0; i < 25; i++) {
  9591. state[i] = new X64Word.init();
  9592. }
  9593. this.blockSize = (1600 - 2 * this.cfg.outputLength) / 32;
  9594. },
  9595. _doProcessBlock: function (M, offset) {
  9596. // Shortcuts
  9597. var state = this._state;
  9598. var nBlockSizeLanes = this.blockSize / 2;
  9599. // Absorb
  9600. for (var i = 0; i < nBlockSizeLanes; i++) {
  9601. // Shortcuts
  9602. var M2i = M[offset + 2 * i];
  9603. var M2i1 = M[offset + 2 * i + 1];
  9604. // Swap endian
  9605. M2i = (
  9606. (((M2i << 8) | (M2i >>> 24)) & 0x00ff00ff) |
  9607. (((M2i << 24) | (M2i >>> 8)) & 0xff00ff00)
  9608. );
  9609. M2i1 = (
  9610. (((M2i1 << 8) | (M2i1 >>> 24)) & 0x00ff00ff) |
  9611. (((M2i1 << 24) | (M2i1 >>> 8)) & 0xff00ff00)
  9612. );
  9613. // Absorb message into state
  9614. var lane = state[i];
  9615. lane.high ^= M2i1;
  9616. lane.low ^= M2i;
  9617. }
  9618. // Rounds
  9619. for (var round = 0; round < 24; round++) {
  9620. // Theta
  9621. for (var x = 0; x < 5; x++) {
  9622. // Mix column lanes
  9623. var tMsw = 0, tLsw = 0;
  9624. for (var y = 0; y < 5; y++) {
  9625. var lane = state[x + 5 * y];
  9626. tMsw ^= lane.high;
  9627. tLsw ^= lane.low;
  9628. }
  9629. // Temporary values
  9630. var Tx = T[x];
  9631. Tx.high = tMsw;
  9632. Tx.low = tLsw;
  9633. }
  9634. for (var x = 0; x < 5; x++) {
  9635. // Shortcuts
  9636. var Tx4 = T[(x + 4) % 5];
  9637. var Tx1 = T[(x + 1) % 5];
  9638. var Tx1Msw = Tx1.high;
  9639. var Tx1Lsw = Tx1.low;
  9640. // Mix surrounding columns
  9641. var tMsw = Tx4.high ^ ((Tx1Msw << 1) | (Tx1Lsw >>> 31));
  9642. var tLsw = Tx4.low ^ ((Tx1Lsw << 1) | (Tx1Msw >>> 31));
  9643. for (var y = 0; y < 5; y++) {
  9644. var lane = state[x + 5 * y];
  9645. lane.high ^= tMsw;
  9646. lane.low ^= tLsw;
  9647. }
  9648. }
  9649. // Rho Pi
  9650. for (var laneIndex = 1; laneIndex < 25; laneIndex++) {
  9651. // Shortcuts
  9652. var lane = state[laneIndex];
  9653. var laneMsw = lane.high;
  9654. var laneLsw = lane.low;
  9655. var rhoOffset = RHO_OFFSETS[laneIndex];
  9656. // Rotate lanes
  9657. if (rhoOffset < 32) {
  9658. var tMsw = (laneMsw << rhoOffset) | (laneLsw >>> (32 - rhoOffset));
  9659. var tLsw = (laneLsw << rhoOffset) | (laneMsw >>> (32 - rhoOffset));
  9660. } else /* if (rhoOffset >= 32) */ {
  9661. var tMsw = (laneLsw << (rhoOffset - 32)) | (laneMsw >>> (64 - rhoOffset));
  9662. var tLsw = (laneMsw << (rhoOffset - 32)) | (laneLsw >>> (64 - rhoOffset));
  9663. }
  9664. // Transpose lanes
  9665. var TPiLane = T[PI_INDEXES[laneIndex]];
  9666. TPiLane.high = tMsw;
  9667. TPiLane.low = tLsw;
  9668. }
  9669. // Rho pi at x = y = 0
  9670. var T0 = T[0];
  9671. var state0 = state[0];
  9672. T0.high = state0.high;
  9673. T0.low = state0.low;
  9674. // Chi
  9675. for (var x = 0; x < 5; x++) {
  9676. for (var y = 0; y < 5; y++) {
  9677. // Shortcuts
  9678. var laneIndex = x + 5 * y;
  9679. var lane = state[laneIndex];
  9680. var TLane = T[laneIndex];
  9681. var Tx1Lane = T[((x + 1) % 5) + 5 * y];
  9682. var Tx2Lane = T[((x + 2) % 5) + 5 * y];
  9683. // Mix rows
  9684. lane.high = TLane.high ^ (~Tx1Lane.high & Tx2Lane.high);
  9685. lane.low = TLane.low ^ (~Tx1Lane.low & Tx2Lane.low);
  9686. }
  9687. }
  9688. // Iota
  9689. var lane = state[0];
  9690. var roundConstant = ROUND_CONSTANTS[round];
  9691. lane.high ^= roundConstant.high;
  9692. lane.low ^= roundConstant.low;;
  9693. }
  9694. },
  9695. _doFinalize: function () {
  9696. // Shortcuts
  9697. var data = this._data;
  9698. var dataWords = data.words;
  9699. var nBitsTotal = this._nDataBytes * 8;
  9700. var nBitsLeft = data.sigBytes * 8;
  9701. var blockSizeBits = this.blockSize * 32;
  9702. // Add padding
  9703. dataWords[nBitsLeft >>> 5] |= 0x1 << (24 - nBitsLeft % 32);
  9704. dataWords[((Math.ceil((nBitsLeft + 1) / blockSizeBits) * blockSizeBits) >>> 5) - 1] |= 0x80;
  9705. data.sigBytes = dataWords.length * 4;
  9706. // Hash final blocks
  9707. this._process();
  9708. // Shortcuts
  9709. var state = this._state;
  9710. var outputLengthBytes = this.cfg.outputLength / 8;
  9711. var outputLengthLanes = outputLengthBytes / 8;
  9712. // Squeeze
  9713. var hashWords = [];
  9714. for (var i = 0; i < outputLengthLanes; i++) {
  9715. // Shortcuts
  9716. var lane = state[i];
  9717. var laneMsw = lane.high;
  9718. var laneLsw = lane.low;
  9719. // Swap endian
  9720. laneMsw = (
  9721. (((laneMsw << 8) | (laneMsw >>> 24)) & 0x00ff00ff) |
  9722. (((laneMsw << 24) | (laneMsw >>> 8)) & 0xff00ff00)
  9723. );
  9724. laneLsw = (
  9725. (((laneLsw << 8) | (laneLsw >>> 24)) & 0x00ff00ff) |
  9726. (((laneLsw << 24) | (laneLsw >>> 8)) & 0xff00ff00)
  9727. );
  9728. // Squeeze state to retrieve hash
  9729. hashWords.push(laneLsw);
  9730. hashWords.push(laneMsw);
  9731. }
  9732. // Return final computed hash
  9733. return new WordArray.init(hashWords, outputLengthBytes);
  9734. },
  9735. clone: function () {
  9736. var clone = Hasher.clone.call(this);
  9737. var state = clone._state = this._state.slice(0);
  9738. for (var i = 0; i < 25; i++) {
  9739. state[i] = state[i].clone();
  9740. }
  9741. return clone;
  9742. }
  9743. });
  9744. /**
  9745. * Shortcut function to the hasher's object interface.
  9746. *
  9747. * @param {WordArray|string} message The message to hash.
  9748. *
  9749. * @return {WordArray} The hash.
  9750. *
  9751. * @static
  9752. *
  9753. * @example
  9754. *
  9755. * var hash = CryptoJS.SHA3('message');
  9756. * var hash = CryptoJS.SHA3(wordArray);
  9757. */
  9758. C.SHA3 = Hasher._createHelper(SHA3);
  9759. /**
  9760. * Shortcut function to the HMAC's object interface.
  9761. *
  9762. * @param {WordArray|string} message The message to hash.
  9763. * @param {WordArray|string} key The secret key.
  9764. *
  9765. * @return {WordArray} The HMAC.
  9766. *
  9767. * @static
  9768. *
  9769. * @example
  9770. *
  9771. * var hmac = CryptoJS.HmacSHA3(message, key);
  9772. */
  9773. C.HmacSHA3 = Hasher._createHmacHelper(SHA3);
  9774. }(Math));
  9775. return CryptoJS.SHA3;
  9776. }));
  9777. },{"./core":51,"./x64-core":82}],79:[function(require,module,exports){
  9778. ;(function (root, factory, undef) {
  9779. if (typeof exports === "object") {
  9780. // CommonJS
  9781. module.exports = exports = factory(require("./core"), require("./x64-core"), require("./sha512"));
  9782. }
  9783. else if (typeof define === "function" && define.amd) {
  9784. // AMD
  9785. define(["./core", "./x64-core", "./sha512"], factory);
  9786. }
  9787. else {
  9788. // Global (browser)
  9789. factory(root.CryptoJS);
  9790. }
  9791. }(this, function (CryptoJS) {
  9792. (function () {
  9793. // Shortcuts
  9794. var C = CryptoJS;
  9795. var C_x64 = C.x64;
  9796. var X64Word = C_x64.Word;
  9797. var X64WordArray = C_x64.WordArray;
  9798. var C_algo = C.algo;
  9799. var SHA512 = C_algo.SHA512;
  9800. /**
  9801. * SHA-384 hash algorithm.
  9802. */
  9803. var SHA384 = C_algo.SHA384 = SHA512.extend({
  9804. _doReset: function () {
  9805. this._hash = new X64WordArray.init([
  9806. new X64Word.init(0xcbbb9d5d, 0xc1059ed8), new X64Word.init(0x629a292a, 0x367cd507),
  9807. new X64Word.init(0x9159015a, 0x3070dd17), new X64Word.init(0x152fecd8, 0xf70e5939),
  9808. new X64Word.init(0x67332667, 0xffc00b31), new X64Word.init(0x8eb44a87, 0x68581511),
  9809. new X64Word.init(0xdb0c2e0d, 0x64f98fa7), new X64Word.init(0x47b5481d, 0xbefa4fa4)
  9810. ]);
  9811. },
  9812. _doFinalize: function () {
  9813. var hash = SHA512._doFinalize.call(this);
  9814. hash.sigBytes -= 16;
  9815. return hash;
  9816. }
  9817. });
  9818. /**
  9819. * Shortcut function to the hasher's object interface.
  9820. *
  9821. * @param {WordArray|string} message The message to hash.
  9822. *
  9823. * @return {WordArray} The hash.
  9824. *
  9825. * @static
  9826. *
  9827. * @example
  9828. *
  9829. * var hash = CryptoJS.SHA384('message');
  9830. * var hash = CryptoJS.SHA384(wordArray);
  9831. */
  9832. C.SHA384 = SHA512._createHelper(SHA384);
  9833. /**
  9834. * Shortcut function to the HMAC's object interface.
  9835. *
  9836. * @param {WordArray|string} message The message to hash.
  9837. * @param {WordArray|string} key The secret key.
  9838. *
  9839. * @return {WordArray} The HMAC.
  9840. *
  9841. * @static
  9842. *
  9843. * @example
  9844. *
  9845. * var hmac = CryptoJS.HmacSHA384(message, key);
  9846. */
  9847. C.HmacSHA384 = SHA512._createHmacHelper(SHA384);
  9848. }());
  9849. return CryptoJS.SHA384;
  9850. }));
  9851. },{"./core":51,"./sha512":80,"./x64-core":82}],80:[function(require,module,exports){
  9852. ;(function (root, factory, undef) {
  9853. if (typeof exports === "object") {
  9854. // CommonJS
  9855. module.exports = exports = factory(require("./core"), require("./x64-core"));
  9856. }
  9857. else if (typeof define === "function" && define.amd) {
  9858. // AMD
  9859. define(["./core", "./x64-core"], factory);
  9860. }
  9861. else {
  9862. // Global (browser)
  9863. factory(root.CryptoJS);
  9864. }
  9865. }(this, function (CryptoJS) {
  9866. (function () {
  9867. // Shortcuts
  9868. var C = CryptoJS;
  9869. var C_lib = C.lib;
  9870. var Hasher = C_lib.Hasher;
  9871. var C_x64 = C.x64;
  9872. var X64Word = C_x64.Word;
  9873. var X64WordArray = C_x64.WordArray;
  9874. var C_algo = C.algo;
  9875. function X64Word_create() {
  9876. return X64Word.create.apply(X64Word, arguments);
  9877. }
  9878. // Constants
  9879. var K = [
  9880. X64Word_create(0x428a2f98, 0xd728ae22), X64Word_create(0x71374491, 0x23ef65cd),
  9881. X64Word_create(0xb5c0fbcf, 0xec4d3b2f), X64Word_create(0xe9b5dba5, 0x8189dbbc),
  9882. X64Word_create(0x3956c25b, 0xf348b538), X64Word_create(0x59f111f1, 0xb605d019),
  9883. X64Word_create(0x923f82a4, 0xaf194f9b), X64Word_create(0xab1c5ed5, 0xda6d8118),
  9884. X64Word_create(0xd807aa98, 0xa3030242), X64Word_create(0x12835b01, 0x45706fbe),
  9885. X64Word_create(0x243185be, 0x4ee4b28c), X64Word_create(0x550c7dc3, 0xd5ffb4e2),
  9886. X64Word_create(0x72be5d74, 0xf27b896f), X64Word_create(0x80deb1fe, 0x3b1696b1),
  9887. X64Word_create(0x9bdc06a7, 0x25c71235), X64Word_create(0xc19bf174, 0xcf692694),
  9888. X64Word_create(0xe49b69c1, 0x9ef14ad2), X64Word_create(0xefbe4786, 0x384f25e3),
  9889. X64Word_create(0x0fc19dc6, 0x8b8cd5b5), X64Word_create(0x240ca1cc, 0x77ac9c65),
  9890. X64Word_create(0x2de92c6f, 0x592b0275), X64Word_create(0x4a7484aa, 0x6ea6e483),
  9891. X64Word_create(0x5cb0a9dc, 0xbd41fbd4), X64Word_create(0x76f988da, 0x831153b5),
  9892. X64Word_create(0x983e5152, 0xee66dfab), X64Word_create(0xa831c66d, 0x2db43210),
  9893. X64Word_create(0xb00327c8, 0x98fb213f), X64Word_create(0xbf597fc7, 0xbeef0ee4),
  9894. X64Word_create(0xc6e00bf3, 0x3da88fc2), X64Word_create(0xd5a79147, 0x930aa725),
  9895. X64Word_create(0x06ca6351, 0xe003826f), X64Word_create(0x14292967, 0x0a0e6e70),
  9896. X64Word_create(0x27b70a85, 0x46d22ffc), X64Word_create(0x2e1b2138, 0x5c26c926),
  9897. X64Word_create(0x4d2c6dfc, 0x5ac42aed), X64Word_create(0x53380d13, 0x9d95b3df),
  9898. X64Word_create(0x650a7354, 0x8baf63de), X64Word_create(0x766a0abb, 0x3c77b2a8),
  9899. X64Word_create(0x81c2c92e, 0x47edaee6), X64Word_create(0x92722c85, 0x1482353b),
  9900. X64Word_create(0xa2bfe8a1, 0x4cf10364), X64Word_create(0xa81a664b, 0xbc423001),
  9901. X64Word_create(0xc24b8b70, 0xd0f89791), X64Word_create(0xc76c51a3, 0x0654be30),
  9902. X64Word_create(0xd192e819, 0xd6ef5218), X64Word_create(0xd6990624, 0x5565a910),
  9903. X64Word_create(0xf40e3585, 0x5771202a), X64Word_create(0x106aa070, 0x32bbd1b8),
  9904. X64Word_create(0x19a4c116, 0xb8d2d0c8), X64Word_create(0x1e376c08, 0x5141ab53),
  9905. X64Word_create(0x2748774c, 0xdf8eeb99), X64Word_create(0x34b0bcb5, 0xe19b48a8),
  9906. X64Word_create(0x391c0cb3, 0xc5c95a63), X64Word_create(0x4ed8aa4a, 0xe3418acb),
  9907. X64Word_create(0x5b9cca4f, 0x7763e373), X64Word_create(0x682e6ff3, 0xd6b2b8a3),
  9908. X64Word_create(0x748f82ee, 0x5defb2fc), X64Word_create(0x78a5636f, 0x43172f60),
  9909. X64Word_create(0x84c87814, 0xa1f0ab72), X64Word_create(0x8cc70208, 0x1a6439ec),
  9910. X64Word_create(0x90befffa, 0x23631e28), X64Word_create(0xa4506ceb, 0xde82bde9),
  9911. X64Word_create(0xbef9a3f7, 0xb2c67915), X64Word_create(0xc67178f2, 0xe372532b),
  9912. X64Word_create(0xca273ece, 0xea26619c), X64Word_create(0xd186b8c7, 0x21c0c207),
  9913. X64Word_create(0xeada7dd6, 0xcde0eb1e), X64Word_create(0xf57d4f7f, 0xee6ed178),
  9914. X64Word_create(0x06f067aa, 0x72176fba), X64Word_create(0x0a637dc5, 0xa2c898a6),
  9915. X64Word_create(0x113f9804, 0xbef90dae), X64Word_create(0x1b710b35, 0x131c471b),
  9916. X64Word_create(0x28db77f5, 0x23047d84), X64Word_create(0x32caab7b, 0x40c72493),
  9917. X64Word_create(0x3c9ebe0a, 0x15c9bebc), X64Word_create(0x431d67c4, 0x9c100d4c),
  9918. X64Word_create(0x4cc5d4be, 0xcb3e42b6), X64Word_create(0x597f299c, 0xfc657e2a),
  9919. X64Word_create(0x5fcb6fab, 0x3ad6faec), X64Word_create(0x6c44198c, 0x4a475817)
  9920. ];
  9921. // Reusable objects
  9922. var W = [];
  9923. (function () {
  9924. for (var i = 0; i < 80; i++) {
  9925. W[i] = X64Word_create();
  9926. }
  9927. }());
  9928. /**
  9929. * SHA-512 hash algorithm.
  9930. */
  9931. var SHA512 = C_algo.SHA512 = Hasher.extend({
  9932. _doReset: function () {
  9933. this._hash = new X64WordArray.init([
  9934. new X64Word.init(0x6a09e667, 0xf3bcc908), new X64Word.init(0xbb67ae85, 0x84caa73b),
  9935. new X64Word.init(0x3c6ef372, 0xfe94f82b), new X64Word.init(0xa54ff53a, 0x5f1d36f1),
  9936. new X64Word.init(0x510e527f, 0xade682d1), new X64Word.init(0x9b05688c, 0x2b3e6c1f),
  9937. new X64Word.init(0x1f83d9ab, 0xfb41bd6b), new X64Word.init(0x5be0cd19, 0x137e2179)
  9938. ]);
  9939. },
  9940. _doProcessBlock: function (M, offset) {
  9941. // Shortcuts
  9942. var H = this._hash.words;
  9943. var H0 = H[0];
  9944. var H1 = H[1];
  9945. var H2 = H[2];
  9946. var H3 = H[3];
  9947. var H4 = H[4];
  9948. var H5 = H[5];
  9949. var H6 = H[6];
  9950. var H7 = H[7];
  9951. var H0h = H0.high;
  9952. var H0l = H0.low;
  9953. var H1h = H1.high;
  9954. var H1l = H1.low;
  9955. var H2h = H2.high;
  9956. var H2l = H2.low;
  9957. var H3h = H3.high;
  9958. var H3l = H3.low;
  9959. var H4h = H4.high;
  9960. var H4l = H4.low;
  9961. var H5h = H5.high;
  9962. var H5l = H5.low;
  9963. var H6h = H6.high;
  9964. var H6l = H6.low;
  9965. var H7h = H7.high;
  9966. var H7l = H7.low;
  9967. // Working variables
  9968. var ah = H0h;
  9969. var al = H0l;
  9970. var bh = H1h;
  9971. var bl = H1l;
  9972. var ch = H2h;
  9973. var cl = H2l;
  9974. var dh = H3h;
  9975. var dl = H3l;
  9976. var eh = H4h;
  9977. var el = H4l;
  9978. var fh = H5h;
  9979. var fl = H5l;
  9980. var gh = H6h;
  9981. var gl = H6l;
  9982. var hh = H7h;
  9983. var hl = H7l;
  9984. // Rounds
  9985. for (var i = 0; i < 80; i++) {
  9986. // Shortcut
  9987. var Wi = W[i];
  9988. // Extend message
  9989. if (i < 16) {
  9990. var Wih = Wi.high = M[offset + i * 2] | 0;
  9991. var Wil = Wi.low = M[offset + i * 2 + 1] | 0;
  9992. } else {
  9993. // Gamma0
  9994. var gamma0x = W[i - 15];
  9995. var gamma0xh = gamma0x.high;
  9996. var gamma0xl = gamma0x.low;
  9997. var gamma0h = ((gamma0xh >>> 1) | (gamma0xl << 31)) ^ ((gamma0xh >>> 8) | (gamma0xl << 24)) ^ (gamma0xh >>> 7);
  9998. var gamma0l = ((gamma0xl >>> 1) | (gamma0xh << 31)) ^ ((gamma0xl >>> 8) | (gamma0xh << 24)) ^ ((gamma0xl >>> 7) | (gamma0xh << 25));
  9999. // Gamma1
  10000. var gamma1x = W[i - 2];
  10001. var gamma1xh = gamma1x.high;
  10002. var gamma1xl = gamma1x.low;
  10003. var gamma1h = ((gamma1xh >>> 19) | (gamma1xl << 13)) ^ ((gamma1xh << 3) | (gamma1xl >>> 29)) ^ (gamma1xh >>> 6);
  10004. var gamma1l = ((gamma1xl >>> 19) | (gamma1xh << 13)) ^ ((gamma1xl << 3) | (gamma1xh >>> 29)) ^ ((gamma1xl >>> 6) | (gamma1xh << 26));
  10005. // W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16]
  10006. var Wi7 = W[i - 7];
  10007. var Wi7h = Wi7.high;
  10008. var Wi7l = Wi7.low;
  10009. var Wi16 = W[i - 16];
  10010. var Wi16h = Wi16.high;
  10011. var Wi16l = Wi16.low;
  10012. var Wil = gamma0l + Wi7l;
  10013. var Wih = gamma0h + Wi7h + ((Wil >>> 0) < (gamma0l >>> 0) ? 1 : 0);
  10014. var Wil = Wil + gamma1l;
  10015. var Wih = Wih + gamma1h + ((Wil >>> 0) < (gamma1l >>> 0) ? 1 : 0);
  10016. var Wil = Wil + Wi16l;
  10017. var Wih = Wih + Wi16h + ((Wil >>> 0) < (Wi16l >>> 0) ? 1 : 0);
  10018. Wi.high = Wih;
  10019. Wi.low = Wil;
  10020. }
  10021. var chh = (eh & fh) ^ (~eh & gh);
  10022. var chl = (el & fl) ^ (~el & gl);
  10023. var majh = (ah & bh) ^ (ah & ch) ^ (bh & ch);
  10024. var majl = (al & bl) ^ (al & cl) ^ (bl & cl);
  10025. var sigma0h = ((ah >>> 28) | (al << 4)) ^ ((ah << 30) | (al >>> 2)) ^ ((ah << 25) | (al >>> 7));
  10026. var sigma0l = ((al >>> 28) | (ah << 4)) ^ ((al << 30) | (ah >>> 2)) ^ ((al << 25) | (ah >>> 7));
  10027. var sigma1h = ((eh >>> 14) | (el << 18)) ^ ((eh >>> 18) | (el << 14)) ^ ((eh << 23) | (el >>> 9));
  10028. var sigma1l = ((el >>> 14) | (eh << 18)) ^ ((el >>> 18) | (eh << 14)) ^ ((el << 23) | (eh >>> 9));
  10029. // t1 = h + sigma1 + ch + K[i] + W[i]
  10030. var Ki = K[i];
  10031. var Kih = Ki.high;
  10032. var Kil = Ki.low;
  10033. var t1l = hl + sigma1l;
  10034. var t1h = hh + sigma1h + ((t1l >>> 0) < (hl >>> 0) ? 1 : 0);
  10035. var t1l = t1l + chl;
  10036. var t1h = t1h + chh + ((t1l >>> 0) < (chl >>> 0) ? 1 : 0);
  10037. var t1l = t1l + Kil;
  10038. var t1h = t1h + Kih + ((t1l >>> 0) < (Kil >>> 0) ? 1 : 0);
  10039. var t1l = t1l + Wil;
  10040. var t1h = t1h + Wih + ((t1l >>> 0) < (Wil >>> 0) ? 1 : 0);
  10041. // t2 = sigma0 + maj
  10042. var t2l = sigma0l + majl;
  10043. var t2h = sigma0h + majh + ((t2l >>> 0) < (sigma0l >>> 0) ? 1 : 0);
  10044. // Update working variables
  10045. hh = gh;
  10046. hl = gl;
  10047. gh = fh;
  10048. gl = fl;
  10049. fh = eh;
  10050. fl = el;
  10051. el = (dl + t1l) | 0;
  10052. eh = (dh + t1h + ((el >>> 0) < (dl >>> 0) ? 1 : 0)) | 0;
  10053. dh = ch;
  10054. dl = cl;
  10055. ch = bh;
  10056. cl = bl;
  10057. bh = ah;
  10058. bl = al;
  10059. al = (t1l + t2l) | 0;
  10060. ah = (t1h + t2h + ((al >>> 0) < (t1l >>> 0) ? 1 : 0)) | 0;
  10061. }
  10062. // Intermediate hash value
  10063. H0l = H0.low = (H0l + al);
  10064. H0.high = (H0h + ah + ((H0l >>> 0) < (al >>> 0) ? 1 : 0));
  10065. H1l = H1.low = (H1l + bl);
  10066. H1.high = (H1h + bh + ((H1l >>> 0) < (bl >>> 0) ? 1 : 0));
  10067. H2l = H2.low = (H2l + cl);
  10068. H2.high = (H2h + ch + ((H2l >>> 0) < (cl >>> 0) ? 1 : 0));
  10069. H3l = H3.low = (H3l + dl);
  10070. H3.high = (H3h + dh + ((H3l >>> 0) < (dl >>> 0) ? 1 : 0));
  10071. H4l = H4.low = (H4l + el);
  10072. H4.high = (H4h + eh + ((H4l >>> 0) < (el >>> 0) ? 1 : 0));
  10073. H5l = H5.low = (H5l + fl);
  10074. H5.high = (H5h + fh + ((H5l >>> 0) < (fl >>> 0) ? 1 : 0));
  10075. H6l = H6.low = (H6l + gl);
  10076. H6.high = (H6h + gh + ((H6l >>> 0) < (gl >>> 0) ? 1 : 0));
  10077. H7l = H7.low = (H7l + hl);
  10078. H7.high = (H7h + hh + ((H7l >>> 0) < (hl >>> 0) ? 1 : 0));
  10079. },
  10080. _doFinalize: function () {
  10081. // Shortcuts
  10082. var data = this._data;
  10083. var dataWords = data.words;
  10084. var nBitsTotal = this._nDataBytes * 8;
  10085. var nBitsLeft = data.sigBytes * 8;
  10086. // Add padding
  10087. dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32);
  10088. dataWords[(((nBitsLeft + 128) >>> 10) << 5) + 30] = Math.floor(nBitsTotal / 0x100000000);
  10089. dataWords[(((nBitsLeft + 128) >>> 10) << 5) + 31] = nBitsTotal;
  10090. data.sigBytes = dataWords.length * 4;
  10091. // Hash final blocks
  10092. this._process();
  10093. // Convert hash to 32-bit word array before returning
  10094. var hash = this._hash.toX32();
  10095. // Return final computed hash
  10096. return hash;
  10097. },
  10098. clone: function () {
  10099. var clone = Hasher.clone.call(this);
  10100. clone._hash = this._hash.clone();
  10101. return clone;
  10102. },
  10103. blockSize: 1024/32
  10104. });
  10105. /**
  10106. * Shortcut function to the hasher's object interface.
  10107. *
  10108. * @param {WordArray|string} message The message to hash.
  10109. *
  10110. * @return {WordArray} The hash.
  10111. *
  10112. * @static
  10113. *
  10114. * @example
  10115. *
  10116. * var hash = CryptoJS.SHA512('message');
  10117. * var hash = CryptoJS.SHA512(wordArray);
  10118. */
  10119. C.SHA512 = Hasher._createHelper(SHA512);
  10120. /**
  10121. * Shortcut function to the HMAC's object interface.
  10122. *
  10123. * @param {WordArray|string} message The message to hash.
  10124. * @param {WordArray|string} key The secret key.
  10125. *
  10126. * @return {WordArray} The HMAC.
  10127. *
  10128. * @static
  10129. *
  10130. * @example
  10131. *
  10132. * var hmac = CryptoJS.HmacSHA512(message, key);
  10133. */
  10134. C.HmacSHA512 = Hasher._createHmacHelper(SHA512);
  10135. }());
  10136. return CryptoJS.SHA512;
  10137. }));
  10138. },{"./core":51,"./x64-core":82}],81:[function(require,module,exports){
  10139. ;(function (root, factory, undef) {
  10140. if (typeof exports === "object") {
  10141. // CommonJS
  10142. module.exports = exports = factory(require("./core"), require("./enc-base64"), require("./md5"), require("./evpkdf"), require("./cipher-core"));
  10143. }
  10144. else if (typeof define === "function" && define.amd) {
  10145. // AMD
  10146. define(["./core", "./enc-base64", "./md5", "./evpkdf", "./cipher-core"], factory);
  10147. }
  10148. else {
  10149. // Global (browser)
  10150. factory(root.CryptoJS);
  10151. }
  10152. }(this, function (CryptoJS) {
  10153. (function () {
  10154. // Shortcuts
  10155. var C = CryptoJS;
  10156. var C_lib = C.lib;
  10157. var WordArray = C_lib.WordArray;
  10158. var BlockCipher = C_lib.BlockCipher;
  10159. var C_algo = C.algo;
  10160. // Permuted Choice 1 constants
  10161. var PC1 = [
  10162. 57, 49, 41, 33, 25, 17, 9, 1,
  10163. 58, 50, 42, 34, 26, 18, 10, 2,
  10164. 59, 51, 43, 35, 27, 19, 11, 3,
  10165. 60, 52, 44, 36, 63, 55, 47, 39,
  10166. 31, 23, 15, 7, 62, 54, 46, 38,
  10167. 30, 22, 14, 6, 61, 53, 45, 37,
  10168. 29, 21, 13, 5, 28, 20, 12, 4
  10169. ];
  10170. // Permuted Choice 2 constants
  10171. var PC2 = [
  10172. 14, 17, 11, 24, 1, 5,
  10173. 3, 28, 15, 6, 21, 10,
  10174. 23, 19, 12, 4, 26, 8,
  10175. 16, 7, 27, 20, 13, 2,
  10176. 41, 52, 31, 37, 47, 55,
  10177. 30, 40, 51, 45, 33, 48,
  10178. 44, 49, 39, 56, 34, 53,
  10179. 46, 42, 50, 36, 29, 32
  10180. ];
  10181. // Cumulative bit shift constants
  10182. var BIT_SHIFTS = [1, 2, 4, 6, 8, 10, 12, 14, 15, 17, 19, 21, 23, 25, 27, 28];
  10183. // SBOXes and round permutation constants
  10184. var SBOX_P = [
  10185. {
  10186. 0x0: 0x808200,
  10187. 0x10000000: 0x8000,
  10188. 0x20000000: 0x808002,
  10189. 0x30000000: 0x2,
  10190. 0x40000000: 0x200,
  10191. 0x50000000: 0x808202,
  10192. 0x60000000: 0x800202,
  10193. 0x70000000: 0x800000,
  10194. 0x80000000: 0x202,
  10195. 0x90000000: 0x800200,
  10196. 0xa0000000: 0x8200,
  10197. 0xb0000000: 0x808000,
  10198. 0xc0000000: 0x8002,
  10199. 0xd0000000: 0x800002,
  10200. 0xe0000000: 0x0,
  10201. 0xf0000000: 0x8202,
  10202. 0x8000000: 0x0,
  10203. 0x18000000: 0x808202,
  10204. 0x28000000: 0x8202,
  10205. 0x38000000: 0x8000,
  10206. 0x48000000: 0x808200,
  10207. 0x58000000: 0x200,
  10208. 0x68000000: 0x808002,
  10209. 0x78000000: 0x2,
  10210. 0x88000000: 0x800200,
  10211. 0x98000000: 0x8200,
  10212. 0xa8000000: 0x808000,
  10213. 0xb8000000: 0x800202,
  10214. 0xc8000000: 0x800002,
  10215. 0xd8000000: 0x8002,
  10216. 0xe8000000: 0x202,
  10217. 0xf8000000: 0x800000,
  10218. 0x1: 0x8000,
  10219. 0x10000001: 0x2,
  10220. 0x20000001: 0x808200,
  10221. 0x30000001: 0x800000,
  10222. 0x40000001: 0x808002,
  10223. 0x50000001: 0x8200,
  10224. 0x60000001: 0x200,
  10225. 0x70000001: 0x800202,
  10226. 0x80000001: 0x808202,
  10227. 0x90000001: 0x808000,
  10228. 0xa0000001: 0x800002,
  10229. 0xb0000001: 0x8202,
  10230. 0xc0000001: 0x202,
  10231. 0xd0000001: 0x800200,
  10232. 0xe0000001: 0x8002,
  10233. 0xf0000001: 0x0,
  10234. 0x8000001: 0x808202,
  10235. 0x18000001: 0x808000,
  10236. 0x28000001: 0x800000,
  10237. 0x38000001: 0x200,
  10238. 0x48000001: 0x8000,
  10239. 0x58000001: 0x800002,
  10240. 0x68000001: 0x2,
  10241. 0x78000001: 0x8202,
  10242. 0x88000001: 0x8002,
  10243. 0x98000001: 0x800202,
  10244. 0xa8000001: 0x202,
  10245. 0xb8000001: 0x808200,
  10246. 0xc8000001: 0x800200,
  10247. 0xd8000001: 0x0,
  10248. 0xe8000001: 0x8200,
  10249. 0xf8000001: 0x808002
  10250. },
  10251. {
  10252. 0x0: 0x40084010,
  10253. 0x1000000: 0x4000,
  10254. 0x2000000: 0x80000,
  10255. 0x3000000: 0x40080010,
  10256. 0x4000000: 0x40000010,
  10257. 0x5000000: 0x40084000,
  10258. 0x6000000: 0x40004000,
  10259. 0x7000000: 0x10,
  10260. 0x8000000: 0x84000,
  10261. 0x9000000: 0x40004010,
  10262. 0xa000000: 0x40000000,
  10263. 0xb000000: 0x84010,
  10264. 0xc000000: 0x80010,
  10265. 0xd000000: 0x0,
  10266. 0xe000000: 0x4010,
  10267. 0xf000000: 0x40080000,
  10268. 0x800000: 0x40004000,
  10269. 0x1800000: 0x84010,
  10270. 0x2800000: 0x10,
  10271. 0x3800000: 0x40004010,
  10272. 0x4800000: 0x40084010,
  10273. 0x5800000: 0x40000000,
  10274. 0x6800000: 0x80000,
  10275. 0x7800000: 0x40080010,
  10276. 0x8800000: 0x80010,
  10277. 0x9800000: 0x0,
  10278. 0xa800000: 0x4000,
  10279. 0xb800000: 0x40080000,
  10280. 0xc800000: 0x40000010,
  10281. 0xd800000: 0x84000,
  10282. 0xe800000: 0x40084000,
  10283. 0xf800000: 0x4010,
  10284. 0x10000000: 0x0,
  10285. 0x11000000: 0x40080010,
  10286. 0x12000000: 0x40004010,
  10287. 0x13000000: 0x40084000,
  10288. 0x14000000: 0x40080000,
  10289. 0x15000000: 0x10,
  10290. 0x16000000: 0x84010,
  10291. 0x17000000: 0x4000,
  10292. 0x18000000: 0x4010,
  10293. 0x19000000: 0x80000,
  10294. 0x1a000000: 0x80010,
  10295. 0x1b000000: 0x40000010,
  10296. 0x1c000000: 0x84000,
  10297. 0x1d000000: 0x40004000,
  10298. 0x1e000000: 0x40000000,
  10299. 0x1f000000: 0x40084010,
  10300. 0x10800000: 0x84010,
  10301. 0x11800000: 0x80000,
  10302. 0x12800000: 0x40080000,
  10303. 0x13800000: 0x4000,
  10304. 0x14800000: 0x40004000,
  10305. 0x15800000: 0x40084010,
  10306. 0x16800000: 0x10,
  10307. 0x17800000: 0x40000000,
  10308. 0x18800000: 0x40084000,
  10309. 0x19800000: 0x40000010,
  10310. 0x1a800000: 0x40004010,
  10311. 0x1b800000: 0x80010,
  10312. 0x1c800000: 0x0,
  10313. 0x1d800000: 0x4010,
  10314. 0x1e800000: 0x40080010,
  10315. 0x1f800000: 0x84000
  10316. },
  10317. {
  10318. 0x0: 0x104,
  10319. 0x100000: 0x0,
  10320. 0x200000: 0x4000100,
  10321. 0x300000: 0x10104,
  10322. 0x400000: 0x10004,
  10323. 0x500000: 0x4000004,
  10324. 0x600000: 0x4010104,
  10325. 0x700000: 0x4010000,
  10326. 0x800000: 0x4000000,
  10327. 0x900000: 0x4010100,
  10328. 0xa00000: 0x10100,
  10329. 0xb00000: 0x4010004,
  10330. 0xc00000: 0x4000104,
  10331. 0xd00000: 0x10000,
  10332. 0xe00000: 0x4,
  10333. 0xf00000: 0x100,
  10334. 0x80000: 0x4010100,
  10335. 0x180000: 0x4010004,
  10336. 0x280000: 0x0,
  10337. 0x380000: 0x4000100,
  10338. 0x480000: 0x4000004,
  10339. 0x580000: 0x10000,
  10340. 0x680000: 0x10004,
  10341. 0x780000: 0x104,
  10342. 0x880000: 0x4,
  10343. 0x980000: 0x100,
  10344. 0xa80000: 0x4010000,
  10345. 0xb80000: 0x10104,
  10346. 0xc80000: 0x10100,
  10347. 0xd80000: 0x4000104,
  10348. 0xe80000: 0x4010104,
  10349. 0xf80000: 0x4000000,
  10350. 0x1000000: 0x4010100,
  10351. 0x1100000: 0x10004,
  10352. 0x1200000: 0x10000,
  10353. 0x1300000: 0x4000100,
  10354. 0x1400000: 0x100,
  10355. 0x1500000: 0x4010104,
  10356. 0x1600000: 0x4000004,
  10357. 0x1700000: 0x0,
  10358. 0x1800000: 0x4000104,
  10359. 0x1900000: 0x4000000,
  10360. 0x1a00000: 0x4,
  10361. 0x1b00000: 0x10100,
  10362. 0x1c00000: 0x4010000,
  10363. 0x1d00000: 0x104,
  10364. 0x1e00000: 0x10104,
  10365. 0x1f00000: 0x4010004,
  10366. 0x1080000: 0x4000000,
  10367. 0x1180000: 0x104,
  10368. 0x1280000: 0x4010100,
  10369. 0x1380000: 0x0,
  10370. 0x1480000: 0x10004,
  10371. 0x1580000: 0x4000100,
  10372. 0x1680000: 0x100,
  10373. 0x1780000: 0x4010004,
  10374. 0x1880000: 0x10000,
  10375. 0x1980000: 0x4010104,
  10376. 0x1a80000: 0x10104,
  10377. 0x1b80000: 0x4000004,
  10378. 0x1c80000: 0x4000104,
  10379. 0x1d80000: 0x4010000,
  10380. 0x1e80000: 0x4,
  10381. 0x1f80000: 0x10100
  10382. },
  10383. {
  10384. 0x0: 0x80401000,
  10385. 0x10000: 0x80001040,
  10386. 0x20000: 0x401040,
  10387. 0x30000: 0x80400000,
  10388. 0x40000: 0x0,
  10389. 0x50000: 0x401000,
  10390. 0x60000: 0x80000040,
  10391. 0x70000: 0x400040,
  10392. 0x80000: 0x80000000,
  10393. 0x90000: 0x400000,
  10394. 0xa0000: 0x40,
  10395. 0xb0000: 0x80001000,
  10396. 0xc0000: 0x80400040,
  10397. 0xd0000: 0x1040,
  10398. 0xe0000: 0x1000,
  10399. 0xf0000: 0x80401040,
  10400. 0x8000: 0x80001040,
  10401. 0x18000: 0x40,
  10402. 0x28000: 0x80400040,
  10403. 0x38000: 0x80001000,
  10404. 0x48000: 0x401000,
  10405. 0x58000: 0x80401040,
  10406. 0x68000: 0x0,
  10407. 0x78000: 0x80400000,
  10408. 0x88000: 0x1000,
  10409. 0x98000: 0x80401000,
  10410. 0xa8000: 0x400000,
  10411. 0xb8000: 0x1040,
  10412. 0xc8000: 0x80000000,
  10413. 0xd8000: 0x400040,
  10414. 0xe8000: 0x401040,
  10415. 0xf8000: 0x80000040,
  10416. 0x100000: 0x400040,
  10417. 0x110000: 0x401000,
  10418. 0x120000: 0x80000040,
  10419. 0x130000: 0x0,
  10420. 0x140000: 0x1040,
  10421. 0x150000: 0x80400040,
  10422. 0x160000: 0x80401000,
  10423. 0x170000: 0x80001040,
  10424. 0x180000: 0x80401040,
  10425. 0x190000: 0x80000000,
  10426. 0x1a0000: 0x80400000,
  10427. 0x1b0000: 0x401040,
  10428. 0x1c0000: 0x80001000,
  10429. 0x1d0000: 0x400000,
  10430. 0x1e0000: 0x40,
  10431. 0x1f0000: 0x1000,
  10432. 0x108000: 0x80400000,
  10433. 0x118000: 0x80401040,
  10434. 0x128000: 0x0,
  10435. 0x138000: 0x401000,
  10436. 0x148000: 0x400040,
  10437. 0x158000: 0x80000000,
  10438. 0x168000: 0x80001040,
  10439. 0x178000: 0x40,
  10440. 0x188000: 0x80000040,
  10441. 0x198000: 0x1000,
  10442. 0x1a8000: 0x80001000,
  10443. 0x1b8000: 0x80400040,
  10444. 0x1c8000: 0x1040,
  10445. 0x1d8000: 0x80401000,
  10446. 0x1e8000: 0x400000,
  10447. 0x1f8000: 0x401040
  10448. },
  10449. {
  10450. 0x0: 0x80,
  10451. 0x1000: 0x1040000,
  10452. 0x2000: 0x40000,
  10453. 0x3000: 0x20000000,
  10454. 0x4000: 0x20040080,
  10455. 0x5000: 0x1000080,
  10456. 0x6000: 0x21000080,
  10457. 0x7000: 0x40080,
  10458. 0x8000: 0x1000000,
  10459. 0x9000: 0x20040000,
  10460. 0xa000: 0x20000080,
  10461. 0xb000: 0x21040080,
  10462. 0xc000: 0x21040000,
  10463. 0xd000: 0x0,
  10464. 0xe000: 0x1040080,
  10465. 0xf000: 0x21000000,
  10466. 0x800: 0x1040080,
  10467. 0x1800: 0x21000080,
  10468. 0x2800: 0x80,
  10469. 0x3800: 0x1040000,
  10470. 0x4800: 0x40000,
  10471. 0x5800: 0x20040080,
  10472. 0x6800: 0x21040000,
  10473. 0x7800: 0x20000000,
  10474. 0x8800: 0x20040000,
  10475. 0x9800: 0x0,
  10476. 0xa800: 0x21040080,
  10477. 0xb800: 0x1000080,
  10478. 0xc800: 0x20000080,
  10479. 0xd800: 0x21000000,
  10480. 0xe800: 0x1000000,
  10481. 0xf800: 0x40080,
  10482. 0x10000: 0x40000,
  10483. 0x11000: 0x80,
  10484. 0x12000: 0x20000000,
  10485. 0x13000: 0x21000080,
  10486. 0x14000: 0x1000080,
  10487. 0x15000: 0x21040000,
  10488. 0x16000: 0x20040080,
  10489. 0x17000: 0x1000000,
  10490. 0x18000: 0x21040080,
  10491. 0x19000: 0x21000000,
  10492. 0x1a000: 0x1040000,
  10493. 0x1b000: 0x20040000,
  10494. 0x1c000: 0x40080,
  10495. 0x1d000: 0x20000080,
  10496. 0x1e000: 0x0,
  10497. 0x1f000: 0x1040080,
  10498. 0x10800: 0x21000080,
  10499. 0x11800: 0x1000000,
  10500. 0x12800: 0x1040000,
  10501. 0x13800: 0x20040080,
  10502. 0x14800: 0x20000000,
  10503. 0x15800: 0x1040080,
  10504. 0x16800: 0x80,
  10505. 0x17800: 0x21040000,
  10506. 0x18800: 0x40080,
  10507. 0x19800: 0x21040080,
  10508. 0x1a800: 0x0,
  10509. 0x1b800: 0x21000000,
  10510. 0x1c800: 0x1000080,
  10511. 0x1d800: 0x40000,
  10512. 0x1e800: 0x20040000,
  10513. 0x1f800: 0x20000080
  10514. },
  10515. {
  10516. 0x0: 0x10000008,
  10517. 0x100: 0x2000,
  10518. 0x200: 0x10200000,
  10519. 0x300: 0x10202008,
  10520. 0x400: 0x10002000,
  10521. 0x500: 0x200000,
  10522. 0x600: 0x200008,
  10523. 0x700: 0x10000000,
  10524. 0x800: 0x0,
  10525. 0x900: 0x10002008,
  10526. 0xa00: 0x202000,
  10527. 0xb00: 0x8,
  10528. 0xc00: 0x10200008,
  10529. 0xd00: 0x202008,
  10530. 0xe00: 0x2008,
  10531. 0xf00: 0x10202000,
  10532. 0x80: 0x10200000,
  10533. 0x180: 0x10202008,
  10534. 0x280: 0x8,
  10535. 0x380: 0x200000,
  10536. 0x480: 0x202008,
  10537. 0x580: 0x10000008,
  10538. 0x680: 0x10002000,
  10539. 0x780: 0x2008,
  10540. 0x880: 0x200008,
  10541. 0x980: 0x2000,
  10542. 0xa80: 0x10002008,
  10543. 0xb80: 0x10200008,
  10544. 0xc80: 0x0,
  10545. 0xd80: 0x10202000,
  10546. 0xe80: 0x202000,
  10547. 0xf80: 0x10000000,
  10548. 0x1000: 0x10002000,
  10549. 0x1100: 0x10200008,
  10550. 0x1200: 0x10202008,
  10551. 0x1300: 0x2008,
  10552. 0x1400: 0x200000,
  10553. 0x1500: 0x10000000,
  10554. 0x1600: 0x10000008,
  10555. 0x1700: 0x202000,
  10556. 0x1800: 0x202008,
  10557. 0x1900: 0x0,
  10558. 0x1a00: 0x8,
  10559. 0x1b00: 0x10200000,
  10560. 0x1c00: 0x2000,
  10561. 0x1d00: 0x10002008,
  10562. 0x1e00: 0x10202000,
  10563. 0x1f00: 0x200008,
  10564. 0x1080: 0x8,
  10565. 0x1180: 0x202000,
  10566. 0x1280: 0x200000,
  10567. 0x1380: 0x10000008,
  10568. 0x1480: 0x10002000,
  10569. 0x1580: 0x2008,
  10570. 0x1680: 0x10202008,
  10571. 0x1780: 0x10200000,
  10572. 0x1880: 0x10202000,
  10573. 0x1980: 0x10200008,
  10574. 0x1a80: 0x2000,
  10575. 0x1b80: 0x202008,
  10576. 0x1c80: 0x200008,
  10577. 0x1d80: 0x0,
  10578. 0x1e80: 0x10000000,
  10579. 0x1f80: 0x10002008
  10580. },
  10581. {
  10582. 0x0: 0x100000,
  10583. 0x10: 0x2000401,
  10584. 0x20: 0x400,
  10585. 0x30: 0x100401,
  10586. 0x40: 0x2100401,
  10587. 0x50: 0x0,
  10588. 0x60: 0x1,
  10589. 0x70: 0x2100001,
  10590. 0x80: 0x2000400,
  10591. 0x90: 0x100001,
  10592. 0xa0: 0x2000001,
  10593. 0xb0: 0x2100400,
  10594. 0xc0: 0x2100000,
  10595. 0xd0: 0x401,
  10596. 0xe0: 0x100400,
  10597. 0xf0: 0x2000000,
  10598. 0x8: 0x2100001,
  10599. 0x18: 0x0,
  10600. 0x28: 0x2000401,
  10601. 0x38: 0x2100400,
  10602. 0x48: 0x100000,
  10603. 0x58: 0x2000001,
  10604. 0x68: 0x2000000,
  10605. 0x78: 0x401,
  10606. 0x88: 0x100401,
  10607. 0x98: 0x2000400,
  10608. 0xa8: 0x2100000,
  10609. 0xb8: 0x100001,
  10610. 0xc8: 0x400,
  10611. 0xd8: 0x2100401,
  10612. 0xe8: 0x1,
  10613. 0xf8: 0x100400,
  10614. 0x100: 0x2000000,
  10615. 0x110: 0x100000,
  10616. 0x120: 0x2000401,
  10617. 0x130: 0x2100001,
  10618. 0x140: 0x100001,
  10619. 0x150: 0x2000400,
  10620. 0x160: 0x2100400,
  10621. 0x170: 0x100401,
  10622. 0x180: 0x401,
  10623. 0x190: 0x2100401,
  10624. 0x1a0: 0x100400,
  10625. 0x1b0: 0x1,
  10626. 0x1c0: 0x0,
  10627. 0x1d0: 0x2100000,
  10628. 0x1e0: 0x2000001,
  10629. 0x1f0: 0x400,
  10630. 0x108: 0x100400,
  10631. 0x118: 0x2000401,
  10632. 0x128: 0x2100001,
  10633. 0x138: 0x1,
  10634. 0x148: 0x2000000,
  10635. 0x158: 0x100000,
  10636. 0x168: 0x401,
  10637. 0x178: 0x2100400,
  10638. 0x188: 0x2000001,
  10639. 0x198: 0x2100000,
  10640. 0x1a8: 0x0,
  10641. 0x1b8: 0x2100401,
  10642. 0x1c8: 0x100401,
  10643. 0x1d8: 0x400,
  10644. 0x1e8: 0x2000400,
  10645. 0x1f8: 0x100001
  10646. },
  10647. {
  10648. 0x0: 0x8000820,
  10649. 0x1: 0x20000,
  10650. 0x2: 0x8000000,
  10651. 0x3: 0x20,
  10652. 0x4: 0x20020,
  10653. 0x5: 0x8020820,
  10654. 0x6: 0x8020800,
  10655. 0x7: 0x800,
  10656. 0x8: 0x8020000,
  10657. 0x9: 0x8000800,
  10658. 0xa: 0x20800,
  10659. 0xb: 0x8020020,
  10660. 0xc: 0x820,
  10661. 0xd: 0x0,
  10662. 0xe: 0x8000020,
  10663. 0xf: 0x20820,
  10664. 0x80000000: 0x800,
  10665. 0x80000001: 0x8020820,
  10666. 0x80000002: 0x8000820,
  10667. 0x80000003: 0x8000000,
  10668. 0x80000004: 0x8020000,
  10669. 0x80000005: 0x20800,
  10670. 0x80000006: 0x20820,
  10671. 0x80000007: 0x20,
  10672. 0x80000008: 0x8000020,
  10673. 0x80000009: 0x820,
  10674. 0x8000000a: 0x20020,
  10675. 0x8000000b: 0x8020800,
  10676. 0x8000000c: 0x0,
  10677. 0x8000000d: 0x8020020,
  10678. 0x8000000e: 0x8000800,
  10679. 0x8000000f: 0x20000,
  10680. 0x10: 0x20820,
  10681. 0x11: 0x8020800,
  10682. 0x12: 0x20,
  10683. 0x13: 0x800,
  10684. 0x14: 0x8000800,
  10685. 0x15: 0x8000020,
  10686. 0x16: 0x8020020,
  10687. 0x17: 0x20000,
  10688. 0x18: 0x0,
  10689. 0x19: 0x20020,
  10690. 0x1a: 0x8020000,
  10691. 0x1b: 0x8000820,
  10692. 0x1c: 0x8020820,
  10693. 0x1d: 0x20800,
  10694. 0x1e: 0x820,
  10695. 0x1f: 0x8000000,
  10696. 0x80000010: 0x20000,
  10697. 0x80000011: 0x800,
  10698. 0x80000012: 0x8020020,
  10699. 0x80000013: 0x20820,
  10700. 0x80000014: 0x20,
  10701. 0x80000015: 0x8020000,
  10702. 0x80000016: 0x8000000,
  10703. 0x80000017: 0x8000820,
  10704. 0x80000018: 0x8020820,
  10705. 0x80000019: 0x8000020,
  10706. 0x8000001a: 0x8000800,
  10707. 0x8000001b: 0x0,
  10708. 0x8000001c: 0x20800,
  10709. 0x8000001d: 0x820,
  10710. 0x8000001e: 0x20020,
  10711. 0x8000001f: 0x8020800
  10712. }
  10713. ];
  10714. // Masks that select the SBOX input
  10715. var SBOX_MASK = [
  10716. 0xf8000001, 0x1f800000, 0x01f80000, 0x001f8000,
  10717. 0x0001f800, 0x00001f80, 0x000001f8, 0x8000001f
  10718. ];
  10719. /**
  10720. * DES block cipher algorithm.
  10721. */
  10722. var DES = C_algo.DES = BlockCipher.extend({
  10723. _doReset: function () {
  10724. // Shortcuts
  10725. var key = this._key;
  10726. var keyWords = key.words;
  10727. // Select 56 bits according to PC1
  10728. var keyBits = [];
  10729. for (var i = 0; i < 56; i++) {
  10730. var keyBitPos = PC1[i] - 1;
  10731. keyBits[i] = (keyWords[keyBitPos >>> 5] >>> (31 - keyBitPos % 32)) & 1;
  10732. }
  10733. // Assemble 16 subkeys
  10734. var subKeys = this._subKeys = [];
  10735. for (var nSubKey = 0; nSubKey < 16; nSubKey++) {
  10736. // Create subkey
  10737. var subKey = subKeys[nSubKey] = [];
  10738. // Shortcut
  10739. var bitShift = BIT_SHIFTS[nSubKey];
  10740. // Select 48 bits according to PC2
  10741. for (var i = 0; i < 24; i++) {
  10742. // Select from the left 28 key bits
  10743. subKey[(i / 6) | 0] |= keyBits[((PC2[i] - 1) + bitShift) % 28] << (31 - i % 6);
  10744. // Select from the right 28 key bits
  10745. subKey[4 + ((i / 6) | 0)] |= keyBits[28 + (((PC2[i + 24] - 1) + bitShift) % 28)] << (31 - i % 6);
  10746. }
  10747. // Since each subkey is applied to an expanded 32-bit input,
  10748. // the subkey can be broken into 8 values scaled to 32-bits,
  10749. // which allows the key to be used without expansion
  10750. subKey[0] = (subKey[0] << 1) | (subKey[0] >>> 31);
  10751. for (var i = 1; i < 7; i++) {
  10752. subKey[i] = subKey[i] >>> ((i - 1) * 4 + 3);
  10753. }
  10754. subKey[7] = (subKey[7] << 5) | (subKey[7] >>> 27);
  10755. }
  10756. // Compute inverse subkeys
  10757. var invSubKeys = this._invSubKeys = [];
  10758. for (var i = 0; i < 16; i++) {
  10759. invSubKeys[i] = subKeys[15 - i];
  10760. }
  10761. },
  10762. encryptBlock: function (M, offset) {
  10763. this._doCryptBlock(M, offset, this._subKeys);
  10764. },
  10765. decryptBlock: function (M, offset) {
  10766. this._doCryptBlock(M, offset, this._invSubKeys);
  10767. },
  10768. _doCryptBlock: function (M, offset, subKeys) {
  10769. // Get input
  10770. this._lBlock = M[offset];
  10771. this._rBlock = M[offset + 1];
  10772. // Initial permutation
  10773. exchangeLR.call(this, 4, 0x0f0f0f0f);
  10774. exchangeLR.call(this, 16, 0x0000ffff);
  10775. exchangeRL.call(this, 2, 0x33333333);
  10776. exchangeRL.call(this, 8, 0x00ff00ff);
  10777. exchangeLR.call(this, 1, 0x55555555);
  10778. // Rounds
  10779. for (var round = 0; round < 16; round++) {
  10780. // Shortcuts
  10781. var subKey = subKeys[round];
  10782. var lBlock = this._lBlock;
  10783. var rBlock = this._rBlock;
  10784. // Feistel function
  10785. var f = 0;
  10786. for (var i = 0; i < 8; i++) {
  10787. f |= SBOX_P[i][((rBlock ^ subKey[i]) & SBOX_MASK[i]) >>> 0];
  10788. }
  10789. this._lBlock = rBlock;
  10790. this._rBlock = lBlock ^ f;
  10791. }
  10792. // Undo swap from last round
  10793. var t = this._lBlock;
  10794. this._lBlock = this._rBlock;
  10795. this._rBlock = t;
  10796. // Final permutation
  10797. exchangeLR.call(this, 1, 0x55555555);
  10798. exchangeRL.call(this, 8, 0x00ff00ff);
  10799. exchangeRL.call(this, 2, 0x33333333);
  10800. exchangeLR.call(this, 16, 0x0000ffff);
  10801. exchangeLR.call(this, 4, 0x0f0f0f0f);
  10802. // Set output
  10803. M[offset] = this._lBlock;
  10804. M[offset + 1] = this._rBlock;
  10805. },
  10806. keySize: 64/32,
  10807. ivSize: 64/32,
  10808. blockSize: 64/32
  10809. });
  10810. // Swap bits across the left and right words
  10811. function exchangeLR(offset, mask) {
  10812. var t = ((this._lBlock >>> offset) ^ this._rBlock) & mask;
  10813. this._rBlock ^= t;
  10814. this._lBlock ^= t << offset;
  10815. }
  10816. function exchangeRL(offset, mask) {
  10817. var t = ((this._rBlock >>> offset) ^ this._lBlock) & mask;
  10818. this._lBlock ^= t;
  10819. this._rBlock ^= t << offset;
  10820. }
  10821. /**
  10822. * Shortcut functions to the cipher's object interface.
  10823. *
  10824. * @example
  10825. *
  10826. * var ciphertext = CryptoJS.DES.encrypt(message, key, cfg);
  10827. * var plaintext = CryptoJS.DES.decrypt(ciphertext, key, cfg);
  10828. */
  10829. C.DES = BlockCipher._createHelper(DES);
  10830. /**
  10831. * Triple-DES block cipher algorithm.
  10832. */
  10833. var TripleDES = C_algo.TripleDES = BlockCipher.extend({
  10834. _doReset: function () {
  10835. // Shortcuts
  10836. var key = this._key;
  10837. var keyWords = key.words;
  10838. // Create DES instances
  10839. this._des1 = DES.createEncryptor(WordArray.create(keyWords.slice(0, 2)));
  10840. this._des2 = DES.createEncryptor(WordArray.create(keyWords.slice(2, 4)));
  10841. this._des3 = DES.createEncryptor(WordArray.create(keyWords.slice(4, 6)));
  10842. },
  10843. encryptBlock: function (M, offset) {
  10844. this._des1.encryptBlock(M, offset);
  10845. this._des2.decryptBlock(M, offset);
  10846. this._des3.encryptBlock(M, offset);
  10847. },
  10848. decryptBlock: function (M, offset) {
  10849. this._des3.decryptBlock(M, offset);
  10850. this._des2.encryptBlock(M, offset);
  10851. this._des1.decryptBlock(M, offset);
  10852. },
  10853. keySize: 192/32,
  10854. ivSize: 64/32,
  10855. blockSize: 64/32
  10856. });
  10857. /**
  10858. * Shortcut functions to the cipher's object interface.
  10859. *
  10860. * @example
  10861. *
  10862. * var ciphertext = CryptoJS.TripleDES.encrypt(message, key, cfg);
  10863. * var plaintext = CryptoJS.TripleDES.decrypt(ciphertext, key, cfg);
  10864. */
  10865. C.TripleDES = BlockCipher._createHelper(TripleDES);
  10866. }());
  10867. return CryptoJS.TripleDES;
  10868. }));
  10869. },{"./cipher-core":50,"./core":51,"./enc-base64":52,"./evpkdf":54,"./md5":59}],82:[function(require,module,exports){
  10870. ;(function (root, factory) {
  10871. if (typeof exports === "object") {
  10872. // CommonJS
  10873. module.exports = exports = factory(require("./core"));
  10874. }
  10875. else if (typeof define === "function" && define.amd) {
  10876. // AMD
  10877. define(["./core"], factory);
  10878. }
  10879. else {
  10880. // Global (browser)
  10881. factory(root.CryptoJS);
  10882. }
  10883. }(this, function (CryptoJS) {
  10884. (function (undefined) {
  10885. // Shortcuts
  10886. var C = CryptoJS;
  10887. var C_lib = C.lib;
  10888. var Base = C_lib.Base;
  10889. var X32WordArray = C_lib.WordArray;
  10890. /**
  10891. * x64 namespace.
  10892. */
  10893. var C_x64 = C.x64 = {};
  10894. /**
  10895. * A 64-bit word.
  10896. */
  10897. var X64Word = C_x64.Word = Base.extend({
  10898. /**
  10899. * Initializes a newly created 64-bit word.
  10900. *
  10901. * @param {number} high The high 32 bits.
  10902. * @param {number} low The low 32 bits.
  10903. *
  10904. * @example
  10905. *
  10906. * var x64Word = CryptoJS.x64.Word.create(0x00010203, 0x04050607);
  10907. */
  10908. init: function (high, low) {
  10909. this.high = high;
  10910. this.low = low;
  10911. }
  10912. /**
  10913. * Bitwise NOTs this word.
  10914. *
  10915. * @return {X64Word} A new x64-Word object after negating.
  10916. *
  10917. * @example
  10918. *
  10919. * var negated = x64Word.not();
  10920. */
  10921. // not: function () {
  10922. // var high = ~this.high;
  10923. // var low = ~this.low;
  10924. // return X64Word.create(high, low);
  10925. // },
  10926. /**
  10927. * Bitwise ANDs this word with the passed word.
  10928. *
  10929. * @param {X64Word} word The x64-Word to AND with this word.
  10930. *
  10931. * @return {X64Word} A new x64-Word object after ANDing.
  10932. *
  10933. * @example
  10934. *
  10935. * var anded = x64Word.and(anotherX64Word);
  10936. */
  10937. // and: function (word) {
  10938. // var high = this.high & word.high;
  10939. // var low = this.low & word.low;
  10940. // return X64Word.create(high, low);
  10941. // },
  10942. /**
  10943. * Bitwise ORs this word with the passed word.
  10944. *
  10945. * @param {X64Word} word The x64-Word to OR with this word.
  10946. *
  10947. * @return {X64Word} A new x64-Word object after ORing.
  10948. *
  10949. * @example
  10950. *
  10951. * var ored = x64Word.or(anotherX64Word);
  10952. */
  10953. // or: function (word) {
  10954. // var high = this.high | word.high;
  10955. // var low = this.low | word.low;
  10956. // return X64Word.create(high, low);
  10957. // },
  10958. /**
  10959. * Bitwise XORs this word with the passed word.
  10960. *
  10961. * @param {X64Word} word The x64-Word to XOR with this word.
  10962. *
  10963. * @return {X64Word} A new x64-Word object after XORing.
  10964. *
  10965. * @example
  10966. *
  10967. * var xored = x64Word.xor(anotherX64Word);
  10968. */
  10969. // xor: function (word) {
  10970. // var high = this.high ^ word.high;
  10971. // var low = this.low ^ word.low;
  10972. // return X64Word.create(high, low);
  10973. // },
  10974. /**
  10975. * Shifts this word n bits to the left.
  10976. *
  10977. * @param {number} n The number of bits to shift.
  10978. *
  10979. * @return {X64Word} A new x64-Word object after shifting.
  10980. *
  10981. * @example
  10982. *
  10983. * var shifted = x64Word.shiftL(25);
  10984. */
  10985. // shiftL: function (n) {
  10986. // if (n < 32) {
  10987. // var high = (this.high << n) | (this.low >>> (32 - n));
  10988. // var low = this.low << n;
  10989. // } else {
  10990. // var high = this.low << (n - 32);
  10991. // var low = 0;
  10992. // }
  10993. // return X64Word.create(high, low);
  10994. // },
  10995. /**
  10996. * Shifts this word n bits to the right.
  10997. *
  10998. * @param {number} n The number of bits to shift.
  10999. *
  11000. * @return {X64Word} A new x64-Word object after shifting.
  11001. *
  11002. * @example
  11003. *
  11004. * var shifted = x64Word.shiftR(7);
  11005. */
  11006. // shiftR: function (n) {
  11007. // if (n < 32) {
  11008. // var low = (this.low >>> n) | (this.high << (32 - n));
  11009. // var high = this.high >>> n;
  11010. // } else {
  11011. // var low = this.high >>> (n - 32);
  11012. // var high = 0;
  11013. // }
  11014. // return X64Word.create(high, low);
  11015. // },
  11016. /**
  11017. * Rotates this word n bits to the left.
  11018. *
  11019. * @param {number} n The number of bits to rotate.
  11020. *
  11021. * @return {X64Word} A new x64-Word object after rotating.
  11022. *
  11023. * @example
  11024. *
  11025. * var rotated = x64Word.rotL(25);
  11026. */
  11027. // rotL: function (n) {
  11028. // return this.shiftL(n).or(this.shiftR(64 - n));
  11029. // },
  11030. /**
  11031. * Rotates this word n bits to the right.
  11032. *
  11033. * @param {number} n The number of bits to rotate.
  11034. *
  11035. * @return {X64Word} A new x64-Word object after rotating.
  11036. *
  11037. * @example
  11038. *
  11039. * var rotated = x64Word.rotR(7);
  11040. */
  11041. // rotR: function (n) {
  11042. // return this.shiftR(n).or(this.shiftL(64 - n));
  11043. // },
  11044. /**
  11045. * Adds this word with the passed word.
  11046. *
  11047. * @param {X64Word} word The x64-Word to add with this word.
  11048. *
  11049. * @return {X64Word} A new x64-Word object after adding.
  11050. *
  11051. * @example
  11052. *
  11053. * var added = x64Word.add(anotherX64Word);
  11054. */
  11055. // add: function (word) {
  11056. // var low = (this.low + word.low) | 0;
  11057. // var carry = (low >>> 0) < (this.low >>> 0) ? 1 : 0;
  11058. // var high = (this.high + word.high + carry) | 0;
  11059. // return X64Word.create(high, low);
  11060. // }
  11061. });
  11062. /**
  11063. * An array of 64-bit words.
  11064. *
  11065. * @property {Array} words The array of CryptoJS.x64.Word objects.
  11066. * @property {number} sigBytes The number of significant bytes in this word array.
  11067. */
  11068. var X64WordArray = C_x64.WordArray = Base.extend({
  11069. /**
  11070. * Initializes a newly created word array.
  11071. *
  11072. * @param {Array} words (Optional) An array of CryptoJS.x64.Word objects.
  11073. * @param {number} sigBytes (Optional) The number of significant bytes in the words.
  11074. *
  11075. * @example
  11076. *
  11077. * var wordArray = CryptoJS.x64.WordArray.create();
  11078. *
  11079. * var wordArray = CryptoJS.x64.WordArray.create([
  11080. * CryptoJS.x64.Word.create(0x00010203, 0x04050607),
  11081. * CryptoJS.x64.Word.create(0x18191a1b, 0x1c1d1e1f)
  11082. * ]);
  11083. *
  11084. * var wordArray = CryptoJS.x64.WordArray.create([
  11085. * CryptoJS.x64.Word.create(0x00010203, 0x04050607),
  11086. * CryptoJS.x64.Word.create(0x18191a1b, 0x1c1d1e1f)
  11087. * ], 10);
  11088. */
  11089. init: function (words, sigBytes) {
  11090. words = this.words = words || [];
  11091. if (sigBytes != undefined) {
  11092. this.sigBytes = sigBytes;
  11093. } else {
  11094. this.sigBytes = words.length * 8;
  11095. }
  11096. },
  11097. /**
  11098. * Converts this 64-bit word array to a 32-bit word array.
  11099. *
  11100. * @return {CryptoJS.lib.WordArray} This word array's data as a 32-bit word array.
  11101. *
  11102. * @example
  11103. *
  11104. * var x32WordArray = x64WordArray.toX32();
  11105. */
  11106. toX32: function () {
  11107. // Shortcuts
  11108. var x64Words = this.words;
  11109. var x64WordsLength = x64Words.length;
  11110. // Convert
  11111. var x32Words = [];
  11112. for (var i = 0; i < x64WordsLength; i++) {
  11113. var x64Word = x64Words[i];
  11114. x32Words.push(x64Word.high);
  11115. x32Words.push(x64Word.low);
  11116. }
  11117. return X32WordArray.create(x32Words, this.sigBytes);
  11118. },
  11119. /**
  11120. * Creates a copy of this word array.
  11121. *
  11122. * @return {X64WordArray} The clone.
  11123. *
  11124. * @example
  11125. *
  11126. * var clone = x64WordArray.clone();
  11127. */
  11128. clone: function () {
  11129. var clone = Base.clone.call(this);
  11130. // Clone "words" array
  11131. var words = clone.words = this.words.slice(0);
  11132. // Clone each X64Word object
  11133. var wordsLength = words.length;
  11134. for (var i = 0; i < wordsLength; i++) {
  11135. words[i] = words[i].clone();
  11136. }
  11137. return clone;
  11138. }
  11139. });
  11140. }());
  11141. return CryptoJS;
  11142. }));
  11143. },{"./core":51}],83:[function(require,module,exports){
  11144. /*! https://mths.be/utf8js v2.0.0 by @mathias */
  11145. ;(function(root) {
  11146. var freeExports = typeof exports == 'object' && exports;
  11147. var freeModule = typeof module == 'object' && module &&
  11148. module.exports == freeExports && module;
  11149. var freeGlobal = typeof global == 'object' && global;
  11150. if (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal) {
  11151. root = freeGlobal;
  11152. }
  11153. /*--------------------------------------------------------------------------*/
  11154. var stringFromCharCode = String.fromCharCode;
  11155. // Taken from https://mths.be/punycode
  11156. function ucs2decode(string) {
  11157. var output = [];
  11158. var counter = 0;
  11159. var length = string.length;
  11160. var value;
  11161. var extra;
  11162. while (counter < length) {
  11163. value = string.charCodeAt(counter++);
  11164. if (value >= 0xD800 && value <= 0xDBFF && counter < length) {
  11165. // high surrogate, and there is a next character
  11166. extra = string.charCodeAt(counter++);
  11167. if ((extra & 0xFC00) == 0xDC00) { // low surrogate
  11168. output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000);
  11169. } else {
  11170. // unmatched surrogate; only append this code unit, in case the next
  11171. // code unit is the high surrogate of a surrogate pair
  11172. output.push(value);
  11173. counter--;
  11174. }
  11175. } else {
  11176. output.push(value);
  11177. }
  11178. }
  11179. return output;
  11180. }
  11181. // Taken from https://mths.be/punycode
  11182. function ucs2encode(array) {
  11183. var length = array.length;
  11184. var index = -1;
  11185. var value;
  11186. var output = '';
  11187. while (++index < length) {
  11188. value = array[index];
  11189. if (value > 0xFFFF) {
  11190. value -= 0x10000;
  11191. output += stringFromCharCode(value >>> 10 & 0x3FF | 0xD800);
  11192. value = 0xDC00 | value & 0x3FF;
  11193. }
  11194. output += stringFromCharCode(value);
  11195. }
  11196. return output;
  11197. }
  11198. function checkScalarValue(codePoint) {
  11199. if (codePoint >= 0xD800 && codePoint <= 0xDFFF) {
  11200. throw Error(
  11201. 'Lone surrogate U+' + codePoint.toString(16).toUpperCase() +
  11202. ' is not a scalar value'
  11203. );
  11204. }
  11205. }
  11206. /*--------------------------------------------------------------------------*/
  11207. function createByte(codePoint, shift) {
  11208. return stringFromCharCode(((codePoint >> shift) & 0x3F) | 0x80);
  11209. }
  11210. function encodeCodePoint(codePoint) {
  11211. if ((codePoint & 0xFFFFFF80) == 0) { // 1-byte sequence
  11212. return stringFromCharCode(codePoint);
  11213. }
  11214. var symbol = '';
  11215. if ((codePoint & 0xFFFFF800) == 0) { // 2-byte sequence
  11216. symbol = stringFromCharCode(((codePoint >> 6) & 0x1F) | 0xC0);
  11217. }
  11218. else if ((codePoint & 0xFFFF0000) == 0) { // 3-byte sequence
  11219. checkScalarValue(codePoint);
  11220. symbol = stringFromCharCode(((codePoint >> 12) & 0x0F) | 0xE0);
  11221. symbol += createByte(codePoint, 6);
  11222. }
  11223. else if ((codePoint & 0xFFE00000) == 0) { // 4-byte sequence
  11224. symbol = stringFromCharCode(((codePoint >> 18) & 0x07) | 0xF0);
  11225. symbol += createByte(codePoint, 12);
  11226. symbol += createByte(codePoint, 6);
  11227. }
  11228. symbol += stringFromCharCode((codePoint & 0x3F) | 0x80);
  11229. return symbol;
  11230. }
  11231. function utf8encode(string) {
  11232. var codePoints = ucs2decode(string);
  11233. var length = codePoints.length;
  11234. var index = -1;
  11235. var codePoint;
  11236. var byteString = '';
  11237. while (++index < length) {
  11238. codePoint = codePoints[index];
  11239. byteString += encodeCodePoint(codePoint);
  11240. }
  11241. return byteString;
  11242. }
  11243. /*--------------------------------------------------------------------------*/
  11244. function readContinuationByte() {
  11245. if (byteIndex >= byteCount) {
  11246. throw Error('Invalid byte index');
  11247. }
  11248. var continuationByte = byteArray[byteIndex] & 0xFF;
  11249. byteIndex++;
  11250. if ((continuationByte & 0xC0) == 0x80) {
  11251. return continuationByte & 0x3F;
  11252. }
  11253. // If we end up here, it’s not a continuation byte
  11254. throw Error('Invalid continuation byte');
  11255. }
  11256. function decodeSymbol() {
  11257. var byte1;
  11258. var byte2;
  11259. var byte3;
  11260. var byte4;
  11261. var codePoint;
  11262. if (byteIndex > byteCount) {
  11263. throw Error('Invalid byte index');
  11264. }
  11265. if (byteIndex == byteCount) {
  11266. return false;
  11267. }
  11268. // Read first byte
  11269. byte1 = byteArray[byteIndex] & 0xFF;
  11270. byteIndex++;
  11271. // 1-byte sequence (no continuation bytes)
  11272. if ((byte1 & 0x80) == 0) {
  11273. return byte1;
  11274. }
  11275. // 2-byte sequence
  11276. if ((byte1 & 0xE0) == 0xC0) {
  11277. var byte2 = readContinuationByte();
  11278. codePoint = ((byte1 & 0x1F) << 6) | byte2;
  11279. if (codePoint >= 0x80) {
  11280. return codePoint;
  11281. } else {
  11282. throw Error('Invalid continuation byte');
  11283. }
  11284. }
  11285. // 3-byte sequence (may include unpaired surrogates)
  11286. if ((byte1 & 0xF0) == 0xE0) {
  11287. byte2 = readContinuationByte();
  11288. byte3 = readContinuationByte();
  11289. codePoint = ((byte1 & 0x0F) << 12) | (byte2 << 6) | byte3;
  11290. if (codePoint >= 0x0800) {
  11291. checkScalarValue(codePoint);
  11292. return codePoint;
  11293. } else {
  11294. throw Error('Invalid continuation byte');
  11295. }
  11296. }
  11297. // 4-byte sequence
  11298. if ((byte1 & 0xF8) == 0xF0) {
  11299. byte2 = readContinuationByte();
  11300. byte3 = readContinuationByte();
  11301. byte4 = readContinuationByte();
  11302. codePoint = ((byte1 & 0x0F) << 0x12) | (byte2 << 0x0C) |
  11303. (byte3 << 0x06) | byte4;
  11304. if (codePoint >= 0x010000 && codePoint <= 0x10FFFF) {
  11305. return codePoint;
  11306. }
  11307. }
  11308. throw Error('Invalid UTF-8 detected');
  11309. }
  11310. var byteArray;
  11311. var byteCount;
  11312. var byteIndex;
  11313. function utf8decode(byteString) {
  11314. byteArray = ucs2decode(byteString);
  11315. byteCount = byteArray.length;
  11316. byteIndex = 0;
  11317. var codePoints = [];
  11318. var tmp;
  11319. while ((tmp = decodeSymbol()) !== false) {
  11320. codePoints.push(tmp);
  11321. }
  11322. return ucs2encode(codePoints);
  11323. }
  11324. /*--------------------------------------------------------------------------*/
  11325. var utf8 = {
  11326. 'version': '2.0.0',
  11327. 'encode': utf8encode,
  11328. 'decode': utf8decode
  11329. };
  11330. // Some AMD build optimizers, like r.js, check for specific condition patterns
  11331. // like the following:
  11332. if (
  11333. typeof define == 'function' &&
  11334. typeof define.amd == 'object' &&
  11335. define.amd
  11336. ) {
  11337. define(function() {
  11338. return utf8;
  11339. });
  11340. } else if (freeExports && !freeExports.nodeType) {
  11341. if (freeModule) { // in Node.js or RingoJS v0.8.0+
  11342. freeModule.exports = utf8;
  11343. } else { // in Narwhal or RingoJS v0.7.0-
  11344. var object = {};
  11345. var hasOwnProperty = object.hasOwnProperty;
  11346. for (var key in utf8) {
  11347. hasOwnProperty.call(utf8, key) && (freeExports[key] = utf8[key]);
  11348. }
  11349. }
  11350. } else { // in Rhino or a web browser
  11351. root.utf8 = utf8;
  11352. }
  11353. }(this));
  11354. },{}],"bignumber.js":[function(require,module,exports){
  11355. 'use strict';
  11356. module.exports = BigNumber; // jshint ignore:line
  11357. },{}],"web3":[function(require,module,exports){
  11358. var Web3 = require('./lib/web3');
  11359. // dont override global variable
  11360. if (typeof window !== 'undefined' && typeof window.Web3 === 'undefined') {
  11361. window.Web3 = Web3;
  11362. }
  11363. module.exports = Web3;
  11364. },{"./lib/web3":22}]},{},["web3"])
  11365. //# sourceMappingURL=web3-light.js.map
  11366. `