UNPKG

chainscript

Version:
1 lines 21 kB
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("bitcore"),require("bitcore-message")):"function"==typeof define&&define.amd?define(["bitcore","bitcore-message"],e):"object"==typeof exports?exports.chainscript=e(require("bitcore"),require("bitcore-message")):t.chainscript=e(t.Bitcore,t.BitcoreMessage)}(this,function(t,e){return function(t){function e(n){if(r[n])return r[n].exports;var i=r[n]={exports:{},id:n,loaded:!1};return t[n].call(i.exports,i,i.exports,e),i.loaded=!0,i.exports}var r={};return e.m=t,e.c=r,e.p="",e(0)}([function(t,e,r){"use strict";function n(t){return t&&t.__esModule?t:{"default":t}}e.__esModule=!0;var i=r(1),o=n(i);e["default"]=o["default"],t.exports=e["default"]},function(t,e,r){"use strict";function n(t){return t&&t.__esModule?t:{"default":t}}function i(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}e.__esModule=!0;var o=function(){function t(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,r,n){return r&&t(e.prototype,r),n&&t(e,n),e}}(),s=r(9),a=n(s),u=r(8),c=n(u),f=r(12),h=r(13),p=n(h),l=r(2),d=n(l),y=r(3),m=n(y),g=r(4),v=n(g),b=function(){function t(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],r=arguments.length<=1||void 0===arguments[1]?!1:arguments[1];i(this,t),this.script=d["default"](e),this.immutable=r,r||(this.initial=d["default"](e))}return o(t,null,[{key:"EXECUTE_URL",value:"http://agent.chainscript.io/execute",enumerable:!0},{key:"SNAPSHOTS_URL",value:"https://chainscript.firebaseio.com/snapshots/",enumerable:!0},{key:"load",value:function(e){var r=arguments.length<=1||void 0===arguments[1]?!1:arguments[1],n=a["default"].get(t.SNAPSHOTS_URL+e.replace(/:/g,"-")+".json").set("Accept","application/json");return v["default"](n.end.bind(n))().then(function(e){if(!e.ok)throw new Error(e.text);if(!e.body)throw new Error("Not found");return new t(d["default"](e.body),r)})},enumerable:!0}]),t.prototype.toJSON=function(){return d["default"](this.script)},t.prototype.clone=function(){var e=new t(this.script,this.immutable);return this.immutable||(e.initial=d["default"](this.initial)),e},t.prototype.run=function(){var e=this;if(!this.immutable){var r=c["default"].get(this.initial,"body.content"),n=c["default"].get(this.script,"body.content");m["default"](r,n)||(this.script.body=this.script.body||{},this.script.body.content=r,this.delta(n,!0))}var i=a["default"].post(t.EXECUTE_URL).send(this.script).set("Accept","application/json");return v["default"](i.end.bind(i))().then(function(r){if(!r.ok)throw new Error(r.text);if(!r.body)throw new Error("Not found");return e.immutable?new t(r.body,!0):(e.script=r.body,e.initial=d["default"](e.script),e)})},t.prototype.get=function(t){var e=c["default"].get(this.script,t);return"undefined"==typeof e?void 0:this.immutable?d["default"](e):e},t.prototype.set=function(e,r){var n=void 0;return n=this.immutable?d["default"](this.script):this.script,c["default"].set(n,e,r),this.immutable?new t(n,!0):this},t.prototype.snapshot=function(){return this.set("x_chainscript.snapshots_enabled",!0).addCommand({snapshot:{}})},t.prototype.update=function(t){var e=arguments.length<=1||void 0===arguments[1]?!1:arguments[1];return this.addCommand({update:t},e)},t.prototype.notarize=function(){return this.addCommand({notarize:{}})},t.prototype.email=function(t,e){return e?this.addCommand({send_email:{to:t,subject:e}}):this.addCommand({send_email:{to:t}})},t.prototype.change=function(t){var e=d["default"](this.get("body.content"));return t(e),this.delta(e)},t.prototype.delta=function(t){var e=arguments.length<=1||void 0===arguments[1]?!1:arguments[1],r=this.get("body.content");return"object"==typeof r&&r&&"object"==typeof t&&t&&Object.keys(r).forEach(function(e){"undefined"==typeof t[e]?t[e]=null:m["default"](r[e],t[e])&&delete t[e]}),this.update(t,e)},t.prototype.sign=function(t){var e,r=c["default"].get(this.script,"body.x_meta.content_digest");if("undefined"==typeof r)throw new Error("Content has no digest");var n=f.PrivateKey.fromWIF(t),i=n.toPublicKey().toAddress().toString(),o=new p["default"](r),s=o.sign(n);return this.addCommand({sign_content:(e={},e[i]={digest:r,signature:s},e)})},t.prototype.getNumCommands=function(){return"undefined"==typeof this.script.execute?0:Object.keys(this.script.execute).length},t.prototype.addCommand=function(e){var r=arguments.length<=1||void 0===arguments[1]?!1:arguments[1],n=r?0:this.getNumCommands(),i=void 0;return i=this.immutable?d["default"](this.script):this.script,i.execute=i.execute||{},r&&!function(){var t={};Object.keys(i.execute).forEach(function(e){t[parseInt(e,10)+1]=i.execute[e]}),i.execute=t}(),i.execute[n]=e,this.immutable?new t(i,!0):this},t}();e["default"]=b,t.exports=e["default"]},function(t,e){"use strict";function r(t){return JSON.parse(JSON.stringify(t))}e.__esModule=!0,e["default"]=r,t.exports=e["default"]},function(t,e,r){"use strict";function n(t,e){return t===e||i.digest(t)===i.digest(e)}e.__esModule=!0,e["default"]=n;var i=r(5);t.exports=e["default"]},function(t,e){"use strict";function r(t){return function(){for(var e=arguments.length,r=Array(e),n=0;e>n;n++)r[n]=arguments[n];return new Promise(function(e,n){t.apply(void 0,r.concat([function(t){for(var r=arguments.length,i=Array(r>1?r-1:0),o=1;r>o;o++)i[o-1]=arguments[o];return t?void n(t):void e.apply(void 0,i)}]))})}}e.__esModule=!0,e["default"]=r,t.exports=e["default"]},function(t,e,r){"use strict";function n(t){var e=void 0===arguments[1]?{}:arguments[1],r=e.algorithm,n=void 0===r?"sha1":r,i=e.inputEncoding,a=void 0===i?"utf8":i,u=e.outputEncoding,c=void 0===u?"hex":u,f=e.crypto,h=void 0===f?s:f;return o(t,{algorithm:n,inputEncoding:a,outputEncoding:c,crypto:h})}var i=function(t){return t&&t.__esModule?t["default"]:t};e.digest=n;var o=r(7).digest,s=i(r(6));Object.defineProperty(e,"__esModule",{value:!0})},function(t,e){"use strict";function r(t,e,r){if(Array.isArray(e))for(var n=e.length,i=0;n>i;i++)t.push(e[i]);else if("utf8"===r)for(var o=unescape(encodeURIComponent(e)),n=o.length,i=0;n>i;i++)t.push(o.charCodeAt(i));else for(var n=e.length,i=0;n>i;i++){var s=255&e.charCodeAt(i);t.push(0===s&&"ascii"===r?32:s)}}function n(t){for(var e=(t.length,4294967295),r=new Array(80),n=[1732584193,4023233417,2562383102,271733878,3285377520],i=0;i<t.length;i+=16){for(var o=n[0],s=n[1],u=n[2],c=n[3],f=n[4],h=0;16>h;h++)r[h]=t[i+h];for(var h=16;79>=h;h++)r[h]=a(r[h-3]^r[h-8]^r[h-14]^r[h-16],1);for(var h=0;19>=h;h++){var p=a(o,5)+(s&u|~s&c)+f+r[h]+1518500249&e;f=c,c=u,u=a(s,30),s=o,o=p}for(var h=20;39>=h;h++){var p=a(o,5)+(s^u^c)+f+r[h]+1859775393&e;f=c,c=u,u=a(s,30),s=o,o=p}for(var h=40;59>=h;h++){var p=a(o,5)+(s&u|s&c|u&c)+f+r[h]+2400959708&e;f=c,c=u,u=a(s,30),s=o,o=p}for(var h=60;79>=h;h++){var p=a(o,5)+(s^u^c)+f+r[h]+3395469782&e;f=c,c=u,u=a(s,30),s=o,o=p}n[0]=n[0]+o&e,n[1]=n[1]+s&e,n[2]=n[2]+u&e,n[3]=n[3]+c&e,n[4]=n[4]+f&e}return n}function i(t){var e=null;switch(t){case"sha1":e=o(t);break;default:throw new Error("Digest method not supported.")}return e}function o(){var t=[],e=[];return{update:function(e,n){r(t,e,n)},digest:function(r){for(var i=t.length,o=0;i-3>o;o+=4)e.push(t[o]<<24|t[o+1]<<16|t[o+2]<<8|t[o+3]);switch(i%4){case 0:e.push(2147483648);break;case 1:e.push(t[i-1]<<24|8388608);break;case 2:e.push(t[i-2]<<24|t[i-1]<<16|32768);break;case 3:e.push(t[i-3]<<24|t[i-2]<<16|t[i-1]<<8|128)}for(;e.length%16!=14;)e.push(0);return e.push(i>>>29),e.push(i<<3&4294967295),s(n(e).reduce(function(t,e){for(var r=7;r>=0;--r)t.push(e>>>4*r&15);return t},[]),r)}}}var s=function(t,e){var r=null,n=function(t){return String.fromCharCode(t)},i=function(t){return t.toString(16)};switch(e){case"binary":r=t.map(n).join("");break;case"base64":r=atob(t.map(n).join(""));break;default:r=t.map(i).join("")}return r},a=function(t,e){return t<<e|t>>>32-e};t.exports={createHash:i}},function(t,e){"use strict";function r(t){var e=void 0===arguments[1]?{}:arguments[1],n=e.algorithm,i=void 0===n?"sha1":n,o=e.inputEncoding,s=void 0===o?"utf8":o,a=e.outputEncoding,u=void 0===a?"hex":a,c=e.crypto,f=c.createHash(i),h=function(){for(var t=arguments.length,e=Array(t),r=0;t>r;r++)e[r]=arguments[r];return f.update(e.join(":"),s)},p=function(t){return r(t,{algorithm:i,inputEncoding:s,outputEncoding:u,crypto:c})};switch(!0){case"undefined"==typeof t:h("u");break;case null===t:h("n");break;case"boolean"==typeof t:case t instanceof Boolean:h("f",t.valueOf());break;case"number"==typeof t:case t instanceof Number:h("i",""+t);break;case"string"==typeof t:case t instanceof String:h("s",""+t);break;case"symbol"==typeof t:case t instanceof Symbol:h("S",""+t);break;case t instanceof Date:h("d",t.toISOString());break;case t instanceof RegExp:h("x",""+t);break;case t instanceof Function:h("F",t.toString());break;case Array.isArray(t):h("["),t.forEach(function(t){return h("a",p(t))}),h("]");break;default:h("{"),Object.keys(t).sort().forEach(function(e){return h("k",p(e),"v",p(t[e]))}),h("}")}return f.digest(u)}e.digest=r,Object.defineProperty(e,"__esModule",{value:!0})},function(t,e,r){var n,i,o;!function(r,s){"use strict";"object"==typeof t&&"object"==typeof t.exports?t.exports=s():(i=[],n=s,o="function"==typeof n?n.apply(e,i):n,!(void 0!==o&&(t.exports=o)))}(this,function(){"use strict";function t(t){if(!t)return!0;if(o(t)&&0===t.length)return!0;if(!n(t)){for(var e in t)if(h.call(t,e))return!1;return!0}return!1}function e(t){return f.call(t)}function r(t){return"number"==typeof t||"[object Number]"===e(t)}function n(t){return"string"==typeof t||"[object String]"===e(t)}function i(t){return"object"==typeof t&&"[object Object]"===e(t)}function o(t){return"object"==typeof t&&"number"==typeof t.length&&"[object Array]"===e(t)}function s(t){return"boolean"==typeof t||"[object Boolean]"===e(t)}function a(t){var e=parseInt(t);return e.toString()===t?e:t}function u(e,i,o,s){if(r(i)&&(i=[i]),t(i))return e;if(n(i))return u(e,i.split(".").map(a),o,s);var c=i[0];if(1===i.length){var f=e[c];return void 0!==f&&s||(e[c]=o),f}return void 0===e[c]&&(r(i[1])?e[c]=[]:e[c]={}),u(e[c],i.slice(1),o,s)}function c(e,i){if(r(i)&&(i=[i]),t(e))return void 0;if(t(i))return e;if(n(i))return c(e,i.split("."));var s=a(i[0]),u=e[s];if(1===i.length)void 0!==u&&(o(e)?e.splice(s,1):delete e[s]);else if(void 0!==e[s])return c(e[s],i.slice(1));return e}var f=Object.prototype.toString,h=Object.prototype.hasOwnProperty,p=function(t){return Object.keys(p).reduce(function(e,r){return"function"==typeof p[r]&&(e[r]=p[r].bind(p,t)),e},{})};return p.has=function(e,s){if(t(e))return!1;if(r(s)?s=[s]:n(s)&&(s=s.split(".")),t(s)||0===s.length)return!1;for(var a=0;a<s.length;a++){var u=s[a];if(!i(e)&&!o(e)||!h.call(e,u))return!1;e=e[u]}return!0},p.ensureExists=function(t,e,r){return u(t,e,r,!0)},p.set=function(t,e,r,n){return u(t,e,r,n)},p.insert=function(t,e,r,n){var i=p.get(t,e);n=~~n,o(i)||(i=[],p.set(t,e,i)),i.splice(n,0,r)},p.empty=function(e,a){if(t(a))return e;if(t(e))return void 0;var u,c;if(!(u=p.get(e,a)))return e;if(n(u))return p.set(e,a,"");if(s(u))return p.set(e,a,!1);if(r(u))return p.set(e,a,0);if(o(u))u.length=0;else{if(!i(u))return p.set(e,a,null);for(c in u)h.call(u,c)&&delete u[c]}},p.push=function(t,e){var r=p.get(t,e);o(r)||(r=[],p.set(t,e,r)),r.push.apply(r,Array.prototype.slice.call(arguments,2))},p.coalesce=function(t,e,r){for(var n,i=0,o=e.length;o>i;i++)if(void 0!==(n=p.get(t,e[i])))return n;return r},p.get=function(e,i,o){if(r(i)&&(i=[i]),t(i))return e;if(t(e))return o;if(n(i))return p.get(e,i.split("."),o);var s=a(i[0]);return 1===i.length?void 0===e[s]?o:e[s]:p.get(e[s],i.slice(1),o)},p.del=function(t,e){return c(t,e)},p})},function(t,e,r){function n(){}function i(t){var e={}.toString.call(t);switch(e){case"[object File]":case"[object Blob]":case"[object FormData]":return!0;default:return!1}}function o(t){return t===Object(t)}function s(t){if(!o(t))return t;var e=[];for(var r in t)null!=t[r]&&e.push(encodeURIComponent(r)+"="+encodeURIComponent(t[r]));return e.join("&")}function a(t){for(var e,r,n={},i=t.split("&"),o=0,s=i.length;s>o;++o)r=i[o],e=r.split("="),n[decodeURIComponent(e[0])]=decodeURIComponent(e[1]);return n}function u(t){var e,r,n,i,o=t.split(/\r?\n/),s={};o.pop();for(var a=0,u=o.length;u>a;++a)r=o[a],e=r.indexOf(":"),n=r.slice(0,e).toLowerCase(),i=g(r.slice(e+1)),s[n]=i;return s}function c(t){return t.split(/ *; */).shift()}function f(t){return m(t.split(/ *; */),function(t,e){var r=e.split(/ *= */),n=r.shift(),i=r.shift();return n&&i&&(t[n]=i),t},{})}function h(t,e){e=e||{},this.req=t,this.xhr=this.req.xhr,this.text="HEAD"!=this.req.method&&(""===this.xhr.responseType||"text"===this.xhr.responseType)||"undefined"==typeof this.xhr.responseType?this.xhr.responseText:null,this.statusText=this.req.xhr.statusText,this.setStatusProperties(this.xhr.status),this.header=this.headers=u(this.xhr.getAllResponseHeaders()),this.header["content-type"]=this.xhr.getResponseHeader("content-type"),this.setHeaderProperties(this.header),this.body="HEAD"!=this.req.method?this.parseBody(this.text?this.text:this.xhr.response):null}function p(t,e){var r=this;y.call(this),this._query=this._query||[],this.method=t,this.url=e,this.header={},this._header={},this.on("end",function(){var t=null,e=null;try{e=new h(r)}catch(n){return t=new Error("Parser is unable to parse the response"),t.parse=!0,t.original=n,r.callback(t)}if(r.emit("response",e),t)return r.callback(t,e);if(e.status>=200&&e.status<300)return r.callback(t,e);var i=new Error(e.statusText||"Unsuccessful HTTP response");i.original=t,i.response=e,i.status=e.status,r.callback(i,e)})}function l(t,e){return"function"==typeof e?new p("GET",t).end(e):1==arguments.length?new p("GET",t):new p(t,e)}var d,y=r(10),m=r(11);d="undefined"!=typeof window?window:"undefined"!=typeof self?self:this,l.getXHR=function(){if(!(!d.XMLHttpRequest||d.location&&"file:"==d.location.protocol&&d.ActiveXObject))return new XMLHttpRequest;try{return new ActiveXObject("Microsoft.XMLHTTP")}catch(t){}try{return new ActiveXObject("Msxml2.XMLHTTP.6.0")}catch(t){}try{return new ActiveXObject("Msxml2.XMLHTTP.3.0")}catch(t){}try{return new ActiveXObject("Msxml2.XMLHTTP")}catch(t){}return!1};var g="".trim?function(t){return t.trim()}:function(t){return t.replace(/(^\s*|\s*$)/g,"")};l.serializeObject=s,l.parseString=a,l.types={html:"text/html",json:"application/json",xml:"application/xml",urlencoded:"application/x-www-form-urlencoded",form:"application/x-www-form-urlencoded","form-data":"application/x-www-form-urlencoded"},l.serialize={"application/x-www-form-urlencoded":s,"application/json":JSON.stringify},l.parse={"application/x-www-form-urlencoded":a,"application/json":JSON.parse},h.prototype.get=function(t){return this.header[t.toLowerCase()]},h.prototype.setHeaderProperties=function(t){var e=this.header["content-type"]||"";this.type=c(e);var r=f(e);for(var n in r)this[n]=r[n]},h.prototype.parse=function(t){return this.parser=t,this},h.prototype.parseBody=function(t){var e=this.parser||l.parse[this.type];return e&&t&&(t.length||t instanceof Object)?e(t):null},h.prototype.setStatusProperties=function(t){1223===t&&(t=204);var e=t/100|0;this.status=this.statusCode=t,this.statusType=e,this.info=1==e,this.ok=2==e,this.clientError=4==e,this.serverError=5==e,this.error=4==e||5==e?this.toError():!1,this.accepted=202==t,this.noContent=204==t,this.badRequest=400==t,this.unauthorized=401==t,this.notAcceptable=406==t,this.notFound=404==t,this.forbidden=403==t},h.prototype.toError=function(){var t=this.req,e=t.method,r=t.url,n="cannot "+e+" "+r+" ("+this.status+")",i=new Error(n);return i.status=this.status,i.method=e,i.url=r,i},l.Response=h,y(p.prototype),p.prototype.use=function(t){return t(this),this},p.prototype.timeout=function(t){return this._timeout=t,this},p.prototype.clearTimeout=function(){return this._timeout=0,clearTimeout(this._timer),this},p.prototype.abort=function(){return this.aborted?void 0:(this.aborted=!0,this.xhr.abort(),this.clearTimeout(),this.emit("abort"),this)},p.prototype.set=function(t,e){if(o(t)){for(var r in t)this.set(r,t[r]);return this}return this._header[t.toLowerCase()]=e,this.header[t]=e,this},p.prototype.unset=function(t){return delete this._header[t.toLowerCase()],delete this.header[t],this},p.prototype.getHeader=function(t){return this._header[t.toLowerCase()]},p.prototype.type=function(t){return this.set("Content-Type",l.types[t]||t),this},p.prototype.accept=function(t){return this.set("Accept",l.types[t]||t),this},p.prototype.auth=function(t,e){var r=btoa(t+":"+e);return this.set("Authorization","Basic "+r),this},p.prototype.query=function(t){return"string"!=typeof t&&(t=s(t)),t&&this._query.push(t),this},p.prototype.field=function(t,e){return this._formData||(this._formData=new d.FormData),this._formData.append(t,e),this},p.prototype.attach=function(t,e,r){return this._formData||(this._formData=new d.FormData),this._formData.append(t,e,r),this},p.prototype.send=function(t){var e=o(t),r=this.getHeader("Content-Type");if(e&&o(this._data))for(var n in t)this._data[n]=t[n];else"string"==typeof t?(r||this.type("form"),r=this.getHeader("Content-Type"),"application/x-www-form-urlencoded"==r?this._data=this._data?this._data+"&"+t:t:this._data=(this._data||"")+t):this._data=t;return!e||i(t)?this:(r||this.type("json"),this)},p.prototype.callback=function(t,e){var r=this._callback;this.clearTimeout(),r(t,e)},p.prototype.crossDomainError=function(){var t=new Error("Origin is not allowed by Access-Control-Allow-Origin");t.crossDomain=!0,this.callback(t)},p.prototype.timeoutError=function(){var t=this._timeout,e=new Error("timeout of "+t+"ms exceeded");e.timeout=t,this.callback(e)},p.prototype.withCredentials=function(){return this._withCredentials=!0,this},p.prototype.end=function(t){var e=this,r=this.xhr=l.getXHR(),o=this._query.join("&"),s=this._timeout,a=this._formData||this._data;this._callback=t||n,r.onreadystatechange=function(){if(4==r.readyState){var t;try{t=r.status}catch(n){t=0}if(0==t){if(e.timedout)return e.timeoutError();if(e.aborted)return;return e.crossDomainError()}e.emit("end")}};var u=function(t){t.total>0&&(t.percent=t.loaded/t.total*100),e.emit("progress",t)};this.hasListeners("progress")&&(r.onprogress=u);try{r.upload&&this.hasListeners("progress")&&(r.upload.onprogress=u)}catch(c){}if(s&&!this._timer&&(this._timer=setTimeout(function(){e.timedout=!0,e.abort()},s)),o&&(o=l.serializeObject(o),this.url+=~this.url.indexOf("?")?"&"+o:"?"+o),r.open(this.method,this.url,!0),this._withCredentials&&(r.withCredentials=!0),"GET"!=this.method&&"HEAD"!=this.method&&"string"!=typeof a&&!i(a)){var f=this.getHeader("Content-Type"),h=l.serialize[f?f.split(";")[0]:""];h&&(a=h(a))}for(var p in this.header)null!=this.header[p]&&r.setRequestHeader(p,this.header[p]);return this.emit("request",this),r.send(a),this},p.prototype.then=function(t,e){return this.end(function(r,n){r?e(r):t(n)})},l.Request=p,l.get=function(t,e,r){var n=l("GET",t);return"function"==typeof e&&(r=e,e=null),e&&n.query(e),r&&n.end(r),n},l.head=function(t,e,r){var n=l("HEAD",t);return"function"==typeof e&&(r=e,e=null),e&&n.send(e),r&&n.end(r),n},l.del=function(t,e){var r=l("DELETE",t);return e&&r.end(e),r},l.patch=function(t,e,r){var n=l("PATCH",t);return"function"==typeof e&&(r=e,e=null),e&&n.send(e),r&&n.end(r),n},l.post=function(t,e,r){var n=l("POST",t);return"function"==typeof e&&(r=e,e=null),e&&n.send(e),r&&n.end(r),n},l.put=function(t,e,r){var n=l("PUT",t);return"function"==typeof e&&(r=e,e=null),e&&n.send(e),r&&n.end(r),n},t.exports=l},function(t,e){function r(t){return t?n(t):void 0}function n(t){for(var e in r.prototype)t[e]=r.prototype[e];return t}t.exports=r,r.prototype.on=r.prototype.addEventListener=function(t,e){return this._callbacks=this._callbacks||{},(this._callbacks[t]=this._callbacks[t]||[]).push(e),this},r.prototype.once=function(t,e){function r(){n.off(t,r),e.apply(this,arguments)}var n=this;return this._callbacks=this._callbacks||{},r.fn=e,this.on(t,r),this},r.prototype.off=r.prototype.removeListener=r.prototype.removeAllListeners=r.prototype.removeEventListener=function(t,e){if(this._callbacks=this._callbacks||{},0==arguments.length)return this._callbacks={},this;var r=this._callbacks[t];if(!r)return this;if(1==arguments.length)return delete this._callbacks[t],this;for(var n,i=0;i<r.length;i++)if(n=r[i],n===e||n.fn===e){r.splice(i,1);break}return this},r.prototype.emit=function(t){this._callbacks=this._callbacks||{};var e=[].slice.call(arguments,1),r=this._callbacks[t];if(r){r=r.slice(0);for(var n=0,i=r.length;i>n;++n)r[n].apply(this,e)}return this},r.prototype.listeners=function(t){return this._callbacks=this._callbacks||{},this._callbacks[t]||[]},r.prototype.hasListeners=function(t){return!!this.listeners(t).length}},function(t,e){t.exports=function(t,e,r){for(var n=0,i=t.length,o=3==arguments.length?r:t[n++];i>n;)o=e.call(null,o,t[n],++n,t);return o}},function(e,r){e.exports=t},function(t,r){t.exports=e}])});