UNPKG

@onekeyfe/blockchain-link

Version:

High-level javascript interface for blockchain communication

1 lines 62.7 kB
!function(e){var t={};function r(n){if(t[n])return t[n].exports;var i=t[n]={i:n,l:!1,exports:{}};return e[n].call(i.exports,i,i.exports,r),i.l=!0,i.exports}r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)r.d(n,i,function(t){return e[t]}.bind(null,i));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="./",r(r.s=482)}({14:function(e,t,r){"use strict";var n,i="object"==typeof Reflect?Reflect:null,s=i&&"function"==typeof i.apply?i.apply:function(e,t,r){return Function.prototype.apply.call(e,t,r)};n=i&&"function"==typeof i.ownKeys?i.ownKeys:Object.getOwnPropertySymbols?function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:function(e){return Object.getOwnPropertyNames(e)};var o=Number.isNaN||function(e){return e!=e};function c(){c.init.call(this)}e.exports=c,e.exports.once=function(e,t){return new Promise((function(r,n){function i(){void 0!==s&&e.removeListener("error",s),r([].slice.call(arguments))}var s;"error"!==t&&(s=function(r){e.removeListener(t,i),n(r)},e.once("error",s)),e.once(t,i)}))},c.EventEmitter=c,c.prototype._events=void 0,c.prototype._eventsCount=0,c.prototype._maxListeners=void 0;var u=10;function a(e){if("function"!=typeof e)throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}function f(e){return void 0===e._maxListeners?c.defaultMaxListeners:e._maxListeners}function l(e,t,r,n){var i,s,o,c;if(a(r),void 0===(s=e._events)?(s=e._events=Object.create(null),e._eventsCount=0):(void 0!==s.newListener&&(e.emit("newListener",t,r.listener?r.listener:r),s=e._events),o=s[t]),void 0===o)o=s[t]=r,++e._eventsCount;else if("function"==typeof o?o=s[t]=n?[r,o]:[o,r]:n?o.unshift(r):o.push(r),(i=f(e))>0&&o.length>i&&!o.warned){o.warned=!0;var u=new Error("Possible EventEmitter memory leak detected. "+o.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");u.name="MaxListenersExceededWarning",u.emitter=e,u.type=t,u.count=o.length,c=u,console&&console.warn&&console.warn(c)}return e}function d(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,0===arguments.length?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function p(e,t,r){var n={fired:!1,wrapFn:void 0,target:e,type:t,listener:r},i=d.bind(n);return i.listener=r,n.wrapFn=i,i}function h(e,t,r){var n=e._events;if(void 0===n)return[];var i=n[t];return void 0===i?[]:"function"==typeof i?r?[i.listener||i]:[i]:r?function(e){for(var t=new Array(e.length),r=0;r<t.length;++r)t[r]=e[r].listener||e[r];return t}(i):b(i,i.length)}function v(e){var t=this._events;if(void 0!==t){var r=t[e];if("function"==typeof r)return 1;if(void 0!==r)return r.length}return 0}function b(e,t){for(var r=new Array(t),n=0;n<t;++n)r[n]=e[n];return r}Object.defineProperty(c,"defaultMaxListeners",{enumerable:!0,get:function(){return u},set:function(e){if("number"!=typeof e||e<0||o(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");u=e}}),c.init=function(){void 0!==this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},c.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||o(e))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+e+".");return this._maxListeners=e,this},c.prototype.getMaxListeners=function(){return f(this)},c.prototype.emit=function(e){for(var t=[],r=1;r<arguments.length;r++)t.push(arguments[r]);var n="error"===e,i=this._events;if(void 0!==i)n=n&&void 0===i.error;else if(!n)return!1;if(n){var o;if(t.length>0&&(o=t[0]),o instanceof Error)throw o;var c=new Error("Unhandled error."+(o?" ("+o.message+")":""));throw c.context=o,c}var u=i[e];if(void 0===u)return!1;if("function"==typeof u)s(u,this,t);else{var a=u.length,f=b(u,a);for(r=0;r<a;++r)s(f[r],this,t)}return!0},c.prototype.addListener=function(e,t){return l(this,e,t,!1)},c.prototype.on=c.prototype.addListener,c.prototype.prependListener=function(e,t){return l(this,e,t,!0)},c.prototype.once=function(e,t){return a(t),this.on(e,p(this,e,t)),this},c.prototype.prependOnceListener=function(e,t){return a(t),this.prependListener(e,p(this,e,t)),this},c.prototype.removeListener=function(e,t){var r,n,i,s,o;if(a(t),void 0===(n=this._events))return this;if(void 0===(r=n[e]))return this;if(r===t||r.listener===t)0==--this._eventsCount?this._events=Object.create(null):(delete n[e],n.removeListener&&this.emit("removeListener",e,r.listener||t));else if("function"!=typeof r){for(i=-1,s=r.length-1;s>=0;s--)if(r[s]===t||r[s].listener===t){o=r[s].listener,i=s;break}if(i<0)return this;0===i?r.shift():function(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}(r,i),1===r.length&&(n[e]=r[0]),void 0!==n.removeListener&&this.emit("removeListener",e,o||t)}return this},c.prototype.off=c.prototype.removeListener,c.prototype.removeAllListeners=function(e){var t,r,n;if(void 0===(r=this._events))return this;if(void 0===r.removeListener)return 0===arguments.length?(this._events=Object.create(null),this._eventsCount=0):void 0!==r[e]&&(0==--this._eventsCount?this._events=Object.create(null):delete r[e]),this;if(0===arguments.length){var i,s=Object.keys(r);for(n=0;n<s.length;++n)"removeListener"!==(i=s[n])&&this.removeAllListeners(i);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if("function"==typeof(t=r[e]))this.removeListener(e,t);else if(void 0!==t)for(n=t.length-1;n>=0;n--)this.removeListener(e,t[n]);return this},c.prototype.listeners=function(e){return h(this,e,!0)},c.prototype.rawListeners=function(e){return h(this,e,!1)},c.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):v.call(e,t)},c.prototype.listenerCount=v,c.prototype.eventNames=function(){return this._eventsCount>0?n(this._events):[]}},28:function(e,t,r){"use strict";var n,i=this&&this.__extends||(n=function(e,t){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])})(e,t)},function(e,t){function r(){this.constructor=e}n(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)});Object.defineProperty(t,"__esModule",{value:!0}),t.CustomError=void 0;var s="blockchain_link/",o={worker_not_found:"Worker not found",worker_invalid:"Invalid worker object",worker_timeout:"Worker timeout",worker_unknown_request:"Unknown message type:",worker_runtime:void 0,invalid_param:"Invalid parameter:",websocket_not_initialized:"WebSocket not initialized",websocket_no_url:"Cannot connect because no server was specified",websocket_timeout:"Websocket timeout",websocket_error_message:void 0,websocket_runtime_error:void 0},c=function(e){function t(t,r){void 0===r&&(r="");var n=e.call(this,r)||this;if(n.message="",n.message=r,"string"==typeof t){var i=0===t.indexOf(s)?t.substring(s.length,t.length):t;n.code=""+s+i;var c=o[i];"string"==typeof c&&(""===n.message?n.message=c:0===r.indexOf("+")&&(n.message=c+" "+r.substr(1,r.length)))}return"string"==typeof n.message&&""!==n.message||(n.message="Message not set"),n}return i(t,e),t}(Error);t.CustomError=c},482:function(e,t,r){"use strict";var n=this&&this.__assign||function(){return(n=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var i in t=arguments[r])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e}).apply(this,arguments)},i=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r),Object.defineProperty(e,n,{enumerable:!0,get:function(){return t[r]}})}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),s=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),o=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)"default"!==r&&Object.prototype.hasOwnProperty.call(e,r)&&i(t,e,r);return s(t,e),t},c=this&&this.__awaiter||function(e,t,r,n){return new(r||(r=Promise))((function(i,s){function o(e){try{u(n.next(e))}catch(e){s(e)}}function c(e){try{u(n.throw(e))}catch(e){s(e)}}function u(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(o,c)}u((n=n.apply(e,t||[])).next())}))},u=this&&this.__generator||function(e,t){var r,n,i,s,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return s={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function c(s){return function(c){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;o;)try{if(r=1,n&&(i=2&s[0]?n.return:s[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,s[1])).done)return i;switch(n=0,i&&(s=[2&s[0],i.value]),s[0]){case 0:case 1:i=s;break;case 4:return o.label++,{value:s[1],done:!1};case 5:o.label++,n=s[1],s=[0];continue;case 7:s=o.ops.pop(),o.trys.pop();continue;default:if(!(i=o.trys,(i=i.length>0&&i[i.length-1])||6!==s[0]&&2!==s[0])){o=0;continue}if(3===s[0]&&(!i||s[1]>i[0]&&s[1]<i[3])){o.label=s[1];break}if(6===s[0]&&o.label<i[1]){o.label=i[1],i=s;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(s);break}i[2]&&o.ops.pop(),o.trys.pop();continue}s=t.call(e,o)}catch(e){s=[6,e],n=0}finally{r=i=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,c])}}},a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});var f,l=r(28),d=r(50),p=a(r(483)),h=o(r(485)),v=new(a(r(92)).default)(postMessage),b=[],y=function(){f&&(f.dispose(),f.removeAllListeners(),f=void 0),b=[],v.removeAccounts(v.getAccounts()),v.removeAddresses(v.getAddresses()),v.clearSubscriptions()},m=function(){return c(void 0,void 0,void 0,(function(){var e,t,r,n,i,s;return u(this,(function(o){switch(o.label){case 0:if(f&&f.isConnected())return[2,f];if(e=v.getSettings(),t=e.server,r=e.timeout,n=e.pingTimeout,i=e.keepAlive,!t||!Array.isArray(t)||t.length<1)throw new l.CustomError("connect","Endpoint not set");b.length<1&&(b=v.shuffleEndpoints(t.slice(0))),v.debug("Connecting to",b[0]),s=new p.default({url:b[0],timeout:r,pingTimeout:n,keepAlive:i}),o.label=1;case 1:return o.trys.push([1,3,,4]),[4,s.connect()];case 2:return o.sent(),f=s,[3,4];case 3:if(o.sent(),v.debug("Websocket connection failed"),f=void 0,b.splice(0,1),b.length<1)throw new l.CustomError("connect","All backends are down");return[2,m()];case 4:return s.on("disconnected",(function(){v.response({id:-1,type:d.RESPONSES.DISCONNECTED,payload:!0}),y()})),v.response({id:-1,type:d.RESPONSES.CONNECTED}),v.debug("Connected"),[2,s]}}))}))},g=function(e){v.response({id:-1,type:d.RESPONSES.NOTIFICATION,payload:{type:"block",payload:{blockHeight:e.height,blockHash:e.hash}}})},_=function(e){if(e.tx){var t=e.address,r=v.getAccount(t);v.response({id:-1,type:d.RESPONSES.NOTIFICATION,payload:{type:"notification",payload:{descriptor:r?r.descriptor:t,tx:r?h.transformTransaction(r.descriptor,r.addresses,e.tx):h.transformTransaction(t,void 0,e.tx)}}})}},E=function(e){v.response({id:-1,type:d.RESPONSES.NOTIFICATION,payload:{type:"fiatRates",payload:{rates:e.rates}}})};onmessage=function(e){if(e.data){var t=e.data,r=t.id,i=t.type;switch(v.debug("onmessage",t),t.type){case d.MESSAGES.HANDSHAKE:v.setSettings(t.settings);break;case d.MESSAGES.CONNECT:m().then((function(){v.response({id:r,type:d.RESPONSES.CONNECT,payload:!0})})).catch((function(e){return v.errorHandler({id:r,error:e})}));break;case d.MESSAGES.GET_INFO:!function(e){c(void 0,void 0,void 0,(function(){var t,r,i;return u(this,(function(s){switch(s.label){case 0:return s.trys.push([0,3,,4]),[4,m()];case 1:return[4,(t=s.sent()).getServerInfo()];case 2:return r=s.sent(),v.response({id:e.id,type:d.RESPONSES.GET_INFO,payload:n({url:t.options.url},h.transformServerInfo(r))}),[3,4];case 3:return i=s.sent(),v.errorHandler({id:e.id,error:i}),[3,4];case 4:return[2]}}))}))}(t);break;case d.MESSAGES.GET_BLOCK_HASH:!function(e){c(void 0,void 0,void 0,(function(){var t,r;return u(this,(function(n){switch(n.label){case 0:return n.trys.push([0,3,,4]),[4,m()];case 1:return[4,n.sent().getBlockHash(e.payload)];case 2:return t=n.sent(),v.response({id:e.id,type:d.RESPONSES.GET_BLOCK_HASH,payload:t.hash}),[3,4];case 3:return r=n.sent(),v.errorHandler({id:e.id,error:r}),[3,4];case 4:return[2]}}))}))}(t);break;case d.MESSAGES.GET_ACCOUNT_INFO:!function(e){c(void 0,void 0,void 0,(function(){var t,r,n;return u(this,(function(i){switch(i.label){case 0:t=e.payload,i.label=1;case 1:return i.trys.push([1,4,,5]),[4,m()];case 2:return[4,i.sent().getAccountInfo(t)];case 3:return r=i.sent(),v.response({id:e.id,type:d.RESPONSES.GET_ACCOUNT_INFO,payload:h.transformAccountInfo(r)}),[3,5];case 4:return n=i.sent(),v.errorHandler({id:e.id,error:n}),[3,5];case 5:return[2]}}))}))}(t);break;case d.MESSAGES.GET_ACCOUNT_UTXO:!function(e){c(void 0,void 0,void 0,(function(){var t,r,n;return u(this,(function(i){switch(i.label){case 0:t=e.payload,i.label=1;case 1:return i.trys.push([1,4,,5]),[4,m()];case 2:return[4,i.sent().getAccountUtxo(t)];case 3:return r=i.sent(),v.response({id:e.id,type:d.RESPONSES.GET_ACCOUNT_UTXO,payload:h.transformAccountUtxo(r)}),[3,5];case 4:return n=i.sent(),v.errorHandler({id:e.id,error:n}),[3,5];case 5:return[2]}}))}))}(t);break;case d.MESSAGES.GET_TRANSACTION:!function(e){c(void 0,void 0,void 0,(function(){var t,r,n;return u(this,(function(i){switch(i.label){case 0:t=e.payload,i.label=1;case 1:return i.trys.push([1,4,,5]),[4,m()];case 2:return[4,i.sent().getTransaction(t)];case 3:return r=i.sent(),v.response({id:e.id,type:d.RESPONSES.GET_TRANSACTION,payload:{type:"blockbook",tx:r}}),[3,5];case 4:return n=i.sent(),v.errorHandler({id:e.id,error:n}),[3,5];case 5:return[2]}}))}))}(t);break;case d.MESSAGES.GET_ACCOUNT_BALANCE_HISTORY:!function(e){c(void 0,void 0,void 0,(function(){var t,r,n;return u(this,(function(i){switch(i.label){case 0:t=e.payload,i.label=1;case 1:return i.trys.push([1,4,,5]),[4,m()];case 2:return[4,i.sent().getAccountBalanceHistory(t)];case 3:return r=i.sent(),v.response({id:e.id,type:d.RESPONSES.GET_ACCOUNT_BALANCE_HISTORY,payload:r}),[3,5];case 4:return n=i.sent(),v.errorHandler({id:e.id,error:n}),[3,5];case 5:return[2]}}))}))}(t);break;case d.MESSAGES.GET_CURRENT_FIAT_RATES:!function(e){c(void 0,void 0,void 0,(function(){var t,r,n;return u(this,(function(i){switch(i.label){case 0:t=e.payload,i.label=1;case 1:return i.trys.push([1,4,,5]),[4,m()];case 2:return[4,i.sent().getCurrentFiatRates(t)];case 3:return r=i.sent(),v.response({id:e.id,type:d.RESPONSES.GET_CURRENT_FIAT_RATES,payload:r}),[3,5];case 4:return n=i.sent(),v.errorHandler({id:e.id,error:n}),[3,5];case 5:return[2]}}))}))}(t);break;case d.MESSAGES.GET_FIAT_RATES_FOR_TIMESTAMPS:!function(e){c(void 0,void 0,void 0,(function(){var t,r,n;return u(this,(function(i){switch(i.label){case 0:t=e.payload,i.label=1;case 1:return i.trys.push([1,4,,5]),[4,m()];case 2:return[4,i.sent().getFiatRatesForTimestamps(t)];case 3:return r=i.sent().tickers,v.response({id:e.id,type:d.RESPONSES.GET_FIAT_RATES_FOR_TIMESTAMPS,payload:{tickers:r}}),[3,5];case 4:return n=i.sent(),v.errorHandler({id:e.id,error:n}),[3,5];case 5:return[2]}}))}))}(t);break;case d.MESSAGES.GET_FIAT_RATES_TICKERS_LIST:!function(e){c(void 0,void 0,void 0,(function(){var t,r,n;return u(this,(function(i){switch(i.label){case 0:t=e.payload,i.label=1;case 1:return i.trys.push([1,4,,5]),[4,m()];case 2:return[4,i.sent().getFiatRatesTickersList(t)];case 3:return r=i.sent(),v.response({id:e.id,type:d.RESPONSES.GET_FIAT_RATES_TICKERS_LIST,payload:{ts:r.ts,availableCurrencies:r.available_currencies}}),[3,5];case 4:return n=i.sent(),v.errorHandler({id:e.id,error:n}),[3,5];case 5:return[2]}}))}))}(t);break;case d.MESSAGES.ESTIMATE_FEE:!function(e){c(void 0,void 0,void 0,(function(){var t,r;return u(this,(function(n){switch(n.label){case 0:return n.trys.push([0,3,,4]),[4,m()];case 1:return[4,n.sent().estimateFee(e.payload)];case 2:return t=n.sent(),v.response({id:e.id,type:d.RESPONSES.ESTIMATE_FEE,payload:t}),[3,4];case 3:return r=n.sent(),v.errorHandler({id:e.id,error:r}),[3,4];case 4:return[2]}}))}))}(t);break;case d.MESSAGES.PUSH_TRANSACTION:!function(e){c(void 0,void 0,void 0,(function(){var t,r;return u(this,(function(n){switch(n.label){case 0:return n.trys.push([0,3,,4]),[4,m()];case 1:return[4,n.sent().pushTransaction(e.payload)];case 2:return t=n.sent(),v.response({id:e.id,type:d.RESPONSES.PUSH_TRANSACTION,payload:t.result}),[3,4];case 3:return r=n.sent(),v.errorHandler({id:e.id,error:r}),[3,4];case 4:return[2]}}))}))}(t);break;case d.MESSAGES.SUBSCRIBE:!function(e){c(void 0,void 0,void 0,(function(){var t,r,n;return u(this,(function(i){switch(i.label){case 0:t=e.payload,i.label=1;case 1:return i.trys.push([1,11,,12]),r=void 0,"accounts"!==t.type?[3,3]:[4,(a=t.accounts,c(void 0,void 0,void 0,(function(){var e;return u(this,(function(t){switch(t.label){case 0:return v.addAccounts(a),[4,m()];case 1:return e=t.sent(),v.getSubscription("notification")||(e.on("notification",_),v.addSubscription("notification")),[2,e.subscribeAddresses(v.getAddresses())]}}))})))];case 2:return r=i.sent(),[3,10];case 3:return"addresses"!==t.type?[3,5]:[4,(o=t.addresses,c(void 0,void 0,void 0,(function(){var e;return u(this,(function(t){switch(t.label){case 0:return v.addAddresses(o),[4,m()];case 1:return e=t.sent(),v.getSubscription("notification")||(e.on("notification",_),v.addSubscription("notification")),[2,e.subscribeAddresses(v.getAddresses())]}}))})))];case 4:return r=i.sent(),[3,10];case 5:return"block"!==t.type?[3,7]:[4,c(void 0,void 0,void 0,(function(){var e;return u(this,(function(t){switch(t.label){case 0:return v.getSubscription("block")?[2,{subscribed:!0}]:[4,m()];case 1:return e=t.sent(),v.addSubscription("block"),e.on("block",g),[2,e.subscribeBlock()]}}))}))];case 6:return r=i.sent(),[3,10];case 7:return"fiatRates"!==t.type?[3,9]:[4,(s=t.currency,c(void 0,void 0,void 0,(function(){var e;return u(this,(function(t){switch(t.label){case 0:return[4,m()];case 1:return e=t.sent(),v.getSubscription("fiatRates")||(v.addSubscription("fiatRates"),e.on("fiatRates",E)),[2,e.subscribeFiatRates(s)]}}))})))];case 8:return r=i.sent(),[3,10];case 9:throw new l.CustomError("invalid_param","+type");case 10:return v.response({id:e.id,type:d.RESPONSES.SUBSCRIBE,payload:r}),[3,12];case 11:return n=i.sent(),v.errorHandler({id:e.id,error:n}),[3,12];case 12:return[2]}var s,o,a}))}))}(t);break;case d.MESSAGES.UNSUBSCRIBE:!function(e){c(void 0,void 0,void 0,(function(){var t,r,n;return u(this,(function(i){switch(i.label){case 0:t=e.payload,i.label=1;case 1:return i.trys.push([1,11,,12]),r=void 0,"accounts"!==t.type?[3,3]:[4,(o=t.accounts,c(void 0,void 0,void 0,(function(){var e,t;return u(this,(function(r){switch(r.label){case 0:return v.removeAccounts(o||v.getAccounts()),[4,m()];case 1:return e=r.sent(),(t=v.getAddresses()).length<1?(e.removeListener("notification",_),v.removeSubscription("notification"),[2,e.unsubscribeAddresses()]):[2,e.subscribeAddresses(t)]}}))})))];case 2:return r=i.sent(),[3,10];case 3:return"addresses"!==t.type?[3,5]:[4,(s=t.addresses,c(void 0,void 0,void 0,(function(){var e,t;return u(this,(function(r){switch(r.label){case 0:return[4,m()];case 1:return e=r.sent(),s||v.removeAccounts(v.getAccounts()),(t=v.removeAddresses(s||v.getAddresses())).length<1?(e.removeListener("notification",_),v.removeSubscription("notification"),[2,e.unsubscribeAddresses()]):[2,e.subscribeAddresses(t)]}}))})))];case 4:return r=i.sent(),[3,10];case 5:return"block"!==t.type?[3,7]:[4,c(void 0,void 0,void 0,(function(){var e;return u(this,(function(t){switch(t.label){case 0:return v.getSubscription("block")?[4,m()]:[2,{subscribed:!1}];case 1:return(e=t.sent()).removeListener("block",g),v.removeSubscription("block"),[2,e.unsubscribeBlock()]}}))}))];case 6:return r=i.sent(),[3,10];case 7:return"fiatRates"!==t.type?[3,9]:[4,c(void 0,void 0,void 0,(function(){var e;return u(this,(function(t){switch(t.label){case 0:return v.getSubscription("fiatRates")?[4,m()]:[2,{subscribed:!1}];case 1:return(e=t.sent()).removeListener("fiatRates",g),v.removeSubscription("fiatRates"),[2,e.unsubscribeFiatRates()]}}))}))];case 8:return r=i.sent(),[3,10];case 9:throw new l.CustomError("invalid_param","+type");case 10:return v.response({id:e.id,type:d.RESPONSES.UNSUBSCRIBE,payload:r}),[3,12];case 11:return n=i.sent(),v.errorHandler({id:e.id,error:n}),[3,12];case 12:return[2]}var s,o}))}))}(t);break;case d.MESSAGES.DISCONNECT:!function(e){c(void 0,void 0,void 0,(function(){var t;return u(this,(function(r){switch(r.label){case 0:if(!f)return v.response({id:e.id,type:d.RESPONSES.DISCONNECTED,payload:!0}),[2];r.label=1;case 1:return r.trys.push([1,3,,4]),[4,f.disconnect()];case 2:return r.sent(),v.response({id:e.id,type:d.RESPONSES.DISCONNECTED,payload:!0}),[3,4];case 3:return t=r.sent(),v.errorHandler({id:e.id,error:t}),[3,4];case 4:return[2]}}))}))}(t);break;case"terminate":y();break;default:v.errorHandler({id:r,error:new l.CustomError("worker_unknown_request","+"+i)})}}},v.handshake()},483:function(e,t,r){"use strict";var n,i=this&&this.__extends||(n=function(e,t){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])})(e,t)},function(e,t){function r(){this.constructor=e}n(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}),s=this&&this.__awaiter||function(e,t,r,n){return new(r||(r=Promise))((function(i,s){function o(e){try{u(n.next(e))}catch(e){s(e)}}function c(e){try{u(n.throw(e))}catch(e){s(e)}}function u(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(o,c)}u((n=n.apply(e,t||[])).next())}))},o=this&&this.__generator||function(e,t){var r,n,i,s,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return s={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function c(s){return function(c){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;o;)try{if(r=1,n&&(i=2&s[0]?n.return:s[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,s[1])).done)return i;switch(n=0,i&&(s=[2&s[0],i.value]),s[0]){case 0:case 1:i=s;break;case 4:return o.label++,{value:s[1],done:!1};case 5:o.label++,n=s[1],s=[0];continue;case 7:s=o.ops.pop(),o.trys.pop();continue;default:if(!(i=o.trys,(i=i.length>0&&i[i.length-1])||6!==s[0]&&2!==s[0])){o=0;continue}if(3===s[0]&&(!i||s[1]>i[0]&&s[1]<i[3])){o.label=s[1];break}if(6===s[0]&&o.label<i[1]){o.label=i[1],i=s;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(s);break}i[2]&&o.ops.pop(),o.trys.pop();continue}s=t.call(e,o)}catch(e){s=[6,e],n=0}finally{r=i=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,c])}}},c=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});var u=c(r(70)),a=r(14),f=r(28),l=r(484),d=new f.CustomError("websocket_not_initialized"),p=function(e){function t(t){var r=e.call(this)||this;return r.messageID=0,r.messages=[],r.subscriptions=[],r.send=function(e,t){void 0===t&&(t={});var n=r.ws;if(!n)throw d;var i=r.messageID.toString(),s=l.create(i),o={id:i,method:e,params:t};return r.messageID++,r.messages.push(s),r.setConnectionTimeout(),r.setPingTimeout(),n.send(JSON.stringify(o)),s.promise},r.setMaxListeners(1/0),r.options=t,r}return i(t,e),t.prototype.setConnectionTimeout=function(){this.clearConnectionTimeout(),this.connectionTimeout=setTimeout(this.onTimeout.bind(this),this.options.timeout||2e4)},t.prototype.clearConnectionTimeout=function(){this.connectionTimeout&&(clearTimeout(this.connectionTimeout),this.connectionTimeout=void 0)},t.prototype.setPingTimeout=function(){this.pingTimeout&&clearTimeout(this.pingTimeout),this.pingTimeout=setTimeout(this.onPing.bind(this),this.options.pingTimeout||5e4)},t.prototype.onTimeout=function(){var e=this.ws;if(e)if(e.listenerCount("open")>0){e.emit("error","Websocket timeout");try{e.close()}catch(e){}}else this.messages.forEach((function(e){return e.reject(new f.CustomError("websocket_timeout"))})),e.close()},t.prototype.onPing=function(){return s(this,void 0,void 0,(function(){return o(this,(function(e){switch(e.label){case 0:return this.ws&&this.isConnected()?this.subscriptions.length>0||this.options.keepAlive?[4,this.getBlockHash(0)]:[3,2]:[3,3];case 1:return e.sent(),[3,3];case 2:try{this.ws.close()}catch(e){}e.label=3;case 3:return[2]}}))}))},t.prototype.onError=function(){this.dispose()},t.prototype.onmessage=function(e){try{var t=JSON.parse(e),r=t.id,n=t.data,i=this.messages.find((function(e){return e.id===r}));if(i)n.error?i.reject(new f.CustomError("websocket_error_message",n.error.message)):i.resolve(n),this.messages.splice(this.messages.indexOf(i),1);else{var s=this.subscriptions.find((function(e){return e&&e.id===r}));s&&s.callback(n)}}catch(e){}0===this.messages.length&&this.clearConnectionTimeout(),this.setPingTimeout()},t.prototype.connect=function(){var e=this,t=this.options.url;if("string"!=typeof t)throw new f.CustomError("websocket_no_url");if(t.startsWith("https")&&(t=t.replace("https","wss")),t.startsWith("http")&&(t=t.replace("http","ws")),!t.endsWith("/websocket")){var r=t.endsWith("/")?"websocket":"/websocket";t+=r}this.setConnectionTimeout();var n=l.create(-1),i=new u.default(t);return"function"==typeof i.setMaxListeners&&i.setMaxListeners(1/0),i.once("error",(function(t){e.dispose(),n.reject(new f.CustomError("websocket_runtime_error",t.message))})),i.on("open",(function(){e.init(),n.resolve()})),this.ws=i,n.promise},t.prototype.init=function(){var e=this,t=this.ws;if(!t||!this.isConnected())throw Error("Blockbook websocket init cannot be called");this.clearConnectionTimeout(),t.removeAllListeners(),t.on("error",this.onError.bind(this)),t.on("message",this.onmessage.bind(this)),t.on("close",(function(){e.emit("disconnected"),e.dispose()}))},t.prototype.disconnect=function(){this.ws&&this.ws.close()},t.prototype.isConnected=function(){var e=this.ws;return e&&e.readyState===u.default.OPEN},t.prototype.getServerInfo=function(){return this.send("getInfo")},t.prototype.getBlockHash=function(e){return this.send("getBlockHash",{height:e})},t.prototype.getAccountInfo=function(e){return this.send("getAccountInfo",e)},t.prototype.getAccountUtxo=function(e){return this.send("getAccountUtxo",{descriptor:e})},t.prototype.getTransaction=function(e){return this.send("getTransaction",{txid:e})},t.prototype.pushTransaction=function(e){return this.send("sendTransaction",{hex:e})},t.prototype.estimateFee=function(e){return this.send("estimateFee",e)},t.prototype.getCurrentFiatRates=function(e){return this.send("getCurrentFiatRates",e)},t.prototype.getAccountBalanceHistory=function(e){return this.send("getBalanceHistory",e)},t.prototype.getFiatRatesForTimestamps=function(e){return this.send("getFiatRatesForTimestamps",e)},t.prototype.getFiatRatesTickersList=function(e){return this.send("getFiatRatesTickersList",e)},t.prototype.subscribeAddresses=function(e){var t=this,r=this.subscriptions.findIndex((function(e){return"notification"===e.type}));r>=0&&this.subscriptions.splice(r,1);var n=this.messageID.toString();return this.subscriptions.push({id:n,type:"notification",callback:function(e){t.emit("notification",e)}}),this.send("subscribeAddresses",{addresses:e})},t.prototype.unsubscribeAddresses=function(){var e=this.subscriptions.findIndex((function(e){return"notification"===e.type}));return e>=0?(this.subscriptions.splice(e,1),this.send("unsubscribeAddresses")):{subscribed:!1}},t.prototype.subscribeBlock=function(){var e=this,t=this.subscriptions.findIndex((function(e){return"block"===e.type}));t>=0&&this.subscriptions.splice(t,1);var r=this.messageID.toString();return this.subscriptions.push({id:r,type:"block",callback:function(t){e.emit("block",t)}}),this.send("subscribeNewBlock")},t.prototype.unsubscribeBlock=function(){var e=this.subscriptions.findIndex((function(e){return"block"===e.type}));return e>=0?(this.subscriptions.splice(e,1),this.send("unsubscribeNewBlock")):{subscribed:!1}},t.prototype.subscribeFiatRates=function(e){var t=this,r=this.subscriptions.findIndex((function(e){return"fiatRates"===e.type}));r>=0&&this.subscriptions.splice(r,1);var n=this.messageID.toString();return this.subscriptions.push({id:n,type:"fiatRates",callback:function(e){t.emit("fiatRates",e)}}),this.send("subscribeFiatRates",{currency:e})},t.prototype.unsubscribeFiatRates=function(){var e=this.subscriptions.findIndex((function(e){return"fiatRates"===e.type}));return e>=0?(this.subscriptions.splice(e,1),this.send("unsubscribeFiatRates")):{subscribed:!1}},t.prototype.dispose=function(){this.pingTimeout&&clearTimeout(this.pingTimeout),this.connectionTimeout&&clearTimeout(this.connectionTimeout);var e=this.ws;this.isConnected()&&this.disconnect(),e&&e.removeAllListeners(),this.removeAllListeners()},t}(a.EventEmitter);t.default=p},484:function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.create=void 0,t.create=function(e){var t=function(){},r=function(){},n=new Promise((function(e,n){t=e,r=n}));return{id:e,resolve:t,reject:r,promise:n}}},485:function(e,t,r){"use strict";var n=this&&this.__assign||function(){return(n=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var i in t=arguments[r])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e}).apply(this,arguments)},i=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.transformAccountUtxo=t.transformAccountInfo=t.transformAddresses=t.transformTokenInfo=t.transformTransaction=t.filterTokenTransfers=t.filterTargets=t.transformServerInfo=void 0;var s=i(r(6));t.transformServerInfo=function(e){return{name:e.name,shortcut:e.shortcut,testnet:e.testnet,version:e.version,decimals:e.decimals,blockHeight:e.bestHeight,blockHash:e.bestHash}};t.filterTargets=function(e,t){if("string"==typeof e&&(e=[e]),!(e&&Array.isArray(e)&&t&&Array.isArray(t)))return[];var r=e.map((function(e){return"string"==typeof e?e:"object"==typeof e&&"string"==typeof e.address?e.address:null}));return t.filter((function(e){return!(!e||!Array.isArray(e.addresses))&&e.addresses.filter((function(e){return r.indexOf(e)>=0})).length>0}))};t.filterTokenTransfers=function(e,t){if("string"==typeof e&&(e=[e]),!(e&&Array.isArray(e)&&t&&Array.isArray(t)))return[];var r=e.map((function(e){return"string"==typeof e?e:"object"==typeof e&&"string"==typeof e.address?e.address:null}));return t.filter((function(e){return!(!e||"object"!=typeof e)&&(e.from&&r.indexOf(e.from)>=0||e.to&&r.indexOf(e.to)>=0)})).map((function(e){var t=e.from&&r.indexOf(e.from)>=0,n=e.to&&r.indexOf(e.to)>=0,i="unknown";return t&&n?i="self":(t&&(i="sent"),n&&(i="recv")),{type:i,name:e.name,symbol:e.symbol,address:e.token,decimals:e.decimals||0,amount:e.value,from:e.from,to:e.to}}))};var o=function(e,t,r){return void 0===t&&(t="0"),void 0===r&&(r="sum"),e.reduce((function(e,t){return"string"!=typeof t.value?e:"sum"===r?e.plus(t.value):e.minus(t.value)}),new s.default(t)).toString()};t.transformTransaction=function(e,r,n){var i,c,u=r?r.change.concat(r.used,r.unused):[e],a=Array.isArray(n.vin)?n.vin.length:0,f=Array.isArray(n.vout)?n.vout.length:0,l=t.filterTargets(u,n.vin),d=t.filterTargets(u,n.vout),p=r?t.filterTargets(r.change,n.vout):[],h=t.filterTokenTransfers(u,n.tokenTransfers),v=[],b=n.value,y=o(a?n.vin:[]),m=o(f?n.vout:[]);if(0===l.length&&0===d.length&&0===h.length)i="unknown";else if(a>0&&f>0&&l.length===a&&d.length===f)i="self",v=n.vout.filter((function(e){return p.indexOf(e)<0})),b=n.fees;else if(0===l.length&&(d.length>0||h.length>0))i="recv",b="0",d.length>0&&(v=d,b=o(d,b));else if(i="sent",0===h.length&&f&&(v=n.vout.filter((function(e){return p.indexOf(e)<0}))),n.ethereumSpecific)b=h.length>0||0===n.ethereumSpecific.status?n.fees:n.value;else if(f){var g=o(l,"0");b=o(d,g,"reduce")}a&&n.vin.forEach((function(e){"number"==typeof e.sequence&&e.sequence<4294967294&&(c=!0)}));var _=n.fees;return n.ethereumSpecific&&!n.ethereumSpecific.gasUsed&&(_=new s.default(n.ethereumSpecific.gasPrice).times(n.ethereumSpecific.gasLimit).toString()),{type:i,txid:n.txid,blockTime:n.blockTime,blockHeight:n.blockHeight,blockHash:n.blockHash,amount:b,fee:_,targets:v.filter((function(e){return"object"==typeof e})).map((function(e){return function(e,t){return{n:e.n||0,addresses:e.addresses,isAddress:e.isAddress,amount:e.value,coinbase:e.coinbase,isAccountTarget:!!t.includes(e)||void 0}}(e,d)})),tokens:h,rbf:c,ethereumSpecific:n.ethereumSpecific,details:{vin:n.vin,vout:n.vout,size:"string"==typeof n.hex?n.hex.length/2:0,totalInput:y?y.toString():"0",totalOutput:m?m.toString():"0"}}};t.transformTokenInfo=function(e){if(e&&Array.isArray(e)){var t=e.reduce((function(e,t){return"ERC20"!==t.type?e:e.concat([{type:t.type,name:t.name,symbol:t.symbol,address:t.contract,balance:t.balance,decimals:t.decimals||0}])}),[]);return t.length>0?t:void 0}};t.transformAddresses=function(e){if(e&&Array.isArray(e)){var t=e.reduce((function(e,t){return"XPUBAddress"!==t.type?e:e.concat([{address:t.name,path:t.path,transfers:t.transfers,balance:t.balance,sent:t.totalSent,received:t.totalReceived}])}),[]);if(!(t.length<1)){var r=t.filter((function(e){return"1"===e.path.split("/")[4]})),n=t.filter((function(e){return r.indexOf(e)<0}));return{change:r,used:n.filter((function(e){return e.transfers>0})),unused:n.filter((function(e){return 0===e.transfers}))}}}};t.transformAccountInfo=function(e){var r;"number"==typeof e.page&&(r={index:e.page,size:e.itemsOnPage,total:e.totalPages});var i={};if("string"==typeof e.nonce&&(i.nonce=e.nonce),e.erc20Contract){var o=t.transformTokenInfo([n(n({},e.erc20Contract),{type:e.erc20Contract.type||"ERC20"})]);if(o){var c=o[0];i.erc20Contract=c}}Object.keys(i).length<1&&(i=void 0);var u=e.address,a=t.transformAddresses(e.tokens),f=t.transformTokenInfo(e.tokens),l=new s.default(e.unconfirmedBalance),d=l.isNaN()||l.isZero()?e.balance:l.plus(e.balance).toString(),p=0===e.txs&&0===e.unconfirmedTxs&&new s.default(d).isZero();return{descriptor:u,balance:e.balance,availableBalance:d,empty:p,tokens:f,addresses:a,history:{total:e.txs,tokens:"number"==typeof e.nonTokenTxs?e.txs-e.nonTokenTxs:void 0,unconfirmed:e.unconfirmedTxs,transactions:e.transactions?e.transactions.map((function(e){return t.transformTransaction(u,a,e)})):void 0},misc:i,page:r}};t.transformAccountUtxo=function(e){return e.map((function(e){return{txid:e.txid,vout:e.vout,amount:e.value,blockHeight:e.height,address:e.address,path:e.path,confirmations:e.confirmations,coinbase:e.coinbase}}))}},50:function(e,t,r){"use strict";var n=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r),Object.defineProperty(e,n,{enumerable:!0,get:function(){return t[r]}})}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),i=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),s=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)"default"!==r&&Object.prototype.hasOwnProperty.call(e,r)&&n(t,e,r);return i(t,e),t};Object.defineProperty(t,"__esModule",{value:!0}),t.NETWORKS=t.RESPONSES=t.MESSAGES=void 0;var o=s(r(90));t.MESSAGES=o;var c=s(r(91));t.RESPONSES=c,t.NETWORKS={RIPPLE:"ripple",BLOCKBOOK:"blockbook"}},6:function(e,t,r){var n;!function(i){"use strict";var s,o=/^-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i,c=Math.ceil,u=Math.floor,a="[BigNumber Error] ",f=a+"Number primitive has more than 15 significant digits: ",l=1e14,d=[1,10,100,1e3,1e4,1e5,1e6,1e7,1e8,1e9,1e10,1e11,1e12,1e13],p=1e9;function h(e){var t=0|e;return e>0||e===t?t:t-1}function v(e){for(var t,r,n=1,i=e.length,s=e[0]+"";n<i;){for(r=14-(t=e[n++]+"").length;r--;t="0"+t);s+=t}for(i=s.length;48===s.charCodeAt(--i););return s.slice(0,i+1||1)}function b(e,t){var r,n,i=e.c,s=t.c,o=e.s,c=t.s,u=e.e,a=t.e;if(!o||!c)return null;if(r=i&&!i[0],n=s&&!s[0],r||n)return r?n?0:-c:o;if(o!=c)return o;if(r=o<0,n=u==a,!i||!s)return n?0:!i^r?1:-1;if(!n)return u>a^r?1:-1;for(c=(u=i.length)<(a=s.length)?u:a,o=0;o<c;o++)if(i[o]!=s[o])return i[o]>s[o]^r?1:-1;return u==a?0:u>a^r?1:-1}function y(e,t,r,n){if(e<t||e>r||e!==u(e))throw Error(a+(n||"Argument")+("number"==typeof e?e<t||e>r?" out of range: ":" not an integer: ":" not a primitive number: ")+String(e))}function m(e){var t=e.c.length-1;return h(e.e/14)==t&&e.c[t]%2!=0}function g(e,t){return(e.length>1?e.charAt(0)+"."+e.slice(1):e)+(t<0?"e":"e+")+t}function _(e,t,r){var n,i;if(t<0){for(i=r+".";++t;i+=r);e=i+e}else if(++t>(n=e.length)){for(i=r,t-=n;--t;i+=r);e+=i}else t<n&&(e=e.slice(0,t)+"."+e.slice(t));return e}(s=function e(t){var r,n,i,s,E,S,T,A,O,w=B.prototype={constructor:B,toString:null,valueOf:null},N=new B(1),C=20,R=4,I=-7,k=21,x=-1e7,P=1e7,L=!1,G=1,M=0,U={prefix:"",groupSize:3,secondaryGroupSize:0,groupSeparator:",",decimalSeparator:".",fractionGroupSize:0,fractionGroupSeparator:" ",suffix:""},F="0123456789abcdefghijklmnopqrstuvwxyz";function B(e,t){var r,s,c,a,l,d,p,h,v=this;if(!(v instanceof B))return new B(e,t);if(null==t){if(e&&!0===e._isBigNumber)return v.s=e.s,void(!e.c||e.e>P?v.c=v.e=null:e.e<x?v.c=[v.e=0]:(v.e=e.e,v.c=e.c.slice()));if((d="number"==typeof e)&&0*e==0){if(v.s=1/e<0?(e=-e,-1):1,e===~~e){for(a=0,l=e;l>=10;l/=10,a++);return void(a>P?v.c=v.e=null:(v.e=a,v.c=[e]))}h=String(e)}else{if(!o.test(h=String(e)))return i(v,h,d);v.s=45==h.charCodeAt(0)?(h=h.slice(1),-1):1}(a=h.indexOf("."))>-1&&(h=h.replace(".","")),(l=h.search(/e/i))>0?(a<0&&(a=l),a+=+h.slice(l+1),h=h.substring(0,l)):a<0&&(a=h.length)}else{if(y(t,2,F.length,"Base"),10==t)return K(v=new B(e),C+v.e+1,R);if(h=String(e),d="number"==typeof e){if(0*e!=0)return i(v,h,d,t);if(v.s=1/e<0?(h=h.slice(1),-1):1,B.DEBUG&&h.replace(/^0\.0*|\./,"").length>15)throw Error(f+e)}else v.s=45===h.charCodeAt(0)?(h=h.slice(1),-1):1;for(r=F.slice(0,t),a=l=0,p=h.length;l<p;l++)if(r.indexOf(s=h.charAt(l))<0){if("."==s){if(l>a){a=p;continue}}else if(!c&&(h==h.toUpperCase()&&(h=h.toLowerCase())||h==h.toLowerCase()&&(h=h.toUpperCase()))){c=!0,l=-1,a=0;continue}return i(v,String(e),d,t)}d=!1,(a=(h=n(h,t,10,v.s)).indexOf("."))>-1?h=h.replace(".",""):a=h.length}for(l=0;48===h.charCodeAt(l);l++);for(p=h.length;48===h.charCodeAt(--p););if(h=h.slice(l,++p)){if(p-=l,d&&B.DEBUG&&p>15&&(e>9007199254740991||e!==u(e)))throw Error(f+v.s*e);if((a=a-l-1)>P)v.c=v.e=null;else if(a<x)v.c=[v.e=0];else{if(v.e=a,v.c=[],l=(a+1)%14,a<0&&(l+=14),l<p){for(l&&v.c.push(+h.slice(0,l)),p-=14;l<p;)v.c.push(+h.slice(l,l+=14));l=14-(h=h.slice(l)).length}else l-=p;for(;l--;h+="0");v.c.push(+h)}}else v.c=[v.e=0]}function j(e,t,r,n){var i,s,o,c,u;if(null==r?r=R:y(r,0,8),!e.c)return e.toString();if(i=e.c[0],o=e.e,null==t)u=v(e.c),u=1==n||2==n&&(o<=I||o>=k)?g(u,o):_(u,o,"0");else if(s=(e=K(new B(e),t,r)).e,c=(u=v(e.c)).length,1==n||2==n&&(t<=s||s<=I)){for(;c<t;u+="0",c++);u=g(u,s)}else if(t-=o,u=_(u,s,"0"),s+1>c){if(--t>0)for(u+=".";t--;u+="0");}else if((t+=s-c)>0)for(s+1==c&&(u+=".");t--;u+="0");return e.s<0&&i?"-"+u:u}function H(e,t){for(var r,n=1,i=new B(e[0]);n<e.length;n++){if(!(r=new B(e[n])).s){i=r;break}t.call(i,r)&&(i=r)}return i}function D(e,t,r){for(var n=1,i=t.length;!t[--i];t.pop());for(i=t[0];i>=10;i/=10,n++);return(r=n+14*r-1)>P?e.c=e.e=null:r<x?e.c=[e.e=0]:(e.e=r,e.c=t),e}function K(e,t,r,n){var i,s,o,a,f,p,h,v=e.c,b=d;if(v){e:{for(i=1,a=v[0];a>=10;a/=10,i++);if((s=t-i)<0)s+=14,o=t,h=(f=v[p=0])/b[i-o-1]%10|0;else if((p=c((s+1)/14))>=v.length){if(!n)break e;for(;v.length<=p;v.push(0));f=h=0,i=1,o=(s%=14)-14+1}else{for(f=a=v[p],i=1;a>=10;a/=10,i++);h=(o=(s%=14)-14+i)<0?0:f/b[i-o-1]%10|0}if(n=n||t<0||null!=v[p+1]||(o<0?f:f%b[i-o-1]),n=r<4?(h||n)&&(0==r||r==(e.s<0?3:2)):h>5||5==h&&(4==r||n||6==r&&(s>0?o>0?f/b[i-o]:0:v[p-1])%10&1||r==(e.s<0?8:7)),t<1||!v[0])return v.length=0,n?(t-=e.e+1,v[0]=b[(14-t%14)%14],e.e=-t||0):v[0]=e.e=0,e;if(0==s?(v.length=p,a=1,p--):(v.length=p+1,a=b[14-s],v[p]=o>0?u(f/b[i-o]%b[o])*a:0),n)for(;;){if(0==p){for(s=1,o=v[0];o>=10;o/=10,s++);for(o=v[0]+=a,a=1;o>=10;o/=10,a++);s!=a&&(e.e++,v[0]==l&&(v[0]=1));break}if(v[p]+=a,v[p]!=l)break;v[p--]=0,a=1}for(s=v.length;0===v[--s];v.pop());}e.e>P?e.c=e.e=null:e.e<x&&(e.c=[e.e=0])}return e}function W(e){var t,r=e.e;return null===r?e.toString():(t=v(e.c),t=r<=I||r>=k?g(t,r):_(t,r,"0"),e.s<0?"-"+t:t)}return B.clone=e,B.ROUND_UP=0,B.ROUND_DOWN=1,B.ROUND_CEIL=2,B.ROUND_FLOOR=3,B.ROUND_HALF_UP=4,B.ROUND_HALF_DOWN=5,B.ROUND_HALF_EVEN=6,B.ROUND_HALF_CEIL=7,B.ROUND_HALF_FLOOR=8,B.EUCLID=9,B.config=B.set=function(e){var t,r;if(null!=e){if("object"!=typeof e)throw Error(a+"Object expected: "+e);if(e.hasOwnProperty(t="DECIMAL_PLACES")&&(y(r=e[t],0,p,t),C=r),e.hasOwnProperty(t="ROUNDING_MODE")&&(y(r=e[t],0,8,t),R=r),e.hasOwnProperty(t="EXPONENTIAL_AT")&&((r=e[t])&&r.pop?(y(r[0],-p,0,t),y(r[1],0,p,t),I=r[0],k=r[1]):(y(r,-p,p,t),I=-(k=r<0?-r:r))),e.hasOwnProperty(t="RANGE"))if((r=e[t])&&r.pop)y(r[0],-p,-1,t),y(r[1],1,p,t),x=r[0],P=r[1];else{if(y(r,-p,p,t),!r)throw Error(a+t+" cannot be zero: "+r);x=-(P=r<0?-r:r)}if(e.hasOwnProperty(t="CRYPTO")){if((r=e[t])!==!!r)throw Error(a+t+" not true or false: "+r);if(r){if("undefined"==typeof crypto||!crypto||!crypto.getRandomValues&&!crypto.randomBytes)throw L=!r,Error(a+"crypto unavailable");L=r}else L=r}if(e.hasOwnProperty(t="MODULO_MODE")&&(y(r=e[t],0,9,t),G=r),e.hasOwnProperty(t="POW_PRECISION")&&(y(r=e[t],0,p,t),M=r),e.hasOwnProperty(t="FORMAT")){if("object"!=typeof(r=e[t]))throw Error(a+t+" not an object: "+r);U=r}if(e.hasOwnProperty(t="ALPHABET")){if("string"!=typeof(r=e[t])||/^.?$|[+\-.\s]|(.).*\1/.test(r))throw Error(a+t+" invalid: "+r);F=r}}return{DECIMAL_PLACES:C,ROUNDING_MODE:R,EXPONENTIAL_AT:[I,k],RANGE:[x,P],CRYPTO:L,MODULO_MODE:G,POW_PRECISION:M,FORMAT:U,ALPHABET:F}},B.isBigNumber=function(e){if(!e||!0!==e._isBigNumber)return!1;if(!B.DEBUG)return!0;var t,r,n=e.c,i=e.e,s=e.s;e:if("[object Array]"=={}.toString.call(n)){if((1===s||-1===s)&&i>=-p&&i<=p&&i===u(i)){if(0===n[0]){if(0===i&&1===n.length)return!0;break e}if((t=(i+1)%14)<1&&(t+=14),String(n[0]).length==t){for(t=0;t<n.length;t++)if((r=n[t])<0||r>=l||r!==u(r))break e;if(0!==r)return!0}}}else if(null===n&&null===i&&(null===s||1===s||-1===s))return!0;throw Error(a+"Invalid BigNumber: "+e)},B.maximum=B.max=function(){return H(arguments,w.lt)},B.minimum=B.min=function(){return H(arguments,w.gt)},B.random=(s=9007199254740992*Math.random()&2097151?function(){return u(9007199254740992*Math.random())}:function(){return 8388608*(1073741824*Math.random()|0)+(8388608*Math.random()|0)},function(e){var t,r,n,i,o,f=0,l=[],h=new B(N);if(null==e?e=C:y(e,0,p),i=c(e/14),L)if(crypto.getRandomValues){for(t=crypto.getRandomValues(new Uint32Array(i*=2));f<i;)(o=131072*t[f]+(t[f+1]>>>11))>=9e15?(r=crypto.getRandomValues(new Uint32Array(2)),t[f]=r[0],t[f+1]=r[1]):(l.push(o%1e14),f+=2);f=i/2}else{if(!crypto.randomBytes)throw L=!1,Error(a+"crypto unavailable");for(t=crypto.randomBytes(i*=7);f<i;)(o=281474976710656*(31&t[f])+1099511627776*t[f+1]+4294967296*t[f+2]+16777216*t[f+3]+(t[f+4]<<16)+(t[f+5]<<8)+t[f+6])>=9e15?crypto.randomBytes(7).copy(t,f):(l.push(o%1e14),f+=7);f=i/7}if(!L)for(;f<i;)(o=s())<9e15&&(l[f++]=o%1e14);for(e%=14,(i=l[--f])&&e&&(o=d[14-e],l[f]=u(i/o)*o);0===l[f];l.pop(),f--);if(f<0)l=[n=0];else{for(n=-1;0===l[0];l.splice(0,1),n-=14);for(f=1,o=l[0];o>=10;o/=10,f++);f<14&&(n-=14-f)}return h.e=n,h.c=l,h}),B.sum=function(){for(var e=1,t=arguments,r=new B(t[0]);e<t.length;)r=r.plus(t[e++]);return r},n=function(){function e(e,t,r,n){for(var i,s,o=[0],c=0,u=e.length;c<u;){for(s=o.length;s--;o[s]*=t);for(o[0]+=n.indexOf(e.charAt(c++)),i=0;i<o.length;i++)o[i]>r-1&&(null==o[i+1]&&(o[i+1]=0),o[i+1]+=o[i]/r|0,o[i]%=r)}return o.reverse()}return function(t,n,i,s,o){var c,u,a,f,l,d,p,h,b=t.indexOf("."),y=C,m=R;for(b>=0&&(f=M,M=0,t=t.replace(".",""),d=(h=new B(n)).pow(t.length-b),M=f,h.c=e(_(v(d.c),d.e,"0"),10,i,"0123456789"),h.e=h.c.length),a=f=(p=e(t,n,i,o?(c=F,"0123456789"):(c="0123456789",F))).length;0==p[--f];p.pop());if(!p[0])return c.charAt(0);if(b<0?--a:(d.c=p,d.e=a,d.s=s,p=(d=r(d,h,y,m,i)).c,l=d.r,a=d.e),b=p[u=a+y+1],f=i/2,l=l||u<0||null!=p[u+1],l=m<4?(null!=b||l)&&(0==m||m==(d.s<0?3:2)):b>f||b==f&&(4==m||l||6==m&&1&p[u-1]||m==(d.s<0?8:7)),u<1||!p[0])t=l?_(c.charAt(1),-y,c.charAt(0)):c.charAt(0);else{if(p.length=u,l)for(--i;++p[--u]>i;)p[u]=0,u||(++a,p=[1].concat(p));for(f=p.length;!p[--f];);for(b=0,t="";b<=f;t+=c.charAt(p[b++]));t=_(t,a,c.charAt(0))}return t}}(),r=function(){function e(e,t,r){var n,i,s,o,c=0,u=e.length,a=t%1e7,f=t/1e7|0;for(e=e.slice();u--;)c=((i=a*(s=e[u]%1e7)+(n=f*s+(o=e[u]/1e7|0)*a)%1e7*1e7+c)/r|0)+(n/1e7|0)+f*o,e[u]=i%r;return c&&(e=[c].concat(e)),e}function t(e,t,r,n){var i,s;if(r!=n)s=r>n?1:-1;else for(i=s=0;i<r;i++)if(e[i]!=t[i]){s=e[i]>t[i]?1:-1;break}return s}function r(e,t,r,n){for(var i=0;r--;)e[r]-=i,i=e[r]<t[r]?1:0,e[r]=i*n+e[r]-t[r];for(;!e[0]&&e.length>1;e.splice(0,1));}return function(n,i,s,o,c){var a,f,d,p,v,b,y,m,g,_,E,S,T,A,O,w,N,C=n.s==i.s?1:-1,R=n.c,I=i.c;if(!(R&&R[0]&&I&&I[0]))return new B(n.s&&i.s&&(R?!I||R[0]!=I[0]:I)?R&&0==R[0]||!I?0*C:C/0:NaN);for(g=(m=new B(C)).c=[],C=s+(f=n.e-i.e)+1,c||(c=l,f=h(n.e/14)-h(i.e/14),C=C/14|0),d=0;I[d]==(R[d]||0);d++);if(I[d]>(R[d]||0)&&f--,C<0)g.push(1),p=!0;else{for(A=R.length,w=I.length,d=0,C+=2,(v=u(c/(I[0]+1)))>1&&(I=e(I,v,c),R=e(R,v,c),w=I.length,A=R.length),T=w,E=(_=R.slice(0,w)).length;E<w;_[E++]=0);N=I.slice(),N=[0].concat(N),O=I[0],I[1]>=c/2&&O++;do{if(v=0,(a=t(I,_,w,E))<0){if(S=_[0],w!=E&&(S=S*c+(_[1]||0)),(v=u(S/O))>1)for(v>=c&&(v=c-1),y=(b=e(I,v,c)).length,E=_.length;1==t(b,_,y,E);)v--,r(b,w<y?N:I,y,c),y=b.length,a=1;else 0==v&&(a=v=1),y=(b=I.slice()).length;if(y<E&&(b=[0].concat(b)),r(_,b,E,c),E=_.length,-1==a)for(;t(I,_,w,E)<1;)v++,r(_,w<E?N:I,E,c),E=_.length}else 0===a&&(v++,_=[0]);g[d++]=v,_[0]?_[E++]=R[T]||0:(_=[R[T]],E=1)}while((T++<A||null!=_[0])&&C--);p=null!=_[0],g[0]||g.splice(0,1)}if(c==l){for(d=1,C=g[0];C>=10;C/=10,d++);K(m,s+(m.e=d+14*f-1)+1,o,p)}else m.e=f,m.r=+p;return m}}(),E=/^(-?)0([xbo])(?=\w[\w.]*$)/i,S=/^([^.]+)\.$/,T=/^\.([^.]+)$/,A=/^-?(Infinity|NaN)$/,O=/^\s*\+(?=[\w.])|^\s+|\s+$/g,i=function(e,t,r,n){var i,s=r?t:t.replace(O,"");if(A.test(s))e.s=isNaN(s)?null:s<0?-1:1;else{if(!r&&(s=s.replace(E,(function(e,t,r){return i="x"==(r=r.toLowerCase())?16:"b"==r?2:8,n&&n!=i?e:t})),n&&(i=n,s=s.replace(S,"$1").replace(T,"0.$1")),t!=s))return new B(s,i);if(B.DEBUG)throw Error(a+"Not a"+(n?" base "+n:"")+" number: "+t);e.s=null}e.c=e.e=null},w.absoluteValue=w.abs=function(){var e=new B(this);return e.s<0&&(e.s=1),e},w.comparedTo=function(e,t){return b(this,new B(e,t))},w.decimalPlaces=w.dp=function(e,t){var r,n,i,s=this;if(null!=e)return y(e,0,p),null==t?t=R:y(t,0,8),K(new B(s),e+s.e+1,t);if(!(r=s.c))return null;if(n=14*((i=r.length-1)-h(this.e/14)),i=r[i])for(;i%10==0;i/=10,n--);return n<0&&(n=0),n},w.dividedBy=w.div=function(e,t){return r(this,new B(e,t),C,R)},w.dividedToIntegerBy=w.idiv=function(e,t){return r(this,new B(e,t),0,1)},w.exponentiatedBy=w.pow=function(e,t){var r,n,i,s,o,f,l,d,p=this;if((e=new B(e)).c&&!e.isInteger())throw Error(a+"Exponent not an integer: "+W(e));if(null!=t&&(t=new B(t)),o=e.e>14,!p.c||!p.c[0]||1==p.c[0]&&!p.e&&1==p.c.length||!e.c||!e.c[0])return d=new B(Math.pow(+W(p),o?2-m(e):+W(e))),t?d.mod(t):d;if(f=e.s<0,t){if(t.c?!t.c[0]:!t.s)return new B(NaN);(n=!f&&p.isInteger()&&t.isInteger())&&(p=p.mod(t))}else{if(e.e>9&&(p.e>0||p.e<-1||(0==p.e?p.c[0]>1||o&&p.c[1]>=24e7:p.c[0]<8e13||o&&p.c[0]<=9999975e7)))return s=p.s<0&&m(e)?-0:0,p.e>-1&&(s=1/s),new B(f?1/s:s);M&&(s=c(M/14+2))}for(o?(r=new B(.5),f&&(e.s=1),l=m(e)):l=(i=Math.abs(+W(e)))%2,d=new B(N);;){if(l){if(!(d=d.times(p)).c)break;s?d.c.length>s&&(d.c.length=s):n&&(d=d.mod(t))}if(i){if(0===(i=u(i/2)))break;l=i%2}else if(K(e=e.times(r),e.e+1,1),e.e>14)l=m(e);else{if(0===(i=+W(e)))break;l=i%2}p=p.times(p),s?p.c&&p.c.length>s&&(p.c.length=s):n&&(p=p.mod(t))}return n?d:(f&&(d=N.div(d)),t?d.mod(t):s?K(d,M,R,void 0):d)},w.integerValue=function(e){var t=new B(this);return null==e?e=R:y(e,0,8),K(t,t.e+1,e)},w.isEqualTo=w.eq=function(e,t){return 0===b(this,new B(e,t))},w.isFinite=function(){return!!this.c},w.isGreaterThan=w.gt=function(e,t){return b(this,new B(e,t))>0},w.isGreaterThanOrEqualTo=w.gte=function(e,t){return 1===(t=b(this,new B(e,t)))||0===t},w.isInteger=function(){return!!this.c&&h(this.e/14)>this.c.length-2},w.isLessThan=w.lt=function(e,t){return b(this,new B(e,t))<0},w.isLessThanOrEqualTo=w.lte=function(e,t){return-1===(t=b(this,new B(e,t)))||0===t},w.isNaN=function(){return!this.s},w.isNegative=function(){return this.s<0},w.isPositive=function(){return this.s>0},w.isZero=function(){return!!this.c&&0==this.c[0]},w.minus=function(e,t){var r,n,i,s,o=this,c=o.s;if(t=(e=new B(e,t)).s,!c||!t)return new B(NaN);if(c!=t)return e.s=-t,o.plus(e);var u=o.e/14,a=e.e/14,f=o.c,d=e.c;if(!u||!a){if(!f||!d)return f?(e.s=-t,e):new B(d?o:NaN);if(!f[0]||!d[0])return d[0]?(e.s=-t,e):new B(f[0]?o:3==R?-0:0)}if(u=h(u),a=h(a),f=f.slice(),c=u-a){for((s=c<0)?(c=-c,i=f):(a=u,i=d),i.reverse(),t=c;t--;i.push(0));i.re