nkn-sdk
Version:
NKN client and wallet SDK
3 lines • 1.9 MB
JavaScript
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).nkn=e()}}((function(){var define,module,exports;return function e(t,r,n){function i(a,s){if(!r[a]){if(!t[a]){var A="function"==typeof require&&require;if(!s&&A)return A(a,!0);if(o)return o(a,!0);var c=new Error("Cannot find module '"+a+"'");throw c.code="MODULE_NOT_FOUND",c}var u=r[a]={exports:{}};t[a][0].call(u.exports,(function(e){return i(t[a][1][e]||e)}),u,u.exports,e,t,r,n)}return r[a].exports}for(var o="function"==typeof require&&require,a=0;a<n.length;a++)i(n[a]);return i}({1:[function(e,t,r){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.default=void 0;var n=l(e("isomorphic-ws")),i=l(e("../wallet")),o=h(e("../common")),a=h(e("./consts")),s=a,A=h(e("./message")),c=l(e("./webrtc")),u=h(e("../common/crypto"));function f(e){if("function"!=typeof WeakMap)return null;var t=new WeakMap,r=new WeakMap;return(f=function(e){return e?r:t})(e)}function h(e,t){if(!t&&e&&e.__esModule)return e;if(null===e||"object"!=g(e)&&"function"!=typeof e)return{default:e};var r=f(t);if(r&&r.has(e))return r.get(e);var n={__proto__:null},i=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var o in e)if("default"!==o&&{}.hasOwnProperty.call(e,o)){var a=i?Object.getOwnPropertyDescriptor(e,o):null;a&&(a.get||a.set)?Object.defineProperty(n,o,a):n[o]=e[o]}return n.default=e,r&&r.set(e,n),n}function l(e){return e&&e.__esModule?e:{default:e}}function g(e){return g="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},g(e)}function p(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return d(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?d(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0,i=function(){};return{s:i,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,a=!0,s=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return a=e.done,e},e:function(e){s=!0,o=e},f:function(){try{a||null==r.return||r.return()}finally{if(s)throw o}}}}function d(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function y(){
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
y=function(){return t};var e,t={},r=Object.prototype,n=r.hasOwnProperty,i=Object.defineProperty||function(e,t,r){e[t]=r.value},o="function"==typeof Symbol?Symbol:{},a=o.iterator||"@@iterator",s=o.asyncIterator||"@@asyncIterator",A=o.toStringTag||"@@toStringTag";function c(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{c({},"")}catch(e){c=function(e,t,r){return e[t]=r}}function u(e,t,r,n){var o=t&&t.prototype instanceof b?t:b,a=Object.create(o.prototype),s=new x(n||[]);return i(a,"_invoke",{value:k(e,r,s)}),a}function f(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}t.wrap=u;var h="suspendedStart",l="suspendedYield",p="executing",d="completed",I={};function b(){}function C(){}function v(){}var _={};c(_,a,(function(){return this}));var B=Object.getPrototypeOf,w=B&&B(B(N([])));w&&w!==r&&n.call(w,a)&&(_=w);var m=v.prototype=b.prototype=Object.create(_);function E(e){["next","throw","return"].forEach((function(t){c(e,t,(function(e){return this._invoke(t,e)}))}))}function Q(e,t){function r(i,o,a,s){var A=f(e[i],e,o);if("throw"!==A.type){var c=A.arg,u=c.value;return u&&"object"==g(u)&&n.call(u,"__await")?t.resolve(u.__await).then((function(e){r("next",e,a,s)}),(function(e){r("throw",e,a,s)})):t.resolve(u).then((function(e){c.value=e,a(c)}),(function(e){return r("throw",e,a,s)}))}s(A.arg)}var o;i(this,"_invoke",{value:function(e,n){function i(){return new t((function(t,i){r(e,n,t,i)}))}return o=o?o.then(i,i):i()}})}function k(t,r,n){var i=h;return function(o,a){if(i===p)throw Error("Generator is already running");if(i===d){if("throw"===o)throw a;return{value:e,done:!0}}for(n.method=o,n.arg=a;;){var s=n.delegate;if(s){var A=S(s,n);if(A){if(A===I)continue;return A}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(i===h)throw i=d,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);i=p;var c=f(t,r,n);if("normal"===c.type){if(i=n.done?d:l,c.arg===I)continue;return{value:c.arg,done:n.done}}"throw"===c.type&&(i=d,n.method="throw",n.arg=c.arg)}}}function S(t,r){var n=r.method,i=t.iterator[n];if(i===e)return r.delegate=null,"throw"===n&&t.iterator.return&&(r.method="return",r.arg=e,S(t,r),"throw"===r.method)||"return"!==n&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+n+"' method")),I;var o=f(i,t.iterator,r.arg);if("throw"===o.type)return r.method="throw",r.arg=o.arg,r.delegate=null,I;var a=o.arg;return a?a.done?(r[t.resultName]=a.value,r.next=t.nextLoc,"return"!==r.method&&(r.method="next",r.arg=e),r.delegate=null,I):a:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,I)}function D(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function M(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function x(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(D,this),this.reset(!0)}function N(t){if(t||""===t){var r=t[a];if(r)return r.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var i=-1,o=function r(){for(;++i<t.length;)if(n.call(t,i))return r.value=t[i],r.done=!1,r;return r.value=e,r.done=!0,r};return o.next=o}}throw new TypeError(g(t)+" is not iterable")}return C.prototype=v,i(m,"constructor",{value:v,configurable:!0}),i(v,"constructor",{value:C,configurable:!0}),C.displayName=c(v,A,"GeneratorFunction"),t.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===C||"GeneratorFunction"===(t.displayName||t.name))},t.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,v):(e.__proto__=v,c(e,A,"GeneratorFunction")),e.prototype=Object.create(m),e},t.awrap=function(e){return{__await:e}},E(Q.prototype),c(Q.prototype,s,(function(){return this})),t.AsyncIterator=Q,t.async=function(e,r,n,i,o){void 0===o&&(o=Promise);var a=new Q(u(e,r,n,i),o);return t.isGeneratorFunction(r)?a:a.next().then((function(e){return e.done?e.value:a.next()}))},E(m),c(m,A,"Generator"),c(m,a,(function(){return this})),c(m,"toString",(function(){return"[object Generator]"})),t.keys=function(e){var t=Object(e),r=[];for(var n in t)r.push(n);return r.reverse(),function e(){for(;r.length;){var n=r.pop();if(n in t)return e.value=n,e.done=!1,e}return e.done=!0,e}},t.values=N,x.prototype={constructor:x,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=e,this.done=!1,this.delegate=null,this.method="next",this.arg=e,this.tryEntries.forEach(M),!t)for(var r in this)"t"===r.charAt(0)&&n.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=e)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var r=this;function i(n,i){return s.type="throw",s.arg=t,r.next=n,i&&(r.method="next",r.arg=e),!!i}for(var o=this.tryEntries.length-1;o>=0;--o){var a=this.tryEntries[o],s=a.completion;if("root"===a.tryLoc)return i("end");if(a.tryLoc<=this.prev){var A=n.call(a,"catchLoc"),c=n.call(a,"finallyLoc");if(A&&c){if(this.prev<a.catchLoc)return i(a.catchLoc,!0);if(this.prev<a.finallyLoc)return i(a.finallyLoc)}else if(A){if(this.prev<a.catchLoc)return i(a.catchLoc,!0)}else{if(!c)throw Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return i(a.finallyLoc)}}}},abrupt:function(e,t){for(var r=this.tryEntries.length-1;r>=0;--r){var i=this.tryEntries[r];if(i.tryLoc<=this.prev&&n.call(i,"finallyLoc")&&this.prev<i.finallyLoc){var o=i;break}}o&&("break"===e||"continue"===e)&&o.tryLoc<=t&&t<=o.finallyLoc&&(o=null);var a=o?o.completion:{};return a.type=e,a.arg=t,o?(this.method="next",this.next=o.finallyLoc,I):this.complete(a)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),I},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),M(r),I}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var i=n.arg;M(r)}return i}}throw Error("illegal catch attempt")},delegateYield:function(t,r,n){return this.delegate={iterator:N(t),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=e),I}},t}function I(e,t,r,n,i,o,a){try{var s=e[o](a),A=s.value}catch(e){return void r(e)}s.done?t(A):Promise.resolve(A).then(n,i)}function b(e){return function(){var t=this,r=arguments;return new Promise((function(n,i){var o=e.apply(t,r);function a(e){I(o,n,i,a,s,"next",e)}function s(e){I(o,n,i,a,s,"throw",e)}a(void 0)}))}}function C(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function v(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,w(n.key),n)}}function _(e,t,r){return t&&v(e.prototype,t),r&&v(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function B(e,t,r){return(t=w(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function w(e){var t=function(e,t){if("object"!=g(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=g(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==g(t)?t:t+""}var m="setClient",E="updateSigChainBlockHash",Q="authChallenge",k=(r.default=function(){return _((function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};C(this,e),B(this,"options",void 0),B(this,"key",void 0),B(this,"identifier",void 0),B(this,"addr",void 0),B(this,"eventListeners",void 0),B(this,"sigChainBlockHash",void 0),B(this,"shouldReconnect",void 0),B(this,"reconnectInterval",void 0),B(this,"responseManager",void 0),B(this,"ws",void 0),B(this,"node",void 0),B(this,"isReady",void 0),B(this,"isFailed",void 0),B(this,"isClosed",void 0),B(this,"wallet",void 0),B(this,"peer",void 0),t=o.util.assignDefined({},s.defaultOptions,t);var r=new o.Key(t.seed,{worker:t.worker}),n=t.identifier||"",a=(n?n+".":"")+r.publicKey,A=new i.default(Object.assign({},t,{seed:r.seed,worker:!1,version:1}));delete t.seed,this.options=t,this.key=r,this.identifier=n,this.addr=a,this.eventListeners={connect:[],connectFailed:[],wsError:[],message:[]},this.sigChainBlockHash=null,this.shouldReconnect=!1,this.reconnectInterval=t.reconnectIntervalMin,this.responseManager=new S,this.ws=null,this.node=null,this.isReady=!1,this.isFailed=!1,this.isClosed=!1,this.wallet=A,void 0===t.webrtc&&void 0===t.tls&&(t.webrtc=this._shouldUseTls()),t.webrtc&&(this.peer=new c.default(t.stunServerAddr)),this._connect()}),[{key:"getSeed",value:function(){return this.key.seed}},{key:"getPublicKey",value:function(){return this.key.publicKey}},{key:"_connect",value:(T=b(y().mark((function e(){var t,r,n,i,a;return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:t=this._shouldUseTls()?o.rpc.getWssAddr:o.rpc.getWsAddr,i=0;case 2:if(!(i<3)){e.next=29;break}if(e.prev=3,!this.options.webrtc){e.next=13;break}return e.next=7,this.peer.offer(this.addr);case 7:return a=e.sent,e.next=10,o.rpc.getPeerAddr(this.addr,{rpcServerAddr:this.options.rpcServerAddr,offer:a});case 10:r=e.sent,e.next=16;break;case 13:return e.next=15,t(this.addr,{rpcServerAddr:this.options.rpcServerAddr});case 15:r=e.sent;case 16:e.next=24;break;case 18:if(e.prev=18,e.t0=e.catch(3),n=e.t0,!(e.t0 instanceof o.errors.ServerError&&e.t0.message.includes(o.errors.rpcRespErrCodes.invalidMethod.toString()))){e.next=23;break}return e.abrupt("break",29);case 23:return e.abrupt("continue",26);case 24:return this._newWsAddr(r),e.abrupt("return");case 26:i++,e.next=2;break;case 29:console.log("RPC call failed,",n),this.shouldReconnect?this._reconnect():this.isClosed||this._connectFailed();case 31:case"end":return e.stop()}}),e,this,[[3,18]])}))),function(){return T.apply(this,arguments)})},{key:"_reconnect",value:function(){var e=this;console.log("Reconnecting in "+this.reconnectInterval/1e3+"s..."),setTimeout((function(){return e._connect()}),this.reconnectInterval),this.reconnectInterval*=2,this.reconnectInterval>this.options.reconnectIntervalMax&&(this.reconnectInterval=this.options.reconnectIntervalMax)}},{key:"_connectFailed",value:function(){this.isFailed||(this.isFailed=!0,this.eventListeners.connectFailed.length>0?this.eventListeners.connectFailed.forEach(function(){var e=b(y().mark((function e(t){return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,t();case 3:e.next=8;break;case 5:e.prev=5,e.t0=e.catch(0),console.log("Connect failed handler error:",e.t0);case 8:case"end":return e.stop()}}),e,null,[[0,5]])})));return function(t){return e.apply(this,arguments)}}()):console.log("Client connect failed"))}},{key:"on",value:function(e,t){this.eventListeners[e]||(this.eventListeners[e]=[]),this.eventListeners[e].push(t)}},{key:"onConnect",value:function(e){this.eventListeners.connect.push(e)}},{key:"onConnectFailed",value:function(e){this.eventListeners.connectFailed.push(e)}},{key:"onWsError",value:function(e){this.eventListeners.wsError.push(e)}},{key:"onMessage",value:function(e){this.eventListeners.message.push(e)}},{key:"_wsSend",value:function(e){if(!this.ws)throw new o.errors.ClientNotReadyError;this.ws.send(e)}},{key:"_processDest",value:(U=b(y().mark((function e(t){var r,n;return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(0!==t.length){e.next=2;break}throw new o.errors.InvalidDestinationError("destination is empty");case 2:if(!((r=t.split("."))[r.length-1].length<2*o.crypto.publicKeyLength)){e.next=12;break}return e.next=6,this.getRegistrant(r[r.length-1]);case 6:if(!((n=e.sent).registrant&&n.registrant.length>0)){e.next=11;break}r[r.length-1]=n.registrant,e.next=12;break;case 11:throw new o.errors.InvalidDestinationError(t+" is neither a valid public key nor a registered name");case 12:return e.abrupt("return",r.join("."));case 13:case"end":return e.stop()}}),e,this)}))),function(e){return U.apply(this,arguments)})},{key:"_processDests",value:(R=b(y().mark((function e(t){var r=this;return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!Array.isArray(t)){e.next=11;break}if(0!==t.length){e.next=3;break}throw new o.errors.InvalidDestinationError("no destinations");case 3:return e.next=5,Promise.all(t.map(function(){var e=b(y().mark((function e(t){return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,r._processDest(t);case 3:return e.abrupt("return",e.sent);case 6:return e.prev=6,e.t0=e.catch(0),console.warn(e.t0.message),e.abrupt("return","");case 10:case"end":return e.stop()}}),e,null,[[0,6]])})));return function(t){return e.apply(this,arguments)}}()));case 5:if(0!==(t=(t=e.sent).filter((function(e){return e.length>0}))).length){e.next=9;break}throw new o.errors.InvalidDestinationError("all destinations are invalid");case 9:e.next=14;break;case 11:return e.next=13,this._processDest(t);case 13:t=e.sent;case 14:return e.abrupt("return",t);case 15:case"end":return e.stop()}}),e,this)}))),function(e){return R.apply(this,arguments)})},{key:"_send",value:(j=b(y().mark((function e(t,r){var n,i,a,s,c,u,f,h,l,g,p,d=this,I=arguments;return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n=!(I.length>2&&void 0!==I[2])||I[2],i=I.length>3&&void 0!==I[3]?I[3]:0,!Array.isArray(t)){e.next=9;break}if(0!==t.length){e.next=5;break}return e.abrupt("return",null);case 5:if(1!==t.length){e.next=9;break}return e.next=8,this._send(t[0],r,n,i);case 8:return e.abrupt("return",e.sent);case 9:return e.next=11,this._processDests(t);case 11:return t=e.sent,e.next=14,this._messageFromPayload(r,n,t);case 14:if(a=(a=e.sent).map((function(e){return e.serializeBinary()})),s=[],c=[],u=[],!(a.length>1)){e.next=41;break}f=0,h=0,l=0;case 20:if(!(l<a.length)){e.next=39;break}if(!((h=a[l].length+t[l].length+o.crypto.signatureLength)>A.maxClientMessageSize)){e.next=24;break}throw new o.errors.DataSizeTooLargeError("encoded message is greater than "+A.maxClientMessageSize+" bytes");case 24:if(!(f+h>A.maxClientMessageSize)){e.next=33;break}return e.t0=s,e.next=28,A.newOutboundMessage(this,c,u,i);case 28:e.t1=e.sent,e.t0.push.call(e.t0,e.t1),c=[],u=[],f=0;case 33:c.push(t[l]),u.push(a[l]),f+=h;case 36:l++,e.next=20;break;case 39:e.next=47;break;case 41:if(g=a[0].length,Array.isArray(t))for(p=0;p<t.length;p++)g+=t[p].length+o.crypto.signatureLength;else g+=t.length+o.crypto.signatureLength;if(!(g>A.maxClientMessageSize)){e.next=45;break}throw new o.errors.DataSizeTooLargeError("encoded message is greater than "+A.maxClientMessageSize+" bytes");case 45:c=t,u=a;case 47:return e.t2=s,e.next=50,A.newOutboundMessage(this,c,u,i);case 50:return e.t3=e.sent,e.t2.push.call(e.t2,e.t3),s.length>1&&console.log("Client message size is greater than ".concat(A.maxClientMessageSize," bytes, split into ").concat(s.length," batches.")),s.forEach((function(e){d._wsSend(e.serializeBinary())})),e.abrupt("return",r.getMessageId()||null);case 55:case"end":return e.stop()}}),e,this)}))),function(e,t){return j.apply(this,arguments)})},{key:"send",value:(P=b(y().mark((function e(t,r){var n,i,a,s=this,c=arguments;return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=c.length>2&&void 0!==c[2]?c[2]:{},n=o.util.assignDefined({},this.options,n),i="string"==typeof r?A.newTextPayload(r,n.replyToId,n.messageId):A.newBinaryPayload(r,n.replyToId,n.messageId),e.next=5,this._send(t,i,n.encrypt,n.msgHoldingSeconds);case 5:if(null!==(a=e.sent)&&!n.noReply){e.next=8;break}return e.abrupt("return",null);case 8:return e.next=10,new Promise((function(e,t){s.responseManager.add(new k(a,n.responseTimeout,e,t))}));case 10:return e.abrupt("return",e.sent);case 11:case"end":return e.stop()}}),e,this)}))),function(e,t){return P.apply(this,arguments)})},{key:"_sendACK",value:(F=b(y().mark((function e(t,r,n){var i,o,a,s;return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!Array.isArray(t)){e.next=17;break}if(0!==t.length){e.next=3;break}return e.abrupt("return");case 3:if(1!==t.length){e.next=7;break}return e.next=6,this._sendACK(t[0],r,n);case 6:return e.abrupt("return",e.sent);case 7:if(!(t.length>1&&n)){e.next=17;break}console.warn("Encrypted ACK with multicast is not supported, fallback to unicast."),i=0;case 10:if(!(i<t.length)){e.next=16;break}return e.next=13,this._sendACK(t[i],r,n);case 13:i++,e.next=10;break;case 16:return e.abrupt("return");case 17:return o=A.newAckPayload(r),e.next=20,this._messageFromPayload(o,n,t);case 20:return a=e.sent,e.next=23,A.newOutboundMessage(this,t,a[0].serializeBinary(),0);case 23:s=e.sent,this._wsSend(s.serializeBinary());case 25:case"end":return e.stop()}}),e,this)}))),function(e,t,r){return F.apply(this,arguments)})},{key:"publish",value:(N=b(y().mark((function e(t,r){var n,i,a,A,c,u=arguments;return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=u.length>2&&void 0!==u[2]?u[2]:{},n=o.util.assignDefined({},s.defaultPublishOptions,n,{noReply:!0}),i=n.offset,e.next=5,this.getSubscribers(t,{offset:i,limit:n.limit,txPool:n.txPool});case 5:if((a=e.sent).subscribers instanceof Array){e.next=8;break}throw new o.errors.InvalidResponseError("subscribers should be an array");case 8:if(!a.subscribersInTxPool||a.subscribersInTxPool instanceof Array){e.next=10;break}throw new o.errors.InvalidResponseError("subscribersInTxPool should be an array");case 10:A=a.subscribers,c=a.subscribersInTxPool;case 12:if(!(a.subscribers&&a.subscribers.length>=n.limit)){e.next=22;break}return i+=n.limit,e.next=16,this.getSubscribers(t,{offset:i,limit:n.limit});case 16:if((a=e.sent).subscribers instanceof Array){e.next=19;break}throw new o.errors.InvalidResponseError("subscribers should be an array");case 19:A=A.concat(a.subscribers),e.next=12;break;case 22:return n.txPool&&c&&(A=A.concat(c)),e.next=25,this.send(A,r,n);case 25:return e.abrupt("return",null);case 26:case"end":return e.stop()}}),e,this)}))),function(e,t){return N.apply(this,arguments)})},{key:"close",value:function(){this.responseManager.stop(),this.shouldReconnect=!1;try{this.ws&&this.ws.close()}catch(e){}this.isClosed=!0}},{key:"_messageFromPayload",value:(x=b(y().mark((function e(t,r,n){return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!r){e.next=4;break}return e.next=3,this._encryptPayload(t.serializeBinary(),n);case 3:return e.abrupt("return",e.sent);case 4:return e.abrupt("return",[A.newMessage(t.serializeBinary(),!1)]);case 5:case"end":return e.stop()}}),e,this)}))),function(e,t,r){return x.apply(this,arguments)})},{key:"_handleMsg",value:(M=b(y().mark((function e(t){var r;return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:r=o.pb.messages.ClientMessage.deserializeBinary(t),e.t0=r.getMessageType(),e.next=e.t0===o.pb.messages.ClientMessageType.INBOUND_MESSAGE?4:7;break;case 4:return e.next=6,this._handleInboundMsg(r.getMessage());case 6:return e.abrupt("return",e.sent);case 7:return e.abrupt("return",!1);case 8:case"end":return e.stop()}}),e,this)}))),function(e){return M.apply(this,arguments)})},{key:"_handleInboundMsg",value:(D=b(y().mark((function e(t){var r,n,i,a,s,c,u,f,h,l,g,d,I;return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r=o.pb.messages.InboundMessage.deserializeBinary(t),!((n=r.getPrevSignature()).length>0)){e.next=8;break}return n=o.util.bytesToHex(n),e.next=6,A.newReceipt(this,n);case 6:i=e.sent,this._wsSend(i.serializeBinary());case 8:if(!(a=o.pb.payloads.Message.deserializeBinary(r.getPayload())).getEncrypted()){e.next=15;break}return e.next=12,this._decryptPayload(a,r.getSrc());case 12:s=e.sent,e.next=16;break;case 15:s=a.getPayload();case 16:c=o.pb.payloads.Payload.deserializeBinary(s),u=c.getData(),e.t0=c.getType(),e.next=e.t0===o.pb.payloads.PayloadType.TEXT?21:e.t0===o.pb.payloads.PayloadType.ACK?24:26;break;case 21:return f=o.pb.payloads.TextData.deserializeBinary(u),u=f.getText(),e.abrupt("break",26);case 24:return this.responseManager.respond(c.getReplyToId(),null,c.getType()),e.abrupt("return",!0);case 26:if(!c.getReplyToId().length){e.next=29;break}return this.responseManager.respond(c.getReplyToId(),u,c.getType()),e.abrupt("return",!0);case 29:e.t1=c.getType(),e.next=e.t1===o.pb.payloads.PayloadType.TEXT||e.t1===o.pb.payloads.PayloadType.BINARY||e.t1===o.pb.payloads.PayloadType.SESSION?32:65;break;case 32:if(!(this.eventListeners.message.length>0)){e.next=64;break}return e.next=35,Promise.all(this.eventListeners.message.map(function(){var e=b(y().mark((function e(t){return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,t({src:r.getSrc(),payload:u,payloadType:c.getType(),isEncrypted:a.getEncrypted(),messageId:c.getMessageId(),noReply:c.getNoReply()});case 3:return e.abrupt("return",e.sent);case 6:return e.prev=6,e.t0=e.catch(0),console.log("Message handler error:",e.t0),e.abrupt("return",null);case 10:case"end":return e.stop()}}),e,null,[[0,6]])})));return function(t){return e.apply(this,arguments)}}()));case 35:if(h=e.sent,c.getNoReply()){e.next=64;break}l=!1,g=p(h),e.prev=39,g.s();case 41:if((d=g.n()).done){e.next=53;break}if(!1!==(I=d.value)){e.next=47;break}return e.abrupt("return",!0);case 47:if(null==I){e.next=51;break}return this.send(r.getSrc(),I,{encrypt:a.getEncrypted(),msgHoldingSeconds:0,replyToId:c.getMessageId()}).catch((function(e){console.log("Send response error:",e)})),l=!0,e.abrupt("break",53);case 51:e.next=41;break;case 53:e.next=58;break;case 55:e.prev=55,e.t2=e.catch(39),g.e(e.t2);case 58:return e.prev=58,g.f(),e.finish(58);case 61:if(l){e.next=64;break}return e.next=64,this._sendACK(r.getSrc(),c.getMessageId(),a.getEncrypted());case 64:return e.abrupt("return",!0);case 65:return e.abrupt("return",!1);case 66:case"end":return e.stop()}}),e,this,[[39,55,58,61]])}))),function(e){return D.apply(this,arguments)})},{key:"_shouldUseTls",value:function(){return void 0!==this.options.tls?!!this.options.tls:"undefined"!=typeof window&&!(!window.location||"https:"!==window.location.protocol)}},{key:"_newWsAddr",value:(w=b(y().mark((function e(t){var r,i,s,A,c,f,h,l=this;return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t.addr){e.next=4;break}return console.log("No address in node info",t),this.shouldReconnect?this._reconnect():this.isClosed||this._connectFailed(),e.abrupt("return");case 4:r=this._shouldUseTls(),e.prev=5,this.options.webrtc?(i=this.peer,this.peer.setRemoteDescription(t.sdp)):(i=new n.default((r?"wss":"ws")+"://"+t.addr)).binaryType="arraybuffer",e.next=14;break;case 9:return e.prev=9,e.t0=e.catch(5),console.log("Create WebSocket or WebRTC failed,",e.t0),this.shouldReconnect?this._reconnect():this.isClosed||this._connectFailed(),e.abrupt("return");case 14:if(this.ws){this.ws.onclose=function(){};try{this.ws.close()}catch(e){}}if(!this.isClosed){e.next=18;break}try{i.close()}catch(e){}return e.abrupt("return");case 18:this.ws=i,this.node=t,this.wallet.options.rpcServerAddr="",!r&&t.rpcAddr&&(s="http://"+t.rpcAddr,o.rpc.getNodeState({rpcServerAddr:s}).then((function(e){"PERSIST_FINISHED"===e.syncState&&(l.wallet.options.rpcServerAddr=s)})).catch((function(e){console.log(e)}))),new Promise((function(e,t){A=e,c=setTimeout((function(){l.ws===i?t(new o.errors.ConnectToNodeTimeoutError):e()}),l.options.connectTimeout)})).then((function(){clearTimeout(c)})).catch((function(e){l.isClosed||console.log("WebSocket or WebRTC connect timeout,",e),l.shouldReconnect?l._reconnect():l.isClosed||l._connectFailed()})),h=new Promise((function(e,t){f=e,setTimeout((function(){l.ws===i&&e(new o.errors.ChallengeTimeoutError)}),a.waitForChallengeTimeout)})),i.onopen=b(y().mark((function e(){var t,r;return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return A(),t={Action:m,Addr:l.addr},e.next=4,h;case 4:!(r=e.sent)||r instanceof o.errors.ChallengeTimeoutError||(t.ClientSalt=o.util.bytesToHex(r.ClientSalt),t.Signature=o.util.bytesToHex(r.Signature)),i.send(JSON.stringify(t)),l.shouldReconnect=!0,l.reconnectInterval=l.options.reconnectIntervalMin;case 9:case"end":return e.stop()}}),e)}))),i.onmessage=function(){var e=b(y().mark((function e(t){var r,n,i,a,s,A,c;return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!((r=t.data)instanceof ArrayBuffer||r instanceof Blob)){e.next=19;break}if(e.prev=2,!(r instanceof Blob)){e.next=9;break}return e.t0=Uint8Array,e.next=7,r.arrayBuffer();case 7:e.t1=e.sent,r=new e.t0(e.t1);case 9:return e.next=11,l._handleMsg(r);case 11:e.sent||console.warn("Unhandled msg."),e.next=18;break;case 15:e.prev=15,e.t2=e.catch(2),console.log(e.t2);case 18:return e.abrupt("return");case 19:if(void 0===(n=JSON.parse(r)).Error||n.Error===o.errors.rpcRespErrCodes.success){e.next=24;break}if(console.log(n),n.Error===o.errors.rpcRespErrCodes.wrongNode)l._newWsAddr(n.Result);else if(n.Action===m)try{l.ws&&l.ws.close()}catch(e){}return e.abrupt("return");case 24:e.t3=n.Action,e.next=e.t3===m?27:e.t3===E?30:e.t3===Q?32:42;break;case 27:return l.sigChainBlockHash=n.Result.sigChainBlockHash,l.isReady||(l.isReady=!0,l.eventListeners.connect.length>0&&l.eventListeners.connect.forEach(function(){var e=b(y().mark((function e(t){return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,t(n.Result);case 3:e.next=8;break;case 5:e.prev=5,e.t0=e.catch(0),console.log("Connect handler error:",e.t0);case 8:case"end":return e.stop()}}),e,null,[[0,5]])})));return function(t){return e.apply(this,arguments)}}())),e.abrupt("break",43);case 30:return l.sigChainBlockHash=n.Result,e.abrupt("break",43);case 32:return i=n.Challenge,a=o.util.hexToBytes(i),s=o.util.randomBytes(32),a=o.util.mergeTypedArrays(a,s),A=o.hash.sha256Hex(o.util.bytesToHex(a)),e.next=39,u.sign(l.key.privateKey,A);case 39:return c=e.sent,f({ClientSalt:s,Signature:o.util.hexToBytes(c)}),e.abrupt("break",43);case 42:console.warn("Unknown msg type:",n.Action);case 43:case"end":return e.stop()}}),e,null,[[2,15]])})));return function(t){return e.apply(this,arguments)}}(),i.onclose=function(){l.shouldReconnect?(console.warn("WebSocket unexpectedly closed."),l._reconnect()):l.isClosed||l._connectFailed()},i.onerror=function(e){l.eventListeners.wsError.length>0?l.eventListeners.wsError.forEach(function(){var t=b(y().mark((function t(r){return y().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,t.next=3,r(e);case 3:t.next=8;break;case 5:t.prev=5,t.t0=t.catch(0),console.log("WsError handler error:",t.t0);case 8:case"end":return t.stop()}}),t,null,[[0,5]])})));return function(e){return t.apply(this,arguments)}}()):console.log(e.message)};case 28:case"end":return e.stop()}}),e,this,[[5,9]])}))),function(e){return w.apply(this,arguments)})},{key:"_encryptPayload",value:(v=b(y().mark((function e(t,r){var n,i,a,s,c,u,f,h,l,g,p;return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!Array.isArray(r)){e.next=22;break}return n=o.util.randomBytes(o.crypto.nonceLength),i=o.util.randomBytes(o.crypto.keyLength),e.next=5,o.crypto.encryptSymmetric(t,n,i);case 5:a=e.sent,s=[],c=0;case 8:if(!(c<r.length)){e.next=19;break}return u=A.addrToPubkey(r[c]),e.next=12,this.key.encrypt(i,u);case 12:f=e.sent,h=o.util.mergeTypedArrays(f.nonce,n),l=A.newMessage(a,!0,h,f.message),s.push(l);case 16:c++,e.next=8;break;case 19:return e.abrupt("return",s);case 22:return g=A.addrToPubkey(r),e.next=25,this.key.encrypt(t,g);case 25:return p=e.sent,e.abrupt("return",[A.newMessage(p.message,!0,p.nonce)]);case 27:case"end":return e.stop()}}),e,this)}))),function(e,t){return v.apply(this,arguments)})},{key:"_decryptPayload",value:(I=b(y().mark((function e(t,r){var n,i,a,s,c,u;return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n=t.getPayload(),i=A.addrToPubkey(r),a=t.getNonce(),!((s=t.getEncryptedKey())&&s.length>0)){e.next=19;break}if(a.length==2*o.crypto.nonceLength){e.next=7;break}throw new o.errors.DecryptionError("invalid nonce length");case 7:return e.next=9,this.key.decrypt(s,a.slice(0,o.crypto.nonceLength),i);case 9:if(null!==(u=e.sent)){e.next=12;break}throw new o.errors.DecryptionError("decrypt shared key failed");case 12:return e.next=14,o.crypto.decryptSymmetric(n,a.slice(o.crypto.nonceLength),u);case 14:if(null!==(c=e.sent)){e.next=17;break}throw new o.errors.DecryptionError("decrypt message failed");case 17:e.next=26;break;case 19:if(a.length==o.crypto.nonceLength){e.next=21;break}throw new o.errors.DecryptionError("invalid nonce length");case 21:return e.next=23,this.key.decrypt(n,a,i);case 23:if(null!==(c=e.sent)){e.next=26;break}throw new o.errors.DecryptionError("decrypt message failed");case 26:return e.abrupt("return",c);case 27:case"end":return e.stop()}}),e,this)}))),function(e,t){return I.apply(this,arguments)})},{key:"getLatestBlock",value:(d=b(y().mark((function e(){return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.wallet.options.rpcServerAddr){e.next=9;break}return e.prev=1,e.next=4,i.default.getLatestBlock(this.options);case 4:return e.abrupt("return",e.sent);case 7:e.prev=7,e.t0=e.catch(1);case 9:return e.next=11,i.default.getLatestBlock(this.options);case 11:return e.abrupt("return",e.sent);case 12:case"end":return e.stop()}}),e,this,[[1,7]])}))),function(){return d.apply(this,arguments)})},{key:"getRegistrant",value:(g=b(y().mark((function e(t){return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.wallet.options.rpcServerAddr){e.next=9;break}return e.prev=1,e.next=4,i.default.getRegistrant(t,this.wallet.options);case 4:return e.abrupt("return",e.sent);case 7:e.prev=7,e.t0=e.catch(1);case 9:return e.next=11,i.default.getRegistrant(t,this.options);case 11:return e.abrupt("return",e.sent);case 12:case"end":return e.stop()}}),e,this,[[1,7]])}))),function(e){return g.apply(this,arguments)})},{key:"getSubscribers",value:(l=b(y().mark((function e(t){var r,n=arguments;return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r=n.length>1&&void 0!==n[1]?n[1]:{},!this.wallet.options.rpcServerAddr){e.next=10;break}return e.prev=2,e.next=5,i.default.getSubscribers(t,Object.assign({},this.wallet.options,r));case 5:return e.abrupt("return",e.sent);case 8:e.prev=8,e.t0=e.catch(2);case 10:return e.next=12,i.default.getSubscribers(t,Object.assign({},this.options,r));case 12:return e.abrupt("return",e.sent);case 13:case"end":return e.stop()}}),e,this,[[2,8]])}))),function(e){return l.apply(this,arguments)})},{key:"getSubscribersCount",value:(h=b(y().mark((function e(t){return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.wallet.options.rpcServerAddr){e.next=9;break}return e.prev=1,e.next=4,i.default.getSubscribersCount(t,this.wallet.options);case 4:return e.abrupt("return",e.sent);case 7:e.prev=7,e.t0=e.catch(1);case 9:return e.next=11,i.default.getSubscribersCount(t,this.options);case 11:return e.abrupt("return",e.sent);case 12:case"end":return e.stop()}}),e,this,[[1,7]])}))),function(e){return h.apply(this,arguments)})},{key:"getSubscription",value:(f=b(y().mark((function e(t,r){return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.wallet.options.rpcServerAddr){e.next=9;break}return e.prev=1,e.next=4,i.default.getSubscription(t,r,this.wallet.options);case 4:return e.abrupt("return",e.sent);case 7:e.prev=7,e.t0=e.catch(1);case 9:return e.next=11,i.default.getSubscription(t,r,this.options);case 11:return e.abrupt("return",e.sent);case 12:case"end":return e.stop()}}),e,this,[[1,7]])}))),function(e,t){return f.apply(this,arguments)})},{key:"getBalance",value:(r=b(y().mark((function e(t){return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.wallet.options.rpcServerAddr){e.next=9;break}return e.prev=1,e.next=4,i.default.getBalance(t||this.wallet.address,this.wallet.options);case 4:return e.abrupt("return",e.sent);case 7:e.prev=7,e.t0=e.catch(1);case 9:return e.next=11,i.default.getBalance(t||this.wallet.address,this.options);case 11:return e.abrupt("return",e.sent);case 12:case"end":return e.stop()}}),e,this,[[1,7]])}))),function(e){return r.apply(this,arguments)})},{key:"getNonce",value:(t=b(y().mark((function e(t){var r,n=arguments;return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r=n.length>1&&void 0!==n[1]?n[1]:{},!this.wallet.options.rpcServerAddr){e.next=10;break}return e.prev=2,e.next=5,i.default.getNonce(t||this.wallet.address,Object.assign({},this.wallet.options,r));case 5:return e.abrupt("return",e.sent);case 8:e.prev=8,e.t0=e.catch(2);case 10:return e.next=12,i.default.getNonce(t||this.wallet.address,Object.assign({},this.options,r));case 12:return e.abrupt("return",e.sent);case 13:case"end":return e.stop()}}),e,this,[[2,8]])}))),function(e){return t.apply(this,arguments)})},{key:"sendTransaction",value:(e=b(y().mark((function e(t){return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.wallet.options.rpcServerAddr){e.next=9;break}return e.prev=1,e.next=4,i.default.sendTransaction(t,this.wallet.options);case 4:return e.abrupt("return",e.sent);case 7:e.prev=7,e.t0=e.catch(1);case 9:return e.next=11,i.default.sendTransaction(t,this.options);case 11:return e.abrupt("return",e.sent);case 12:case"end":return e.stop()}}),e,this,[[1,7]])}))),function(t){return e.apply(this,arguments)})},{key:"transferTo",value:function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return o.rpc.transferTo.call(this,e,t,r)}},{key:"registerName",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return o.rpc.registerName.call(this,e,t)}},{key:"transferName",value:function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return o.rpc.transferName.call(this,e,t,r)}},{key:"deleteName",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return o.rpc.deleteName.call(this,e,t)}},{key:"subscribe",value:function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"",n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"",i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{};return o.rpc.subscribe.call(this,e,t,r,n,i)}},{key:"unsubscribe",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return o.rpc.unsubscribe.call(this,e,t,r)}},{key:"createTransaction",value:function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return this.wallet.createTransaction(e,t,r)}}]);var e,t,r,f,h,l,g,d,I,v,w,D,M,x,N,F,P,j,R,U,T}(),function(){return _((function e(t,r,n,i){C(this,e),B(this,"messageId",void 0),B(this,"deadline",void 0),B(this,"responseHandler",void 0),B(this,"timeoutHandler",void 0),t instanceof Uint8Array&&(t=o.util.bytesToHex(t)),this.messageId=t,r&&(this.deadline=Date.now()+r),this.responseHandler=n,this.timeoutHandler=i}),[{key:"checkTimeout",value:function(e){return!!this.deadline&&(e||(e=Date.now()),e>this.deadline)}},{key:"handleResponse",value:function(e){this.responseHandler&&this.responseHandler(e)}},{key:"handleTimeout",value:function(){this.timeoutHandler&&this.timeoutHandler(new Error("Message timeout"))}}])}()),S=function(){return _((function e(){C(this,e),B(this,"responseProcessors",void 0),B(this,"timer",void 0),this.responseProcessors=new Map,this.timer=null,this.checkTimeout()}),[{key:"add",value:function(e){this.responseProcessors.set(e.messageId,e)}},{key:"clear",value:function(){var e,t=p(this.responseProcessors.values());try{for(t.s();!(e=t.n()).done;){e.value.handleTimeout()}}catch(e){t.e(e)}finally{t.f()}this.responseProcessors=new Map}},{key:"stop",value:function(){clearTimeout(this.timer),this.clear()}},{key:"respond",value:function(e,t,r){e instanceof Uint8Array&&(e=o.util.bytesToHex(e));var n=this.responseProcessors.get(e);n&&(n.handleResponse(t),this.responseProcessors.delete(e))}},{key:"checkTimeout",value:function(){var e,t=this,r=[],n=Date.now(),i=p(this.responseProcessors.values());try{for(i.s();!(e=i.n()).done;){var o=e.value;o.checkTimeout(n)&&r.push(o)}}catch(e){i.e(e)}finally{i.f()}r.forEach((function(e){e.handleTimeout(),t.responseProcessors.delete(e.messageId)})),this.timer=setTimeout(this.checkTimeout.bind(this),s.checkTimeoutInterval)}}])}()},{"../common":11,"../common/crypto":8,"../wallet":29,"./consts":2,"./message":4,"./webrtc":5,"isomorphic-ws":391}],2:[function(e,t,r){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.waitForChallengeTimeout=r.defaultPublishOptions=r.defaultOptions=r.checkTimeoutInterval=void 0;r.defaultOptions={reconnectIntervalMin:1e3,reconnectIntervalMax:64e3,responseTimeout:5e3,connectTimeout:1e4,msgHoldingSeconds:0,encrypt:!0,rpcServerAddr:"https://mainnet-rpc-node-0001.nkn.org/mainnet/api/wallet",stunServerAddr:["stun:stun.l.google.com:19302","stun:stun.cloudflare.com:3478","stun:stunserver.stunprotocol.org:3478"],worker:!1},r.defaultPublishOptions={txPool:!1,offset:0,limit:1e3},r.checkTimeoutInterval=250,r.waitForChallengeTimeout=5e3},{}],3:[function(e,t,r){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),Object.defineProperty(r,"default",{enumerable:!0,get:function(){return i.default}});var n,i=(n=e("./client"))&&n.__esModule?n:{default:n}},{"./client":1}],4:[function(e,t,r){(function(t){(function(){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.addrToID=I,r.addrToPubkey=b,r.messageIdSize=r.maxClientMessageSize=void 0,r.newAckPayload=function(e,t){return h(o.pb.payloads.PayloadType.ACK,e,null,t)},r.newBinaryPayload=function(e,t,r){return h(o.pb.payloads.PayloadType.BINARY,t,e,r)},r.newClientMessage=l,r.newMessage=function(e,t,r,n){var i=new o.pb.payloads.Message;i.setPayload(e),i.setEncrypted(t),r&&i.setNonce(r);n&&i.setEncryptedKey(n);return i},r.newOutboundMessage=function(e,t,r,n){return g.apply(this,arguments)},r.newPayload=h,r.newReceipt=function(e,t){return p.apply(this,arguments)},r.newSessionPayload=function(e,t){return h(o.pb.payloads.PayloadType.SESSION,null,e,t)},r.newTextPayload=function(e,t,r){var n=new o.pb.payloads.TextData;return n.setText(e),h(o.pb.payloads.PayloadType.TEXT,t,n.serializeBinary(),r)},r.serializeSigChainElem=y,r.serializeSigChainMetadata=d;var n,i=(n=e("pako"))&&n.__esModule?n:{default:n},o=function(e,t){if(!t&&e&&e.__esModule)return e;if(null===e||"object"!=s(e)&&"function"!=typeof e)return{default:e};var r=a(t);if(r&&r.has(e))return r.get(e);var n={__proto__:null},i=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var o in e)if("default"!==o&&{}.hasOwnProperty.call(e,o)){var A=i?Object.getOwnPropertyDescriptor(e,o):null;A&&(A.get||A.set)?Object.defineProperty(n,o,A):n[o]=e[o]}return n.default=e,r&&r.set(e,n),n}(e("../common"));function a(e){if("function"!=typeof WeakMap)return null;var t=new WeakMap,r=new WeakMap;return(a=function(e){return e?r:t})(e)}function s(e){return s="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},s(e)}function A(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */A=function(){return t};var e,t={},r=Object.prototype,n=r.hasOwnProperty,i=Object.defineProperty||function(e,t,r){e[t]=r.value},o="function"==typeof Symbol?Symbol:{},a=o.iterator||"@@iterator",c=o.asyncIterator||"@@asyncIterator",u=o.toStringTag||"@@toStringTag";function f(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{f({},"")}catch(e){f=function(e,t,r){return e[t]=r}}function h(e,t,r,n){var o=t&&t.prototype instanceof b?t:b,a=Object.create(o.prototype),s=new x(n||[]);return i(a,"_invoke",{value:k(e,r,s)}),a}function l(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}t.wrap=h;var g="suspendedStart",p="suspendedYield",d="executing",y="completed",I={};function b(){}function C(){}function v(){}var _={};f(_,a,(function(){return this}));var B=Object.getPrototypeOf,w=B&&B(B(N([])));w&&w!==r&&n.call(w,a)&&(_=w);var m=v.prototype=b.prototype=Object.create(_);function E(e){["next","throw","return"].forEach((function(t){f(e,t,(function(e){return this._invoke(t,e)}))}))}function Q(e,t){function r(i,o,a,A){var c=l(e[i],e,o);if("throw"!==c.type){var u=c.arg,f=u.value;return f&&"object"==s(f)&&n.call(f,"__await")?t.resolve(f.__await).then((function(e){r("next",e,a,A)}),(function(e){r("throw",e,a,A)})):t.resolve(f).then((function(e){u.value=e,a(u)}),(function(e){return r("throw",e,a,A)}))}A(c.arg)}var o;i(this,"_invoke",{value:function(e,n){function i(){return new t((function(t,i){r(e,n,t,i)}))}return o=o?o.then(i,i):i()}})}function k(t,r,n){var i=g;return function(o,a){if(i===d)throw Error("Generator is already running");if(i===y){if("throw"===o)throw a;return{value:e,done:!0}}for(n.method=o,n.arg=a;;){var s=n.delegate;if(s){var A=S(s,n);if(A){if(A===I)continue;return A}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(i===g)throw i=y,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);i=d;var c=l(t,r,n);if("normal"===c.type){if(i=n.done?y:p,c.arg===I)continue;return{value:c.arg,done:n.done}}"throw"===c.type&&(i=y,n.method="throw",n.arg=c.arg)}}}function S(t,r){var n=r.method,i=t.iterator[n];if(i===e)return r.delegate=null,"throw"===n&&t.iterator.return&&(r.method="return",r.arg=e,S(t,r),"throw"===r.method)||"return"!==n&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+n+"' method")),I;var o=l(i,t.iterator,r.arg);if("throw"===o.type)return r.method="throw",r.arg=o.arg,r.delegate=null,I;var a=o.arg;return a?a.done?(r[t.resultName]=a.value,r.next=t.nextLoc,"return"!==r.method&&(r.method="next",r.arg=e),r.delegate=null,I):a:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,I)}function D(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function M(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function x(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(D,this),this.reset(!0)}function N(t){if(t||""===t){var r=t[a];if(r)return r.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var i=-1,o=function r(){for(;++i<t.length;)if(n.call(t,i))return r.value=t[i],r.done=!1,r;return r.value=e,r.done=!0,r};return o.next=o}}throw new TypeError(s(t)+" is not iterable")}return C.prototype=v,i(m,"constructor",{value:v,configurable:!0}),i(v,"constructor",{value:C,configurable:!0}),C.displayName=f(v,u,"GeneratorFunction"),t.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===C||"GeneratorFunction"===(t.displayName||t.name))},t.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,v):(e.__proto__=v,f(e,u,"GeneratorFunction")),e.prototype=Object.create(m),e},t.awrap=function(e){return{__await:e}},E(Q.prototype),f(Q.prototype,c,(function(){return this})),t.AsyncIterator=Q,t.async=function(e,r,n,i,o){void 0===o&&(o=Promise);var a=new Q(h(e,r,n,i),o);return t.isGeneratorFunction(r)?a:a.next().then((function(e){return e.done?e.value:a.next()}))},E(m),f(m,u,"Generator"),f(m,a,(function(){return this})),f(m,"toString",(function(){return"[object Generator]"})),t.keys=function(e){var t=Object(e),r=[];for(var n in t)r.push(n);return r.reverse(),function e(){for(;r.length;){var n=r.pop();if(n in t)return e.value=n,e.done=!1,e}return e.done=!0,e}},t.values=N,x.prototype={constructor:x,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=e,this.done=!1,this.delegate=null,this.method="next",this.arg=e,this.tryEntries.forEach(M),!t)for(var r in this)"t"===r.charAt(0)&&n.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=e)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var r=this;function i(n,i){return s.type="throw",s.arg=t,r.next=n,i&&(r.method="next",r.arg=e),!!i}for(var o=this.tryEntries.length-1;o>=0;--o){var a=this.tryEntries[o],s=a.completion;if("root"===a.tryLoc)return i("end");if(a.tryLoc<=this.prev){var A=n.call(a,"catchLoc"),c=n.call(a,"finallyLoc");if(A&&c){if(this.prev<a.catchLoc)return i(a.catchLoc,!0);if(this.prev<a.finallyLoc)return i(a.finallyLoc)}else if(A){if(this.prev<a.catchLoc)return i(a.catchLoc,!0)}else{if(!c)throw Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return i(a.finallyLoc)}}}},abrupt:function(e,t){for(var r=this.tryEntries.length-1;r>=0;--r){var i=this.tryEntries[r];if(i.tryLoc<=this.prev&&n.call(i,"finallyLoc")&&this.prev<i.finallyLoc){var o=i;break}}o&&("break"===e||"continue"===e)&&o.tryLoc<=t&&t<=o.finallyLoc&&(o=null);var a=o?o.completion:{};return a.type=e,a.arg=t,o?(this.method="next",this.next=o.finallyLoc,I):this.complete(a)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),I},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),M(r),I}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var i=n.arg;M(r)}return i}}throw Error("illegal catch attempt")},delegateYield:function(t,r,n){return this.delegate={iterator:N(t),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=e),I}},t}function c(e,t,r,n,i,o,a){try{var s=e[o](a),A=s.value}catch(e){return void r(e)}s.done?t(A):Promise.resolve(A).then(n,i)}function u(e){return function(){var t=this,r=arguments;return new Promise((function(n,i){var o=e.apply(t,r);function a(e){c(o,n,i,a,s,"next",e)}function s(e){c(o,n,i,a,s,"throw",e)}a(void 0)}))}}var f=r.messageIdSize=8;r.maxClientMessageSize=4e6;function h(e,t,r,n){var i=new o.pb.payloads.Payload;return i.setType(e),t?i.setReplyToId(t):n?i.setMessageId(n):i.setMessageId(o.util.randomBytes(f)),i.setData(r),i}function l(e,t,r){var n=new o.pb.messages.ClientMessage;switch(n.setMessageType(e),n.setCompressionType(r),r){case o.pb.messages.CompressionType.COMPRESSION_NONE:break;case o.pb.messages.CompressionType.COMPRESSION_ZLIB:t=i.default.deflate(t);break;default:throw new o.errors.InvalidArgumentError("unknown compression type "+r)}return n.setMessage(t),n}function g(){return(g=u(A().mark((function e(r,n,i,a){var s,c,u,f,h,g,p,C,v,_;return A().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(Array.isArray(n)||(n=[n]),0!==n.length){e.next=3;