@walletconnect/core
Advanced tools
Comparing version 1.0.0-beta.3 to 1.0.0-beta.4
@@ -1,2 +0,2 @@ | ||
import { ICryptoLib, ISessionStatus, ISessionError, IPartialRpcResponse, ITxData, IClientMeta, IWalletConnectOptions } from '@walletconnect/types'; | ||
import { ICryptoLib, ISessionStatus, ISessionError, IPartialRpcResponse, IPartialRpcRequest, ITxData, IClientMeta, IWalletConnectOptions } from '@walletconnect/types'; | ||
declare class Connector { | ||
@@ -21,3 +21,5 @@ private cryptoLib; | ||
private _connected; | ||
constructor(cryptoLib: ICryptoLib, opts: IWalletConnectOptions, clientMeta?: IClientMeta); | ||
private _browser; | ||
private _pingInterval; | ||
constructor(cryptoLib: ICryptoLib, opts: IWalletConnectOptions, browser: boolean, clientMeta?: IClientMeta); | ||
bridge: string; | ||
@@ -59,2 +61,3 @@ key: string; | ||
signTypedData(params: any[]): Promise<any>; | ||
sendCustomRequest(request: IPartialRpcRequest): Promise<any>; | ||
approveRequest(response: IPartialRpcResponse): void; | ||
@@ -68,2 +71,3 @@ rejectRequest(response: IPartialRpcResponse): void; | ||
private _formatResponse; | ||
private _handleSessionDisconnect; | ||
private _handleSessionResponse; | ||
@@ -70,0 +74,0 @@ private _subscribeToSessionRequest; |
@@ -1,2 +0,2 @@ | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("@walletconnect/core",[],e):"object"==typeof exports?exports["@walletconnect/core"]=e():t["@walletconnect/core"]=e()}(window,function(){return function(t){var e={};function n(r){if(e[r])return e[r].exports;var o=e[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)n.d(r,o,function(e){return t[e]}.bind(null,o));return r},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=0)}([function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=n(1),o=n(2);var i=null;"undefined"!=typeof window&&void 0!==window.localStorage&&(i=window.localStorage);var s=function(){function t(t,e,n){if(this.cryptoLib=t,this.protocol="wc",this.version=1,this._bridge="",this._key=null,this._nextKey=null,this._clientId="",this._clientMeta=null,this._peerId="",this._peerMeta=null,this._handshakeId=0,this._handshakeTopic="",this._accounts=[],this._chainId=0,this._socket=null,this._queue=[],this._eventEmitters=[],this._connected=!1,n&&(this.clientMeta=n),!e.bridge&&!e.uri&&!e.session)throw new Error("Missing one of two required parameters: bridge / uri / session");e.bridge&&(this.bridge=e.bridge),e.uri&&(this.uri=e.uri,this._subscribeToSessionRequest());var r=e.session||this._getStorageSession();r&&(this.session=r,this._exchangeKey()),this.handshakeId&&this._subscribeToSessionResponse(this.handshakeId,"Session request rejected"),this._subscribeToInternalEvents(),this._socketOpen()}return Object.defineProperty(t.prototype,"bridge",{get:function(){return this._bridge},set:function(t){t&&(this._bridge=t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"key",{get:function(){return this._key?o.convertArrayBufferToHex(this._key):""},set:function(t){if(t){var e=o.convertHexToArrayBuffer(t);this._key=e}},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"nextKey",{get:function(){return this._nextKey?o.convertArrayBufferToHex(this._nextKey):""},set:function(t){if(t){var e=o.convertHexToArrayBuffer(t);this._nextKey=e}},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"clientId",{get:function(){var t=this._clientId;return t||(t=this._clientId=o.uuid()),this._clientId},set:function(t){t&&(this._clientId=t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"peerId",{get:function(){return this._peerId},set:function(t){t&&(this._peerId=t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"clientMeta",{get:function(){var t=this._clientMeta;return t||(t=this._clientMeta=o.getMeta()),t},set:function(t){},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"peerMeta",{get:function(){return this._peerMeta},set:function(t){this._peerMeta=t},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"handshakeTopic",{get:function(){return this._handshakeTopic},set:function(t){t&&(this._handshakeTopic=t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"handshakeId",{get:function(){return this._handshakeId},set:function(t){t&&(this._handshakeId=t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"uri",{get:function(){return this._formatUri()},set:function(t){if(t){var e=this._parseUri(t),n=e.handshakeTopic,r=e.bridge,o=e.key;this.handshakeTopic=n,this.bridge=r,this.key=o}},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"chainId",{get:function(){return this._chainId},set:function(t){this._chainId=t},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"accounts",{get:function(){return this._accounts},set:function(t){this._accounts=t},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"connected",{get:function(){return this._connected},set:function(t){},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"pending",{get:function(){return!!this._handshakeTopic},set:function(t){},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"session",{get:function(){return{connected:this.connected,accounts:this.accounts,chainId:this.chainId,bridge:this.bridge,key:this.key,clientId:this.clientId,clientMeta:this.clientMeta,peerId:this.peerId,peerMeta:this.peerMeta,handshakeId:this.handshakeId,handshakeTopic:this.handshakeTopic}},set:function(t){t&&(this._connected=t.connected,this.accounts=t.accounts,this.chainId=t.chainId,this.bridge=t.bridge,this.key=t.key,this.clientId=t.clientId,this.clientMeta=t.clientMeta,this.peerId=t.peerId,this.peerMeta=t.peerMeta,this.handshakeId=t.handshakeId,this.handshakeTopic=t.handshakeTopic)},enumerable:!0,configurable:!0}),t.prototype.on=function(t,e){var n={event:t,callback:e};this._eventEmitters.push(n)},t.prototype.createSession=function(){return r.__awaiter(this,void 0,void 0,function(){var t,e;return r.__generator(this,function(n){switch(n.label){case 0:if(this._connected)throw new Error("Session currently connected");return this.pending?[2]:(t=this,[4,this._generateKey()]);case 1:return t._key=n.sent(),e=this._formatRequest({method:"wc_sessionRequest",params:[{peerId:this.clientId,peerMeta:this.clientMeta}]}),this.handshakeId=e.id,this.handshakeTopic=o.uuid(),this._sendSessionRequest(e,"Session update rejected",this.handshakeTopic),this._setStorageSession(),[2]}})})},t.prototype.approveSession=function(t){if(this._connected)throw new Error("Session currently connected");this.chainId=t.chainId,this.accounts=t.accounts;var e={approved:!0,chainId:this.chainId,accounts:this.accounts,message:null},n={id:this.handshakeId,jsonrpc:"2.0",result:e};this._sendResponse(n),this._connected=!0,this._triggerEvents({event:"connect",params:[{peerId:this.peerId,peerMeta:this.peerMeta,chainId:this.chainId,accounts:this.accounts}]}),this._setStorageSession()},t.prototype.rejectSession=function(t){if(this._connected)throw new Error("Session currently connected");var e=t?t.message:null,n={approved:!1,chainId:null,accounts:null,message:e},r={id:this.handshakeId,jsonrpc:"2.0",result:n};this._sendResponse(r),this._connected=!1,this._triggerEvents({event:"disconnect",params:[{message:e}]}),this._removeStorageSession()},t.prototype.updateSession=function(t){if(!this._connected)throw new Error("Session currently disconnected");this.chainId=t.chainId,this.accounts=t.accounts;var e={approved:!0,chainId:this.chainId,accounts:this.accounts,message:null},n=this._formatRequest({method:"wc_sessionUpdate",params:[e]});this._sendSessionRequest(n,"Session update rejected"),this._triggerEvents({event:"session_update",params:[{chainId:this.chainId,accounts:this.accounts}]}),this._setStorageSession()},t.prototype.killSession=function(t){if(!this._connected)throw new Error("Session currently disconnected");var e=t?t.message:null,n={approved:!1,chainId:null,accounts:null,message:e},r=this._formatRequest({method:"wc_sessionUpdate",params:[n]});this._sendSessionRequest(r,"Session kill rejected"),this._connected=!1,this._triggerEvents({event:"disconnect",params:[{message:e}]}),this._removeStorageSession()},t.prototype.sendTransaction=function(t){return r.__awaiter(this,void 0,void 0,function(){var e;return r.__generator(this,function(n){switch(n.label){case 0:if(!this._connected)throw new Error("Session currently disconnected");e=this._formatRequest({method:"eth_sendTransaction",params:[t]}),n.label=1;case 1:return n.trys.push([1,3,,4]),[4,this._sendCallRequest(e)];case 2:return[2,n.sent()];case 3:throw n.sent();case 4:return[2]}})})},t.prototype.signMessage=function(t){return r.__awaiter(this,void 0,void 0,function(){var e;return r.__generator(this,function(n){switch(n.label){case 0:if(!this._connected)throw new Error("Session currently disconnected");e=this._formatRequest({method:"eth_sign",params:t}),n.label=1;case 1:return n.trys.push([1,3,,4]),[4,this._sendCallRequest(e)];case 2:return[2,n.sent()];case 3:throw n.sent();case 4:return[2]}})})},t.prototype.signTypedData=function(t){return r.__awaiter(this,void 0,void 0,function(){var e;return r.__generator(this,function(n){switch(n.label){case 0:if(!this._connected)throw new Error("Session currently disconnected");e=this._formatRequest({method:"eth_signTypedData",params:t}),n.label=1;case 1:return n.trys.push([1,3,,4]),[4,this._sendCallRequest(e)];case 2:return[2,n.sent()];case 3:throw n.sent();case 4:return[2]}})})},t.prototype.approveRequest=function(t){var e=this._formatResponse(t);this._sendResponse(e)},t.prototype.rejectRequest=function(t){var e=this._formatResponse(t);this._sendResponse(e)},t.prototype._sendRequest=function(t,e){return r.__awaiter(this,void 0,void 0,function(){var n,o,i,s,u;return r.__generator(this,function(r){switch(r.label){case 0:return n=this._formatRequest(t),[4,this._encrypt(n)];case 1:return o=r.sent(),i=e||this.peerId,s=JSON.stringify(o),u={topic:i,type:"pub",payload:s},this._socket?this._socketSend(u):this._setToQueue(u),[2]}})})},t.prototype._sendResponse=function(t){return r.__awaiter(this,void 0,void 0,function(){var e,n,o,i;return r.__generator(this,function(r){switch(r.label){case 0:return[4,this._encrypt(t)];case 1:return e=r.sent(),n=this.peerId,o=JSON.stringify(e),i={topic:n,type:"pub",payload:o},this._socket?this._socketSend(i):this._setToQueue(i),[2]}})})},t.prototype._sendSessionRequest=function(t,e,n){return r.__awaiter(this,void 0,void 0,function(){return r.__generator(this,function(r){return this._sendRequest(t,n),this._subscribeToSessionResponse(t.id,e),[2]})})},t.prototype._sendCallRequest=function(t){return this._sendRequest(t),this._subscribeToCallResponse(t.id)},t.prototype._formatRequest=function(t){return r.__assign({id:o.payloadId(),jsonrpc:"2.0"},t)},t.prototype._formatResponse=function(t){return r.__assign({jsonrpc:"2.0"},t)},t.prototype._handleSessionResponse=function(t,e){if(t.approved)this._connected?(t.chainId&&(this.chainId=t.chainId),t.accounts&&(this.accounts=t.accounts),this._triggerEvents({event:"session_update",params:[{chainId:this.chainId,accounts:this.accounts}]})):(this._connected=!0,t.chainId&&(this.chainId=t.chainId),t.accounts&&(this.accounts=t.accounts),this._triggerEvents({event:"connect",params:[{peerId:this.peerId,peerMeta:this.peerMeta,chainId:this.chainId,accounts:this.accounts}]})),this._setStorageSession();else{this._connected=!1;var n=t.message||e;this._triggerEvents({event:"disconnect",params:[{message:n}]}),console.error(n),this._removeStorageSession()}},t.prototype._subscribeToSessionRequest=function(){this._setToQueue({topic:""+this.handshakeTopic,type:"sub",payload:""})},t.prototype._subscribeToSessionResponse=function(t,e){var n=this;this.on("response:"+t,function(t,r){t&&console.error(e),n._handleSessionResponse(r.result,e)})},t.prototype._subscribeToCallResponse=function(t){var e=this;return new Promise(function(n,r){e.on("response:"+t,function(t,e){t&&r(t),e.result?n(e.result):r(new Error("Invalid JSON RPC response format received"))})})},t.prototype._subscribeToInternalEvents=function(){var t=this;this.on("wc_sessionRequest",function(e,n){e&&console.error(e),t.handshakeId=n.id,t.peerId=n.params[0].peerId,t.peerMeta=n.params[0].peerMeta,t._exchangeKey()}),this.on("wc_sessionUpdate",function(e,n){e&&console.error(e),t._handleSessionResponse(n.params[0],"Session disconnected")}),this.on("wc_exchangeKey",function(e,n){e&&console.error(e),t._handleExchangeKeyRequest(n)})},t.prototype._triggerEvents=function(t){var e,n=[];(e="method"in t?t.method:function(t){return"result"in t}(t)?"response:"+t.id:function(t){return"event"in t}(t)?t.event:"")&&(n=this._eventEmitters.filter(function(t){return t.event===e})),n&&n.length||(n=this._eventEmitters.filter(function(t){return"call_request"===t.event})),n.forEach(function(e){return e.callback(null,t)})},t.prototype._exchangeKey=function(){return r.__awaiter(this,void 0,void 0,function(){var t,e;return r.__generator(this,function(n){switch(n.label){case 0:return t=this,[4,this._generateKey()];case 1:t._nextKey=n.sent(),e=this._formatRequest({method:"wc_exchangeKey",params:[{peerId:this.clientId,peerMeta:this.clientMeta,nextKey:this.nextKey}]}),n.label=2;case 2:return n.trys.push([2,4,,5]),[4,this._sendCallRequest(e)];case 3:return n.sent(),this._swapKey(),[3,5];case 4:throw n.sent();case 5:return[2]}})})},t.prototype._handleExchangeKeyRequest=function(t){return r.__awaiter(this,void 0,void 0,function(){var e,n,o,i,s;return r.__generator(this,function(r){switch(r.label){case 0:return e=t.params[0],n=e.peerId,o=e.peerMeta,i=e.nextKey,this.peerId=n,this.peerMeta=o,this.nextKey=i,s={id:t.id,jsonrpc:"2.0",result:!0},[4,this._sendResponse(s)];case 1:return r.sent(),this._swapKey(),[2]}})})},t.prototype._swapKey=function(){this._key=this._nextKey,this._nextKey=null,this._setStorageSession()},t.prototype._socketOpen=function(){var t=this,e=this.bridge,n=e.startsWith("https")?e.replace("https","wss"):e.startsWith("http")?e.replace("http","ws"):e,r=new WebSocket(n);r.onmessage=function(e){return t._socketReceive(e)},r.onopen=function(){t._socket=r,t._setToQueue({topic:""+t.clientId,type:"sub",payload:""}),t._dispatchQueue()}},t.prototype._socketSend=function(t){var e=this._socket;if(!e)throw new Error("Missing socket: required for sending message");var n=JSON.stringify(t);e.send(n)},t.prototype._socketReceive=function(t){return r.__awaiter(this,void 0,void 0,function(){var e,n,o;return r.__generator(this,function(r){switch(r.label){case 0:try{e=JSON.parse(t.data)}catch(t){throw t}if(![this.clientId,this.handshakeTopic].includes(e.topic))return[2];try{n=JSON.parse(e.payload)}catch(t){throw t}return[4,this._decrypt(n)];case 1:return(o=r.sent())&&this._triggerEvents(o),[2]}})})},t.prototype._setToQueue=function(t){this._queue.push(t)},t.prototype._dispatchQueue=function(){var t=this;this._queue.forEach(function(e){return t._socketSend(e)}),this._queue=[]},t.prototype._formatUri=function(){return this.protocol+":"+this.handshakeTopic+"@"+this.version+"?bridge="+encodeURIComponent(this.bridge)+"&key="+this.key},t.prototype._parseUri=function(t){var e=o.parseWalletConnectUri(t);if(e.protocol===this.protocol){if(!e.handshakeTopic)throw Error("Invalid or missing handshakeTopic parameter value");var n=e.handshakeTopic;if(!e.bridge)throw Error("Invalid or missing bridge url parameter value");var r=decodeURIComponent(e.bridge);if(!e.key)throw Error("Invalid or missing kkey parameter value");return{handshakeTopic:n,bridge:r,key:e.key}}throw new Error("URI format doesn't follow Connector protocol")},t.prototype._generateKey=function(){return r.__awaiter(this,void 0,void 0,function(){return r.__generator(this,function(t){switch(t.label){case 0:return this.cryptoLib?[4,this.cryptoLib.generateKey()]:[3,2];case 1:return[2,t.sent()];case 2:return[2,null]}})})},t.prototype._encrypt=function(t){return r.__awaiter(this,void 0,void 0,function(){var e;return r.__generator(this,function(n){switch(n.label){case 0:return e=this._key,this.cryptoLib&&e?[4,this.cryptoLib.encrypt(t,e)]:[3,2];case 1:return[2,n.sent()];case 2:return[2,null]}})})},t.prototype._decrypt=function(t){return r.__awaiter(this,void 0,void 0,function(){var e;return r.__generator(this,function(n){switch(n.label){case 0:return e=this._key,this.cryptoLib&&e?[4,this.cryptoLib.decrypt(t,e)]:[3,2];case 1:return[2,n.sent()];case 2:return[2,null]}})})},t.prototype._getStorageSession=function(){var t=null,e=null;if(i&&(e=i.getItem("walletconnect")),e&&"string"==typeof e)try{var n=JSON.parse(e);"bridge"in n&&(t=n)}catch(t){throw t}return t},t.prototype._setStorageSession=function(){var t=this.session,e=JSON.stringify(t);return i&&i.setItem("walletconnect",e),t},t.prototype._removeStorageSession=function(){i&&i.removeItem("walletconnect")},t}();e.default=s},function(t,e,n){"use strict";n.r(e),n.d(e,"__extends",function(){return o}),n.d(e,"__assign",function(){return i}),n.d(e,"__rest",function(){return s}),n.d(e,"__decorate",function(){return u}),n.d(e,"__param",function(){return a}),n.d(e,"__metadata",function(){return c}),n.d(e,"__awaiter",function(){return f}),n.d(e,"__generator",function(){return h}),n.d(e,"__exportStar",function(){return l}),n.d(e,"__values",function(){return p}),n.d(e,"__read",function(){return d}),n.d(e,"__spread",function(){return y}),n.d(e,"__await",function(){return _}),n.d(e,"__asyncGenerator",function(){return g}),n.d(e,"__asyncDelegator",function(){return v}),n.d(e,"__asyncValues",function(){return w}),n.d(e,"__makeTemplateObject",function(){return b}),n.d(e,"__importStar",function(){return m}),n.d(e,"__importDefault",function(){return S}); | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("@walletconnect/core",[],e):"object"==typeof exports?exports["@walletconnect/core"]=e():t["@walletconnect/core"]=e()}(window,function(){return function(t){var e={};function n(r){if(e[r])return e[r].exports;var o=e[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)n.d(r,o,function(e){return t[e]}.bind(null,o));return r},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=0)}([function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=n(1),o=n(2);function i(t){return"result"in t}function s(t){return"error"in t}var u=null;"undefined"!=typeof window&&void 0!==window.localStorage&&(u=window.localStorage);var a=function(){function t(t,e,n,r){if(this.cryptoLib=t,this.protocol="wc",this.version=1,this._bridge="",this._key=null,this._nextKey=null,this._clientId="",this._clientMeta=null,this._peerId="",this._peerMeta=null,this._handshakeId=0,this._handshakeTopic="",this._accounts=[],this._chainId=0,this._socket=null,this._queue=[],this._eventEmitters=[],this._connected=!1,this._browser=n,this._pingInterval=null,r&&(this.clientMeta=r),!e.bridge&&!e.uri&&!e.session)throw new Error("Missing one of two required parameters: bridge / uri / session");e.bridge&&(this.bridge=e.bridge),e.uri&&(this.uri=e.uri,this._subscribeToSessionRequest());var o=e.session||this._getStorageSession();o&&(this.session=o,this._browser&&this._exchangeKey()),this.handshakeId&&this._subscribeToSessionResponse(this.handshakeId,"Session request rejected"),this._subscribeToInternalEvents(),this._socketOpen()}return Object.defineProperty(t.prototype,"bridge",{get:function(){return this._bridge},set:function(t){t&&(this._bridge=t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"key",{get:function(){return this._key?o.convertArrayBufferToHex(this._key):""},set:function(t){if(t){var e=o.convertHexToArrayBuffer(t);this._key=e}},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"nextKey",{get:function(){return this._nextKey?o.convertArrayBufferToHex(this._nextKey):""},set:function(t){if(t){var e=o.convertHexToArrayBuffer(t);this._nextKey=e}},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"clientId",{get:function(){var t=this._clientId;return t||(t=this._clientId=o.uuid()),this._clientId},set:function(t){t&&(this._clientId=t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"peerId",{get:function(){return this._peerId},set:function(t){t&&(this._peerId=t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"clientMeta",{get:function(){var t=this._clientMeta;return t||(t=this._clientMeta=o.getMeta()),t},set:function(t){},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"peerMeta",{get:function(){return this._peerMeta},set:function(t){this._peerMeta=t},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"handshakeTopic",{get:function(){return this._handshakeTopic},set:function(t){t&&(this._handshakeTopic=t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"handshakeId",{get:function(){return this._handshakeId},set:function(t){t&&(this._handshakeId=t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"uri",{get:function(){return this._formatUri()},set:function(t){if(t){var e=this._parseUri(t),n=e.handshakeTopic,r=e.bridge,o=e.key;this.handshakeTopic=n,this.bridge=r,this.key=o}},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"chainId",{get:function(){return this._chainId},set:function(t){this._chainId=t},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"accounts",{get:function(){return this._accounts},set:function(t){this._accounts=t},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"connected",{get:function(){return this._connected},set:function(t){},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"pending",{get:function(){return!!this._handshakeTopic},set:function(t){},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"session",{get:function(){return{connected:this.connected,accounts:this.accounts,chainId:this.chainId,bridge:this.bridge,key:this.key,clientId:this.clientId,clientMeta:this.clientMeta,peerId:this.peerId,peerMeta:this.peerMeta,handshakeId:this.handshakeId,handshakeTopic:this.handshakeTopic}},set:function(t){t&&(this._connected=t.connected,this.accounts=t.accounts,this.chainId=t.chainId,this.bridge=t.bridge,this.key=t.key,this.clientId=t.clientId,this.clientMeta=t.clientMeta,this.peerId=t.peerId,this.peerMeta=t.peerMeta,this.handshakeId=t.handshakeId,this.handshakeTopic=t.handshakeTopic)},enumerable:!0,configurable:!0}),t.prototype.on=function(t,e){var n={event:t,callback:e};this._eventEmitters.push(n)},t.prototype.createSession=function(){return r.__awaiter(this,void 0,void 0,function(){var t,e;return r.__generator(this,function(n){switch(n.label){case 0:if(this._connected)throw new Error("Session currently connected");return this.pending?[2]:(t=this,[4,this._generateKey()]);case 1:return t._key=n.sent(),e=this._formatRequest({method:"wc_sessionRequest",params:[{peerId:this.clientId,peerMeta:this.clientMeta}]}),this.handshakeId=e.id,this.handshakeTopic=o.uuid(),this._sendSessionRequest(e,"Session update rejected",this.handshakeTopic),this._setStorageSession(),[2]}})})},t.prototype.approveSession=function(t){if(this._connected)throw new Error("Session currently connected");this.chainId=t.chainId,this.accounts=t.accounts;var e={approved:!0,chainId:this.chainId,accounts:this.accounts},n={id:this.handshakeId,jsonrpc:"2.0",result:e};this._sendResponse(n),this._connected=!0,this._triggerEvents({event:"connect",params:[{peerId:this.peerId,peerMeta:this.peerMeta,chainId:this.chainId,accounts:this.accounts}]}),this._setStorageSession()},t.prototype.rejectSession=function(t){if(this._connected)throw new Error("Session currently connected");var e=t&&t.message?t.message:"Session Rejected",n=this._formatResponse({id:this.handshakeId,error:{message:e}});this._sendResponse(n),this._connected=!1,this._triggerEvents({event:"disconnect",params:[{message:e}]}),this._removeStorageSession()},t.prototype.updateSession=function(t){if(!this._connected)throw new Error("Session currently disconnected");this.chainId=t.chainId,this.accounts=t.accounts;var e={approved:!0,chainId:this.chainId,accounts:this.accounts},n=this._formatRequest({method:"wc_sessionUpdate",params:[e]});this._sendSessionRequest(n,"Session update rejected"),this._triggerEvents({event:"session_update",params:[{chainId:this.chainId,accounts:this.accounts}]}),this._setStorageSession()},t.prototype.killSession=function(t){var e=t?t.message:"Session Disconnected",n=this._formatRequest({method:"wc_sessionUpdate",params:[{approved:!1,chainId:null,accounts:null}]});this._sendSessionRequest(n,"Failed to kill Session"),this._handleSessionDisconnect(e)},t.prototype.sendTransaction=function(t){return r.__awaiter(this,void 0,void 0,function(){var e;return r.__generator(this,function(n){switch(n.label){case 0:if(!this._connected)throw new Error("Session currently disconnected");e=this._formatRequest({method:"eth_sendTransaction",params:[t]}),n.label=1;case 1:return n.trys.push([1,3,,4]),[4,this._sendCallRequest(e)];case 2:return[2,n.sent()];case 3:throw n.sent();case 4:return[2]}})})},t.prototype.signMessage=function(t){return r.__awaiter(this,void 0,void 0,function(){var e;return r.__generator(this,function(n){switch(n.label){case 0:if(!this._connected)throw new Error("Session currently disconnected");e=this._formatRequest({method:"eth_sign",params:t}),n.label=1;case 1:return n.trys.push([1,3,,4]),[4,this._sendCallRequest(e)];case 2:return[2,n.sent()];case 3:throw n.sent();case 4:return[2]}})})},t.prototype.signTypedData=function(t){return r.__awaiter(this,void 0,void 0,function(){var e;return r.__generator(this,function(n){switch(n.label){case 0:if(!this._connected)throw new Error("Session currently disconnected");e=this._formatRequest({method:"eth_signTypedData",params:t}),n.label=1;case 1:return n.trys.push([1,3,,4]),[4,this._sendCallRequest(e)];case 2:return[2,n.sent()];case 3:throw n.sent();case 4:return[2]}})})},t.prototype.sendCustomRequest=function(t){return r.__awaiter(this,void 0,void 0,function(){var e;return r.__generator(this,function(n){switch(n.label){case 0:if(!this._connected)throw new Error("Session currently disconnected");e=this._formatRequest(t),n.label=1;case 1:return n.trys.push([1,3,,4]),[4,this._sendCallRequest(e)];case 2:return[2,n.sent()];case 3:throw n.sent();case 4:return[2]}})})},t.prototype.approveRequest=function(t){if(!i(t))throw new Error('JSON-RPC success response must include "result" field');var e=this._formatResponse(t);this._sendResponse(e)},t.prototype.rejectRequest=function(t){if(!s(t))throw new Error('JSON-RPC error response must include "error" field');var e=this._formatResponse(t);this._sendResponse(e)},t.prototype._sendRequest=function(t,e){return r.__awaiter(this,void 0,void 0,function(){var n,o,i,s,u;return r.__generator(this,function(r){switch(r.label){case 0:return n=this._formatRequest(t),[4,this._encrypt(n)];case 1:return o=r.sent(),i=e||this.peerId,s=JSON.stringify(o),u={topic:i,type:"pub",payload:s},this._socket?this._socketSend(u):this._setToQueue(u),[2]}})})},t.prototype._sendResponse=function(t){return r.__awaiter(this,void 0,void 0,function(){var e,n,o,i;return r.__generator(this,function(r){switch(r.label){case 0:return[4,this._encrypt(t)];case 1:return e=r.sent(),n=this.peerId,o=JSON.stringify(e),i={topic:n,type:"pub",payload:o},this._socket?this._socketSend(i):this._setToQueue(i),[2]}})})},t.prototype._sendSessionRequest=function(t,e,n){return r.__awaiter(this,void 0,void 0,function(){return r.__generator(this,function(r){return this._sendRequest(t,n),this._subscribeToSessionResponse(t.id,e),[2]})})},t.prototype._sendCallRequest=function(t){return this._sendRequest(t),this._subscribeToCallResponse(t.id)},t.prototype._formatRequest=function(t){return r.__assign({id:o.payloadId(),jsonrpc:"2.0"},t)},t.prototype._formatResponse=function(t){if(s(t)){var e=o.formatRpcError(t.error);return r.__assign({jsonrpc:"2.0"},t,{error:e})}return r.__assign({jsonrpc:"2.0",result:null},t)},t.prototype._handleSessionDisconnect=function(t){var e=t||"Session Disconnected";this._connected=!1,this._triggerEvents({event:"disconnect",params:[{message:e}]}),console.error(e),this._removeStorageSession(),clearInterval(this._pingInterval)},t.prototype._handleSessionResponse=function(t,e){e&&e.approved?(this._connected?(e.chainId&&(this.chainId=e.chainId),e.accounts&&(this.accounts=e.accounts),this._triggerEvents({event:"session_update",params:[{chainId:this.chainId,accounts:this.accounts}]})):(this._connected=!0,e.chainId&&(this.chainId=e.chainId),e.accounts&&(this.accounts=e.accounts),this._triggerEvents({event:"connect",params:[{peerId:this.peerId,peerMeta:this.peerMeta,chainId:this.chainId,accounts:this.accounts}]})),this._setStorageSession()):this._handleSessionDisconnect(t)},t.prototype._subscribeToSessionRequest=function(){this._setToQueue({topic:""+this.handshakeTopic,type:"sub",payload:""})},t.prototype._subscribeToSessionResponse=function(t,e){var n=this;this.on("response:"+t,function(t,r){t&&n._handleSessionResponse(t.message),n._handleSessionResponse(e,r.result)})},t.prototype._subscribeToCallResponse=function(t){var e=this;return new Promise(function(n,r){e.on("response:"+t,function(t,e){t&&r(t),e.result?n(e.result):r(new Error("Invalid JSON RPC response format received"))})})},t.prototype._subscribeToInternalEvents=function(){var t=this;this.on("wc_sessionRequest",function(e,n){e&&console.error(e),t.handshakeId=n.id,t.peerId=n.params[0].peerId,t.peerMeta=n.params[0].peerMeta,t._exchangeKey();var o=r.__assign({},n,{method:"session_request"});t._triggerEvents(o)}),this.on("wc_sessionUpdate",function(e,n){e&&t._handleSessionResponse(e.message),t._handleSessionResponse("Session disconnected",n.params[0])}),this.on("wc_exchangeKey",function(e,n){e&&console.error(e),t._handleExchangeKeyRequest(n)})},t.prototype._triggerEvents=function(t){var e,n=[];(e="method"in t?t.method:i(t)||s(t)?"response:"+t.id:function(t){return"event"in t}(t)?t.event:"")&&(n=this._eventEmitters.filter(function(t){return t.event===e})),n&&n.length||(n=this._eventEmitters.filter(function(t){return"call_request"===t.event})),n.forEach(function(e){if(s(t)){var n=new Error(t.error.message);e.callback(n,null)}else e.callback(null,t)})},t.prototype._exchangeKey=function(){return r.__awaiter(this,void 0,void 0,function(){var t,e;return r.__generator(this,function(n){switch(n.label){case 0:return t=this,[4,this._generateKey()];case 1:t._nextKey=n.sent(),e=this._formatRequest({method:"wc_exchangeKey",params:[{peerId:this.clientId,peerMeta:this.clientMeta,nextKey:this.nextKey}]}),n.label=2;case 2:return n.trys.push([2,4,,5]),[4,this._sendCallRequest(e)];case 3:return n.sent(),this._swapKey(),[3,5];case 4:throw n.sent();case 5:return[2]}})})},t.prototype._handleExchangeKeyRequest=function(t){return r.__awaiter(this,void 0,void 0,function(){var e,n,o,i,s;return r.__generator(this,function(r){switch(r.label){case 0:return e=t.params[0],n=e.peerId,o=e.peerMeta,i=e.nextKey,this.peerId=n,this.peerMeta=o,this.nextKey=i,s={id:t.id,jsonrpc:"2.0",result:!0},[4,this._sendResponse(s)];case 1:return r.sent(),this._swapKey(),[2]}})})},t.prototype._swapKey=function(){this._key=this._nextKey,this._nextKey=null,this._setStorageSession()},t.prototype._socketOpen=function(){var t=this,e=this.bridge,n=e.startsWith("https")?e.replace("https","wss"):e.startsWith("http")?e.replace("http","ws"):e,r=new WebSocket(n);r.onmessage=function(e){return t._socketReceive(e)},r.onopen=function(){t._socket=r,t._setToQueue({topic:""+t.clientId,type:"sub",payload:""}),t._dispatchQueue(),t._pingInterval=setInterval(function(){r.send("ping")},500)}},t.prototype._socketSend=function(t){var e=this._socket;if(!e)throw new Error("Missing socket: required for sending message");var n=JSON.stringify(t);e.send(n)},t.prototype._socketReceive=function(t){return r.__awaiter(this,void 0,void 0,function(){var e,n,o;return r.__generator(this,function(r){switch(r.label){case 0:try{e=JSON.parse(t.data)}catch(t){throw t}if(![this.clientId,this.handshakeTopic].includes(e.topic))return[2];try{n=JSON.parse(e.payload)}catch(t){throw t}return[4,this._decrypt(n)];case 1:return(o=r.sent())&&this._triggerEvents(o),[2]}})})},t.prototype._setToQueue=function(t){this._queue.push(t)},t.prototype._dispatchQueue=function(){var t=this;this._queue.forEach(function(e){return t._socketSend(e)}),this._queue=[]},t.prototype._formatUri=function(){return this.protocol+":"+this.handshakeTopic+"@"+this.version+"?bridge="+encodeURIComponent(this.bridge)+"&key="+this.key},t.prototype._parseUri=function(t){var e=o.parseWalletConnectUri(t);if(e.protocol===this.protocol){if(!e.handshakeTopic)throw Error("Invalid or missing handshakeTopic parameter value");var n=e.handshakeTopic;if(!e.bridge)throw Error("Invalid or missing bridge url parameter value");var r=decodeURIComponent(e.bridge);if(!e.key)throw Error("Invalid or missing kkey parameter value");return{handshakeTopic:n,bridge:r,key:e.key}}throw new Error("URI format doesn't follow Connector protocol")},t.prototype._generateKey=function(){return r.__awaiter(this,void 0,void 0,function(){return r.__generator(this,function(t){switch(t.label){case 0:return this.cryptoLib?[4,this.cryptoLib.generateKey()]:[3,2];case 1:return[2,t.sent()];case 2:return[2,null]}})})},t.prototype._encrypt=function(t){return r.__awaiter(this,void 0,void 0,function(){var e;return r.__generator(this,function(n){switch(n.label){case 0:return e=this._key,this.cryptoLib&&e?[4,this.cryptoLib.encrypt(t,e)]:[3,2];case 1:return[2,n.sent()];case 2:return[2,null]}})})},t.prototype._decrypt=function(t){return r.__awaiter(this,void 0,void 0,function(){var e;return r.__generator(this,function(n){switch(n.label){case 0:return e=this._key,this.cryptoLib&&e?[4,this.cryptoLib.decrypt(t,e)]:[3,2];case 1:return[2,n.sent()];case 2:return[2,null]}})})},t.prototype._getStorageSession=function(){var t=null,e=null;if(u&&(e=u.getItem("walletconnect")),e&&"string"==typeof e)try{var n=JSON.parse(e);"bridge"in n&&(t=n)}catch(t){throw t}return t},t.prototype._setStorageSession=function(){var t=this.session,e=JSON.stringify(t);return u&&u.setItem("walletconnect",e),t},t.prototype._removeStorageSession=function(){u&&u.removeItem("walletconnect")},t}();e.default=a},function(t,e,n){"use strict";n.r(e),n.d(e,"__extends",function(){return o}),n.d(e,"__assign",function(){return i}),n.d(e,"__rest",function(){return s}),n.d(e,"__decorate",function(){return u}),n.d(e,"__param",function(){return a}),n.d(e,"__metadata",function(){return c}),n.d(e,"__awaiter",function(){return f}),n.d(e,"__generator",function(){return h}),n.d(e,"__exportStar",function(){return l}),n.d(e,"__values",function(){return p}),n.d(e,"__read",function(){return d}),n.d(e,"__spread",function(){return y}),n.d(e,"__await",function(){return _}),n.d(e,"__asyncGenerator",function(){return g}),n.d(e,"__asyncDelegator",function(){return v}),n.d(e,"__asyncValues",function(){return w}),n.d(e,"__makeTemplateObject",function(){return b}),n.d(e,"__importStar",function(){return m}),n.d(e,"__importDefault",function(){return S}); | ||
/*! ***************************************************************************** | ||
@@ -16,3 +16,3 @@ Copyright (c) Microsoft Corporation. All rights reserved. | ||
***************************************************************************** */ | ||
var r=function(t,e){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,e)};function o(t,e){function n(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}var i=function(){return(i=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)};function s(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(t);o<r.length;o++)e.indexOf(r[o])<0&&(n[r[o]]=t[r[o]])}return n}function u(t,e,n,r){var o,i=arguments.length,s=i<3?e:null===r?r=Object.getOwnPropertyDescriptor(e,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(t,e,n,r);else for(var u=t.length-1;u>=0;u--)(o=t[u])&&(s=(i<3?o(s):i>3?o(e,n,s):o(e,n))||s);return i>3&&s&&Object.defineProperty(e,n,s),s}function a(t,e){return function(n,r){e(n,r,t)}}function c(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)}function f(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{a(r.next(t))}catch(t){i(t)}}function u(t){try{a(r.throw(t))}catch(t){i(t)}}function a(t){t.done?o(t.value):new n(function(e){e(t.value)}).then(s,u)}a((r=r.apply(t,e||[])).next())})}function h(t,e){var n,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(i){return function(u){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,r=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!(o=(o=s.trys).length>0&&o[o.length-1])&&(6===i[0]||2===i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){s.label=i[1];break}if(6===i[0]&&s.label<o[1]){s.label=o[1],o=i;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(i);break}o[2]&&s.ops.pop(),s.trys.pop();continue}i=e.call(t,s)}catch(t){i=[6,t],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,u])}}}function l(t,e){for(var n in t)e.hasOwnProperty(n)||(e[n]=t[n])}function p(t){var e="function"==typeof Symbol&&t[Symbol.iterator],n=0;return e?e.call(t):{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}}}function d(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)s.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return s}function y(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(d(arguments[e]));return t}function _(t){return this instanceof _?(this.v=t,this):new _(t)}function g(t,e,n){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var r,o=n.apply(t,e||[]),i=[];return r={},s("next"),s("throw"),s("return"),r[Symbol.asyncIterator]=function(){return this},r;function s(t){o[t]&&(r[t]=function(e){return new Promise(function(n,r){i.push([t,e,n,r])>1||u(t,e)})})}function u(t,e){try{(n=o[t](e)).value instanceof _?Promise.resolve(n.value.v).then(a,c):f(i[0][2],n)}catch(t){f(i[0][3],t)}var n}function a(t){u("next",t)}function c(t){u("throw",t)}function f(t,e){t(e),i.shift(),i.length&&u(i[0][0],i[0][1])}}function v(t){var e,n;return e={},r("next"),r("throw",function(t){throw t}),r("return"),e[Symbol.iterator]=function(){return this},e;function r(r,o){e[r]=t[r]?function(e){return(n=!n)?{value:_(t[r](e)),done:"return"===r}:o?o(e):e}:o}}function w(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e,n=t[Symbol.asyncIterator];return n?n.call(t):(t=p(t),e={},r("next"),r("throw"),r("return"),e[Symbol.asyncIterator]=function(){return this},e);function r(n){e[n]=t[n]&&function(e){return new Promise(function(r,o){(function(t,e,n,r){Promise.resolve(r).then(function(e){t({value:e,done:n})},e)})(r,o,(e=t[n](e)).done,e.value)})}}}function b(t,e){return Object.defineProperty?Object.defineProperty(t,"raw",{value:e}):t.raw=e,t}function m(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var n in t)Object.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e.default=t,e}function S(t){return t&&t.__esModule?t:{default:t}}},function(t,e,n){window,t.exports=function(t){var e={};function n(r){if(e[r])return e[r].exports;var o=e[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)n.d(r,o,function(e){return t[e]}.bind(null,o));return r},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=0)}([function(t,e,n){"use strict";(function(t){Object.defineProperty(e,"__esModule",{value:!0});var r=n(6);function o(t){return t.toString("hex")}function i(e){return new t(e,"hex")}function s(t){for(var e=new Uint8Array(t),n=[],r=0;r<e.length;r++){var o=e[r];n.push("0123456789abcdef"[(240&o)>>4]+"0123456789abcdef"[15&o])}return n.join("")}function u(t){for(var e=[],n=0;n<t.length;n+=2)e.push(parseInt(t.substr(n,2),16));return new Uint8Array(e).buffer}e.convertArrayBufferToBuffer=function(t){return i(s(t))},e.convertBufferToArrayBuffer=function(t){return u(o(t))},e.convertUtf8ToBuffer=function(e){return new t(e,"utf8")},e.convertBufferToUtf8=function(t){return t.toString("utf8")},e.convertBufferToHex=o,e.convertHexToBuffer=i,e.concatBuffers=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return i(t.map(function(t){return o(t)}).join(""))},e.concatArrayBuffers=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return u(t.map(function(t){return s(t)}).join(""))},e.convertArrayBufferToUtf8=function(t){for(var e=new Uint8Array(t),n=[],r=0;r<e.length;){var o=e[r];o<128?(n.push(String.fromCharCode(o)),r++):o>191&&o<224?(n.push(String.fromCharCode((31&o)<<6|63&e[r+1])),r+=2):(n.push(String.fromCharCode((15&o)<<12|(63&e[r+1])<<6|63&e[r+2])),r+=3)}return n.join("")},e.convertUtf8ToArrayBuffer=function(t){var e=[],n=0;for(t=encodeURI(t);n<t.length;){var r=t.charCodeAt(n++);37===r?(e.push(parseInt(t.substr(n,2),16)),n+=2):e.push(r)}return new Uint8Array(e).buffer},e.convertArrayBufferToHex=s,e.convertHexToArrayBuffer=u,e.payloadId=function(){return(new Date).getTime()*Math.pow(10,3)+Math.floor(Math.random()*Math.pow(10,3))},e.uuid=function(){return function(t,e){for(e=t="";t++<36;e+=51*t&52?(15^t?8^Math.random()*(20^t?16:4):4).toString(16):"-");return e}()},e.getMeta=function(){if("undefined"==typeof window||"undefined"==typeof document||void 0===window.location)return null;function t(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];for(var n=document.getElementsByTagName("meta"),r=function(e){var r=n[e],o=["itemprop","property","name"].map(function(t){return r.getAttribute(t)}).filter(function(e){e&&t.includes(e)});if(o.length&&o){var i=r.getAttribute("content");if(i)return{value:i}}},o=0;o<n.length;o++){var i=r(o);if("object"==typeof i)return i.value}return""}var e=function(){var e=t("name","og:site_name","og:title","twitter:title");return e||(e=document.title),e}(),n=t("description","og:description","twitter:description","keywords"),r=window.location.href.startsWith("https");return{description:n,url:window.location.origin,icons:function(){for(var t=document.getElementsByTagName("link"),e=[],n=0;n<t.length;n++){var r=t[n],o=r.getAttribute("rel");if(o&&o.toLowerCase().indexOf("icon")>-1){var i=r.getAttribute("href");if(i)if(-1===i.toLowerCase().indexOf("https:")&&-1===i.toLowerCase().indexOf("http:")&&0!==i.indexOf("//")){var s=window.location.protocol+"//"+window.location.host;if(0===i.indexOf("/"))s+=i;else{var u=window.location.pathname.split("/");u.pop(),s+=u.join("/")+"/"+i}e.push(s)}else if(0===i.indexOf("//")){var a=window.location.protocol+i;e.push(a)}else e.push(i)}}return e}(),name:e,ssl:r}},e.parseWalletConnectUri=function(t){var e=t.indexOf(":"),n=-1!==t.indexOf("?")?t.indexOf("?"):void 0,o=t.substring(0,e),i=function(t){var e=t.split("@");return{handshakeTopic:e[0],version:parseInt(e[1],10)}}(t.substring(e+1,n)),s=function(t){for(var e={},n=("?"===t[0]?t.substr(1):t).split("&"),r=0;r<n.length;r++){var o=n[r].match(/\w+(?==)/i)||[],i=n[r].match(/=.+/i)||[];o[0]&&(e[decodeURIComponent(o[0])]=decodeURIComponent(i[0].substr(1)))}return{key:e.key||"",bridge:e.bridge||""}}(void 0!==n?t.substr(n):"");return r.__assign({protocol:o},i,s)},e.promisify=function(t,e){var n=this;return function(){for(var o=[],i=0;i<arguments.length;i++)o[i]=arguments[i];return r.__awaiter(n,void 0,void 0,function(){return r.__generator(this,function(n){return[2,new Promise(function(n,i){t.apply(e,r.__spread(o,[function(t,e){null==t&&i(t),n(e)}]))})]})})}}}).call(this,n(1).Buffer)},function(t,e,n){"use strict";(function(t){ | ||
var r=function(t,e){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,e)};function o(t,e){function n(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}var i=function(){return(i=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)};function s(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(t);o<r.length;o++)e.indexOf(r[o])<0&&(n[r[o]]=t[r[o]])}return n}function u(t,e,n,r){var o,i=arguments.length,s=i<3?e:null===r?r=Object.getOwnPropertyDescriptor(e,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(t,e,n,r);else for(var u=t.length-1;u>=0;u--)(o=t[u])&&(s=(i<3?o(s):i>3?o(e,n,s):o(e,n))||s);return i>3&&s&&Object.defineProperty(e,n,s),s}function a(t,e){return function(n,r){e(n,r,t)}}function c(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)}function f(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{a(r.next(t))}catch(t){i(t)}}function u(t){try{a(r.throw(t))}catch(t){i(t)}}function a(t){t.done?o(t.value):new n(function(e){e(t.value)}).then(s,u)}a((r=r.apply(t,e||[])).next())})}function h(t,e){var n,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(i){return function(u){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,r=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!(o=(o=s.trys).length>0&&o[o.length-1])&&(6===i[0]||2===i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){s.label=i[1];break}if(6===i[0]&&s.label<o[1]){s.label=o[1],o=i;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(i);break}o[2]&&s.ops.pop(),s.trys.pop();continue}i=e.call(t,s)}catch(t){i=[6,t],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,u])}}}function l(t,e){for(var n in t)e.hasOwnProperty(n)||(e[n]=t[n])}function p(t){var e="function"==typeof Symbol&&t[Symbol.iterator],n=0;return e?e.call(t):{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}}}function d(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)s.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return s}function y(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(d(arguments[e]));return t}function _(t){return this instanceof _?(this.v=t,this):new _(t)}function g(t,e,n){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var r,o=n.apply(t,e||[]),i=[];return r={},s("next"),s("throw"),s("return"),r[Symbol.asyncIterator]=function(){return this},r;function s(t){o[t]&&(r[t]=function(e){return new Promise(function(n,r){i.push([t,e,n,r])>1||u(t,e)})})}function u(t,e){try{(n=o[t](e)).value instanceof _?Promise.resolve(n.value.v).then(a,c):f(i[0][2],n)}catch(t){f(i[0][3],t)}var n}function a(t){u("next",t)}function c(t){u("throw",t)}function f(t,e){t(e),i.shift(),i.length&&u(i[0][0],i[0][1])}}function v(t){var e,n;return e={},r("next"),r("throw",function(t){throw t}),r("return"),e[Symbol.iterator]=function(){return this},e;function r(r,o){e[r]=t[r]?function(e){return(n=!n)?{value:_(t[r](e)),done:"return"===r}:o?o(e):e}:o}}function w(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e,n=t[Symbol.asyncIterator];return n?n.call(t):(t=p(t),e={},r("next"),r("throw"),r("return"),e[Symbol.asyncIterator]=function(){return this},e);function r(n){e[n]=t[n]&&function(e){return new Promise(function(r,o){(function(t,e,n,r){Promise.resolve(r).then(function(e){t({value:e,done:n})},e)})(r,o,(e=t[n](e)).done,e.value)})}}}function b(t,e){return Object.defineProperty?Object.defineProperty(t,"raw",{value:e}):t.raw=e,t}function m(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var n in t)Object.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e.default=t,e}function S(t){return t&&t.__esModule?t:{default:t}}},function(t,e,n){window,t.exports=function(t){var e={};function n(r){if(e[r])return e[r].exports;var o=e[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)n.d(r,o,function(e){return t[e]}.bind(null,o));return r},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=0)}([function(t,e,n){"use strict";(function(t){Object.defineProperty(e,"__esModule",{value:!0});var r=n(6);function o(t){return t.toString("hex")}function i(e){return new t(e,"hex")}function s(t){for(var e=new Uint8Array(t),n=[],r=0;r<e.length;r++){var o=e[r];n.push("0123456789abcdef"[(240&o)>>4]+"0123456789abcdef"[15&o])}return n.join("")}function u(t){for(var e=[],n=0;n<t.length;n+=2)e.push(parseInt(t.substr(n,2),16));return new Uint8Array(e).buffer}e.convertArrayBufferToBuffer=function(t){return i(s(t))},e.convertBufferToArrayBuffer=function(t){return u(o(t))},e.convertUtf8ToBuffer=function(e){return new t(e,"utf8")},e.convertBufferToUtf8=function(t){return t.toString("utf8")},e.convertBufferToHex=o,e.convertHexToBuffer=i,e.concatBuffers=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return i(t.map(function(t){return o(t)}).join(""))},e.concatArrayBuffers=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return u(t.map(function(t){return s(t)}).join(""))},e.convertArrayBufferToUtf8=function(t){for(var e=new Uint8Array(t),n=[],r=0;r<e.length;){var o=e[r];o<128?(n.push(String.fromCharCode(o)),r++):o>191&&o<224?(n.push(String.fromCharCode((31&o)<<6|63&e[r+1])),r+=2):(n.push(String.fromCharCode((15&o)<<12|(63&e[r+1])<<6|63&e[r+2])),r+=3)}return n.join("")},e.convertUtf8ToArrayBuffer=function(t){var e=[],n=0;for(t=encodeURI(t);n<t.length;){var r=t.charCodeAt(n++);37===r?(e.push(parseInt(t.substr(n,2),16)),n+=2):e.push(r)}return new Uint8Array(e).buffer},e.convertArrayBufferToHex=s,e.convertHexToArrayBuffer=u,e.payloadId=function(){return(new Date).getTime()*Math.pow(10,3)+Math.floor(Math.random()*Math.pow(10,3))},e.uuid=function(){return function(t,e){for(e=t="";t++<36;e+=51*t&52?(15^t?8^Math.random()*(20^t?16:4):4).toString(16):"-");return e}()},e.getMeta=function(){if("undefined"==typeof window||"undefined"==typeof document||void 0===window.location)return null;function t(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];for(var n=document.getElementsByTagName("meta"),r=function(e){var r=n[e],o=["itemprop","property","name"].map(function(t){return r.getAttribute(t)}).filter(function(e){e&&t.includes(e)});if(o.length&&o){var i=r.getAttribute("content");if(i)return{value:i}}},o=0;o<n.length;o++){var i=r(o);if("object"==typeof i)return i.value}return""}var e=function(){var e=t("name","og:site_name","og:title","twitter:title");return e||(e=document.title),e}(),n=t("description","og:description","twitter:description","keywords"),r=window.location.href.startsWith("https");return{description:n,url:window.location.origin,icons:function(){for(var t=document.getElementsByTagName("link"),e=[],n=0;n<t.length;n++){var r=t[n],o=r.getAttribute("rel");if(o&&o.toLowerCase().indexOf("icon")>-1){var i=r.getAttribute("href");if(i)if(-1===i.toLowerCase().indexOf("https:")&&-1===i.toLowerCase().indexOf("http:")&&0!==i.indexOf("//")){var s=window.location.protocol+"//"+window.location.host;if(0===i.indexOf("/"))s+=i;else{var u=window.location.pathname.split("/");u.pop(),s+=u.join("/")+"/"+i}e.push(s)}else if(0===i.indexOf("//")){var a=window.location.protocol+i;e.push(a)}else e.push(i)}}return e}(),name:e,ssl:r}},e.parseWalletConnectUri=function(t){var e=t.indexOf(":"),n=-1!==t.indexOf("?")?t.indexOf("?"):void 0,o=t.substring(0,e),i=function(t){var e=t.split("@");return{handshakeTopic:e[0],version:parseInt(e[1],10)}}(t.substring(e+1,n)),s=function(t){for(var e={},n=("?"===t[0]?t.substr(1):t).split("&"),r=0;r<n.length;r++){var o=n[r].match(/\w+(?==)/i)||[],i=n[r].match(/=.+/i)||[];o[0]&&(e[decodeURIComponent(o[0])]=decodeURIComponent(i[0].substr(1)))}return{key:e.key||"",bridge:e.bridge||""}}(void 0!==n?t.substr(n):"");return r.__assign({protocol:o},i,s)},e.promisify=function(t,e){var n=this;return function(){for(var o=[],i=0;i<arguments.length;i++)o[i]=arguments[i];return r.__awaiter(n,void 0,void 0,function(){return r.__generator(this,function(n){return[2,new Promise(function(n,i){t.apply(e,r.__spread(o,[function(t,e){null==t&&i(t),n(e)}]))})]})})}},e.formatRpcError=function(t){var e=-32e3;if(t&&!t.code)switch(t.message){case"Parse error":e=-32700;break;case"Invalid request":e=-32600;break;case"Method not found":e=-32601;break;case"Invalid params":e=-32602;break;case"Internal error":e=-32603;break;default:e=-32e3}return{code:e,message:t.message}}}).call(this,n(1).Buffer)},function(t,e,n){"use strict";(function(t){ | ||
/*! | ||
@@ -24,3 +24,3 @@ * The buffer module from node.js, for the browser. | ||
*/ | ||
var r=n(3),o=n(4),i=n(5);function s(){return a.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function u(t,e){if(s()<e)throw new RangeError("Invalid typed array length");return a.TYPED_ARRAY_SUPPORT?(t=new Uint8Array(e)).__proto__=a.prototype:(null===t&&(t=new a(e)),t.length=e),t}function a(t,e,n){if(!(a.TYPED_ARRAY_SUPPORT||this instanceof a))return new a(t,e,n);if("number"==typeof t){if("string"==typeof e)throw new Error("If encoding is specified then the first argument must be a string");return h(this,t)}return c(this,t,e,n)}function c(t,e,n,r){if("number"==typeof e)throw new TypeError('"value" argument must not be a number');return"undefined"!=typeof ArrayBuffer&&e instanceof ArrayBuffer?function(t,e,n,r){if(e.byteLength,n<0||e.byteLength<n)throw new RangeError("'offset' is out of bounds");if(e.byteLength<n+(r||0))throw new RangeError("'length' is out of bounds");return e=void 0===n&&void 0===r?new Uint8Array(e):void 0===r?new Uint8Array(e,n):new Uint8Array(e,n,r),a.TYPED_ARRAY_SUPPORT?(t=e).__proto__=a.prototype:t=l(t,e),t}(t,e,n,r):"string"==typeof e?function(t,e,n){if("string"==typeof n&&""!==n||(n="utf8"),!a.isEncoding(n))throw new TypeError('"encoding" must be a valid string encoding');var r=0|d(e,n),o=(t=u(t,r)).write(e,n);return o!==r&&(t=t.slice(0,o)),t}(t,e,n):function(t,e){if(a.isBuffer(e)){var n=0|p(e.length);return 0===(t=u(t,n)).length?t:(e.copy(t,0,0,n),t)}if(e){if("undefined"!=typeof ArrayBuffer&&e.buffer instanceof ArrayBuffer||"length"in e)return"number"!=typeof e.length||(r=e.length)!=r?u(t,0):l(t,e);if("Buffer"===e.type&&i(e.data))return l(t,e.data)}var r;throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.")}(t,e)}function f(t){if("number"!=typeof t)throw new TypeError('"size" argument must be a number');if(t<0)throw new RangeError('"size" argument must not be negative')}function h(t,e){if(f(e),t=u(t,e<0?0:0|p(e)),!a.TYPED_ARRAY_SUPPORT)for(var n=0;n<e;++n)t[n]=0;return t}function l(t,e){var n=e.length<0?0:0|p(e.length);t=u(t,n);for(var r=0;r<n;r+=1)t[r]=255&e[r];return t}function p(t){if(t>=s())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+s().toString(16)+" bytes");return 0|t}function d(t,e){if(a.isBuffer(t))return t.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(t)||t instanceof ArrayBuffer))return t.byteLength;"string"!=typeof t&&(t=""+t);var n=t.length;if(0===n)return 0;for(var r=!1;;)switch(e){case"ascii":case"latin1":case"binary":return n;case"utf8":case"utf-8":case void 0:return D(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*n;case"hex":return n>>>1;case"base64":return N(t).length;default:if(r)return D(t).length;e=(""+e).toLowerCase(),r=!0}}function y(t,e,n){var r=t[e];t[e]=t[n],t[n]=r}function _(t,e,n,r,o){if(0===t.length)return-1;if("string"==typeof n?(r=n,n=0):n>2147483647?n=2147483647:n<-2147483648&&(n=-2147483648),n=+n,isNaN(n)&&(n=o?0:t.length-1),n<0&&(n=t.length+n),n>=t.length){if(o)return-1;n=t.length-1}else if(n<0){if(!o)return-1;n=0}if("string"==typeof e&&(e=a.from(e,r)),a.isBuffer(e))return 0===e.length?-1:g(t,e,n,r,o);if("number"==typeof e)return e&=255,a.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?o?Uint8Array.prototype.indexOf.call(t,e,n):Uint8Array.prototype.lastIndexOf.call(t,e,n):g(t,[e],n,r,o);throw new TypeError("val must be string, number or Buffer")}function g(t,e,n,r,o){var i,s=1,u=t.length,a=e.length;if(void 0!==r&&("ucs2"===(r=String(r).toLowerCase())||"ucs-2"===r||"utf16le"===r||"utf-16le"===r)){if(t.length<2||e.length<2)return-1;s=2,u/=2,a/=2,n/=2}function c(t,e){return 1===s?t[e]:t.readUInt16BE(e*s)}if(o){var f=-1;for(i=n;i<u;i++)if(c(t,i)===c(e,-1===f?0:i-f)){if(-1===f&&(f=i),i-f+1===a)return f*s}else-1!==f&&(i-=i-f),f=-1}else for(n+a>u&&(n=u-a),i=n;i>=0;i--){for(var h=!0,l=0;l<a;l++)if(c(t,i+l)!==c(e,l)){h=!1;break}if(h)return i}return-1}function v(t,e,n,r){n=Number(n)||0;var o=t.length-n;r?(r=Number(r))>o&&(r=o):r=o;var i=e.length;if(i%2!=0)throw new TypeError("Invalid hex string");r>i/2&&(r=i/2);for(var s=0;s<r;++s){var u=parseInt(e.substr(2*s,2),16);if(isNaN(u))return s;t[n+s]=u}return s}function w(t,e,n,r){return K(D(e,t.length-n),t,n,r)}function b(t,e,n,r){return K(function(t){for(var e=[],n=0;n<t.length;++n)e.push(255&t.charCodeAt(n));return e}(e),t,n,r)}function m(t,e,n,r){return b(t,e,n,r)}function S(t,e,n,r){return K(N(e),t,n,r)}function I(t,e,n,r){return K(function(t,e){for(var n,r,o,i=[],s=0;s<t.length&&!((e-=2)<0);++s)n=t.charCodeAt(s),r=n>>8,o=n%256,i.push(o),i.push(r);return i}(e,t.length-n),t,n,r)}function R(t,e,n){return 0===e&&n===t.length?r.fromByteArray(t):r.fromByteArray(t.slice(e,n))}function E(t,e,n){n=Math.min(t.length,n);for(var r=[],o=e;o<n;){var i,s,u,a,c=t[o],f=null,h=c>239?4:c>223?3:c>191?2:1;if(o+h<=n)switch(h){case 1:c<128&&(f=c);break;case 2:128==(192&(i=t[o+1]))&&(a=(31&c)<<6|63&i)>127&&(f=a);break;case 3:i=t[o+1],s=t[o+2],128==(192&i)&&128==(192&s)&&(a=(15&c)<<12|(63&i)<<6|63&s)>2047&&(a<55296||a>57343)&&(f=a);break;case 4:i=t[o+1],s=t[o+2],u=t[o+3],128==(192&i)&&128==(192&s)&&128==(192&u)&&(a=(15&c)<<18|(63&i)<<12|(63&s)<<6|63&u)>65535&&a<1114112&&(f=a)}null===f?(f=65533,h=1):f>65535&&(f-=65536,r.push(f>>>10&1023|55296),f=56320|1023&f),r.push(f),o+=h}return function(t){var e=t.length;if(e<=P)return String.fromCharCode.apply(String,t);for(var n="",r=0;r<e;)n+=String.fromCharCode.apply(String,t.slice(r,r+=P));return n}(r)}e.Buffer=a,e.SlowBuffer=function(t){return+t!=t&&(t=0),a.alloc(+t)},e.INSPECT_MAX_BYTES=50,a.TYPED_ARRAY_SUPPORT=void 0!==t.TYPED_ARRAY_SUPPORT?t.TYPED_ARRAY_SUPPORT:function(){try{var t=new Uint8Array(1);return t.__proto__={__proto__:Uint8Array.prototype,foo:function(){return 42}},42===t.foo()&&"function"==typeof t.subarray&&0===t.subarray(1,1).byteLength}catch(t){return!1}}(),e.kMaxLength=s(),a.poolSize=8192,a._augment=function(t){return t.__proto__=a.prototype,t},a.from=function(t,e,n){return c(null,t,e,n)},a.TYPED_ARRAY_SUPPORT&&(a.prototype.__proto__=Uint8Array.prototype,a.__proto__=Uint8Array,"undefined"!=typeof Symbol&&Symbol.species&&a[Symbol.species]===a&&Object.defineProperty(a,Symbol.species,{value:null,configurable:!0})),a.alloc=function(t,e,n){return function(t,e,n,r){return f(e),e<=0?u(t,e):void 0!==n?"string"==typeof r?u(t,e).fill(n,r):u(t,e).fill(n):u(t,e)}(null,t,e,n)},a.allocUnsafe=function(t){return h(null,t)},a.allocUnsafeSlow=function(t){return h(null,t)},a.isBuffer=function(t){return!(null==t||!t._isBuffer)},a.compare=function(t,e){if(!a.isBuffer(t)||!a.isBuffer(e))throw new TypeError("Arguments must be Buffers");if(t===e)return 0;for(var n=t.length,r=e.length,o=0,i=Math.min(n,r);o<i;++o)if(t[o]!==e[o]){n=t[o],r=e[o];break}return n<r?-1:r<n?1:0},a.isEncoding=function(t){switch(String(t).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},a.concat=function(t,e){if(!i(t))throw new TypeError('"list" argument must be an Array of Buffers');if(0===t.length)return a.alloc(0);var n;if(void 0===e)for(e=0,n=0;n<t.length;++n)e+=t[n].length;var r=a.allocUnsafe(e),o=0;for(n=0;n<t.length;++n){var s=t[n];if(!a.isBuffer(s))throw new TypeError('"list" argument must be an Array of Buffers');s.copy(r,o),o+=s.length}return r},a.byteLength=d,a.prototype._isBuffer=!0,a.prototype.swap16=function(){var t=this.length;if(t%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var e=0;e<t;e+=2)y(this,e,e+1);return this},a.prototype.swap32=function(){var t=this.length;if(t%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var e=0;e<t;e+=4)y(this,e,e+3),y(this,e+1,e+2);return this},a.prototype.swap64=function(){var t=this.length;if(t%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var e=0;e<t;e+=8)y(this,e,e+7),y(this,e+1,e+6),y(this,e+2,e+5),y(this,e+3,e+4);return this},a.prototype.toString=function(){var t=0|this.length;return 0===t?"":0===arguments.length?E(this,0,t):function(t,e,n){var r=!1;if((void 0===e||e<0)&&(e=0),e>this.length)return"";if((void 0===n||n>this.length)&&(n=this.length),n<=0)return"";if((n>>>=0)<=(e>>>=0))return"";for(t||(t="utf8");;)switch(t){case"hex":return A(this,e,n);case"utf8":case"utf-8":return E(this,e,n);case"ascii":return T(this,e,n);case"latin1":case"binary":return O(this,e,n);case"base64":return R(this,e,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return x(this,e,n);default:if(r)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),r=!0}}.apply(this,arguments)},a.prototype.equals=function(t){if(!a.isBuffer(t))throw new TypeError("Argument must be a Buffer");return this===t||0===a.compare(this,t)},a.prototype.inspect=function(){var t="",n=e.INSPECT_MAX_BYTES;return this.length>0&&(t=this.toString("hex",0,n).match(/.{2}/g).join(" "),this.length>n&&(t+=" ... ")),"<Buffer "+t+">"},a.prototype.compare=function(t,e,n,r,o){if(!a.isBuffer(t))throw new TypeError("Argument must be a Buffer");if(void 0===e&&(e=0),void 0===n&&(n=t?t.length:0),void 0===r&&(r=0),void 0===o&&(o=this.length),e<0||n>t.length||r<0||o>this.length)throw new RangeError("out of range index");if(r>=o&&e>=n)return 0;if(r>=o)return-1;if(e>=n)return 1;if(this===t)return 0;for(var i=(o>>>=0)-(r>>>=0),s=(n>>>=0)-(e>>>=0),u=Math.min(i,s),c=this.slice(r,o),f=t.slice(e,n),h=0;h<u;++h)if(c[h]!==f[h]){i=c[h],s=f[h];break}return i<s?-1:s<i?1:0},a.prototype.includes=function(t,e,n){return-1!==this.indexOf(t,e,n)},a.prototype.indexOf=function(t,e,n){return _(this,t,e,n,!0)},a.prototype.lastIndexOf=function(t,e,n){return _(this,t,e,n,!1)},a.prototype.write=function(t,e,n,r){if(void 0===e)r="utf8",n=this.length,e=0;else if(void 0===n&&"string"==typeof e)r=e,n=this.length,e=0;else{if(!isFinite(e))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");e|=0,isFinite(n)?(n|=0,void 0===r&&(r="utf8")):(r=n,n=void 0)}var o=this.length-e;if((void 0===n||n>o)&&(n=o),t.length>0&&(n<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");r||(r="utf8");for(var i=!1;;)switch(r){case"hex":return v(this,t,e,n);case"utf8":case"utf-8":return w(this,t,e,n);case"ascii":return b(this,t,e,n);case"latin1":case"binary":return m(this,t,e,n);case"base64":return S(this,t,e,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return I(this,t,e,n);default:if(i)throw new TypeError("Unknown encoding: "+r);r=(""+r).toLowerCase(),i=!0}},a.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var P=4096;function T(t,e,n){var r="";n=Math.min(t.length,n);for(var o=e;o<n;++o)r+=String.fromCharCode(127&t[o]);return r}function O(t,e,n){var r="";n=Math.min(t.length,n);for(var o=e;o<n;++o)r+=String.fromCharCode(t[o]);return r}function A(t,e,n){var r=t.length;(!e||e<0)&&(e=0),(!n||n<0||n>r)&&(n=r);for(var o="",i=e;i<n;++i)o+=q(t[i]);return o}function x(t,e,n){for(var r=t.slice(e,n),o="",i=0;i<r.length;i+=2)o+=String.fromCharCode(r[i]+256*r[i+1]);return o}function k(t,e,n){if(t%1!=0||t<0)throw new RangeError("offset is not uint");if(t+e>n)throw new RangeError("Trying to access beyond buffer length")}function j(t,e,n,r,o,i){if(!a.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>o||e<i)throw new RangeError('"value" argument is out of bounds');if(n+r>t.length)throw new RangeError("Index out of range")}function B(t,e,n,r){e<0&&(e=65535+e+1);for(var o=0,i=Math.min(t.length-n,2);o<i;++o)t[n+o]=(e&255<<8*(r?o:1-o))>>>8*(r?o:1-o)}function M(t,e,n,r){e<0&&(e=4294967295+e+1);for(var o=0,i=Math.min(t.length-n,4);o<i;++o)t[n+o]=e>>>8*(r?o:3-o)&255}function U(t,e,n,r,o,i){if(n+r>t.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("Index out of range")}function C(t,e,n,r,i){return i||U(t,0,n,4),o.write(t,e,n,r,23,4),n+4}function Y(t,e,n,r,i){return i||U(t,0,n,8),o.write(t,e,n,r,52,8),n+8}a.prototype.slice=function(t,e){var n,r=this.length;if((t=~~t)<0?(t+=r)<0&&(t=0):t>r&&(t=r),(e=void 0===e?r:~~e)<0?(e+=r)<0&&(e=0):e>r&&(e=r),e<t&&(e=t),a.TYPED_ARRAY_SUPPORT)(n=this.subarray(t,e)).__proto__=a.prototype;else{var o=e-t;n=new a(o,void 0);for(var i=0;i<o;++i)n[i]=this[i+t]}return n},a.prototype.readUIntLE=function(t,e,n){t|=0,e|=0,n||k(t,e,this.length);for(var r=this[t],o=1,i=0;++i<e&&(o*=256);)r+=this[t+i]*o;return r},a.prototype.readUIntBE=function(t,e,n){t|=0,e|=0,n||k(t,e,this.length);for(var r=this[t+--e],o=1;e>0&&(o*=256);)r+=this[t+--e]*o;return r},a.prototype.readUInt8=function(t,e){return e||k(t,1,this.length),this[t]},a.prototype.readUInt16LE=function(t,e){return e||k(t,2,this.length),this[t]|this[t+1]<<8},a.prototype.readUInt16BE=function(t,e){return e||k(t,2,this.length),this[t]<<8|this[t+1]},a.prototype.readUInt32LE=function(t,e){return e||k(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},a.prototype.readUInt32BE=function(t,e){return e||k(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},a.prototype.readIntLE=function(t,e,n){t|=0,e|=0,n||k(t,e,this.length);for(var r=this[t],o=1,i=0;++i<e&&(o*=256);)r+=this[t+i]*o;return r>=(o*=128)&&(r-=Math.pow(2,8*e)),r},a.prototype.readIntBE=function(t,e,n){t|=0,e|=0,n||k(t,e,this.length);for(var r=e,o=1,i=this[t+--r];r>0&&(o*=256);)i+=this[t+--r]*o;return i>=(o*=128)&&(i-=Math.pow(2,8*e)),i},a.prototype.readInt8=function(t,e){return e||k(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},a.prototype.readInt16LE=function(t,e){e||k(t,2,this.length);var n=this[t]|this[t+1]<<8;return 32768&n?4294901760|n:n},a.prototype.readInt16BE=function(t,e){e||k(t,2,this.length);var n=this[t+1]|this[t]<<8;return 32768&n?4294901760|n:n},a.prototype.readInt32LE=function(t,e){return e||k(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},a.prototype.readInt32BE=function(t,e){return e||k(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},a.prototype.readFloatLE=function(t,e){return e||k(t,4,this.length),o.read(this,t,!0,23,4)},a.prototype.readFloatBE=function(t,e){return e||k(t,4,this.length),o.read(this,t,!1,23,4)},a.prototype.readDoubleLE=function(t,e){return e||k(t,8,this.length),o.read(this,t,!0,52,8)},a.prototype.readDoubleBE=function(t,e){return e||k(t,8,this.length),o.read(this,t,!1,52,8)},a.prototype.writeUIntLE=function(t,e,n,r){t=+t,e|=0,n|=0,r||j(this,t,e,n,Math.pow(2,8*n)-1,0);var o=1,i=0;for(this[e]=255&t;++i<n&&(o*=256);)this[e+i]=t/o&255;return e+n},a.prototype.writeUIntBE=function(t,e,n,r){t=+t,e|=0,n|=0,r||j(this,t,e,n,Math.pow(2,8*n)-1,0);var o=n-1,i=1;for(this[e+o]=255&t;--o>=0&&(i*=256);)this[e+o]=t/i&255;return e+n},a.prototype.writeUInt8=function(t,e,n){return t=+t,e|=0,n||j(this,t,e,1,255,0),a.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),this[e]=255&t,e+1},a.prototype.writeUInt16LE=function(t,e,n){return t=+t,e|=0,n||j(this,t,e,2,65535,0),a.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):B(this,t,e,!0),e+2},a.prototype.writeUInt16BE=function(t,e,n){return t=+t,e|=0,n||j(this,t,e,2,65535,0),a.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):B(this,t,e,!1),e+2},a.prototype.writeUInt32LE=function(t,e,n){return t=+t,e|=0,n||j(this,t,e,4,4294967295,0),a.TYPED_ARRAY_SUPPORT?(this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t):M(this,t,e,!0),e+4},a.prototype.writeUInt32BE=function(t,e,n){return t=+t,e|=0,n||j(this,t,e,4,4294967295,0),a.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):M(this,t,e,!1),e+4},a.prototype.writeIntLE=function(t,e,n,r){if(t=+t,e|=0,!r){var o=Math.pow(2,8*n-1);j(this,t,e,n,o-1,-o)}var i=0,s=1,u=0;for(this[e]=255&t;++i<n&&(s*=256);)t<0&&0===u&&0!==this[e+i-1]&&(u=1),this[e+i]=(t/s>>0)-u&255;return e+n},a.prototype.writeIntBE=function(t,e,n,r){if(t=+t,e|=0,!r){var o=Math.pow(2,8*n-1);j(this,t,e,n,o-1,-o)}var i=n-1,s=1,u=0;for(this[e+i]=255&t;--i>=0&&(s*=256);)t<0&&0===u&&0!==this[e+i+1]&&(u=1),this[e+i]=(t/s>>0)-u&255;return e+n},a.prototype.writeInt8=function(t,e,n){return t=+t,e|=0,n||j(this,t,e,1,127,-128),a.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),t<0&&(t=255+t+1),this[e]=255&t,e+1},a.prototype.writeInt16LE=function(t,e,n){return t=+t,e|=0,n||j(this,t,e,2,32767,-32768),a.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):B(this,t,e,!0),e+2},a.prototype.writeInt16BE=function(t,e,n){return t=+t,e|=0,n||j(this,t,e,2,32767,-32768),a.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):B(this,t,e,!1),e+2},a.prototype.writeInt32LE=function(t,e,n){return t=+t,e|=0,n||j(this,t,e,4,2147483647,-2147483648),a.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24):M(this,t,e,!0),e+4},a.prototype.writeInt32BE=function(t,e,n){return t=+t,e|=0,n||j(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),a.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):M(this,t,e,!1),e+4},a.prototype.writeFloatLE=function(t,e,n){return C(this,t,e,!0,n)},a.prototype.writeFloatBE=function(t,e,n){return C(this,t,e,!1,n)},a.prototype.writeDoubleLE=function(t,e,n){return Y(this,t,e,!0,n)},a.prototype.writeDoubleBE=function(t,e,n){return Y(this,t,e,!1,n)},a.prototype.copy=function(t,e,n,r){if(n||(n=0),r||0===r||(r=this.length),e>=t.length&&(e=t.length),e||(e=0),r>0&&r<n&&(r=n),r===n)return 0;if(0===t.length||0===this.length)return 0;if(e<0)throw new RangeError("targetStart out of bounds");if(n<0||n>=this.length)throw new RangeError("sourceStart out of bounds");if(r<0)throw new RangeError("sourceEnd out of bounds");r>this.length&&(r=this.length),t.length-e<r-n&&(r=t.length-e+n);var o,i=r-n;if(this===t&&n<e&&e<r)for(o=i-1;o>=0;--o)t[o+e]=this[o+n];else if(i<1e3||!a.TYPED_ARRAY_SUPPORT)for(o=0;o<i;++o)t[o+e]=this[o+n];else Uint8Array.prototype.set.call(t,this.subarray(n,n+i),e);return i},a.prototype.fill=function(t,e,n,r){if("string"==typeof t){if("string"==typeof e?(r=e,e=0,n=this.length):"string"==typeof n&&(r=n,n=this.length),1===t.length){var o=t.charCodeAt(0);o<256&&(t=o)}if(void 0!==r&&"string"!=typeof r)throw new TypeError("encoding must be a string");if("string"==typeof r&&!a.isEncoding(r))throw new TypeError("Unknown encoding: "+r)}else"number"==typeof t&&(t&=255);if(e<0||this.length<e||this.length<n)throw new RangeError("Out of range index");if(n<=e)return this;var i;if(e>>>=0,n=void 0===n?this.length:n>>>0,t||(t=0),"number"==typeof t)for(i=e;i<n;++i)this[i]=t;else{var s=a.isBuffer(t)?t:D(new a(t,r).toString()),u=s.length;for(i=0;i<n-e;++i)this[i+e]=s[i%u]}return this};var L=/[^+\/0-9A-Za-z-_]/g;function q(t){return t<16?"0"+t.toString(16):t.toString(16)}function D(t,e){var n;e=e||1/0;for(var r=t.length,o=null,i=[],s=0;s<r;++s){if((n=t.charCodeAt(s))>55295&&n<57344){if(!o){if(n>56319){(e-=3)>-1&&i.push(239,191,189);continue}if(s+1===r){(e-=3)>-1&&i.push(239,191,189);continue}o=n;continue}if(n<56320){(e-=3)>-1&&i.push(239,191,189),o=n;continue}n=65536+(o-55296<<10|n-56320)}else o&&(e-=3)>-1&&i.push(239,191,189);if(o=null,n<128){if((e-=1)<0)break;i.push(n)}else if(n<2048){if((e-=2)<0)break;i.push(n>>6|192,63&n|128)}else if(n<65536){if((e-=3)<0)break;i.push(n>>12|224,n>>6&63|128,63&n|128)}else{if(!(n<1114112))throw new Error("Invalid code point");if((e-=4)<0)break;i.push(n>>18|240,n>>12&63|128,n>>6&63|128,63&n|128)}}return i}function N(t){return r.toByteArray(function(t){if((t=function(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}(t).replace(L,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function K(t,e,n,r){for(var o=0;o<r&&!(o+n>=e.length||o>=t.length);++o)e[o+n]=t[o];return o}}).call(this,n(2))},function(t,e){var n;n=function(){return this}();try{n=n||new Function("return this")()}catch(t){"object"==typeof window&&(n=window)}t.exports=n},function(t,e,n){"use strict";e.byteLength=function(t){var e=c(t),n=e[0],r=e[1];return 3*(n+r)/4-r},e.toByteArray=function(t){for(var e,n=c(t),r=n[0],s=n[1],u=new i(NaN),a=0,f=s>0?r-4:r,h=0;h<f;h+=4)e=o[t.charCodeAt(h)]<<18|o[t.charCodeAt(h+1)]<<12|o[t.charCodeAt(h+2)]<<6|o[t.charCodeAt(h+3)],u[a++]=e>>16&255,u[a++]=e>>8&255,u[a++]=255&e;return 2===s&&(e=o[t.charCodeAt(h)]<<2|o[t.charCodeAt(h+1)]>>4,u[a++]=255&e),1===s&&(e=o[t.charCodeAt(h)]<<10|o[t.charCodeAt(h+1)]<<4|o[t.charCodeAt(h+2)]>>2,u[a++]=e>>8&255,u[a++]=255&e),u},e.fromByteArray=function(t){for(var e,n=t.length,o=n%3,i=[],s=0,u=n-o;s<u;s+=16383)i.push(f(t,s,s+16383>u?u:s+16383));return 1===o?(e=t[n-1],i.push(r[e>>2]+r[e<<4&63]+"==")):2===o&&(e=(t[n-2]<<8)+t[n-1],i.push(r[e>>10]+r[e>>4&63]+r[e<<2&63]+"=")),i.join("")};for(var r=[],o=[],i="undefined"!=typeof Uint8Array?Uint8Array:Array,s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",u=0,a=s.length;u<a;++u)r[u]=s[u],o[s.charCodeAt(u)]=u;function c(t){var e=t.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var n=t.indexOf("=");return-1===n&&(n=e),[n,n===e?0:4-n%4]}function f(t,e,n){for(var o,i,s=[],u=e;u<n;u+=3)o=(t[u]<<16&16711680)+(t[u+1]<<8&65280)+(255&t[u+2]),s.push(r[(i=o)>>18&63]+r[i>>12&63]+r[i>>6&63]+r[63&i]);return s.join("")}o["-".charCodeAt(0)]=62,o["_".charCodeAt(0)]=63},function(t,e){e.read=function(t,e,n,r,o){var i,s,u=8*o-r-1,a=(1<<u)-1,c=a>>1,f=-7,h=n?o-1:0,l=n?-1:1,p=t[e+h];for(h+=l,i=p&(1<<-f)-1,p>>=-f,f+=u;f>0;i=256*i+t[e+h],h+=l,f-=8);for(s=i&(1<<-f)-1,i>>=-f,f+=r;f>0;s=256*s+t[e+h],h+=l,f-=8);if(0===i)i=1-c;else{if(i===a)return s?NaN:1/0*(p?-1:1);s+=Math.pow(2,r),i-=c}return(p?-1:1)*s*Math.pow(2,i-r)},e.write=function(t,e,n,r,o,i){var s,u,a,c=8*i-o-1,f=(1<<c)-1,h=f>>1,l=23===o?Math.pow(2,-24)-Math.pow(2,-77):0,p=r?0:i-1,d=r?1:-1,y=e<0||0===e&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(u=isNaN(e)?1:0,s=f):(s=Math.floor(Math.log(e)/Math.LN2),e*(a=Math.pow(2,-s))<1&&(s--,a*=2),(e+=s+h>=1?l/a:l*Math.pow(2,1-h))*a>=2&&(s++,a/=2),s+h>=f?(u=0,s=f):s+h>=1?(u=(e*a-1)*Math.pow(2,o),s+=h):(u=e*Math.pow(2,h-1)*Math.pow(2,o),s=0));o>=8;t[n+p]=255&u,p+=d,u/=256,o-=8);for(s=s<<o|u,c+=o;c>0;t[n+p]=255&s,p+=d,s/=256,c-=8);t[n+p-d]|=128*y}},function(t,e){var n={}.toString;t.exports=Array.isArray||function(t){return"[object Array]"==n.call(t)}},function(t,e,n){"use strict";n.r(e),n.d(e,"__extends",function(){return o}),n.d(e,"__assign",function(){return i}),n.d(e,"__rest",function(){return s}),n.d(e,"__decorate",function(){return u}),n.d(e,"__param",function(){return a}),n.d(e,"__metadata",function(){return c}),n.d(e,"__awaiter",function(){return f}),n.d(e,"__generator",function(){return h}),n.d(e,"__exportStar",function(){return l}),n.d(e,"__values",function(){return p}),n.d(e,"__read",function(){return d}),n.d(e,"__spread",function(){return y}),n.d(e,"__await",function(){return _}),n.d(e,"__asyncGenerator",function(){return g}),n.d(e,"__asyncDelegator",function(){return v}),n.d(e,"__asyncValues",function(){return w}),n.d(e,"__makeTemplateObject",function(){return b}),n.d(e,"__importStar",function(){return m}),n.d(e,"__importDefault",function(){return S}); | ||
var r=n(3),o=n(4),i=n(5);function s(){return a.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function u(t,e){if(s()<e)throw new RangeError("Invalid typed array length");return a.TYPED_ARRAY_SUPPORT?(t=new Uint8Array(e)).__proto__=a.prototype:(null===t&&(t=new a(e)),t.length=e),t}function a(t,e,n){if(!(a.TYPED_ARRAY_SUPPORT||this instanceof a))return new a(t,e,n);if("number"==typeof t){if("string"==typeof e)throw new Error("If encoding is specified then the first argument must be a string");return h(this,t)}return c(this,t,e,n)}function c(t,e,n,r){if("number"==typeof e)throw new TypeError('"value" argument must not be a number');return"undefined"!=typeof ArrayBuffer&&e instanceof ArrayBuffer?function(t,e,n,r){if(e.byteLength,n<0||e.byteLength<n)throw new RangeError("'offset' is out of bounds");if(e.byteLength<n+(r||0))throw new RangeError("'length' is out of bounds");return e=void 0===n&&void 0===r?new Uint8Array(e):void 0===r?new Uint8Array(e,n):new Uint8Array(e,n,r),a.TYPED_ARRAY_SUPPORT?(t=e).__proto__=a.prototype:t=l(t,e),t}(t,e,n,r):"string"==typeof e?function(t,e,n){if("string"==typeof n&&""!==n||(n="utf8"),!a.isEncoding(n))throw new TypeError('"encoding" must be a valid string encoding');var r=0|d(e,n),o=(t=u(t,r)).write(e,n);return o!==r&&(t=t.slice(0,o)),t}(t,e,n):function(t,e){if(a.isBuffer(e)){var n=0|p(e.length);return 0===(t=u(t,n)).length?t:(e.copy(t,0,0,n),t)}if(e){if("undefined"!=typeof ArrayBuffer&&e.buffer instanceof ArrayBuffer||"length"in e)return"number"!=typeof e.length||(r=e.length)!=r?u(t,0):l(t,e);if("Buffer"===e.type&&i(e.data))return l(t,e.data)}var r;throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.")}(t,e)}function f(t){if("number"!=typeof t)throw new TypeError('"size" argument must be a number');if(t<0)throw new RangeError('"size" argument must not be negative')}function h(t,e){if(f(e),t=u(t,e<0?0:0|p(e)),!a.TYPED_ARRAY_SUPPORT)for(var n=0;n<e;++n)t[n]=0;return t}function l(t,e){var n=e.length<0?0:0|p(e.length);t=u(t,n);for(var r=0;r<n;r+=1)t[r]=255&e[r];return t}function p(t){if(t>=s())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+s().toString(16)+" bytes");return 0|t}function d(t,e){if(a.isBuffer(t))return t.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(t)||t instanceof ArrayBuffer))return t.byteLength;"string"!=typeof t&&(t=""+t);var n=t.length;if(0===n)return 0;for(var r=!1;;)switch(e){case"ascii":case"latin1":case"binary":return n;case"utf8":case"utf-8":case void 0:return D(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*n;case"hex":return n>>>1;case"base64":return N(t).length;default:if(r)return D(t).length;e=(""+e).toLowerCase(),r=!0}}function y(t,e,n){var r=t[e];t[e]=t[n],t[n]=r}function _(t,e,n,r,o){if(0===t.length)return-1;if("string"==typeof n?(r=n,n=0):n>2147483647?n=2147483647:n<-2147483648&&(n=-2147483648),n=+n,isNaN(n)&&(n=o?0:t.length-1),n<0&&(n=t.length+n),n>=t.length){if(o)return-1;n=t.length-1}else if(n<0){if(!o)return-1;n=0}if("string"==typeof e&&(e=a.from(e,r)),a.isBuffer(e))return 0===e.length?-1:g(t,e,n,r,o);if("number"==typeof e)return e&=255,a.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?o?Uint8Array.prototype.indexOf.call(t,e,n):Uint8Array.prototype.lastIndexOf.call(t,e,n):g(t,[e],n,r,o);throw new TypeError("val must be string, number or Buffer")}function g(t,e,n,r,o){var i,s=1,u=t.length,a=e.length;if(void 0!==r&&("ucs2"===(r=String(r).toLowerCase())||"ucs-2"===r||"utf16le"===r||"utf-16le"===r)){if(t.length<2||e.length<2)return-1;s=2,u/=2,a/=2,n/=2}function c(t,e){return 1===s?t[e]:t.readUInt16BE(e*s)}if(o){var f=-1;for(i=n;i<u;i++)if(c(t,i)===c(e,-1===f?0:i-f)){if(-1===f&&(f=i),i-f+1===a)return f*s}else-1!==f&&(i-=i-f),f=-1}else for(n+a>u&&(n=u-a),i=n;i>=0;i--){for(var h=!0,l=0;l<a;l++)if(c(t,i+l)!==c(e,l)){h=!1;break}if(h)return i}return-1}function v(t,e,n,r){n=Number(n)||0;var o=t.length-n;r?(r=Number(r))>o&&(r=o):r=o;var i=e.length;if(i%2!=0)throw new TypeError("Invalid hex string");r>i/2&&(r=i/2);for(var s=0;s<r;++s){var u=parseInt(e.substr(2*s,2),16);if(isNaN(u))return s;t[n+s]=u}return s}function w(t,e,n,r){return K(D(e,t.length-n),t,n,r)}function b(t,e,n,r){return K(function(t){for(var e=[],n=0;n<t.length;++n)e.push(255&t.charCodeAt(n));return e}(e),t,n,r)}function m(t,e,n,r){return b(t,e,n,r)}function S(t,e,n,r){return K(N(e),t,n,r)}function R(t,e,n,r){return K(function(t,e){for(var n,r,o,i=[],s=0;s<t.length&&!((e-=2)<0);++s)n=t.charCodeAt(s),r=n>>8,o=n%256,i.push(o),i.push(r);return i}(e,t.length-n),t,n,r)}function I(t,e,n){return 0===e&&n===t.length?r.fromByteArray(t):r.fromByteArray(t.slice(e,n))}function E(t,e,n){n=Math.min(t.length,n);for(var r=[],o=e;o<n;){var i,s,u,a,c=t[o],f=null,h=c>239?4:c>223?3:c>191?2:1;if(o+h<=n)switch(h){case 1:c<128&&(f=c);break;case 2:128==(192&(i=t[o+1]))&&(a=(31&c)<<6|63&i)>127&&(f=a);break;case 3:i=t[o+1],s=t[o+2],128==(192&i)&&128==(192&s)&&(a=(15&c)<<12|(63&i)<<6|63&s)>2047&&(a<55296||a>57343)&&(f=a);break;case 4:i=t[o+1],s=t[o+2],u=t[o+3],128==(192&i)&&128==(192&s)&&128==(192&u)&&(a=(15&c)<<18|(63&i)<<12|(63&s)<<6|63&u)>65535&&a<1114112&&(f=a)}null===f?(f=65533,h=1):f>65535&&(f-=65536,r.push(f>>>10&1023|55296),f=56320|1023&f),r.push(f),o+=h}return function(t){var e=t.length;if(e<=P)return String.fromCharCode.apply(String,t);for(var n="",r=0;r<e;)n+=String.fromCharCode.apply(String,t.slice(r,r+=P));return n}(r)}e.Buffer=a,e.SlowBuffer=function(t){return+t!=t&&(t=0),a.alloc(+t)},e.INSPECT_MAX_BYTES=50,a.TYPED_ARRAY_SUPPORT=void 0!==t.TYPED_ARRAY_SUPPORT?t.TYPED_ARRAY_SUPPORT:function(){try{var t=new Uint8Array(1);return t.__proto__={__proto__:Uint8Array.prototype,foo:function(){return 42}},42===t.foo()&&"function"==typeof t.subarray&&0===t.subarray(1,1).byteLength}catch(t){return!1}}(),e.kMaxLength=s(),a.poolSize=8192,a._augment=function(t){return t.__proto__=a.prototype,t},a.from=function(t,e,n){return c(null,t,e,n)},a.TYPED_ARRAY_SUPPORT&&(a.prototype.__proto__=Uint8Array.prototype,a.__proto__=Uint8Array,"undefined"!=typeof Symbol&&Symbol.species&&a[Symbol.species]===a&&Object.defineProperty(a,Symbol.species,{value:null,configurable:!0})),a.alloc=function(t,e,n){return function(t,e,n,r){return f(e),e<=0?u(t,e):void 0!==n?"string"==typeof r?u(t,e).fill(n,r):u(t,e).fill(n):u(t,e)}(null,t,e,n)},a.allocUnsafe=function(t){return h(null,t)},a.allocUnsafeSlow=function(t){return h(null,t)},a.isBuffer=function(t){return!(null==t||!t._isBuffer)},a.compare=function(t,e){if(!a.isBuffer(t)||!a.isBuffer(e))throw new TypeError("Arguments must be Buffers");if(t===e)return 0;for(var n=t.length,r=e.length,o=0,i=Math.min(n,r);o<i;++o)if(t[o]!==e[o]){n=t[o],r=e[o];break}return n<r?-1:r<n?1:0},a.isEncoding=function(t){switch(String(t).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},a.concat=function(t,e){if(!i(t))throw new TypeError('"list" argument must be an Array of Buffers');if(0===t.length)return a.alloc(0);var n;if(void 0===e)for(e=0,n=0;n<t.length;++n)e+=t[n].length;var r=a.allocUnsafe(e),o=0;for(n=0;n<t.length;++n){var s=t[n];if(!a.isBuffer(s))throw new TypeError('"list" argument must be an Array of Buffers');s.copy(r,o),o+=s.length}return r},a.byteLength=d,a.prototype._isBuffer=!0,a.prototype.swap16=function(){var t=this.length;if(t%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var e=0;e<t;e+=2)y(this,e,e+1);return this},a.prototype.swap32=function(){var t=this.length;if(t%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var e=0;e<t;e+=4)y(this,e,e+3),y(this,e+1,e+2);return this},a.prototype.swap64=function(){var t=this.length;if(t%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var e=0;e<t;e+=8)y(this,e,e+7),y(this,e+1,e+6),y(this,e+2,e+5),y(this,e+3,e+4);return this},a.prototype.toString=function(){var t=0|this.length;return 0===t?"":0===arguments.length?E(this,0,t):function(t,e,n){var r=!1;if((void 0===e||e<0)&&(e=0),e>this.length)return"";if((void 0===n||n>this.length)&&(n=this.length),n<=0)return"";if((n>>>=0)<=(e>>>=0))return"";for(t||(t="utf8");;)switch(t){case"hex":return A(this,e,n);case"utf8":case"utf-8":return E(this,e,n);case"ascii":return T(this,e,n);case"latin1":case"binary":return O(this,e,n);case"base64":return I(this,e,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return k(this,e,n);default:if(r)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),r=!0}}.apply(this,arguments)},a.prototype.equals=function(t){if(!a.isBuffer(t))throw new TypeError("Argument must be a Buffer");return this===t||0===a.compare(this,t)},a.prototype.inspect=function(){var t="",n=e.INSPECT_MAX_BYTES;return this.length>0&&(t=this.toString("hex",0,n).match(/.{2}/g).join(" "),this.length>n&&(t+=" ... ")),"<Buffer "+t+">"},a.prototype.compare=function(t,e,n,r,o){if(!a.isBuffer(t))throw new TypeError("Argument must be a Buffer");if(void 0===e&&(e=0),void 0===n&&(n=t?t.length:0),void 0===r&&(r=0),void 0===o&&(o=this.length),e<0||n>t.length||r<0||o>this.length)throw new RangeError("out of range index");if(r>=o&&e>=n)return 0;if(r>=o)return-1;if(e>=n)return 1;if(this===t)return 0;for(var i=(o>>>=0)-(r>>>=0),s=(n>>>=0)-(e>>>=0),u=Math.min(i,s),c=this.slice(r,o),f=t.slice(e,n),h=0;h<u;++h)if(c[h]!==f[h]){i=c[h],s=f[h];break}return i<s?-1:s<i?1:0},a.prototype.includes=function(t,e,n){return-1!==this.indexOf(t,e,n)},a.prototype.indexOf=function(t,e,n){return _(this,t,e,n,!0)},a.prototype.lastIndexOf=function(t,e,n){return _(this,t,e,n,!1)},a.prototype.write=function(t,e,n,r){if(void 0===e)r="utf8",n=this.length,e=0;else if(void 0===n&&"string"==typeof e)r=e,n=this.length,e=0;else{if(!isFinite(e))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");e|=0,isFinite(n)?(n|=0,void 0===r&&(r="utf8")):(r=n,n=void 0)}var o=this.length-e;if((void 0===n||n>o)&&(n=o),t.length>0&&(n<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");r||(r="utf8");for(var i=!1;;)switch(r){case"hex":return v(this,t,e,n);case"utf8":case"utf-8":return w(this,t,e,n);case"ascii":return b(this,t,e,n);case"latin1":case"binary":return m(this,t,e,n);case"base64":return S(this,t,e,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return R(this,t,e,n);default:if(i)throw new TypeError("Unknown encoding: "+r);r=(""+r).toLowerCase(),i=!0}},a.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var P=4096;function T(t,e,n){var r="";n=Math.min(t.length,n);for(var o=e;o<n;++o)r+=String.fromCharCode(127&t[o]);return r}function O(t,e,n){var r="";n=Math.min(t.length,n);for(var o=e;o<n;++o)r+=String.fromCharCode(t[o]);return r}function A(t,e,n){var r=t.length;(!e||e<0)&&(e=0),(!n||n<0||n>r)&&(n=r);for(var o="",i=e;i<n;++i)o+=L(t[i]);return o}function k(t,e,n){for(var r=t.slice(e,n),o="",i=0;i<r.length;i+=2)o+=String.fromCharCode(r[i]+256*r[i+1]);return o}function x(t,e,n){if(t%1!=0||t<0)throw new RangeError("offset is not uint");if(t+e>n)throw new RangeError("Trying to access beyond buffer length")}function j(t,e,n,r,o,i){if(!a.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>o||e<i)throw new RangeError('"value" argument is out of bounds');if(n+r>t.length)throw new RangeError("Index out of range")}function B(t,e,n,r){e<0&&(e=65535+e+1);for(var o=0,i=Math.min(t.length-n,2);o<i;++o)t[n+o]=(e&255<<8*(r?o:1-o))>>>8*(r?o:1-o)}function M(t,e,n,r){e<0&&(e=4294967295+e+1);for(var o=0,i=Math.min(t.length-n,4);o<i;++o)t[n+o]=e>>>8*(r?o:3-o)&255}function U(t,e,n,r,o,i){if(n+r>t.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("Index out of range")}function C(t,e,n,r,i){return i||U(t,0,n,4),o.write(t,e,n,r,23,4),n+4}function Y(t,e,n,r,i){return i||U(t,0,n,8),o.write(t,e,n,r,52,8),n+8}a.prototype.slice=function(t,e){var n,r=this.length;if((t=~~t)<0?(t+=r)<0&&(t=0):t>r&&(t=r),(e=void 0===e?r:~~e)<0?(e+=r)<0&&(e=0):e>r&&(e=r),e<t&&(e=t),a.TYPED_ARRAY_SUPPORT)(n=this.subarray(t,e)).__proto__=a.prototype;else{var o=e-t;n=new a(o,void 0);for(var i=0;i<o;++i)n[i]=this[i+t]}return n},a.prototype.readUIntLE=function(t,e,n){t|=0,e|=0,n||x(t,e,this.length);for(var r=this[t],o=1,i=0;++i<e&&(o*=256);)r+=this[t+i]*o;return r},a.prototype.readUIntBE=function(t,e,n){t|=0,e|=0,n||x(t,e,this.length);for(var r=this[t+--e],o=1;e>0&&(o*=256);)r+=this[t+--e]*o;return r},a.prototype.readUInt8=function(t,e){return e||x(t,1,this.length),this[t]},a.prototype.readUInt16LE=function(t,e){return e||x(t,2,this.length),this[t]|this[t+1]<<8},a.prototype.readUInt16BE=function(t,e){return e||x(t,2,this.length),this[t]<<8|this[t+1]},a.prototype.readUInt32LE=function(t,e){return e||x(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},a.prototype.readUInt32BE=function(t,e){return e||x(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},a.prototype.readIntLE=function(t,e,n){t|=0,e|=0,n||x(t,e,this.length);for(var r=this[t],o=1,i=0;++i<e&&(o*=256);)r+=this[t+i]*o;return r>=(o*=128)&&(r-=Math.pow(2,8*e)),r},a.prototype.readIntBE=function(t,e,n){t|=0,e|=0,n||x(t,e,this.length);for(var r=e,o=1,i=this[t+--r];r>0&&(o*=256);)i+=this[t+--r]*o;return i>=(o*=128)&&(i-=Math.pow(2,8*e)),i},a.prototype.readInt8=function(t,e){return e||x(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},a.prototype.readInt16LE=function(t,e){e||x(t,2,this.length);var n=this[t]|this[t+1]<<8;return 32768&n?4294901760|n:n},a.prototype.readInt16BE=function(t,e){e||x(t,2,this.length);var n=this[t+1]|this[t]<<8;return 32768&n?4294901760|n:n},a.prototype.readInt32LE=function(t,e){return e||x(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},a.prototype.readInt32BE=function(t,e){return e||x(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},a.prototype.readFloatLE=function(t,e){return e||x(t,4,this.length),o.read(this,t,!0,23,4)},a.prototype.readFloatBE=function(t,e){return e||x(t,4,this.length),o.read(this,t,!1,23,4)},a.prototype.readDoubleLE=function(t,e){return e||x(t,8,this.length),o.read(this,t,!0,52,8)},a.prototype.readDoubleBE=function(t,e){return e||x(t,8,this.length),o.read(this,t,!1,52,8)},a.prototype.writeUIntLE=function(t,e,n,r){t=+t,e|=0,n|=0,r||j(this,t,e,n,Math.pow(2,8*n)-1,0);var o=1,i=0;for(this[e]=255&t;++i<n&&(o*=256);)this[e+i]=t/o&255;return e+n},a.prototype.writeUIntBE=function(t,e,n,r){t=+t,e|=0,n|=0,r||j(this,t,e,n,Math.pow(2,8*n)-1,0);var o=n-1,i=1;for(this[e+o]=255&t;--o>=0&&(i*=256);)this[e+o]=t/i&255;return e+n},a.prototype.writeUInt8=function(t,e,n){return t=+t,e|=0,n||j(this,t,e,1,255,0),a.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),this[e]=255&t,e+1},a.prototype.writeUInt16LE=function(t,e,n){return t=+t,e|=0,n||j(this,t,e,2,65535,0),a.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):B(this,t,e,!0),e+2},a.prototype.writeUInt16BE=function(t,e,n){return t=+t,e|=0,n||j(this,t,e,2,65535,0),a.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):B(this,t,e,!1),e+2},a.prototype.writeUInt32LE=function(t,e,n){return t=+t,e|=0,n||j(this,t,e,4,4294967295,0),a.TYPED_ARRAY_SUPPORT?(this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t):M(this,t,e,!0),e+4},a.prototype.writeUInt32BE=function(t,e,n){return t=+t,e|=0,n||j(this,t,e,4,4294967295,0),a.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):M(this,t,e,!1),e+4},a.prototype.writeIntLE=function(t,e,n,r){if(t=+t,e|=0,!r){var o=Math.pow(2,8*n-1);j(this,t,e,n,o-1,-o)}var i=0,s=1,u=0;for(this[e]=255&t;++i<n&&(s*=256);)t<0&&0===u&&0!==this[e+i-1]&&(u=1),this[e+i]=(t/s>>0)-u&255;return e+n},a.prototype.writeIntBE=function(t,e,n,r){if(t=+t,e|=0,!r){var o=Math.pow(2,8*n-1);j(this,t,e,n,o-1,-o)}var i=n-1,s=1,u=0;for(this[e+i]=255&t;--i>=0&&(s*=256);)t<0&&0===u&&0!==this[e+i+1]&&(u=1),this[e+i]=(t/s>>0)-u&255;return e+n},a.prototype.writeInt8=function(t,e,n){return t=+t,e|=0,n||j(this,t,e,1,127,-128),a.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),t<0&&(t=255+t+1),this[e]=255&t,e+1},a.prototype.writeInt16LE=function(t,e,n){return t=+t,e|=0,n||j(this,t,e,2,32767,-32768),a.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):B(this,t,e,!0),e+2},a.prototype.writeInt16BE=function(t,e,n){return t=+t,e|=0,n||j(this,t,e,2,32767,-32768),a.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):B(this,t,e,!1),e+2},a.prototype.writeInt32LE=function(t,e,n){return t=+t,e|=0,n||j(this,t,e,4,2147483647,-2147483648),a.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24):M(this,t,e,!0),e+4},a.prototype.writeInt32BE=function(t,e,n){return t=+t,e|=0,n||j(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),a.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):M(this,t,e,!1),e+4},a.prototype.writeFloatLE=function(t,e,n){return C(this,t,e,!0,n)},a.prototype.writeFloatBE=function(t,e,n){return C(this,t,e,!1,n)},a.prototype.writeDoubleLE=function(t,e,n){return Y(this,t,e,!0,n)},a.prototype.writeDoubleBE=function(t,e,n){return Y(this,t,e,!1,n)},a.prototype.copy=function(t,e,n,r){if(n||(n=0),r||0===r||(r=this.length),e>=t.length&&(e=t.length),e||(e=0),r>0&&r<n&&(r=n),r===n)return 0;if(0===t.length||0===this.length)return 0;if(e<0)throw new RangeError("targetStart out of bounds");if(n<0||n>=this.length)throw new RangeError("sourceStart out of bounds");if(r<0)throw new RangeError("sourceEnd out of bounds");r>this.length&&(r=this.length),t.length-e<r-n&&(r=t.length-e+n);var o,i=r-n;if(this===t&&n<e&&e<r)for(o=i-1;o>=0;--o)t[o+e]=this[o+n];else if(i<1e3||!a.TYPED_ARRAY_SUPPORT)for(o=0;o<i;++o)t[o+e]=this[o+n];else Uint8Array.prototype.set.call(t,this.subarray(n,n+i),e);return i},a.prototype.fill=function(t,e,n,r){if("string"==typeof t){if("string"==typeof e?(r=e,e=0,n=this.length):"string"==typeof n&&(r=n,n=this.length),1===t.length){var o=t.charCodeAt(0);o<256&&(t=o)}if(void 0!==r&&"string"!=typeof r)throw new TypeError("encoding must be a string");if("string"==typeof r&&!a.isEncoding(r))throw new TypeError("Unknown encoding: "+r)}else"number"==typeof t&&(t&=255);if(e<0||this.length<e||this.length<n)throw new RangeError("Out of range index");if(n<=e)return this;var i;if(e>>>=0,n=void 0===n?this.length:n>>>0,t||(t=0),"number"==typeof t)for(i=e;i<n;++i)this[i]=t;else{var s=a.isBuffer(t)?t:D(new a(t,r).toString()),u=s.length;for(i=0;i<n-e;++i)this[i+e]=s[i%u]}return this};var q=/[^+\/0-9A-Za-z-_]/g;function L(t){return t<16?"0"+t.toString(16):t.toString(16)}function D(t,e){var n;e=e||1/0;for(var r=t.length,o=null,i=[],s=0;s<r;++s){if((n=t.charCodeAt(s))>55295&&n<57344){if(!o){if(n>56319){(e-=3)>-1&&i.push(239,191,189);continue}if(s+1===r){(e-=3)>-1&&i.push(239,191,189);continue}o=n;continue}if(n<56320){(e-=3)>-1&&i.push(239,191,189),o=n;continue}n=65536+(o-55296<<10|n-56320)}else o&&(e-=3)>-1&&i.push(239,191,189);if(o=null,n<128){if((e-=1)<0)break;i.push(n)}else if(n<2048){if((e-=2)<0)break;i.push(n>>6|192,63&n|128)}else if(n<65536){if((e-=3)<0)break;i.push(n>>12|224,n>>6&63|128,63&n|128)}else{if(!(n<1114112))throw new Error("Invalid code point");if((e-=4)<0)break;i.push(n>>18|240,n>>12&63|128,n>>6&63|128,63&n|128)}}return i}function N(t){return r.toByteArray(function(t){if((t=function(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}(t).replace(q,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function K(t,e,n,r){for(var o=0;o<r&&!(o+n>=e.length||o>=t.length);++o)e[o+n]=t[o];return o}}).call(this,n(2))},function(t,e){var n;n=function(){return this}();try{n=n||new Function("return this")()}catch(t){"object"==typeof window&&(n=window)}t.exports=n},function(t,e,n){"use strict";e.byteLength=function(t){var e=c(t),n=e[0],r=e[1];return 3*(n+r)/4-r},e.toByteArray=function(t){for(var e,n=c(t),r=n[0],s=n[1],u=new i(NaN),a=0,f=s>0?r-4:r,h=0;h<f;h+=4)e=o[t.charCodeAt(h)]<<18|o[t.charCodeAt(h+1)]<<12|o[t.charCodeAt(h+2)]<<6|o[t.charCodeAt(h+3)],u[a++]=e>>16&255,u[a++]=e>>8&255,u[a++]=255&e;return 2===s&&(e=o[t.charCodeAt(h)]<<2|o[t.charCodeAt(h+1)]>>4,u[a++]=255&e),1===s&&(e=o[t.charCodeAt(h)]<<10|o[t.charCodeAt(h+1)]<<4|o[t.charCodeAt(h+2)]>>2,u[a++]=e>>8&255,u[a++]=255&e),u},e.fromByteArray=function(t){for(var e,n=t.length,o=n%3,i=[],s=0,u=n-o;s<u;s+=16383)i.push(f(t,s,s+16383>u?u:s+16383));return 1===o?(e=t[n-1],i.push(r[e>>2]+r[e<<4&63]+"==")):2===o&&(e=(t[n-2]<<8)+t[n-1],i.push(r[e>>10]+r[e>>4&63]+r[e<<2&63]+"=")),i.join("")};for(var r=[],o=[],i="undefined"!=typeof Uint8Array?Uint8Array:Array,s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",u=0,a=s.length;u<a;++u)r[u]=s[u],o[s.charCodeAt(u)]=u;function c(t){var e=t.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var n=t.indexOf("=");return-1===n&&(n=e),[n,n===e?0:4-n%4]}function f(t,e,n){for(var o,i,s=[],u=e;u<n;u+=3)o=(t[u]<<16&16711680)+(t[u+1]<<8&65280)+(255&t[u+2]),s.push(r[(i=o)>>18&63]+r[i>>12&63]+r[i>>6&63]+r[63&i]);return s.join("")}o["-".charCodeAt(0)]=62,o["_".charCodeAt(0)]=63},function(t,e){e.read=function(t,e,n,r,o){var i,s,u=8*o-r-1,a=(1<<u)-1,c=a>>1,f=-7,h=n?o-1:0,l=n?-1:1,p=t[e+h];for(h+=l,i=p&(1<<-f)-1,p>>=-f,f+=u;f>0;i=256*i+t[e+h],h+=l,f-=8);for(s=i&(1<<-f)-1,i>>=-f,f+=r;f>0;s=256*s+t[e+h],h+=l,f-=8);if(0===i)i=1-c;else{if(i===a)return s?NaN:1/0*(p?-1:1);s+=Math.pow(2,r),i-=c}return(p?-1:1)*s*Math.pow(2,i-r)},e.write=function(t,e,n,r,o,i){var s,u,a,c=8*i-o-1,f=(1<<c)-1,h=f>>1,l=23===o?Math.pow(2,-24)-Math.pow(2,-77):0,p=r?0:i-1,d=r?1:-1,y=e<0||0===e&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(u=isNaN(e)?1:0,s=f):(s=Math.floor(Math.log(e)/Math.LN2),e*(a=Math.pow(2,-s))<1&&(s--,a*=2),(e+=s+h>=1?l/a:l*Math.pow(2,1-h))*a>=2&&(s++,a/=2),s+h>=f?(u=0,s=f):s+h>=1?(u=(e*a-1)*Math.pow(2,o),s+=h):(u=e*Math.pow(2,h-1)*Math.pow(2,o),s=0));o>=8;t[n+p]=255&u,p+=d,u/=256,o-=8);for(s=s<<o|u,c+=o;c>0;t[n+p]=255&s,p+=d,s/=256,c-=8);t[n+p-d]|=128*y}},function(t,e){var n={}.toString;t.exports=Array.isArray||function(t){return"[object Array]"==n.call(t)}},function(t,e,n){"use strict";n.r(e),n.d(e,"__extends",function(){return o}),n.d(e,"__assign",function(){return i}),n.d(e,"__rest",function(){return s}),n.d(e,"__decorate",function(){return u}),n.d(e,"__param",function(){return a}),n.d(e,"__metadata",function(){return c}),n.d(e,"__awaiter",function(){return f}),n.d(e,"__generator",function(){return h}),n.d(e,"__exportStar",function(){return l}),n.d(e,"__values",function(){return p}),n.d(e,"__read",function(){return d}),n.d(e,"__spread",function(){return y}),n.d(e,"__await",function(){return _}),n.d(e,"__asyncGenerator",function(){return g}),n.d(e,"__asyncDelegator",function(){return v}),n.d(e,"__asyncValues",function(){return w}),n.d(e,"__makeTemplateObject",function(){return b}),n.d(e,"__importStar",function(){return m}),n.d(e,"__importDefault",function(){return S}); | ||
/*! ***************************************************************************** | ||
@@ -27,0 +27,0 @@ Copyright (c) Microsoft Corporation. All rights reserved. |
{ | ||
"name": "@walletconnect/core", | ||
"version": "1.0.0-beta.3", | ||
"version": "1.0.0-beta.4", | ||
"description": "Core Library for WalletConnect", | ||
@@ -56,6 +56,6 @@ "scripts": { | ||
"dependencies": { | ||
"@walletconnect/types": "^1.0.0-beta.2", | ||
"@walletconnect/utils": "^1.0.0-beta.3" | ||
"@walletconnect/types": "^1.0.0-beta.4", | ||
"@walletconnect/utils": "^1.0.0-beta.4" | ||
}, | ||
"gitHead": "165f7993c2acc907c653c02847fb02721052c6e7" | ||
} |
272
src/index.ts
@@ -8,3 +8,4 @@ import { | ||
IInternalEvent, | ||
IJsonRpcResponse, | ||
IJsonRpcResponseSuccess, | ||
IJsonRpcResponseError, | ||
IPartialRpcResponse, | ||
@@ -27,2 +28,3 @@ IPartialRpcRequest, | ||
uuid, | ||
formatRpcError, | ||
parseWalletConnectUri | ||
@@ -37,6 +39,10 @@ } from '@walletconnect/utils' | ||
function isRpcResponse (object: any): object is IJsonRpcResponse { | ||
function isRpcResponseSuccess (object: any): object is IJsonRpcResponseSuccess { | ||
return 'result' in object | ||
} | ||
function isRpcResponseError (object: any): object is IJsonRpcResponseError { | ||
return 'error' in object | ||
} | ||
function isInternalEvent (object: any): object is IInternalEvent { | ||
@@ -86,2 +92,4 @@ return 'event' in object | ||
private _connected: boolean | ||
private _browser: boolean | ||
private _pingInterval: any | ||
@@ -93,2 +101,3 @@ // -- constructor ----------------------------------------------------- // | ||
opts: IWalletConnectOptions, | ||
browser: boolean, | ||
clientMeta?: IClientMeta | ||
@@ -117,2 +126,4 @@ ) { | ||
this._connected = false | ||
this._browser = browser | ||
this._pingInterval = null | ||
@@ -141,3 +152,5 @@ if (clientMeta) { | ||
this.session = session | ||
this._exchangeKey() | ||
if (this._browser) { | ||
this._exchangeKey() | ||
} | ||
} | ||
@@ -403,4 +416,3 @@ | ||
chainId: this.chainId, | ||
accounts: this.accounts, | ||
message: null | ||
accounts: this.accounts | ||
} | ||
@@ -436,16 +448,11 @@ | ||
const message = sessionError ? sessionError.message : null | ||
const message = | ||
sessionError && sessionError.message | ||
? sessionError.message | ||
: 'Session Rejected' | ||
const sessionParams: ISessionParams = { | ||
approved: false, | ||
chainId: null, | ||
accounts: null, | ||
message | ||
} | ||
const response = { | ||
const response = this._formatResponse({ | ||
id: this.handshakeId, | ||
jsonrpc: '2.0', | ||
result: sessionParams | ||
} | ||
error: { message } | ||
}) | ||
@@ -473,4 +480,3 @@ this._sendResponse(response) | ||
chainId: this.chainId, | ||
accounts: this.accounts, | ||
message: null | ||
accounts: this.accounts | ||
} | ||
@@ -498,13 +504,8 @@ | ||
public killSession (sessionError?: ISessionError) { | ||
if (!this._connected) { | ||
throw new Error('Session currently disconnected') | ||
} | ||
const message = sessionError ? sessionError.message : 'Session Disconnected' | ||
const message = sessionError ? sessionError.message : null | ||
const sessionParams: ISessionParams = { | ||
approved: false, | ||
chainId: null, | ||
accounts: null, | ||
message | ||
accounts: null | ||
} | ||
@@ -517,12 +518,5 @@ | ||
this._sendSessionRequest(request, 'Session kill rejected') | ||
this._sendSessionRequest(request, 'Failed to kill Session') | ||
this._connected = false | ||
this._triggerEvents({ | ||
event: 'disconnect', | ||
params: [{ message }] | ||
}) | ||
this._removeStorageSession() | ||
this._handleSessionDisconnect(message) | ||
} | ||
@@ -584,10 +578,33 @@ | ||
public async sendCustomRequest (request: IPartialRpcRequest) { | ||
if (!this._connected) { | ||
throw new Error('Session currently disconnected') | ||
} | ||
const formattedRequest = this._formatRequest(request) | ||
try { | ||
const result = await this._sendCallRequest(formattedRequest) | ||
return result | ||
} catch (error) { | ||
throw error | ||
} | ||
} | ||
public approveRequest (response: IPartialRpcResponse) { | ||
const formattedResponse: IJsonRpcResponse = this._formatResponse(response) | ||
this._sendResponse(formattedResponse) | ||
if (isRpcResponseSuccess(response)) { | ||
const formattedResponse = this._formatResponse(response) | ||
this._sendResponse(formattedResponse) | ||
} else { | ||
throw new Error('JSON-RPC success response must include "result" field') | ||
} | ||
} | ||
public rejectRequest (response: IPartialRpcResponse) { | ||
const formattedResponse: IJsonRpcResponse = this._formatResponse(response) | ||
this._sendResponse(formattedResponse) | ||
if (isRpcResponseError(response)) { | ||
const formattedResponse = this._formatResponse(response) | ||
this._sendResponse(formattedResponse) | ||
} else { | ||
throw new Error('JSON-RPC error response must include "error" field') | ||
} | ||
} | ||
@@ -620,3 +637,5 @@ | ||
private async _sendResponse (response: IJsonRpcResponse) { | ||
private async _sendResponse ( | ||
response: IJsonRpcResponseSuccess | IJsonRpcResponseError | ||
) { | ||
const encryptionPayload: IEncryptionPayload | null = await this._encrypt( | ||
@@ -665,63 +684,87 @@ response | ||
private _formatResponse (response: IPartialRpcResponse): IJsonRpcResponse { | ||
const formattedResponse: IJsonRpcResponse = { | ||
private _formatResponse ( | ||
response: IPartialRpcResponse | ||
): IJsonRpcResponseSuccess | IJsonRpcResponseError { | ||
if (isRpcResponseError(response)) { | ||
const error = formatRpcError(response.error) | ||
const formattedResponseError: IJsonRpcResponseError = { | ||
jsonrpc: '2.0', | ||
...response, | ||
error | ||
} | ||
return formattedResponseError | ||
} | ||
const formattedResponseSuccess: IJsonRpcResponseSuccess = { | ||
jsonrpc: '2.0', | ||
result: null, | ||
...response | ||
} | ||
return formattedResponse | ||
return formattedResponseSuccess | ||
} | ||
private _handleSessionDisconnect (errorMsg?: string) { | ||
const message = errorMsg || 'Session Disconnected' | ||
this._connected = false | ||
this._triggerEvents({ | ||
event: 'disconnect', | ||
params: [{ message }] | ||
}) | ||
console.error(message) // tslint:disable-line | ||
this._removeStorageSession() | ||
clearInterval(this._pingInterval) | ||
} | ||
private _handleSessionResponse ( | ||
sessionParams: ISessionParams, | ||
errorMsg: string | ||
errorMsg: string, | ||
sessionParams?: ISessionParams | ||
) { | ||
if (sessionParams.approved) { | ||
if (!this._connected) { | ||
this._connected = true | ||
if (sessionParams.chainId) { | ||
this.chainId = sessionParams.chainId | ||
if (sessionParams) { | ||
if (sessionParams.approved) { | ||
if (!this._connected) { | ||
this._connected = true | ||
if (sessionParams.chainId) { | ||
this.chainId = sessionParams.chainId | ||
} | ||
if (sessionParams.accounts) { | ||
this.accounts = sessionParams.accounts | ||
} | ||
this._triggerEvents({ | ||
event: 'connect', | ||
params: [ | ||
{ | ||
peerId: this.peerId, | ||
peerMeta: this.peerMeta, | ||
chainId: this.chainId, | ||
accounts: this.accounts | ||
} | ||
] | ||
}) | ||
} else { | ||
if (sessionParams.chainId) { | ||
this.chainId = sessionParams.chainId | ||
} | ||
if (sessionParams.accounts) { | ||
this.accounts = sessionParams.accounts | ||
} | ||
this._triggerEvents({ | ||
event: 'session_update', | ||
params: [ | ||
{ | ||
chainId: this.chainId, | ||
accounts: this.accounts | ||
} | ||
] | ||
}) | ||
} | ||
if (sessionParams.accounts) { | ||
this.accounts = sessionParams.accounts | ||
} | ||
this._triggerEvents({ | ||
event: 'connect', | ||
params: [ | ||
{ | ||
peerId: this.peerId, | ||
peerMeta: this.peerMeta, | ||
chainId: this.chainId, | ||
accounts: this.accounts | ||
} | ||
] | ||
}) | ||
this._setStorageSession() | ||
} else { | ||
if (sessionParams.chainId) { | ||
this.chainId = sessionParams.chainId | ||
} | ||
if (sessionParams.accounts) { | ||
this.accounts = sessionParams.accounts | ||
} | ||
this._triggerEvents({ | ||
event: 'session_update', | ||
params: [ | ||
{ | ||
chainId: this.chainId, | ||
accounts: this.accounts | ||
} | ||
] | ||
}) | ||
this._handleSessionDisconnect(errorMsg) | ||
} | ||
this._setStorageSession() | ||
} else { | ||
this._connected = false | ||
const message = sessionParams.message || errorMsg | ||
this._triggerEvents({ | ||
event: 'disconnect', | ||
params: [{ message }] | ||
}) | ||
console.error(message) // tslint:disable-line | ||
this._removeStorageSession() | ||
this._handleSessionDisconnect(errorMsg) | ||
} | ||
@@ -741,6 +784,6 @@ } | ||
if (error) { | ||
console.error(errorMsg) // tslint:disable-line | ||
this._handleSessionResponse(error.message) | ||
} | ||
this._handleSessionResponse(payload.result, errorMsg) | ||
this._handleSessionResponse(errorMsg, payload.result) | ||
}) | ||
@@ -774,2 +817,8 @@ } | ||
this._exchangeKey() | ||
let internalPayload = { | ||
...payload, | ||
method: 'session_request' | ||
} | ||
this._triggerEvents(internalPayload) | ||
}) | ||
@@ -779,5 +828,5 @@ | ||
if (error) { | ||
console.error(error) // tslint:disable-line | ||
this._handleSessionResponse(error.message) | ||
} | ||
this._handleSessionResponse(payload.params[0], 'Session disconnected') | ||
this._handleSessionResponse('Session disconnected', payload.params[0]) | ||
}) | ||
@@ -794,3 +843,7 @@ | ||
private _triggerEvents ( | ||
payload: IJsonRpcRequest | IJsonRpcResponse | IInternalEvent | ||
payload: | ||
| IJsonRpcRequest | ||
| IJsonRpcResponseSuccess | ||
| IJsonRpcResponseError | ||
| IInternalEvent | ||
): void { | ||
@@ -802,3 +855,3 @@ let eventEmitters: IEventEmitter[] = [] | ||
event = payload.method | ||
} else if (isRpcResponse(payload)) { | ||
} else if (isRpcResponseSuccess(payload) || isRpcResponseError(payload)) { | ||
event = `response:${payload.id}` | ||
@@ -823,5 +876,10 @@ } else if (isInternalEvent(payload)) { | ||
eventEmitters.forEach((eventEmitter: IEventEmitter) => | ||
eventEmitter.callback(null, payload) | ||
) | ||
eventEmitters.forEach((eventEmitter: IEventEmitter) => { | ||
if (isRpcResponseError(payload)) { | ||
const error = new Error(payload.error.message) | ||
eventEmitter.callback(error, null) | ||
} else { | ||
eventEmitter.callback(null, payload) | ||
} | ||
}) | ||
} | ||
@@ -898,2 +956,6 @@ | ||
this._dispatchQueue() | ||
this._pingInterval = setInterval(() => { | ||
socket.send('ping') | ||
}, 500) | ||
} | ||
@@ -936,3 +998,4 @@ } | ||
| IJsonRpcRequest | ||
| IJsonRpcResponse | ||
| IJsonRpcResponseSuccess | ||
| IJsonRpcResponseError | ||
| null = await this._decrypt(encryptionPayload) | ||
@@ -1007,3 +1070,3 @@ | ||
private async _encrypt ( | ||
data: IJsonRpcRequest | IJsonRpcResponse | ||
data: IJsonRpcRequest | IJsonRpcResponseSuccess | IJsonRpcResponseError | ||
): Promise<IEncryptionPayload | null> { | ||
@@ -1020,3 +1083,5 @@ const key: ArrayBuffer | null = this._key | ||
payload: IEncryptionPayload | ||
): Promise<IJsonRpcRequest | IJsonRpcResponse | null> { | ||
): Promise< | ||
IJsonRpcRequest | IJsonRpcResponseSuccess | IJsonRpcResponseError | null | ||
> { | ||
const key: ArrayBuffer | null = this._key | ||
@@ -1026,3 +1091,4 @@ if (this.cryptoLib && key) { | ||
| IJsonRpcRequest | ||
| IJsonRpcResponse | ||
| IJsonRpcResponseSuccess | ||
| IJsonRpcResponseError | ||
| null = await this.cryptoLib.decrypt(payload, key) | ||
@@ -1029,0 +1095,0 @@ return result |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
233706
1269