@walletconnect/ethereum-provider 2.0.0-beta.20.4 → 2.0.0-beta.20.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/umd/index.min.js +1 -1
- package/package.json +5 -5
package/dist/umd/index.min.js
CHANGED
|
@@ -22,4 +22,4 @@ PERFORMANCE OF THIS SOFTWARE.
|
|
|
22
22
|
***************************************************************************** */
|
|
23
23
|
var r=function(e,t){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)};function i(e,t){function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}var o=function(){return(o=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var i in t=arguments[n])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e}).apply(this,arguments)};function s(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(r=Object.getOwnPropertySymbols(e);i<r.length;i++)t.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(e,r[i])&&(n[r[i]]=e[r[i]])}return n}function a(e,t,n,r){var i,o=arguments.length,s=o<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,n,r);else for(var a=e.length-1;a>=0;a--)(i=e[a])&&(s=(o<3?i(s):o>3?i(t,n,s):i(t,n))||s);return o>3&&s&&Object.defineProperty(t,n,s),s}function c(e,t){return function(n,r){t(n,r,e)}}function u(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}function h(e,t,n,r){return new(n||(n=Promise))((function(i,o){function s(e){try{c(r.next(e))}catch(e){o(e)}}function a(e){try{c(r.throw(e))}catch(e){o(e)}}function c(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((r=r.apply(e,t||[])).next())}))}function l(e,t){var n,r,i,o,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(i=2&o[0]?r.return:o[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,o[1])).done)return i;switch(r=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,r=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(i=s.trys,(i=i.length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){s=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){s.label=o[1];break}if(6===o[0]&&s.label<i[1]){s.label=i[1],i=o;break}if(i&&s.label<i[2]){s.label=i[2],s.ops.push(o);break}i[2]&&s.ops.pop(),s.trys.pop();continue}o=t.call(e,s)}catch(e){o=[6,e],r=0}finally{n=i=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,a])}}}function d(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}function f(e,t){for(var n in e)"default"===n||t.hasOwnProperty(n)||(t[n]=e[n])}function p(e){var t="function"==typeof Symbol&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function g(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,i,o=n.call(e),s=[];try{for(;(void 0===t||t-- >0)&&!(r=o.next()).done;)s.push(r.value)}catch(e){i={error:e}}finally{try{r&&!r.done&&(n=o.return)&&n.call(o)}finally{if(i)throw i.error}}return s}function y(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(g(arguments[t]));return e}function v(){for(var e=0,t=0,n=arguments.length;t<n;t++)e+=arguments[t].length;var r=Array(e),i=0;for(t=0;t<n;t++)for(var o=arguments[t],s=0,a=o.length;s<a;s++,i++)r[i]=o[s];return r}function m(e){return this instanceof m?(this.v=e,this):new m(e)}function E(e,t,n){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var r,i=n.apply(e,t||[]),o=[];return r={},s("next"),s("throw"),s("return"),r[Symbol.asyncIterator]=function(){return this},r;function s(e){i[e]&&(r[e]=function(t){return new Promise((function(n,r){o.push([e,t,n,r])>1||a(e,t)}))})}function a(e,t){try{(n=i[e](t)).value instanceof m?Promise.resolve(n.value.v).then(c,u):h(o[0][2],n)}catch(e){h(o[0][3],e)}var n}function c(e){a("next",e)}function u(e){a("throw",e)}function h(e,t){e(t),o.shift(),o.length&&a(o[0][0],o[0][1])}}function b(e){var t,n;return t={},r("next"),r("throw",(function(e){throw e})),r("return"),t[Symbol.iterator]=function(){return this},t;function r(r,i){t[r]=e[r]?function(t){return(n=!n)?{value:m(e[r](t)),done:"return"===r}:i?i(t):t}:i}}function _(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t,n=e[Symbol.asyncIterator];return n?n.call(e):(e=p(e),t={},r("next"),r("throw"),r("return"),t[Symbol.asyncIterator]=function(){return this},t);function r(n){t[n]=e[n]&&function(t){return new Promise((function(r,i){(function(e,t,n,r){Promise.resolve(r).then((function(t){e({value:t,done:n})}),t)})(r,i,(t=e[n](t)).done,t.value)}))}}}function w(e,t){return Object.defineProperty?Object.defineProperty(e,"raw",{value:t}):e.raw=t,e}function R(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)Object.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t.default=e,t}function O(e){return e&&e.__esModule?e:{default:e}}function T(e,t){if(!t.has(e))throw new TypeError("attempted to get private field on non-instance");return t.get(e)}function S(e,t,n){if(!t.has(e))throw new TypeError("attempted to set private field on non-instance");return t.set(e,n),n}},function(e,t,n){"use strict";(function(e){function n(){return(null==e?void 0:e.crypto)||(null==e?void 0:e.msCrypto)||{}}function r(){const e=n();return e.subtle||e.webkitSubtle}Object.defineProperty(t,"__esModule",{value:!0}),t.isBrowserCryptoAvailable=t.getSubtleCrypto=t.getBrowerCrypto=void 0,t.getBrowerCrypto=n,t.getSubtleCrypto=r,t.isBrowserCryptoAvailable=function(){return!!n()&&!!r()}}).call(this,n(22))},function(e,t,n){"use strict";(function(e){function n(){return"undefined"==typeof document&&"undefined"!=typeof navigator&&"ReactNative"===navigator.product}function r(){return void 0!==e&&void 0!==e.versions&&void 0!==e.versions.node}Object.defineProperty(t,"__esModule",{value:!0}),t.isBrowser=t.isNode=t.isReactNative=void 0,t.isReactNative=n,t.isNode=r,t.isBrowser=function(){return!n()&&!r()}}).call(this,n(32))},function(e,t,n){"use strict";function r(e){try{return JSON.stringify(e)}catch(e){return'"[Circular]"'}}e.exports=function(e,t,n){var i=n&&n.stringify||r;if("object"==typeof e&&null!==e){var o=t.length+1;if(1===o)return e;var s=new Array(o);s[0]=i(e);for(var a=1;a<o;a++)s[a]=i(t[a]);return s.join(" ")}if("string"!=typeof e)return e;var c=t.length;if(0===c)return e;for(var u="",h=0,l=-1,d=e&&e.length||0,f=0;f<d;){if(37===e.charCodeAt(f)&&f+1<d){switch(l=l>-1?l:0,e.charCodeAt(f+1)){case 100:case 102:if(h>=c)break;if(null==t[h])break;l<f&&(u+=e.slice(l,f)),u+=Number(t[h]),l=f+2,f++;break;case 105:if(h>=c)break;if(null==t[h])break;l<f&&(u+=e.slice(l,f)),u+=Math.floor(Number(t[h])),l=f+2,f++;break;case 79:case 111:case 106:if(h>=c)break;if(void 0===t[h])break;l<f&&(u+=e.slice(l,f));var p=typeof t[h];if("string"===p){u+="'"+t[h]+"'",l=f+2,f++;break}if("function"===p){u+=t[h].name||"<anonymous>",l=f+2,f++;break}u+=i(t[h]),l=f+2,f++;break;case 115:if(h>=c)break;l<f&&(u+=e.slice(l,f)),u+=String(t[h]),l=f+2,f++;break;case 37:l<f&&(u+=e.slice(l,f)),u+="%",l=f+2,f++,h--}++h}++f}if(-1===l)return e;l<d&&(u+=e.slice(l));return u}},function(e,t,n){(function(t){!function(){"use strict";var n;function r(){}(n=r).prototype.getItem=function(e){return this.hasOwnProperty(e)?String(this[e]):null},n.prototype.setItem=function(e,t){this[e]=String(t)},n.prototype.removeItem=function(e){delete this[e]},n.prototype.clear=function(){var e=this;Object.keys(e).forEach((function(t){e[t]=void 0,delete e[t]}))},n.prototype.key=function(e){return e=e||0,Object.keys(this)[e]},n.prototype.__defineGetter__("length",(function(){return Object.keys(this).length})),t.localStorage?e.exports=localStorage:e.exports=new r}()}).call(this,n(22))},function(e,t,n){"use strict";function r(e){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}Object.defineProperty(t,"__esModule",{value:!0}),r(n(83)),r(n(85))},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(84);t.IKeyValueStorage=r.IKeyValueStorage},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});t.IKeyValueStorage=class{}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const r=n(41);function i(e){return t.REACT_NATIVE_REQUIRED_OPTION in e}function o(e){return t.NODE_JS_REQUIRED_OPTION in e}t.REACT_NATIVE_REQUIRED_OPTION="asyncStorage",t.isReactNativeOptions=i,t.getReactNativeOptions=function(e){if(void 0===e||!i(e))throw new Error(`Missing ${t.REACT_NATIVE_REQUIRED_OPTION} option required for React-Native`);return e},t.NODE_JS_REQUIRED_OPTION="database",t.isNodeJSOptions=o,t.getNodeJSOptions=function(e){if(void 0===e||!o(e))throw new Error(`Missing ${t.NODE_JS_REQUIRED_OPTION} option required for NodeJS`);return e},t.parseEntry=function(e){return[e[0],r.safeJsonParse(e[1])]}},function(e,t,n){"use strict";t.byteLength=function(e){var t=u(e),n=t[0],r=t[1];return 3*(n+r)/4-r},t.toByteArray=function(e){var t,n,r=u(e),s=r[0],a=r[1],c=new o(function(e,t,n){return 3*(t+n)/4-n}(0,s,a)),h=0,l=a>0?s-4:s;for(n=0;n<l;n+=4)t=i[e.charCodeAt(n)]<<18|i[e.charCodeAt(n+1)]<<12|i[e.charCodeAt(n+2)]<<6|i[e.charCodeAt(n+3)],c[h++]=t>>16&255,c[h++]=t>>8&255,c[h++]=255&t;2===a&&(t=i[e.charCodeAt(n)]<<2|i[e.charCodeAt(n+1)]>>4,c[h++]=255&t);1===a&&(t=i[e.charCodeAt(n)]<<10|i[e.charCodeAt(n+1)]<<4|i[e.charCodeAt(n+2)]>>2,c[h++]=t>>8&255,c[h++]=255&t);return c},t.fromByteArray=function(e){for(var t,n=e.length,i=n%3,o=[],s=0,a=n-i;s<a;s+=16383)o.push(h(e,s,s+16383>a?a:s+16383));1===i?(t=e[n-1],o.push(r[t>>2]+r[t<<4&63]+"==")):2===i&&(t=(e[n-2]<<8)+e[n-1],o.push(r[t>>10]+r[t>>4&63]+r[t<<2&63]+"="));return o.join("")};for(var r=[],i=[],o="undefined"!=typeof Uint8Array?Uint8Array:Array,s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",a=0,c=s.length;a<c;++a)r[a]=s[a],i[s.charCodeAt(a)]=a;function u(e){var t=e.length;if(t%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var n=e.indexOf("=");return-1===n&&(n=t),[n,n===t?0:4-n%4]}function h(e,t,n){for(var i,o,s=[],a=t;a<n;a+=3)i=(e[a]<<16&16711680)+(e[a+1]<<8&65280)+(255&e[a+2]),s.push(r[(o=i)>>18&63]+r[o>>12&63]+r[o>>6&63]+r[63&o]);return s.join("")}i["-".charCodeAt(0)]=62,i["_".charCodeAt(0)]=63},function(e,t){
|
|
24
24
|
/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
|
|
25
|
-
t.read=function(e,t,n,r,i){var o,s,a=8*i-r-1,c=(1<<a)-1,u=c>>1,h=-7,l=n?i-1:0,d=n?-1:1,f=e[t+l];for(l+=d,o=f&(1<<-h)-1,f>>=-h,h+=a;h>0;o=256*o+e[t+l],l+=d,h-=8);for(s=o&(1<<-h)-1,o>>=-h,h+=r;h>0;s=256*s+e[t+l],l+=d,h-=8);if(0===o)o=1-u;else{if(o===c)return s?NaN:1/0*(f?-1:1);s+=Math.pow(2,r),o-=u}return(f?-1:1)*s*Math.pow(2,o-r)},t.write=function(e,t,n,r,i,o){var s,a,c,u=8*o-i-1,h=(1<<u)-1,l=h>>1,d=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,f=r?0:o-1,p=r?1:-1,g=t<0||0===t&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(a=isNaN(t)?1:0,s=h):(s=Math.floor(Math.log(t)/Math.LN2),t*(c=Math.pow(2,-s))<1&&(s--,c*=2),(t+=s+l>=1?d/c:d*Math.pow(2,1-l))*c>=2&&(s++,c/=2),s+l>=h?(a=0,s=h):s+l>=1?(a=(t*c-1)*Math.pow(2,i),s+=l):(a=t*Math.pow(2,l-1)*Math.pow(2,i),s=0));i>=8;e[n+f]=255&a,f+=p,a/=256,i-=8);for(s=s<<i|a,u+=i;u>0;e[n+f]=255&s,f+=p,s/=256,u-=8);e[n+f-p]|=128*g}},function(e,t){var n={}.toString;e.exports=Array.isArray||function(e){return"[object Array]"==n.call(e)}},function(e,t,n){(function(t){var r=n(68).strict;e.exports=function(e){if(r(e)){var n=t.from(e.buffer);return e.byteLength!==e.buffer.byteLength&&(n=n.slice(e.byteOffset,e.byteOffset+e.byteLength)),n}return t.from(e)}}).call(this,n(67).Buffer)},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(91),i=n(95),o=n(27);function s(e,n){return void 0===n&&(n=t.defaultRandomSource),n.randomBytes(e)}t.defaultRandomSource=new r.SystemRandomSource,t.randomBytes=s,t.randomUint32=function(e){void 0===e&&(e=t.defaultRandomSource);var n=s(4,e),r=i.readUint32LE(n);return o.wipe(n),r};var a="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";function c(e,n,r){if(void 0===n&&(n=a),void 0===r&&(r=t.defaultRandomSource),n.length<2)throw new Error("randomString charset is too short");if(n.length>256)throw new Error("randomString charset is too long");for(var i="",c=n.length,u=256-256%c;e>0;){for(var h=s(Math.ceil(256*e/u),r),l=0;l<h.length&&e>0;l++){var d=h[l];d<u&&(i+=n.charAt(d%c),e--)}o.wipe(h)}return i}t.randomString=c,t.randomStringForEntropy=function(e,n,r){return void 0===n&&(n=a),void 0===r&&(r=t.defaultRandomSource),c(Math.ceil(e/(Math.log(n.length)/Math.LN2)),n,r)}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(92),i=n(93),o=function(){function e(){return this.isAvailable=!1,this.name="",this._source=new r.BrowserRandomSource,this._source.isAvailable?(this.isAvailable=!0,void(this.name="Browser")):(this._source=new i.NodeRandomSource,this._source.isAvailable?(this.isAvailable=!0,void(this.name="Node")):void 0)}return e.prototype.randomBytes=function(e){if(!this.isAvailable)throw new Error("System random byte generator is not available.");return this._source.randomBytes(e)},e}();t.SystemRandomSource=o},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=function(){function e(){this.isAvailable=!1,this.isInstantiated=!1;var e="undefined"!=typeof self?self.crypto||self.msCrypto:null;e&&e.getRandomValues&&(this._crypto=e,this.isAvailable=!0,this.isInstantiated=!0)}return e.prototype.randomBytes=function(e){if(!this.isAvailable||!this._crypto)throw new Error("Browser random byte generator is not available.");for(var t=new Uint8Array(e),n=0;n<t.length;n+=65536)this._crypto.getRandomValues(t.subarray(n,n+Math.min(t.length-n,65536)));return t},e}();t.BrowserRandomSource=r},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(27),i=function(){function e(){this.isAvailable=!1,this.isInstantiated=!1;var e=n(94);e&&e.randomBytes&&(this._crypto=e,this.isAvailable=!0,this.isInstantiated=!0)}return e.prototype.randomBytes=function(e){if(!this.isAvailable||!this._crypto)throw new Error("Node.js random byte generator is not available.");var t=this._crypto.randomBytes(e);if(t.length!==e)throw new Error("NodeRandomSource: got fewer bytes than requested");for(var n=new Uint8Array(e),i=0;i<n.length;i++)n[i]=t[i];return r.wipe(t),n},e}();t.NodeRandomSource=i},function(e,t){},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(96);function i(e,t,n){return void 0===t&&(t=new Uint8Array(2)),void 0===n&&(n=0),t[n+0]=e>>>8,t[n+1]=e>>>0,t}function o(e,t,n){return void 0===t&&(t=new Uint8Array(2)),void 0===n&&(n=0),t[n+0]=e>>>0,t[n+1]=e>>>8,t}function s(e,t){return void 0===t&&(t=0),e[t]<<24|e[t+1]<<16|e[t+2]<<8|e[t+3]}function a(e,t){return void 0===t&&(t=0),(e[t]<<24|e[t+1]<<16|e[t+2]<<8|e[t+3])>>>0}function c(e,t){return void 0===t&&(t=0),e[t+3]<<24|e[t+2]<<16|e[t+1]<<8|e[t]}function u(e,t){return void 0===t&&(t=0),(e[t+3]<<24|e[t+2]<<16|e[t+1]<<8|e[t])>>>0}function h(e,t,n){return void 0===t&&(t=new Uint8Array(4)),void 0===n&&(n=0),t[n+0]=e>>>24,t[n+1]=e>>>16,t[n+2]=e>>>8,t[n+3]=e>>>0,t}function l(e,t,n){return void 0===t&&(t=new Uint8Array(4)),void 0===n&&(n=0),t[n+0]=e>>>0,t[n+1]=e>>>8,t[n+2]=e>>>16,t[n+3]=e>>>24,t}function d(e,t,n){return void 0===t&&(t=new Uint8Array(8)),void 0===n&&(n=0),h(e/4294967296>>>0,t,n),h(e>>>0,t,n+4),t}function f(e,t,n){return void 0===t&&(t=new Uint8Array(8)),void 0===n&&(n=0),l(e>>>0,t,n),l(e/4294967296>>>0,t,n+4),t}t.readInt16BE=function(e,t){return void 0===t&&(t=0),(e[t+0]<<8|e[t+1])<<16>>16},t.readUint16BE=function(e,t){return void 0===t&&(t=0),(e[t+0]<<8|e[t+1])>>>0},t.readInt16LE=function(e,t){return void 0===t&&(t=0),(e[t+1]<<8|e[t])<<16>>16},t.readUint16LE=function(e,t){return void 0===t&&(t=0),(e[t+1]<<8|e[t])>>>0},t.writeUint16BE=i,t.writeInt16BE=i,t.writeUint16LE=o,t.writeInt16LE=o,t.readInt32BE=s,t.readUint32BE=a,t.readInt32LE=c,t.readUint32LE=u,t.writeUint32BE=h,t.writeInt32BE=h,t.writeUint32LE=l,t.writeInt32LE=l,t.readInt64BE=function(e,t){void 0===t&&(t=0);var n=s(e,t),r=s(e,t+4);return 4294967296*n+r-4294967296*(r>>31)},t.readUint64BE=function(e,t){return void 0===t&&(t=0),4294967296*a(e,t)+a(e,t+4)},t.readInt64LE=function(e,t){void 0===t&&(t=0);var n=c(e,t);return 4294967296*c(e,t+4)+n-4294967296*(n>>31)},t.readUint64LE=function(e,t){void 0===t&&(t=0);var n=u(e,t);return 4294967296*u(e,t+4)+n},t.writeUint64BE=d,t.writeInt64BE=d,t.writeUint64LE=f,t.writeInt64LE=f,t.readUintBE=function(e,t,n){if(void 0===n&&(n=0),e%8!=0)throw new Error("readUintBE supports only bitLengths divisible by 8");if(e/8>t.length-n)throw new Error("readUintBE: array is too short for the given bitLength");for(var r=0,i=1,o=e/8+n-1;o>=n;o--)r+=t[o]*i,i*=256;return r},t.readUintLE=function(e,t,n){if(void 0===n&&(n=0),e%8!=0)throw new Error("readUintLE supports only bitLengths divisible by 8");if(e/8>t.length-n)throw new Error("readUintLE: array is too short for the given bitLength");for(var r=0,i=1,o=n;o<n+e/8;o++)r+=t[o]*i,i*=256;return r},t.writeUintBE=function(e,t,n,i){if(void 0===n&&(n=new Uint8Array(e/8)),void 0===i&&(i=0),e%8!=0)throw new Error("writeUintBE supports only bitLengths divisible by 8");if(!r.isSafeInteger(t))throw new Error("writeUintBE value must be an integer");for(var o=1,s=e/8+i-1;s>=i;s--)n[s]=t/o&255,o*=256;return n},t.writeUintLE=function(e,t,n,i){if(void 0===n&&(n=new Uint8Array(e/8)),void 0===i&&(i=0),e%8!=0)throw new Error("writeUintLE supports only bitLengths divisible by 8");if(!r.isSafeInteger(t))throw new Error("writeUintLE value must be an integer");for(var o=1,s=i;s<i+e/8;s++)n[s]=t/o&255,o*=256;return n},t.readFloat32BE=function(e,t){return void 0===t&&(t=0),new DataView(e.buffer,e.byteOffset,e.byteLength).getFloat32(t)},t.readFloat32LE=function(e,t){return void 0===t&&(t=0),new DataView(e.buffer,e.byteOffset,e.byteLength).getFloat32(t,!0)},t.readFloat64BE=function(e,t){return void 0===t&&(t=0),new DataView(e.buffer,e.byteOffset,e.byteLength).getFloat64(t)},t.readFloat64LE=function(e,t){return void 0===t&&(t=0),new DataView(e.buffer,e.byteOffset,e.byteLength).getFloat64(t,!0)},t.writeFloat32BE=function(e,t,n){return void 0===t&&(t=new Uint8Array(4)),void 0===n&&(n=0),new DataView(t.buffer,t.byteOffset,t.byteLength).setFloat32(n,e),t},t.writeFloat32LE=function(e,t,n){return void 0===t&&(t=new Uint8Array(4)),void 0===n&&(n=0),new DataView(t.buffer,t.byteOffset,t.byteLength).setFloat32(n,e,!0),t},t.writeFloat64BE=function(e,t,n){return void 0===t&&(t=new Uint8Array(8)),void 0===n&&(n=0),new DataView(t.buffer,t.byteOffset,t.byteLength).setFloat64(n,e),t},t.writeFloat64LE=function(e,t,n){return void 0===t&&(t=new Uint8Array(8)),void 0===n&&(n=0),new DataView(t.buffer,t.byteOffset,t.byteLength).setFloat64(n,e,!0),t}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.mul=Math.imul||function(e,t){var n=65535&e,r=65535&t;return n*r+((e>>>16&65535)*r+n*(t>>>16&65535)<<16>>>0)|0},t.add=function(e,t){return e+t|0},t.sub=function(e,t){return e-t|0},t.rotl=function(e,t){return e<<t|e>>>32-t},t.rotr=function(e,t){return e<<32-t|e>>>t},t.isInteger=Number.isInteger||function(e){return"number"==typeof e&&isFinite(e)&&Math.floor(e)===e},t.MAX_SAFE_INTEGER=9007199254740991,t.isSafeInteger=function(e){return t.isInteger(e)&&e>=-t.MAX_SAFE_INTEGER&&e<=t.MAX_SAFE_INTEGER}},function(e,t,n){"use strict";e.exports=e=>encodeURIComponent(e).replace(/[!'()*]/g,e=>"%"+e.charCodeAt(0).toString(16).toUpperCase())},function(e,t,n){"use strict";var r=new RegExp("%[a-f0-9]{2}","gi"),i=new RegExp("(%[a-f0-9]{2})+","gi");function o(e,t){try{return decodeURIComponent(e.join(""))}catch(e){}if(1===e.length)return e;t=t||1;var n=e.slice(0,t),r=e.slice(t);return Array.prototype.concat.call([],o(n),o(r))}function s(e){try{return decodeURIComponent(e)}catch(i){for(var t=e.match(r),n=1;n<t.length;n++)t=(e=o(t,n).join("")).match(r);return e}}e.exports=function(e){if("string"!=typeof e)throw new TypeError("Expected `encodedURI` to be of type `string`, got `"+typeof e+"`");try{return e=e.replace(/\+/g," "),decodeURIComponent(e)}catch(t){return function(e){for(var t={"%FE%FF":"��","%FF%FE":"��"},n=i.exec(e);n;){try{t[n[0]]=decodeURIComponent(n[0])}catch(e){var r=s(n[0]);r!==n[0]&&(t[n[0]]=r)}n=i.exec(e)}t["%C2"]="�";for(var o=Object.keys(t),a=0;a<o.length;a++){var c=o[a];e=e.replace(new RegExp(c,"g"),t[c])}return e}(e)}}},function(e,t,n){"use strict";e.exports=(e,t)=>{if("string"!=typeof e||"string"!=typeof t)throw new TypeError("Expected the arguments to be of type `string`");if(""===t)return[e];const n=e.indexOf(t);return-1===n?[e]:[e.slice(0,n),e.slice(n+t.length)]}},function(e,t,n){"use strict";e.exports=function(e,t){for(var n={},r=Object.keys(e),i=Array.isArray(t),o=0;o<r.length;o++){var s=r[o],a=e[s];(i?-1!==t.indexOf(s):t(s,a,e))&&(n[s]=a)}return n}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.generateChildLogger=t.formatChildLoggerContext=t.getLoggerContext=t.setBrowserLoggerContext=t.getBrowserLoggerContext=t.getDefaultLoggerOptions=void 0;const r=n(69);function i(e,t=r.PINO_CUSTOM_CONTEXT_KEY){return e[t]||""}function o(e,t,n=r.PINO_CUSTOM_CONTEXT_KEY){return e[n]=t,e}function s(e,t=r.PINO_CUSTOM_CONTEXT_KEY){let n="";return n=void 0===e.bindings?i(e,t):e.bindings().context||"",n}function a(e,t,n=r.PINO_CUSTOM_CONTEXT_KEY){const i=s(e,n);return i.trim()?`${i}/${t}`:t}t.getDefaultLoggerOptions=function(e){return Object.assign(Object.assign({},e),{level:(null==e?void 0:e.level)||r.PINO_LOGGER_DEFAULTS.level,prettyPrint:(null==e?void 0:e.prettyPrint)||r.PINO_LOGGER_DEFAULTS.prettyPrint})},t.getBrowserLoggerContext=i,t.setBrowserLoggerContext=o,t.getLoggerContext=s,t.formatChildLoggerContext=a,t.generateChildLogger=function(e,t,n=r.PINO_CUSTOM_CONTEXT_KEY){const i=a(e,t,n);return o(e.child({context:i}),i,n)}},function(e,t,n){"use strict";e.exports=function(){throw new Error("ws does not work in the browser. Browser clients must use the native WebSocket object")}},function(e,t,n){"use strict";n.r(t),n.d(t,"SIGNER_EVENTS",(function(){return rt})),n.d(t,"SignerConnection",(function(){return it}));var r=n(3),i=n(5),o=n(0),s=n(19),a=n.n(s),c=n(26),u=n.n(c),h=n(6),l=n(17),d=n(2);var f=n(12);const p=Object(f.c)({GENERIC:"GENERIC",MISSING_OR_INVALID:"MISSING_OR_INVALID",MISSING_RESPONSE:"MISSING_RESPONSE",MISSING_DECRYPT_PARAMS:"MISSING_DECRYPT_PARAMS",INVALID_UPDATE_REQUEST:"INVALID_UPDATE_REQUEST",INVALID_UPGRADE_REQUEST:"INVALID_UPGRADE_REQUEST",INVALID_STORAGE_KEY_NAME:"INVALID_STORAGE_KEY_NAME",RECORD_ALREADY_EXISTS:"RECORD_ALREADY_EXISTS",RESTORE_WILL_OVERRIDE:"RESTORE_WILL_OVERRIDE",NO_MATCHING_ID:"NO_MATCHING_ID",NO_MATCHING_TOPIC:"NO_MATCHING_TOPIC",NO_MATCHING_RESPONSE:"NO_MATCHING_RESPONSE",NO_MATCHING_KEY:"NO_MATCHING_KEY",UNKNOWN_JSONRPC_METHOD:"UNKNOWN_JSONRPC_METHOD",MISMATCHED_TOPIC:"MISMATCHED_TOPIC",MISMATCHED_ACCOUNTS:"MISMATCHED_ACCOUNTS",SETTLED:"SETTLED",NOT_APPROVED:"NOT_APPROVED",PROPOSAL_RESPONDED:"PROPOSAL_RESPONDED",RESPONSE_ACKNOWLEDGED:"RESPONSE_ACKNOWLEDGED",EXPIRED:"EXPIRED",DELETED:"DELETED",RESUBSCRIBED:"RESUBSCRIBED",SETTLE_TIMEOUT:"SETTLE_TIMEOUT",JSONRPC_REQUEST_TIMEOUT:"JSONRPC_REQUEST_TIMEOUT",UNAUTHORIZED_TARGET_CHAIN:"UNAUTHORIZED_TARGET_CHAIN",UNAUTHORIZED_JSON_RPC_METHOD:"UNAUTHORIZED_JSON_RPC_METHOD",UNAUTHORIZED_NOTIFICATION_TYPE:"UNAUTHORIZED_NOTIFICATION_TYPE",UNAUTHORIZED_UPDATE_REQUEST:"UNAUTHORIZED_UPDATE_REQUEST",UNAUTHORIZED_UPGRADE_REQUEST:"UNAUTHORIZED_UPGRADE_REQUEST",UNAUTHORIZED_MATCHING_CONTROLLER:"UNAUTHORIZED_MATCHING_CONTROLLER",JSONRPC_REQUEST_METHOD_REJECTED:"JSONRPC_REQUEST_METHOD_REJECTED",JSONRPC_REQUEST_METHOD_UNAUTHORIZED:"JSONRPC_REQUEST_METHOD_UNAUTHORIZED",JSONRPC_REQUEST_METHOD_UNSUPPORTED:"JSONRPC_REQUEST_METHOD_UNSUPPORTED",DISCONNECTED_ALL_CHAINS:"DISCONNECTED_ALL_CHAINS",DISCONNECTED_TARGET_CHAIN:"DISCONNECTED_TARGET_CHAIN",DISAPPROVED_CHAINS:"DISAPPROVED_CHAINS",DISAPPROVED_JSONRPC:"DISAPPROVED_JSONRPC",DISAPPROVED_NOTIFICATION:"DISAPPROVED_NOTIFICATION",UNSUPPORTED_CHAINS:"UNSUPPORTED_CHAINS",UNSUPPORTED_JSONRPC:"UNSUPPORTED_JSONRPC",UNSUPPORTED_NOTIFICATION:"UNSUPPORTED_NOTIFICATION",UNSUPPORTED_SIGNAL:"UNSUPPORTED_SIGNAL",USER_DISCONNECTED:"USER_DISCONNECTED",UNKNOWN:"UNKNOWN"}),g="undefined",y="Something went wrong",v="parameter",m="session",E="Ethereum",b={[p.GENERIC]:{type:p.GENERIC,code:0,stringify:e=>(null==e?void 0:e.message)||y,format:e=>({code:b[p.GENERIC].code,message:b[p.GENERIC].stringify(e)})},[p.MISSING_OR_INVALID]:{type:p.MISSING_OR_INVALID,code:1e3,stringify:e=>"Missing or invalid "+((null==e?void 0:e.name)||v),format:e=>({code:b[p.MISSING_OR_INVALID].code,message:b[p.MISSING_OR_INVALID].stringify(e)})},[p.MISSING_RESPONSE]:{type:p.MISSING_RESPONSE,code:1001,stringify:e=>`Response is required for approved ${(null==e?void 0:e.context)||m} proposals`,format:e=>({code:b[p.MISSING_RESPONSE].code,message:b[p.MISSING_RESPONSE].stringify(e)})},[p.MISSING_DECRYPT_PARAMS]:{type:p.MISSING_DECRYPT_PARAMS,code:1002,stringify:e=>"Decrypt params required for "+((null==e?void 0:e.context)||m),format:e=>({code:b[p.MISSING_DECRYPT_PARAMS].code,message:b[p.MISSING_DECRYPT_PARAMS].stringify(e)})},[p.INVALID_UPDATE_REQUEST]:{type:p.INVALID_UPDATE_REQUEST,code:1003,stringify:e=>`Invalid ${(null==e?void 0:e.context)||m} update request`,format:e=>({code:b[p.INVALID_UPDATE_REQUEST].code,message:b[p.INVALID_UPDATE_REQUEST].stringify(e)})},[p.INVALID_UPGRADE_REQUEST]:{type:p.INVALID_UPGRADE_REQUEST,code:1004,stringify:e=>`Invalid ${(null==e?void 0:e.context)||m} upgrade request`,format:e=>({code:b[p.INVALID_UPGRADE_REQUEST].code,message:b[p.INVALID_UPGRADE_REQUEST].stringify(e)})},[p.INVALID_STORAGE_KEY_NAME]:{type:p.INVALID_STORAGE_KEY_NAME,code:1005,stringify:e=>"Invalid storage key name: "+((null==e?void 0:e.name)||v),format:e=>({code:b[p.INVALID_STORAGE_KEY_NAME].code,message:b[p.INVALID_STORAGE_KEY_NAME].stringify(e)})},[p.RECORD_ALREADY_EXISTS]:{type:p.RECORD_ALREADY_EXISTS,code:1100,stringify:e=>`Record already exists for ${(null==e?void 0:e.context)||m} matching id: ${null==e?void 0:e.id}`,format:e=>({code:b[p.RECORD_ALREADY_EXISTS].code,message:b[p.RECORD_ALREADY_EXISTS].stringify(e)})},[p.RESTORE_WILL_OVERRIDE]:{type:p.RESTORE_WILL_OVERRIDE,code:1200,stringify:e=>"Restore will override already set "+((null==e?void 0:e.context)||m),format:e=>({code:b[p.RESTORE_WILL_OVERRIDE].code,message:b[p.RESTORE_WILL_OVERRIDE].stringify(e)})},[p.NO_MATCHING_ID]:{type:p.NO_MATCHING_ID,code:1300,stringify:e=>`No matching ${(null==e?void 0:e.context)||m} with id: ${null==e?void 0:e.id}`,format:e=>({code:b[p.NO_MATCHING_ID].code,message:b[p.NO_MATCHING_ID].stringify(e)})},[p.NO_MATCHING_TOPIC]:{type:p.NO_MATCHING_TOPIC,code:1301,stringify:e=>`No matching ${(null==e?void 0:e.context)||m} with topic: ${null==e?void 0:e.topic}`,format:e=>({code:b[p.NO_MATCHING_TOPIC].code,message:b[p.NO_MATCHING_TOPIC].stringify(e)})},[p.NO_MATCHING_RESPONSE]:{type:p.NO_MATCHING_RESPONSE,code:1302,stringify:e=>`No response found in pending ${(null==e?void 0:e.context)||m} proposal`,format:e=>({code:b[p.NO_MATCHING_RESPONSE].code,message:b[p.NO_MATCHING_RESPONSE].stringify(e)})},[p.NO_MATCHING_KEY]:{type:p.NO_MATCHING_KEY,code:1303,stringify:e=>"No matching key with tag: "+(null==e?void 0:e.tag),format:e=>({code:b[p.NO_MATCHING_KEY].code,message:b[p.NO_MATCHING_KEY].stringify(e)})},[p.UNKNOWN_JSONRPC_METHOD]:{type:p.UNKNOWN_JSONRPC_METHOD,code:1400,stringify:e=>"Unknown JSON-RPC Method Requested: "+(null==e?void 0:e.method),format:e=>({code:b[p.UNKNOWN_JSONRPC_METHOD].code,message:b[p.UNKNOWN_JSONRPC_METHOD].stringify(e)})},[p.MISMATCHED_TOPIC]:{type:p.MISMATCHED_TOPIC,code:1500,stringify:e=>`Mismatched topic for ${(null==e?void 0:e.context)||m} with id: ${null==e?void 0:e.id}`,format:e=>({code:b[p.MISMATCHED_TOPIC].code,message:b[p.MISMATCHED_TOPIC].stringify(e)})},[p.MISMATCHED_ACCOUNTS]:{type:p.MISMATCHED_ACCOUNTS,code:1501,stringify:e=>"Invalid accounts with mismatched chains: "+(null==e?void 0:e.mismatched.toString()),format:e=>({code:b[p.MISMATCHED_ACCOUNTS].code,message:b[p.MISMATCHED_ACCOUNTS].stringify(e)})},[p.SETTLED]:{type:p.SETTLED,code:1600,stringify:e=>Object(f.b)((null==e?void 0:e.context)||m)+" settled",format:e=>({code:b[p.SETTLED].code,message:b[p.SETTLED].stringify(e)})},[p.NOT_APPROVED]:{type:p.NOT_APPROVED,code:1601,stringify:e=>Object(f.b)((null==e?void 0:e.context)||m)+" not approved",format:e=>({code:b[p.NOT_APPROVED].code,message:b[p.NOT_APPROVED].stringify(e)})},[p.PROPOSAL_RESPONDED]:{type:p.PROPOSAL_RESPONDED,code:1602,stringify:e=>Object(f.b)((null==e?void 0:e.context)||m)+" proposal responded",format:e=>({code:b[p.PROPOSAL_RESPONDED].code,message:b[p.PROPOSAL_RESPONDED].stringify(e)})},[p.RESPONSE_ACKNOWLEDGED]:{type:p.RESPONSE_ACKNOWLEDGED,code:1603,stringify:e=>Object(f.b)((null==e?void 0:e.context)||m)+" response acknowledge",format:e=>({code:b[p.RESPONSE_ACKNOWLEDGED].code,message:b[p.RESPONSE_ACKNOWLEDGED].stringify(e)})},[p.EXPIRED]:{type:p.EXPIRED,code:1604,stringify:e=>Object(f.b)((null==e?void 0:e.context)||m)+" expired",format:e=>({code:b[p.EXPIRED].code,message:b[p.EXPIRED].stringify(e)})},[p.DELETED]:{type:p.DELETED,code:1605,stringify:e=>Object(f.b)((null==e?void 0:e.context)||m)+" deleted",format:e=>({code:b[p.DELETED].code,message:b[p.DELETED].stringify(e)})},[p.RESUBSCRIBED]:{type:p.RESUBSCRIBED,code:1606,stringify:e=>"Subscription resubscribed with topic: "+(e.topic||g),format:e=>({code:b[p.RESUBSCRIBED].code,message:b[p.RESUBSCRIBED].stringify(e)})},[p.SETTLE_TIMEOUT]:{type:p.SETTLE_TIMEOUT,code:2e3,stringify:e=>`${Object(f.b)((null==e?void 0:e.context)||m)} failed to settle after ${Object(f.g)(null==e?void 0:e.timeout)} seconds`,format:e=>({code:b[p.SETTLE_TIMEOUT].code,message:b[p.SETTLE_TIMEOUT].stringify(e)})},[p.JSONRPC_REQUEST_TIMEOUT]:{type:p.JSONRPC_REQUEST_TIMEOUT,code:2001,stringify:e=>`JSON-RPC Request timeout after ${Object(f.g)(null==e?void 0:e.timeout)} seconds: ${null==e?void 0:e.method}`,format:e=>({code:b[p.JSONRPC_REQUEST_TIMEOUT].code,message:b[p.JSONRPC_REQUEST_TIMEOUT].stringify(e)})},[p.UNAUTHORIZED_TARGET_CHAIN]:{type:p.UNAUTHORIZED_TARGET_CHAIN,code:3e3,stringify:e=>"Unauthorized Target ChainId Requested: "+(null==e?void 0:e.chainId),format:e=>({code:b[p.UNAUTHORIZED_TARGET_CHAIN].code,message:b[p.UNAUTHORIZED_TARGET_CHAIN].stringify(e)})},[p.UNAUTHORIZED_JSON_RPC_METHOD]:{type:p.UNAUTHORIZED_JSON_RPC_METHOD,code:3001,stringify:e=>"Unauthorized JSON-RPC Method Requested: "+(null==e?void 0:e.method),format:e=>({code:b[p.UNAUTHORIZED_JSON_RPC_METHOD].code,message:b[p.UNAUTHORIZED_JSON_RPC_METHOD].stringify(e)})},[p.UNAUTHORIZED_NOTIFICATION_TYPE]:{type:p.UNAUTHORIZED_NOTIFICATION_TYPE,code:3002,stringify:e=>"Unauthorized Notification Type Requested: "+(null==e?void 0:e.type),format:e=>({code:b[p.UNAUTHORIZED_NOTIFICATION_TYPE].code,message:b[p.UNAUTHORIZED_NOTIFICATION_TYPE].stringify(e)})},[p.UNAUTHORIZED_UPDATE_REQUEST]:{type:p.UNAUTHORIZED_UPDATE_REQUEST,code:3003,stringify:e=>`Unauthorized ${(null==e?void 0:e.context)||m} update request`,format:e=>({code:b[p.UNAUTHORIZED_UPDATE_REQUEST].code,message:b[p.UNAUTHORIZED_UPDATE_REQUEST].stringify(e)})},[p.UNAUTHORIZED_UPGRADE_REQUEST]:{type:p.UNAUTHORIZED_UPGRADE_REQUEST,code:3004,stringify:e=>`Unauthorized ${(null==e?void 0:e.context)||m} upgrade request`,format:e=>({code:b[p.UNAUTHORIZED_UPGRADE_REQUEST].code,message:b[p.UNAUTHORIZED_UPGRADE_REQUEST].stringify(e)})},[p.UNAUTHORIZED_MATCHING_CONTROLLER]:{type:p.UNAUTHORIZED_MATCHING_CONTROLLER,code:3005,stringify:e=>`Unauthorized: peer is also ${(null==e?void 0:e.controller)?"":"not "}controller`,format:e=>({code:b[p.UNAUTHORIZED_MATCHING_CONTROLLER].code,message:b[p.UNAUTHORIZED_MATCHING_CONTROLLER].stringify(e)})},[p.JSONRPC_REQUEST_METHOD_REJECTED]:{type:p.JSONRPC_REQUEST_METHOD_REJECTED,code:4001,stringify:e=>"User rejected the request.",format:e=>({code:b[p.JSONRPC_REQUEST_METHOD_REJECTED].code,message:b[p.JSONRPC_REQUEST_METHOD_REJECTED].stringify(e)})},[p.JSONRPC_REQUEST_METHOD_UNAUTHORIZED]:{type:p.JSONRPC_REQUEST_METHOD_UNAUTHORIZED,code:4100,stringify:e=>"The requested account and/or method has not been authorized by the user.",format:e=>({code:b[p.JSONRPC_REQUEST_METHOD_UNAUTHORIZED].code,message:b[p.JSONRPC_REQUEST_METHOD_UNAUTHORIZED].stringify(e)})},[p.JSONRPC_REQUEST_METHOD_UNSUPPORTED]:{type:p.JSONRPC_REQUEST_METHOD_UNSUPPORTED,code:4200,stringify:e=>`The requested method is not supported by this ${(null==e?void 0:e.blockhain)||E} provider.`,format:e=>({code:b[p.JSONRPC_REQUEST_METHOD_UNSUPPORTED].code,message:b[p.JSONRPC_REQUEST_METHOD_UNSUPPORTED].stringify(e)})},[p.DISCONNECTED_ALL_CHAINS]:{type:p.DISCONNECTED_ALL_CHAINS,code:4900,stringify:e=>"The provider is disconnected from all chains.",format:e=>({code:b[p.DISCONNECTED_ALL_CHAINS].code,message:b[p.DISCONNECTED_ALL_CHAINS].stringify(e)})},[p.DISCONNECTED_TARGET_CHAIN]:{type:p.DISCONNECTED_TARGET_CHAIN,code:4901,stringify:e=>"The provider is disconnected from the specified chain.",format:e=>({code:b[p.DISCONNECTED_TARGET_CHAIN].code,message:b[p.DISCONNECTED_TARGET_CHAIN].stringify(e)})},[p.DISAPPROVED_CHAINS]:{type:p.DISAPPROVED_CHAINS,code:5e3,stringify:e=>"User disapproved requested chains",format:e=>({code:b[p.DISAPPROVED_CHAINS].code,message:b[p.DISAPPROVED_CHAINS].stringify(e)})},[p.DISAPPROVED_JSONRPC]:{type:p.DISAPPROVED_JSONRPC,code:5001,stringify:e=>"User disapproved requested json-rpc methods",format:e=>({code:b[p.DISAPPROVED_JSONRPC].code,message:b[p.DISAPPROVED_JSONRPC].stringify(e)})},[p.DISAPPROVED_NOTIFICATION]:{type:p.DISAPPROVED_NOTIFICATION,code:5002,stringify:e=>"User disapproved requested notification types",format:e=>({code:b[p.DISAPPROVED_NOTIFICATION].code,message:b[p.DISAPPROVED_NOTIFICATION].stringify(e)})},[p.UNSUPPORTED_CHAINS]:{type:p.UNSUPPORTED_CHAINS,code:5100,stringify:e=>"Requested chains are not supported: "+(null==e?void 0:e.chains.toString()),format:e=>({code:b[p.UNSUPPORTED_CHAINS].code,message:b[p.UNSUPPORTED_CHAINS].stringify(e)})},[p.UNSUPPORTED_JSONRPC]:{type:p.UNSUPPORTED_JSONRPC,code:5101,stringify:e=>"Requested json-rpc methods are not supported: "+(null==e?void 0:e.methods.toString()),format:e=>({code:b[p.UNSUPPORTED_JSONRPC].code,message:b[p.UNSUPPORTED_JSONRPC].stringify(e)})},[p.UNSUPPORTED_NOTIFICATION]:{type:p.UNSUPPORTED_NOTIFICATION,code:5102,stringify:e=>"Requested notification types are not supported: "+(null==e?void 0:e.types.toString()),format:e=>({code:b[p.UNSUPPORTED_NOTIFICATION].code,message:b[p.UNSUPPORTED_NOTIFICATION].stringify(e)})},[p.UNSUPPORTED_SIGNAL]:{type:p.UNSUPPORTED_SIGNAL,code:5103,stringify:e=>`Proposed ${(null==e?void 0:e.context)||m} signal is unsupported`,format:e=>({code:b[p.UNSUPPORTED_SIGNAL].code,message:b[p.UNSUPPORTED_SIGNAL].stringify(e)})},[p.USER_DISCONNECTED]:{type:p.USER_DISCONNECTED,code:5900,stringify:e=>"User disconnected "+((null==e?void 0:e.context)||m),format:e=>({code:b[p.USER_DISCONNECTED].code,message:b[p.USER_DISCONNECTED].stringify(e)})},[p.UNKNOWN]:{type:p.UNKNOWN,code:9e3,stringify:e=>"Unknown error"+(e?": "+(null==e?void 0:e.toString()):""),format:e=>({code:b[p.UNKNOWN].code,message:b[p.UNKNOWN].stringify(e)})}};var _=n(20),w=n(8);function R(e){return"pairing"===e.method}function O(e){return"responded"===e.status&&"outcome"in e}function T(e){return"reason"in e}function S(e){return"responded"===e}function I(e){const t=function(e){if(void 0===e||void 0===e.chains||!P(e.chains,C))return x(b.MISSING_OR_INVALID.format({name:"blockchain permissions"}));return{valid:!0}}(e.blockchain);if(j(t))return t;const n=function(e){if(void 0===e||void 0===e.methods||!P(e.methods,U))return x(b.MISSING_OR_INVALID.format({name:"jsonrpc permissions"}));return{valid:!0}}(e.jsonrpc);if(j(n))return n;const r=function(e){if(void 0===e||void 0===e.types||!P(e.types,U))return x(b.MISSING_OR_INVALID.format({name:"notification permissions"}));return{valid:!0}}(e.notifications);return j(r)?r:{valid:!0}}function N(e){return U(e.name)?U(e.description)?void 0!==e.url&&L(e.url)?void 0!==e.icons&&P(e.icons,L)?{valid:!0}:x(b.MISSING_OR_INVALID.format({name:"metadata icons"})):x(b.MISSING_OR_INVALID.format({name:"metadata url"})):x(b.MISSING_OR_INVALID.format({name:"metadata description"})):x(b.MISSING_OR_INVALID.format({name:"metadata name"}))}function A(e){if(e.approved){if(void 0===e.response)return x(b.MISSING_RESPONSE.format({context:"session"}));const t=function(e,t){if(void 0===t||void 0===t.chains||!P(t.chains,C))return x(b.MISSING_OR_INVALID.format({name:"blockchain permissions"}));if(void 0===e||void 0===e.accounts||!P(e.accounts,D))return x(b.MISSING_OR_INVALID.format({name:"state accounts"}));const n=e.accounts.filter(e=>{const[n,r]=e.split(":"),i=`${n}:${r}`;return!t.chains.includes(i)});if(n.length)return x(b.MISMATCHED_ACCOUNTS.format({mismatched:n}));return{valid:!0}}(e.response.state,e.proposal.permissions.blockchain);if(j(t))return t;const n=N(e.response.metadata);if(j(n))return n}return{valid:!0}}function P(e,t){if(Array.isArray(e)){if(void 0!==t&&e.length){return e.filter(t).length===e.length}return!0}return!1}function U(e){return"string"==typeof e&&!!e.trim()}function C(e){if(U(e)&&e.includes(":")){return 2===e.split(":").length}return!1}function D(e){if(U(e)&&e.includes(":")){const t=e.split(":");if(3===t.length){const e=t[0]+":"+t[1];return!!t[2]&&C(e)}}return!1}function L(e){if(U(e))try{return void 0!==new URL(e)}catch(e){return!1}return!1}function j(e){return"valid"in e&&!1===e.valid&&"error"in e&&"number"==typeof e.error.code&&"string"==typeof e.error.message}function x(e){return{valid:!1,error:e}}var q=n(1);const M="client",H="error",K=!1,J="wss://relay.walletconnect.com",B={proposal:"pairing_proposal",updated:"pairing_updated",created:"pairing_created",deleted:"pairing_deleted",sync:"pairing_sync"},G={proposal:"session_proposal",updated:"session_updated",created:"session_created",deleted:"session_deleted",notification:"session_notification",request:"session_request",response:"session_response",sync:"session_sync"},k={database:":memory:"},V="expirer_created",F="expirer_deleted",z="expirer_expired",Y="expirer_init",W="expirer_sync",$="heartbeat_pulse",Q="history_created",Z="history_updated",X="history_deleted",ee="history_init",te="history_sync",ne={propose:"wc_pairingPropose",approve:"wc_pairingApprove",reject:"wc_pairingReject",update:"wc_pairingUpdate",upgrade:"wc_pairingUpgrade",delete:"wc_pairingDelete",payload:"wc_pairingPayload",ping:"wc_pairingPing",notification:"wc_pairingNotification"},re={proposed:"proposed",responded:"responded",pending:"pending",settled:"settled"},ie={proposed:"pairing_proposed",responded:"pairing_responded",settled:"pairing_settled",updated:"pairing_updated",deleted:"pairing_deleted",request:"pairing_request",response:"pairing_response",sync:"pairing_sync",notification:"pairing_notification"},oe="relayer_payload",se="relayer_connect",ae="relayer_disconnect",ce="relayer_error",ue="payload",he="connect",le="disconnect",de="error",fe={database:":memory:"},pe={propose:"wc_sessionPropose",approve:"wc_sessionApprove",reject:"wc_sessionReject",update:"wc_sessionUpdate",upgrade:"wc_sessionUpgrade",delete:"wc_sessionDelete",payload:"wc_sessionPayload",ping:"wc_sessionPing",notification:"wc_sessionNotification"},ge={proposed:"proposed",responded:"responded",pending:"pending",settled:"settled"},ye={proposed:"session_proposed",responded:"session_responded",settled:"session_settled",updated:"session_updated",deleted:"session_deleted",request:"session_request",response:"session_response",sync:"session_sync",notification:"session_notification"},ve={jsonrpc:{methods:[]},blockchain:{chains:[]},notifications:{types:[]}},me={accounts:[]},Ee={metadata:{name:"",description:"",url:"",icons:[]},state:me},be="store_created",_e="store_updated",we="store_deleted",Re="store_init",Oe="store_sync",Te={crypto:{keychain:"crypto:keychain"},session:{pending:"session:pending",settled:"session:settled",history:"session:history",expirer:"session:expirer"},pairing:{pending:"pairing:pending",settled:"pairing:settled",history:"pairing:history",expirer:"pairing:expirer"},relayer:{history:"relayer:history",subscription:"relayer:subscription"}},Se="subscription_created",Ie="subscription_deleted",Ne="subscription_expired",Ae="subscription_enabled",Pe="subscription_disabled",Ue="subscription_sync";class Ce{constructor(e,t){this.client=e,this.logger=t,this.keychain=new Map,this.name="keychain",this.client=e,this.logger=Object(q.generateChildLogger)(t,this.name)}get context(){return Object(q.getLoggerContext)(this.logger)}async init(){await this.restore()}async has(e,t){return this.keychain.has(e)}async set(e,t,n){this.keychain.set(e,t),await this.persist()}async get(e,t){const n=this.keychain.get(e);if(void 0===n)throw new Error(b.NO_MATCHING_KEY.format({tag:e}).message);return n}async del(e,t){this.keychain.delete(e),await this.persist()}async restore(){const e=await this.client.storage.getKeyChain(this.context);void 0!==e&&(this.keychain=e)}async persist(){await this.client.storage.setKeyChain(this.context,this.keychain)}}class De{constructor(e,t,n){this.client=e,this.logger=t,this.name="crypto",this.client=e,this.logger=Object(q.generateChildLogger)(t,this.name),this.keychain=n||new Ce(this.client,this.logger)}get context(){return Object(q.getLoggerContext)(this.logger)}async init(){await this.keychain.init()}async hasKeys(e){return this.keychain.has(e)}async generateKeyPair(){const e=function(){const e=l.generateKeyPair();return{privateKey:d.arrayToHex(e.privateKey),publicKey:d.arrayToHex(e.publicKey)}}();return this.setKeyPair(e)}async generateSharedKey(e,t,n){const r=await this.getKeyPair(e.publicKey),i=function(e,t){const n=l.derive(d.hexToArray(e),d.hexToArray(t));return d.arrayToHex(n)}(r.privateKey,t.publicKey);return this.setEncryptionKeys({sharedKey:i,publicKey:r.publicKey},n)}async encrypt(e,t){const{sharedKey:n,publicKey:r}=await this.getEncryptionKeys(e);return await async function(e){const t=d.utf8ToArray(e.message),n=d.hexToArray(e.sharedKey),r=d.hexToArray(e.publicKey),i=void 0!==e.iv?d.hexToArray(e.iv):void 0,o=await l.encryptWithSharedKey(t,n,r,i);return d.arrayToHex(o)}({message:t,sharedKey:n,publicKey:r})}async decrypt(e,t){const{sharedKey:n}=await this.getEncryptionKeys(e);return await async function(e){const t=d.hexToArray(e.encrypted),n=d.hexToArray(e.sharedKey),r=await l.decryptWithSharedKey(t,n);return d.arrayToUtf8(r)}({encrypted:t,sharedKey:n})}async encode(e,t){const n=Object(w.b)(t);return await this.hasKeys(e)?await this.encrypt(e,n):d.utf8ToHex(n)}async decode(e,t){const n=await this.hasKeys(e)?await this.decrypt(e,t):d.hexToUtf8(t);return Object(w.a)(n)}concatKeys(e,t){return d.arrayToHex(d.concatArrays(d.hexToArray(e),d.hexToArray(t)))}splitKeys(e){const t=d.hexToArray(e);return[d.arrayToHex(t.slice(0,32)),d.arrayToHex(t.slice(32,64))]}async setKeyPair(e){const t=this.concatKeys(e.publicKey,e.privateKey);return await this.keychain.set(e.publicKey,t),e.publicKey}async getKeyPair(e){const[t,n]=this.splitKeys(await this.keychain.get(e));return{publicKey:e,privateKey:n}}async setEncryptionKeys(e,t){const n=t||await async function(e){const t=await l.sha256(d.hexToArray(e));return d.arrayToHex(t)}(e.sharedKey),r=this.concatKeys(e.sharedKey,e.publicKey);return await this.keychain.set(n,r),n}async getEncryptionKeys(e){const[t,n]=this.splitKeys(await this.keychain.get(e));return{sharedKey:t,publicKey:n}}}class Le{constructor(e,t){this.client=e,this.logger=t,this.name="encoder",this.client=e,this.logger=Object(q.generateChildLogger)(t,this.name)}get context(){return Object(q.getLoggerContext)(this.logger)}async encode(e,t){const n=Object(w.b)(t);return await this.client.crypto.hasKeys(e)?await this.client.crypto.encrypt(e,n):d.utf8ToHex(n)}async decode(e,t){const n=await this.client.crypto.hasKeys(e)?await this.client.crypto.decrypt(e,t):d.hexToUtf8(t);return Object(w.a)(n)}}class je{async encode(e,t){return d.utf8ToHex(Object(w.b)(t))}async decode(e,t){return Object(w.a)(d.hexToUtf8(t))}}class xe extends h.IEngine{constructor(e){super(e),this.sequence=e,this.registerEventListeners()}async find(e){return this.sequence.values.filter(t=>{var n,r,i,o,s,a;let c=!1;return(null===(n=t.permissions)||void 0===n?void 0:n.jsonrpc)&&(null===(r=e.jsonrpc)||void 0===r?void 0:r.methods)&&Object(f.i)(e.jsonrpc.methods,t.permissions.jsonrpc.methods)&&(c=!0),(null===(i=t.permissions)||void 0===i?void 0:i.blockchain)&&(null===(o=e.blockchain)||void 0===o?void 0:o.chains)&&Object(f.i)(e.blockchain.chains,t.permissions.blockchain.chains)&&(c=!0),(null===(s=t.permissions)||void 0===s?void 0:s.notifications)&&(null===(a=e.notifications)||void 0===a?void 0:a.types)&&Object(f.i)(e.notifications.types,t.permissions.notifications.types)&&(c=!0),c})}async ping(e,t){const n={method:this.sequence.config.jsonrpc.ping,params:{}};return this.request({topic:e,request:n,timeout:t||Object(f.m)(30)})}async send(e,t,n){const r=t,i=await this.sequence.settled.get(e);if(Object(o.isJsonRpcRequest)(t)&&!Object.values(this.sequence.config.jsonrpc).includes(t.method)){await this.isJsonRpcAuthorized(e,i.self,t),await this.sequence.validateRequest({topic:e,request:t,chainId:n});const r={chainId:n,request:{method:t.method,params:t.params}};r.chainId||delete r.chainId,t=Object(o.formatJsonRpcRequest)(this.sequence.config.jsonrpc.payload,r,t.id)}await this.sequence.client.relayer.publish(i.topic,t,{relay:i.relay}),(Object(o.isJsonRpcResponse)(r)||Object(o.isJsonRpcRequest)(r)&&!Object.values(this.sequence.config.jsonrpc).includes(r.method))&&await this.recordPayloadEvent({topic:e,payload:r,chainId:n})}get length(){return this.sequence.settled.length}get topics(){return this.sequence.settled.topics}get values(){return this.sequence.settled.values}create(e){return new Promise(async(t,n)=>{this.sequence.logger.debug("Create "+this.sequence.context),this.sequence.logger.trace({type:"method",method:"create",params:e});const r=(null==e?void 0:e.timeout)||Object(f.m)(300),i=setTimeout(()=>{const e=b.SETTLE_TIMEOUT.format({context:this.sequence.name,timeout:r});this.sequence.logger.error(e.message),n(e.message)},r);let o;try{o=await this.propose(e)}catch(e){return clearTimeout(i),n(e)}this.sequence.pending.on(_e,async e=>{if(o.topic===e.sequence.topic&&O(e.sequence)){const r=e.sequence.outcome;if(clearTimeout(i),T(r)){try{await this.sequence.pending.delete(o.topic,r.reason)}catch(e){return n(e)}n(new Error(r.reason.message))}else try{const e=await this.sequence.settled.get(r.topic),n=b.SETTLED.format({context:this.sequence.name});await this.sequence.pending.delete(o.topic,n),t(e)}catch(e){return n(e)}}})})}async respond(e){this.sequence.logger.debug("Respond "+this.sequence.context),this.sequence.logger.trace({type:"method",method:"respond",params:e}),await this.sequence.validateRespond(e);const{approved:t,proposal:n,response:r}=e,{relay:i,ttl:o}=n,s={publicKey:await this.sequence.client.crypto.generateKeyPair(),metadata:null==r?void 0:r.metadata};if(s.metadata||delete s.metadata,!t){const t=b.NOT_APPROVED.format({context:this.sequence.name}),r={reason:(null==e?void 0:e.reason)||t},o={status:this.sequence.config.status.responded,topic:n.topic,relay:i,self:s,proposal:n,outcome:r};return await this.sequence.pending.set(o.topic,o),o}try{const e={publicKey:s.publicKey,metadata:null==r?void 0:r.metadata};e.metadata||delete e.metadata;const t=Object(f.a)(n.ttl),a=(null==r?void 0:r.state)||{},c={publicKey:n.proposer.publicKey,metadata:n.proposer.metadata};c.metadata||delete c.metadata;const u=n.proposer.controller?{publicKey:c.publicKey}:{publicKey:s.publicKey},h=Object.assign(Object.assign({},n.permissions),{controller:u}),l={topic:(await this.settle({relay:i,self:s,peer:c,permissions:h,state:a,ttl:o,expiry:t})).topic,relay:i,state:a,responder:e,expiry:t},d={status:this.sequence.config.status.responded,topic:n.topic,relay:i,self:s,proposal:n,outcome:l};return await this.sequence.pending.set(d.topic,d),d}catch(e){const t={reason:b.GENERIC.format({message:e.message})},r={status:this.sequence.config.status.responded,topic:n.topic,relay:i,self:s,proposal:n,outcome:t};return await this.sequence.pending.set(r.topic,r),r}}async update(e){this.sequence.logger.debug("Update "+this.sequence.context),this.sequence.logger.trace({type:"method",method:"update",params:e});const t=await this.sequence.settled.get(e.topic),n={publicKey:t.self.publicKey},r=await this.handleUpdate(e.topic,e,n),i=Object(o.formatJsonRpcRequest)(this.sequence.config.jsonrpc.update,r);return await this.send(t.topic,i),t}async upgrade(e){this.sequence.logger.debug("Upgrade "+this.sequence.context),this.sequence.logger.trace({type:"method",method:"upgrade",params:e});const t=await this.sequence.settled.get(e.topic),n={publicKey:t.self.publicKey},r=await this.handleUpgrade(e.topic,e,n),i=Object(o.formatJsonRpcRequest)(this.sequence.config.jsonrpc.upgrade,r);return await this.send(t.topic,i),t}async request(e){return new Promise(async(t,n)=>{try{await this.sequence.validateRequest(e)}catch(e){return n(e)}const r=Object(o.formatJsonRpcRequest)(e.request.method,e.request.params),i=(null==e?void 0:e.timeout)||Object(f.m)(300),s=setTimeout(()=>{const e=b.JSONRPC_REQUEST_TIMEOUT.format({method:r.method,timeout:i});this.sequence.logger.error(e.message),n(e.message)},i);this.sequence.events.on(this.sequence.config.events.response,i=>{if(e.topic!==i.topic)return;const a=i.response;if(a.id===r.id){if(clearTimeout(s),Object(o.isJsonRpcError)(a)){const e=a.error.message;return this.sequence.logger.error(e),n(new Error(e))}return t(a.result)}});try{await this.send(e.topic,r,null==e?void 0:e.chainId)}catch(e){return clearTimeout(s),n(e)}})}async delete(e){this.sequence.logger.debug("Delete "+this.sequence.context),this.sequence.logger.trace({type:"method",method:"delete",params:e}),await this.sequence.settled.delete(e.topic,e.reason)}async notify(e){const{topic:t,notification:n}=e,r=await this.sequence.settled.get(e.topic);await this.isNotificationAuthorized(e.topic,r.self,n.type);const i=Object(o.formatJsonRpcRequest)(this.sequence.config.jsonrpc.notification,n);await this.send(e.topic,i)}async propose(e){this.sequence.logger.debug("Propose "+this.sequence.context),this.sequence.logger.trace({type:"method",method:"propose",params:e}),await this.sequence.validatePropose(e);const t=(null==e?void 0:e.relay)||{protocol:"waku"},n=d.arrayToHex(l.randomBytes(32)),r={publicKey:await this.sequence.client.crypto.generateKeyPair(),metadata:null==e?void 0:e.metadata};r.metadata||delete r.metadata;const i={publicKey:r.publicKey,controller:this.sequence.client.controller,metadata:r.metadata};i.metadata||delete i.metadata;const o={relay:t,topic:n,proposer:i,signal:(null==e?void 0:e.signal)||await this.sequence.getDefaultSignal({topic:n,relay:t,proposer:i}),permissions:(null==e?void 0:e.permissions)||await this.sequence.getDefaultPermissions(),ttl:(null==e?void 0:e.ttl)||await this.sequence.getDefaultTTL()},s={status:this.sequence.config.status.proposed,topic:o.topic,relay:o.relay,self:r,proposal:o};return await this.sequence.pending.set(s.topic,s),s}async settle(e){this.sequence.logger.debug("Settle "+this.sequence.context),this.sequence.logger.trace({type:"method",method:"settle",params:e});const t={topic:await this.sequence.client.crypto.generateSharedKey(e.self,e.peer),relay:e.relay,self:e.self,peer:e.peer,permissions:e.permissions,expiry:e.expiry,state:e.state,acknowledged:!1};return await this.sequence.settled.set(t.topic,t),t}async onResponse(e){const{topic:t,payload:n}=e;this.sequence.logger.debug(`Receiving ${this.sequence.context} response`),this.sequence.logger.trace({type:"method",method:"onResponse",topic:t,payload:n});const r=n,i=r.params,s=await this.sequence.pending.get(t);let a,c;if(function(e){return"reason"in e}(i))this.sequence.logger.error(i.reason),await this.sequence.pending.update(t,{status:this.sequence.config.status.responded,outcome:{reason:i.reason}});else{try{const e=s.proposal.proposer.controller?{publicKey:s.proposal.proposer.publicKey}:{publicKey:i.responder.publicKey},n={publicKey:i.responder.publicKey,metadata:i.responder.metadata};n.metadata||delete n.metadata;const r=i.state||{},o=Object.assign(Object.assign({},s.proposal.permissions),{controller:e}),a=await this.settle({relay:s.relay,self:s.self,peer:n,permissions:o,ttl:s.proposal.ttl,expiry:i.expiry,state:r}),c={topic:a.topic,relay:a.relay,responder:i.responder,expiry:a.expiry,state:a.state};await this.sequence.pending.update(t,{status:this.sequence.config.status.responded,outcome:c})}catch(e){this.sequence.logger.error(e),a=b.GENERIC.format({message:e.message}),c={reason:a},await this.sequence.pending.update(t,{status:this.sequence.config.status.responded,outcome:c})}await this.sequence.client.relayer.publish(s.topic,void 0===a?Object(o.formatJsonRpcResult)(r.id,!0):Object(o.formatJsonRpcError)(r.id,a),{relay:s.relay}),void 0===c||T(c)||await this.sequence.settled.update(c.topic,{acknowledged:!0})}}async onAcknowledge(e){const{topic:t,payload:n}=e;this.sequence.logger.debug(`Receiving ${this.sequence.context} acknowledge`),this.sequence.logger.trace({type:"method",method:"onAcknowledge",topic:t,payload:n});const r=n,i=await this.sequence.pending.get(t);if(!O(i))return;const{outcome:s}=i;Object(o.isJsonRpcError)(r)&&!T(s)&&await this.sequence.settled.delete(s.topic,r.error),void 0===s||T(s)||await this.sequence.settled.update(s.topic,{acknowledged:!0});const a=b.RESPONSE_ACKNOWLEDGED.format({context:this.sequence.name});await this.sequence.pending.delete(t,a)}async onMessage(e){const{topic:t,payload:n}=e;if(this.sequence.logger.debug(`Receiving ${this.sequence.context} message`),this.sequence.logger.trace({type:"method",method:"onMessage",topic:t,payload:n}),Object(o.isJsonRpcRequest)(n)){const t=n,r=await this.sequence.settled.get(e.topic);let i;switch(t.method){case this.sequence.config.jsonrpc.payload:await this.onPayload(e);break;case this.sequence.config.jsonrpc.update:await this.onUpdate(e);break;case this.sequence.config.jsonrpc.upgrade:await this.onUpgrade(e);break;case this.sequence.config.jsonrpc.notification:await this.onNotification(e);break;case this.sequence.config.jsonrpc.delete:await this.sequence.settled.delete(r.topic,t.params.reason);break;case this.sequence.config.jsonrpc.ping:await this.send(r.topic,Object(o.formatJsonRpcResult)(t.id,!0));break;default:i=b.UNKNOWN_JSONRPC_METHOD.format({method:t.method}),this.sequence.logger.error(i.message),await this.send(r.topic,Object(o.formatJsonRpcError)(t.id,i))}}else this.onPayloadEvent(e)}async onPayload(e){const{topic:t,payload:n}=e;if(Object(o.isJsonRpcRequest)(n)){const{id:e,params:r}=n,{chainId:i}=r,s=Object(o.formatJsonRpcRequest)(r.request.method,r.request.params,e),a=await this.sequence.settled.get(t);await this.isJsonRpcAuthorized(t,a.peer,s),await this.sequence.validateRequest({topic:t,request:s,chainId:i});const c={topic:t,payload:s,chainId:i};this.sequence.logger.debug(`Receiving ${this.sequence.context} payload`),this.sequence.logger.trace(Object.assign({type:"method",method:"onPayload"},c)),this.onPayloadEvent(c)}else{const e={topic:t,payload:n};this.sequence.logger.debug(`Receiving ${this.sequence.context} payload`),this.sequence.logger.trace(Object.assign({type:"method",method:"onPayload"},e)),this.onPayloadEvent(e)}}async onUpdate(e){const{topic:t,payload:n}=e;this.sequence.logger.debug(`Receiving ${this.sequence.context} update`),this.sequence.logger.trace({type:"method",method:"onUpdate",topic:t,payload:n});const r=e.payload,i=await this.sequence.settled.get(e.topic);try{const e={publicKey:i.peer.publicKey};await this.handleUpdate(t,r.params,e);const n=Object(o.formatJsonRpcResult)(r.id,!0);await this.send(i.topic,n)}catch(e){this.sequence.logger.error(e);const t=Object(o.formatJsonRpcError)(r.id,e.message);await this.send(i.topic,t)}}async onUpgrade(e){const{topic:t,payload:n}=e;this.sequence.logger.debug(`Receiving ${this.sequence.context} upgrade`),this.sequence.logger.trace({type:"method",method:"onUpgrade",topic:t,payload:n});const r=e.payload,i=await this.sequence.settled.get(e.topic);try{const e={publicKey:i.peer.publicKey};await this.handleUpgrade(t,r.params,e);const n=Object(o.formatJsonRpcResult)(r.id,!0);await this.send(i.topic,n)}catch(e){this.sequence.logger.error(e);const t=Object(o.formatJsonRpcError)(r.id,e.message);await this.send(i.topic,t)}}async onNotification(e){const{params:t}=e.payload,n=e.payload,r=await this.sequence.settled.get(e.topic);try{await this.isNotificationAuthorized(e.topic,r.peer,t.type);const i={topic:e.topic,notification:t},s=this.sequence.config.events.notification;this.sequence.logger.info("Emitting "+s),this.sequence.logger.debug({type:"event",event:s,notificationEvent:i}),this.sequence.events.emit(s,i);const a=Object(o.formatJsonRpcResult)(n.id,!0);await this.send(r.topic,a)}catch(e){this.sequence.logger.error(e);const t=Object(o.formatJsonRpcError)(n.id,e.message);await this.send(r.topic,t)}}async handleUpdate(e,t,n){if(void 0===t.state){const e=b.INVALID_UPDATE_REQUEST.format({context:this.sequence.name});throw this.sequence.logger.error(e.message),new Error(e.message)}const r=await this.sequence.settled.get(e);if(n.publicKey!==r.permissions.controller.publicKey){const e=b.UNAUTHORIZED_UPDATE_REQUEST.format({context:this.sequence.name});throw this.sequence.logger.error(e.message),new Error(e.message)}return r.state=await this.sequence.mergeUpdate(e,t),await this.sequence.settled.update(r.topic,r),t}async handleUpgrade(e,t,n){if(void 0===t.permissions){const e=b.INVALID_UPGRADE_REQUEST.format({context:this.sequence.name});throw this.sequence.logger.error(e.message),new Error(e.message)}const r=await this.sequence.settled.get(e);if(n.publicKey!==r.permissions.controller.publicKey){const e=b.UNAUTHORIZED_UPGRADE_REQUEST.format({context:this.sequence.name});throw this.sequence.logger.error(e.message),new Error(e.message)}return r.permissions=await this.sequence.mergeUpgrade(e,t),await this.sequence.settled.update(r.topic,r),t}async isJsonRpcAuthorized(e,t,n){const r=await this.sequence.settled.get(e);if(t.publicKey!==r.permissions.controller.publicKey&&!r.permissions.jsonrpc.methods.includes(n.method)){const e=b.UNAUTHORIZED_JSON_RPC_METHOD.format({method:n.method});throw this.sequence.logger.error(e.message),new Error(e.message)}}async isNotificationAuthorized(e,t,n){const r=await this.sequence.settled.get(e);if(t.publicKey!==r.permissions.controller.publicKey&&r.self.publicKey!==r.permissions.controller.publicKey&&!r.permissions.notifications.types.includes(n)){const e=b.UNAUTHORIZED_NOTIFICATION_TYPE.format({type:n});throw this.sequence.logger.error(e.message),new Error(e.message)}}async recordPayloadEvent(e){const{topic:t,payload:n,chainId:r}=e;Object(o.isJsonRpcRequest)(n)?await this.sequence.history.set(t,n,r):await this.sequence.history.resolve(n)}async shouldIgnorePayloadEvent(e){const{topic:t,payload:n}=e;if(!this.sequence.settled.sequences.has(t))return!0;let r=!1;try{if(Object(o.isJsonRpcRequest)(n))r=await this.sequence.history.exists(t,n.id);else{let e;try{e=await this.sequence.history.get(t,n.id)}catch(e){}r=void 0!==e&&void 0!==e.response}}catch(e){}return r}async onPayloadEvent(e){const{topic:t,payload:n,chainId:r}=e;if(!await this.shouldIgnorePayloadEvent(e)){if(Object(o.isJsonRpcRequest)(n)){const e={topic:t,request:n,chainId:r},i=this.sequence.config.events.request;this.sequence.logger.info("Emitting "+i),this.sequence.logger.debug({type:"event",event:i,sequence:e}),this.sequence.events.emit(i,e)}else{const e={topic:t,response:n,chainId:r},i=this.sequence.config.events.response;this.sequence.logger.info("Emitting "+i),this.sequence.logger.debug({type:"event",event:i,sequence:e}),this.sequence.events.emit(i,e)}await this.recordPayloadEvent(e)}}async onPendingPayloadEvent(e){if(Object(o.isJsonRpcRequest)(e.payload))switch(e.payload.method){case this.sequence.config.jsonrpc.approve:case this.sequence.config.jsonrpc.reject:this.onResponse(e)}else this.onAcknowledge(e)}async onPendingStatusEvent(e){const{sequence:t}=e;if(R(t.proposal.signal)&&!await this.sequence.client.crypto.hasKeys(t.proposal.topic)){const e=await this.sequence.client.pairing.settled.get(t.proposal.signal.params.topic);await this.sequence.client.crypto.generateSharedKey(e.self,e.peer,t.proposal.topic)}if(O(t)){const n=this.sequence.config.events.responded;if(this.sequence.logger.info("Emitting "+n),this.sequence.logger.debug({type:"event",event:n,sequence:t}),this.sequence.events.emit(n,t),!function(e){return"update"in e}(e)){const{topic:e,outcome:n,relay:r}=t,i=T(n)?this.sequence.config.jsonrpc.reject:this.sequence.config.jsonrpc.approve,s=T(n)?{reason:n.reason}:{relay:n.relay,responder:n.responder,expiry:n.expiry,state:n.state},a=Object(o.formatJsonRpcRequest)(i,s);await this.sequence.client.relayer.publish(e,a,{relay:r})}}else{const e=this.sequence.config.events.proposed;if(this.sequence.logger.info("Emitting "+e),this.sequence.logger.debug({type:"event",event:e,sequence:t}),this.sequence.events.emit(e,t),R(t.proposal.signal)){const e=Object(o.formatJsonRpcRequest)(this.sequence.config.jsonrpc.propose,t.proposal);await this.sequence.client.pairing.send(t.proposal.signal.params.topic,e)}}}async subscribeNewPending(e){const{topic:t,sequence:n}=e,r=Object(f.a)(86400);await this.sequence.client.relayer.subscribe(t,{relay:n.relay}),await this.sequence.expirer.set(t,{topic:t,expiry:r})}async subscribeNewSettled(e){const{topic:t,sequence:n}=e,{expiry:r}=n;await this.sequence.client.relayer.subscribe(t,{relay:n.relay}),await this.sequence.expirer.set(t,{topic:t,expiry:r})}registerEventListeners(){this.sequence.pending.on(be,async e=>{await this.subscribeNewPending(e),await this.onPendingStatusEvent(e)}),this.sequence.pending.on(_e,async e=>await this.onPendingStatusEvent(e)),this.sequence.pending.on(we,async e=>{const{sequence:t}=e;await this.sequence.client.relayer.unsubscribe(t.topic,{relay:t.relay}),await this.sequence.expirer.del(t.topic)}),this.sequence.settled.on(be,async e=>{await this.subscribeNewSettled(e);const{sequence:t}=e,n=this.sequence.config.events.settled;this.sequence.logger.info("Emitting "+n),this.sequence.logger.debug({type:"event",event:n,sequence:t}),this.sequence.events.emit(n,t)}),this.sequence.settled.on(_e,async e=>{const{sequence:t,update:n}=e,r=this.sequence.config.events.updated;this.sequence.logger.info("Emitting "+r),this.sequence.logger.debug({type:"event",event:r,sequence:t,update:n}),this.sequence.events.emit(r,t,n)}),this.sequence.settled.on(we,async e=>{const{sequence:t,reason:n}=e,r=this.sequence.config.events.deleted;this.sequence.logger.info("Emitting "+r),this.sequence.logger.debug({type:"event",event:r,sequence:t,reason:n}),this.sequence.events.emit(r,t,n);const i=Object(o.formatJsonRpcRequest)(this.sequence.config.jsonrpc.delete,{reason:n});await this.sequence.history.delete(t.topic),await this.sequence.client.relayer.publish(t.topic,i,{relay:t.relay}),await this.sequence.client.relayer.unsubscribe(t.topic,{relay:t.relay}),await this.sequence.expirer.del(t.topic)}),this.sequence.settled.on(Oe,()=>this.sequence.events.emit(this.sequence.config.events.sync)),this.sequence.client.relayer.on(oe,e=>{this.sequence.pending.sequences.has(e.topic)?this.onPendingPayloadEvent(e):this.sequence.settled.sequences.has(e.topic)&&this.onMessage(e)}),this.sequence.expirer.on(Ne,async e=>{if(this.sequence.pending.sequences.has(e.topic)){const t=b.EXPIRED.format({context:Object(f.d)(this.sequence.pending.context)});this.sequence.pending.delete(e.topic,t)}else{const t=b.EXPIRED.format({context:Object(f.d)(this.sequence.settled.context)});this.sequence.settled.delete(e.topic,t)}})}}class qe extends h.IExpirer{constructor(e,t){super(e,t),this.client=e,this.logger=t,this.expirations=new Map,this.events=new r.EventEmitter,this.name="expirer",this.cached=[],this.client,this.logger=Object(q.generateChildLogger)(t,this.name),this.registerEventListeners()}get context(){return Object(q.getLoggerContext)(this.logger)}get length(){return this.expirations.size}get topics(){return Array.from(this.expirations.keys())}get values(){return Array.from(this.expirations.values())}async init(){this.logger.trace("Initialized"),await this.initialize()}async has(e){try{return void 0!==this.getExpiration(e)}catch(e){return!1}}async set(e,t){await this.isInitialized(),this.expirations.set(e,t),this.checkExpiry(e,t),this.events.emit(V,{topic:e,expiration:t})}async get(e){return await this.isInitialized(),this.getExpiration(e)}async del(e){await this.isInitialized();const t=this.getExpiration(e);this.expirations.delete(e),this.events.emit(F,{topic:e,expiration:t})}on(e,t){this.events.on(e,t)}once(e,t){this.events.once(e,t)}off(e,t){this.events.off(e,t)}removeListener(e,t){this.events.removeListener(e,t)}async persist(){await this.client.storage.setSequenceStore(this.context,this.values),this.events.emit(W)}async restore(){try{const e=await this.client.storage.getSequenceStore(this.context);if(void 0===e)return;if(!e.length)return;if(this.expirations.size){const e=b.RESTORE_WILL_OVERRIDE.format({context:Object(f.d)(this.context)});throw this.logger.error(e.message),new Error(e.message)}this.cached=e,this.logger.debug("Successfully Restored expirations for "+Object(f.d)(this.context)),this.logger.trace({type:"method",method:"restore",expirations:this.values})}catch(e){this.logger.debug("Failed to Restore expirations for "+Object(f.d)(this.context)),this.logger.error(e)}}async initialize(){await this.restore(),this.reset(),this.onInit()}reset(){this.cached.forEach(e=>this.expirations.set(e.topic,e))}onInit(){this.cached=[],this.events.emit(Y)}async isInitialized(){if(this.cached.length)return new Promise(e=>{this.events.once(Y,()=>e())})}getExpiration(e){const t=this.expirations.get(e);if(!t){const t=b.NO_MATCHING_ID.format({context:Object(f.d)(this.context),topic:e});throw new Error(t.message)}return t}checkExpiry(e,t){const{expiry:n}=t;Object(f.m)(n)-Date.now()<=0&&this.expire(e,t)}expire(e,t){this.expirations.delete(e),this.events.emit(z,{topic:e,expiration:t})}checkExpirations(){this.expirations.forEach((e,t)=>this.checkExpiry(t,e))}registerEventListeners(){this.client.heartbeat.on($,()=>this.checkExpirations()),this.events.on(V,e=>{const t=V;this.logger.info("Emitting "+t),this.logger.debug({type:"event",event:t,data:e}),this.persist()}),this.events.on(z,e=>{const t=z;this.logger.info("Emitting "+t),this.logger.debug({type:"event",event:t,data:e}),this.persist()}),this.events.on(F,e=>{const t=F;this.logger.info("Emitting "+t),this.logger.debug({type:"event",event:t,data:e}),this.persist()})}}class Me extends h.IHeartBeat{constructor(e){super(e),this.events=new r.EventEmitter,this.interval=5,this.name="heartbeat",this.logger=void 0!==(null==e?void 0:e.logger)&&"string"!=typeof(null==e?void 0:e.logger)?Object(q.generateChildLogger)(e.logger,this.name):a()(Object(q.getDefaultLoggerOptions)({level:(null==e?void 0:e.logger)||"error"})),this.interval=(null==e?void 0:e.interval)||5}static async init(e){const t=new Me(e);return await t.init(),t}get context(){return Object(q.getLoggerContext)(this.logger)}async init(){this.logger.trace("Initialized"),await this.initialize()}on(e,t){this.events.on(e,t)}once(e,t){this.events.once(e,t)}off(e,t){this.events.off(e,t)}removeListener(e,t){this.events.removeListener(e,t)}async initialize(){setInterval(()=>this.pulse(),Object(f.m)(this.interval)),this.logger.trace("Initialized")}pulse(){this.events.emit($)}}class He extends h.IJsonRpcHistory{constructor(e,t){super(e,t),this.logger=e,this.storage=t,this.records=new Map,this.events=new r.EventEmitter,this.name="history",this.cached=[],this.logger=Object(q.generateChildLogger)(e,this.name),this.storage=t,this.registerEventListeners()}async init(){this.logger.trace("Initialized"),await this.initialize()}get context(){return Object(q.getLoggerContext)(this.logger)}get size(){return this.records.size}get keys(){return Array.from(this.records.keys())}get values(){return Array.from(this.records.values())}get pending(){const e=[];return this.values.forEach(t=>{if(void 0!==t.response)return;const n={topic:t.topic,request:Object(o.formatJsonRpcRequest)(t.request.method,t.request.params,t.id),chainId:t.chainId};return e.push(n)}),e}async set(e,t,n){if(await this.isInitialized(),this.logger.debug("Setting JSON-RPC request history record"),this.logger.trace({type:"method",method:"set",topic:e,request:t,chainId:n}),this.records.has(t.id))return;const r={id:t.id,topic:e,request:{method:t.method,params:t.params||null},chainId:n};this.records.set(r.id,r),this.events.emit(Q,r)}async resolve(e){if(await this.isInitialized(),this.logger.debug("Updating JSON-RPC response history record"),this.logger.trace({type:"method",method:"update",response:e}),!this.records.has(e.id))return;const t=await this.getRecord(e.id);void 0===t.response&&(t.response=Object(o.isJsonRpcError)(e)?{error:e.error}:{result:e.result},this.records.set(t.id,t),this.events.emit(Z,t))}async get(e,t){await this.isInitialized(),this.logger.debug("Getting record"),this.logger.trace({type:"method",method:"get",topic:e,id:t});const n=await this.getRecord(t);if(n.topic!==e){const e=b.MISMATCHED_TOPIC.format({context:Object(f.d)(this.context),id:t});throw new Error(e.message)}return n}async delete(e,t){await this.isInitialized(),this.logger.debug("Deleting record"),this.logger.trace({type:"method",method:"delete",id:t}),this.values.forEach(n=>{if(n.topic===e){if(void 0!==t&&n.id!==t)return;this.records.delete(n.id),this.events.emit(X,n)}})}async exists(e,t){if(await this.isInitialized(),!this.records.has(t))return!1;return(await this.getRecord(t)).topic===e}on(e,t){this.events.on(e,t)}once(e,t){this.events.once(e,t)}off(e,t){this.events.off(e,t)}removeListener(e,t){this.events.removeListener(e,t)}async getRecord(e){await this.isInitialized();const t=this.records.get(e);if(!t){const t=b.NO_MATCHING_ID.format({context:Object(f.d)(this.context),id:e});throw new Error(t.message)}return t}async persist(){await this.storage.setJsonRpcRecords(this.context,this.values),this.events.emit(te)}async restore(){try{const e=await this.storage.getJsonRpcRecords(this.context);if(void 0===e)return;if(!e.length)return;if(this.records.size){const e=b.RESTORE_WILL_OVERRIDE.format({context:Object(f.d)(this.context)});throw this.logger.error(e.message),new Error(e.message)}this.cached=e,this.logger.debug("Successfully Restored records for "+Object(f.d)(this.context)),this.logger.trace({type:"method",method:"restore",records:this.values})}catch(e){this.logger.debug("Failed to Restore records for "+Object(f.d)(this.context)),this.logger.error(e)}}async initialize(){await this.restore(),this.reset(),this.onInit()}reset(){this.cached.forEach(e=>this.records.set(e.id,e))}onInit(){this.cached=[],this.events.emit(ee)}async isInitialized(){if(this.cached.length)return new Promise(e=>{this.events.once(ee,()=>e())})}registerEventListeners(){this.events.on(Q,e=>{const t=Q;this.logger.info("Emitting "+t),this.logger.debug({type:"event",event:t,record:e}),this.persist()}),this.events.on(Z,e=>{const t=Z;this.logger.info("Emitting "+t),this.logger.debug({type:"event",event:t,record:e}),this.persist()}),this.events.on(X,e=>{const t=X;this.logger.info("Emitting "+t),this.logger.debug({type:"event",event:t,record:e}),this.persist()})}}class Ke extends h.IStore{constructor(e,t,n){super(e,t,n),this.client=e,this.logger=t,this.name=n,this.sequences=new Map,this.events=new r.EventEmitter,this.cached=[],this.logger=Object(q.generateChildLogger)(t,this.name),this.registerEventListeners()}async init(){this.logger.trace("Initialized"),await this.initialize()}get context(){return Object(q.getLoggerContext)(this.logger)}get length(){return this.sequences.size}get topics(){return Array.from(this.sequences.keys())}get values(){return Array.from(this.sequences.values())}async set(e,t){await this.isInitialized(),this.sequences.has(e)?this.update(e,t):(this.logger.debug("Setting sequence"),this.logger.trace({type:"method",method:"set",topic:e,sequence:t}),this.sequences.set(e,t),this.events.emit(be,{topic:e,sequence:t}))}async get(e){await this.isInitialized(),this.logger.debug("Getting sequence"),this.logger.trace({type:"method",method:"get",topic:e});return await this.getSequence(e)}async update(e,t){await this.isInitialized(),this.logger.debug("Updating sequence"),this.logger.trace({type:"method",method:"update",topic:e,update:t});const n=Object.assign(Object.assign({},await this.getSequence(e)),t);this.sequences.set(e,n),this.events.emit(_e,{topic:e,sequence:n,update:t})}async delete(e,t){if(await this.isInitialized(),!this.sequences.has(e))return;this.logger.debug("Deleting sequence"),this.logger.trace({type:"method",method:"delete",topic:e,reason:t});const n=await this.getSequence(e);this.sequences.delete(e),this.events.emit(we,{topic:e,sequence:n,reason:t})}on(e,t){this.events.on(e,t)}once(e,t){this.events.once(e,t)}off(e,t){this.events.off(e,t)}removeListener(e,t){this.events.removeListener(e,t)}async getSequence(e){await this.isInitialized();const t=this.sequences.get(e);if(!t){const t=b.NO_MATCHING_TOPIC.format({context:Object(f.d)(this.context),topic:e});throw this.logger.error(t.message),new Error(t.message)}return t}async persist(){await this.client.storage.setSequenceStore(this.context,this.values),this.events.emit(Oe)}async restore(){try{const e=await this.client.storage.getSequenceStore(this.context);if(void 0===e)return;if(!e.length)return;if(this.sequences.size){const e=b.RESTORE_WILL_OVERRIDE.format({context:Object(f.d)(this.context)});throw this.logger.error(e.message),new Error(e.message)}this.cached=e,this.logger.debug("Successfully Restored sequences for "+Object(f.d)(this.context)),this.logger.trace({type:"method",method:"restore",sequences:this.values})}catch(e){this.logger.debug("Failed to Restore sequences for "+Object(f.d)(this.context)),this.logger.error(e)}}async initialize(){await this.restore(),this.reset(),this.onInit()}reset(){this.cached.forEach(e=>this.sequences.set(e.topic,e))}onInit(){this.cached=[],this.events.emit(Re)}async isInitialized(){if(this.cached.length)return new Promise(e=>{this.events.once(Re,()=>e())})}registerEventListeners(){this.events.on(be,e=>{const t=be;this.logger.info("Emitting "+t),this.logger.debug({type:"event",event:t,data:e}),this.persist()}),this.events.on(_e,e=>{const t=_e;this.logger.info("Emitting "+t),this.logger.debug({type:"event",event:t,data:e}),this.persist()}),this.events.on(we,e=>{const t=we;this.logger.info("Emitting "+t),this.logger.debug({type:"event",event:t,data:e}),this.persist()})}}class Je extends h.IPairing{constructor(e,t){super(e,t),this.client=e,this.logger=t,this.events=new r.EventEmitter,this.name="pairing",this.config={status:re,events:ie,jsonrpc:ne},this.logger=Object(q.generateChildLogger)(t,this.name),this.pending=new Ke(e,this.logger,this.config.status.pending),this.settled=new Ke(e,this.logger,this.config.status.settled),this.history=new He(this.logger,this.client.storage),this.expirer=new qe(e,this.logger),this.engine=new xe(this)}async init(){this.logger.trace("Initialized"),await this.pending.init(),await this.settled.init(),await this.history.init(),await this.expirer.init()}get(e){return this.settled.get(e)}find(e){return this.engine.find(e)}ping(e,t){return this.engine.ping(e,t)}send(e,t){return this.engine.send(e,t)}get context(){return Object(q.getLoggerContext)(this.logger)}get length(){return this.settled.length}get topics(){return this.settled.topics}get values(){return this.settled.values}create(e){return this.engine.create(e)}respond(e){return this.engine.respond(e)}upgrade(e){return this.engine.upgrade(e)}update(e){return this.engine.update(e)}request(e){return this.engine.request(e)}delete(e){return this.engine.delete(e)}notify(e){return this.engine.notify(e)}on(e,t){this.events.on(e,t)}once(e,t){this.events.once(e,t)}off(e,t){this.events.off(e,t)}removeListener(e,t){this.events.removeListener(e,t)}async mergeUpdate(e,t){const n=await this.settled.get(e);return{metadata:t.state.metadata||n.state.metadata}}async mergeUpgrade(e,t){var n,r,i;const o=await this.settled.get(e);return{jsonrpc:{methods:Object(f.k)(o.permissions.jsonrpc.methods,(null===(n=t.permissions.jsonrpc)||void 0===n?void 0:n.methods)||[])},notifications:{types:Object(f.k)((null===(r=o.permissions.notifications)||void 0===r?void 0:r.types)||[],(null===(i=t.permissions.notifications)||void 0===i?void 0:i.types)||[])},controller:o.permissions.controller}}async validateRespond(e){}async validateRequest(e){}async validatePropose(e){}async getDefaultSignal({topic:e,relay:t,proposer:n}){var r;return{method:"uri",params:{uri:`${(r={protocol:this.client.protocol,version:this.client.version,topic:e,publicKey:n.publicKey,controller:n.controller,relay:t}).protocol}:${r.topic}@${r.version}?`+_.stringify({publicKey:r.publicKey,controller:r.controller,relay:Object(w.b)(r.relay)})}}}async getDefaultTTL(){return 2592e3}async getDefaultPermissions(){return{jsonrpc:{methods:[pe.propose]},notifications:{types:[]}}}}var Be=n(75),Ge=n(28),ke=n(25).a;class Ve{constructor(){this.map=new Map}get topics(){return Array.from(this.map.keys())}set(e,t){const n=this.get(e);this.exists(e,t)||this.map.set(e,[...n,t])}get(e){return this.map.get(e)||[]}exists(e,t){return this.get(e).includes(t)}delete(e,t){if(void 0===t)return void this.map.delete(e);if(!this.map.has(e))return;const n=this.get(e);if(!this.exists(e,t))return;const r=n.filter(e=>e!==t);r.length?this.map.set(e,r):this.map.delete(e)}clear(){this.map.clear()}}class Fe extends h.ISubscriber{constructor(e,t){super(e,t),this.relayer=e,this.logger=t,this.subscriptions=new Map,this.topicMap=new Ve,this.events=new r.EventEmitter,this.name="subscription",this.pending=new Map,this.cached=[],this.relayer=e,this.logger=Object(q.generateChildLogger)(t,this.name),this.registerEventListeners()}async init(){this.logger.trace("Initialized"),await this.initialize()}get context(){return Object(q.getLoggerContext)(this.logger)}get length(){return this.subscriptions.size}get ids(){return Array.from(this.subscriptions.keys())}get values(){return Array.from(this.subscriptions.values())}get topics(){return this.topicMap.topics}async subscribe(e,t){this.logger.debug("Subscribing Topic"),this.logger.trace({type:"method",method:"subscribe",params:{topic:e,opts:t}});try{const n=Ze(t),r={topic:e,relay:n};this.pending.set(e,r);const i=await this.rpcSubscribe(e,n);return await this.onSubscribe(i,r),this.logger.debug("Successfully Subscribed Topic"),this.logger.trace({type:"method",method:"subscribe",params:{topic:e,opts:t}}),i}catch(e){throw this.logger.debug("Failed to Subscribe Topic"),this.logger.error(e),e}}async unsubscribe(e,t){void 0!==(null==t?void 0:t.id)?await this.unsubscribeById(e,t.id,t):await this.unsubscribeByTopic(e,t)}on(e,t){this.events.on(e,t)}once(e,t){this.events.once(e,t)}off(e,t){this.events.off(e,t)}removeListener(e,t){this.events.removeListener(e,t)}async enable(){this.cached.length&&this.onEnable()}async disable(){this.cached.length||this.onDisable()}async hasSubscription(e,t){await this.isEnabled();let n=!1;try{n=(await this.getSubscription(e)).topic===t}catch(e){}return n}onEnable(){this.cached=[],this.events.emit(Ae)}onDisable(){this.cached=this.values,this.subscriptions.clear(),this.topicMap.clear(),this.events.emit(Pe)}async unsubscribeByTopic(e,t){const n=this.topicMap.get(e);await Promise.all(n.map(async n=>await this.unsubscribeById(e,n,t)))}async unsubscribeById(e,t,n){this.logger.debug("Unsubscribing Topic"),this.logger.trace({type:"method",method:"unsubscribe",params:{topic:e,id:t,opts:n}});try{const r=Ze(n);await this.rpcUnsubscribe(e,t,r);const i=b.DELETED.format({context:Object(f.d)(this.context)});await this.onUnsubscribe(e,t,i),this.logger.debug("Successfully Unsubscribed Topic"),this.logger.trace({type:"method",method:"unsubscribe",params:{topic:e,id:t,opts:n}})}catch(e){throw this.logger.debug("Failed to Unsubscribe Topic"),this.logger.error(e),e}}async rpcSubscribe(e,t){const n={method:Xe(t.protocol).subscribe,params:{topic:e}};return this.logger.debug("Outgoing Relay Payload"),this.logger.trace({type:"payload",direction:"outgoing",request:n}),this.relayer.provider.request(n)}async rpcUnsubscribe(e,t,n){const r={method:Xe(n.protocol).unsubscribe,params:{topic:e,id:t}};return this.logger.debug("Outgoing Relay Payload"),this.logger.trace({type:"payload",direction:"outgoing",request:r}),this.relayer.provider.request(r)}async onSubscribe(e,t){await this.setSubscription(e,Object.assign(Object.assign({},t),{id:e})),this.pending.delete(t.topic)}async onResubscribe(e,t){await this.addSubscription(e,Object.assign(Object.assign({},t),{id:e})),this.pending.delete(t.topic)}async onUnsubscribe(e,t,n){this.events.removeAllListeners(t),await this.hasSubscription(t,e)&&await this.deleteSubscription(t,n),await this.relayer.history.delete(e)}async setSubscription(e,t){await this.isEnabled(),this.subscriptions.has(e)||(this.logger.debug("Setting subscription"),this.logger.trace({type:"method",method:"setSubscription",id:e,subscription:t}),await this.addSubscription(e,t))}async addSubscription(e,t){this.subscriptions.set(e,Object.assign({},t)),this.topicMap.set(t.topic,e),this.events.emit(Se,t)}async getSubscription(e){await this.isEnabled(),this.logger.debug("Getting subscription"),this.logger.trace({type:"method",method:"getSubscription",id:e});const t=this.subscriptions.get(e);if(!t){const t=b.NO_MATCHING_ID.format({context:Object(f.d)(this.context),id:e});throw new Error(t.message)}return t}async deleteSubscription(e,t){await this.isEnabled(),this.logger.debug("Deleting subscription"),this.logger.trace({type:"method",method:"deleteSubscription",id:e,reason:t});const n=await this.getSubscription(e);this.subscriptions.delete(e),this.topicMap.delete(n.topic,e),this.events.emit(Ie,Object.assign(Object.assign({},n),{reason:t}))}async persist(){await this.relayer.storage.setRelayerSubscriptions(this.context,this.values),this.events.emit(Ue)}async restore(){try{const e=await this.relayer.storage.getRelayerSubscriptions(this.context);if(void 0===e)return;if(!e.length)return;if(this.subscriptions.size){const e=b.RESTORE_WILL_OVERRIDE.format({context:Object(f.d)(this.context)});throw this.logger.error(e.message),new Error(e.message)}this.cached=e,this.logger.debug("Successfully Restored subscriptions for "+Object(f.d)(this.context)),this.logger.trace({type:"method",method:"restore",subscriptions:this.values})}catch(e){this.logger.debug("Failed to Restore subscriptions for "+Object(f.d)(this.context)),this.logger.error(e)}}async initialize(){await this.restore(),await this.reset(),await this.enable()}async isEnabled(){if(this.cached.length)return new Promise(e=>{this.events.once(Ae,()=>e())})}async reset(){this.cached.length&&await Promise.all(this.cached.map(async e=>this.resubscribe(e)))}async resubscribe(e){const{topic:t,relay:n}=e,r={topic:t,relay:n};this.pending.set(r.topic,r);const i=await this.rpcSubscribe(r.topic,r.relay);if(await this.onResubscribe(i,r),this.ids.includes(e.id)){const t=b.RESUBSCRIBED.format({topic:e.topic});await this.deleteSubscription(e.id,t)}}async onConnect(){await this.reset(),await this.enable()}async onDisconnect(){await this.disable()}checkPending(){this.pending.forEach(async e=>{const t=await this.rpcSubscribe(e.topic,e.relay);await this.onSubscribe(t,e)})}registerEventListeners(){this.relayer.heartbeat.on($,()=>{this.checkPending()}),this.relayer.provider.on(he,async()=>{await this.onConnect()}),this.relayer.provider.on(le,async()=>{await this.onDisconnect()}),this.events.on(Se,async e=>{const t=Se;this.logger.info("Emitting "+t),this.logger.debug({type:"event",event:t,data:e}),await this.persist()}),this.events.on(Ie,async e=>{const t=Ie;this.logger.info("Emitting "+t),this.logger.debug({type:"event",event:t,data:e}),await this.persist()})}}class ze extends class{constructor(e,t,n){this.logger=e,this.keyValueStorage=t,this.config=n,this.name="storage",this.version="0.2",this.keyMap=Te,this.logger=Object(q.generateChildLogger)(e,this.name),this.keyValueStorage=t,this.config=n}get context(){return Object(q.getLoggerContext)(this.logger)}get prefix(){return`${this.config.protocol}@${this.config.version}:${this.config.context}:${this.version}`}getStorageKey(e){const t=this.getStorageKeyName(e);if(!this.isValidStorageKeyName(t)){const e=b.INVALID_STORAGE_KEY_NAME.format({name:t});throw new Error(e.message)}return this.prefix+"//"+t}getStorageKeyName(e){return Object(f.f)(e)}isValidStorageKeyName(e){return Object.keys(this.keyMap).map(e=>Object.values(this.keyMap[e])).flat().includes(e.toLowerCase())}}{constructor(e,t,n){super(e,t,n),this.logger=e,this.keyValueStorage=t,this.config=n}async setJsonRpcRecords(e,t){const n=this.getStorageKey(e);await this.keyValueStorage.setItem(n,t)}async getJsonRpcRecords(e){const t=this.getStorageKey(e);return await this.keyValueStorage.getItem(t)}async setRelayerSubscriptions(e,t){const n=this.getStorageKey(e);await this.keyValueStorage.setItem(n,t)}async getRelayerSubscriptions(e){const t=this.getStorageKey(e);return await this.keyValueStorage.getItem(t)}}class Ye extends ze{constructor(e,t,n){super(e,t,n),this.logger=e,this.keyValueStorage=t,this.config=n}async setKeyChain(e,t){const n=this.getStorageKey(e);await this.keyValueStorage.setItem(n,Object(f.j)(t))}async getKeyChain(e){const t=this.getStorageKey(e),n=await this.keyValueStorage.getItem(t);return void 0!==n?Object(f.l)(n):void 0}async setSequenceStore(e,t){const n=this.getStorageKey(e);await this.keyValueStorage.setItem(n,t)}async getSequenceStore(e){const t=this.getStorageKey(e);return await this.keyValueStorage.getItem(t)}async setExpirations(e,t){const n=this.getStorageKey(e);await this.keyValueStorage.setItem(n,t)}async getExpirations(e){const t=this.getStorageKey(e);return await this.keyValueStorage.getItem(t)}}class We extends i.IEvents{constructor(e,t){super(),this.relayer=e,this.logger=t}}class $e extends We{constructor(e,t){super(e,t),this.relayer=e,this.logger=t,this.events=new r.EventEmitter,this.name="publisher",this.queue=new Map,this.relayer=e,this.logger=Object(q.generateChildLogger)(t,this.name),this.registerEventListeners()}get context(){return Object(q.getLoggerContext)(this.logger)}async init(){this.logger.trace("Initialized"),await this.initialize()}async publish(e,t,n){this.logger.debug("Publishing Payload"),this.logger.trace({type:"method",method:"publish",params:{topic:e,payload:t,opts:n}});try{const r=(null==n?void 0:n.ttl)||21600,i=Ze(n),o={topic:e,payload:t,opts:{ttl:r,relay:i}};this.queue.set(t.id,o);const s=await this.relayer.encoder.encode(e,t);await this.rpcPublish(e,s,r,i),await this.onPublish(t.id,o),this.logger.debug("Successfully Published Payload"),this.logger.trace({type:"method",method:"publish",params:{topic:e,payload:t,opts:n}})}catch(e){throw this.logger.debug("Failed to Publish Payload"),this.logger.error(e),e}}on(e,t){this.events.on(e,t)}once(e,t){this.events.once(e,t)}off(e,t){this.events.off(e,t)}removeListener(e,t){this.events.removeListener(e,t)}async initialize(){}async rpcPublish(e,t,n,r){const i={method:Xe(r.protocol).publish,params:{topic:e,message:t,ttl:n}};return this.logger.debug("Outgoing Relay Payload"),this.logger.trace({type:"payload",direction:"outgoing",request:i}),this.relayer.provider.request(i)}async onPublish(e,t){this.queue.delete(e)}checkQueue(){this.queue.forEach(async e=>{const{topic:t,payload:n,opts:{ttl:r,relay:i}}=e,o=await this.relayer.encoder.encode(t,n);await this.rpcPublish(t,o,r,i),await this.onPublish(n.id,e)})}registerEventListeners(){this.relayer.heartbeat.on($,()=>{this.checkQueue()})}}class Qe extends h.IRelayer{constructor(e){super(e),this.protocol="irn",this.version=1,this.events=new r.EventEmitter,this.name="relayer",this.logger=void 0!==(null==e?void 0:e.logger)&&"string"!=typeof(null==e?void 0:e.logger)?Object(q.generateChildLogger)(e.logger,this.name):a()(Object(q.getDefaultLoggerOptions)({level:(null==e?void 0:e.logger)||"error"}));const t=(null==e?void 0:e.keyValueStorage)||new u.a(fe);this.storage=void 0!==(null==e?void 0:e.storage)?e.storage:new ze(this.logger,t,{protocol:this.protocol,version:this.version,context:this.context}),this.heartbeat=(null==e?void 0:e.heartbeat)||new Me({logger:this.logger}),this.encoder=(null==e?void 0:e.encoder)||new je;const n=Object(f.e)(this.protocol,this.version,(null==e?void 0:e.relayUrl)||"wss://relay.walletconnect.com",null==e?void 0:e.projectId);this.provider=new Ge.JsonRpcProvider(new ke(n)),this.history=new He(this.logger,this.storage),this.subscriber=new Fe(this,this.logger),this.publisher=new $e(this,this.logger),this.registerEventListeners()}get context(){return Object(q.getLoggerContext)(this.logger)}get connected(){return this.provider.connection.connected}get connecting(){return this.provider.connection.connecting}async init(){this.logger.trace("Initialized"),await this.history.init(),await this.provider.connect(),await this.subscriber.init(),await this.publisher.init()}async publish(e,t,n){await this.publisher.publish(e,t,n),await this.recordPayloadEvent({topic:e,payload:t})}async subscribe(e,t){return await this.subscriber.subscribe(e,t)}async unsubscribe(e,t){await this.subscriber.unsubscribe(e,t)}on(e,t){this.events.on(e,t)}once(e,t){this.events.once(e,t)}off(e,t){this.events.off(e,t)}removeListener(e,t){this.events.removeListener(e,t)}async recordPayloadEvent(e){const{topic:t,payload:n}=e;Object(o.isJsonRpcRequest)(n)?await this.history.set(t,n):await this.history.resolve(n)}async shouldIgnorePayloadEvent(e){const{topic:t,payload:n}=e;if(!this.subscriber.topics.includes(t))return!0;let r=!1;try{if(Object(o.isJsonRpcRequest)(n))r=await this.history.exists(t,n.id);else{let e;try{e=await this.history.get(t,n.id)}catch(e){}r=void 0!==e&&void 0!==e.response}}catch(e){}return r}async onPayload(e){if(this.logger.debug("Incoming Relay Payload"),this.logger.trace({type:"payload",direction:"incoming",payload:e}),Object(o.isJsonRpcRequest)(e)){if(!e.method.endsWith("_subscription"))return;const t=e.params,{topic:n,message:r}=t.data,i={topic:n,payload:await this.encoder.decode(n,r)};if(await this.shouldIgnorePayloadEvent(i))return;this.logger.debug("Emitting Relayer Payload"),this.logger.trace(Object.assign({type:"event",event:t.id},i)),this.events.emit(t.id,i),this.events.emit(oe,i),await this.acknowledgePayload(e),await this.recordPayloadEvent(i)}}async acknowledgePayload(e){const t=Object(o.formatJsonRpcResult)(e.id,!0);await this.provider.connection.send(t)}registerEventListeners(){this.provider.on(ue,e=>this.onPayload(e)),this.provider.on(he,async()=>{this.events.emit(se)}),this.provider.on(le,async()=>{this.events.emit(ae),setTimeout(()=>{this.provider.connect()},1)}),this.provider.on(de,e=>this.events.emit(ce,e))}}function Ze(e){return(null==e?void 0:e.relay)||{protocol:"waku"}}function Xe(e){const t=Be.RELAY_JSONRPC[e];if(void 0===t)throw new Error("Relay Protocol not supported: "+e);return t}class et extends h.ISession{constructor(e,t){super(e,t),this.client=e,this.logger=t,this.events=new r.EventEmitter,this.name="session",this.config={status:ge,events:ye,jsonrpc:pe},this.logger=Object(q.generateChildLogger)(t,this.name),this.pending=new Ke(e,this.logger,this.config.status.pending),this.settled=new Ke(e,this.logger,this.config.status.settled),this.history=new He(this.logger,this.client.storage),this.expirer=new qe(e,this.logger),this.engine=new xe(this)}async init(){this.logger.trace("Initialized"),await this.pending.init(),await this.settled.init(),await this.history.init(),await this.expirer.init()}get(e){return this.settled.get(e)}find(e){return this.engine.find(e)}ping(e,t){return this.engine.ping(e,t)}send(e,t,n){return this.engine.send(e,t,n)}get context(){return Object(q.getLoggerContext)(this.logger)}get length(){return this.settled.length}get topics(){return this.settled.topics}get values(){return this.settled.values}create(e){return this.engine.create(e)}respond(e){return this.engine.respond(e)}upgrade(e){return this.engine.upgrade(e)}update(e){return this.engine.update(e)}request(e){return this.engine.request(e)}delete(e){return this.engine.delete(e)}notify(e){return this.engine.notify(e)}on(e,t){this.events.on(e,t)}once(e,t){this.events.once(e,t)}off(e,t){this.events.off(e,t)}removeListener(e,t){this.events.removeListener(e,t)}async mergeUpdate(e,t){var n;const r=await this.settled.get(e);return{accounts:(null===(n=t.state)||void 0===n?void 0:n.accounts)||r.state.accounts}}async mergeUpgrade(e,t){var n,r,i,o,s;const a=await this.settled.get(e);return{jsonrpc:{methods:Object(f.k)(a.permissions.jsonrpc.methods,(null===(n=t.permissions.jsonrpc)||void 0===n?void 0:n.methods)||[])},notifications:{types:Object(f.k)((null===(r=a.permissions.notifications)||void 0===r?void 0:r.types)||[],(null===(i=t.permissions.notifications)||void 0===i?void 0:i.types)||[])},blockchain:{chains:Object(f.k)((null===(o=a.permissions.blockchain)||void 0===o?void 0:o.chains)||[],(null===(s=t.permissions.blockchain)||void 0===s?void 0:s.chains)||[])},controller:a.permissions.controller}}async validateRespond(e){if(void 0===e){const e=b.MISSING_OR_INVALID.format({name:"respond params"});throw this.logger.error(e.message),new Error(e.message)}const t=A(e);if(j(t))throw this.logger.error(t.error.message),new Error(t.error.message)}async validateRequest(e){if(void 0===e){const e=b.MISSING_OR_INVALID.format({name:"request params"});throw this.logger.error(e.message),new Error(e.message)}const{topic:t,chainId:n}=e,r=await this.settled.get(t);if(n&&!r.permissions.blockchain.chains.includes(n)){const e=b.UNAUTHORIZED_TARGET_CHAIN.format({chainId:n});throw this.logger.error(e.message),new Error(e.message)}}async validatePropose(e){if(void 0===e){const e=b.MISSING_OR_INVALID.format({name:"propose params"});throw this.logger.error(e.message),new Error(e.message)}const t=function(e){const t=I(e.permissions);if(j(t))return t;const n=N(e.metadata);return j(n)?n:{valid:!0}}(e);if(j(t))throw this.logger.error(t.error.message),new Error(t.error.message);if("pairing"!==e.signal.method){const e=b.UNSUPPORTED_SIGNAL.format({context:this.context});throw this.logger.error(e.message),new Error(e.message)}}async getDefaultSignal(e){return{method:"pairing",params:{topic:(await this.client.pairing.settled.get(e.topic)).topic}}}async getDefaultTTL(){return 604800}async getDefaultPermissions(){return{jsonrpc:{methods:[]},notifications:{types:[]},blockchain:{chains:[]}}}}class tt extends h.IClient{constructor(e){super(e),this.protocol="wc",this.version=2,this.events=new r.EventEmitter,this.name="client";const t=void 0!==(null==e?void 0:e.logger)&&"string"!=typeof(null==e?void 0:e.logger)?e.logger:a()(Object(q.getDefaultLoggerOptions)({level:(null==e?void 0:e.logger)||H}));this.name=(null==e?void 0:e.name)||M,this.controller=(null==e?void 0:e.controller)||K,this.metadata=(null==e?void 0:e.metadata)||Object(f.h)(),this.projectId=null==e?void 0:e.projectId,this.logger=Object(q.generateChildLogger)(t,this.name),this.heartbeat=new Me({logger:this.logger}),this.crypto=new De(this,this.logger,null==e?void 0:e.keychain),this.encoder=new Le(this,this.logger);const n=(null==e?void 0:e.storage)||new u.a(Object.assign(Object.assign({},k),null==e?void 0:e.storageOptions));this.storage=new Ye(this.logger,n,{protocol:this.protocol,version:this.version,context:this.context});const i=Object(f.e)(this.protocol,this.version,(null==e?void 0:e.relayUrl)||J,this.projectId);this.relayer=new Qe({relayUrl:i,heartbeat:this.heartbeat,encoder:this.encoder,logger:this.logger,storage:this.storage}),this.pairing=new Je(this,this.logger),this.session=new et(this,this.logger)}static async init(e){const t=new tt(e);return await t.initialize(),t}get context(){return Object(q.getLoggerContext)(this.logger)}on(e,t){this.events.on(e,t)}once(e,t){this.events.once(e,t)}off(e,t){this.events.off(e,t)}removeListener(e,t){this.events.removeListener(e,t)}async connect(e){this.logger.debug("Connecting Application"),this.logger.trace({type:"method",method:"connect",params:e});try{void 0===typeof e.pairing&&this.logger.info("Connecing with existing pairing");const t=void 0===e.pairing?await this.pairing.create():await this.pairing.get(e.pairing.topic);this.logger.trace({type:"method",method:"connect",pairing:t});const n=e.metadata||this.metadata;if(void 0===n){const e=b.MISSING_OR_INVALID.format({name:"app metadata"});throw this.logger.error(e.message),new Error(e.message)}const r=await this.session.create({signal:{method:"pairing",params:{topic:t.topic}},relay:e.relay||{protocol:"waku"},metadata:n,permissions:Object.assign(Object.assign({},e.permissions),{notifications:ve.notifications})});return this.logger.debug("Application Connection Successful"),this.logger.trace({type:"method",method:"connect",session:r}),r}catch(e){throw this.logger.debug("Application Connection Failure"),this.logger.error(e),e}}async pair(e){this.logger.debug("Pairing"),this.logger.trace({type:"method",method:"pair",params:e});const t=function(e){const t=function(e){const t=e.indexOf(":"),n=-1!==e.indexOf("?")?e.indexOf("?"):void 0,r=e.substring(0,t),i=e.substring(t+1,n).split("@"),o=void 0!==n?e.substr(n):"",s=_.parse(o);return{protocol:r,topic:i[0],version:parseInt(i[1],10),publicKey:s.publicKey,controller:"true"===s.controller,relay:Object(w.a)(s.relay)}}(e);return{topic:t.topic,relay:t.relay,proposer:{publicKey:t.publicKey,controller:t.controller},signal:{method:"uri",params:{uri:e}},permissions:{jsonrpc:{methods:[pe.propose]},notifications:{types:[]}},ttl:2592e3}}(e.uri),n=t.proposer.controller!==this.controller,r=n?void 0:b.UNAUTHORIZED_MATCHING_CONTROLLER.format({controller:this.controller}),i=await this.pairing.respond({approved:n,proposal:t,reason:r});if(!function(e){return S(e.status)&&"outcome"in e}(i)){const e=b.NO_MATCHING_RESPONSE.format({context:"pairing"});throw this.logger.error(e.message),new Error(e.message)}if("reason"in i.outcome)throw this.logger.debug("Pairing Failure"),this.logger.trace({type:"method",method:"pair",outcome:i.outcome}),new Error(i.outcome.reason.message);this.logger.debug("Pairing Success"),this.logger.trace({type:"method",method:"pair",pending:i});return await this.pairing.get(i.outcome.topic)}async approve(e){if(this.logger.debug("Approving Session Proposal"),this.logger.trace({type:"method",method:"approve",params:e}),void 0===e.response){const e=b.MISSING_RESPONSE.format({context:"session"});throw this.logger.error(e.message),new Error(e.message)}const t=e.response.state||me,n=e.response.metadata||this.metadata;if(void 0===n){const e=b.MISSING_OR_INVALID.format({name:"app metadata"});throw this.logger.error(e.message),new Error(e.message)}const r=e.proposal.proposer.controller!==this.controller,i=r?void 0:b.UNAUTHORIZED_MATCHING_CONTROLLER.format({controller:this.controller}),o=await this.session.respond({approved:r,proposal:e.proposal,response:{state:t,metadata:n},reason:i});if(!function(e){return S(e.status)&&"outcome"in e}(o)){const e=b.NO_MATCHING_RESPONSE.format({context:"session"});throw this.logger.error(e.message),new Error(e.message)}if("reason"in o.outcome)throw this.logger.debug("Session Proposal Approval Failure"),this.logger.trace({type:"method",method:"approve",outcome:o.outcome}),new Error(o.outcome.reason.message);return this.logger.debug("Session Proposal Approval Success"),this.logger.trace({type:"method",method:"approve",pending:o}),this.session.get(o.outcome.topic)}async reject(e){this.logger.debug("Rejecting Session Proposal"),this.logger.trace({type:"method",method:"reject",params:e});const t=await this.session.respond({approved:!1,proposal:e.proposal,response:Ee,reason:e.reason});this.logger.debug("Session Proposal Response Success"),this.logger.trace({type:"method",method:"reject",pending:t})}async upgrade(e){await this.session.upgrade(e)}async update(e){await this.session.update(e)}async request(e){return this.session.request(e)}async respond(e){await this.session.send(e.topic,e.response)}async ping(e){await this.session.ping(e.topic,e.timeout)}async notify(e){await this.session.notify(e)}async disconnect(e){this.logger.debug("Disconnecting Application"),this.logger.trace({type:"method",method:"disconnect",params:e}),await this.session.delete(e)}async onPairingRequest(e,t){if(e.method===pe.propose){const n=e.params;if(n.proposer.controller===this.controller){const e=b.UNAUTHORIZED_MATCHING_CONTROLLER.format({controller:this.controller});return void await this.session.respond({approved:!1,proposal:n,response:Ee,reason:e})}const r=G.proposal;this.logger.info("Emitting "+r),this.logger.debug({type:"event",event:r,data:n}),this.events.emit(r,n);const i=Object(o.formatJsonRpcResult)(e.id,!0);await this.pairing.send(t,i)}}async onPairingSettled(e){e.permissions.controller.publicKey===e.self.publicKey&&void 0===e.state.metadata&&setTimeout(async()=>await this.pairing.update({topic:e.topic,state:{metadata:this.metadata}}),50)}async initialize(){this.logger.trace("Initialized");try{await this.pairing.init(),await this.session.init(),await this.crypto.init(),await this.relayer.init(),await this.heartbeat.init(),this.registerEventListeners(),this.logger.info("Client Initilization Success")}catch(e){throw this.logger.info("Client Initilization Failure"),this.logger.error(e),e}}registerEventListeners(){this.pairing.on(ie.proposed,e=>{const t=B.proposal;this.logger.info("Emitting "+t),this.logger.debug({type:"event",event:t,data:e.proposal}),this.events.emit(t,e.proposal)}),this.pairing.on(ie.settled,e=>{const t=B.created;this.logger.info("Emitting "+t),this.logger.debug({type:"event",event:t,data:e}),this.events.emit(t,e),this.onPairingSettled(e)}),this.pairing.on(ie.updated,(e,t)=>{const n=B.updated;this.logger.info("Emitting "+n),this.logger.debug({type:"event",event:n,data:e,update:t}),this.events.emit(n,e,t)}),this.pairing.on(ie.deleted,(e,t)=>{const n=B.deleted;this.logger.info("Emitting "+n),this.logger.debug({type:"event",event:n,data:e,reason:t}),this.events.emit(n,e,t)}),this.pairing.on(ie.request,e=>{this.onPairingRequest(e.request,e.topic)}),this.session.on(ie.sync,()=>this.events.emit(B.sync)),this.session.on(ye.proposed,e=>{const t=G.proposal;this.logger.info("Emitting "+t),this.logger.debug({type:"event",event:t,data:e.proposal}),this.events.emit(t,e.proposal)}),this.session.on(ye.settled,e=>{const t=G.created;this.logger.info("Emitting "+t),this.logger.debug({type:"event",event:t,data:e}),this.events.emit(t,e)}),this.session.on(ye.updated,(e,t)=>{const n=G.updated;this.logger.info("Emitting "+n),this.logger.debug({type:"event",event:n,data:e,update:t}),this.events.emit(n,e,t)}),this.session.on(ye.deleted,(e,t)=>{const n=G.deleted;this.logger.info("Emitting "+n),this.logger.debug({type:"event",event:n,data:e,reason:t}),this.events.emit(n,e,t)}),this.session.on(ye.request,e=>{const t=G.request;this.logger.info("Emitting "+t),this.logger.debug({type:"event",event:t,data:e}),this.events.emit(t,e)}),this.session.on(ye.response,e=>{const t=G.response;this.logger.info("Emitting "+t),this.logger.debug({type:"event",event:t,data:e}),this.events.emit(t,e)}),this.session.on(ye.notification,e=>{const t=G.notification;this.logger.info("Emitting "+t),this.logger.debug({type:"event",event:t,data:e}),this.events.emit(t,e)}),this.session.on(ye.sync,()=>this.events.emit(G.sync))}}const nt=tt;const rt={init:"signer_init",uri:"signer_uri",created:"signer_created",updated:"signer_updated",deleted:"signer_deleted",notification:"signer_notification"};class it extends i.IJsonRpcConnection{constructor(e){super(),this.events=new r.EventEmitter,this.pending=!1,this.initializing=!1,this.chains=(null==e?void 0:e.chains)||[],this.methods=(null==e?void 0:e.methods)||[],this.opts=null==e?void 0:e.client}get connected(){return void 0!==this.session}get connecting(){return this.pending}get accounts(){var e;return(null===(e=this.session)||void 0===e?void 0:e.state.accounts)||[]}on(e,t){this.events.on(e,t)}once(e,t){this.events.once(e,t)}off(e,t){this.events.off(e,t)}removeListener(e,t){this.events.removeListener(e,t)}async open(){if(this.pending)return new Promise((e,t)=>{this.events.once("open",()=>{if(this.events.once("open_error",e=>{t(e)}),void 0===this.client)return t(new Error("Client not initialized"));e()})});try{this.pending=!0;const e=await this.register(),t=await e.session.find({blockchain:{chains:this.chains},jsonrpc:{methods:this.methods}});if(t.length)return this.onOpen(t[0]);this.session=await e.connect({permissions:{blockchain:{chains:this.chains},jsonrpc:{methods:this.methods}}}),this.onOpen()}catch(e){throw this.events.emit("open_error",e),e}}async close(){if(void 0===this.session)return;const e=await this.register();await e.disconnect({topic:this.session.topic,reason:b.USER_DISCONNECTED.format()}),this.onClose()}async send(e,t){if(void 0===this.client&&(this.client=await this.register(),this.connected||await this.open()),void 0===this.session)throw new Error("Signer connection is missing session");this.client.request({topic:this.session.topic,request:e,chainId:null==t?void 0:t.chainId}).then(t=>this.events.emit("payload",Object(o.formatJsonRpcResult)(e.id,t))).catch(t=>this.events.emit("payload",Object(o.formatJsonRpcError)(e.id,t.message)))}async register(e=this.opts){if(void 0!==this.client)return this.client;if(this.initializing)return new Promise((e,t)=>{this.events.once("register_error",e=>{t(e)}),this.events.once(rt.init,()=>{if(void 0===this.client)return t(new Error("Client not initialized"));e(this.client)})});if(function(e){return void 0!==e&&void 0!==e.context}(e))return this.client=e,this.registerEventListeners(),this.client;try{return this.initializing=!0,this.client=await nt.init(e),this.initializing=!1,this.registerEventListeners(),this.events.emit(rt.init),this.client}catch(e){throw this.events.emit("register_error",e),e}}onOpen(e){this.pending=!1,e&&(this.session=e),this.events.emit("open")}onClose(){this.pending=!1,this.client&&(this.client=void 0),this.events.emit("close")}registerEventListeners(){void 0!==this.client&&(this.client.on(G.created,e=>{var t;this.session&&(null===(t=this.session)||void 0===t?void 0:t.topic)!==e.topic||(this.session=e,this.events.emit(rt.created,e))}),this.client.on(G.updated,e=>{var t;this.session&&(null===(t=this.session)||void 0===t?void 0:t.topic)!==e.topic||(this.session=e,this.events.emit(rt.updated,e))}),this.client.on(G.notification,e=>{var t;this.session&&(null===(t=this.session)||void 0===t?void 0:t.topic)!==e.topic||this.events.emit(rt.notification,e.notification)}),this.client.on(G.deleted,e=>{var t;this.session&&(this.session&&(null===(t=this.session)||void 0===t?void 0:t.topic)!==e.topic||(this.onClose(),this.events.emit(rt.deleted,e),this.session=void 0))}),this.client.on(B.proposal,async e=>{const t=e.signal.params.uri;this.events.emit(rt.uri,{uri:t})}))}}t.default=it},function(e,t,n){"use strict";n.r(t),n.d(t,"HttpConnection",(function(){return u}));var r=n(3),i=n(29),o=n.n(i),s=n(8),a=n(0);const c={headers:{Accept:"application/json","Content-Type":"application/json"},method:"POST"};class u{constructor(e){if(this.url=e,this.events=new r.EventEmitter,this.isAvailable=!1,this.registering=!1,!Object(a.isHttpUrl)(e))throw new Error("Provided URL is not compatible with HTTP connection: "+e);this.url=e}get connected(){return this.isAvailable}get connecting(){return this.registering}on(e,t){this.events.on(e,t)}once(e,t){this.events.once(e,t)}off(e,t){this.events.off(e,t)}removeListener(e,t){this.events.removeListener(e,t)}async open(e=this.url){await this.register(e)}async close(){if(!this.isAvailable)throw new Error("Connection already closed");this.onClose()}async send(e,t){this.isAvailable||await this.register();try{const t=Object(s.b)(e),n=await o()(this.url,Object.assign(Object.assign({},c),{body:t})),r=await n.json();this.onPayload({data:r})}catch(t){this.onError(e.id,t)}}async register(e=this.url){if(!Object(a.isHttpUrl)(e))throw new Error("Provided URL is not compatible with HTTP connection: "+e);if(this.registering)return new Promise((e,t)=>{this.events.once("register_error",e=>{t(e)}),this.events.once("open",()=>{if(void 0===this.isAvailable)return t(new Error("HTTP connection is missing or invalid"));e()})});this.url=e,this.registering=!0;try{const t=Object(s.b)({id:1,jsonrpc:"2.0",method:"test",params:[]});await o()(e,Object.assign(Object.assign({},c),{body:t})),this.onOpen()}catch(e){const t=this.parseError(e);throw this.events.emit("register_error",t),this.onClose(),t}}onOpen(){this.isAvailable=!0,this.registering=!1,this.events.emit("open")}onClose(){this.isAvailable=!1,this.registering=!1,this.events.emit("close")}onPayload(e){if(void 0===e.data)return;const t="string"==typeof e.data?Object(s.a)(e.data):e.data;this.events.emit("payload",t)}onError(e,t){const n=this.parseError(t),r=n.message||n.toString(),i=Object(a.formatJsonRpcError)(e,r);this.events.emit("payload",i)}parseError(e,t=this.url){return Object(a.parseConnectionError)(e,t,"HTTP")}}var h=u;t.default=h}])}));
|
|
25
|
+
t.read=function(e,t,n,r,i){var o,s,a=8*i-r-1,c=(1<<a)-1,u=c>>1,h=-7,l=n?i-1:0,d=n?-1:1,f=e[t+l];for(l+=d,o=f&(1<<-h)-1,f>>=-h,h+=a;h>0;o=256*o+e[t+l],l+=d,h-=8);for(s=o&(1<<-h)-1,o>>=-h,h+=r;h>0;s=256*s+e[t+l],l+=d,h-=8);if(0===o)o=1-u;else{if(o===c)return s?NaN:1/0*(f?-1:1);s+=Math.pow(2,r),o-=u}return(f?-1:1)*s*Math.pow(2,o-r)},t.write=function(e,t,n,r,i,o){var s,a,c,u=8*o-i-1,h=(1<<u)-1,l=h>>1,d=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,f=r?0:o-1,p=r?1:-1,g=t<0||0===t&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(a=isNaN(t)?1:0,s=h):(s=Math.floor(Math.log(t)/Math.LN2),t*(c=Math.pow(2,-s))<1&&(s--,c*=2),(t+=s+l>=1?d/c:d*Math.pow(2,1-l))*c>=2&&(s++,c/=2),s+l>=h?(a=0,s=h):s+l>=1?(a=(t*c-1)*Math.pow(2,i),s+=l):(a=t*Math.pow(2,l-1)*Math.pow(2,i),s=0));i>=8;e[n+f]=255&a,f+=p,a/=256,i-=8);for(s=s<<i|a,u+=i;u>0;e[n+f]=255&s,f+=p,s/=256,u-=8);e[n+f-p]|=128*g}},function(e,t){var n={}.toString;e.exports=Array.isArray||function(e){return"[object Array]"==n.call(e)}},function(e,t,n){(function(t){var r=n(68).strict;e.exports=function(e){if(r(e)){var n=t.from(e.buffer);return e.byteLength!==e.buffer.byteLength&&(n=n.slice(e.byteOffset,e.byteOffset+e.byteLength)),n}return t.from(e)}}).call(this,n(67).Buffer)},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(91),i=n(95),o=n(27);function s(e,n){return void 0===n&&(n=t.defaultRandomSource),n.randomBytes(e)}t.defaultRandomSource=new r.SystemRandomSource,t.randomBytes=s,t.randomUint32=function(e){void 0===e&&(e=t.defaultRandomSource);var n=s(4,e),r=i.readUint32LE(n);return o.wipe(n),r};var a="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";function c(e,n,r){if(void 0===n&&(n=a),void 0===r&&(r=t.defaultRandomSource),n.length<2)throw new Error("randomString charset is too short");if(n.length>256)throw new Error("randomString charset is too long");for(var i="",c=n.length,u=256-256%c;e>0;){for(var h=s(Math.ceil(256*e/u),r),l=0;l<h.length&&e>0;l++){var d=h[l];d<u&&(i+=n.charAt(d%c),e--)}o.wipe(h)}return i}t.randomString=c,t.randomStringForEntropy=function(e,n,r){return void 0===n&&(n=a),void 0===r&&(r=t.defaultRandomSource),c(Math.ceil(e/(Math.log(n.length)/Math.LN2)),n,r)}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(92),i=n(93),o=function(){function e(){return this.isAvailable=!1,this.name="",this._source=new r.BrowserRandomSource,this._source.isAvailable?(this.isAvailable=!0,void(this.name="Browser")):(this._source=new i.NodeRandomSource,this._source.isAvailable?(this.isAvailable=!0,void(this.name="Node")):void 0)}return e.prototype.randomBytes=function(e){if(!this.isAvailable)throw new Error("System random byte generator is not available.");return this._source.randomBytes(e)},e}();t.SystemRandomSource=o},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=function(){function e(){this.isAvailable=!1,this.isInstantiated=!1;var e="undefined"!=typeof self?self.crypto||self.msCrypto:null;e&&e.getRandomValues&&(this._crypto=e,this.isAvailable=!0,this.isInstantiated=!0)}return e.prototype.randomBytes=function(e){if(!this.isAvailable||!this._crypto)throw new Error("Browser random byte generator is not available.");for(var t=new Uint8Array(e),n=0;n<t.length;n+=65536)this._crypto.getRandomValues(t.subarray(n,n+Math.min(t.length-n,65536)));return t},e}();t.BrowserRandomSource=r},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(27),i=function(){function e(){this.isAvailable=!1,this.isInstantiated=!1;var e=n(94);e&&e.randomBytes&&(this._crypto=e,this.isAvailable=!0,this.isInstantiated=!0)}return e.prototype.randomBytes=function(e){if(!this.isAvailable||!this._crypto)throw new Error("Node.js random byte generator is not available.");var t=this._crypto.randomBytes(e);if(t.length!==e)throw new Error("NodeRandomSource: got fewer bytes than requested");for(var n=new Uint8Array(e),i=0;i<n.length;i++)n[i]=t[i];return r.wipe(t),n},e}();t.NodeRandomSource=i},function(e,t){},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(96);function i(e,t,n){return void 0===t&&(t=new Uint8Array(2)),void 0===n&&(n=0),t[n+0]=e>>>8,t[n+1]=e>>>0,t}function o(e,t,n){return void 0===t&&(t=new Uint8Array(2)),void 0===n&&(n=0),t[n+0]=e>>>0,t[n+1]=e>>>8,t}function s(e,t){return void 0===t&&(t=0),e[t]<<24|e[t+1]<<16|e[t+2]<<8|e[t+3]}function a(e,t){return void 0===t&&(t=0),(e[t]<<24|e[t+1]<<16|e[t+2]<<8|e[t+3])>>>0}function c(e,t){return void 0===t&&(t=0),e[t+3]<<24|e[t+2]<<16|e[t+1]<<8|e[t]}function u(e,t){return void 0===t&&(t=0),(e[t+3]<<24|e[t+2]<<16|e[t+1]<<8|e[t])>>>0}function h(e,t,n){return void 0===t&&(t=new Uint8Array(4)),void 0===n&&(n=0),t[n+0]=e>>>24,t[n+1]=e>>>16,t[n+2]=e>>>8,t[n+3]=e>>>0,t}function l(e,t,n){return void 0===t&&(t=new Uint8Array(4)),void 0===n&&(n=0),t[n+0]=e>>>0,t[n+1]=e>>>8,t[n+2]=e>>>16,t[n+3]=e>>>24,t}function d(e,t,n){return void 0===t&&(t=new Uint8Array(8)),void 0===n&&(n=0),h(e/4294967296>>>0,t,n),h(e>>>0,t,n+4),t}function f(e,t,n){return void 0===t&&(t=new Uint8Array(8)),void 0===n&&(n=0),l(e>>>0,t,n),l(e/4294967296>>>0,t,n+4),t}t.readInt16BE=function(e,t){return void 0===t&&(t=0),(e[t+0]<<8|e[t+1])<<16>>16},t.readUint16BE=function(e,t){return void 0===t&&(t=0),(e[t+0]<<8|e[t+1])>>>0},t.readInt16LE=function(e,t){return void 0===t&&(t=0),(e[t+1]<<8|e[t])<<16>>16},t.readUint16LE=function(e,t){return void 0===t&&(t=0),(e[t+1]<<8|e[t])>>>0},t.writeUint16BE=i,t.writeInt16BE=i,t.writeUint16LE=o,t.writeInt16LE=o,t.readInt32BE=s,t.readUint32BE=a,t.readInt32LE=c,t.readUint32LE=u,t.writeUint32BE=h,t.writeInt32BE=h,t.writeUint32LE=l,t.writeInt32LE=l,t.readInt64BE=function(e,t){void 0===t&&(t=0);var n=s(e,t),r=s(e,t+4);return 4294967296*n+r-4294967296*(r>>31)},t.readUint64BE=function(e,t){return void 0===t&&(t=0),4294967296*a(e,t)+a(e,t+4)},t.readInt64LE=function(e,t){void 0===t&&(t=0);var n=c(e,t);return 4294967296*c(e,t+4)+n-4294967296*(n>>31)},t.readUint64LE=function(e,t){void 0===t&&(t=0);var n=u(e,t);return 4294967296*u(e,t+4)+n},t.writeUint64BE=d,t.writeInt64BE=d,t.writeUint64LE=f,t.writeInt64LE=f,t.readUintBE=function(e,t,n){if(void 0===n&&(n=0),e%8!=0)throw new Error("readUintBE supports only bitLengths divisible by 8");if(e/8>t.length-n)throw new Error("readUintBE: array is too short for the given bitLength");for(var r=0,i=1,o=e/8+n-1;o>=n;o--)r+=t[o]*i,i*=256;return r},t.readUintLE=function(e,t,n){if(void 0===n&&(n=0),e%8!=0)throw new Error("readUintLE supports only bitLengths divisible by 8");if(e/8>t.length-n)throw new Error("readUintLE: array is too short for the given bitLength");for(var r=0,i=1,o=n;o<n+e/8;o++)r+=t[o]*i,i*=256;return r},t.writeUintBE=function(e,t,n,i){if(void 0===n&&(n=new Uint8Array(e/8)),void 0===i&&(i=0),e%8!=0)throw new Error("writeUintBE supports only bitLengths divisible by 8");if(!r.isSafeInteger(t))throw new Error("writeUintBE value must be an integer");for(var o=1,s=e/8+i-1;s>=i;s--)n[s]=t/o&255,o*=256;return n},t.writeUintLE=function(e,t,n,i){if(void 0===n&&(n=new Uint8Array(e/8)),void 0===i&&(i=0),e%8!=0)throw new Error("writeUintLE supports only bitLengths divisible by 8");if(!r.isSafeInteger(t))throw new Error("writeUintLE value must be an integer");for(var o=1,s=i;s<i+e/8;s++)n[s]=t/o&255,o*=256;return n},t.readFloat32BE=function(e,t){return void 0===t&&(t=0),new DataView(e.buffer,e.byteOffset,e.byteLength).getFloat32(t)},t.readFloat32LE=function(e,t){return void 0===t&&(t=0),new DataView(e.buffer,e.byteOffset,e.byteLength).getFloat32(t,!0)},t.readFloat64BE=function(e,t){return void 0===t&&(t=0),new DataView(e.buffer,e.byteOffset,e.byteLength).getFloat64(t)},t.readFloat64LE=function(e,t){return void 0===t&&(t=0),new DataView(e.buffer,e.byteOffset,e.byteLength).getFloat64(t,!0)},t.writeFloat32BE=function(e,t,n){return void 0===t&&(t=new Uint8Array(4)),void 0===n&&(n=0),new DataView(t.buffer,t.byteOffset,t.byteLength).setFloat32(n,e),t},t.writeFloat32LE=function(e,t,n){return void 0===t&&(t=new Uint8Array(4)),void 0===n&&(n=0),new DataView(t.buffer,t.byteOffset,t.byteLength).setFloat32(n,e,!0),t},t.writeFloat64BE=function(e,t,n){return void 0===t&&(t=new Uint8Array(8)),void 0===n&&(n=0),new DataView(t.buffer,t.byteOffset,t.byteLength).setFloat64(n,e),t},t.writeFloat64LE=function(e,t,n){return void 0===t&&(t=new Uint8Array(8)),void 0===n&&(n=0),new DataView(t.buffer,t.byteOffset,t.byteLength).setFloat64(n,e,!0),t}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.mul=Math.imul||function(e,t){var n=65535&e,r=65535&t;return n*r+((e>>>16&65535)*r+n*(t>>>16&65535)<<16>>>0)|0},t.add=function(e,t){return e+t|0},t.sub=function(e,t){return e-t|0},t.rotl=function(e,t){return e<<t|e>>>32-t},t.rotr=function(e,t){return e<<32-t|e>>>t},t.isInteger=Number.isInteger||function(e){return"number"==typeof e&&isFinite(e)&&Math.floor(e)===e},t.MAX_SAFE_INTEGER=9007199254740991,t.isSafeInteger=function(e){return t.isInteger(e)&&e>=-t.MAX_SAFE_INTEGER&&e<=t.MAX_SAFE_INTEGER}},function(e,t,n){"use strict";e.exports=e=>encodeURIComponent(e).replace(/[!'()*]/g,e=>"%"+e.charCodeAt(0).toString(16).toUpperCase())},function(e,t,n){"use strict";var r=new RegExp("%[a-f0-9]{2}","gi"),i=new RegExp("(%[a-f0-9]{2})+","gi");function o(e,t){try{return decodeURIComponent(e.join(""))}catch(e){}if(1===e.length)return e;t=t||1;var n=e.slice(0,t),r=e.slice(t);return Array.prototype.concat.call([],o(n),o(r))}function s(e){try{return decodeURIComponent(e)}catch(i){for(var t=e.match(r),n=1;n<t.length;n++)t=(e=o(t,n).join("")).match(r);return e}}e.exports=function(e){if("string"!=typeof e)throw new TypeError("Expected `encodedURI` to be of type `string`, got `"+typeof e+"`");try{return e=e.replace(/\+/g," "),decodeURIComponent(e)}catch(t){return function(e){for(var t={"%FE%FF":"��","%FF%FE":"��"},n=i.exec(e);n;){try{t[n[0]]=decodeURIComponent(n[0])}catch(e){var r=s(n[0]);r!==n[0]&&(t[n[0]]=r)}n=i.exec(e)}t["%C2"]="�";for(var o=Object.keys(t),a=0;a<o.length;a++){var c=o[a];e=e.replace(new RegExp(c,"g"),t[c])}return e}(e)}}},function(e,t,n){"use strict";e.exports=(e,t)=>{if("string"!=typeof e||"string"!=typeof t)throw new TypeError("Expected the arguments to be of type `string`");if(""===t)return[e];const n=e.indexOf(t);return-1===n?[e]:[e.slice(0,n),e.slice(n+t.length)]}},function(e,t,n){"use strict";e.exports=function(e,t){for(var n={},r=Object.keys(e),i=Array.isArray(t),o=0;o<r.length;o++){var s=r[o],a=e[s];(i?-1!==t.indexOf(s):t(s,a,e))&&(n[s]=a)}return n}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.generateChildLogger=t.formatChildLoggerContext=t.getLoggerContext=t.setBrowserLoggerContext=t.getBrowserLoggerContext=t.getDefaultLoggerOptions=void 0;const r=n(69);function i(e,t=r.PINO_CUSTOM_CONTEXT_KEY){return e[t]||""}function o(e,t,n=r.PINO_CUSTOM_CONTEXT_KEY){return e[n]=t,e}function s(e,t=r.PINO_CUSTOM_CONTEXT_KEY){let n="";return n=void 0===e.bindings?i(e,t):e.bindings().context||"",n}function a(e,t,n=r.PINO_CUSTOM_CONTEXT_KEY){const i=s(e,n);return i.trim()?`${i}/${t}`:t}t.getDefaultLoggerOptions=function(e){return Object.assign(Object.assign({},e),{level:(null==e?void 0:e.level)||r.PINO_LOGGER_DEFAULTS.level,prettyPrint:(null==e?void 0:e.prettyPrint)||r.PINO_LOGGER_DEFAULTS.prettyPrint})},t.getBrowserLoggerContext=i,t.setBrowserLoggerContext=o,t.getLoggerContext=s,t.formatChildLoggerContext=a,t.generateChildLogger=function(e,t,n=r.PINO_CUSTOM_CONTEXT_KEY){const i=a(e,t,n);return o(e.child({context:i}),i,n)}},function(e,t,n){"use strict";e.exports=function(){throw new Error("ws does not work in the browser. Browser clients must use the native WebSocket object")}},function(e,t,n){"use strict";n.r(t),n.d(t,"SIGNER_EVENTS",(function(){return nt})),n.d(t,"SignerConnection",(function(){return rt}));var r=n(3),i=n(5),o=n(0),s=n(19),a=n.n(s),c=n(26),u=n.n(c),h=n(6),l=n(17),d=n(2);var f=n(12);const p=Object(f.c)({GENERIC:"GENERIC",MISSING_OR_INVALID:"MISSING_OR_INVALID",MISSING_RESPONSE:"MISSING_RESPONSE",MISSING_DECRYPT_PARAMS:"MISSING_DECRYPT_PARAMS",INVALID_UPDATE_REQUEST:"INVALID_UPDATE_REQUEST",INVALID_UPGRADE_REQUEST:"INVALID_UPGRADE_REQUEST",INVALID_STORAGE_KEY_NAME:"INVALID_STORAGE_KEY_NAME",RECORD_ALREADY_EXISTS:"RECORD_ALREADY_EXISTS",RESTORE_WILL_OVERRIDE:"RESTORE_WILL_OVERRIDE",NO_MATCHING_ID:"NO_MATCHING_ID",NO_MATCHING_TOPIC:"NO_MATCHING_TOPIC",NO_MATCHING_RESPONSE:"NO_MATCHING_RESPONSE",NO_MATCHING_KEY:"NO_MATCHING_KEY",UNKNOWN_JSONRPC_METHOD:"UNKNOWN_JSONRPC_METHOD",MISMATCHED_TOPIC:"MISMATCHED_TOPIC",MISMATCHED_ACCOUNTS:"MISMATCHED_ACCOUNTS",SETTLED:"SETTLED",NOT_APPROVED:"NOT_APPROVED",PROPOSAL_RESPONDED:"PROPOSAL_RESPONDED",RESPONSE_ACKNOWLEDGED:"RESPONSE_ACKNOWLEDGED",EXPIRED:"EXPIRED",DELETED:"DELETED",RESUBSCRIBED:"RESUBSCRIBED",SETTLE_TIMEOUT:"SETTLE_TIMEOUT",JSONRPC_REQUEST_TIMEOUT:"JSONRPC_REQUEST_TIMEOUT",UNAUTHORIZED_TARGET_CHAIN:"UNAUTHORIZED_TARGET_CHAIN",UNAUTHORIZED_JSON_RPC_METHOD:"UNAUTHORIZED_JSON_RPC_METHOD",UNAUTHORIZED_NOTIFICATION_TYPE:"UNAUTHORIZED_NOTIFICATION_TYPE",UNAUTHORIZED_UPDATE_REQUEST:"UNAUTHORIZED_UPDATE_REQUEST",UNAUTHORIZED_UPGRADE_REQUEST:"UNAUTHORIZED_UPGRADE_REQUEST",UNAUTHORIZED_MATCHING_CONTROLLER:"UNAUTHORIZED_MATCHING_CONTROLLER",JSONRPC_REQUEST_METHOD_REJECTED:"JSONRPC_REQUEST_METHOD_REJECTED",JSONRPC_REQUEST_METHOD_UNAUTHORIZED:"JSONRPC_REQUEST_METHOD_UNAUTHORIZED",JSONRPC_REQUEST_METHOD_UNSUPPORTED:"JSONRPC_REQUEST_METHOD_UNSUPPORTED",DISCONNECTED_ALL_CHAINS:"DISCONNECTED_ALL_CHAINS",DISCONNECTED_TARGET_CHAIN:"DISCONNECTED_TARGET_CHAIN",DISAPPROVED_CHAINS:"DISAPPROVED_CHAINS",DISAPPROVED_JSONRPC:"DISAPPROVED_JSONRPC",DISAPPROVED_NOTIFICATION:"DISAPPROVED_NOTIFICATION",UNSUPPORTED_CHAINS:"UNSUPPORTED_CHAINS",UNSUPPORTED_JSONRPC:"UNSUPPORTED_JSONRPC",UNSUPPORTED_NOTIFICATION:"UNSUPPORTED_NOTIFICATION",UNSUPPORTED_SIGNAL:"UNSUPPORTED_SIGNAL",USER_DISCONNECTED:"USER_DISCONNECTED",UNKNOWN:"UNKNOWN"}),g="undefined",y="Something went wrong",v="parameter",m="session",E="Ethereum",b={[p.GENERIC]:{type:p.GENERIC,code:0,stringify:e=>(null==e?void 0:e.message)||y,format:e=>({code:b[p.GENERIC].code,message:b[p.GENERIC].stringify(e)})},[p.MISSING_OR_INVALID]:{type:p.MISSING_OR_INVALID,code:1e3,stringify:e=>"Missing or invalid "+((null==e?void 0:e.name)||v),format:e=>({code:b[p.MISSING_OR_INVALID].code,message:b[p.MISSING_OR_INVALID].stringify(e)})},[p.MISSING_RESPONSE]:{type:p.MISSING_RESPONSE,code:1001,stringify:e=>`Response is required for approved ${(null==e?void 0:e.context)||m} proposals`,format:e=>({code:b[p.MISSING_RESPONSE].code,message:b[p.MISSING_RESPONSE].stringify(e)})},[p.MISSING_DECRYPT_PARAMS]:{type:p.MISSING_DECRYPT_PARAMS,code:1002,stringify:e=>"Decrypt params required for "+((null==e?void 0:e.context)||m),format:e=>({code:b[p.MISSING_DECRYPT_PARAMS].code,message:b[p.MISSING_DECRYPT_PARAMS].stringify(e)})},[p.INVALID_UPDATE_REQUEST]:{type:p.INVALID_UPDATE_REQUEST,code:1003,stringify:e=>`Invalid ${(null==e?void 0:e.context)||m} update request`,format:e=>({code:b[p.INVALID_UPDATE_REQUEST].code,message:b[p.INVALID_UPDATE_REQUEST].stringify(e)})},[p.INVALID_UPGRADE_REQUEST]:{type:p.INVALID_UPGRADE_REQUEST,code:1004,stringify:e=>`Invalid ${(null==e?void 0:e.context)||m} upgrade request`,format:e=>({code:b[p.INVALID_UPGRADE_REQUEST].code,message:b[p.INVALID_UPGRADE_REQUEST].stringify(e)})},[p.INVALID_STORAGE_KEY_NAME]:{type:p.INVALID_STORAGE_KEY_NAME,code:1005,stringify:e=>"Invalid storage key name: "+((null==e?void 0:e.name)||v),format:e=>({code:b[p.INVALID_STORAGE_KEY_NAME].code,message:b[p.INVALID_STORAGE_KEY_NAME].stringify(e)})},[p.RECORD_ALREADY_EXISTS]:{type:p.RECORD_ALREADY_EXISTS,code:1100,stringify:e=>`Record already exists for ${(null==e?void 0:e.context)||m} matching id: ${null==e?void 0:e.id}`,format:e=>({code:b[p.RECORD_ALREADY_EXISTS].code,message:b[p.RECORD_ALREADY_EXISTS].stringify(e)})},[p.RESTORE_WILL_OVERRIDE]:{type:p.RESTORE_WILL_OVERRIDE,code:1200,stringify:e=>"Restore will override already set "+((null==e?void 0:e.context)||m),format:e=>({code:b[p.RESTORE_WILL_OVERRIDE].code,message:b[p.RESTORE_WILL_OVERRIDE].stringify(e)})},[p.NO_MATCHING_ID]:{type:p.NO_MATCHING_ID,code:1300,stringify:e=>`No matching ${(null==e?void 0:e.context)||m} with id: ${null==e?void 0:e.id}`,format:e=>({code:b[p.NO_MATCHING_ID].code,message:b[p.NO_MATCHING_ID].stringify(e)})},[p.NO_MATCHING_TOPIC]:{type:p.NO_MATCHING_TOPIC,code:1301,stringify:e=>`No matching ${(null==e?void 0:e.context)||m} with topic: ${null==e?void 0:e.topic}`,format:e=>({code:b[p.NO_MATCHING_TOPIC].code,message:b[p.NO_MATCHING_TOPIC].stringify(e)})},[p.NO_MATCHING_RESPONSE]:{type:p.NO_MATCHING_RESPONSE,code:1302,stringify:e=>`No response found in pending ${(null==e?void 0:e.context)||m} proposal`,format:e=>({code:b[p.NO_MATCHING_RESPONSE].code,message:b[p.NO_MATCHING_RESPONSE].stringify(e)})},[p.NO_MATCHING_KEY]:{type:p.NO_MATCHING_KEY,code:1303,stringify:e=>"No matching key with tag: "+(null==e?void 0:e.tag),format:e=>({code:b[p.NO_MATCHING_KEY].code,message:b[p.NO_MATCHING_KEY].stringify(e)})},[p.UNKNOWN_JSONRPC_METHOD]:{type:p.UNKNOWN_JSONRPC_METHOD,code:1400,stringify:e=>"Unknown JSON-RPC Method Requested: "+(null==e?void 0:e.method),format:e=>({code:b[p.UNKNOWN_JSONRPC_METHOD].code,message:b[p.UNKNOWN_JSONRPC_METHOD].stringify(e)})},[p.MISMATCHED_TOPIC]:{type:p.MISMATCHED_TOPIC,code:1500,stringify:e=>`Mismatched topic for ${(null==e?void 0:e.context)||m} with id: ${null==e?void 0:e.id}`,format:e=>({code:b[p.MISMATCHED_TOPIC].code,message:b[p.MISMATCHED_TOPIC].stringify(e)})},[p.MISMATCHED_ACCOUNTS]:{type:p.MISMATCHED_ACCOUNTS,code:1501,stringify:e=>"Invalid accounts with mismatched chains: "+(null==e?void 0:e.mismatched.toString()),format:e=>({code:b[p.MISMATCHED_ACCOUNTS].code,message:b[p.MISMATCHED_ACCOUNTS].stringify(e)})},[p.SETTLED]:{type:p.SETTLED,code:1600,stringify:e=>Object(f.b)((null==e?void 0:e.context)||m)+" settled",format:e=>({code:b[p.SETTLED].code,message:b[p.SETTLED].stringify(e)})},[p.NOT_APPROVED]:{type:p.NOT_APPROVED,code:1601,stringify:e=>Object(f.b)((null==e?void 0:e.context)||m)+" not approved",format:e=>({code:b[p.NOT_APPROVED].code,message:b[p.NOT_APPROVED].stringify(e)})},[p.PROPOSAL_RESPONDED]:{type:p.PROPOSAL_RESPONDED,code:1602,stringify:e=>Object(f.b)((null==e?void 0:e.context)||m)+" proposal responded",format:e=>({code:b[p.PROPOSAL_RESPONDED].code,message:b[p.PROPOSAL_RESPONDED].stringify(e)})},[p.RESPONSE_ACKNOWLEDGED]:{type:p.RESPONSE_ACKNOWLEDGED,code:1603,stringify:e=>Object(f.b)((null==e?void 0:e.context)||m)+" response acknowledge",format:e=>({code:b[p.RESPONSE_ACKNOWLEDGED].code,message:b[p.RESPONSE_ACKNOWLEDGED].stringify(e)})},[p.EXPIRED]:{type:p.EXPIRED,code:1604,stringify:e=>Object(f.b)((null==e?void 0:e.context)||m)+" expired",format:e=>({code:b[p.EXPIRED].code,message:b[p.EXPIRED].stringify(e)})},[p.DELETED]:{type:p.DELETED,code:1605,stringify:e=>Object(f.b)((null==e?void 0:e.context)||m)+" deleted",format:e=>({code:b[p.DELETED].code,message:b[p.DELETED].stringify(e)})},[p.RESUBSCRIBED]:{type:p.RESUBSCRIBED,code:1606,stringify:e=>"Subscription resubscribed with topic: "+(e.topic||g),format:e=>({code:b[p.RESUBSCRIBED].code,message:b[p.RESUBSCRIBED].stringify(e)})},[p.SETTLE_TIMEOUT]:{type:p.SETTLE_TIMEOUT,code:2e3,stringify:e=>`${Object(f.b)((null==e?void 0:e.context)||m)} failed to settle after ${Object(f.g)(null==e?void 0:e.timeout)} seconds`,format:e=>({code:b[p.SETTLE_TIMEOUT].code,message:b[p.SETTLE_TIMEOUT].stringify(e)})},[p.JSONRPC_REQUEST_TIMEOUT]:{type:p.JSONRPC_REQUEST_TIMEOUT,code:2001,stringify:e=>`JSON-RPC Request timeout after ${Object(f.g)(null==e?void 0:e.timeout)} seconds: ${null==e?void 0:e.method}`,format:e=>({code:b[p.JSONRPC_REQUEST_TIMEOUT].code,message:b[p.JSONRPC_REQUEST_TIMEOUT].stringify(e)})},[p.UNAUTHORIZED_TARGET_CHAIN]:{type:p.UNAUTHORIZED_TARGET_CHAIN,code:3e3,stringify:e=>"Unauthorized Target ChainId Requested: "+(null==e?void 0:e.chainId),format:e=>({code:b[p.UNAUTHORIZED_TARGET_CHAIN].code,message:b[p.UNAUTHORIZED_TARGET_CHAIN].stringify(e)})},[p.UNAUTHORIZED_JSON_RPC_METHOD]:{type:p.UNAUTHORIZED_JSON_RPC_METHOD,code:3001,stringify:e=>"Unauthorized JSON-RPC Method Requested: "+(null==e?void 0:e.method),format:e=>({code:b[p.UNAUTHORIZED_JSON_RPC_METHOD].code,message:b[p.UNAUTHORIZED_JSON_RPC_METHOD].stringify(e)})},[p.UNAUTHORIZED_NOTIFICATION_TYPE]:{type:p.UNAUTHORIZED_NOTIFICATION_TYPE,code:3002,stringify:e=>"Unauthorized Notification Type Requested: "+(null==e?void 0:e.type),format:e=>({code:b[p.UNAUTHORIZED_NOTIFICATION_TYPE].code,message:b[p.UNAUTHORIZED_NOTIFICATION_TYPE].stringify(e)})},[p.UNAUTHORIZED_UPDATE_REQUEST]:{type:p.UNAUTHORIZED_UPDATE_REQUEST,code:3003,stringify:e=>`Unauthorized ${(null==e?void 0:e.context)||m} update request`,format:e=>({code:b[p.UNAUTHORIZED_UPDATE_REQUEST].code,message:b[p.UNAUTHORIZED_UPDATE_REQUEST].stringify(e)})},[p.UNAUTHORIZED_UPGRADE_REQUEST]:{type:p.UNAUTHORIZED_UPGRADE_REQUEST,code:3004,stringify:e=>`Unauthorized ${(null==e?void 0:e.context)||m} upgrade request`,format:e=>({code:b[p.UNAUTHORIZED_UPGRADE_REQUEST].code,message:b[p.UNAUTHORIZED_UPGRADE_REQUEST].stringify(e)})},[p.UNAUTHORIZED_MATCHING_CONTROLLER]:{type:p.UNAUTHORIZED_MATCHING_CONTROLLER,code:3005,stringify:e=>`Unauthorized: peer is also ${(null==e?void 0:e.controller)?"":"not "}controller`,format:e=>({code:b[p.UNAUTHORIZED_MATCHING_CONTROLLER].code,message:b[p.UNAUTHORIZED_MATCHING_CONTROLLER].stringify(e)})},[p.JSONRPC_REQUEST_METHOD_REJECTED]:{type:p.JSONRPC_REQUEST_METHOD_REJECTED,code:4001,stringify:e=>"User rejected the request.",format:e=>({code:b[p.JSONRPC_REQUEST_METHOD_REJECTED].code,message:b[p.JSONRPC_REQUEST_METHOD_REJECTED].stringify(e)})},[p.JSONRPC_REQUEST_METHOD_UNAUTHORIZED]:{type:p.JSONRPC_REQUEST_METHOD_UNAUTHORIZED,code:4100,stringify:e=>"The requested account and/or method has not been authorized by the user.",format:e=>({code:b[p.JSONRPC_REQUEST_METHOD_UNAUTHORIZED].code,message:b[p.JSONRPC_REQUEST_METHOD_UNAUTHORIZED].stringify(e)})},[p.JSONRPC_REQUEST_METHOD_UNSUPPORTED]:{type:p.JSONRPC_REQUEST_METHOD_UNSUPPORTED,code:4200,stringify:e=>`The requested method is not supported by this ${(null==e?void 0:e.blockhain)||E} provider.`,format:e=>({code:b[p.JSONRPC_REQUEST_METHOD_UNSUPPORTED].code,message:b[p.JSONRPC_REQUEST_METHOD_UNSUPPORTED].stringify(e)})},[p.DISCONNECTED_ALL_CHAINS]:{type:p.DISCONNECTED_ALL_CHAINS,code:4900,stringify:e=>"The provider is disconnected from all chains.",format:e=>({code:b[p.DISCONNECTED_ALL_CHAINS].code,message:b[p.DISCONNECTED_ALL_CHAINS].stringify(e)})},[p.DISCONNECTED_TARGET_CHAIN]:{type:p.DISCONNECTED_TARGET_CHAIN,code:4901,stringify:e=>"The provider is disconnected from the specified chain.",format:e=>({code:b[p.DISCONNECTED_TARGET_CHAIN].code,message:b[p.DISCONNECTED_TARGET_CHAIN].stringify(e)})},[p.DISAPPROVED_CHAINS]:{type:p.DISAPPROVED_CHAINS,code:5e3,stringify:e=>"User disapproved requested chains",format:e=>({code:b[p.DISAPPROVED_CHAINS].code,message:b[p.DISAPPROVED_CHAINS].stringify(e)})},[p.DISAPPROVED_JSONRPC]:{type:p.DISAPPROVED_JSONRPC,code:5001,stringify:e=>"User disapproved requested json-rpc methods",format:e=>({code:b[p.DISAPPROVED_JSONRPC].code,message:b[p.DISAPPROVED_JSONRPC].stringify(e)})},[p.DISAPPROVED_NOTIFICATION]:{type:p.DISAPPROVED_NOTIFICATION,code:5002,stringify:e=>"User disapproved requested notification types",format:e=>({code:b[p.DISAPPROVED_NOTIFICATION].code,message:b[p.DISAPPROVED_NOTIFICATION].stringify(e)})},[p.UNSUPPORTED_CHAINS]:{type:p.UNSUPPORTED_CHAINS,code:5100,stringify:e=>"Requested chains are not supported: "+(null==e?void 0:e.chains.toString()),format:e=>({code:b[p.UNSUPPORTED_CHAINS].code,message:b[p.UNSUPPORTED_CHAINS].stringify(e)})},[p.UNSUPPORTED_JSONRPC]:{type:p.UNSUPPORTED_JSONRPC,code:5101,stringify:e=>"Requested json-rpc methods are not supported: "+(null==e?void 0:e.methods.toString()),format:e=>({code:b[p.UNSUPPORTED_JSONRPC].code,message:b[p.UNSUPPORTED_JSONRPC].stringify(e)})},[p.UNSUPPORTED_NOTIFICATION]:{type:p.UNSUPPORTED_NOTIFICATION,code:5102,stringify:e=>"Requested notification types are not supported: "+(null==e?void 0:e.types.toString()),format:e=>({code:b[p.UNSUPPORTED_NOTIFICATION].code,message:b[p.UNSUPPORTED_NOTIFICATION].stringify(e)})},[p.UNSUPPORTED_SIGNAL]:{type:p.UNSUPPORTED_SIGNAL,code:5103,stringify:e=>`Proposed ${(null==e?void 0:e.context)||m} signal is unsupported`,format:e=>({code:b[p.UNSUPPORTED_SIGNAL].code,message:b[p.UNSUPPORTED_SIGNAL].stringify(e)})},[p.USER_DISCONNECTED]:{type:p.USER_DISCONNECTED,code:5900,stringify:e=>"User disconnected "+((null==e?void 0:e.context)||m),format:e=>({code:b[p.USER_DISCONNECTED].code,message:b[p.USER_DISCONNECTED].stringify(e)})},[p.UNKNOWN]:{type:p.UNKNOWN,code:9e3,stringify:e=>"Unknown error"+(e?": "+(null==e?void 0:e.toString()):""),format:e=>({code:b[p.UNKNOWN].code,message:b[p.UNKNOWN].stringify(e)})}};var _=n(20),w=n(8);function R(e){return"pairing"===e.method}function O(e){return"responded"===e.status&&"outcome"in e}function T(e){return"reason"in e}function S(e){return"responded"===e}function I(e){const t=function(e){if(void 0===e||void 0===e.chains||!P(e.chains,C))return x(b.MISSING_OR_INVALID.format({name:"blockchain permissions"}));return{valid:!0}}(e.blockchain);if(j(t))return t;const n=function(e){if(void 0===e||void 0===e.methods||!P(e.methods,U))return x(b.MISSING_OR_INVALID.format({name:"jsonrpc permissions"}));return{valid:!0}}(e.jsonrpc);if(j(n))return n;const r=function(e){if(void 0===e||void 0===e.types||!P(e.types,U))return x(b.MISSING_OR_INVALID.format({name:"notification permissions"}));return{valid:!0}}(e.notifications);return j(r)?r:{valid:!0}}function N(e){return U(e.name)?U(e.description)?void 0!==e.url&&L(e.url)?void 0!==e.icons&&P(e.icons,L)?{valid:!0}:x(b.MISSING_OR_INVALID.format({name:"metadata icons"})):x(b.MISSING_OR_INVALID.format({name:"metadata url"})):x(b.MISSING_OR_INVALID.format({name:"metadata description"})):x(b.MISSING_OR_INVALID.format({name:"metadata name"}))}function A(e){if(e.approved){if(void 0===e.response)return x(b.MISSING_RESPONSE.format({context:"session"}));const t=function(e,t){if(void 0===t||void 0===t.chains||!P(t.chains,C))return x(b.MISSING_OR_INVALID.format({name:"blockchain permissions"}));if(void 0===e||void 0===e.accounts||!P(e.accounts,D))return x(b.MISSING_OR_INVALID.format({name:"state accounts"}));const n=e.accounts.filter(e=>{const[n,r]=e.split(":"),i=`${n}:${r}`;return!t.chains.includes(i)});if(n.length)return x(b.MISMATCHED_ACCOUNTS.format({mismatched:n}));return{valid:!0}}(e.response.state,e.proposal.permissions.blockchain);if(j(t))return t;const n=N(e.response.metadata);if(j(n))return n}return{valid:!0}}function P(e,t){if(Array.isArray(e)){if(void 0!==t&&e.length){return e.filter(t).length===e.length}return!0}return!1}function U(e){return"string"==typeof e&&!!e.trim()}function C(e){if(U(e)&&e.includes(":")){return 2===e.split(":").length}return!1}function D(e){if(U(e)&&e.includes(":")){const t=e.split(":");if(3===t.length){const e=t[0]+":"+t[1];return!!t[2]&&C(e)}}return!1}function L(e){if(U(e))try{return void 0!==new URL(e)}catch(e){return!1}return!1}function j(e){return"valid"in e&&!1===e.valid&&"error"in e&&"number"==typeof e.error.code&&"string"==typeof e.error.message}function x(e){return{valid:!1,error:e}}var q=n(1);const M="client",H="error",K=!1,J="wss://relay.walletconnect.com",B={proposal:"pairing_proposal",updated:"pairing_updated",created:"pairing_created",deleted:"pairing_deleted",sync:"pairing_sync"},G={proposal:"session_proposal",updated:"session_updated",created:"session_created",deleted:"session_deleted",notification:"session_notification",request:"session_request",response:"session_response",sync:"session_sync"},k={database:":memory:"},V="expirer_created",F="expirer_deleted",z="expirer_expired",Y="expirer_init",W="expirer_sync",$="heartbeat_pulse",Q="history_created",Z="history_updated",X="history_deleted",ee="history_init",te="history_sync",ne={propose:"wc_pairingPropose",approve:"wc_pairingApprove",reject:"wc_pairingReject",update:"wc_pairingUpdate",upgrade:"wc_pairingUpgrade",delete:"wc_pairingDelete",payload:"wc_pairingPayload",ping:"wc_pairingPing",notification:"wc_pairingNotification"},re={proposed:"proposed",responded:"responded",pending:"pending",settled:"settled"},ie={proposed:"pairing_proposed",responded:"pairing_responded",settled:"pairing_settled",updated:"pairing_updated",deleted:"pairing_deleted",request:"pairing_request",response:"pairing_response",sync:"pairing_sync",notification:"pairing_notification"},oe="relayer_payload",se="relayer_connect",ae="relayer_disconnect",ce="relayer_error",ue="payload",he="connect",le="disconnect",de="error",fe={database:":memory:"},pe={propose:"wc_sessionPropose",approve:"wc_sessionApprove",reject:"wc_sessionReject",update:"wc_sessionUpdate",upgrade:"wc_sessionUpgrade",delete:"wc_sessionDelete",payload:"wc_sessionPayload",ping:"wc_sessionPing",notification:"wc_sessionNotification"},ge={proposed:"proposed",responded:"responded",pending:"pending",settled:"settled"},ye={proposed:"session_proposed",responded:"session_responded",settled:"session_settled",updated:"session_updated",deleted:"session_deleted",request:"session_request",response:"session_response",sync:"session_sync",notification:"session_notification"},ve={jsonrpc:{methods:[]},blockchain:{chains:[]},notifications:{types:[]}},me={accounts:[]},Ee={metadata:{name:"",description:"",url:"",icons:[]},state:me},be="store_created",_e="store_updated",we="store_deleted",Re="store_init",Oe="store_sync",Te={crypto:{keychain:"crypto:keychain"},session:{pending:"session:pending",settled:"session:settled",history:"session:history",expirer:"session:expirer"},pairing:{pending:"pairing:pending",settled:"pairing:settled",history:"pairing:history",expirer:"pairing:expirer"},relayer:{history:"relayer:history",subscription:"relayer:subscription"}},Se="subscription_created",Ie="subscription_deleted",Ne="subscription_enabled",Ae="subscription_disabled",Pe="subscription_sync";class Ue{constructor(e,t){this.client=e,this.logger=t,this.keychain=new Map,this.name="keychain",this.client=e,this.logger=Object(q.generateChildLogger)(t,this.name)}get context(){return Object(q.getLoggerContext)(this.logger)}async init(){await this.restore()}async has(e,t){return this.keychain.has(e)}async set(e,t,n){this.keychain.set(e,t),await this.persist()}async get(e,t){const n=this.keychain.get(e);if(void 0===n)throw new Error(b.NO_MATCHING_KEY.format({tag:e}).message);return n}async del(e,t){this.keychain.delete(e),await this.persist()}async restore(){const e=await this.client.storage.getKeyChain(this.context);void 0!==e&&(this.keychain=e)}async persist(){await this.client.storage.setKeyChain(this.context,this.keychain)}}class Ce{constructor(e,t,n){this.client=e,this.logger=t,this.name="crypto",this.client=e,this.logger=Object(q.generateChildLogger)(t,this.name),this.keychain=n||new Ue(this.client,this.logger)}get context(){return Object(q.getLoggerContext)(this.logger)}async init(){await this.keychain.init()}async hasKeys(e){return this.keychain.has(e)}async generateKeyPair(){const e=function(){const e=l.generateKeyPair();return{privateKey:d.arrayToHex(e.privateKey),publicKey:d.arrayToHex(e.publicKey)}}();return this.setKeyPair(e)}async generateSharedKey(e,t,n){const r=await this.getKeyPair(e.publicKey),i=function(e,t){const n=l.derive(d.hexToArray(e),d.hexToArray(t));return d.arrayToHex(n)}(r.privateKey,t.publicKey);return this.setEncryptionKeys({sharedKey:i,publicKey:r.publicKey},n)}async encrypt(e,t){const{sharedKey:n,publicKey:r}=await this.getEncryptionKeys(e);return await async function(e){const t=d.utf8ToArray(e.message),n=d.hexToArray(e.sharedKey),r=d.hexToArray(e.publicKey),i=void 0!==e.iv?d.hexToArray(e.iv):void 0,o=await l.encryptWithSharedKey(t,n,r,i);return d.arrayToHex(o)}({message:t,sharedKey:n,publicKey:r})}async decrypt(e,t){const{sharedKey:n}=await this.getEncryptionKeys(e);return await async function(e){const t=d.hexToArray(e.encrypted),n=d.hexToArray(e.sharedKey),r=await l.decryptWithSharedKey(t,n);return d.arrayToUtf8(r)}({encrypted:t,sharedKey:n})}async encode(e,t){const n=Object(w.b)(t);return await this.hasKeys(e)?await this.encrypt(e,n):d.utf8ToHex(n)}async decode(e,t){const n=await this.hasKeys(e)?await this.decrypt(e,t):d.hexToUtf8(t);return Object(w.a)(n)}concatKeys(e,t){return d.arrayToHex(d.concatArrays(d.hexToArray(e),d.hexToArray(t)))}splitKeys(e){const t=d.hexToArray(e);return[d.arrayToHex(t.slice(0,32)),d.arrayToHex(t.slice(32,64))]}async setKeyPair(e){const t=this.concatKeys(e.publicKey,e.privateKey);return await this.keychain.set(e.publicKey,t),e.publicKey}async getKeyPair(e){const[t,n]=this.splitKeys(await this.keychain.get(e));return{publicKey:e,privateKey:n}}async setEncryptionKeys(e,t){const n=t||await async function(e){const t=await l.sha256(d.hexToArray(e));return d.arrayToHex(t)}(e.sharedKey),r=this.concatKeys(e.sharedKey,e.publicKey);return await this.keychain.set(n,r),n}async getEncryptionKeys(e){const[t,n]=this.splitKeys(await this.keychain.get(e));return{sharedKey:t,publicKey:n}}}class De{constructor(e,t){this.client=e,this.logger=t,this.name="encoder",this.client=e,this.logger=Object(q.generateChildLogger)(t,this.name)}get context(){return Object(q.getLoggerContext)(this.logger)}async encode(e,t){const n=Object(w.b)(t);return await this.client.crypto.hasKeys(e)?await this.client.crypto.encrypt(e,n):d.utf8ToHex(n)}async decode(e,t){const n=await this.client.crypto.hasKeys(e)?await this.client.crypto.decrypt(e,t):d.hexToUtf8(t);return Object(w.a)(n)}}class Le{async encode(e,t){return d.utf8ToHex(Object(w.b)(t))}async decode(e,t){return Object(w.a)(d.hexToUtf8(t))}}class je extends h.IEngine{constructor(e){super(e),this.sequence=e,this.registerEventListeners()}async find(e){return this.sequence.values.filter(t=>{var n,r,i,o,s,a;let c=!1;return(null===(n=t.permissions)||void 0===n?void 0:n.jsonrpc)&&(null===(r=e.jsonrpc)||void 0===r?void 0:r.methods)&&Object(f.i)(e.jsonrpc.methods,t.permissions.jsonrpc.methods)&&(c=!0),(null===(i=t.permissions)||void 0===i?void 0:i.blockchain)&&(null===(o=e.blockchain)||void 0===o?void 0:o.chains)&&Object(f.i)(e.blockchain.chains,t.permissions.blockchain.chains)&&(c=!0),(null===(s=t.permissions)||void 0===s?void 0:s.notifications)&&(null===(a=e.notifications)||void 0===a?void 0:a.types)&&Object(f.i)(e.notifications.types,t.permissions.notifications.types)&&(c=!0),c})}async ping(e,t){const n={method:this.sequence.config.jsonrpc.ping,params:{}};return this.request({topic:e,request:n,timeout:t||Object(f.m)(30)})}async send(e,t,n){const r=t,i=await this.sequence.settled.get(e);if(Object(o.isJsonRpcRequest)(t)&&!Object.values(this.sequence.config.jsonrpc).includes(t.method)){await this.isJsonRpcAuthorized(e,i.self,t),await this.sequence.validateRequest({topic:e,request:t,chainId:n});const r={chainId:n,request:{method:t.method,params:t.params}};r.chainId||delete r.chainId,t=Object(o.formatJsonRpcRequest)(this.sequence.config.jsonrpc.payload,r,t.id)}await this.sequence.client.relayer.publish(i.topic,t,{relay:i.relay}),(Object(o.isJsonRpcResponse)(r)||Object(o.isJsonRpcRequest)(r)&&!Object.values(this.sequence.config.jsonrpc).includes(r.method))&&await this.recordPayloadEvent({topic:e,payload:r,chainId:n})}get length(){return this.sequence.settled.length}get topics(){return this.sequence.settled.topics}get values(){return this.sequence.settled.values}create(e){return new Promise(async(t,n)=>{this.sequence.logger.debug("Create "+this.sequence.context),this.sequence.logger.trace({type:"method",method:"create",params:e});const r=(null==e?void 0:e.timeout)||Object(f.m)(300),i=setTimeout(()=>{const e=b.SETTLE_TIMEOUT.format({context:this.sequence.name,timeout:r});this.sequence.logger.error(e.message),n(e.message)},r);let o;try{o=await this.propose(e)}catch(e){return clearTimeout(i),n(e)}this.sequence.pending.on(_e,async e=>{if(o.topic===e.sequence.topic&&O(e.sequence)){const r=e.sequence.outcome;if(clearTimeout(i),T(r)){try{await this.sequence.pending.delete(o.topic,r.reason)}catch(e){return n(e)}n(new Error(r.reason.message))}else try{const e=await this.sequence.settled.get(r.topic),n=b.SETTLED.format({context:this.sequence.name});await this.sequence.pending.delete(o.topic,n),t(e)}catch(e){return n(e)}}})})}async respond(e){this.sequence.logger.debug("Respond "+this.sequence.context),this.sequence.logger.trace({type:"method",method:"respond",params:e}),await this.sequence.validateRespond(e);const{approved:t,proposal:n,response:r}=e,{relay:i,ttl:o}=n,s={publicKey:await this.sequence.client.crypto.generateKeyPair(),metadata:null==r?void 0:r.metadata};if(s.metadata||delete s.metadata,!t){const t=b.NOT_APPROVED.format({context:this.sequence.name}),r={reason:(null==e?void 0:e.reason)||t},o={status:this.sequence.config.status.responded,topic:n.topic,relay:i,self:s,proposal:n,outcome:r};return await this.sequence.pending.set(o.topic,o),o}try{const e={publicKey:s.publicKey,metadata:null==r?void 0:r.metadata};e.metadata||delete e.metadata;const t=Object(f.a)(n.ttl),a=(null==r?void 0:r.state)||{},c={publicKey:n.proposer.publicKey,metadata:n.proposer.metadata};c.metadata||delete c.metadata;const u=n.proposer.controller?{publicKey:c.publicKey}:{publicKey:s.publicKey},h=Object.assign(Object.assign({},n.permissions),{controller:u}),l={topic:(await this.settle({relay:i,self:s,peer:c,permissions:h,state:a,ttl:o,expiry:t})).topic,relay:i,state:a,responder:e,expiry:t},d={status:this.sequence.config.status.responded,topic:n.topic,relay:i,self:s,proposal:n,outcome:l};return await this.sequence.pending.set(d.topic,d),d}catch(e){const t={reason:b.GENERIC.format({message:e.message})},r={status:this.sequence.config.status.responded,topic:n.topic,relay:i,self:s,proposal:n,outcome:t};return await this.sequence.pending.set(r.topic,r),r}}async update(e){this.sequence.logger.debug("Update "+this.sequence.context),this.sequence.logger.trace({type:"method",method:"update",params:e});const t=await this.sequence.settled.get(e.topic),n={publicKey:t.self.publicKey},r=await this.handleUpdate(e.topic,e,n),i=Object(o.formatJsonRpcRequest)(this.sequence.config.jsonrpc.update,r);return await this.send(t.topic,i),t}async upgrade(e){this.sequence.logger.debug("Upgrade "+this.sequence.context),this.sequence.logger.trace({type:"method",method:"upgrade",params:e});const t=await this.sequence.settled.get(e.topic),n={publicKey:t.self.publicKey},r=await this.handleUpgrade(e.topic,e,n),i=Object(o.formatJsonRpcRequest)(this.sequence.config.jsonrpc.upgrade,r);return await this.send(t.topic,i),t}async request(e){return new Promise(async(t,n)=>{try{await this.sequence.validateRequest(e)}catch(e){return n(e)}const r=Object(o.formatJsonRpcRequest)(e.request.method,e.request.params),i=(null==e?void 0:e.timeout)||Object(f.m)(300),s=setTimeout(()=>{const e=b.JSONRPC_REQUEST_TIMEOUT.format({method:r.method,timeout:i});this.sequence.logger.error(e.message),n(e.message)},i);this.sequence.events.on(this.sequence.config.events.response,i=>{if(e.topic!==i.topic)return;const a=i.response;if(a.id===r.id){if(clearTimeout(s),Object(o.isJsonRpcError)(a)){const e=a.error.message;return this.sequence.logger.error(e),n(new Error(e))}return t(a.result)}});try{await this.send(e.topic,r,null==e?void 0:e.chainId)}catch(e){return clearTimeout(s),n(e)}})}async delete(e){this.sequence.logger.debug("Delete "+this.sequence.context),this.sequence.logger.trace({type:"method",method:"delete",params:e}),await this.sequence.settled.delete(e.topic,e.reason)}async notify(e){const{topic:t,notification:n}=e,r=await this.sequence.settled.get(e.topic);await this.isNotificationAuthorized(e.topic,r.self,n.type);const i=Object(o.formatJsonRpcRequest)(this.sequence.config.jsonrpc.notification,n);await this.send(e.topic,i)}async propose(e){this.sequence.logger.debug("Propose "+this.sequence.context),this.sequence.logger.trace({type:"method",method:"propose",params:e}),await this.sequence.validatePropose(e);const t=(null==e?void 0:e.relay)||{protocol:"waku"},n=d.arrayToHex(l.randomBytes(32)),r={publicKey:await this.sequence.client.crypto.generateKeyPair(),metadata:null==e?void 0:e.metadata};r.metadata||delete r.metadata;const i={publicKey:r.publicKey,controller:this.sequence.client.controller,metadata:r.metadata};i.metadata||delete i.metadata;const o={relay:t,topic:n,proposer:i,signal:(null==e?void 0:e.signal)||await this.sequence.getDefaultSignal({topic:n,relay:t,proposer:i}),permissions:(null==e?void 0:e.permissions)||await this.sequence.getDefaultPermissions(),ttl:(null==e?void 0:e.ttl)||await this.sequence.getDefaultTTL()},s={status:this.sequence.config.status.proposed,topic:o.topic,relay:o.relay,self:r,proposal:o};return await this.sequence.pending.set(s.topic,s),s}async settle(e){this.sequence.logger.debug("Settle "+this.sequence.context),this.sequence.logger.trace({type:"method",method:"settle",params:e});const t={topic:await this.sequence.client.crypto.generateSharedKey(e.self,e.peer),relay:e.relay,self:e.self,peer:e.peer,permissions:e.permissions,expiry:e.expiry,state:e.state,acknowledged:!1};return await this.sequence.settled.set(t.topic,t),t}async onResponse(e){const{topic:t,payload:n}=e;this.sequence.logger.debug(`Receiving ${this.sequence.context} response`),this.sequence.logger.trace({type:"method",method:"onResponse",topic:t,payload:n});const r=n,i=r.params,s=await this.sequence.pending.get(t);let a,c;if(function(e){return"reason"in e}(i))this.sequence.logger.error(i.reason),await this.sequence.pending.update(t,{status:this.sequence.config.status.responded,outcome:{reason:i.reason}});else{try{const e=s.proposal.proposer.controller?{publicKey:s.proposal.proposer.publicKey}:{publicKey:i.responder.publicKey},n={publicKey:i.responder.publicKey,metadata:i.responder.metadata};n.metadata||delete n.metadata;const r=i.state||{},o=Object.assign(Object.assign({},s.proposal.permissions),{controller:e}),a=await this.settle({relay:s.relay,self:s.self,peer:n,permissions:o,ttl:s.proposal.ttl,expiry:i.expiry,state:r}),c={topic:a.topic,relay:a.relay,responder:i.responder,expiry:a.expiry,state:a.state};await this.sequence.pending.update(t,{status:this.sequence.config.status.responded,outcome:c})}catch(e){this.sequence.logger.error(e),a=b.GENERIC.format({message:e.message}),c={reason:a},await this.sequence.pending.update(t,{status:this.sequence.config.status.responded,outcome:c})}await this.sequence.client.relayer.publish(s.topic,void 0===a?Object(o.formatJsonRpcResult)(r.id,!0):Object(o.formatJsonRpcError)(r.id,a),{relay:s.relay}),void 0===c||T(c)||await this.sequence.settled.update(c.topic,{acknowledged:!0})}}async onAcknowledge(e){const{topic:t,payload:n}=e;this.sequence.logger.debug(`Receiving ${this.sequence.context} acknowledge`),this.sequence.logger.trace({type:"method",method:"onAcknowledge",topic:t,payload:n});const r=n,i=await this.sequence.pending.get(t);if(!O(i))return;const{outcome:s}=i;Object(o.isJsonRpcError)(r)&&!T(s)&&await this.sequence.settled.delete(s.topic,r.error),void 0===s||T(s)||await this.sequence.settled.update(s.topic,{acknowledged:!0});const a=b.RESPONSE_ACKNOWLEDGED.format({context:this.sequence.name});await this.sequence.pending.delete(t,a)}async onMessage(e){const{topic:t,payload:n}=e;if(this.sequence.logger.debug(`Receiving ${this.sequence.context} message`),this.sequence.logger.trace({type:"method",method:"onMessage",topic:t,payload:n}),Object(o.isJsonRpcRequest)(n)){const t=n,r=await this.sequence.settled.get(e.topic);let i;switch(t.method){case this.sequence.config.jsonrpc.payload:await this.onPayload(e);break;case this.sequence.config.jsonrpc.update:await this.onUpdate(e);break;case this.sequence.config.jsonrpc.upgrade:await this.onUpgrade(e);break;case this.sequence.config.jsonrpc.notification:await this.onNotification(e);break;case this.sequence.config.jsonrpc.delete:await this.sequence.settled.delete(r.topic,t.params.reason);break;case this.sequence.config.jsonrpc.ping:await this.send(r.topic,Object(o.formatJsonRpcResult)(t.id,!0));break;default:i=b.UNKNOWN_JSONRPC_METHOD.format({method:t.method}),this.sequence.logger.error(i.message),await this.send(r.topic,Object(o.formatJsonRpcError)(t.id,i))}}else this.onPayloadEvent(e)}async onPayload(e){const{topic:t,payload:n}=e;if(Object(o.isJsonRpcRequest)(n)){const{id:e,params:r}=n,{chainId:i}=r,s=Object(o.formatJsonRpcRequest)(r.request.method,r.request.params,e),a=await this.sequence.settled.get(t);await this.isJsonRpcAuthorized(t,a.peer,s),await this.sequence.validateRequest({topic:t,request:s,chainId:i});const c={topic:t,payload:s,chainId:i};this.sequence.logger.debug(`Receiving ${this.sequence.context} payload`),this.sequence.logger.trace(Object.assign({type:"method",method:"onPayload"},c)),this.onPayloadEvent(c)}else{const e={topic:t,payload:n};this.sequence.logger.debug(`Receiving ${this.sequence.context} payload`),this.sequence.logger.trace(Object.assign({type:"method",method:"onPayload"},e)),this.onPayloadEvent(e)}}async onUpdate(e){const{topic:t,payload:n}=e;this.sequence.logger.debug(`Receiving ${this.sequence.context} update`),this.sequence.logger.trace({type:"method",method:"onUpdate",topic:t,payload:n});const r=e.payload,i=await this.sequence.settled.get(e.topic);try{const e={publicKey:i.peer.publicKey};await this.handleUpdate(t,r.params,e);const n=Object(o.formatJsonRpcResult)(r.id,!0);await this.send(i.topic,n)}catch(e){this.sequence.logger.error(e);const t=Object(o.formatJsonRpcError)(r.id,e.message);await this.send(i.topic,t)}}async onUpgrade(e){const{topic:t,payload:n}=e;this.sequence.logger.debug(`Receiving ${this.sequence.context} upgrade`),this.sequence.logger.trace({type:"method",method:"onUpgrade",topic:t,payload:n});const r=e.payload,i=await this.sequence.settled.get(e.topic);try{const e={publicKey:i.peer.publicKey};await this.handleUpgrade(t,r.params,e);const n=Object(o.formatJsonRpcResult)(r.id,!0);await this.send(i.topic,n)}catch(e){this.sequence.logger.error(e);const t=Object(o.formatJsonRpcError)(r.id,e.message);await this.send(i.topic,t)}}async onNotification(e){const{params:t}=e.payload,n=e.payload,r=await this.sequence.settled.get(e.topic);try{await this.isNotificationAuthorized(e.topic,r.peer,t.type);const i={topic:e.topic,notification:t},s=this.sequence.config.events.notification;this.sequence.logger.info("Emitting "+s),this.sequence.logger.debug({type:"event",event:s,notificationEvent:i}),this.sequence.events.emit(s,i);const a=Object(o.formatJsonRpcResult)(n.id,!0);await this.send(r.topic,a)}catch(e){this.sequence.logger.error(e);const t=Object(o.formatJsonRpcError)(n.id,e.message);await this.send(r.topic,t)}}async handleUpdate(e,t,n){if(void 0===t.state){const e=b.INVALID_UPDATE_REQUEST.format({context:this.sequence.name});throw this.sequence.logger.error(e.message),new Error(e.message)}const r=await this.sequence.settled.get(e);if(n.publicKey!==r.permissions.controller.publicKey){const e=b.UNAUTHORIZED_UPDATE_REQUEST.format({context:this.sequence.name});throw this.sequence.logger.error(e.message),new Error(e.message)}return r.state=await this.sequence.mergeUpdate(e,t),await this.sequence.settled.update(r.topic,r),t}async handleUpgrade(e,t,n){if(void 0===t.permissions){const e=b.INVALID_UPGRADE_REQUEST.format({context:this.sequence.name});throw this.sequence.logger.error(e.message),new Error(e.message)}const r=await this.sequence.settled.get(e);if(n.publicKey!==r.permissions.controller.publicKey){const e=b.UNAUTHORIZED_UPGRADE_REQUEST.format({context:this.sequence.name});throw this.sequence.logger.error(e.message),new Error(e.message)}return r.permissions=await this.sequence.mergeUpgrade(e,t),await this.sequence.settled.update(r.topic,r),t}async isJsonRpcAuthorized(e,t,n){const r=await this.sequence.settled.get(e);if(t.publicKey!==r.permissions.controller.publicKey&&!r.permissions.jsonrpc.methods.includes(n.method)){const e=b.UNAUTHORIZED_JSON_RPC_METHOD.format({method:n.method});throw this.sequence.logger.error(e.message),new Error(e.message)}}async isNotificationAuthorized(e,t,n){const r=await this.sequence.settled.get(e);if(t.publicKey!==r.permissions.controller.publicKey&&r.self.publicKey!==r.permissions.controller.publicKey&&!r.permissions.notifications.types.includes(n)){const e=b.UNAUTHORIZED_NOTIFICATION_TYPE.format({type:n});throw this.sequence.logger.error(e.message),new Error(e.message)}}async recordPayloadEvent(e){const{topic:t,payload:n,chainId:r}=e;Object(o.isJsonRpcRequest)(n)?await this.sequence.history.set(t,n,r):await this.sequence.history.resolve(n)}async shouldIgnorePayloadEvent(e){const{topic:t,payload:n}=e;if(!this.sequence.settled.sequences.has(t))return!0;let r=!1;try{if(Object(o.isJsonRpcRequest)(n))r=await this.sequence.history.exists(t,n.id);else{let e;try{e=await this.sequence.history.get(t,n.id)}catch(e){}r=void 0!==e&&void 0!==e.response}}catch(e){}return r}async onPayloadEvent(e){const{topic:t,payload:n,chainId:r}=e;if(!await this.shouldIgnorePayloadEvent(e)){if(Object(o.isJsonRpcRequest)(n)){const e={topic:t,request:n,chainId:r},i=this.sequence.config.events.request;this.sequence.logger.info("Emitting "+i),this.sequence.logger.debug({type:"event",event:i,sequence:e}),this.sequence.events.emit(i,e)}else{const e={topic:t,response:n,chainId:r},i=this.sequence.config.events.response;this.sequence.logger.info("Emitting "+i),this.sequence.logger.debug({type:"event",event:i,sequence:e}),this.sequence.events.emit(i,e)}await this.recordPayloadEvent(e)}}async onPendingPayloadEvent(e){if(Object(o.isJsonRpcRequest)(e.payload))switch(e.payload.method){case this.sequence.config.jsonrpc.approve:case this.sequence.config.jsonrpc.reject:this.onResponse(e)}else this.onAcknowledge(e)}async onPendingStatusEvent(e){const{sequence:t}=e;if(R(t.proposal.signal)&&!await this.sequence.client.crypto.hasKeys(t.proposal.topic)){const e=await this.sequence.client.pairing.settled.get(t.proposal.signal.params.topic);await this.sequence.client.crypto.generateSharedKey(e.self,e.peer,t.proposal.topic)}if(O(t)){const n=this.sequence.config.events.responded;if(this.sequence.logger.info("Emitting "+n),this.sequence.logger.debug({type:"event",event:n,sequence:t}),this.sequence.events.emit(n,t),!function(e){return"update"in e}(e)){const{topic:e,outcome:n,relay:r}=t,i=T(n)?this.sequence.config.jsonrpc.reject:this.sequence.config.jsonrpc.approve,s=T(n)?{reason:n.reason}:{relay:n.relay,responder:n.responder,expiry:n.expiry,state:n.state},a=Object(o.formatJsonRpcRequest)(i,s);await this.sequence.client.relayer.publish(e,a,{relay:r})}}else{const e=this.sequence.config.events.proposed;if(this.sequence.logger.info("Emitting "+e),this.sequence.logger.debug({type:"event",event:e,sequence:t}),this.sequence.events.emit(e,t),R(t.proposal.signal)){const e=Object(o.formatJsonRpcRequest)(this.sequence.config.jsonrpc.propose,t.proposal);await this.sequence.client.pairing.send(t.proposal.signal.params.topic,e)}}}async subscribeNewPending(e){const{topic:t,sequence:n}=e,r=Object(f.a)(86400);await this.sequence.client.relayer.subscribe(t,{relay:n.relay}),await this.sequence.expirer.set(t,{topic:t,expiry:r})}async subscribeNewSettled(e){const{topic:t,sequence:n}=e,{expiry:r}=n;await this.sequence.client.relayer.subscribe(t,{relay:n.relay}),await this.sequence.expirer.set(t,{topic:t,expiry:r})}registerEventListeners(){this.sequence.pending.on(be,async e=>{await this.subscribeNewPending(e),await this.onPendingStatusEvent(e)}),this.sequence.pending.on(_e,async e=>await this.onPendingStatusEvent(e)),this.sequence.pending.on(we,async e=>{const{sequence:t}=e;await this.sequence.client.relayer.unsubscribe(t.topic,{relay:t.relay}),await this.sequence.expirer.del(t.topic)}),this.sequence.settled.on(be,async e=>{await this.subscribeNewSettled(e);const{sequence:t}=e,n=this.sequence.config.events.settled;this.sequence.logger.info("Emitting "+n),this.sequence.logger.debug({type:"event",event:n,sequence:t}),this.sequence.events.emit(n,t)}),this.sequence.settled.on(_e,async e=>{const{sequence:t,update:n}=e,r=this.sequence.config.events.updated;this.sequence.logger.info("Emitting "+r),this.sequence.logger.debug({type:"event",event:r,sequence:t,update:n}),this.sequence.events.emit(r,t,n)}),this.sequence.settled.on(we,async e=>{const{sequence:t,reason:n}=e,r=this.sequence.config.events.deleted;this.sequence.logger.info("Emitting "+r),this.sequence.logger.debug({type:"event",event:r,sequence:t,reason:n}),this.sequence.events.emit(r,t,n);const i=Object(o.formatJsonRpcRequest)(this.sequence.config.jsonrpc.delete,{reason:n});await this.sequence.history.delete(t.topic),await this.sequence.client.relayer.publish(t.topic,i,{relay:t.relay}),await this.sequence.client.relayer.unsubscribe(t.topic,{relay:t.relay}),await this.sequence.expirer.del(t.topic)}),this.sequence.settled.on(Oe,()=>this.sequence.events.emit(this.sequence.config.events.sync)),this.sequence.client.relayer.on(oe,e=>{this.sequence.pending.sequences.has(e.topic)?this.onPendingPayloadEvent(e):this.sequence.settled.sequences.has(e.topic)&&this.onMessage(e)}),this.sequence.expirer.on(z,async e=>{if(this.sequence.pending.sequences.has(e.topic)){const t=b.EXPIRED.format({context:Object(f.d)(this.sequence.pending.context)});this.sequence.pending.delete(e.topic,t)}else{const t=b.EXPIRED.format({context:Object(f.d)(this.sequence.settled.context)});this.sequence.settled.delete(e.topic,t)}})}}class xe extends h.IExpirer{constructor(e,t){super(e,t),this.client=e,this.logger=t,this.expirations=new Map,this.events=new r.EventEmitter,this.name="expirer",this.cached=[],this.client,this.logger=Object(q.generateChildLogger)(t,this.name),this.registerEventListeners()}get context(){return Object(q.getLoggerContext)(this.logger)}get length(){return this.expirations.size}get topics(){return Array.from(this.expirations.keys())}get values(){return Array.from(this.expirations.values())}async init(){this.logger.trace("Initialized"),await this.initialize()}async has(e){try{return void 0!==this.getExpiration(e)}catch(e){return!1}}async set(e,t){await this.isInitialized(),this.expirations.set(e,t),this.checkExpiry(e,t),this.events.emit(V,{topic:e,expiration:t})}async get(e){return await this.isInitialized(),this.getExpiration(e)}async del(e){await this.isInitialized();const t=this.getExpiration(e);this.expirations.delete(e),this.events.emit(F,{topic:e,expiration:t})}on(e,t){this.events.on(e,t)}once(e,t){this.events.once(e,t)}off(e,t){this.events.off(e,t)}removeListener(e,t){this.events.removeListener(e,t)}async persist(){await this.client.storage.setSequenceStore(this.context,this.values),this.events.emit(W)}async restore(){try{const e=await this.client.storage.getSequenceStore(this.context);if(void 0===e)return;if(!e.length)return;if(this.expirations.size){const e=b.RESTORE_WILL_OVERRIDE.format({context:Object(f.d)(this.context)});throw this.logger.error(e.message),new Error(e.message)}this.cached=e,this.logger.debug("Successfully Restored expirations for "+Object(f.d)(this.context)),this.logger.trace({type:"method",method:"restore",expirations:this.values})}catch(e){this.logger.debug("Failed to Restore expirations for "+Object(f.d)(this.context)),this.logger.error(e)}}async initialize(){await this.restore(),this.reset(),this.onInit()}reset(){this.cached.forEach(e=>this.expirations.set(e.topic,e))}onInit(){this.cached=[],this.events.emit(Y)}async isInitialized(){if(this.cached.length)return new Promise(e=>{this.events.once(Y,()=>e())})}getExpiration(e){const t=this.expirations.get(e);if(!t){const t=b.NO_MATCHING_ID.format({context:Object(f.d)(this.context),topic:e});throw new Error(t.message)}return t}checkExpiry(e,t){const{expiry:n}=t;Object(f.m)(n)-Date.now()<=0&&this.expire(e,t)}expire(e,t){this.expirations.delete(e),this.events.emit(z,{topic:e,expiration:t})}checkExpirations(){this.expirations.forEach((e,t)=>this.checkExpiry(t,e))}registerEventListeners(){this.client.heartbeat.on($,()=>this.checkExpirations()),this.events.on(V,e=>{const t=V;this.logger.info("Emitting "+t),this.logger.debug({type:"event",event:t,data:e}),this.persist()}),this.events.on(z,e=>{const t=z;this.logger.info("Emitting "+t),this.logger.debug({type:"event",event:t,data:e}),this.persist()}),this.events.on(F,e=>{const t=F;this.logger.info("Emitting "+t),this.logger.debug({type:"event",event:t,data:e}),this.persist()})}}class qe extends h.IHeartBeat{constructor(e){super(e),this.events=new r.EventEmitter,this.interval=5,this.name="heartbeat",this.logger=void 0!==(null==e?void 0:e.logger)&&"string"!=typeof(null==e?void 0:e.logger)?Object(q.generateChildLogger)(e.logger,this.name):a()(Object(q.getDefaultLoggerOptions)({level:(null==e?void 0:e.logger)||"error"})),this.interval=(null==e?void 0:e.interval)||5}static async init(e){const t=new qe(e);return await t.init(),t}get context(){return Object(q.getLoggerContext)(this.logger)}async init(){this.logger.trace("Initialized"),await this.initialize()}on(e,t){this.events.on(e,t)}once(e,t){this.events.once(e,t)}off(e,t){this.events.off(e,t)}removeListener(e,t){this.events.removeListener(e,t)}async initialize(){setInterval(()=>this.pulse(),Object(f.m)(this.interval)),this.logger.trace("Initialized")}pulse(){this.events.emit($)}}class Me extends h.IJsonRpcHistory{constructor(e,t){super(e,t),this.logger=e,this.storage=t,this.records=new Map,this.events=new r.EventEmitter,this.name="history",this.cached=[],this.logger=Object(q.generateChildLogger)(e,this.name),this.storage=t,this.registerEventListeners()}async init(){this.logger.trace("Initialized"),await this.initialize()}get context(){return Object(q.getLoggerContext)(this.logger)}get size(){return this.records.size}get keys(){return Array.from(this.records.keys())}get values(){return Array.from(this.records.values())}get pending(){const e=[];return this.values.forEach(t=>{if(void 0!==t.response)return;const n={topic:t.topic,request:Object(o.formatJsonRpcRequest)(t.request.method,t.request.params,t.id),chainId:t.chainId};return e.push(n)}),e}async set(e,t,n){if(await this.isInitialized(),this.logger.debug("Setting JSON-RPC request history record"),this.logger.trace({type:"method",method:"set",topic:e,request:t,chainId:n}),this.records.has(t.id))return;const r={id:t.id,topic:e,request:{method:t.method,params:t.params||null},chainId:n};this.records.set(r.id,r),this.events.emit(Q,r)}async resolve(e){if(await this.isInitialized(),this.logger.debug("Updating JSON-RPC response history record"),this.logger.trace({type:"method",method:"update",response:e}),!this.records.has(e.id))return;const t=await this.getRecord(e.id);void 0===t.response&&(t.response=Object(o.isJsonRpcError)(e)?{error:e.error}:{result:e.result},this.records.set(t.id,t),this.events.emit(Z,t))}async get(e,t){await this.isInitialized(),this.logger.debug("Getting record"),this.logger.trace({type:"method",method:"get",topic:e,id:t});const n=await this.getRecord(t);if(n.topic!==e){const e=b.MISMATCHED_TOPIC.format({context:Object(f.d)(this.context),id:t});throw new Error(e.message)}return n}async delete(e,t){await this.isInitialized(),this.logger.debug("Deleting record"),this.logger.trace({type:"method",method:"delete",id:t}),this.values.forEach(n=>{if(n.topic===e){if(void 0!==t&&n.id!==t)return;this.records.delete(n.id),this.events.emit(X,n)}})}async exists(e,t){if(await this.isInitialized(),!this.records.has(t))return!1;return(await this.getRecord(t)).topic===e}on(e,t){this.events.on(e,t)}once(e,t){this.events.once(e,t)}off(e,t){this.events.off(e,t)}removeListener(e,t){this.events.removeListener(e,t)}async getRecord(e){await this.isInitialized();const t=this.records.get(e);if(!t){const t=b.NO_MATCHING_ID.format({context:Object(f.d)(this.context),id:e});throw new Error(t.message)}return t}async persist(){await this.storage.setJsonRpcRecords(this.context,this.values),this.events.emit(te)}async restore(){try{const e=await this.storage.getJsonRpcRecords(this.context);if(void 0===e)return;if(!e.length)return;if(this.records.size){const e=b.RESTORE_WILL_OVERRIDE.format({context:Object(f.d)(this.context)});throw this.logger.error(e.message),new Error(e.message)}this.cached=e,this.logger.debug("Successfully Restored records for "+Object(f.d)(this.context)),this.logger.trace({type:"method",method:"restore",records:this.values})}catch(e){this.logger.debug("Failed to Restore records for "+Object(f.d)(this.context)),this.logger.error(e)}}async initialize(){await this.restore(),this.reset(),this.onInit()}reset(){this.cached.forEach(e=>this.records.set(e.id,e))}onInit(){this.cached=[],this.events.emit(ee)}async isInitialized(){if(this.cached.length)return new Promise(e=>{this.events.once(ee,()=>e())})}registerEventListeners(){this.events.on(Q,e=>{const t=Q;this.logger.info("Emitting "+t),this.logger.debug({type:"event",event:t,record:e}),this.persist()}),this.events.on(Z,e=>{const t=Z;this.logger.info("Emitting "+t),this.logger.debug({type:"event",event:t,record:e}),this.persist()}),this.events.on(X,e=>{const t=X;this.logger.info("Emitting "+t),this.logger.debug({type:"event",event:t,record:e}),this.persist()})}}class He extends h.IStore{constructor(e,t,n){super(e,t,n),this.client=e,this.logger=t,this.name=n,this.sequences=new Map,this.events=new r.EventEmitter,this.cached=[],this.logger=Object(q.generateChildLogger)(t,this.name),this.registerEventListeners()}async init(){this.logger.trace("Initialized"),await this.initialize()}get context(){return Object(q.getLoggerContext)(this.logger)}get length(){return this.sequences.size}get topics(){return Array.from(this.sequences.keys())}get values(){return Array.from(this.sequences.values())}async set(e,t){await this.isInitialized(),this.sequences.has(e)?this.update(e,t):(this.logger.debug("Setting sequence"),this.logger.trace({type:"method",method:"set",topic:e,sequence:t}),this.sequences.set(e,t),this.events.emit(be,{topic:e,sequence:t}))}async get(e){await this.isInitialized(),this.logger.debug("Getting sequence"),this.logger.trace({type:"method",method:"get",topic:e});return await this.getSequence(e)}async update(e,t){await this.isInitialized(),this.logger.debug("Updating sequence"),this.logger.trace({type:"method",method:"update",topic:e,update:t});const n=Object.assign(Object.assign({},await this.getSequence(e)),t);this.sequences.set(e,n),this.events.emit(_e,{topic:e,sequence:n,update:t})}async delete(e,t){if(await this.isInitialized(),!this.sequences.has(e))return;this.logger.debug("Deleting sequence"),this.logger.trace({type:"method",method:"delete",topic:e,reason:t});const n=await this.getSequence(e);this.sequences.delete(e),this.events.emit(we,{topic:e,sequence:n,reason:t})}on(e,t){this.events.on(e,t)}once(e,t){this.events.once(e,t)}off(e,t){this.events.off(e,t)}removeListener(e,t){this.events.removeListener(e,t)}async getSequence(e){await this.isInitialized();const t=this.sequences.get(e);if(!t){const t=b.NO_MATCHING_TOPIC.format({context:Object(f.d)(this.context),topic:e});throw this.logger.error(t.message),new Error(t.message)}return t}async persist(){await this.client.storage.setSequenceStore(this.context,this.values),this.events.emit(Oe)}async restore(){try{const e=await this.client.storage.getSequenceStore(this.context);if(void 0===e)return;if(!e.length)return;if(this.sequences.size){const e=b.RESTORE_WILL_OVERRIDE.format({context:Object(f.d)(this.context)});throw this.logger.error(e.message),new Error(e.message)}this.cached=e,this.logger.debug("Successfully Restored sequences for "+Object(f.d)(this.context)),this.logger.trace({type:"method",method:"restore",sequences:this.values})}catch(e){this.logger.debug("Failed to Restore sequences for "+Object(f.d)(this.context)),this.logger.error(e)}}async initialize(){await this.restore(),this.reset(),this.onInit()}reset(){this.cached.forEach(e=>this.sequences.set(e.topic,e))}onInit(){this.cached=[],this.events.emit(Re)}async isInitialized(){if(this.cached.length)return new Promise(e=>{this.events.once(Re,()=>e())})}registerEventListeners(){this.events.on(be,e=>{const t=be;this.logger.info("Emitting "+t),this.logger.debug({type:"event",event:t,data:e}),this.persist()}),this.events.on(_e,e=>{const t=_e;this.logger.info("Emitting "+t),this.logger.debug({type:"event",event:t,data:e}),this.persist()}),this.events.on(we,e=>{const t=we;this.logger.info("Emitting "+t),this.logger.debug({type:"event",event:t,data:e}),this.persist()})}}class Ke extends h.IPairing{constructor(e,t){super(e,t),this.client=e,this.logger=t,this.events=new r.EventEmitter,this.name="pairing",this.config={status:re,events:ie,jsonrpc:ne},this.logger=Object(q.generateChildLogger)(t,this.name),this.pending=new He(e,this.logger,this.config.status.pending),this.settled=new He(e,this.logger,this.config.status.settled),this.history=new Me(this.logger,this.client.storage),this.expirer=new xe(e,this.logger),this.engine=new je(this)}async init(){this.logger.trace("Initialized"),await this.pending.init(),await this.settled.init(),await this.history.init(),await this.expirer.init()}get(e){return this.settled.get(e)}find(e){return this.engine.find(e)}ping(e,t){return this.engine.ping(e,t)}send(e,t){return this.engine.send(e,t)}get context(){return Object(q.getLoggerContext)(this.logger)}get length(){return this.settled.length}get topics(){return this.settled.topics}get values(){return this.settled.values}create(e){return this.engine.create(e)}respond(e){return this.engine.respond(e)}upgrade(e){return this.engine.upgrade(e)}update(e){return this.engine.update(e)}request(e){return this.engine.request(e)}delete(e){return this.engine.delete(e)}notify(e){return this.engine.notify(e)}on(e,t){this.events.on(e,t)}once(e,t){this.events.once(e,t)}off(e,t){this.events.off(e,t)}removeListener(e,t){this.events.removeListener(e,t)}async mergeUpdate(e,t){const n=await this.settled.get(e);return{metadata:t.state.metadata||n.state.metadata}}async mergeUpgrade(e,t){var n,r,i;const o=await this.settled.get(e);return{jsonrpc:{methods:Object(f.k)(o.permissions.jsonrpc.methods,(null===(n=t.permissions.jsonrpc)||void 0===n?void 0:n.methods)||[])},notifications:{types:Object(f.k)((null===(r=o.permissions.notifications)||void 0===r?void 0:r.types)||[],(null===(i=t.permissions.notifications)||void 0===i?void 0:i.types)||[])},controller:o.permissions.controller}}async validateRespond(e){}async validateRequest(e){}async validatePropose(e){}async getDefaultSignal({topic:e,relay:t,proposer:n}){var r;return{method:"uri",params:{uri:`${(r={protocol:this.client.protocol,version:this.client.version,topic:e,publicKey:n.publicKey,controller:n.controller,relay:t}).protocol}:${r.topic}@${r.version}?`+_.stringify({publicKey:r.publicKey,controller:r.controller,relay:Object(w.b)(r.relay)})}}}async getDefaultTTL(){return 2592e3}async getDefaultPermissions(){return{jsonrpc:{methods:[pe.propose]},notifications:{types:[]}}}}var Je=n(75),Be=n(28),Ge=n(25).a;class ke{constructor(){this.map=new Map}get topics(){return Array.from(this.map.keys())}set(e,t){const n=this.get(e);this.exists(e,t)||this.map.set(e,[...n,t])}get(e){return this.map.get(e)||[]}exists(e,t){return this.get(e).includes(t)}delete(e,t){if(void 0===t)return void this.map.delete(e);if(!this.map.has(e))return;const n=this.get(e);if(!this.exists(e,t))return;const r=n.filter(e=>e!==t);r.length?this.map.set(e,r):this.map.delete(e)}clear(){this.map.clear()}}class Ve extends h.ISubscriber{constructor(e,t){super(e,t),this.relayer=e,this.logger=t,this.subscriptions=new Map,this.topicMap=new ke,this.events=new r.EventEmitter,this.name="subscription",this.pending=new Map,this.cached=[],this.relayer=e,this.logger=Object(q.generateChildLogger)(t,this.name),this.registerEventListeners()}async init(){this.logger.trace("Initialized"),await this.initialize()}get context(){return Object(q.getLoggerContext)(this.logger)}get length(){return this.subscriptions.size}get ids(){return Array.from(this.subscriptions.keys())}get values(){return Array.from(this.subscriptions.values())}get topics(){return this.topicMap.topics}async subscribe(e,t){this.logger.debug("Subscribing Topic"),this.logger.trace({type:"method",method:"subscribe",params:{topic:e,opts:t}});try{const n=Qe(t),r={topic:e,relay:n};this.pending.set(e,r);const i=await this.rpcSubscribe(e,n);return await this.onSubscribe(i,r),this.logger.debug("Successfully Subscribed Topic"),this.logger.trace({type:"method",method:"subscribe",params:{topic:e,opts:t}}),i}catch(e){throw this.logger.debug("Failed to Subscribe Topic"),this.logger.error(e),e}}async unsubscribe(e,t){void 0!==(null==t?void 0:t.id)?await this.unsubscribeById(e,t.id,t):await this.unsubscribeByTopic(e,t)}on(e,t){this.events.on(e,t)}once(e,t){this.events.once(e,t)}off(e,t){this.events.off(e,t)}removeListener(e,t){this.events.removeListener(e,t)}async enable(){this.cached.length&&this.onEnable()}async disable(){this.cached.length||this.onDisable()}async hasSubscription(e,t){await this.isEnabled();let n=!1;try{n=(await this.getSubscription(e)).topic===t}catch(e){}return n}onEnable(){this.cached=[],this.events.emit(Ne)}onDisable(){this.cached=this.values,this.subscriptions.clear(),this.topicMap.clear(),this.events.emit(Ae)}async unsubscribeByTopic(e,t){const n=this.topicMap.get(e);await Promise.all(n.map(async n=>await this.unsubscribeById(e,n,t)))}async unsubscribeById(e,t,n){this.logger.debug("Unsubscribing Topic"),this.logger.trace({type:"method",method:"unsubscribe",params:{topic:e,id:t,opts:n}});try{const r=Qe(n);await this.rpcUnsubscribe(e,t,r);const i=b.DELETED.format({context:Object(f.d)(this.context)});await this.onUnsubscribe(e,t,i),this.logger.debug("Successfully Unsubscribed Topic"),this.logger.trace({type:"method",method:"unsubscribe",params:{topic:e,id:t,opts:n}})}catch(e){throw this.logger.debug("Failed to Unsubscribe Topic"),this.logger.error(e),e}}async rpcSubscribe(e,t){const n={method:Ze(t.protocol).subscribe,params:{topic:e}};return this.logger.debug("Outgoing Relay Payload"),this.logger.trace({type:"payload",direction:"outgoing",request:n}),this.relayer.provider.request(n)}async rpcUnsubscribe(e,t,n){const r={method:Ze(n.protocol).unsubscribe,params:{topic:e,id:t}};return this.logger.debug("Outgoing Relay Payload"),this.logger.trace({type:"payload",direction:"outgoing",request:r}),this.relayer.provider.request(r)}async onSubscribe(e,t){await this.setSubscription(e,Object.assign(Object.assign({},t),{id:e})),this.pending.delete(t.topic)}async onResubscribe(e,t){await this.addSubscription(e,Object.assign(Object.assign({},t),{id:e})),this.pending.delete(t.topic)}async onUnsubscribe(e,t,n){this.events.removeAllListeners(t),await this.hasSubscription(t,e)&&await this.deleteSubscription(t,n),await this.relayer.history.delete(e)}async setSubscription(e,t){await this.isEnabled(),this.subscriptions.has(e)||(this.logger.debug("Setting subscription"),this.logger.trace({type:"method",method:"setSubscription",id:e,subscription:t}),await this.addSubscription(e,t))}async addSubscription(e,t){this.subscriptions.set(e,Object.assign({},t)),this.topicMap.set(t.topic,e),this.events.emit(Se,t)}async getSubscription(e){await this.isEnabled(),this.logger.debug("Getting subscription"),this.logger.trace({type:"method",method:"getSubscription",id:e});const t=this.subscriptions.get(e);if(!t){const t=b.NO_MATCHING_ID.format({context:Object(f.d)(this.context),id:e});throw new Error(t.message)}return t}async deleteSubscription(e,t){await this.isEnabled(),this.logger.debug("Deleting subscription"),this.logger.trace({type:"method",method:"deleteSubscription",id:e,reason:t});const n=await this.getSubscription(e);this.subscriptions.delete(e),this.topicMap.delete(n.topic,e),this.events.emit(Ie,Object.assign(Object.assign({},n),{reason:t}))}async persist(){await this.relayer.storage.setRelayerSubscriptions(this.context,this.values),this.events.emit(Pe)}async restore(){try{const e=await this.relayer.storage.getRelayerSubscriptions(this.context);if(void 0===e)return;if(!e.length)return;if(this.subscriptions.size){const e=b.RESTORE_WILL_OVERRIDE.format({context:Object(f.d)(this.context)});throw this.logger.error(e.message),new Error(e.message)}this.cached=e,this.logger.debug("Successfully Restored subscriptions for "+Object(f.d)(this.context)),this.logger.trace({type:"method",method:"restore",subscriptions:this.values})}catch(e){this.logger.debug("Failed to Restore subscriptions for "+Object(f.d)(this.context)),this.logger.error(e)}}async initialize(){await this.restore(),await this.reset(),await this.enable()}async isEnabled(){if(this.cached.length)return new Promise(e=>{this.events.once(Ne,()=>e())})}async reset(){this.cached.length&&await Promise.all(this.cached.map(async e=>this.resubscribe(e)))}async resubscribe(e){const{topic:t,relay:n}=e,r={topic:t,relay:n};this.pending.set(r.topic,r);const i=await this.rpcSubscribe(r.topic,r.relay);if(await this.onResubscribe(i,r),this.ids.includes(e.id)){const t=b.RESUBSCRIBED.format({topic:e.topic});await this.deleteSubscription(e.id,t)}}async onConnect(){await this.reset(),await this.enable()}async onDisconnect(){await this.disable()}checkPending(){this.pending.forEach(async e=>{const t=await this.rpcSubscribe(e.topic,e.relay);await this.onSubscribe(t,e)})}registerEventListeners(){this.relayer.heartbeat.on($,()=>{this.checkPending()}),this.relayer.provider.on(he,async()=>{await this.onConnect()}),this.relayer.provider.on(le,async()=>{await this.onDisconnect()}),this.events.on(Se,async e=>{const t=Se;this.logger.info("Emitting "+t),this.logger.debug({type:"event",event:t,data:e}),await this.persist()}),this.events.on(Ie,async e=>{const t=Ie;this.logger.info("Emitting "+t),this.logger.debug({type:"event",event:t,data:e}),await this.persist()})}}class Fe extends class{constructor(e,t,n){this.logger=e,this.keyValueStorage=t,this.config=n,this.name="storage",this.version="0.2",this.keyMap=Te,this.logger=Object(q.generateChildLogger)(e,this.name),this.keyValueStorage=t,this.config=n}get context(){return Object(q.getLoggerContext)(this.logger)}get prefix(){return`${this.config.protocol}@${this.config.version}:${this.config.context}:${this.version}`}getStorageKey(e){const t=this.getStorageKeyName(e);if(!this.isValidStorageKeyName(t)){const e=b.INVALID_STORAGE_KEY_NAME.format({name:t});throw new Error(e.message)}return this.prefix+"//"+t}getStorageKeyName(e){return Object(f.f)(e)}isValidStorageKeyName(e){return Object.keys(this.keyMap).map(e=>Object.values(this.keyMap[e])).flat().includes(e.toLowerCase())}}{constructor(e,t,n){super(e,t,n),this.logger=e,this.keyValueStorage=t,this.config=n}async setJsonRpcRecords(e,t){const n=this.getStorageKey(e);await this.keyValueStorage.setItem(n,t)}async getJsonRpcRecords(e){const t=this.getStorageKey(e);return await this.keyValueStorage.getItem(t)}async setRelayerSubscriptions(e,t){const n=this.getStorageKey(e);await this.keyValueStorage.setItem(n,t)}async getRelayerSubscriptions(e){const t=this.getStorageKey(e);return await this.keyValueStorage.getItem(t)}}class ze extends Fe{constructor(e,t,n){super(e,t,n),this.logger=e,this.keyValueStorage=t,this.config=n}async setKeyChain(e,t){const n=this.getStorageKey(e);await this.keyValueStorage.setItem(n,Object(f.j)(t))}async getKeyChain(e){const t=this.getStorageKey(e),n=await this.keyValueStorage.getItem(t);return void 0!==n?Object(f.l)(n):void 0}async setSequenceStore(e,t){const n=this.getStorageKey(e);await this.keyValueStorage.setItem(n,t)}async getSequenceStore(e){const t=this.getStorageKey(e);return await this.keyValueStorage.getItem(t)}async setExpirations(e,t){const n=this.getStorageKey(e);await this.keyValueStorage.setItem(n,t)}async getExpirations(e){const t=this.getStorageKey(e);return await this.keyValueStorage.getItem(t)}}class Ye extends i.IEvents{constructor(e,t){super(),this.relayer=e,this.logger=t}}class We extends Ye{constructor(e,t){super(e,t),this.relayer=e,this.logger=t,this.events=new r.EventEmitter,this.name="publisher",this.queue=new Map,this.relayer=e,this.logger=Object(q.generateChildLogger)(t,this.name),this.registerEventListeners()}get context(){return Object(q.getLoggerContext)(this.logger)}async init(){this.logger.trace("Initialized"),await this.initialize()}async publish(e,t,n){this.logger.debug("Publishing Payload"),this.logger.trace({type:"method",method:"publish",params:{topic:e,payload:t,opts:n}});try{const r=(null==n?void 0:n.ttl)||21600,i=Qe(n),o={topic:e,payload:t,opts:{ttl:r,relay:i}};this.queue.set(t.id,o);const s=await this.relayer.encoder.encode(e,t);await this.rpcPublish(e,s,r,i),await this.onPublish(t.id,o),this.logger.debug("Successfully Published Payload"),this.logger.trace({type:"method",method:"publish",params:{topic:e,payload:t,opts:n}})}catch(e){throw this.logger.debug("Failed to Publish Payload"),this.logger.error(e),e}}on(e,t){this.events.on(e,t)}once(e,t){this.events.once(e,t)}off(e,t){this.events.off(e,t)}removeListener(e,t){this.events.removeListener(e,t)}async initialize(){}async rpcPublish(e,t,n,r){const i={method:Ze(r.protocol).publish,params:{topic:e,message:t,ttl:n}};return this.logger.debug("Outgoing Relay Payload"),this.logger.trace({type:"payload",direction:"outgoing",request:i}),this.relayer.provider.request(i)}async onPublish(e,t){this.queue.delete(e)}checkQueue(){this.queue.forEach(async e=>{const{topic:t,payload:n,opts:{ttl:r,relay:i}}=e,o=await this.relayer.encoder.encode(t,n);await this.rpcPublish(t,o,r,i),await this.onPublish(n.id,e)})}registerEventListeners(){this.relayer.heartbeat.on($,()=>{this.checkQueue()})}}class $e extends h.IRelayer{constructor(e){super(e),this.protocol="irn",this.version=1,this.events=new r.EventEmitter,this.name="relayer",this.logger=void 0!==(null==e?void 0:e.logger)&&"string"!=typeof(null==e?void 0:e.logger)?Object(q.generateChildLogger)(e.logger,this.name):a()(Object(q.getDefaultLoggerOptions)({level:(null==e?void 0:e.logger)||"error"}));const t=(null==e?void 0:e.keyValueStorage)||new u.a(fe);this.storage=void 0!==(null==e?void 0:e.storage)?e.storage:new Fe(this.logger,t,{protocol:this.protocol,version:this.version,context:this.context}),this.heartbeat=(null==e?void 0:e.heartbeat)||new qe({logger:this.logger}),this.encoder=(null==e?void 0:e.encoder)||new Le;const n=Object(f.e)(this.protocol,this.version,(null==e?void 0:e.relayUrl)||"wss://relay.walletconnect.com",null==e?void 0:e.projectId);this.provider=new Be.JsonRpcProvider(new Ge(n)),this.history=new Me(this.logger,this.storage),this.subscriber=new Ve(this,this.logger),this.publisher=new We(this,this.logger),this.registerEventListeners()}get context(){return Object(q.getLoggerContext)(this.logger)}get connected(){return this.provider.connection.connected}get connecting(){return this.provider.connection.connecting}async init(){this.logger.trace("Initialized"),await this.history.init(),await this.provider.connect(),await this.subscriber.init(),await this.publisher.init()}async publish(e,t,n){await this.publisher.publish(e,t,n),await this.recordPayloadEvent({topic:e,payload:t})}async subscribe(e,t){return await this.subscriber.subscribe(e,t)}async unsubscribe(e,t){await this.subscriber.unsubscribe(e,t)}on(e,t){this.events.on(e,t)}once(e,t){this.events.once(e,t)}off(e,t){this.events.off(e,t)}removeListener(e,t){this.events.removeListener(e,t)}async recordPayloadEvent(e){const{topic:t,payload:n}=e;Object(o.isJsonRpcRequest)(n)?await this.history.set(t,n):await this.history.resolve(n)}async shouldIgnorePayloadEvent(e){const{topic:t,payload:n}=e;if(!this.subscriber.topics.includes(t))return!0;let r=!1;try{if(Object(o.isJsonRpcRequest)(n))r=await this.history.exists(t,n.id);else{let e;try{e=await this.history.get(t,n.id)}catch(e){}r=void 0!==e&&void 0!==e.response}}catch(e){}return r}async onPayload(e){if(this.logger.debug("Incoming Relay Payload"),this.logger.trace({type:"payload",direction:"incoming",payload:e}),Object(o.isJsonRpcRequest)(e)){if(!e.method.endsWith("_subscription"))return;const t=e.params,{topic:n,message:r}=t.data,i={topic:n,payload:await this.encoder.decode(n,r)};if(await this.shouldIgnorePayloadEvent(i))return;this.logger.debug("Emitting Relayer Payload"),this.logger.trace(Object.assign({type:"event",event:t.id},i)),this.events.emit(t.id,i),this.events.emit(oe,i),await this.acknowledgePayload(e),await this.recordPayloadEvent(i)}}async acknowledgePayload(e){const t=Object(o.formatJsonRpcResult)(e.id,!0);await this.provider.connection.send(t)}registerEventListeners(){this.provider.on(ue,e=>this.onPayload(e)),this.provider.on(he,async()=>{this.events.emit(se)}),this.provider.on(le,async()=>{this.events.emit(ae),setTimeout(()=>{this.provider.connect()},1)}),this.provider.on(de,e=>this.events.emit(ce,e))}}function Qe(e){return(null==e?void 0:e.relay)||{protocol:"waku"}}function Ze(e){const t=Je.RELAY_JSONRPC[e];if(void 0===t)throw new Error("Relay Protocol not supported: "+e);return t}class Xe extends h.ISession{constructor(e,t){super(e,t),this.client=e,this.logger=t,this.events=new r.EventEmitter,this.name="session",this.config={status:ge,events:ye,jsonrpc:pe},this.logger=Object(q.generateChildLogger)(t,this.name),this.pending=new He(e,this.logger,this.config.status.pending),this.settled=new He(e,this.logger,this.config.status.settled),this.history=new Me(this.logger,this.client.storage),this.expirer=new xe(e,this.logger),this.engine=new je(this)}async init(){this.logger.trace("Initialized"),await this.pending.init(),await this.settled.init(),await this.history.init(),await this.expirer.init()}get(e){return this.settled.get(e)}find(e){return this.engine.find(e)}ping(e,t){return this.engine.ping(e,t)}send(e,t,n){return this.engine.send(e,t,n)}get context(){return Object(q.getLoggerContext)(this.logger)}get length(){return this.settled.length}get topics(){return this.settled.topics}get values(){return this.settled.values}create(e){return this.engine.create(e)}respond(e){return this.engine.respond(e)}upgrade(e){return this.engine.upgrade(e)}update(e){return this.engine.update(e)}request(e){return this.engine.request(e)}delete(e){return this.engine.delete(e)}notify(e){return this.engine.notify(e)}on(e,t){this.events.on(e,t)}once(e,t){this.events.once(e,t)}off(e,t){this.events.off(e,t)}removeListener(e,t){this.events.removeListener(e,t)}async mergeUpdate(e,t){var n;const r=await this.settled.get(e);return{accounts:(null===(n=t.state)||void 0===n?void 0:n.accounts)||r.state.accounts}}async mergeUpgrade(e,t){var n,r,i,o,s;const a=await this.settled.get(e);return{jsonrpc:{methods:Object(f.k)(a.permissions.jsonrpc.methods,(null===(n=t.permissions.jsonrpc)||void 0===n?void 0:n.methods)||[])},notifications:{types:Object(f.k)((null===(r=a.permissions.notifications)||void 0===r?void 0:r.types)||[],(null===(i=t.permissions.notifications)||void 0===i?void 0:i.types)||[])},blockchain:{chains:Object(f.k)((null===(o=a.permissions.blockchain)||void 0===o?void 0:o.chains)||[],(null===(s=t.permissions.blockchain)||void 0===s?void 0:s.chains)||[])},controller:a.permissions.controller}}async validateRespond(e){if(void 0===e){const e=b.MISSING_OR_INVALID.format({name:"respond params"});throw this.logger.error(e.message),new Error(e.message)}const t=A(e);if(j(t))throw this.logger.error(t.error.message),new Error(t.error.message)}async validateRequest(e){if(void 0===e){const e=b.MISSING_OR_INVALID.format({name:"request params"});throw this.logger.error(e.message),new Error(e.message)}const{topic:t,chainId:n}=e,r=await this.settled.get(t);if(n&&!r.permissions.blockchain.chains.includes(n)){const e=b.UNAUTHORIZED_TARGET_CHAIN.format({chainId:n});throw this.logger.error(e.message),new Error(e.message)}}async validatePropose(e){if(void 0===e){const e=b.MISSING_OR_INVALID.format({name:"propose params"});throw this.logger.error(e.message),new Error(e.message)}const t=function(e){const t=I(e.permissions);if(j(t))return t;const n=N(e.metadata);return j(n)?n:{valid:!0}}(e);if(j(t))throw this.logger.error(t.error.message),new Error(t.error.message);if("pairing"!==e.signal.method){const e=b.UNSUPPORTED_SIGNAL.format({context:this.context});throw this.logger.error(e.message),new Error(e.message)}}async getDefaultSignal(e){return{method:"pairing",params:{topic:(await this.client.pairing.settled.get(e.topic)).topic}}}async getDefaultTTL(){return 604800}async getDefaultPermissions(){return{jsonrpc:{methods:[]},notifications:{types:[]},blockchain:{chains:[]}}}}class et extends h.IClient{constructor(e){super(e),this.protocol="wc",this.version=2,this.events=new r.EventEmitter,this.name="client";const t=void 0!==(null==e?void 0:e.logger)&&"string"!=typeof(null==e?void 0:e.logger)?e.logger:a()(Object(q.getDefaultLoggerOptions)({level:(null==e?void 0:e.logger)||H}));this.name=(null==e?void 0:e.name)||M,this.controller=(null==e?void 0:e.controller)||K,this.metadata=(null==e?void 0:e.metadata)||Object(f.h)(),this.projectId=null==e?void 0:e.projectId,this.logger=Object(q.generateChildLogger)(t,this.name),this.heartbeat=new qe({logger:this.logger}),this.crypto=new Ce(this,this.logger,null==e?void 0:e.keychain),this.encoder=new De(this,this.logger);const n=(null==e?void 0:e.storage)||new u.a(Object.assign(Object.assign({},k),null==e?void 0:e.storageOptions));this.storage=new ze(this.logger,n,{protocol:this.protocol,version:this.version,context:this.context});const i=Object(f.e)(this.protocol,this.version,(null==e?void 0:e.relayUrl)||J,this.projectId);this.relayer=new $e({relayUrl:i,heartbeat:this.heartbeat,encoder:this.encoder,logger:this.logger,storage:this.storage}),this.pairing=new Ke(this,this.logger),this.session=new Xe(this,this.logger)}static async init(e){const t=new et(e);return await t.initialize(),t}get context(){return Object(q.getLoggerContext)(this.logger)}on(e,t){this.events.on(e,t)}once(e,t){this.events.once(e,t)}off(e,t){this.events.off(e,t)}removeListener(e,t){this.events.removeListener(e,t)}async connect(e){this.logger.debug("Connecting Application"),this.logger.trace({type:"method",method:"connect",params:e});try{void 0===typeof e.pairing&&this.logger.info("Connecing with existing pairing");const t=void 0===e.pairing?await this.pairing.create():await this.pairing.get(e.pairing.topic);this.logger.trace({type:"method",method:"connect",pairing:t});const n=e.metadata||this.metadata;if(void 0===n){const e=b.MISSING_OR_INVALID.format({name:"app metadata"});throw this.logger.error(e.message),new Error(e.message)}const r=await this.session.create({signal:{method:"pairing",params:{topic:t.topic}},relay:e.relay||{protocol:"waku"},metadata:n,permissions:Object.assign(Object.assign({},e.permissions),{notifications:ve.notifications})});return this.logger.debug("Application Connection Successful"),this.logger.trace({type:"method",method:"connect",session:r}),r}catch(e){throw this.logger.debug("Application Connection Failure"),this.logger.error(e),e}}async pair(e){this.logger.debug("Pairing"),this.logger.trace({type:"method",method:"pair",params:e});const t=function(e){const t=function(e){const t=e.indexOf(":"),n=-1!==e.indexOf("?")?e.indexOf("?"):void 0,r=e.substring(0,t),i=e.substring(t+1,n).split("@"),o=void 0!==n?e.substr(n):"",s=_.parse(o);return{protocol:r,topic:i[0],version:parseInt(i[1],10),publicKey:s.publicKey,controller:"true"===s.controller,relay:Object(w.a)(s.relay)}}(e);return{topic:t.topic,relay:t.relay,proposer:{publicKey:t.publicKey,controller:t.controller},signal:{method:"uri",params:{uri:e}},permissions:{jsonrpc:{methods:[pe.propose]},notifications:{types:[]}},ttl:2592e3}}(e.uri),n=t.proposer.controller!==this.controller,r=n?void 0:b.UNAUTHORIZED_MATCHING_CONTROLLER.format({controller:this.controller}),i=await this.pairing.respond({approved:n,proposal:t,reason:r});if(!function(e){return S(e.status)&&"outcome"in e}(i)){const e=b.NO_MATCHING_RESPONSE.format({context:"pairing"});throw this.logger.error(e.message),new Error(e.message)}if("reason"in i.outcome)throw this.logger.debug("Pairing Failure"),this.logger.trace({type:"method",method:"pair",outcome:i.outcome}),new Error(i.outcome.reason.message);this.logger.debug("Pairing Success"),this.logger.trace({type:"method",method:"pair",pending:i});return await this.pairing.get(i.outcome.topic)}async approve(e){if(this.logger.debug("Approving Session Proposal"),this.logger.trace({type:"method",method:"approve",params:e}),void 0===e.response){const e=b.MISSING_RESPONSE.format({context:"session"});throw this.logger.error(e.message),new Error(e.message)}const t=e.response.state||me,n=e.response.metadata||this.metadata;if(void 0===n){const e=b.MISSING_OR_INVALID.format({name:"app metadata"});throw this.logger.error(e.message),new Error(e.message)}const r=e.proposal.proposer.controller!==this.controller,i=r?void 0:b.UNAUTHORIZED_MATCHING_CONTROLLER.format({controller:this.controller}),o=await this.session.respond({approved:r,proposal:e.proposal,response:{state:t,metadata:n},reason:i});if(!function(e){return S(e.status)&&"outcome"in e}(o)){const e=b.NO_MATCHING_RESPONSE.format({context:"session"});throw this.logger.error(e.message),new Error(e.message)}if("reason"in o.outcome)throw this.logger.debug("Session Proposal Approval Failure"),this.logger.trace({type:"method",method:"approve",outcome:o.outcome}),new Error(o.outcome.reason.message);return this.logger.debug("Session Proposal Approval Success"),this.logger.trace({type:"method",method:"approve",pending:o}),this.session.get(o.outcome.topic)}async reject(e){this.logger.debug("Rejecting Session Proposal"),this.logger.trace({type:"method",method:"reject",params:e});const t=await this.session.respond({approved:!1,proposal:e.proposal,response:Ee,reason:e.reason});this.logger.debug("Session Proposal Response Success"),this.logger.trace({type:"method",method:"reject",pending:t})}async upgrade(e){await this.session.upgrade(e)}async update(e){await this.session.update(e)}async request(e){return this.session.request(e)}async respond(e){await this.session.send(e.topic,e.response)}async ping(e){await this.session.ping(e.topic,e.timeout)}async notify(e){await this.session.notify(e)}async disconnect(e){this.logger.debug("Disconnecting Application"),this.logger.trace({type:"method",method:"disconnect",params:e}),await this.session.delete(e)}async onPairingRequest(e,t){if(e.method===pe.propose){const n=e.params;if(n.proposer.controller===this.controller){const e=b.UNAUTHORIZED_MATCHING_CONTROLLER.format({controller:this.controller});return void await this.session.respond({approved:!1,proposal:n,response:Ee,reason:e})}const r=G.proposal;this.logger.info("Emitting "+r),this.logger.debug({type:"event",event:r,data:n}),this.events.emit(r,n);const i=Object(o.formatJsonRpcResult)(e.id,!0);await this.pairing.send(t,i)}}async onPairingSettled(e){e.permissions.controller.publicKey===e.self.publicKey&&void 0===e.state.metadata&&setTimeout(async()=>await this.pairing.update({topic:e.topic,state:{metadata:this.metadata}}),50)}async initialize(){this.logger.trace("Initialized");try{await this.pairing.init(),await this.session.init(),await this.crypto.init(),await this.relayer.init(),await this.heartbeat.init(),this.registerEventListeners(),this.logger.info("Client Initilization Success")}catch(e){throw this.logger.info("Client Initilization Failure"),this.logger.error(e),e}}registerEventListeners(){this.pairing.on(ie.proposed,e=>{const t=B.proposal;this.logger.info("Emitting "+t),this.logger.debug({type:"event",event:t,data:e.proposal}),this.events.emit(t,e.proposal)}),this.pairing.on(ie.settled,e=>{const t=B.created;this.logger.info("Emitting "+t),this.logger.debug({type:"event",event:t,data:e}),this.events.emit(t,e),this.onPairingSettled(e)}),this.pairing.on(ie.updated,(e,t)=>{const n=B.updated;this.logger.info("Emitting "+n),this.logger.debug({type:"event",event:n,data:e,update:t}),this.events.emit(n,e,t)}),this.pairing.on(ie.deleted,(e,t)=>{const n=B.deleted;this.logger.info("Emitting "+n),this.logger.debug({type:"event",event:n,data:e,reason:t}),this.events.emit(n,e,t)}),this.pairing.on(ie.request,e=>{this.onPairingRequest(e.request,e.topic)}),this.session.on(ie.sync,()=>this.events.emit(B.sync)),this.session.on(ye.proposed,e=>{const t=G.proposal;this.logger.info("Emitting "+t),this.logger.debug({type:"event",event:t,data:e.proposal}),this.events.emit(t,e.proposal)}),this.session.on(ye.settled,e=>{const t=G.created;this.logger.info("Emitting "+t),this.logger.debug({type:"event",event:t,data:e}),this.events.emit(t,e)}),this.session.on(ye.updated,(e,t)=>{const n=G.updated;this.logger.info("Emitting "+n),this.logger.debug({type:"event",event:n,data:e,update:t}),this.events.emit(n,e,t)}),this.session.on(ye.deleted,(e,t)=>{const n=G.deleted;this.logger.info("Emitting "+n),this.logger.debug({type:"event",event:n,data:e,reason:t}),this.events.emit(n,e,t)}),this.session.on(ye.request,e=>{const t=G.request;this.logger.info("Emitting "+t),this.logger.debug({type:"event",event:t,data:e}),this.events.emit(t,e)}),this.session.on(ye.response,e=>{const t=G.response;this.logger.info("Emitting "+t),this.logger.debug({type:"event",event:t,data:e}),this.events.emit(t,e)}),this.session.on(ye.notification,e=>{const t=G.notification;this.logger.info("Emitting "+t),this.logger.debug({type:"event",event:t,data:e}),this.events.emit(t,e)}),this.session.on(ye.sync,()=>this.events.emit(G.sync))}}const tt=et;const nt={init:"signer_init",uri:"signer_uri",created:"signer_created",updated:"signer_updated",deleted:"signer_deleted",notification:"signer_notification"};class rt extends i.IJsonRpcConnection{constructor(e){super(),this.events=new r.EventEmitter,this.pending=!1,this.initializing=!1,this.chains=(null==e?void 0:e.chains)||[],this.methods=(null==e?void 0:e.methods)||[],this.opts=null==e?void 0:e.client}get connected(){return void 0!==this.session}get connecting(){return this.pending}get accounts(){var e;return(null===(e=this.session)||void 0===e?void 0:e.state.accounts)||[]}on(e,t){this.events.on(e,t)}once(e,t){this.events.once(e,t)}off(e,t){this.events.off(e,t)}removeListener(e,t){this.events.removeListener(e,t)}async open(){if(this.pending)return new Promise((e,t)=>{this.events.once("open",()=>{if(this.events.once("open_error",e=>{t(e)}),void 0===this.client)return t(new Error("Client not initialized"));e()})});try{this.pending=!0;const e=await this.register(),t=await e.session.find({blockchain:{chains:this.chains},jsonrpc:{methods:this.methods}});if(t.length)return this.onOpen(t[0]);this.session=await e.connect({permissions:{blockchain:{chains:this.chains},jsonrpc:{methods:this.methods}}}),this.onOpen()}catch(e){throw this.events.emit("open_error",e),e}}async close(){if(void 0===this.session)return;const e=await this.register();await e.disconnect({topic:this.session.topic,reason:b.USER_DISCONNECTED.format()}),this.onClose()}async send(e,t){if(void 0===this.client&&(this.client=await this.register(),this.connected||await this.open()),void 0===this.session)throw new Error("Signer connection is missing session");this.client.request({topic:this.session.topic,request:e,chainId:null==t?void 0:t.chainId}).then(t=>this.events.emit("payload",Object(o.formatJsonRpcResult)(e.id,t))).catch(t=>this.events.emit("payload",Object(o.formatJsonRpcError)(e.id,t.message)))}async register(e=this.opts){if(void 0!==this.client)return this.client;if(this.initializing)return new Promise((e,t)=>{this.events.once("register_error",e=>{t(e)}),this.events.once(nt.init,()=>{if(void 0===this.client)return t(new Error("Client not initialized"));e(this.client)})});if(function(e){return void 0!==e&&void 0!==e.context}(e))return this.client=e,this.registerEventListeners(),this.client;try{return this.initializing=!0,this.client=await tt.init(e),this.initializing=!1,this.registerEventListeners(),this.events.emit(nt.init),this.client}catch(e){throw this.events.emit("register_error",e),e}}onOpen(e){this.pending=!1,e&&(this.session=e),this.events.emit("open")}onClose(){this.pending=!1,this.client&&(this.client=void 0),this.events.emit("close")}registerEventListeners(){void 0!==this.client&&(this.client.on(G.created,e=>{var t;this.session&&(null===(t=this.session)||void 0===t?void 0:t.topic)!==e.topic||(this.session=e,this.events.emit(nt.created,e))}),this.client.on(G.updated,e=>{var t;this.session&&(null===(t=this.session)||void 0===t?void 0:t.topic)!==e.topic||(this.session=e,this.events.emit(nt.updated,e))}),this.client.on(G.notification,e=>{var t;this.session&&(null===(t=this.session)||void 0===t?void 0:t.topic)!==e.topic||this.events.emit(nt.notification,e.notification)}),this.client.on(G.deleted,e=>{var t;this.session&&(this.session&&(null===(t=this.session)||void 0===t?void 0:t.topic)!==e.topic||(this.onClose(),this.events.emit(nt.deleted,e),this.session=void 0))}),this.client.on(B.proposal,async e=>{const t=e.signal.params.uri;this.events.emit(nt.uri,{uri:t})}))}}t.default=rt},function(e,t,n){"use strict";n.r(t),n.d(t,"HttpConnection",(function(){return u}));var r=n(3),i=n(29),o=n.n(i),s=n(8),a=n(0);const c={headers:{Accept:"application/json","Content-Type":"application/json"},method:"POST"};class u{constructor(e){if(this.url=e,this.events=new r.EventEmitter,this.isAvailable=!1,this.registering=!1,!Object(a.isHttpUrl)(e))throw new Error("Provided URL is not compatible with HTTP connection: "+e);this.url=e}get connected(){return this.isAvailable}get connecting(){return this.registering}on(e,t){this.events.on(e,t)}once(e,t){this.events.once(e,t)}off(e,t){this.events.off(e,t)}removeListener(e,t){this.events.removeListener(e,t)}async open(e=this.url){await this.register(e)}async close(){if(!this.isAvailable)throw new Error("Connection already closed");this.onClose()}async send(e,t){this.isAvailable||await this.register();try{const t=Object(s.b)(e),n=await o()(this.url,Object.assign(Object.assign({},c),{body:t})),r=await n.json();this.onPayload({data:r})}catch(t){this.onError(e.id,t)}}async register(e=this.url){if(!Object(a.isHttpUrl)(e))throw new Error("Provided URL is not compatible with HTTP connection: "+e);if(this.registering)return new Promise((e,t)=>{this.events.once("register_error",e=>{t(e)}),this.events.once("open",()=>{if(void 0===this.isAvailable)return t(new Error("HTTP connection is missing or invalid"));e()})});this.url=e,this.registering=!0;try{const t=Object(s.b)({id:1,jsonrpc:"2.0",method:"test",params:[]});await o()(e,Object.assign(Object.assign({},c),{body:t})),this.onOpen()}catch(e){const t=this.parseError(e);throw this.events.emit("register_error",t),this.onClose(),t}}onOpen(){this.isAvailable=!0,this.registering=!1,this.events.emit("open")}onClose(){this.isAvailable=!1,this.registering=!1,this.events.emit("close")}onPayload(e){if(void 0===e.data)return;const t="string"==typeof e.data?Object(s.a)(e.data):e.data;this.events.emit("payload",t)}onError(e,t){const n=this.parseError(t),r=n.message||n.toString(),i=Object(a.formatJsonRpcError)(e,r);this.events.emit("payload",i)}parseError(e,t=this.url){return Object(a.parseConnectionError)(e,t,"HTTP")}}var h=u;t.default=h}])}));
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@walletconnect/ethereum-provider",
|
|
3
3
|
"description": "Ethereum Provider for WalletConnect Protocol",
|
|
4
|
-
"version": "2.0.0-beta.20.
|
|
4
|
+
"version": "2.0.0-beta.20.5",
|
|
5
5
|
"author": "WalletConnect, Inc. <walletconnect.com>",
|
|
6
6
|
"homepage": "https://github.com/walletconnect/walletconnect-monorepo/",
|
|
7
7
|
"repository": {
|
|
@@ -34,14 +34,14 @@
|
|
|
34
34
|
"lint": "eslint -c '../../.eslintrc' --fix './src/**/*.ts'"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@walletconnect/client": "^2.0.0-beta.20.
|
|
37
|
+
"@walletconnect/client": "^2.0.0-beta.20.5",
|
|
38
38
|
"@walletconnect/jsonrpc-http-connection": "^1.0.0",
|
|
39
39
|
"@walletconnect/jsonrpc-provider": "^1.0.0",
|
|
40
40
|
"@walletconnect/jsonrpc-types": "^1.0.0",
|
|
41
41
|
"@walletconnect/jsonrpc-utils": "^1.0.0",
|
|
42
|
-
"@walletconnect/signer-connection": "^2.0.0-beta.20.
|
|
43
|
-
"@walletconnect/types": "^2.0.0-beta.20.
|
|
44
|
-
"@walletconnect/utils": "^2.0.0-beta.20.
|
|
42
|
+
"@walletconnect/signer-connection": "^2.0.0-beta.20.5",
|
|
43
|
+
"@walletconnect/types": "^2.0.0-beta.20.5",
|
|
44
|
+
"@walletconnect/utils": "^2.0.0-beta.20.5",
|
|
45
45
|
"eip1193-provider": "^1.0.1"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|