@walletconnect/ethereum-provider 2.7.4 → 2.7.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/index.umd.js +2 -2
- package/dist/index.umd.js.map +1 -1
- package/package.json +5 -5
package/dist/index.umd.js
CHANGED
|
@@ -69,7 +69,7 @@
|
|
|
69
69
|
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
70
70
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
71
71
|
PERFORMANCE OF THIS SOFTWARE.
|
|
72
|
-
***************************************************************************** */var Gu=function(t,e){return Gu=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,n){r.__proto__=n}||function(r,n){for(var i in n)n.hasOwnProperty(i)&&(r[i]=n[i])},Gu(t,e)};function z4(t,e){Gu(t,e);function r(){this.constructor=t}t.prototype=e===null?Object.create(e):(r.prototype=e.prototype,new r)}var Zu=function(){return Zu=Object.assign||function(e){for(var r,n=1,i=arguments.length;n<i;n++){r=arguments[n];for(var o in r)Object.prototype.hasOwnProperty.call(r,o)&&(e[o]=r[o])}return e},Zu.apply(this,arguments)};function W4(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,n=Object.getOwnPropertySymbols(t);i<n.length;i++)e.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(t,n[i])&&(r[n[i]]=t[n[i]]);return r}function q4(t,e,r,n){var i=arguments.length,o=i<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,r):n,c;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")o=Reflect.decorate(t,e,r,n);else for(var l=t.length-1;l>=0;l--)(c=t[l])&&(o=(i<3?c(o):i>3?c(e,r,o):c(e,r))||o);return i>3&&o&&Object.defineProperty(e,r,o),o}function V4(t,e){return function(r,n){e(r,n,t)}}function K4(t,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(t,e)}function G4(t,e,r,n){function i(o){return o instanceof r?o:new r(function(c){c(o)})}return new(r||(r=Promise))(function(o,c){function l(v){try{d(n.next(v))}catch(E){c(E)}}function h(v){try{d(n.throw(v))}catch(E){c(E)}}function d(v){v.done?o(v.value):i(v.value).then(l,h)}d((n=n.apply(t,e||[])).next())})}function Z4(t,e){var r={label:0,sent:function(){if(o[0]&1)throw o[1];return o[1]},trys:[],ops:[]},n,i,o,c;return c={next:l(0),throw:l(1),return:l(2)},typeof Symbol=="function"&&(c[Symbol.iterator]=function(){return this}),c;function l(d){return function(v){return h([d,v])}}function h(d){if(n)throw new TypeError("Generator is already executing.");for(;r;)try{if(n=1,i&&(o=d[0]&2?i.return:d[0]?i.throw||((o=i.return)&&o.call(i),0):i.next)&&!(o=o.call(i,d[1])).done)return o;switch(i=0,o&&(d=[d[0]&2,o.value]),d[0]){case 0:case 1:o=d;break;case 4:return r.label++,{value:d[1],done:!1};case 5:r.label++,i=d[1],d=[0];continue;case 7:d=r.ops.pop(),r.trys.pop();continue;default:if(o=r.trys,!(o=o.length>0&&o[o.length-1])&&(d[0]===6||d[0]===2)){r=0;continue}if(d[0]===3&&(!o||d[1]>o[0]&&d[1]<o[3])){r.label=d[1];break}if(d[0]===6&&r.label<o[1]){r.label=o[1],o=d;break}if(o&&r.label<o[2]){r.label=o[2],r.ops.push(d);break}o[2]&&r.ops.pop(),r.trys.pop();continue}d=e.call(t,r)}catch(v){d=[6,v],i=0}finally{n=o=0}if(d[0]&5)throw d[1];return{value:d[0]?d[1]:void 0,done:!0}}}function Y4(t,e,r,n){n===void 0&&(n=r),t[n]=e[r]}function J4(t,e){for(var r in t)r!=="default"&&!e.hasOwnProperty(r)&&(e[r]=t[r])}function Yu(t){var e=typeof Symbol=="function"&&Symbol.iterator,r=e&&t[e],n=0;if(r)return r.call(t);if(t&&typeof t.length=="number")return{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function bp(t,e){var r=typeof Symbol=="function"&&t[Symbol.iterator];if(!r)return t;var n=r.call(t),i,o=[],c;try{for(;(e===void 0||e-- >0)&&!(i=n.next()).done;)o.push(i.value)}catch(l){c={error:l}}finally{try{i&&!i.done&&(r=n.return)&&r.call(n)}finally{if(c)throw c.error}}return o}function X4(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(bp(arguments[e]));return t}function Q4(){for(var t=0,e=0,r=arguments.length;e<r;e++)t+=arguments[e].length;for(var n=Array(t),i=0,e=0;e<r;e++)for(var o=arguments[e],c=0,l=o.length;c<l;c++,i++)n[i]=o[c];return n}function jo(t){return this instanceof jo?(this.v=t,this):new jo(t)}function e_(t,e,r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n=r.apply(t,e||[]),i,o=[];return i={},c("next"),c("throw"),c("return"),i[Symbol.asyncIterator]=function(){return this},i;function c(_){n[_]&&(i[_]=function(O){return new Promise(function(P,U){o.push([_,O,P,U])>1||l(_,O)})})}function l(_,O){try{h(n[_](O))}catch(P){E(o[0][3],P)}}function h(_){_.value instanceof jo?Promise.resolve(_.value.v).then(d,v):E(o[0][2],_)}function d(_){l("next",_)}function v(_){l("throw",_)}function E(_,O){_(O),o.shift(),o.length&&l(o[0][0],o[0][1])}}function t_(t){var e,r;return e={},n("next"),n("throw",function(i){throw i}),n("return"),e[Symbol.iterator]=function(){return this},e;function n(i,o){e[i]=t[i]?function(c){return(r=!r)?{value:jo(t[i](c)),done:i==="return"}:o?o(c):c}:o}}function r_(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e=t[Symbol.asyncIterator],r;return e?e.call(t):(t=typeof Yu=="function"?Yu(t):t[Symbol.iterator](),r={},n("next"),n("throw"),n("return"),r[Symbol.asyncIterator]=function(){return this},r);function n(o){r[o]=t[o]&&function(c){return new Promise(function(l,h){c=t[o](c),i(l,h,c.done,c.value)})}}function i(o,c,l,h){Promise.resolve(h).then(function(d){o({value:d,done:l})},c)}}function n_(t,e){return Object.defineProperty?Object.defineProperty(t,"raw",{value:e}):t.raw=e,t}function i_(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)Object.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e.default=t,e}function s_(t){return t&&t.__esModule?t:{default:t}}function o_(t,e){if(!e.has(t))throw new TypeError("attempted to get private field on non-instance");return e.get(t)}function a_(t,e,r){if(!e.has(t))throw new TypeError("attempted to set private field on non-instance");return e.set(t,r),r}var c_=Object.freeze({__proto__:null,__extends:z4,get __assign(){return Zu},__rest:W4,__decorate:q4,__param:V4,__metadata:K4,__awaiter:G4,__generator:Z4,__createBinding:Y4,__exportStar:J4,__values:Yu,__read:bp,__spread:X4,__spreadArrays:Q4,__await:jo,__asyncGenerator:e_,__asyncDelegator:t_,__asyncValues:r_,__makeTemplateObject:n_,__importStar:i_,__importDefault:s_,__classPrivateFieldGet:o_,__classPrivateFieldSet:a_}),l_=Li(c_),zn={},_p;function u_(){if(_p)return zn;_p=1,Object.defineProperty(zn,"__esModule",{value:!0}),zn.isBrowserCryptoAvailable=zn.getSubtleCrypto=zn.getBrowerCrypto=void 0;function t(){return fr?.crypto||fr?.msCrypto||{}}zn.getBrowerCrypto=t;function e(){const n=t();return n.subtle||n.webkitSubtle}zn.getSubtleCrypto=e;function r(){return!!t()&&!!e()}return zn.isBrowserCryptoAvailable=r,zn}var Wn={},Ep;function h_(){if(Ep)return Wn;Ep=1,Object.defineProperty(Wn,"__esModule",{value:!0}),Wn.isBrowser=Wn.isNode=Wn.isReactNative=void 0;function t(){return typeof document>"u"&&typeof navigator<"u"&&navigator.product==="ReactNative"}Wn.isReactNative=t;function e(){return typeof process<"u"&&typeof process.versions<"u"&&typeof process.versions.node<"u"}Wn.isNode=e;function r(){return!t()&&!e()}return Wn.isBrowser=r,Wn}(function(t){Object.defineProperty(t,"__esModule",{value:!0});const e=l_;e.__exportStar(u_(),t),e.__exportStar(h_(),t)})(yp);function xp(t=3){const e=Date.now()*Math.pow(10,t),r=Math.floor(Math.random()*Math.pow(10,t));return e+r}function f_(t=6){return BigInt(xp(t))}function ec(t,e,r){return{id:r||xp(),jsonrpc:"2.0",method:t,params:e}}function Ju(t,e){return{id:t,jsonrpc:"2.0",result:e}}function tc(t,e,r){return{id:t,jsonrpc:"2.0",error:d_(e,r)}}function d_(t,e){return typeof t>"u"?wp(gp):(typeof t=="string"&&(t=Object.assign(Object.assign({},wp(Ku)),{message:t})),typeof e<"u"&&(t.data=e),k4(t.code)&&(t=H4(t.code)),t)}class p_{}class g_ extends p_{constructor(){super()}}class m_ extends g_{constructor(e){super()}}const w_="^https?:",v_="^wss?:";function y_(t){const e=t.match(new RegExp(/^\w+:/,"gi"));if(!(!e||!e.length))return e[0]}function Cp(t,e){const r=y_(t);return typeof r>"u"?!1:new RegExp(e).test(r)}function Ip(t){return Cp(t,w_)}function Sp(t){return Cp(t,v_)}function b_(t){return new RegExp("wss?://localhost(:d{2,5})?").test(t)}function Op(t){return typeof t=="object"&&"id"in t&&"jsonrpc"in t&&t.jsonrpc==="2.0"}function Xu(t){return Op(t)&&"method"in t}function Qu(t){return Op(t)&&(qn(t)||_n(t))}function qn(t){return"result"in t}function _n(t){return"error"in t}class ui extends m_{constructor(e){super(e),this.events=new yr.exports.EventEmitter,this.hasRegisteredEventListeners=!1,this.connection=this.setConnection(e),this.connection.connected&&this.registerEventListeners()}async connect(e=this.connection){await this.open(e)}async disconnect(){await this.close()}on(e,r){this.events.on(e,r)}once(e,r){this.events.once(e,r)}off(e,r){this.events.off(e,r)}removeListener(e,r){this.events.removeListener(e,r)}async request(e,r){return this.requestStrict(ec(e.method,e.params||[],f_().toString()),r)}async requestStrict(e,r){return new Promise(async(n,i)=>{if(!this.connection.connected)try{await this.open()}catch(o){i(o)}this.events.on(`${e.id}`,o=>{_n(o)?i(o.error):n(o.result)});try{await this.connection.send(e,r)}catch(o){i(o)}})}setConnection(e=this.connection){return e}onPayload(e){this.events.emit("payload",e),Qu(e)?this.events.emit(`${e.id}`,e):this.events.emit("message",{type:e.method,data:e.params})}onClose(e){e&&e.code===3e3&&this.events.emit("error",new Error(`WebSocket connection closed abnormally with code: ${e.code} ${e.reason?`(${e.reason})`:""}`)),this.events.emit("disconnect")}async open(e=this.connection){this.connection===e&&this.connection.connected||(this.connection.connected&&this.close(),typeof e=="string"&&(await this.connection.open(e),e=this.connection),this.connection=this.setConnection(e),await this.connection.open(),this.registerEventListeners(),this.events.emit("connect"))}async close(){await this.connection.close()}registerEventListeners(){this.hasRegisteredEventListeners||(this.connection.on("payload",e=>this.onPayload(e)),this.connection.on("close",e=>this.onClose(e)),this.connection.on("error",e=>this.events.emit("error",e)),this.connection.on("register_error",e=>this.onClose()),this.hasRegisteredEventListeners=!0)}}const Ap=10,__=()=>typeof global<"u"&&typeof global.WebSocket<"u"?global.WebSocket:typeof window<"u"&&typeof window.WebSocket<"u"?window.WebSocket:require("ws"),E_=()=>typeof window<"u",x_=__();class C_{constructor(e){if(this.url=e,this.events=new yr.exports.EventEmitter,this.registering=!1,!Sp(e))throw new Error(`Provided URL is not compatible with WebSocket connection: ${e}`);this.url=e}get connected(){return typeof this.socket<"u"}get connecting(){return this.registering}on(e,r){this.events.on(e,r)}once(e,r){this.events.once(e,r)}off(e,r){this.events.off(e,r)}removeListener(e,r){this.events.removeListener(e,r)}async open(e=this.url){await this.register(e)}async close(){return new Promise((e,r)=>{if(typeof this.socket>"u"){r(new Error("Connection already closed"));return}this.socket.onclose=n=>{this.onClose(n),e()},this.socket.close()})}async send(e,r){typeof this.socket>"u"&&(this.socket=await this.register());try{this.socket.send(Mo(e))}catch(n){this.onError(e.id,n)}}register(e=this.url){if(!Sp(e))throw new Error(`Provided URL is not compatible with WebSocket connection: ${e}`);if(this.registering){const r=this.events.getMaxListeners();return(this.events.listenerCount("register_error")>=r||this.events.listenerCount("open")>=r)&&this.events.setMaxListeners(r+1),new Promise((n,i)=>{this.events.once("register_error",o=>{this.resetMaxListeners(),i(o)}),this.events.once("open",()=>{if(this.resetMaxListeners(),typeof this.socket>"u")return i(new Error("WebSocket connection is missing or invalid"));n(this.socket)})})}return this.url=e,this.registering=!0,new Promise((r,n)=>{const i=yp.isReactNative()?void 0:{rejectUnauthorized:!b_(e)},o=new x_(e,[],i);E_()?o.onerror=c=>{const l=c;n(this.emitError(l.error))}:o.on("error",c=>{n(this.emitError(c))}),o.onopen=()=>{this.onOpen(o),r(o)}})}onOpen(e){e.onmessage=r=>this.onPayload(r),e.onclose=r=>this.onClose(r),this.socket=e,this.registering=!1,this.events.emit("open")}onClose(e){this.socket=void 0,this.registering=!1,this.events.emit("close",e)}onPayload(e){if(typeof e.data>"u")return;const r=typeof e.data=="string"?qu(e.data):e.data;this.events.emit("payload",r)}onError(e,r){const n=this.parseError(r),i=n.message||n.toString(),o=tc(e,i);this.events.emit("payload",o)}parseError(e,r=this.url){return vp(e,r,"WS")}resetMaxListeners(){this.events.getMaxListeners()>Ap&&this.events.setMaxListeners(Ap)}emitError(e){const r=this.parseError(new Error(e?.message||`WebSocket connection failed for URL: ${this.url}`));return this.events.emit("register_error",r),r}}var eh={exports:{}};(function(t,e){var r=200,n="__lodash_hash_undefined__",i=1,o=2,c=9007199254740991,l="[object Arguments]",h="[object Array]",d="[object AsyncFunction]",v="[object Boolean]",E="[object Date]",_="[object Error]",O="[object Function]",P="[object GeneratorFunction]",U="[object Map]",H="[object Number]",G="[object Null]",N="[object Object]",L="[object Promise]",$="[object Proxy]",T="[object RegExp]",I="[object Set]",f="[object String]",x="[object Symbol]",J="[object Undefined]",z="[object WeakMap]",ee="[object ArrayBuffer]",de="[object DataView]",me="[object Float32Array]",S="[object Float64Array]",j="[object Int8Array]",ce="[object Int16Array]",le="[object Int32Array]",re="[object Uint8Array]",ne="[object Uint8ClampedArray]",ae="[object Uint16Array]",ie="[object Uint32Array]",Ae=/[\\^$.*+?()[\]{}|]/g,ge=/^\[object .+?Constructor\]$/,Fe=/^(?:0|[1-9]\d*)$/,ye={};ye[me]=ye[S]=ye[j]=ye[ce]=ye[le]=ye[re]=ye[ne]=ye[ae]=ye[ie]=!0,ye[l]=ye[h]=ye[ee]=ye[v]=ye[de]=ye[E]=ye[_]=ye[O]=ye[U]=ye[H]=ye[N]=ye[T]=ye[I]=ye[f]=ye[z]=!1;var Le=typeof fr=="object"&&fr&&fr.Object===Object&&fr,X=typeof self=="object"&&self&&self.Object===Object&&self,Y=Le||X||Function("return this")(),W=e&&!e.nodeType&&e,w=W&&!0&&t&&!t.nodeType&&t,F=w&&w.exports===W,we=F&&Le.process,ve=function(){try{return we&&we.binding&&we.binding("util")}catch{}}(),Me=ve&&ve.isTypedArray;function nt(R,q){for(var fe=-1,Ce=R==null?0:R.length,It=0,Xe=[];++fe<Ce;){var Tt=R[fe];q(Tt,fe,R)&&(Xe[It++]=Tt)}return Xe}function at(R,q){for(var fe=-1,Ce=q.length,It=R.length;++fe<Ce;)R[It+fe]=q[fe];return R}function Ge(R,q){for(var fe=-1,Ce=R==null?0:R.length;++fe<Ce;)if(q(R[fe],fe,R))return!0;return!1}function Dt(R,q){for(var fe=-1,Ce=Array(R);++fe<R;)Ce[fe]=q(fe);return Ce}function $t(R){return function(q){return R(q)}}function Je(R,q){return R.has(q)}function He(R,q){return R?.[q]}function Be(R){var q=-1,fe=Array(R.size);return R.forEach(function(Ce,It){fe[++q]=[It,Ce]}),fe}function Ke(R,q){return function(fe){return R(q(fe))}}function rt(R){var q=-1,fe=Array(R.size);return R.forEach(function(Ce){fe[++q]=Ce}),fe}var Ue=Array.prototype,Ze=Function.prototype,b=Object.prototype,p=Y["__core-js_shared__"],m=Ze.toString,D=b.hasOwnProperty,B=function(){var R=/[^.]+$/.exec(p&&p.keys&&p.keys.IE_PROTO||"");return R?"Symbol(src)_1."+R:""}(),K=b.toString,Q=RegExp("^"+m.call(D).replace(Ae,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),Ee=F?Y.Buffer:void 0,Te=Y.Symbol,st=Y.Uint8Array,ht=b.propertyIsEnumerable,lt=Ue.splice,Mr=Te?Te.toStringTag:void 0,Yn=Object.getOwnPropertySymbols,Ci=Ee?Ee.isBuffer:void 0,ls=Ke(Object.keys,Object),Ht=Xr(Y,"DataView"),Lt=Xr(Y,"Map"),zt=Xr(Y,"Promise"),Wt=Xr(Y,"Set"),Ft=Xr(Y,"WeakMap"),Mt=Xr(Object,"create"),rr=Xn(Ht),nr=Xn(Lt),qt=Xn(zt),ir=Xn(Wt),Vt=Xn(Ft),Yt=Te?Te.prototype:void 0,Kt=Yt?Yt.valueOf:void 0;function Pt(R){var q=-1,fe=R==null?0:R.length;for(this.clear();++q<fe;){var Ce=R[q];this.set(Ce[0],Ce[1])}}function sr(){this.__data__=Mt?Mt(null):{},this.size=0}function or(R){var q=this.has(R)&&delete this.__data__[R];return this.size-=q?1:0,q}function Uf(R){var q=this.__data__;if(Mt){var fe=q[R];return fe===n?void 0:fe}return D.call(q,R)?q[R]:void 0}function jf(R){var q=this.__data__;return Mt?q[R]!==void 0:D.call(q,R)}function Ff(R,q){var fe=this.__data__;return this.size+=this.has(R)?0:1,fe[R]=Mt&&q===void 0?n:q,this}Pt.prototype.clear=sr,Pt.prototype.delete=or,Pt.prototype.get=Uf,Pt.prototype.has=jf,Pt.prototype.set=Ff;function hn(R){var q=-1,fe=R==null?0:R.length;for(this.clear();++q<fe;){var Ce=R[q];this.set(Ce[0],Ce[1])}}function Bf(){this.__data__=[],this.size=0}function kf(R){var q=this.__data__,fe=us(q,R);if(fe<0)return!1;var Ce=q.length-1;return fe==Ce?q.pop():lt.call(q,fe,1),--this.size,!0}function Hf(R){var q=this.__data__,fe=us(q,R);return fe<0?void 0:q[fe][1]}function zf(R){return us(this.__data__,R)>-1}function Wf(R,q){var fe=this.__data__,Ce=us(fe,R);return Ce<0?(++this.size,fe.push([R,q])):fe[Ce][1]=q,this}hn.prototype.clear=Bf,hn.prototype.delete=kf,hn.prototype.get=Hf,hn.prototype.has=zf,hn.prototype.set=Wf;function Jn(R){var q=-1,fe=R==null?0:R.length;for(this.clear();++q<fe;){var Ce=R[q];this.set(Ce[0],Ce[1])}}function Xs(){this.size=0,this.__data__={hash:new Pt,map:new(Lt||hn),string:new Pt}}function qf(R){var q=Ii(this,R).delete(R);return this.size-=q?1:0,q}function Qs(R){return Ii(this,R).get(R)}function Vf(R){return Ii(this,R).has(R)}function Kf(R,q){var fe=Ii(this,R),Ce=fe.size;return fe.set(R,q),this.size+=fe.size==Ce?0:1,this}Jn.prototype.clear=Xs,Jn.prototype.delete=qf,Jn.prototype.get=Qs,Jn.prototype.has=Vf,Jn.prototype.set=Kf;function eo(R){var q=-1,fe=R==null?0:R.length;for(this.__data__=new Jn;++q<fe;)this.add(R[q])}function Kc(R){return this.__data__.set(R,n),this}function Gc(R){return this.__data__.has(R)}eo.prototype.add=eo.prototype.push=Kc,eo.prototype.has=Gc;function En(R){var q=this.__data__=new hn(R);this.size=q.size}function Gf(){this.__data__=new hn,this.size=0}function Zf(R){var q=this.__data__,fe=q.delete(R);return this.size=q.size,fe}function Yf(R){return this.__data__.get(R)}function Jf(R){return this.__data__.has(R)}function Zc(R,q){var fe=this.__data__;if(fe instanceof hn){var Ce=fe.__data__;if(!Lt||Ce.length<r-1)return Ce.push([R,q]),this.size=++fe.size,this;fe=this.__data__=new Jn(Ce)}return fe.set(R,q),this.size=fe.size,this}En.prototype.clear=Gf,En.prototype.delete=Zf,En.prototype.get=Yf,En.prototype.has=Jf,En.prototype.set=Zc;function Yc(R,q){var fe=no(R),Ce=!fe&&cl(R),It=!fe&&!Ce&&va(R),Xe=!fe&&!Ce&&!It&&hl(R),Tt=fe||Ce||It||Xe,ar=Tt?Dt(R.length,String):[],mt=ar.length;for(var St in R)(q||D.call(R,St))&&!(Tt&&(St=="length"||It&&(St=="offset"||St=="parent")||Xe&&(St=="buffer"||St=="byteLength"||St=="byteOffset")||nl(St,mt)))&&ar.push(St);return ar}function us(R,q){for(var fe=R.length;fe--;)if(al(R[fe][0],q))return fe;return-1}function ma(R,q,fe){var Ce=q(R);return no(R)?Ce:at(Ce,fe(R))}function hs(R){return R==null?R===void 0?J:G:Mr&&Mr in Object(R)?tl(R):e0(R)}function wa(R){return ds(R)&&hs(R)==l}function fs(R,q,fe,Ce,It){return R===q?!0:R==null||q==null||!ds(R)&&!ds(q)?R!==R&&q!==q:Jc(R,q,fe,Ce,fs,It)}function Jc(R,q,fe,Ce,It,Xe){var Tt=no(R),ar=no(q),mt=Tt?h:Un(R),St=ar?h:Un(q);mt=mt==l?N:mt,St=St==l?N:St;var Jt=mt==N,Wr=St==N,cr=mt==St;if(cr&&va(R)){if(!va(q))return!1;Tt=!0,Jt=!1}if(cr&&!Jt)return Xe||(Xe=new En),Tt||hl(R)?to(R,q,fe,Ce,It,Xe):Qf(R,q,mt,fe,Ce,It,Xe);if(!(fe&i)){var Rt=Jt&&D.call(R,"__wrapped__"),Ur=Wr&&D.call(q,"__wrapped__");if(Rt||Ur){var xn=Rt?R.value():R,fn=Ur?q.value():q;return Xe||(Xe=new En),It(xn,fn,fe,Ce,Xe)}}return cr?(Xe||(Xe=new En),el(R,q,fe,Ce,It,Xe)):!1}function Xf(R){if(!ul(R)||sl(R))return!1;var q=io(R)?Q:ge;return q.test(Xn(R))}function Xc(R){return ds(R)&&ll(R.length)&&!!ye[hs(R)]}function Qc(R){if(!ol(R))return ls(R);var q=[];for(var fe in Object(R))D.call(R,fe)&&fe!="constructor"&&q.push(fe);return q}function to(R,q,fe,Ce,It,Xe){var Tt=fe&i,ar=R.length,mt=q.length;if(ar!=mt&&!(Tt&&mt>ar))return!1;var St=Xe.get(R);if(St&&Xe.get(q))return St==q;var Jt=-1,Wr=!0,cr=fe&o?new eo:void 0;for(Xe.set(R,q),Xe.set(q,R);++Jt<ar;){var Rt=R[Jt],Ur=q[Jt];if(Ce)var xn=Tt?Ce(Ur,Rt,Jt,q,R,Xe):Ce(Rt,Ur,Jt,R,q,Xe);if(xn!==void 0){if(xn)continue;Wr=!1;break}if(cr){if(!Ge(q,function(fn,jn){if(!Je(cr,jn)&&(Rt===fn||It(Rt,fn,fe,Ce,Xe)))return cr.push(jn)})){Wr=!1;break}}else if(!(Rt===Ur||It(Rt,Ur,fe,Ce,Xe))){Wr=!1;break}}return Xe.delete(R),Xe.delete(q),Wr}function Qf(R,q,fe,Ce,It,Xe,Tt){switch(fe){case de:if(R.byteLength!=q.byteLength||R.byteOffset!=q.byteOffset)return!1;R=R.buffer,q=q.buffer;case ee:return!(R.byteLength!=q.byteLength||!Xe(new st(R),new st(q)));case v:case E:case H:return al(+R,+q);case _:return R.name==q.name&&R.message==q.message;case T:case f:return R==q+"";case U:var ar=Be;case I:var mt=Ce&i;if(ar||(ar=rt),R.size!=q.size&&!mt)return!1;var St=Tt.get(R);if(St)return St==q;Ce|=o,Tt.set(R,q);var Jt=to(ar(R),ar(q),Ce,It,Xe,Tt);return Tt.delete(R),Jt;case x:if(Kt)return Kt.call(R)==Kt.call(q)}return!1}function el(R,q,fe,Ce,It,Xe){var Tt=fe&i,ar=ro(R),mt=ar.length,St=ro(q),Jt=St.length;if(mt!=Jt&&!Tt)return!1;for(var Wr=mt;Wr--;){var cr=ar[Wr];if(!(Tt?cr in q:D.call(q,cr)))return!1}var Rt=Xe.get(R);if(Rt&&Xe.get(q))return Rt==q;var Ur=!0;Xe.set(R,q),Xe.set(q,R);for(var xn=Tt;++Wr<mt;){cr=ar[Wr];var fn=R[cr],jn=q[cr];if(Ce)var ya=Tt?Ce(jn,fn,cr,q,R,Xe):Ce(fn,jn,cr,R,q,Xe);if(!(ya===void 0?fn===jn||It(fn,jn,fe,Ce,Xe):ya)){Ur=!1;break}xn||(xn=cr=="constructor")}if(Ur&&!xn){var ps=R.constructor,wr=q.constructor;ps!=wr&&"constructor"in R&&"constructor"in q&&!(typeof ps=="function"&&ps instanceof ps&&typeof wr=="function"&&wr instanceof wr)&&(Ur=!1)}return Xe.delete(R),Xe.delete(q),Ur}function ro(R){return ma(R,n0,rl)}function Ii(R,q){var fe=R.__data__;return il(q)?fe[typeof q=="string"?"string":"hash"]:fe.map}function Xr(R,q){var fe=He(R,q);return Xf(fe)?fe:void 0}function tl(R){var q=D.call(R,Mr),fe=R[Mr];try{R[Mr]=void 0;var Ce=!0}catch{}var It=K.call(R);return Ce&&(q?R[Mr]=fe:delete R[Mr]),It}var rl=Yn?function(R){return R==null?[]:(R=Object(R),nt(Yn(R),function(q){return ht.call(R,q)}))}:Ct,Un=hs;(Ht&&Un(new Ht(new ArrayBuffer(1)))!=de||Lt&&Un(new Lt)!=U||zt&&Un(zt.resolve())!=L||Wt&&Un(new Wt)!=I||Ft&&Un(new Ft)!=z)&&(Un=function(R){var q=hs(R),fe=q==N?R.constructor:void 0,Ce=fe?Xn(fe):"";if(Ce)switch(Ce){case rr:return de;case nr:return U;case qt:return L;case ir:return I;case Vt:return z}return q});function nl(R,q){return q=q??c,!!q&&(typeof R=="number"||Fe.test(R))&&R>-1&&R%1==0&&R<q}function il(R){var q=typeof R;return q=="string"||q=="number"||q=="symbol"||q=="boolean"?R!=="__proto__":R===null}function sl(R){return!!B&&B in R}function ol(R){var q=R&&R.constructor,fe=typeof q=="function"&&q.prototype||b;return R===fe}function e0(R){return K.call(R)}function Xn(R){if(R!=null){try{return m.call(R)}catch{}try{return R+""}catch{}}return""}function al(R,q){return R===q||R!==R&&q!==q}var cl=wa(function(){return arguments}())?wa:function(R){return ds(R)&&D.call(R,"callee")&&!ht.call(R,"callee")},no=Array.isArray;function t0(R){return R!=null&&ll(R.length)&&!io(R)}var va=Ci||xt;function r0(R,q){return fs(R,q)}function io(R){if(!ul(R))return!1;var q=hs(R);return q==O||q==P||q==d||q==$}function ll(R){return typeof R=="number"&&R>-1&&R%1==0&&R<=c}function ul(R){var q=typeof R;return R!=null&&(q=="object"||q=="function")}function ds(R){return R!=null&&typeof R=="object"}var hl=Me?$t(Me):Xc;function n0(R){return t0(R)?Yc(R):Qc(R)}function Ct(){return[]}function xt(){return!1}t.exports=r0})(eh,eh.exports);var I_=eh.exports,S_=Object.defineProperty,Dp=Object.getOwnPropertySymbols,O_=Object.prototype.hasOwnProperty,A_=Object.prototype.propertyIsEnumerable,$p=(t,e,r)=>e in t?S_(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Tr=(t,e)=>{for(var r in e||(e={}))O_.call(e,r)&&$p(t,r,e[r]);if(Dp)for(var r of Dp(e))A_.call(e,r)&&$p(t,r,e[r]);return t};function D_(t,e){if(t.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var i=0;i<t.length;i++){var o=t.charAt(i),c=o.charCodeAt(0);if(r[c]!==255)throw new TypeError(o+" is ambiguous");r[c]=i}var l=t.length,h=t.charAt(0),d=Math.log(l)/Math.log(256),v=Math.log(256)/Math.log(l);function E(P){if(P instanceof Uint8Array||(ArrayBuffer.isView(P)?P=new Uint8Array(P.buffer,P.byteOffset,P.byteLength):Array.isArray(P)&&(P=Uint8Array.from(P))),!(P instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(P.length===0)return"";for(var U=0,H=0,G=0,N=P.length;G!==N&&P[G]===0;)G++,U++;for(var L=(N-G)*v+1>>>0,$=new Uint8Array(L);G!==N;){for(var T=P[G],I=0,f=L-1;(T!==0||I<H)&&f!==-1;f--,I++)T+=256*$[f]>>>0,$[f]=T%l>>>0,T=T/l>>>0;if(T!==0)throw new Error("Non-zero carry");H=I,G++}for(var x=L-H;x!==L&&$[x]===0;)x++;for(var J=h.repeat(U);x<L;++x)J+=t.charAt($[x]);return J}function _(P){if(typeof P!="string")throw new TypeError("Expected String");if(P.length===0)return new Uint8Array;var U=0;if(P[U]!==" "){for(var H=0,G=0;P[U]===h;)H++,U++;for(var N=(P.length-U)*d+1>>>0,L=new Uint8Array(N);P[U];){var $=r[P.charCodeAt(U)];if($===255)return;for(var T=0,I=N-1;($!==0||T<G)&&I!==-1;I--,T++)$+=l*L[I]>>>0,L[I]=$%256>>>0,$=$/256>>>0;if($!==0)throw new Error("Non-zero carry");G=T,U++}if(P[U]!==" "){for(var f=N-G;f!==N&&L[f]===0;)f++;for(var x=new Uint8Array(H+(N-f)),J=H;f!==N;)x[J++]=L[f++];return x}}}function O(P){var U=_(P);if(U)return U;throw new Error(`Non-${e} character`)}return{encode:E,decodeUnsafe:_,decode:O}}var $_=D_,P_=$_;const Pp=t=>{if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return t;if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);throw new Error("Unknown type, must be binary type")},T_=t=>new TextEncoder().encode(t),R_=t=>new TextDecoder().decode(t);class N_{constructor(e,r,n){this.name=e,this.prefix=r,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}}class L_{constructor(e,r,n){if(this.name=e,this.prefix=r,r.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=r.codePointAt(0),this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return Tp(this,e)}}class M_{constructor(e){this.decoders=e}or(e){return Tp(this,e)}decode(e){const r=e[0],n=this.decoders[r];if(n)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}}const Tp=(t,e)=>new M_(Tr(Tr({},t.decoders||{[t.prefix]:t}),e.decoders||{[e.prefix]:e}));class U_{constructor(e,r,n,i){this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=i,this.encoder=new N_(e,r,n),this.decoder=new L_(e,r,i)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}}const rc=({name:t,prefix:e,encode:r,decode:n})=>new U_(t,e,r,n),Fo=({prefix:t,name:e,alphabet:r})=>{const{encode:n,decode:i}=P_(r,e);return rc({prefix:t,name:e,encode:n,decode:o=>Pp(i(o))})},j_=(t,e,r,n)=>{const i={};for(let v=0;v<e.length;++v)i[e[v]]=v;let o=t.length;for(;t[o-1]==="=";)--o;const c=new Uint8Array(o*r/8|0);let l=0,h=0,d=0;for(let v=0;v<o;++v){const E=i[t[v]];if(E===void 0)throw new SyntaxError(`Non-${n} character`);h=h<<r|E,l+=r,l>=8&&(l-=8,c[d++]=255&h>>l)}if(l>=r||255&h<<8-l)throw new SyntaxError("Unexpected end of data");return c},F_=(t,e,r)=>{const n=e[e.length-1]==="=",i=(1<<r)-1;let o="",c=0,l=0;for(let h=0;h<t.length;++h)for(l=l<<8|t[h],c+=8;c>r;)c-=r,o+=e[i&l>>c];if(c&&(o+=e[i&l<<r-c]),n)for(;o.length*r&7;)o+="=";return o},_r=({name:t,prefix:e,bitsPerChar:r,alphabet:n})=>rc({prefix:e,name:t,encode(i){return F_(i,n,r)},decode(i){return j_(i,n,r,t)}}),B_=rc({prefix:"\0",name:"identity",encode:t=>R_(t),decode:t=>T_(t)});var k_=Object.freeze({__proto__:null,identity:B_});const H_=_r({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var z_=Object.freeze({__proto__:null,base2:H_});const W_=_r({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var q_=Object.freeze({__proto__:null,base8:W_});const V_=Fo({prefix:"9",name:"base10",alphabet:"0123456789"});var K_=Object.freeze({__proto__:null,base10:V_});const G_=_r({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Z_=_r({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Y_=Object.freeze({__proto__:null,base16:G_,base16upper:Z_});const J_=_r({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),X_=_r({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Q_=_r({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),e8=_r({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),t8=_r({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),r8=_r({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),n8=_r({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),i8=_r({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),s8=_r({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var o8=Object.freeze({__proto__:null,base32:J_,base32upper:X_,base32pad:Q_,base32padupper:e8,base32hex:t8,base32hexupper:r8,base32hexpad:n8,base32hexpadupper:i8,base32z:s8});const a8=Fo({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),c8=Fo({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var l8=Object.freeze({__proto__:null,base36:a8,base36upper:c8});const u8=Fo({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),h8=Fo({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var f8=Object.freeze({__proto__:null,base58btc:u8,base58flickr:h8});const d8=_r({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),p8=_r({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),g8=_r({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),m8=_r({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var w8=Object.freeze({__proto__:null,base64:d8,base64pad:p8,base64url:g8,base64urlpad:m8});const Rp=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),v8=Rp.reduce((t,e,r)=>(t[r]=e,t),[]),y8=Rp.reduce((t,e,r)=>(t[e.codePointAt(0)]=r,t),[]);function b8(t){return t.reduce((e,r)=>(e+=v8[r],e),"")}function _8(t){const e=[];for(const r of t){const n=y8[r.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${r}`);e.push(n)}return new Uint8Array(e)}const E8=rc({prefix:"\u{1F680}",name:"base256emoji",encode:b8,decode:_8});var x8=Object.freeze({__proto__:null,base256emoji:E8}),C8=Lp,Np=128,I8=127,S8=~I8,O8=Math.pow(2,31);function Lp(t,e,r){e=e||[],r=r||0;for(var n=r;t>=O8;)e[r++]=t&255|Np,t/=128;for(;t&S8;)e[r++]=t&255|Np,t>>>=7;return e[r]=t|0,Lp.bytes=r-n+1,e}var A8=th,D8=128,Mp=127;function th(t,n){var r=0,n=n||0,i=0,o=n,c,l=t.length;do{if(o>=l)throw th.bytes=0,new RangeError("Could not decode varint");c=t[o++],r+=i<28?(c&Mp)<<i:(c&Mp)*Math.pow(2,i),i+=7}while(c>=D8);return th.bytes=o-n,r}var $8=Math.pow(2,7),P8=Math.pow(2,14),T8=Math.pow(2,21),R8=Math.pow(2,28),N8=Math.pow(2,35),L8=Math.pow(2,42),M8=Math.pow(2,49),U8=Math.pow(2,56),j8=Math.pow(2,63),F8=function(t){return t<$8?1:t<P8?2:t<T8?3:t<R8?4:t<N8?5:t<L8?6:t<M8?7:t<U8?8:t<j8?9:10},B8={encode:C8,decode:A8,encodingLength:F8},Up=B8;const jp=(t,e,r=0)=>(Up.encode(t,e,r),e),Fp=t=>Up.encodingLength(t),rh=(t,e)=>{const r=e.byteLength,n=Fp(t),i=n+Fp(r),o=new Uint8Array(i+r);return jp(t,o,0),jp(r,o,n),o.set(e,i),new k8(t,r,e,o)};class k8{constructor(e,r,n,i){this.code=e,this.size=r,this.digest=n,this.bytes=i}}const Bp=({name:t,code:e,encode:r})=>new H8(t,e,r);class H8{constructor(e,r,n){this.name=e,this.code=r,this.encode=n}digest(e){if(e instanceof Uint8Array){const r=this.encode(e);return r instanceof Uint8Array?rh(this.code,r):r.then(n=>rh(this.code,n))}else throw Error("Unknown type, must be binary type")}}const kp=t=>async e=>new Uint8Array(await crypto.subtle.digest(t,e)),z8=Bp({name:"sha2-256",code:18,encode:kp("SHA-256")}),W8=Bp({name:"sha2-512",code:19,encode:kp("SHA-512")});var q8=Object.freeze({__proto__:null,sha256:z8,sha512:W8});const Hp=0,V8="identity",zp=Pp;var K8=Object.freeze({__proto__:null,identity:{code:Hp,name:V8,encode:zp,digest:t=>rh(Hp,zp(t))}});new TextEncoder,new TextDecoder;const Wp=Tr(Tr(Tr(Tr(Tr(Tr(Tr(Tr(Tr(Tr({},k_),z_),q_),K_),Y_),o8),l8),f8),w8),x8);Tr(Tr({},q8),K8);function qp(t){return globalThis.Buffer!=null?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):t}function G8(t=0){return globalThis.Buffer!=null&&globalThis.Buffer.allocUnsafe!=null?qp(globalThis.Buffer.allocUnsafe(t)):new Uint8Array(t)}function Vp(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}const Kp=Vp("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),nh=Vp("ascii","a",t=>{let e="a";for(let r=0;r<t.length;r++)e+=String.fromCharCode(t[r]);return e},t=>{t=t.substring(1);const e=G8(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),Z8=Tr({utf8:Kp,"utf-8":Kp,hex:Wp.base16,latin1:nh,ascii:nh,binary:nh},Wp);function Y8(t,e="utf8"){const r=Z8[e];if(!r)throw new Error(`Unsupported encoding "${e}"`);return(e==="utf8"||e==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?qp(globalThis.Buffer.from(t,"utf-8")):r.decoder.decode(`${r.prefix}${t}`)}const Gp="wc",J8=2,ih="core",hi=`${Gp}@${2}:${ih}:`,X8={name:ih,logger:"error"},Q8={database:":memory:"},eE="crypto",Zp="client_ed25519_seed",tE=ke.ONE_DAY,rE="keychain",nE="0.3",iE="messages",sE="0.3",oE=ke.SIX_HOURS,aE="publisher",Yp="irn",cE="error",Jp="wss://relay.walletconnect.com",lE="relayer",pr={message:"relayer_message",connect:"relayer_connect",disconnect:"relayer_disconnect",error:"relayer_error",connection_stalled:"relayer_connection_stalled",transport_closed:"relayer_transport_closed",publish:"relayer_publish"},uE="_subscription",Bo={payload:"payload",connect:"connect",disconnect:"disconnect",error:"error"},hE=ke.ONE_SECOND/2,fE="2.7.4",dE="0.3",$n={created:"subscription_created",deleted:"subscription_deleted",expired:"subscription_expired",disabled:"subscription_disabled",sync:"subscription_sync",resubscribed:"subscription_resubscribed"},pE="subscription",gE="0.3",mE=ke.FIVE_SECONDS*1e3,wE="pairing",vE="0.3",ko={wc_pairingDelete:{req:{ttl:ke.ONE_DAY,prompt:!1,tag:1e3},res:{ttl:ke.ONE_DAY,prompt:!1,tag:1001}},wc_pairingPing:{req:{ttl:ke.THIRTY_SECONDS,prompt:!1,tag:1002},res:{ttl:ke.THIRTY_SECONDS,prompt:!1,tag:1003}},unregistered_method:{req:{ttl:ke.ONE_DAY,prompt:!1,tag:0},res:{ttl:ke.ONE_DAY,prompt:!1,tag:0}}},Pn={created:"history_created",updated:"history_updated",deleted:"history_deleted",sync:"history_sync"},yE="history",bE="0.3",_E="expirer",sn={created:"expirer_created",deleted:"expirer_deleted",expired:"expirer_expired",sync:"expirer_sync"},EE="0.3",sh="verify-api",Xp="https://verify.walletconnect.com";class xE{constructor(e,r){this.core=e,this.logger=r,this.keychain=new Map,this.name=rE,this.version=nE,this.initialized=!1,this.storagePrefix=hi,this.init=async()=>{if(!this.initialized){const n=await this.getKeyChain();typeof n<"u"&&(this.keychain=n),this.initialized=!0}},this.has=n=>(this.isInitialized(),this.keychain.has(n)),this.set=async(n,i)=>{this.isInitialized(),this.keychain.set(n,i),await this.persist()},this.get=n=>{this.isInitialized();const i=this.keychain.get(n);if(typeof i>"u"){const{message:o}=_e("NO_MATCHING_KEY",`${this.name}: ${n}`);throw new Error(o)}return i},this.del=async n=>{this.isInitialized(),this.keychain.delete(n),await this.persist()},this.core=e,this.logger=pt.generateChildLogger(r,this.name)}get context(){return pt.getLoggerContext(this.logger)}get storageKey(){return this.storagePrefix+this.version+"//"+this.name}async setKeyChain(e){await this.core.storage.setItem(this.storageKey,A1(e))}async getKeyChain(){const e=await this.core.storage.getItem(this.storageKey);return typeof e<"u"?D1(e):void 0}async persist(){await this.setKeyChain(this.keychain)}isInitialized(){if(!this.initialized){const{message:e}=_e("NOT_INITIALIZED",this.name);throw new Error(e)}}}class CE{constructor(e,r,n){this.core=e,this.logger=r,this.name=eE,this.initialized=!1,this.init=async()=>{this.initialized||(await this.keychain.init(),this.initialized=!0)},this.hasKeys=i=>(this.isInitialized(),this.keychain.has(i)),this.getClientId=async()=>{this.isInitialized();const i=await this.getClientSeed(),o=pp(i);return dp(o.publicKey)},this.generateKeyPair=()=>{this.isInitialized();const i=N5();return this.setPrivateKey(i.publicKey,i.privateKey)},this.signJWT=async i=>{this.isInitialized();const o=await this.getClientSeed(),c=pp(o),l=Cu();return await L4(l,i,tE,c)},this.generateSharedKey=(i,o,c)=>{this.isInitialized();const l=this.getPrivateKey(i),h=L5(l,o);return this.setSymKey(h,c)},this.setSymKey=async(i,o)=>{this.isInitialized();const c=o||M5(i);return await this.keychain.set(c,i),c},this.deleteKeyPair=async i=>{this.isInitialized(),await this.keychain.del(i)},this.deleteSymKey=async i=>{this.isInitialized(),await this.keychain.del(i)},this.encode=async(i,o,c)=>{this.isInitialized();const l=_1(c),h=Mo(o);if(E1(l)){const _=l.senderPublicKey,O=l.receiverPublicKey;i=await this.generateSharedKey(_,O)}const d=this.getSymKey(i),{type:v,senderPublicKey:E}=l;return j5({type:v,symKey:d,message:h,senderPublicKey:E})},this.decode=async(i,o,c)=>{this.isInitialized();const l=k5(o,c);if(E1(l)){const v=l.receiverPublicKey,E=l.senderPublicKey;i=await this.generateSharedKey(v,E)}const h=this.getSymKey(i),d=F5({symKey:h,encoded:o});return qu(d)},this.getPayloadType=i=>{const o=Va(i);return Io(o.type)},this.getPayloadSenderPublicKey=i=>{const o=Va(i);return o.senderPublicKey?Ar(o.senderPublicKey,Dr):void 0},this.core=e,this.logger=pt.generateChildLogger(r,this.name),this.keychain=n||new xE(this.core,this.logger)}get context(){return pt.getLoggerContext(this.logger)}async setPrivateKey(e,r){return await this.keychain.set(e,r),e}getPrivateKey(e){return this.keychain.get(e)}async getClientSeed(){let e="";try{e=this.keychain.get(Zp)}catch{e=Cu(),await this.keychain.set(Zp,e)}return Y8(e,"base16")}getSymKey(e){return this.keychain.get(e)}isInitialized(){if(!this.initialized){const{message:e}=_e("NOT_INITIALIZED",this.name);throw new Error(e)}}}class IE extends h4{constructor(e,r){super(e,r),this.logger=e,this.core=r,this.messages=new Map,this.name=iE,this.version=sE,this.initialized=!1,this.storagePrefix=hi,this.init=async()=>{if(!this.initialized){this.logger.trace("Initialized");try{const n=await this.getRelayerMessages();typeof n<"u"&&(this.messages=n),this.logger.debug(`Successfully Restored records for ${this.name}`),this.logger.trace({type:"method",method:"restore",size:this.messages.size})}catch(n){this.logger.debug(`Failed to Restore records for ${this.name}`),this.logger.error(n)}finally{this.initialized=!0}}},this.set=async(n,i)=>{this.isInitialized();const o=Bi(i);let c=this.messages.get(n);return typeof c>"u"&&(c={}),typeof c[o]<"u"||(c[o]=i,this.messages.set(n,c),await this.persist()),o},this.get=n=>{this.isInitialized();let i=this.messages.get(n);return typeof i>"u"&&(i={}),i},this.has=(n,i)=>{this.isInitialized();const o=this.get(n),c=Bi(i);return typeof o[c]<"u"},this.del=async n=>{this.isInitialized(),this.messages.delete(n),await this.persist()},this.logger=pt.generateChildLogger(e,this.name),this.core=r}get context(){return pt.getLoggerContext(this.logger)}get storageKey(){return this.storagePrefix+this.version+"//"+this.name}async setRelayerMessages(e){await this.core.storage.setItem(this.storageKey,A1(e))}async getRelayerMessages(){const e=await this.core.storage.getItem(this.storageKey);return typeof e<"u"?D1(e):void 0}async persist(){await this.setRelayerMessages(this.messages)}isInitialized(){if(!this.initialized){const{message:e}=_e("NOT_INITIALIZED",this.name);throw new Error(e)}}}class SE extends f4{constructor(e,r){super(e,r),this.relayer=e,this.logger=r,this.events=new yr.exports.EventEmitter,this.name=aE,this.queue=new Map,this.publishTimeout=1e4,this.publish=async(n,i,o)=>{this.logger.debug("Publishing Payload"),this.logger.trace({type:"method",method:"publish",params:{topic:n,message:i,opts:o}});try{const c=o?.ttl||oE,l=Au(o),h=o?.prompt||!1,d=o?.tag||0,v={topic:n,message:i,opts:{ttl:c,relay:l,prompt:h,tag:d}},E=Bi(i);this.queue.set(E,v);try{await await Ka(this.rpcPublish(n,i,c,l,h,d),this.publishTimeout),this.relayer.events.emit(pr.publish,v)}catch{this.logger.debug("Publishing Payload stalled"),this.relayer.events.emit(pr.connection_stalled);return}this.onPublish(E,v),this.logger.debug("Successfully Published Payload"),this.logger.trace({type:"method",method:"publish",params:{topic:n,message:i,opts:o}})}catch(c){throw this.logger.debug("Failed to Publish Payload"),this.logger.error(c),c}},this.on=(n,i)=>{this.events.on(n,i)},this.once=(n,i)=>{this.events.once(n,i)},this.off=(n,i)=>{this.events.off(n,i)},this.removeListener=(n,i)=>{this.events.removeListener(n,i)},this.relayer=e,this.logger=pt.generateChildLogger(r,this.name),this.registerEventListeners()}get context(){return pt.getLoggerContext(this.logger)}rpcPublish(e,r,n,i,o,c){var l,h,d,v;const E={method:Ga(i.protocol).publish,params:{topic:e,message:r,ttl:n,prompt:o,tag:c}};return $r((l=E.params)==null?void 0:l.prompt)&&((h=E.params)==null||delete h.prompt),$r((d=E.params)==null?void 0:d.tag)&&((v=E.params)==null||delete v.tag),this.logger.debug("Outgoing Relay Payload"),this.logger.trace({type:"message",direction:"outgoing",request:E}),this.relayer.request(E)}onPublish(e,r){this.queue.delete(e)}checkQueue(){this.queue.forEach(async e=>{const{topic:r,message:n,opts:i}=e;await this.publish(r,n,i)})}registerEventListeners(){this.relayer.core.heartbeat.on(Po.HEARTBEAT_EVENTS.pulse,()=>{this.checkQueue()})}}class OE{constructor(){this.map=new Map,this.set=(e,r)=>{const n=this.get(e);this.exists(e,r)||this.map.set(e,[...n,r])},this.get=e=>this.map.get(e)||[],this.exists=(e,r)=>this.get(e).includes(r),this.delete=(e,r)=>{if(typeof r>"u"){this.map.delete(e);return}if(!this.map.has(e))return;const n=this.get(e);if(!this.exists(e,r))return;const i=n.filter(o=>o!==r);if(!i.length){this.map.delete(e);return}this.map.set(e,i)},this.clear=()=>{this.map.clear()}}get topics(){return Array.from(this.map.keys())}}var AE=Object.defineProperty,DE=Object.defineProperties,$E=Object.getOwnPropertyDescriptors,Qp=Object.getOwnPropertySymbols,PE=Object.prototype.hasOwnProperty,TE=Object.prototype.propertyIsEnumerable,eg=(t,e,r)=>e in t?AE(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Ho=(t,e)=>{for(var r in e||(e={}))PE.call(e,r)&&eg(t,r,e[r]);if(Qp)for(var r of Qp(e))TE.call(e,r)&&eg(t,r,e[r]);return t},oh=(t,e)=>DE(t,$E(e));class RE extends g4{constructor(e,r){super(e,r),this.relayer=e,this.logger=r,this.subscriptions=new Map,this.topicMap=new OE,this.events=new yr.exports.EventEmitter,this.name=pE,this.version=gE,this.pending=new Map,this.cached=[],this.initialized=!1,this.pendingSubscriptionWatchLabel="pending_sub_watch_label",this.pollingInterval=20,this.storagePrefix=hi,this.subscribeTimeout=1e4,this.restartInProgress=!1,this.batchSubscribeTopicsLimit=500,this.init=async()=>{this.initialized||(this.logger.trace("Initialized"),await this.restart(),this.registerEventListeners(),this.onEnable(),this.clientId=await this.relayer.core.crypto.getClientId())},this.subscribe=async(n,i)=>{await this.restartToComplete(),this.isInitialized(),this.logger.debug("Subscribing Topic"),this.logger.trace({type:"method",method:"subscribe",params:{topic:n,opts:i}});try{const o=Au(i),c={topic:n,relay:o};this.pending.set(n,c);const l=await this.rpcSubscribe(n,o);return this.onSubscribe(l,c),this.logger.debug("Successfully Subscribed Topic"),this.logger.trace({type:"method",method:"subscribe",params:{topic:n,opts:i}}),l}catch(o){throw this.logger.debug("Failed to Subscribe Topic"),this.logger.error(o),o}},this.unsubscribe=async(n,i)=>{await this.restartToComplete(),this.isInitialized(),typeof i?.id<"u"?await this.unsubscribeById(n,i.id,i):await this.unsubscribeByTopic(n,i)},this.isSubscribed=async n=>this.topics.includes(n)?!0:await new Promise((i,o)=>{const c=new ke.Watch;c.start(this.pendingSubscriptionWatchLabel);const l=setInterval(()=>{!this.pending.has(n)&&this.topics.includes(n)&&(clearInterval(l),c.stop(this.pendingSubscriptionWatchLabel),i(!0)),c.elapsed(this.pendingSubscriptionWatchLabel)>=mE&&(clearInterval(l),c.stop(this.pendingSubscriptionWatchLabel),o(!1))},this.pollingInterval)}),this.on=(n,i)=>{this.events.on(n,i)},this.once=(n,i)=>{this.events.once(n,i)},this.off=(n,i)=>{this.events.off(n,i)},this.removeListener=(n,i)=>{this.events.removeListener(n,i)},this.restart=async()=>{this.restartInProgress=!0,await this.restore(),await this.reset(),this.restartInProgress=!1},this.relayer=e,this.logger=pt.generateChildLogger(r,this.name),this.clientId=""}get context(){return pt.getLoggerContext(this.logger)}get storageKey(){return this.storagePrefix+this.version+"//"+this.name}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}hasSubscription(e,r){let n=!1;try{n=this.getSubscription(e).topic===r}catch{}return n}onEnable(){this.cached=[],this.initialized=!0}onDisable(){this.cached=this.values,this.subscriptions.clear(),this.topicMap.clear()}async unsubscribeByTopic(e,r){const n=this.topicMap.get(e);await Promise.all(n.map(async i=>await this.unsubscribeById(e,i,r)))}async unsubscribeById(e,r,n){this.logger.debug("Unsubscribing Topic"),this.logger.trace({type:"method",method:"unsubscribe",params:{topic:e,id:r,opts:n}});try{const i=Au(n);await this.rpcUnsubscribe(e,r,i);const o=Zt("USER_DISCONNECTED",`${this.name}, ${e}`);await this.onUnsubscribe(e,r,o),this.logger.debug("Successfully Unsubscribed Topic"),this.logger.trace({type:"method",method:"unsubscribe",params:{topic:e,id:r,opts:n}})}catch(i){throw this.logger.debug("Failed to Unsubscribe Topic"),this.logger.error(i),i}}async rpcSubscribe(e,r){const n={method:Ga(r.protocol).subscribe,params:{topic:e}};this.logger.debug("Outgoing Relay Payload"),this.logger.trace({type:"payload",direction:"outgoing",request:n});try{await await Ka(this.relayer.request(n),this.subscribeTimeout)}catch{this.logger.debug("Outgoing Relay Subscribe Payload stalled"),this.relayer.events.emit(pr.connection_stalled)}return Bi(e+this.clientId)}async rpcBatchSubscribe(e){if(!e.length)return;const r=e[0].relay,n={method:Ga(r.protocol).batchSubscribe,params:{topics:e.map(i=>i.topic)}};this.logger.debug("Outgoing Relay Payload"),this.logger.trace({type:"payload",direction:"outgoing",request:n});try{return await await Ka(this.relayer.request(n),this.subscribeTimeout)}catch{this.logger.debug("Outgoing Relay Payload stalled"),this.relayer.events.emit(pr.connection_stalled)}}rpcUnsubscribe(e,r,n){const i={method:Ga(n.protocol).unsubscribe,params:{topic:e,id:r}};return this.logger.debug("Outgoing Relay Payload"),this.logger.trace({type:"payload",direction:"outgoing",request:i}),this.relayer.request(i)}onSubscribe(e,r){this.setSubscription(e,oh(Ho({},r),{id:e})),this.pending.delete(r.topic)}onBatchSubscribe(e){e.length&&e.forEach(r=>{this.setSubscription(r.id,Ho({},r)),this.pending.delete(r.topic)})}async onUnsubscribe(e,r,n){this.events.removeAllListeners(r),this.hasSubscription(r,e)&&this.deleteSubscription(r,n),await this.relayer.messages.del(e)}async setRelayerSubscriptions(e){await this.relayer.core.storage.setItem(this.storageKey,e)}async getRelayerSubscriptions(){return await this.relayer.core.storage.getItem(this.storageKey)}setSubscription(e,r){this.subscriptions.has(e)||(this.logger.debug("Setting subscription"),this.logger.trace({type:"method",method:"setSubscription",id:e,subscription:r}),this.addSubscription(e,r))}addSubscription(e,r){this.subscriptions.set(e,Ho({},r)),this.topicMap.set(r.topic,e),this.events.emit($n.created,r)}getSubscription(e){this.logger.debug("Getting subscription"),this.logger.trace({type:"method",method:"getSubscription",id:e});const r=this.subscriptions.get(e);if(!r){const{message:n}=_e("NO_MATCHING_KEY",`${this.name}: ${e}`);throw new Error(n)}return r}deleteSubscription(e,r){this.logger.debug("Deleting subscription"),this.logger.trace({type:"method",method:"deleteSubscription",id:e,reason:r});const n=this.getSubscription(e);this.subscriptions.delete(e),this.topicMap.delete(n.topic,e),this.events.emit($n.deleted,oh(Ho({},n),{reason:r}))}async persist(){await this.setRelayerSubscriptions(this.values),this.events.emit($n.sync)}async reset(){if(this.cached.length){const e=Math.ceil(this.cached.length/this.batchSubscribeTopicsLimit);for(let r=0;r<e;r++){const n=this.cached.splice(0,this.batchSubscribeTopicsLimit);await this.batchSubscribe(n)}}this.events.emit($n.resubscribed)}async restore(){try{const e=await this.getRelayerSubscriptions();if(typeof e>"u"||!e.length)return;if(this.subscriptions.size){const{message:r}=_e("RESTORE_WILL_OVERRIDE",this.name);throw this.logger.error(r),this.logger.error(`${this.name}: ${JSON.stringify(this.values)}`),new Error(r)}this.cached=e,this.logger.debug(`Successfully Restored subscriptions for ${this.name}`),this.logger.trace({type:"method",method:"restore",subscriptions:this.values})}catch(e){this.logger.debug(`Failed to Restore subscriptions for ${this.name}`),this.logger.error(e)}}async batchSubscribe(e){if(!e.length)return;const r=await this.rpcBatchSubscribe(e);Hn(r)&&this.onBatchSubscribe(r.map((n,i)=>oh(Ho({},e[i]),{id:n})))}async onConnect(){this.restartInProgress||(await this.restart(),this.onEnable())}onDisconnect(){this.onDisable()}async checkPending(){if(this.relayer.transportExplicitlyClosed)return;const e=[];this.pending.forEach(r=>{e.push(r)}),await this.batchSubscribe(e)}registerEventListeners(){this.relayer.core.heartbeat.on(Po.HEARTBEAT_EVENTS.pulse,async()=>{await this.checkPending()}),this.relayer.on(pr.connect,async()=>{await this.onConnect()}),this.relayer.on(pr.disconnect,()=>{this.onDisconnect()}),this.events.on($n.created,async e=>{const r=$n.created;this.logger.info(`Emitting ${r}`),this.logger.debug({type:"event",event:r,data:e}),await this.persist()}),this.events.on($n.deleted,async e=>{const r=$n.deleted;this.logger.info(`Emitting ${r}`),this.logger.debug({type:"event",event:r,data:e}),await this.persist()})}isInitialized(){if(!this.initialized){const{message:e}=_e("NOT_INITIALIZED",this.name);throw new Error(e)}}async restartToComplete(){this.restartInProgress&&await new Promise(e=>{const r=setInterval(()=>{this.restartInProgress||(clearInterval(r),e())},this.pollingInterval)})}}var NE=Object.defineProperty,tg=Object.getOwnPropertySymbols,LE=Object.prototype.hasOwnProperty,ME=Object.prototype.propertyIsEnumerable,rg=(t,e,r)=>e in t?NE(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,UE=(t,e)=>{for(var r in e||(e={}))LE.call(e,r)&&rg(t,r,e[r]);if(tg)for(var r of tg(e))ME.call(e,r)&&rg(t,r,e[r]);return t};class jE extends d4{constructor(e){super(e),this.protocol="wc",this.version=2,this.events=new yr.exports.EventEmitter,this.name=lE,this.transportExplicitlyClosed=!1,this.initialized=!1,this.reconnecting=!1,this.connectionStatusPollingInterval=20,this.staleConnectionErrors=["socket hang up","socket stalled"],this.request=async r=>{this.logger.debug("Publishing Request Payload");try{return await this.toEstablishConnection(),await this.provider.request(r)}catch(n){throw this.logger.debug("Failed to Publish Request"),this.logger.error(n),n}},this.core=e.core,this.logger=typeof e.logger<"u"&&typeof e.logger!="string"?pt.generateChildLogger(e.logger,this.name):pt.pino(pt.getDefaultLoggerOptions({level:e.logger||cE})),this.messages=new IE(this.logger,e.core),this.subscriber=new RE(this,this.logger),this.publisher=new SE(this,this.logger),this.relayUrl=e?.relayUrl||Jp,this.projectId=e.projectId,this.provider={}}async init(){this.logger.trace("Initialized"),await this.createProvider(),await Promise.all([this.messages.init(),this.transportOpen(),this.subscriber.init()]),this.registerEventListeners(),this.initialized=!0}get context(){return pt.getLoggerContext(this.logger)}get connected(){return this.provider.connection.connected}get connecting(){return this.provider.connection.connecting}async publish(e,r,n){this.isInitialized(),await this.publisher.publish(e,r,n),await this.recordMessageEvent({topic:e,message:r,publishedAt:Date.now()})}async subscribe(e,r){this.isInitialized();let n="";return await Promise.all([new Promise(i=>{this.subscriber.once($n.created,o=>{o.topic===e&&i()})}),new Promise(async i=>{n=await this.subscriber.subscribe(e,r),i()})]),n}async unsubscribe(e,r){this.isInitialized(),await this.subscriber.unsubscribe(e,r)}on(e,r){this.events.on(e,r)}once(e,r){this.events.once(e,r)}off(e,r){this.events.off(e,r)}removeListener(e,r){this.events.removeListener(e,r)}async transportClose(){this.transportExplicitlyClosed=!0,this.connected&&(await this.provider.disconnect(),this.events.emit(pr.transport_closed))}async transportOpen(e){if(this.transportExplicitlyClosed=!1,!this.reconnecting){this.relayUrl=e||this.relayUrl,this.reconnecting=!0;try{await Promise.all([new Promise(r=>{this.initialized||r(),this.subscriber.once($n.resubscribed,()=>{r()})}),await Promise.race([new Promise(async(r,n)=>{await Ka(this.provider.connect(),5e3,"socket stalled").catch(i=>n(i)).then(()=>r()).finally(()=>this.removeListener(pr.transport_closed,this.rejectTransportOpen))}),new Promise(r=>this.once(pr.transport_closed,this.rejectTransportOpen))])])}catch(r){this.logger.error(r);const n=r;if(!this.isConnectionStalled(n.message))throw r;this.events.emit(pr.transport_closed)}finally{this.reconnecting=!1}}}async restartTransport(e){this.transportExplicitlyClosed||(this.relayUrl=e||this.relayUrl,this.connected&&await Promise.all([new Promise(r=>{this.provider.once(Bo.disconnect,()=>{r()})}),this.transportClose()]),await this.createProvider(),await this.transportOpen())}isConnectionStalled(e){return this.staleConnectionErrors.some(r=>e.includes(r))}rejectTransportOpen(){throw new Error("closeTransport called before connection was established")}async createProvider(){const e=await this.core.crypto.signJWT(this.relayUrl);this.provider=new ui(new C_(X5({sdkVersion:fE,protocol:this.protocol,version:this.version,relayUrl:this.relayUrl,projectId:this.projectId,auth:e,useOnCloseEvent:!0}))),this.registerProviderListeners()}async recordMessageEvent(e){const{topic:r,message:n}=e;await this.messages.set(r,n)}async shouldIgnoreMessageEvent(e){const{topic:r,message:n}=e;return await this.subscriber.isSubscribed(r)?this.messages.has(r,n):!0}async onProviderPayload(e){if(this.logger.debug("Incoming Relay Payload"),this.logger.trace({type:"payload",direction:"incoming",payload:e}),Xu(e)){if(!e.method.endsWith(uE))return;const r=e.params,{topic:n,message:i,publishedAt:o}=r.data,c={topic:n,message:i,publishedAt:o};this.logger.debug("Emitting Relayer Payload"),this.logger.trace(UE({type:"event",event:r.id},c)),this.events.emit(r.id,c),await this.acknowledgePayload(e),await this.onMessageEvent(c)}}async onMessageEvent(e){await this.shouldIgnoreMessageEvent(e)||(this.events.emit(pr.message,e),await this.recordMessageEvent(e))}async acknowledgePayload(e){const r=Ju(e.id,!0);await this.provider.connection.send(r)}registerProviderListeners(){this.provider.on(Bo.payload,e=>this.onProviderPayload(e)),this.provider.on(Bo.connect,()=>{this.events.emit(pr.connect)}),this.provider.on(Bo.disconnect,()=>{this.onProviderDisconnect()}),this.provider.on(Bo.error,e=>{this.logger.error(e),this.events.emit(pr.error,e)})}registerEventListeners(){this.events.on(pr.connection_stalled,async()=>{await this.restartTransport()})}onProviderDisconnect(){this.events.emit(pr.disconnect),this.attemptToReconnect()}attemptToReconnect(){this.transportExplicitlyClosed||setTimeout(async()=>{await this.restartTransport()},ke.toMiliseconds(hE))}isInitialized(){if(!this.initialized){const{message:e}=_e("NOT_INITIALIZED",this.name);throw new Error(e)}}async toEstablishConnection(){if(!this.connected){if(this.connecting)return await new Promise(e=>{const r=setInterval(()=>{this.connected&&(clearInterval(r),e())},this.connectionStatusPollingInterval)});await this.restartTransport()}}}var FE=Object.defineProperty,ng=Object.getOwnPropertySymbols,BE=Object.prototype.hasOwnProperty,kE=Object.prototype.propertyIsEnumerable,ig=(t,e,r)=>e in t?FE(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,sg=(t,e)=>{for(var r in e||(e={}))BE.call(e,r)&&ig(t,r,e[r]);if(ng)for(var r of ng(e))kE.call(e,r)&&ig(t,r,e[r]);return t};class nc extends p4{constructor(e,r,n,i=hi,o=void 0){super(e,r,n,i),this.core=e,this.logger=r,this.name=n,this.map=new Map,this.version=dE,this.cached=[],this.initialized=!1,this.storagePrefix=hi,this.init=async()=>{this.initialized||(this.logger.trace("Initialized"),await this.restore(),this.cached.forEach(c=>{this.getKey&&c!==null&&!$r(c)?this.map.set(this.getKey(c),c):yb(c)?this.map.set(c.id,c):bb(c)&&this.map.set(c.topic,c)}),this.cached=[],this.initialized=!0)},this.set=async(c,l)=>{this.isInitialized(),this.map.has(c)?await this.update(c,l):(this.logger.debug("Setting value"),this.logger.trace({type:"method",method:"set",key:c,value:l}),this.map.set(c,l),await this.persist())},this.get=c=>(this.isInitialized(),this.logger.debug("Getting value"),this.logger.trace({type:"method",method:"get",key:c}),this.getData(c)),this.getAll=c=>(this.isInitialized(),c?this.values.filter(l=>Object.keys(c).every(h=>I_(l[h],c[h]))):this.values),this.update=async(c,l)=>{this.isInitialized(),this.logger.debug("Updating value"),this.logger.trace({type:"method",method:"update",key:c,update:l});const h=sg(sg({},this.getData(c)),l);this.map.set(c,h),await this.persist()},this.delete=async(c,l)=>{this.isInitialized(),this.map.has(c)&&(this.logger.debug("Deleting value"),this.logger.trace({type:"method",method:"delete",key:c,reason:l}),this.map.delete(c),await this.persist())},this.logger=pt.generateChildLogger(r,this.name),this.storagePrefix=i,this.getKey=o}get context(){return pt.getLoggerContext(this.logger)}get storageKey(){return this.storagePrefix+this.version+"//"+this.name}get length(){return this.map.size}get keys(){return Array.from(this.map.keys())}get values(){return Array.from(this.map.values())}async setDataStore(e){await this.core.storage.setItem(this.storageKey,e)}async getDataStore(){return await this.core.storage.getItem(this.storageKey)}getData(e){const r=this.map.get(e);if(!r){const{message:n}=_e("NO_MATCHING_KEY",`${this.name}: ${e}`);throw this.logger.error(n),new Error(n)}return r}async persist(){await this.setDataStore(this.values)}async restore(){try{const e=await this.getDataStore();if(typeof e>"u"||!e.length)return;if(this.map.size){const{message:r}=_e("RESTORE_WILL_OVERRIDE",this.name);throw this.logger.error(r),new Error(r)}this.cached=e,this.logger.debug(`Successfully Restored value for ${this.name}`),this.logger.trace({type:"method",method:"restore",value:this.values})}catch(e){this.logger.debug(`Failed to Restore value for ${this.name}`),this.logger.error(e)}}isInitialized(){if(!this.initialized){const{message:e}=_e("NOT_INITIALIZED",this.name);throw new Error(e)}}}class HE{constructor(e,r){this.core=e,this.logger=r,this.name=wE,this.version=vE,this.events=new yr.exports,this.initialized=!1,this.storagePrefix=hi,this.ignoredPayloadTypes=[Fi],this.registeredMethods=[],this.init=async()=>{this.initialized||(await this.pairings.init(),await this.cleanup(),this.registerRelayerEvents(),this.registerExpirerEvents(),this.initialized=!0,this.logger.trace("Initialized"))},this.register=({methods:n})=>{this.isInitialized(),this.registeredMethods=[...new Set([...this.registeredMethods,...n])]},this.create=async()=>{this.isInitialized();const n=Cu(),i=await this.core.crypto.setSymKey(n),o=Dn(ke.FIVE_MINUTES),c={protocol:Yp},l={topic:i,expiry:o,relay:c,active:!1},h=lb({protocol:this.core.protocol,version:this.core.version,topic:i,symKey:n,relay:c});return await this.pairings.set(i,l),await this.core.relayer.subscribe(i),this.core.expirer.set(i,o),{topic:i,uri:h}},this.pair=async n=>{this.isInitialized(),this.isValidPair(n);const{topic:i,symKey:o,relay:c}=ab(n.uri);if(this.pairings.keys.includes(i))throw new Error(`Pairing already exists: ${i}`);if(this.core.crypto.hasKeys(i))throw new Error(`Keychain already exists: ${i}`);const l=Dn(ke.FIVE_MINUTES),h={topic:i,relay:c,expiry:l,active:!1};return await this.pairings.set(i,h),await this.core.crypto.setSymKey(o,i),await this.core.relayer.subscribe(i,{relay:c}),this.core.expirer.set(i,l),n.activatePairing&&await this.activate({topic:i}),h},this.activate=async({topic:n})=>{this.isInitialized();const i=Dn(ke.THIRTY_DAYS);await this.pairings.update(n,{active:!0,expiry:i}),this.core.expirer.set(n,i)},this.ping=async n=>{this.isInitialized(),await this.isValidPing(n);const{topic:i}=n;if(this.pairings.keys.includes(i)){const o=await this.sendRequest(i,"wc_pairingPing",{}),{done:c,resolve:l,reject:h}=Os();this.events.once(er("pairing_ping",o),({error:d})=>{d?h(d):l()}),await c()}},this.updateExpiry=async({topic:n,expiry:i})=>{this.isInitialized(),await this.pairings.update(n,{expiry:i})},this.updateMetadata=async({topic:n,metadata:i})=>{this.isInitialized(),await this.pairings.update(n,{peerMetadata:i})},this.getPairings=()=>(this.isInitialized(),this.pairings.values),this.disconnect=async n=>{this.isInitialized(),await this.isValidDisconnect(n);const{topic:i}=n;this.pairings.keys.includes(i)&&(await this.sendRequest(i,"wc_pairingDelete",Zt("USER_DISCONNECTED")),await this.deletePairing(i))},this.sendRequest=async(n,i,o)=>{const c=ec(i,o),l=await this.core.crypto.encode(n,c),h=ko[i].req;return this.core.history.set(n,c),await this.core.relayer.publish(n,l,h),c.id},this.sendResult=async(n,i,o)=>{const c=Ju(n,o),l=await this.core.crypto.encode(i,c),h=await this.core.history.get(i,n),d=ko[h.request.method].res;await this.core.relayer.publish(i,l,d),await this.core.history.resolve(c)},this.sendError=async(n,i,o)=>{const c=tc(n,o),l=await this.core.crypto.encode(i,c),h=await this.core.history.get(i,n),d=ko[h.request.method]?ko[h.request.method].res:ko.unregistered_method.res;await this.core.relayer.publish(i,l,d),await this.core.history.resolve(c)},this.deletePairing=async(n,i)=>{await this.core.relayer.unsubscribe(n),await Promise.all([this.pairings.delete(n,Zt("USER_DISCONNECTED")),this.core.crypto.deleteSymKey(n),i?Promise.resolve():this.core.expirer.del(n)])},this.cleanup=async()=>{const n=this.pairings.getAll().filter(i=>li(i.expiry));await Promise.all(n.map(i=>this.deletePairing(i.topic)))},this.onRelayEventRequest=n=>{const{topic:i,payload:o}=n,c=o.method;if(this.pairings.keys.includes(i))switch(c){case"wc_pairingPing":return this.onPairingPingRequest(i,o);case"wc_pairingDelete":return this.onPairingDeleteRequest(i,o);default:return this.onUnknownRpcMethodRequest(i,o)}},this.onRelayEventResponse=async n=>{const{topic:i,payload:o}=n,c=(await this.core.history.get(i,o.id)).request.method;if(this.pairings.keys.includes(i))switch(c){case"wc_pairingPing":return this.onPairingPingResponse(i,o);default:return this.onUnknownRpcMethodResponse(c)}},this.onPairingPingRequest=async(n,i)=>{const{id:o}=i;try{this.isValidPing({topic:n}),await this.sendResult(o,n,!0),this.events.emit("pairing_ping",{id:o,topic:n})}catch(c){await this.sendError(o,n,c),this.logger.error(c)}},this.onPairingPingResponse=(n,i)=>{const{id:o}=i;setTimeout(()=>{qn(i)?this.events.emit(er("pairing_ping",o),{}):_n(i)&&this.events.emit(er("pairing_ping",o),{error:i.error})},500)},this.onPairingDeleteRequest=async(n,i)=>{const{id:o}=i;try{this.isValidDisconnect({topic:n}),await this.deletePairing(n),this.events.emit("pairing_delete",{id:o,topic:n})}catch(c){await this.sendError(o,n,c),this.logger.error(c)}},this.onUnknownRpcMethodRequest=async(n,i)=>{const{id:o,method:c}=i;try{if(this.registeredMethods.includes(c))return;const l=Zt("WC_METHOD_UNSUPPORTED",c);await this.sendError(o,n,l),this.logger.error(l)}catch(l){await this.sendError(o,n,l),this.logger.error(l)}},this.onUnknownRpcMethodResponse=n=>{this.registeredMethods.includes(n)||this.logger.error(Zt("WC_METHOD_UNSUPPORTED",n))},this.isValidPair=n=>{if(!Hr(n)){const{message:i}=_e("MISSING_OR_INVALID",`pair() params: ${n}`);throw new Error(i)}if(!vb(n.uri)){const{message:i}=_e("MISSING_OR_INVALID",`pair() uri: ${n.uri}`);throw new Error(i)}},this.isValidPing=async n=>{if(!Hr(n)){const{message:o}=_e("MISSING_OR_INVALID",`ping() params: ${n}`);throw new Error(o)}const{topic:i}=n;await this.isValidPairingTopic(i)},this.isValidDisconnect=async n=>{if(!Hr(n)){const{message:o}=_e("MISSING_OR_INVALID",`disconnect() params: ${n}`);throw new Error(o)}const{topic:i}=n;await this.isValidPairingTopic(i)},this.isValidPairingTopic=async n=>{if(!dr(n,!1)){const{message:i}=_e("MISSING_OR_INVALID",`pairing topic should be a string: ${n}`);throw new Error(i)}if(!this.pairings.keys.includes(n)){const{message:i}=_e("NO_MATCHING_KEY",`pairing topic doesn't exist: ${n}`);throw new Error(i)}if(li(this.pairings.get(n).expiry)){await this.deletePairing(n);const{message:i}=_e("EXPIRED",`pairing topic: ${n}`);throw new Error(i)}},this.core=e,this.logger=pt.generateChildLogger(r,this.name),this.pairings=new nc(this.core,this.logger,this.name,this.storagePrefix)}get context(){return pt.getLoggerContext(this.logger)}isInitialized(){if(!this.initialized){const{message:e}=_e("NOT_INITIALIZED",this.name);throw new Error(e)}}registerRelayerEvents(){this.core.relayer.on(pr.message,async e=>{const{topic:r,message:n}=e;if(this.ignoredPayloadTypes.includes(this.core.crypto.getPayloadType(n)))return;const i=await this.core.crypto.decode(r,n);Xu(i)?(this.core.history.set(r,i),this.onRelayEventRequest({topic:r,payload:i})):Qu(i)&&(await this.core.history.resolve(i),this.onRelayEventResponse({topic:r,payload:i}))})}registerExpirerEvents(){this.core.expirer.on(sn.expired,async e=>{const{topic:r}=P1(e.target);r&&this.pairings.keys.includes(r)&&(await this.deletePairing(r,!0),this.events.emit("pairing_expire",{topic:r}))})}}class zE extends u4{constructor(e,r){super(e,r),this.core=e,this.logger=r,this.records=new Map,this.events=new yr.exports.EventEmitter,this.name=yE,this.version=bE,this.cached=[],this.initialized=!1,this.storagePrefix=hi,this.init=async()=>{this.initialized||(this.logger.trace("Initialized"),await this.restore(),this.cached.forEach(n=>this.records.set(n.id,n)),this.cached=[],this.registerEventListeners(),this.initialized=!0)},this.set=(n,i,o)=>{if(this.isInitialized(),this.logger.debug("Setting JSON-RPC request history record"),this.logger.trace({type:"method",method:"set",topic:n,request:i,chainId:o}),this.records.has(i.id))return;const c={id:i.id,topic:n,request:{method:i.method,params:i.params||null},chainId:o};this.records.set(c.id,c),this.events.emit(Pn.created,c)},this.resolve=async n=>{if(this.isInitialized(),this.logger.debug("Updating JSON-RPC response history record"),this.logger.trace({type:"method",method:"update",response:n}),!this.records.has(n.id))return;const i=await this.getRecord(n.id);typeof i.response>"u"&&(i.response=_n(n)?{error:n.error}:{result:n.result},this.records.set(i.id,i),this.events.emit(Pn.updated,i))},this.get=async(n,i)=>(this.isInitialized(),this.logger.debug("Getting record"),this.logger.trace({type:"method",method:"get",topic:n,id:i}),await this.getRecord(i)),this.delete=(n,i)=>{this.isInitialized(),this.logger.debug("Deleting record"),this.logger.trace({type:"method",method:"delete",id:i}),this.values.forEach(o=>{if(o.topic===n){if(typeof i<"u"&&o.id!==i)return;this.records.delete(o.id),this.events.emit(Pn.deleted,o)}})},this.exists=async(n,i)=>(this.isInitialized(),this.records.has(i)?(await this.getRecord(i)).topic===n:!1),this.on=(n,i)=>{this.events.on(n,i)},this.once=(n,i)=>{this.events.once(n,i)},this.off=(n,i)=>{this.events.off(n,i)},this.removeListener=(n,i)=>{this.events.removeListener(n,i)},this.logger=pt.generateChildLogger(r,this.name)}get context(){return pt.getLoggerContext(this.logger)}get storageKey(){return this.storagePrefix+this.version+"//"+this.name}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(r=>{if(typeof r.response<"u")return;const n={topic:r.topic,request:ec(r.request.method,r.request.params,r.id),chainId:r.chainId};return e.push(n)}),e}async setJsonRpcRecords(e){await this.core.storage.setItem(this.storageKey,e)}async getJsonRpcRecords(){return await this.core.storage.getItem(this.storageKey)}getRecord(e){this.isInitialized();const r=this.records.get(e);if(!r){const{message:n}=_e("NO_MATCHING_KEY",`${this.name}: ${e}`);throw new Error(n)}return r}async persist(){await this.setJsonRpcRecords(this.values),this.events.emit(Pn.sync)}async restore(){try{const e=await this.getJsonRpcRecords();if(typeof e>"u"||!e.length)return;if(this.records.size){const{message:r}=_e("RESTORE_WILL_OVERRIDE",this.name);throw this.logger.error(r),new Error(r)}this.cached=e,this.logger.debug(`Successfully Restored records for ${this.name}`),this.logger.trace({type:"method",method:"restore",records:this.values})}catch(e){this.logger.debug(`Failed to Restore records for ${this.name}`),this.logger.error(e)}}registerEventListeners(){this.events.on(Pn.created,e=>{const r=Pn.created;this.logger.info(`Emitting ${r}`),this.logger.debug({type:"event",event:r,record:e}),this.persist()}),this.events.on(Pn.updated,e=>{const r=Pn.updated;this.logger.info(`Emitting ${r}`),this.logger.debug({type:"event",event:r,record:e}),this.persist()}),this.events.on(Pn.deleted,e=>{const r=Pn.deleted;this.logger.info(`Emitting ${r}`),this.logger.debug({type:"event",event:r,record:e}),this.persist()})}isInitialized(){if(!this.initialized){const{message:e}=_e("NOT_INITIALIZED",this.name);throw new Error(e)}}}class WE extends m4{constructor(e,r){super(e,r),this.core=e,this.logger=r,this.expirations=new Map,this.events=new yr.exports.EventEmitter,this.name=_E,this.version=EE,this.cached=[],this.initialized=!1,this.storagePrefix=hi,this.init=async()=>{this.initialized||(this.logger.trace("Initialized"),await this.restore(),this.cached.forEach(n=>this.expirations.set(n.target,n)),this.cached=[],this.registerEventListeners(),this.initialized=!0)},this.has=n=>{try{const i=this.formatTarget(n);return typeof this.getExpiration(i)<"u"}catch{return!1}},this.set=(n,i)=>{this.isInitialized();const o=this.formatTarget(n),c={target:o,expiry:i};this.expirations.set(o,c),this.checkExpiry(o,c),this.events.emit(sn.created,{target:o,expiration:c})},this.get=n=>{this.isInitialized();const i=this.formatTarget(n);return this.getExpiration(i)},this.del=n=>{if(this.isInitialized(),this.has(n)){const i=this.formatTarget(n),o=this.getExpiration(i);this.expirations.delete(i),this.events.emit(sn.deleted,{target:i,expiration:o})}},this.on=(n,i)=>{this.events.on(n,i)},this.once=(n,i)=>{this.events.once(n,i)},this.off=(n,i)=>{this.events.off(n,i)},this.removeListener=(n,i)=>{this.events.removeListener(n,i)},this.logger=pt.generateChildLogger(r,this.name)}get context(){return pt.getLoggerContext(this.logger)}get storageKey(){return this.storagePrefix+this.version+"//"+this.name}get length(){return this.expirations.size}get keys(){return Array.from(this.expirations.keys())}get values(){return Array.from(this.expirations.values())}formatTarget(e){if(typeof e=="string")return Q5(e);if(typeof e=="number")return eb(e);const{message:r}=_e("UNKNOWN_TYPE",`Target type: ${typeof e}`);throw new Error(r)}async setExpirations(e){await this.core.storage.setItem(this.storageKey,e)}async getExpirations(){return await this.core.storage.getItem(this.storageKey)}async persist(){await this.setExpirations(this.values),this.events.emit(sn.sync)}async restore(){try{const e=await this.getExpirations();if(typeof e>"u"||!e.length)return;if(this.expirations.size){const{message:r}=_e("RESTORE_WILL_OVERRIDE",this.name);throw this.logger.error(r),new Error(r)}this.cached=e,this.logger.debug(`Successfully Restored expirations for ${this.name}`),this.logger.trace({type:"method",method:"restore",expirations:this.values})}catch(e){this.logger.debug(`Failed to Restore expirations for ${this.name}`),this.logger.error(e)}}getExpiration(e){const r=this.expirations.get(e);if(!r){const{message:n}=_e("NO_MATCHING_KEY",`${this.name}: ${e}`);throw this.logger.error(n),new Error(n)}return r}checkExpiry(e,r){const{expiry:n}=r;ke.toMiliseconds(n)-Date.now()<=0&&this.expire(e,r)}expire(e,r){this.expirations.delete(e),this.events.emit(sn.expired,{target:e,expiration:r})}checkExpirations(){this.core.relayer.connected&&this.expirations.forEach((e,r)=>this.checkExpiry(r,e))}registerEventListeners(){this.core.heartbeat.on(Po.HEARTBEAT_EVENTS.pulse,()=>this.checkExpirations()),this.events.on(sn.created,e=>{const r=sn.created;this.logger.info(`Emitting ${r}`),this.logger.debug({type:"event",event:r,data:e}),this.persist()}),this.events.on(sn.expired,e=>{const r=sn.expired;this.logger.info(`Emitting ${r}`),this.logger.debug({type:"event",event:r,data:e}),this.persist()}),this.events.on(sn.deleted,e=>{const r=sn.deleted;this.logger.info(`Emitting ${r}`),this.logger.debug({type:"event",event:r,data:e}),this.persist()})}isInitialized(){if(!this.initialized){const{message:e}=_e("NOT_INITIALIZED",this.name);throw new Error(e)}}}class qE extends w4{constructor(e,r){super(e,r),this.projectId=e,this.logger=r,this.name=sh,this.initialized=!1,this.init=async n=>{S1()||!Su()||(this.verifyUrl=n?.verifyUrl||Xp,await this.createIframe())},this.register=async n=>{var i;this.initialized||await this.init(),this.iframe&&((i=this.iframe.contentWindow)==null||i.postMessage(n.attestationId,this.verifyUrl),this.logger.info(`postMessage sent: ${n.attestationId} ${this.verifyUrl}`))},this.resolve=async n=>{var i;if(this.isDevEnv)return"";this.logger.info(`resolving attestation: ${n.attestationId}`);const o=this.startAbortTimer(ke.FIVE_SECONDS),c=await fetch(`${this.verifyUrl}/attestation/${n.attestationId}`,{signal:this.abortController.signal});return clearTimeout(o),c.status===200?(i=await c.json())==null?void 0:i.origin:""},this.createIframe=async()=>{try{await Promise.race([new Promise((n,i)=>{if(document.getElementById(sh))return n();const o=document.createElement("iframe");o.setAttribute("id",sh),o.setAttribute("src",`${this.verifyUrl}/${this.projectId}`),o.style.display="none",o.addEventListener("load",()=>{this.initialized=!0,n()}),o.addEventListener("error",c=>{i(c)}),document.body.append(o),this.iframe=o}),new Promise(n=>{setTimeout(()=>n("iframe load timeout"),ke.toMiliseconds(ke.ONE_SECOND/2))})])}catch(n){this.logger.error(`Verify iframe failed to load: ${this.verifyUrl}`),this.logger.error(n)}},this.logger=pt.generateChildLogger(r,this.name),this.verifyUrl=Xp,this.abortController=new AbortController,this.isDevEnv=Iu()&&process.env.IS_VITEST}get context(){return pt.getLoggerContext(this.logger)}startAbortTimer(e){return setTimeout(()=>this.abortController.abort(),ke.toMiliseconds(e))}}var VE=Object.defineProperty,og=Object.getOwnPropertySymbols,KE=Object.prototype.hasOwnProperty,GE=Object.prototype.propertyIsEnumerable,ag=(t,e,r)=>e in t?VE(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,cg=(t,e)=>{for(var r in e||(e={}))KE.call(e,r)&&ag(t,r,e[r]);if(og)for(var r of og(e))GE.call(e,r)&&ag(t,r,e[r]);return t};class ah extends l4{constructor(e){super(e),this.protocol=Gp,this.version=J8,this.name=ih,this.events=new yr.exports.EventEmitter,this.initialized=!1,this.on=(n,i)=>this.events.on(n,i),this.once=(n,i)=>this.events.once(n,i),this.off=(n,i)=>this.events.off(n,i),this.removeListener=(n,i)=>this.events.removeListener(n,i),this.projectId=e?.projectId,this.relayUrl=e?.relayUrl||Jp;const r=typeof e?.logger<"u"&&typeof e?.logger!="string"?e.logger:pt.pino(pt.getDefaultLoggerOptions({level:e?.logger||X8.logger}));this.logger=pt.generateChildLogger(r,this.name),this.heartbeat=new Po.HeartBeat,this.crypto=new CE(this,this.logger,e?.keychain),this.history=new zE(this,this.logger),this.expirer=new WE(this,this.logger),this.storage=e!=null&&e.storage?e.storage:new d6(cg(cg({},Q8),e?.storageOptions)),this.relayer=new jE({core:this,logger:this.logger,relayUrl:this.relayUrl,projectId:this.projectId}),this.pairing=new HE(this,this.logger),this.verify=new qE(this.projectId||"",this.logger)}static async init(e){const r=new ah(e);return await r.initialize(),r}get context(){return pt.getLoggerContext(this.logger)}async start(){this.initialized||await this.initialize()}async initialize(){this.logger.trace("Initialized");try{await this.crypto.init(),await this.history.init(),await this.expirer.init(),await this.relayer.init(),await this.heartbeat.init(),await this.pairing.init(),this.initialized=!0,this.logger.info("Core Initialization Success")}catch(e){throw this.logger.warn(`Core Initialization Failure at epoch ${Date.now()}`,e),this.logger.error(e.message),e}}}const ZE=ah,lg="wc",ug=2,hg="client",ch=`${lg}@${ug}:${hg}:`,lh={name:hg,logger:"error",controller:!1,relayUrl:"wss://relay.walletconnect.com"},YE="proposal",fg="Proposal expired",JE="session",ic=ke.SEVEN_DAYS,XE="engine",zo={wc_sessionPropose:{req:{ttl:ke.FIVE_MINUTES,prompt:!0,tag:1100},res:{ttl:ke.FIVE_MINUTES,prompt:!1,tag:1101}},wc_sessionSettle:{req:{ttl:ke.FIVE_MINUTES,prompt:!1,tag:1102},res:{ttl:ke.FIVE_MINUTES,prompt:!1,tag:1103}},wc_sessionUpdate:{req:{ttl:ke.ONE_DAY,prompt:!1,tag:1104},res:{ttl:ke.ONE_DAY,prompt:!1,tag:1105}},wc_sessionExtend:{req:{ttl:ke.ONE_DAY,prompt:!1,tag:1106},res:{ttl:ke.ONE_DAY,prompt:!1,tag:1107}},wc_sessionRequest:{req:{ttl:ke.FIVE_MINUTES,prompt:!0,tag:1108},res:{ttl:ke.FIVE_MINUTES,prompt:!1,tag:1109}},wc_sessionEvent:{req:{ttl:ke.FIVE_MINUTES,prompt:!0,tag:1110},res:{ttl:ke.FIVE_MINUTES,prompt:!1,tag:1111}},wc_sessionDelete:{req:{ttl:ke.ONE_DAY,prompt:!1,tag:1112},res:{ttl:ke.ONE_DAY,prompt:!1,tag:1113}},wc_sessionPing:{req:{ttl:ke.THIRTY_SECONDS,prompt:!1,tag:1114},res:{ttl:ke.THIRTY_SECONDS,prompt:!1,tag:1115}}},uh={min:ke.FIVE_MINUTES,max:ke.SEVEN_DAYS},QE="request",e7=["wc_sessionPropose","wc_sessionRequest","wc_authRequest"];var t7=Object.defineProperty,r7=Object.defineProperties,n7=Object.getOwnPropertyDescriptors,dg=Object.getOwnPropertySymbols,i7=Object.prototype.hasOwnProperty,s7=Object.prototype.propertyIsEnumerable,pg=(t,e,r)=>e in t?t7(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,on=(t,e)=>{for(var r in e||(e={}))i7.call(e,r)&&pg(t,r,e[r]);if(dg)for(var r of dg(e))s7.call(e,r)&&pg(t,r,e[r]);return t},hh=(t,e)=>r7(t,n7(e));class o7 extends y4{constructor(e){super(e),this.name=XE,this.events=new yr.exports,this.initialized=!1,this.ignoredPayloadTypes=[Fi],this.init=async()=>{this.initialized||(await this.cleanup(),this.registerRelayerEvents(),this.registerExpirerEvents(),this.client.core.pairing.register({methods:Object.keys(zo)}),this.initialized=!0)},this.connect=async r=>{this.isInitialized();const n=hh(on({},r),{requiredNamespaces:r.requiredNamespaces||{},optionalNamespaces:r.optionalNamespaces||{}});await this.isValidConnect(n);const{pairingTopic:i,requiredNamespaces:o,optionalNamespaces:c,sessionProperties:l,relays:h}=n;let d=i,v,E=!1;if(d&&(E=this.client.core.pairing.pairings.get(d).active),!d||!E){const{topic:L,uri:$}=await this.client.core.pairing.create();d=L,v=$}const _=await this.client.core.crypto.generateKeyPair(),O=on({requiredNamespaces:o,optionalNamespaces:c,relays:h??[{protocol:Yp}],proposer:{publicKey:_,metadata:this.client.metadata}},l&&{sessionProperties:l}),{reject:P,resolve:U,done:H}=Os(ke.FIVE_MINUTES,fg);if(this.events.once(er("session_connect"),async({error:L,session:$})=>{if(L)P(L);else if($){$.self.publicKey=_;const T=hh(on({},$),{requiredNamespaces:$.requiredNamespaces,optionalNamespaces:$.optionalNamespaces});await this.client.session.set($.topic,T),await this.setExpiry($.topic,$.expiry),d&&await this.client.core.pairing.updateMetadata({topic:d,metadata:$.peer.metadata}),U(T)}}),!d){const{message:L}=_e("NO_MATCHING_KEY",`connect() pairing topic: ${d}`);throw new Error(L)}const G=await this.sendRequest(d,"wc_sessionPropose",O),N=Dn(ke.FIVE_MINUTES);return await this.setProposal(G,on({id:G,expiry:N},O)),{uri:v,approval:H}},this.pair=async r=>(this.isInitialized(),await this.client.core.pairing.pair(r)),this.approve=async r=>{this.isInitialized(),await this.isValidApprove(r);const{id:n,relayProtocol:i,namespaces:o,sessionProperties:c}=r,l=this.client.proposal.get(n);let{pairingTopic:h,proposer:d,requiredNamespaces:v,optionalNamespaces:E}=l;h=h||"",Ds(v)||(v=db(o,"approve()"));const _=await this.client.core.crypto.generateKeyPair(),O=d.publicKey,P=await this.client.core.crypto.generateSharedKey(_,O);h&&n&&(await this.client.core.pairing.updateMetadata({topic:h,metadata:d.metadata}),await this.sendResult(n,h,{relay:{protocol:i??"irn"},responderPublicKey:_}),await this.client.proposal.delete(n,Zt("USER_DISCONNECTED")),await this.client.core.pairing.activate({topic:h}));const U=on({relay:{protocol:i??"irn"},namespaces:o,requiredNamespaces:v,optionalNamespaces:E,pairingTopic:h,controller:{publicKey:_,metadata:this.client.metadata},expiry:Dn(ic)},c&&{sessionProperties:c});await this.client.core.relayer.subscribe(P),await this.sendRequest(P,"wc_sessionSettle",U);const H=hh(on({},U),{topic:P,pairingTopic:h,acknowledged:!1,self:U.controller,peer:{publicKey:d.publicKey,metadata:d.metadata},controller:_});return await this.client.session.set(P,H),await this.setExpiry(P,Dn(ic)),{topic:P,acknowledged:()=>new Promise(G=>G(this.client.session.get(P)))}},this.reject=async r=>{this.isInitialized(),await this.isValidReject(r);const{id:n,reason:i}=r,{pairingTopic:o}=this.client.proposal.get(n);o&&(await this.sendError(n,o,i),await this.client.proposal.delete(n,Zt("USER_DISCONNECTED")))},this.update=async r=>{this.isInitialized(),await this.isValidUpdate(r);const{topic:n,namespaces:i}=r,o=await this.sendRequest(n,"wc_sessionUpdate",{namespaces:i}),{done:c,resolve:l,reject:h}=Os();return this.events.once(er("session_update",o),({error:d})=>{d?h(d):l()}),await this.client.session.update(n,{namespaces:i}),{acknowledged:c}},this.extend=async r=>{this.isInitialized(),await this.isValidExtend(r);const{topic:n}=r,i=await this.sendRequest(n,"wc_sessionExtend",{}),{done:o,resolve:c,reject:l}=Os();return this.events.once(er("session_extend",i),({error:h})=>{h?l(h):c()}),await this.setExpiry(n,Dn(ic)),{acknowledged:o}},this.request=async r=>{this.isInitialized(),await this.isValidRequest(r);const{chainId:n,request:i,topic:o,expiry:c}=r,l=await this.sendRequest(o,"wc_sessionRequest",{request:i,chainId:n},c),{done:h,resolve:d,reject:v}=Os(c);return this.events.once(er("session_request",l),({error:E,result:_})=>{E?v(E):d(_)}),this.client.events.emit("session_request_sent",{topic:o,request:i,chainId:n,id:l}),await h()},this.respond=async r=>{this.isInitialized(),await this.isValidRespond(r);const{topic:n,response:i}=r,{id:o}=i;qn(i)?await this.sendResult(o,n,i.result):_n(i)&&await this.sendError(o,n,i.error),this.deletePendingSessionRequest(r.response.id,{message:"fulfilled",code:0})},this.ping=async r=>{this.isInitialized(),await this.isValidPing(r);const{topic:n}=r;if(this.client.session.keys.includes(n)){const i=await this.sendRequest(n,"wc_sessionPing",{}),{done:o,resolve:c,reject:l}=Os();this.events.once(er("session_ping",i),({error:h})=>{h?l(h):c()}),await o()}else this.client.core.pairing.pairings.keys.includes(n)&&await this.client.core.pairing.ping({topic:n})},this.emit=async r=>{this.isInitialized(),await this.isValidEmit(r);const{topic:n,event:i,chainId:o}=r;await this.sendRequest(n,"wc_sessionEvent",{event:i,chainId:o})},this.disconnect=async r=>{this.isInitialized(),await this.isValidDisconnect(r);const{topic:n}=r;this.client.session.keys.includes(n)?(await this.sendRequest(n,"wc_sessionDelete",Zt("USER_DISCONNECTED")),await this.deleteSession(n)):await this.client.core.pairing.disconnect({topic:n})},this.find=r=>(this.isInitialized(),this.client.session.getAll().filter(n=>mb(n,r))),this.getPendingSessionRequests=()=>(this.isInitialized(),this.client.pendingRequest.getAll()),this.cleanupDuplicatePairings=async r=>{try{const n=this.client.core.pairing.pairings.get(r.pairingTopic),i=this.client.core.pairing.pairings.getAll().filter(o=>{var c,l;return((c=o.peerMetadata)==null?void 0:c.url)&&((l=o.peerMetadata)==null?void 0:l.url)===r.self.metadata.url&&o.topic!==n.topic});if(i.length===0)return;this.client.logger.info(`Cleaning up ${i.length} duplicate pairing(s)`),await Promise.all(i.map(o=>this.client.core.pairing.disconnect({topic:o.topic}))),this.client.logger.info("Duplicate pairings clean up finished")}catch(n){this.client.logger.error(n)}},this.deleteSession=async(r,n)=>{const{self:i}=this.client.session.get(r);await this.client.core.relayer.unsubscribe(r),await Promise.all([this.client.session.delete(r,Zt("USER_DISCONNECTED")),this.client.core.crypto.deleteKeyPair(i.publicKey),this.client.core.crypto.deleteSymKey(r),n?Promise.resolve():this.client.core.expirer.del(r)])},this.deleteProposal=async(r,n)=>{await Promise.all([this.client.proposal.delete(r,Zt("USER_DISCONNECTED")),n?Promise.resolve():this.client.core.expirer.del(r)])},this.deletePendingSessionRequest=async(r,n,i=!1)=>{await Promise.all([this.client.pendingRequest.delete(r,n),i?Promise.resolve():this.client.core.expirer.del(r)])},this.setExpiry=async(r,n)=>{this.client.session.keys.includes(r)&&await this.client.session.update(r,{expiry:n}),this.client.core.expirer.set(r,n)},this.setProposal=async(r,n)=>{await this.client.proposal.set(r,n),this.client.core.expirer.set(r,n.expiry)},this.setPendingSessionRequest=async r=>{const n=zo.wc_sessionRequest.req.ttl,{id:i,topic:o,params:c}=r;await this.client.pendingRequest.set(i,{id:i,topic:o,params:c}),n&&this.client.core.expirer.set(i,Dn(n))},this.sendRequest=async(r,n,i,o)=>{const c=ec(n,i);if(Su()&&e7.includes(n)){const d=Bi(JSON.stringify(c));await this.client.core.verify.register({attestationId:d})}const l=await this.client.core.crypto.encode(r,c),h=zo[n].req;return o&&(h.ttl=o),this.client.core.history.set(r,c),this.client.core.relayer.publish(r,l,h),c.id},this.sendResult=async(r,n,i)=>{const o=Ju(r,i),c=await this.client.core.crypto.encode(n,o),l=await this.client.core.history.get(n,r),h=zo[l.request.method].res;this.client.core.relayer.publish(n,c,h),await this.client.core.history.resolve(o)},this.sendError=async(r,n,i)=>{const o=tc(r,i),c=await this.client.core.crypto.encode(n,o),l=await this.client.core.history.get(n,r),h=zo[l.request.method].res;this.client.core.relayer.publish(n,c,h),await this.client.core.history.resolve(o)},this.cleanup=async()=>{const r=[],n=[];this.client.session.getAll().forEach(i=>{li(i.expiry)&&r.push(i.topic)}),this.client.proposal.getAll().forEach(i=>{li(i.expiry)&&n.push(i.id)}),await Promise.all([...r.map(i=>this.deleteSession(i)),...n.map(i=>this.deleteProposal(i))])},this.onRelayEventRequest=r=>{const{topic:n,payload:i}=r,o=i.method;switch(o){case"wc_sessionPropose":return this.onSessionProposeRequest(n,i);case"wc_sessionSettle":return this.onSessionSettleRequest(n,i);case"wc_sessionUpdate":return this.onSessionUpdateRequest(n,i);case"wc_sessionExtend":return this.onSessionExtendRequest(n,i);case"wc_sessionPing":return this.onSessionPingRequest(n,i);case"wc_sessionDelete":return this.onSessionDeleteRequest(n,i);case"wc_sessionRequest":return this.onSessionRequest(n,i);case"wc_sessionEvent":return this.onSessionEventRequest(n,i);default:return this.client.logger.info(`Unsupported request method ${o}`)}},this.onRelayEventResponse=async r=>{const{topic:n,payload:i}=r,o=(await this.client.core.history.get(n,i.id)).request.method;switch(o){case"wc_sessionPropose":return this.onSessionProposeResponse(n,i);case"wc_sessionSettle":return this.onSessionSettleResponse(n,i);case"wc_sessionUpdate":return this.onSessionUpdateResponse(n,i);case"wc_sessionExtend":return this.onSessionExtendResponse(n,i);case"wc_sessionPing":return this.onSessionPingResponse(n,i);case"wc_sessionRequest":return this.onSessionRequestResponse(n,i);default:return this.client.logger.info(`Unsupported response method ${o}`)}},this.onSessionProposeRequest=async(r,n)=>{const{params:i,id:o}=n;try{this.isValidConnect(on({},n.params));const c=Dn(ke.FIVE_MINUTES),l=on({id:o,pairingTopic:r,expiry:c},i);await this.setProposal(o,l);const h=Bi(JSON.stringify(n)),d=await this.getVerifyContext(h,l.proposer.metadata);this.client.events.emit("session_proposal",{id:o,params:l,context:d})}catch(c){await this.sendError(o,r,c),this.client.logger.error(c)}},this.onSessionProposeResponse=async(r,n)=>{const{id:i}=n;if(qn(n)){const{result:o}=n;this.client.logger.trace({type:"method",method:"onSessionProposeResponse",result:o});const c=this.client.proposal.get(i);this.client.logger.trace({type:"method",method:"onSessionProposeResponse",proposal:c});const l=c.proposer.publicKey;this.client.logger.trace({type:"method",method:"onSessionProposeResponse",selfPublicKey:l});const h=o.responderPublicKey;this.client.logger.trace({type:"method",method:"onSessionProposeResponse",peerPublicKey:h});const d=await this.client.core.crypto.generateSharedKey(l,h);this.client.logger.trace({type:"method",method:"onSessionProposeResponse",sessionTopic:d});const v=await this.client.core.relayer.subscribe(d);this.client.logger.trace({type:"method",method:"onSessionProposeResponse",subscriptionId:v}),await this.client.core.pairing.activate({topic:r})}else _n(n)&&(await this.client.proposal.delete(i,Zt("USER_DISCONNECTED")),this.events.emit(er("session_connect"),{error:n.error}))},this.onSessionSettleRequest=async(r,n)=>{const{id:i,params:o}=n;try{this.isValidSessionSettleRequest(o);const{relay:c,controller:l,expiry:h,namespaces:d,requiredNamespaces:v,optionalNamespaces:E,sessionProperties:_,pairingTopic:O}=n.params,P=on({topic:r,relay:c,expiry:h,namespaces:d,acknowledged:!0,pairingTopic:O,requiredNamespaces:v,optionalNamespaces:E,controller:l.publicKey,self:{publicKey:"",metadata:this.client.metadata},peer:{publicKey:l.publicKey,metadata:l.metadata}},_&&{sessionProperties:_});await this.sendResult(n.id,r,!0),this.events.emit(er("session_connect"),{session:P}),this.cleanupDuplicatePairings(P)}catch(c){await this.sendError(i,r,c),this.client.logger.error(c)}},this.onSessionSettleResponse=async(r,n)=>{const{id:i}=n;qn(n)?(await this.client.session.update(r,{acknowledged:!0}),this.events.emit(er("session_approve",i),{})):_n(n)&&(await this.client.session.delete(r,Zt("USER_DISCONNECTED")),this.events.emit(er("session_approve",i),{error:n.error}))},this.onSessionUpdateRequest=async(r,n)=>{const{params:i,id:o}=n;try{this.isValidUpdate(on({topic:r},i)),await this.client.session.update(r,{namespaces:i.namespaces}),await this.sendResult(o,r,!0),this.client.events.emit("session_update",{id:o,topic:r,params:i})}catch(c){await this.sendError(o,r,c),this.client.logger.error(c)}},this.onSessionUpdateResponse=(r,n)=>{const{id:i}=n;qn(n)?this.events.emit(er("session_update",i),{}):_n(n)&&this.events.emit(er("session_update",i),{error:n.error})},this.onSessionExtendRequest=async(r,n)=>{const{id:i}=n;try{this.isValidExtend({topic:r}),await this.setExpiry(r,Dn(ic)),await this.sendResult(i,r,!0),this.client.events.emit("session_extend",{id:i,topic:r})}catch(o){await this.sendError(i,r,o),this.client.logger.error(o)}},this.onSessionExtendResponse=(r,n)=>{const{id:i}=n;qn(n)?this.events.emit(er("session_extend",i),{}):_n(n)&&this.events.emit(er("session_extend",i),{error:n.error})},this.onSessionPingRequest=async(r,n)=>{const{id:i}=n;try{this.isValidPing({topic:r}),await this.sendResult(i,r,!0),this.client.events.emit("session_ping",{id:i,topic:r})}catch(o){await this.sendError(i,r,o),this.client.logger.error(o)}},this.onSessionPingResponse=(r,n)=>{const{id:i}=n;setTimeout(()=>{qn(n)?this.events.emit(er("session_ping",i),{}):_n(n)&&this.events.emit(er("session_ping",i),{error:n.error})},500)},this.onSessionDeleteRequest=async(r,n)=>{const{id:i}=n;try{this.isValidDisconnect({topic:r,reason:n.params}),await Promise.all([new Promise(o=>{this.client.core.relayer.once(pr.publish,async()=>{o(await this.deleteSession(r))})}),this.sendResult(i,r,!0)]),this.client.events.emit("session_delete",{id:i,topic:r})}catch(o){await this.sendError(i,r,o),this.client.logger.error(o)}},this.onSessionRequest=async(r,n)=>{const{id:i,params:o}=n;try{this.isValidRequest(on({topic:r},o)),await this.setPendingSessionRequest({id:i,topic:r,params:o});const c=Bi(JSON.stringify(n)),l=this.client.session.get(r),h=await this.getVerifyContext(c,l.peer.metadata);this.client.events.emit("session_request",{id:i,topic:r,params:o,context:h})}catch(c){await this.sendError(i,r,c),this.client.logger.error(c)}},this.onSessionRequestResponse=(r,n)=>{const{id:i}=n;qn(n)?this.events.emit(er("session_request",i),{result:n.result}):_n(n)&&this.events.emit(er("session_request",i),{error:n.error})},this.onSessionEventRequest=async(r,n)=>{const{id:i,params:o}=n;try{this.isValidEmit(on({topic:r},o)),this.client.events.emit("session_event",{id:i,topic:r,params:o})}catch(c){await this.sendError(i,r,c),this.client.logger.error(c)}},this.isValidConnect=async r=>{if(!Hr(r)){const{message:h}=_e("MISSING_OR_INVALID",`connect() params: ${JSON.stringify(r)}`);throw new Error(h)}const{pairingTopic:n,requiredNamespaces:i,optionalNamespaces:o,sessionProperties:c,relays:l}=r;if($r(n)||await this.isValidPairingTopic(n),!Ab(l,!0)){const{message:h}=_e("MISSING_OR_INVALID",`connect() relays: ${l}`);throw new Error(h)}!$r(i)&&Ds(i)!==0&&this.validateNamespaces(i,"requiredNamespaces"),!$r(o)&&Ds(o)!==0&&this.validateNamespaces(o,"optionalNamespaces"),$r(c)||this.validateSessionProps(c,"sessionProperties")},this.validateNamespaces=(r,n)=>{const i=Ob(r,"connect()",n);if(i)throw new Error(i.message)},this.isValidApprove=async r=>{if(!Hr(r))throw new Error(_e("MISSING_OR_INVALID",`approve() params: ${r}`).message);const{id:n,namespaces:i,relayProtocol:o,sessionProperties:c}=r;await this.isValidProposalId(n);const l=this.client.proposal.get(n),h=Ya(i,"approve()");if(h)throw new Error(h.message);const d=F1(l.requiredNamespaces,i,"approve()");if(d)throw new Error(d.message);if(!dr(o,!0)){const{message:v}=_e("MISSING_OR_INVALID",`approve() relayProtocol: ${o}`);throw new Error(v)}$r(c)||this.validateSessionProps(c,"sessionProperties")},this.isValidReject=async r=>{if(!Hr(r)){const{message:o}=_e("MISSING_OR_INVALID",`reject() params: ${r}`);throw new Error(o)}const{id:n,reason:i}=r;if(await this.isValidProposalId(n),!$b(i)){const{message:o}=_e("MISSING_OR_INVALID",`reject() reason: ${JSON.stringify(i)}`);throw new Error(o)}},this.isValidSessionSettleRequest=r=>{if(!Hr(r)){const{message:d}=_e("MISSING_OR_INVALID",`onSessionSettleRequest() params: ${r}`);throw new Error(d)}const{relay:n,controller:i,namespaces:o,expiry:c}=r;if(!U1(n)){const{message:d}=_e("MISSING_OR_INVALID","onSessionSettleRequest() relay protocol should be a string");throw new Error(d)}const l=_b(i,"onSessionSettleRequest()");if(l)throw new Error(l.message);const h=Ya(o,"onSessionSettleRequest()");if(h)throw new Error(h.message);if(li(c)){const{message:d}=_e("EXPIRED","onSessionSettleRequest()");throw new Error(d)}},this.isValidUpdate=async r=>{if(!Hr(r)){const{message:h}=_e("MISSING_OR_INVALID",`update() params: ${r}`);throw new Error(h)}const{topic:n,namespaces:i}=r;await this.isValidSessionTopic(n);const o=this.client.session.get(n),c=Ya(i,"update()");if(c)throw new Error(c.message);const l=F1(o.requiredNamespaces,i,"update()");if(l)throw new Error(l.message)},this.isValidExtend=async r=>{if(!Hr(r)){const{message:i}=_e("MISSING_OR_INVALID",`extend() params: ${r}`);throw new Error(i)}const{topic:n}=r;await this.isValidSessionTopic(n)},this.isValidRequest=async r=>{if(!Hr(r)){const{message:h}=_e("MISSING_OR_INVALID",`request() params: ${r}`);throw new Error(h)}const{topic:n,request:i,chainId:o,expiry:c}=r;await this.isValidSessionTopic(n);const{namespaces:l}=this.client.session.get(n);if(!j1(l,o)){const{message:h}=_e("MISSING_OR_INVALID",`request() chainId: ${o}`);throw new Error(h)}if(!Pb(i)){const{message:h}=_e("MISSING_OR_INVALID",`request() ${JSON.stringify(i)}`);throw new Error(h)}if(!Nb(l,o,i.method)){const{message:h}=_e("MISSING_OR_INVALID",`request() method: ${i.method}`);throw new Error(h)}if(c&&!jb(c,uh)){const{message:h}=_e("MISSING_OR_INVALID",`request() expiry: ${c}. Expiry must be a number (in seconds) between ${uh.min} and ${uh.max}`);throw new Error(h)}},this.isValidRespond=async r=>{if(!Hr(r)){const{message:o}=_e("MISSING_OR_INVALID",`respond() params: ${r}`);throw new Error(o)}const{topic:n,response:i}=r;if(await this.isValidSessionTopic(n),!Tb(i)){const{message:o}=_e("MISSING_OR_INVALID",`respond() response: ${JSON.stringify(i)}`);throw new Error(o)}},this.isValidPing=async r=>{if(!Hr(r)){const{message:i}=_e("MISSING_OR_INVALID",`ping() params: ${r}`);throw new Error(i)}const{topic:n}=r;await this.isValidSessionOrPairingTopic(n)},this.isValidEmit=async r=>{if(!Hr(r)){const{message:l}=_e("MISSING_OR_INVALID",`emit() params: ${r}`);throw new Error(l)}const{topic:n,event:i,chainId:o}=r;await this.isValidSessionTopic(n);const{namespaces:c}=this.client.session.get(n);if(!j1(c,o)){const{message:l}=_e("MISSING_OR_INVALID",`emit() chainId: ${o}`);throw new Error(l)}if(!Rb(i)){const{message:l}=_e("MISSING_OR_INVALID",`emit() event: ${JSON.stringify(i)}`);throw new Error(l)}if(!Lb(c,o,i.name)){const{message:l}=_e("MISSING_OR_INVALID",`emit() event: ${JSON.stringify(i)}`);throw new Error(l)}},this.isValidDisconnect=async r=>{if(!Hr(r)){const{message:i}=_e("MISSING_OR_INVALID",`disconnect() params: ${r}`);throw new Error(i)}const{topic:n}=r;await this.isValidSessionOrPairingTopic(n)},this.getVerifyContext=async(r,n)=>{const i={verified:{verifyUrl:n.verifyUrl||"",validation:"UNKNOWN",origin:n.url||""}};try{const o=await this.client.core.verify.resolve({attestationId:r,verifyUrl:n.verifyUrl});o&&(i.verified.origin=o,i.verified.validation=o===n.url?"VALID":"INVALID")}catch(o){this.client.logger.error(o)}return this.client.logger.info(`Verify context: ${JSON.stringify(i)}`),i},this.validateSessionProps=(r,n)=>{Object.values(r).forEach(i=>{if(!dr(i,!1)){const{message:o}=_e("MISSING_OR_INVALID",`${n} must be in Record<string, string> format. Received: ${JSON.stringify(i)}`);throw new Error(o)}})}}isInitialized(){if(!this.initialized){const{message:e}=_e("NOT_INITIALIZED",this.name);throw new Error(e)}}registerRelayerEvents(){this.client.core.relayer.on(pr.message,async e=>{const{topic:r,message:n}=e;if(this.ignoredPayloadTypes.includes(this.client.core.crypto.getPayloadType(n)))return;const i=await this.client.core.crypto.decode(r,n);Xu(i)?(this.client.core.history.set(r,i),this.onRelayEventRequest({topic:r,payload:i})):Qu(i)&&(await this.client.core.history.resolve(i),this.onRelayEventResponse({topic:r,payload:i}))})}registerExpirerEvents(){this.client.core.expirer.on(sn.expired,async e=>{const{topic:r,id:n}=P1(e.target);if(n&&this.client.pendingRequest.keys.includes(n))return await this.deletePendingSessionRequest(n,_e("EXPIRED"),!0);r?this.client.session.keys.includes(r)&&(await this.deleteSession(r,!0),this.client.events.emit("session_expire",{topic:r})):n&&(await this.deleteProposal(n,!0),this.client.events.emit("proposal_expire",{id:n}))})}isValidPairingTopic(e){if(!dr(e,!1)){const{message:r}=_e("MISSING_OR_INVALID",`pairing topic should be a string: ${e}`);throw new Error(r)}if(!this.client.core.pairing.pairings.keys.includes(e)){const{message:r}=_e("NO_MATCHING_KEY",`pairing topic doesn't exist: ${e}`);throw new Error(r)}if(li(this.client.core.pairing.pairings.get(e).expiry)){const{message:r}=_e("EXPIRED",`pairing topic: ${e}`);throw new Error(r)}}async isValidSessionTopic(e){if(!dr(e,!1)){const{message:r}=_e("MISSING_OR_INVALID",`session topic should be a string: ${e}`);throw new Error(r)}if(!this.client.session.keys.includes(e)){const{message:r}=_e("NO_MATCHING_KEY",`session topic doesn't exist: ${e}`);throw new Error(r)}if(li(this.client.session.get(e).expiry)){await this.deleteSession(e);const{message:r}=_e("EXPIRED",`session topic: ${e}`);throw new Error(r)}}async isValidSessionOrPairingTopic(e){if(this.client.session.keys.includes(e))await this.isValidSessionTopic(e);else if(this.client.core.pairing.pairings.keys.includes(e))this.isValidPairingTopic(e);else if(dr(e,!1)){const{message:r}=_e("NO_MATCHING_KEY",`session or pairing topic doesn't exist: ${e}`);throw new Error(r)}else{const{message:r}=_e("MISSING_OR_INVALID",`session or pairing topic should be a string: ${e}`);throw new Error(r)}}async isValidProposalId(e){if(!Db(e)){const{message:r}=_e("MISSING_OR_INVALID",`proposal id should be a number: ${e}`);throw new Error(r)}if(!this.client.proposal.keys.includes(e)){const{message:r}=_e("NO_MATCHING_KEY",`proposal id doesn't exist: ${e}`);throw new Error(r)}if(li(this.client.proposal.get(e).expiry)){await this.deleteProposal(e);const{message:r}=_e("EXPIRED",`proposal id: ${e}`);throw new Error(r)}}}class a7 extends nc{constructor(e,r){super(e,r,YE,ch),this.core=e,this.logger=r}}class c7 extends nc{constructor(e,r){super(e,r,JE,ch),this.core=e,this.logger=r}}class l7 extends nc{constructor(e,r){super(e,r,QE,ch,n=>n.id),this.core=e,this.logger=r}}class fh extends v4{constructor(e){super(e),this.protocol=lg,this.version=ug,this.name=lh.name,this.events=new yr.exports.EventEmitter,this.on=(n,i)=>this.events.on(n,i),this.once=(n,i)=>this.events.once(n,i),this.off=(n,i)=>this.events.off(n,i),this.removeListener=(n,i)=>this.events.removeListener(n,i),this.removeAllListeners=n=>this.events.removeAllListeners(n),this.connect=async n=>{try{return await this.engine.connect(n)}catch(i){throw this.logger.error(i.message),i}},this.pair=async n=>{try{return await this.engine.pair(n)}catch(i){throw this.logger.error(i.message),i}},this.approve=async n=>{try{return await this.engine.approve(n)}catch(i){throw this.logger.error(i.message),i}},this.reject=async n=>{try{return await this.engine.reject(n)}catch(i){throw this.logger.error(i.message),i}},this.update=async n=>{try{return await this.engine.update(n)}catch(i){throw this.logger.error(i.message),i}},this.extend=async n=>{try{return await this.engine.extend(n)}catch(i){throw this.logger.error(i.message),i}},this.request=async n=>{try{return await this.engine.request(n)}catch(i){throw this.logger.error(i.message),i}},this.respond=async n=>{try{return await this.engine.respond(n)}catch(i){throw this.logger.error(i.message),i}},this.ping=async n=>{try{return await this.engine.ping(n)}catch(i){throw this.logger.error(i.message),i}},this.emit=async n=>{try{return await this.engine.emit(n)}catch(i){throw this.logger.error(i.message),i}},this.disconnect=async n=>{try{return await this.engine.disconnect(n)}catch(i){throw this.logger.error(i.message),i}},this.find=n=>{try{return this.engine.find(n)}catch(i){throw this.logger.error(i.message),i}},this.getPendingSessionRequests=()=>{try{return this.engine.getPendingSessionRequests()}catch(n){throw this.logger.error(n.message),n}},this.name=e?.name||lh.name,this.metadata=e?.metadata||G5();const r=typeof e?.logger<"u"&&typeof e?.logger!="string"?e.logger:pt.pino(pt.getDefaultLoggerOptions({level:e?.logger||lh.logger}));this.core=e?.core||new ZE(e),this.logger=pt.generateChildLogger(r,this.name),this.session=new c7(this.core,this.logger),this.proposal=new a7(this.core,this.logger),this.pendingRequest=new l7(this.core,this.logger),this.engine=new o7(this)}static async init(e){const r=new fh(e);return await r.initialize(),r}get context(){return pt.getLoggerContext(this.logger)}get pairing(){return this.core.pairing.pairings}async initialize(){this.logger.trace("Initialized");try{await this.core.start(),await this.session.init(),await this.proposal.init(),await this.pendingRequest.init(),await this.engine.init(),this.core.verify.init({verifyUrl:this.metadata.verifyUrl}),this.logger.info("SignClient Initialization Success")}catch(e){throw this.logger.info("SignClient Initialization Failure"),this.logger.error(e.message),e}}}var dh={exports:{}};(function(t,e){var r=typeof self<"u"?self:fr,n=function(){function o(){this.fetch=!1,this.DOMException=r.DOMException}return o.prototype=r,new o}();(function(o){(function(c){var l={searchParams:"URLSearchParams"in o,iterable:"Symbol"in o&&"iterator"in Symbol,blob:"FileReader"in o&&"Blob"in o&&function(){try{return new Blob,!0}catch{return!1}}(),formData:"FormData"in o,arrayBuffer:"ArrayBuffer"in o};function h(S){return S&&DataView.prototype.isPrototypeOf(S)}if(l.arrayBuffer)var d=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],v=ArrayBuffer.isView||function(S){return S&&d.indexOf(Object.prototype.toString.call(S))>-1};function E(S){if(typeof S!="string"&&(S=String(S)),/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(S))throw new TypeError("Invalid character in header field name");return S.toLowerCase()}function _(S){return typeof S!="string"&&(S=String(S)),S}function O(S){var j={next:function(){var ce=S.shift();return{done:ce===void 0,value:ce}}};return l.iterable&&(j[Symbol.iterator]=function(){return j}),j}function P(S){this.map={},S instanceof P?S.forEach(function(j,ce){this.append(ce,j)},this):Array.isArray(S)?S.forEach(function(j){this.append(j[0],j[1])},this):S&&Object.getOwnPropertyNames(S).forEach(function(j){this.append(j,S[j])},this)}P.prototype.append=function(S,j){S=E(S),j=_(j);var ce=this.map[S];this.map[S]=ce?ce+", "+j:j},P.prototype.delete=function(S){delete this.map[E(S)]},P.prototype.get=function(S){return S=E(S),this.has(S)?this.map[S]:null},P.prototype.has=function(S){return this.map.hasOwnProperty(E(S))},P.prototype.set=function(S,j){this.map[E(S)]=_(j)},P.prototype.forEach=function(S,j){for(var ce in this.map)this.map.hasOwnProperty(ce)&&S.call(j,this.map[ce],ce,this)},P.prototype.keys=function(){var S=[];return this.forEach(function(j,ce){S.push(ce)}),O(S)},P.prototype.values=function(){var S=[];return this.forEach(function(j){S.push(j)}),O(S)},P.prototype.entries=function(){var S=[];return this.forEach(function(j,ce){S.push([ce,j])}),O(S)},l.iterable&&(P.prototype[Symbol.iterator]=P.prototype.entries);function U(S){if(S.bodyUsed)return Promise.reject(new TypeError("Already read"));S.bodyUsed=!0}function H(S){return new Promise(function(j,ce){S.onload=function(){j(S.result)},S.onerror=function(){ce(S.error)}})}function G(S){var j=new FileReader,ce=H(j);return j.readAsArrayBuffer(S),ce}function N(S){var j=new FileReader,ce=H(j);return j.readAsText(S),ce}function L(S){for(var j=new Uint8Array(S),ce=new Array(j.length),le=0;le<j.length;le++)ce[le]=String.fromCharCode(j[le]);return ce.join("")}function $(S){if(S.slice)return S.slice(0);var j=new Uint8Array(S.byteLength);return j.set(new Uint8Array(S)),j.buffer}function T(){return this.bodyUsed=!1,this._initBody=function(S){this._bodyInit=S,S?typeof S=="string"?this._bodyText=S:l.blob&&Blob.prototype.isPrototypeOf(S)?this._bodyBlob=S:l.formData&&FormData.prototype.isPrototypeOf(S)?this._bodyFormData=S:l.searchParams&&URLSearchParams.prototype.isPrototypeOf(S)?this._bodyText=S.toString():l.arrayBuffer&&l.blob&&h(S)?(this._bodyArrayBuffer=$(S.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):l.arrayBuffer&&(ArrayBuffer.prototype.isPrototypeOf(S)||v(S))?this._bodyArrayBuffer=$(S):this._bodyText=S=Object.prototype.toString.call(S):this._bodyText="",this.headers.get("content-type")||(typeof S=="string"?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):l.searchParams&&URLSearchParams.prototype.isPrototypeOf(S)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},l.blob&&(this.blob=function(){var S=U(this);if(S)return S;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){return this._bodyArrayBuffer?U(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(G)}),this.text=function(){var S=U(this);if(S)return S;if(this._bodyBlob)return N(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(L(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},l.formData&&(this.formData=function(){return this.text().then(J)}),this.json=function(){return this.text().then(JSON.parse)},this}var I=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function f(S){var j=S.toUpperCase();return I.indexOf(j)>-1?j:S}function x(S,j){j=j||{};var ce=j.body;if(S instanceof x){if(S.bodyUsed)throw new TypeError("Already read");this.url=S.url,this.credentials=S.credentials,j.headers||(this.headers=new P(S.headers)),this.method=S.method,this.mode=S.mode,this.signal=S.signal,!ce&&S._bodyInit!=null&&(ce=S._bodyInit,S.bodyUsed=!0)}else this.url=String(S);if(this.credentials=j.credentials||this.credentials||"same-origin",(j.headers||!this.headers)&&(this.headers=new P(j.headers)),this.method=f(j.method||this.method||"GET"),this.mode=j.mode||this.mode||null,this.signal=j.signal||this.signal,this.referrer=null,(this.method==="GET"||this.method==="HEAD")&&ce)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(ce)}x.prototype.clone=function(){return new x(this,{body:this._bodyInit})};function J(S){var j=new FormData;return S.trim().split("&").forEach(function(ce){if(ce){var le=ce.split("="),re=le.shift().replace(/\+/g," "),ne=le.join("=").replace(/\+/g," ");j.append(decodeURIComponent(re),decodeURIComponent(ne))}}),j}function z(S){var j=new P,ce=S.replace(/\r?\n[\t ]+/g," ");return ce.split(/\r?\n/).forEach(function(le){var re=le.split(":"),ne=re.shift().trim();if(ne){var ae=re.join(":").trim();j.append(ne,ae)}}),j}T.call(x.prototype);function ee(S,j){j||(j={}),this.type="default",this.status=j.status===void 0?200:j.status,this.ok=this.status>=200&&this.status<300,this.statusText="statusText"in j?j.statusText:"OK",this.headers=new P(j.headers),this.url=j.url||"",this._initBody(S)}T.call(ee.prototype),ee.prototype.clone=function(){return new ee(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new P(this.headers),url:this.url})},ee.error=function(){var S=new ee(null,{status:0,statusText:""});return S.type="error",S};var de=[301,302,303,307,308];ee.redirect=function(S,j){if(de.indexOf(j)===-1)throw new RangeError("Invalid status code");return new ee(null,{status:j,headers:{location:S}})},c.DOMException=o.DOMException;try{new c.DOMException}catch{c.DOMException=function(j,ce){this.message=j,this.name=ce;var le=Error(j);this.stack=le.stack},c.DOMException.prototype=Object.create(Error.prototype),c.DOMException.prototype.constructor=c.DOMException}function me(S,j){return new Promise(function(ce,le){var re=new x(S,j);if(re.signal&&re.signal.aborted)return le(new c.DOMException("Aborted","AbortError"));var ne=new XMLHttpRequest;function ae(){ne.abort()}ne.onload=function(){var ie={status:ne.status,statusText:ne.statusText,headers:z(ne.getAllResponseHeaders()||"")};ie.url="responseURL"in ne?ne.responseURL:ie.headers.get("X-Request-URL");var Ae="response"in ne?ne.response:ne.responseText;ce(new ee(Ae,ie))},ne.onerror=function(){le(new TypeError("Network request failed"))},ne.ontimeout=function(){le(new TypeError("Network request failed"))},ne.onabort=function(){le(new c.DOMException("Aborted","AbortError"))},ne.open(re.method,re.url,!0),re.credentials==="include"?ne.withCredentials=!0:re.credentials==="omit"&&(ne.withCredentials=!1),"responseType"in ne&&l.blob&&(ne.responseType="blob"),re.headers.forEach(function(ie,Ae){ne.setRequestHeader(Ae,ie)}),re.signal&&(re.signal.addEventListener("abort",ae),ne.onreadystatechange=function(){ne.readyState===4&&re.signal.removeEventListener("abort",ae)}),ne.send(typeof re._bodyInit>"u"?null:re._bodyInit)})}return me.polyfill=!0,o.fetch||(o.fetch=me,o.Headers=P,o.Request=x,o.Response=ee),c.Headers=P,c.Request=x,c.Response=ee,c.fetch=me,Object.defineProperty(c,"__esModule",{value:!0}),c})({})})(n),n.fetch.ponyfill=!0,delete n.fetch.polyfill;var i=n;e=i.fetch,e.default=i.fetch,e.fetch=i.fetch,e.Headers=i.Headers,e.Request=i.Request,e.Response=i.Response,t.exports=e})(dh,dh.exports);var gg=hw(dh.exports);const mg={headers:{Accept:"application/json","Content-Type":"application/json"},method:"POST"},wg=10;class Vi{constructor(e){if(this.url=e,this.events=new yr.exports.EventEmitter,this.isAvailable=!1,this.registering=!1,!Ip(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,r){this.events.on(e,r)}once(e,r){this.events.once(e,r)}off(e,r){this.events.off(e,r)}removeListener(e,r){this.events.removeListener(e,r)}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,r){this.isAvailable||await this.register();try{const n=Mo(e),o=await(await gg(this.url,Object.assign(Object.assign({},mg),{body:n}))).json();this.onPayload({data:o})}catch(n){this.onError(e.id,n)}}async register(e=this.url){if(!Ip(e))throw new Error(`Provided URL is not compatible with HTTP connection: ${e}`);if(this.registering){const r=this.events.getMaxListeners();return(this.events.listenerCount("register_error")>=r||this.events.listenerCount("open")>=r)&&this.events.setMaxListeners(r+1),new Promise((n,i)=>{this.events.once("register_error",o=>{this.resetMaxListeners(),i(o)}),this.events.once("open",()=>{if(this.resetMaxListeners(),typeof this.isAvailable>"u")return i(new Error("HTTP connection is missing or invalid"));n()})})}this.url=e,this.registering=!0;try{const r=Mo({id:1,jsonrpc:"2.0",method:"test",params:[]});await gg(e,Object.assign(Object.assign({},mg),{body:r})),this.onOpen()}catch(r){const n=this.parseError(r);throw this.events.emit("register_error",n),this.onClose(),n}}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(typeof e.data>"u")return;const r=typeof e.data=="string"?qu(e.data):e.data;this.events.emit("payload",r)}onError(e,r){const n=this.parseError(r),i=n.message||n.toString(),o=tc(e,i);this.events.emit("payload",o)}parseError(e,r=this.url){return vp(e,r,"HTTP")}resetMaxListeners(){this.events.getMaxListeners()>wg&&this.events.setMaxListeners(wg)}}const vg="error",u7="wss://relay.walletconnect.com",h7="wc",f7="universal_provider",yg=`${h7}@${2}:${f7}:`,d7="https://rpc.walletconnect.com/v1",fi={DEFAULT_CHAIN_CHANGED:"default_chain_changed"};var Wo=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},ph={exports:{}};/**
|
|
72
|
+
***************************************************************************** */var Gu=function(t,e){return Gu=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,n){r.__proto__=n}||function(r,n){for(var i in n)n.hasOwnProperty(i)&&(r[i]=n[i])},Gu(t,e)};function z4(t,e){Gu(t,e);function r(){this.constructor=t}t.prototype=e===null?Object.create(e):(r.prototype=e.prototype,new r)}var Zu=function(){return Zu=Object.assign||function(e){for(var r,n=1,i=arguments.length;n<i;n++){r=arguments[n];for(var o in r)Object.prototype.hasOwnProperty.call(r,o)&&(e[o]=r[o])}return e},Zu.apply(this,arguments)};function W4(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,n=Object.getOwnPropertySymbols(t);i<n.length;i++)e.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(t,n[i])&&(r[n[i]]=t[n[i]]);return r}function q4(t,e,r,n){var i=arguments.length,o=i<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,r):n,c;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")o=Reflect.decorate(t,e,r,n);else for(var l=t.length-1;l>=0;l--)(c=t[l])&&(o=(i<3?c(o):i>3?c(e,r,o):c(e,r))||o);return i>3&&o&&Object.defineProperty(e,r,o),o}function V4(t,e){return function(r,n){e(r,n,t)}}function K4(t,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(t,e)}function G4(t,e,r,n){function i(o){return o instanceof r?o:new r(function(c){c(o)})}return new(r||(r=Promise))(function(o,c){function l(v){try{d(n.next(v))}catch(E){c(E)}}function h(v){try{d(n.throw(v))}catch(E){c(E)}}function d(v){v.done?o(v.value):i(v.value).then(l,h)}d((n=n.apply(t,e||[])).next())})}function Z4(t,e){var r={label:0,sent:function(){if(o[0]&1)throw o[1];return o[1]},trys:[],ops:[]},n,i,o,c;return c={next:l(0),throw:l(1),return:l(2)},typeof Symbol=="function"&&(c[Symbol.iterator]=function(){return this}),c;function l(d){return function(v){return h([d,v])}}function h(d){if(n)throw new TypeError("Generator is already executing.");for(;r;)try{if(n=1,i&&(o=d[0]&2?i.return:d[0]?i.throw||((o=i.return)&&o.call(i),0):i.next)&&!(o=o.call(i,d[1])).done)return o;switch(i=0,o&&(d=[d[0]&2,o.value]),d[0]){case 0:case 1:o=d;break;case 4:return r.label++,{value:d[1],done:!1};case 5:r.label++,i=d[1],d=[0];continue;case 7:d=r.ops.pop(),r.trys.pop();continue;default:if(o=r.trys,!(o=o.length>0&&o[o.length-1])&&(d[0]===6||d[0]===2)){r=0;continue}if(d[0]===3&&(!o||d[1]>o[0]&&d[1]<o[3])){r.label=d[1];break}if(d[0]===6&&r.label<o[1]){r.label=o[1],o=d;break}if(o&&r.label<o[2]){r.label=o[2],r.ops.push(d);break}o[2]&&r.ops.pop(),r.trys.pop();continue}d=e.call(t,r)}catch(v){d=[6,v],i=0}finally{n=o=0}if(d[0]&5)throw d[1];return{value:d[0]?d[1]:void 0,done:!0}}}function Y4(t,e,r,n){n===void 0&&(n=r),t[n]=e[r]}function J4(t,e){for(var r in t)r!=="default"&&!e.hasOwnProperty(r)&&(e[r]=t[r])}function Yu(t){var e=typeof Symbol=="function"&&Symbol.iterator,r=e&&t[e],n=0;if(r)return r.call(t);if(t&&typeof t.length=="number")return{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function bp(t,e){var r=typeof Symbol=="function"&&t[Symbol.iterator];if(!r)return t;var n=r.call(t),i,o=[],c;try{for(;(e===void 0||e-- >0)&&!(i=n.next()).done;)o.push(i.value)}catch(l){c={error:l}}finally{try{i&&!i.done&&(r=n.return)&&r.call(n)}finally{if(c)throw c.error}}return o}function X4(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(bp(arguments[e]));return t}function Q4(){for(var t=0,e=0,r=arguments.length;e<r;e++)t+=arguments[e].length;for(var n=Array(t),i=0,e=0;e<r;e++)for(var o=arguments[e],c=0,l=o.length;c<l;c++,i++)n[i]=o[c];return n}function jo(t){return this instanceof jo?(this.v=t,this):new jo(t)}function e_(t,e,r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n=r.apply(t,e||[]),i,o=[];return i={},c("next"),c("throw"),c("return"),i[Symbol.asyncIterator]=function(){return this},i;function c(_){n[_]&&(i[_]=function(O){return new Promise(function(P,U){o.push([_,O,P,U])>1||l(_,O)})})}function l(_,O){try{h(n[_](O))}catch(P){E(o[0][3],P)}}function h(_){_.value instanceof jo?Promise.resolve(_.value.v).then(d,v):E(o[0][2],_)}function d(_){l("next",_)}function v(_){l("throw",_)}function E(_,O){_(O),o.shift(),o.length&&l(o[0][0],o[0][1])}}function t_(t){var e,r;return e={},n("next"),n("throw",function(i){throw i}),n("return"),e[Symbol.iterator]=function(){return this},e;function n(i,o){e[i]=t[i]?function(c){return(r=!r)?{value:jo(t[i](c)),done:i==="return"}:o?o(c):c}:o}}function r_(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e=t[Symbol.asyncIterator],r;return e?e.call(t):(t=typeof Yu=="function"?Yu(t):t[Symbol.iterator](),r={},n("next"),n("throw"),n("return"),r[Symbol.asyncIterator]=function(){return this},r);function n(o){r[o]=t[o]&&function(c){return new Promise(function(l,h){c=t[o](c),i(l,h,c.done,c.value)})}}function i(o,c,l,h){Promise.resolve(h).then(function(d){o({value:d,done:l})},c)}}function n_(t,e){return Object.defineProperty?Object.defineProperty(t,"raw",{value:e}):t.raw=e,t}function i_(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)Object.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e.default=t,e}function s_(t){return t&&t.__esModule?t:{default:t}}function o_(t,e){if(!e.has(t))throw new TypeError("attempted to get private field on non-instance");return e.get(t)}function a_(t,e,r){if(!e.has(t))throw new TypeError("attempted to set private field on non-instance");return e.set(t,r),r}var c_=Object.freeze({__proto__:null,__extends:z4,get __assign(){return Zu},__rest:W4,__decorate:q4,__param:V4,__metadata:K4,__awaiter:G4,__generator:Z4,__createBinding:Y4,__exportStar:J4,__values:Yu,__read:bp,__spread:X4,__spreadArrays:Q4,__await:jo,__asyncGenerator:e_,__asyncDelegator:t_,__asyncValues:r_,__makeTemplateObject:n_,__importStar:i_,__importDefault:s_,__classPrivateFieldGet:o_,__classPrivateFieldSet:a_}),l_=Li(c_),zn={},_p;function u_(){if(_p)return zn;_p=1,Object.defineProperty(zn,"__esModule",{value:!0}),zn.isBrowserCryptoAvailable=zn.getSubtleCrypto=zn.getBrowerCrypto=void 0;function t(){return fr?.crypto||fr?.msCrypto||{}}zn.getBrowerCrypto=t;function e(){const n=t();return n.subtle||n.webkitSubtle}zn.getSubtleCrypto=e;function r(){return!!t()&&!!e()}return zn.isBrowserCryptoAvailable=r,zn}var Wn={},Ep;function h_(){if(Ep)return Wn;Ep=1,Object.defineProperty(Wn,"__esModule",{value:!0}),Wn.isBrowser=Wn.isNode=Wn.isReactNative=void 0;function t(){return typeof document>"u"&&typeof navigator<"u"&&navigator.product==="ReactNative"}Wn.isReactNative=t;function e(){return typeof process<"u"&&typeof process.versions<"u"&&typeof process.versions.node<"u"}Wn.isNode=e;function r(){return!t()&&!e()}return Wn.isBrowser=r,Wn}(function(t){Object.defineProperty(t,"__esModule",{value:!0});const e=l_;e.__exportStar(u_(),t),e.__exportStar(h_(),t)})(yp);function xp(t=3){const e=Date.now()*Math.pow(10,t),r=Math.floor(Math.random()*Math.pow(10,t));return e+r}function f_(t=6){return BigInt(xp(t))}function ec(t,e,r){return{id:r||xp(),jsonrpc:"2.0",method:t,params:e}}function Ju(t,e){return{id:t,jsonrpc:"2.0",result:e}}function tc(t,e,r){return{id:t,jsonrpc:"2.0",error:d_(e,r)}}function d_(t,e){return typeof t>"u"?wp(gp):(typeof t=="string"&&(t=Object.assign(Object.assign({},wp(Ku)),{message:t})),typeof e<"u"&&(t.data=e),k4(t.code)&&(t=H4(t.code)),t)}class p_{}class g_ extends p_{constructor(){super()}}class m_ extends g_{constructor(e){super()}}const w_="^https?:",v_="^wss?:";function y_(t){const e=t.match(new RegExp(/^\w+:/,"gi"));if(!(!e||!e.length))return e[0]}function Cp(t,e){const r=y_(t);return typeof r>"u"?!1:new RegExp(e).test(r)}function Ip(t){return Cp(t,w_)}function Sp(t){return Cp(t,v_)}function b_(t){return new RegExp("wss?://localhost(:d{2,5})?").test(t)}function Op(t){return typeof t=="object"&&"id"in t&&"jsonrpc"in t&&t.jsonrpc==="2.0"}function Xu(t){return Op(t)&&"method"in t}function Qu(t){return Op(t)&&(qn(t)||_n(t))}function qn(t){return"result"in t}function _n(t){return"error"in t}class ui extends m_{constructor(e){super(e),this.events=new yr.exports.EventEmitter,this.hasRegisteredEventListeners=!1,this.connection=this.setConnection(e),this.connection.connected&&this.registerEventListeners()}async connect(e=this.connection){await this.open(e)}async disconnect(){await this.close()}on(e,r){this.events.on(e,r)}once(e,r){this.events.once(e,r)}off(e,r){this.events.off(e,r)}removeListener(e,r){this.events.removeListener(e,r)}async request(e,r){return this.requestStrict(ec(e.method,e.params||[],f_().toString()),r)}async requestStrict(e,r){return new Promise(async(n,i)=>{if(!this.connection.connected)try{await this.open()}catch(o){i(o)}this.events.on(`${e.id}`,o=>{_n(o)?i(o.error):n(o.result)});try{await this.connection.send(e,r)}catch(o){i(o)}})}setConnection(e=this.connection){return e}onPayload(e){this.events.emit("payload",e),Qu(e)?this.events.emit(`${e.id}`,e):this.events.emit("message",{type:e.method,data:e.params})}onClose(e){e&&e.code===3e3&&this.events.emit("error",new Error(`WebSocket connection closed abnormally with code: ${e.code} ${e.reason?`(${e.reason})`:""}`)),this.events.emit("disconnect")}async open(e=this.connection){this.connection===e&&this.connection.connected||(this.connection.connected&&this.close(),typeof e=="string"&&(await this.connection.open(e),e=this.connection),this.connection=this.setConnection(e),await this.connection.open(),this.registerEventListeners(),this.events.emit("connect"))}async close(){await this.connection.close()}registerEventListeners(){this.hasRegisteredEventListeners||(this.connection.on("payload",e=>this.onPayload(e)),this.connection.on("close",e=>this.onClose(e)),this.connection.on("error",e=>this.events.emit("error",e)),this.connection.on("register_error",e=>this.onClose()),this.hasRegisteredEventListeners=!0)}}const Ap=10,__=()=>typeof global<"u"&&typeof global.WebSocket<"u"?global.WebSocket:typeof window<"u"&&typeof window.WebSocket<"u"?window.WebSocket:require("ws"),E_=()=>typeof window<"u",x_=__();class C_{constructor(e){if(this.url=e,this.events=new yr.exports.EventEmitter,this.registering=!1,!Sp(e))throw new Error(`Provided URL is not compatible with WebSocket connection: ${e}`);this.url=e}get connected(){return typeof this.socket<"u"}get connecting(){return this.registering}on(e,r){this.events.on(e,r)}once(e,r){this.events.once(e,r)}off(e,r){this.events.off(e,r)}removeListener(e,r){this.events.removeListener(e,r)}async open(e=this.url){await this.register(e)}async close(){return new Promise((e,r)=>{if(typeof this.socket>"u"){r(new Error("Connection already closed"));return}this.socket.onclose=n=>{this.onClose(n),e()},this.socket.close()})}async send(e,r){typeof this.socket>"u"&&(this.socket=await this.register());try{this.socket.send(Mo(e))}catch(n){this.onError(e.id,n)}}register(e=this.url){if(!Sp(e))throw new Error(`Provided URL is not compatible with WebSocket connection: ${e}`);if(this.registering){const r=this.events.getMaxListeners();return(this.events.listenerCount("register_error")>=r||this.events.listenerCount("open")>=r)&&this.events.setMaxListeners(r+1),new Promise((n,i)=>{this.events.once("register_error",o=>{this.resetMaxListeners(),i(o)}),this.events.once("open",()=>{if(this.resetMaxListeners(),typeof this.socket>"u")return i(new Error("WebSocket connection is missing or invalid"));n(this.socket)})})}return this.url=e,this.registering=!0,new Promise((r,n)=>{const i=yp.isReactNative()?void 0:{rejectUnauthorized:!b_(e)},o=new x_(e,[],i);E_()?o.onerror=c=>{const l=c;n(this.emitError(l.error))}:o.on("error",c=>{n(this.emitError(c))}),o.onopen=()=>{this.onOpen(o),r(o)}})}onOpen(e){e.onmessage=r=>this.onPayload(r),e.onclose=r=>this.onClose(r),this.socket=e,this.registering=!1,this.events.emit("open")}onClose(e){this.socket=void 0,this.registering=!1,this.events.emit("close",e)}onPayload(e){if(typeof e.data>"u")return;const r=typeof e.data=="string"?qu(e.data):e.data;this.events.emit("payload",r)}onError(e,r){const n=this.parseError(r),i=n.message||n.toString(),o=tc(e,i);this.events.emit("payload",o)}parseError(e,r=this.url){return vp(e,r,"WS")}resetMaxListeners(){this.events.getMaxListeners()>Ap&&this.events.setMaxListeners(Ap)}emitError(e){const r=this.parseError(new Error(e?.message||`WebSocket connection failed for URL: ${this.url}`));return this.events.emit("register_error",r),r}}var eh={exports:{}};(function(t,e){var r=200,n="__lodash_hash_undefined__",i=1,o=2,c=9007199254740991,l="[object Arguments]",h="[object Array]",d="[object AsyncFunction]",v="[object Boolean]",E="[object Date]",_="[object Error]",O="[object Function]",P="[object GeneratorFunction]",U="[object Map]",H="[object Number]",G="[object Null]",N="[object Object]",L="[object Promise]",$="[object Proxy]",T="[object RegExp]",I="[object Set]",f="[object String]",x="[object Symbol]",J="[object Undefined]",z="[object WeakMap]",ee="[object ArrayBuffer]",de="[object DataView]",me="[object Float32Array]",S="[object Float64Array]",j="[object Int8Array]",ce="[object Int16Array]",le="[object Int32Array]",re="[object Uint8Array]",ne="[object Uint8ClampedArray]",ae="[object Uint16Array]",ie="[object Uint32Array]",Ae=/[\\^$.*+?()[\]{}|]/g,ge=/^\[object .+?Constructor\]$/,Fe=/^(?:0|[1-9]\d*)$/,ye={};ye[me]=ye[S]=ye[j]=ye[ce]=ye[le]=ye[re]=ye[ne]=ye[ae]=ye[ie]=!0,ye[l]=ye[h]=ye[ee]=ye[v]=ye[de]=ye[E]=ye[_]=ye[O]=ye[U]=ye[H]=ye[N]=ye[T]=ye[I]=ye[f]=ye[z]=!1;var Le=typeof fr=="object"&&fr&&fr.Object===Object&&fr,X=typeof self=="object"&&self&&self.Object===Object&&self,Y=Le||X||Function("return this")(),W=e&&!e.nodeType&&e,w=W&&!0&&t&&!t.nodeType&&t,F=w&&w.exports===W,we=F&&Le.process,ve=function(){try{return we&&we.binding&&we.binding("util")}catch{}}(),Me=ve&&ve.isTypedArray;function nt(R,q){for(var fe=-1,Ce=R==null?0:R.length,It=0,Xe=[];++fe<Ce;){var Tt=R[fe];q(Tt,fe,R)&&(Xe[It++]=Tt)}return Xe}function at(R,q){for(var fe=-1,Ce=q.length,It=R.length;++fe<Ce;)R[It+fe]=q[fe];return R}function Ge(R,q){for(var fe=-1,Ce=R==null?0:R.length;++fe<Ce;)if(q(R[fe],fe,R))return!0;return!1}function Dt(R,q){for(var fe=-1,Ce=Array(R);++fe<R;)Ce[fe]=q(fe);return Ce}function $t(R){return function(q){return R(q)}}function Je(R,q){return R.has(q)}function He(R,q){return R?.[q]}function Be(R){var q=-1,fe=Array(R.size);return R.forEach(function(Ce,It){fe[++q]=[It,Ce]}),fe}function Ke(R,q){return function(fe){return R(q(fe))}}function rt(R){var q=-1,fe=Array(R.size);return R.forEach(function(Ce){fe[++q]=Ce}),fe}var Ue=Array.prototype,Ze=Function.prototype,b=Object.prototype,p=Y["__core-js_shared__"],m=Ze.toString,D=b.hasOwnProperty,B=function(){var R=/[^.]+$/.exec(p&&p.keys&&p.keys.IE_PROTO||"");return R?"Symbol(src)_1."+R:""}(),K=b.toString,Q=RegExp("^"+m.call(D).replace(Ae,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),Ee=F?Y.Buffer:void 0,Te=Y.Symbol,st=Y.Uint8Array,ht=b.propertyIsEnumerable,lt=Ue.splice,Mr=Te?Te.toStringTag:void 0,Yn=Object.getOwnPropertySymbols,Ci=Ee?Ee.isBuffer:void 0,ls=Ke(Object.keys,Object),Ht=Xr(Y,"DataView"),Lt=Xr(Y,"Map"),zt=Xr(Y,"Promise"),Wt=Xr(Y,"Set"),Ft=Xr(Y,"WeakMap"),Mt=Xr(Object,"create"),rr=Xn(Ht),nr=Xn(Lt),qt=Xn(zt),ir=Xn(Wt),Vt=Xn(Ft),Yt=Te?Te.prototype:void 0,Kt=Yt?Yt.valueOf:void 0;function Pt(R){var q=-1,fe=R==null?0:R.length;for(this.clear();++q<fe;){var Ce=R[q];this.set(Ce[0],Ce[1])}}function sr(){this.__data__=Mt?Mt(null):{},this.size=0}function or(R){var q=this.has(R)&&delete this.__data__[R];return this.size-=q?1:0,q}function Uf(R){var q=this.__data__;if(Mt){var fe=q[R];return fe===n?void 0:fe}return D.call(q,R)?q[R]:void 0}function jf(R){var q=this.__data__;return Mt?q[R]!==void 0:D.call(q,R)}function Ff(R,q){var fe=this.__data__;return this.size+=this.has(R)?0:1,fe[R]=Mt&&q===void 0?n:q,this}Pt.prototype.clear=sr,Pt.prototype.delete=or,Pt.prototype.get=Uf,Pt.prototype.has=jf,Pt.prototype.set=Ff;function hn(R){var q=-1,fe=R==null?0:R.length;for(this.clear();++q<fe;){var Ce=R[q];this.set(Ce[0],Ce[1])}}function Bf(){this.__data__=[],this.size=0}function kf(R){var q=this.__data__,fe=us(q,R);if(fe<0)return!1;var Ce=q.length-1;return fe==Ce?q.pop():lt.call(q,fe,1),--this.size,!0}function Hf(R){var q=this.__data__,fe=us(q,R);return fe<0?void 0:q[fe][1]}function zf(R){return us(this.__data__,R)>-1}function Wf(R,q){var fe=this.__data__,Ce=us(fe,R);return Ce<0?(++this.size,fe.push([R,q])):fe[Ce][1]=q,this}hn.prototype.clear=Bf,hn.prototype.delete=kf,hn.prototype.get=Hf,hn.prototype.has=zf,hn.prototype.set=Wf;function Jn(R){var q=-1,fe=R==null?0:R.length;for(this.clear();++q<fe;){var Ce=R[q];this.set(Ce[0],Ce[1])}}function Xs(){this.size=0,this.__data__={hash:new Pt,map:new(Lt||hn),string:new Pt}}function qf(R){var q=Ii(this,R).delete(R);return this.size-=q?1:0,q}function Qs(R){return Ii(this,R).get(R)}function Vf(R){return Ii(this,R).has(R)}function Kf(R,q){var fe=Ii(this,R),Ce=fe.size;return fe.set(R,q),this.size+=fe.size==Ce?0:1,this}Jn.prototype.clear=Xs,Jn.prototype.delete=qf,Jn.prototype.get=Qs,Jn.prototype.has=Vf,Jn.prototype.set=Kf;function eo(R){var q=-1,fe=R==null?0:R.length;for(this.__data__=new Jn;++q<fe;)this.add(R[q])}function Kc(R){return this.__data__.set(R,n),this}function Gc(R){return this.__data__.has(R)}eo.prototype.add=eo.prototype.push=Kc,eo.prototype.has=Gc;function En(R){var q=this.__data__=new hn(R);this.size=q.size}function Gf(){this.__data__=new hn,this.size=0}function Zf(R){var q=this.__data__,fe=q.delete(R);return this.size=q.size,fe}function Yf(R){return this.__data__.get(R)}function Jf(R){return this.__data__.has(R)}function Zc(R,q){var fe=this.__data__;if(fe instanceof hn){var Ce=fe.__data__;if(!Lt||Ce.length<r-1)return Ce.push([R,q]),this.size=++fe.size,this;fe=this.__data__=new Jn(Ce)}return fe.set(R,q),this.size=fe.size,this}En.prototype.clear=Gf,En.prototype.delete=Zf,En.prototype.get=Yf,En.prototype.has=Jf,En.prototype.set=Zc;function Yc(R,q){var fe=no(R),Ce=!fe&&cl(R),It=!fe&&!Ce&&va(R),Xe=!fe&&!Ce&&!It&&hl(R),Tt=fe||Ce||It||Xe,ar=Tt?Dt(R.length,String):[],mt=ar.length;for(var St in R)(q||D.call(R,St))&&!(Tt&&(St=="length"||It&&(St=="offset"||St=="parent")||Xe&&(St=="buffer"||St=="byteLength"||St=="byteOffset")||nl(St,mt)))&&ar.push(St);return ar}function us(R,q){for(var fe=R.length;fe--;)if(al(R[fe][0],q))return fe;return-1}function ma(R,q,fe){var Ce=q(R);return no(R)?Ce:at(Ce,fe(R))}function hs(R){return R==null?R===void 0?J:G:Mr&&Mr in Object(R)?tl(R):e0(R)}function wa(R){return ds(R)&&hs(R)==l}function fs(R,q,fe,Ce,It){return R===q?!0:R==null||q==null||!ds(R)&&!ds(q)?R!==R&&q!==q:Jc(R,q,fe,Ce,fs,It)}function Jc(R,q,fe,Ce,It,Xe){var Tt=no(R),ar=no(q),mt=Tt?h:Un(R),St=ar?h:Un(q);mt=mt==l?N:mt,St=St==l?N:St;var Jt=mt==N,Wr=St==N,cr=mt==St;if(cr&&va(R)){if(!va(q))return!1;Tt=!0,Jt=!1}if(cr&&!Jt)return Xe||(Xe=new En),Tt||hl(R)?to(R,q,fe,Ce,It,Xe):Qf(R,q,mt,fe,Ce,It,Xe);if(!(fe&i)){var Rt=Jt&&D.call(R,"__wrapped__"),Ur=Wr&&D.call(q,"__wrapped__");if(Rt||Ur){var xn=Rt?R.value():R,fn=Ur?q.value():q;return Xe||(Xe=new En),It(xn,fn,fe,Ce,Xe)}}return cr?(Xe||(Xe=new En),el(R,q,fe,Ce,It,Xe)):!1}function Xf(R){if(!ul(R)||sl(R))return!1;var q=io(R)?Q:ge;return q.test(Xn(R))}function Xc(R){return ds(R)&&ll(R.length)&&!!ye[hs(R)]}function Qc(R){if(!ol(R))return ls(R);var q=[];for(var fe in Object(R))D.call(R,fe)&&fe!="constructor"&&q.push(fe);return q}function to(R,q,fe,Ce,It,Xe){var Tt=fe&i,ar=R.length,mt=q.length;if(ar!=mt&&!(Tt&&mt>ar))return!1;var St=Xe.get(R);if(St&&Xe.get(q))return St==q;var Jt=-1,Wr=!0,cr=fe&o?new eo:void 0;for(Xe.set(R,q),Xe.set(q,R);++Jt<ar;){var Rt=R[Jt],Ur=q[Jt];if(Ce)var xn=Tt?Ce(Ur,Rt,Jt,q,R,Xe):Ce(Rt,Ur,Jt,R,q,Xe);if(xn!==void 0){if(xn)continue;Wr=!1;break}if(cr){if(!Ge(q,function(fn,jn){if(!Je(cr,jn)&&(Rt===fn||It(Rt,fn,fe,Ce,Xe)))return cr.push(jn)})){Wr=!1;break}}else if(!(Rt===Ur||It(Rt,Ur,fe,Ce,Xe))){Wr=!1;break}}return Xe.delete(R),Xe.delete(q),Wr}function Qf(R,q,fe,Ce,It,Xe,Tt){switch(fe){case de:if(R.byteLength!=q.byteLength||R.byteOffset!=q.byteOffset)return!1;R=R.buffer,q=q.buffer;case ee:return!(R.byteLength!=q.byteLength||!Xe(new st(R),new st(q)));case v:case E:case H:return al(+R,+q);case _:return R.name==q.name&&R.message==q.message;case T:case f:return R==q+"";case U:var ar=Be;case I:var mt=Ce&i;if(ar||(ar=rt),R.size!=q.size&&!mt)return!1;var St=Tt.get(R);if(St)return St==q;Ce|=o,Tt.set(R,q);var Jt=to(ar(R),ar(q),Ce,It,Xe,Tt);return Tt.delete(R),Jt;case x:if(Kt)return Kt.call(R)==Kt.call(q)}return!1}function el(R,q,fe,Ce,It,Xe){var Tt=fe&i,ar=ro(R),mt=ar.length,St=ro(q),Jt=St.length;if(mt!=Jt&&!Tt)return!1;for(var Wr=mt;Wr--;){var cr=ar[Wr];if(!(Tt?cr in q:D.call(q,cr)))return!1}var Rt=Xe.get(R);if(Rt&&Xe.get(q))return Rt==q;var Ur=!0;Xe.set(R,q),Xe.set(q,R);for(var xn=Tt;++Wr<mt;){cr=ar[Wr];var fn=R[cr],jn=q[cr];if(Ce)var ya=Tt?Ce(jn,fn,cr,q,R,Xe):Ce(fn,jn,cr,R,q,Xe);if(!(ya===void 0?fn===jn||It(fn,jn,fe,Ce,Xe):ya)){Ur=!1;break}xn||(xn=cr=="constructor")}if(Ur&&!xn){var ps=R.constructor,wr=q.constructor;ps!=wr&&"constructor"in R&&"constructor"in q&&!(typeof ps=="function"&&ps instanceof ps&&typeof wr=="function"&&wr instanceof wr)&&(Ur=!1)}return Xe.delete(R),Xe.delete(q),Ur}function ro(R){return ma(R,n0,rl)}function Ii(R,q){var fe=R.__data__;return il(q)?fe[typeof q=="string"?"string":"hash"]:fe.map}function Xr(R,q){var fe=He(R,q);return Xf(fe)?fe:void 0}function tl(R){var q=D.call(R,Mr),fe=R[Mr];try{R[Mr]=void 0;var Ce=!0}catch{}var It=K.call(R);return Ce&&(q?R[Mr]=fe:delete R[Mr]),It}var rl=Yn?function(R){return R==null?[]:(R=Object(R),nt(Yn(R),function(q){return ht.call(R,q)}))}:Ct,Un=hs;(Ht&&Un(new Ht(new ArrayBuffer(1)))!=de||Lt&&Un(new Lt)!=U||zt&&Un(zt.resolve())!=L||Wt&&Un(new Wt)!=I||Ft&&Un(new Ft)!=z)&&(Un=function(R){var q=hs(R),fe=q==N?R.constructor:void 0,Ce=fe?Xn(fe):"";if(Ce)switch(Ce){case rr:return de;case nr:return U;case qt:return L;case ir:return I;case Vt:return z}return q});function nl(R,q){return q=q??c,!!q&&(typeof R=="number"||Fe.test(R))&&R>-1&&R%1==0&&R<q}function il(R){var q=typeof R;return q=="string"||q=="number"||q=="symbol"||q=="boolean"?R!=="__proto__":R===null}function sl(R){return!!B&&B in R}function ol(R){var q=R&&R.constructor,fe=typeof q=="function"&&q.prototype||b;return R===fe}function e0(R){return K.call(R)}function Xn(R){if(R!=null){try{return m.call(R)}catch{}try{return R+""}catch{}}return""}function al(R,q){return R===q||R!==R&&q!==q}var cl=wa(function(){return arguments}())?wa:function(R){return ds(R)&&D.call(R,"callee")&&!ht.call(R,"callee")},no=Array.isArray;function t0(R){return R!=null&&ll(R.length)&&!io(R)}var va=Ci||xt;function r0(R,q){return fs(R,q)}function io(R){if(!ul(R))return!1;var q=hs(R);return q==O||q==P||q==d||q==$}function ll(R){return typeof R=="number"&&R>-1&&R%1==0&&R<=c}function ul(R){var q=typeof R;return R!=null&&(q=="object"||q=="function")}function ds(R){return R!=null&&typeof R=="object"}var hl=Me?$t(Me):Xc;function n0(R){return t0(R)?Yc(R):Qc(R)}function Ct(){return[]}function xt(){return!1}t.exports=r0})(eh,eh.exports);var I_=eh.exports,S_=Object.defineProperty,Dp=Object.getOwnPropertySymbols,O_=Object.prototype.hasOwnProperty,A_=Object.prototype.propertyIsEnumerable,$p=(t,e,r)=>e in t?S_(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Tr=(t,e)=>{for(var r in e||(e={}))O_.call(e,r)&&$p(t,r,e[r]);if(Dp)for(var r of Dp(e))A_.call(e,r)&&$p(t,r,e[r]);return t};function D_(t,e){if(t.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var i=0;i<t.length;i++){var o=t.charAt(i),c=o.charCodeAt(0);if(r[c]!==255)throw new TypeError(o+" is ambiguous");r[c]=i}var l=t.length,h=t.charAt(0),d=Math.log(l)/Math.log(256),v=Math.log(256)/Math.log(l);function E(P){if(P instanceof Uint8Array||(ArrayBuffer.isView(P)?P=new Uint8Array(P.buffer,P.byteOffset,P.byteLength):Array.isArray(P)&&(P=Uint8Array.from(P))),!(P instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(P.length===0)return"";for(var U=0,H=0,G=0,N=P.length;G!==N&&P[G]===0;)G++,U++;for(var L=(N-G)*v+1>>>0,$=new Uint8Array(L);G!==N;){for(var T=P[G],I=0,f=L-1;(T!==0||I<H)&&f!==-1;f--,I++)T+=256*$[f]>>>0,$[f]=T%l>>>0,T=T/l>>>0;if(T!==0)throw new Error("Non-zero carry");H=I,G++}for(var x=L-H;x!==L&&$[x]===0;)x++;for(var J=h.repeat(U);x<L;++x)J+=t.charAt($[x]);return J}function _(P){if(typeof P!="string")throw new TypeError("Expected String");if(P.length===0)return new Uint8Array;var U=0;if(P[U]!==" "){for(var H=0,G=0;P[U]===h;)H++,U++;for(var N=(P.length-U)*d+1>>>0,L=new Uint8Array(N);P[U];){var $=r[P.charCodeAt(U)];if($===255)return;for(var T=0,I=N-1;($!==0||T<G)&&I!==-1;I--,T++)$+=l*L[I]>>>0,L[I]=$%256>>>0,$=$/256>>>0;if($!==0)throw new Error("Non-zero carry");G=T,U++}if(P[U]!==" "){for(var f=N-G;f!==N&&L[f]===0;)f++;for(var x=new Uint8Array(H+(N-f)),J=H;f!==N;)x[J++]=L[f++];return x}}}function O(P){var U=_(P);if(U)return U;throw new Error(`Non-${e} character`)}return{encode:E,decodeUnsafe:_,decode:O}}var $_=D_,P_=$_;const Pp=t=>{if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return t;if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);throw new Error("Unknown type, must be binary type")},T_=t=>new TextEncoder().encode(t),R_=t=>new TextDecoder().decode(t);class N_{constructor(e,r,n){this.name=e,this.prefix=r,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}}class L_{constructor(e,r,n){if(this.name=e,this.prefix=r,r.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=r.codePointAt(0),this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return Tp(this,e)}}class M_{constructor(e){this.decoders=e}or(e){return Tp(this,e)}decode(e){const r=e[0],n=this.decoders[r];if(n)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}}const Tp=(t,e)=>new M_(Tr(Tr({},t.decoders||{[t.prefix]:t}),e.decoders||{[e.prefix]:e}));class U_{constructor(e,r,n,i){this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=i,this.encoder=new N_(e,r,n),this.decoder=new L_(e,r,i)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}}const rc=({name:t,prefix:e,encode:r,decode:n})=>new U_(t,e,r,n),Fo=({prefix:t,name:e,alphabet:r})=>{const{encode:n,decode:i}=P_(r,e);return rc({prefix:t,name:e,encode:n,decode:o=>Pp(i(o))})},j_=(t,e,r,n)=>{const i={};for(let v=0;v<e.length;++v)i[e[v]]=v;let o=t.length;for(;t[o-1]==="=";)--o;const c=new Uint8Array(o*r/8|0);let l=0,h=0,d=0;for(let v=0;v<o;++v){const E=i[t[v]];if(E===void 0)throw new SyntaxError(`Non-${n} character`);h=h<<r|E,l+=r,l>=8&&(l-=8,c[d++]=255&h>>l)}if(l>=r||255&h<<8-l)throw new SyntaxError("Unexpected end of data");return c},F_=(t,e,r)=>{const n=e[e.length-1]==="=",i=(1<<r)-1;let o="",c=0,l=0;for(let h=0;h<t.length;++h)for(l=l<<8|t[h],c+=8;c>r;)c-=r,o+=e[i&l>>c];if(c&&(o+=e[i&l<<r-c]),n)for(;o.length*r&7;)o+="=";return o},_r=({name:t,prefix:e,bitsPerChar:r,alphabet:n})=>rc({prefix:e,name:t,encode(i){return F_(i,n,r)},decode(i){return j_(i,n,r,t)}}),B_=rc({prefix:"\0",name:"identity",encode:t=>R_(t),decode:t=>T_(t)});var k_=Object.freeze({__proto__:null,identity:B_});const H_=_r({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var z_=Object.freeze({__proto__:null,base2:H_});const W_=_r({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var q_=Object.freeze({__proto__:null,base8:W_});const V_=Fo({prefix:"9",name:"base10",alphabet:"0123456789"});var K_=Object.freeze({__proto__:null,base10:V_});const G_=_r({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Z_=_r({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Y_=Object.freeze({__proto__:null,base16:G_,base16upper:Z_});const J_=_r({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),X_=_r({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Q_=_r({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),e8=_r({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),t8=_r({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),r8=_r({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),n8=_r({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),i8=_r({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),s8=_r({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var o8=Object.freeze({__proto__:null,base32:J_,base32upper:X_,base32pad:Q_,base32padupper:e8,base32hex:t8,base32hexupper:r8,base32hexpad:n8,base32hexpadupper:i8,base32z:s8});const a8=Fo({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),c8=Fo({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var l8=Object.freeze({__proto__:null,base36:a8,base36upper:c8});const u8=Fo({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),h8=Fo({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var f8=Object.freeze({__proto__:null,base58btc:u8,base58flickr:h8});const d8=_r({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),p8=_r({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),g8=_r({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),m8=_r({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var w8=Object.freeze({__proto__:null,base64:d8,base64pad:p8,base64url:g8,base64urlpad:m8});const Rp=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),v8=Rp.reduce((t,e,r)=>(t[r]=e,t),[]),y8=Rp.reduce((t,e,r)=>(t[e.codePointAt(0)]=r,t),[]);function b8(t){return t.reduce((e,r)=>(e+=v8[r],e),"")}function _8(t){const e=[];for(const r of t){const n=y8[r.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${r}`);e.push(n)}return new Uint8Array(e)}const E8=rc({prefix:"\u{1F680}",name:"base256emoji",encode:b8,decode:_8});var x8=Object.freeze({__proto__:null,base256emoji:E8}),C8=Lp,Np=128,I8=127,S8=~I8,O8=Math.pow(2,31);function Lp(t,e,r){e=e||[],r=r||0;for(var n=r;t>=O8;)e[r++]=t&255|Np,t/=128;for(;t&S8;)e[r++]=t&255|Np,t>>>=7;return e[r]=t|0,Lp.bytes=r-n+1,e}var A8=th,D8=128,Mp=127;function th(t,n){var r=0,n=n||0,i=0,o=n,c,l=t.length;do{if(o>=l)throw th.bytes=0,new RangeError("Could not decode varint");c=t[o++],r+=i<28?(c&Mp)<<i:(c&Mp)*Math.pow(2,i),i+=7}while(c>=D8);return th.bytes=o-n,r}var $8=Math.pow(2,7),P8=Math.pow(2,14),T8=Math.pow(2,21),R8=Math.pow(2,28),N8=Math.pow(2,35),L8=Math.pow(2,42),M8=Math.pow(2,49),U8=Math.pow(2,56),j8=Math.pow(2,63),F8=function(t){return t<$8?1:t<P8?2:t<T8?3:t<R8?4:t<N8?5:t<L8?6:t<M8?7:t<U8?8:t<j8?9:10},B8={encode:C8,decode:A8,encodingLength:F8},Up=B8;const jp=(t,e,r=0)=>(Up.encode(t,e,r),e),Fp=t=>Up.encodingLength(t),rh=(t,e)=>{const r=e.byteLength,n=Fp(t),i=n+Fp(r),o=new Uint8Array(i+r);return jp(t,o,0),jp(r,o,n),o.set(e,i),new k8(t,r,e,o)};class k8{constructor(e,r,n,i){this.code=e,this.size=r,this.digest=n,this.bytes=i}}const Bp=({name:t,code:e,encode:r})=>new H8(t,e,r);class H8{constructor(e,r,n){this.name=e,this.code=r,this.encode=n}digest(e){if(e instanceof Uint8Array){const r=this.encode(e);return r instanceof Uint8Array?rh(this.code,r):r.then(n=>rh(this.code,n))}else throw Error("Unknown type, must be binary type")}}const kp=t=>async e=>new Uint8Array(await crypto.subtle.digest(t,e)),z8=Bp({name:"sha2-256",code:18,encode:kp("SHA-256")}),W8=Bp({name:"sha2-512",code:19,encode:kp("SHA-512")});var q8=Object.freeze({__proto__:null,sha256:z8,sha512:W8});const Hp=0,V8="identity",zp=Pp;var K8=Object.freeze({__proto__:null,identity:{code:Hp,name:V8,encode:zp,digest:t=>rh(Hp,zp(t))}});new TextEncoder,new TextDecoder;const Wp=Tr(Tr(Tr(Tr(Tr(Tr(Tr(Tr(Tr(Tr({},k_),z_),q_),K_),Y_),o8),l8),f8),w8),x8);Tr(Tr({},q8),K8);function qp(t){return globalThis.Buffer!=null?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):t}function G8(t=0){return globalThis.Buffer!=null&&globalThis.Buffer.allocUnsafe!=null?qp(globalThis.Buffer.allocUnsafe(t)):new Uint8Array(t)}function Vp(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}const Kp=Vp("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),nh=Vp("ascii","a",t=>{let e="a";for(let r=0;r<t.length;r++)e+=String.fromCharCode(t[r]);return e},t=>{t=t.substring(1);const e=G8(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),Z8=Tr({utf8:Kp,"utf-8":Kp,hex:Wp.base16,latin1:nh,ascii:nh,binary:nh},Wp);function Y8(t,e="utf8"){const r=Z8[e];if(!r)throw new Error(`Unsupported encoding "${e}"`);return(e==="utf8"||e==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?qp(globalThis.Buffer.from(t,"utf-8")):r.decoder.decode(`${r.prefix}${t}`)}const Gp="wc",J8=2,ih="core",hi=`${Gp}@${2}:${ih}:`,X8={name:ih,logger:"error"},Q8={database:":memory:"},eE="crypto",Zp="client_ed25519_seed",tE=ke.ONE_DAY,rE="keychain",nE="0.3",iE="messages",sE="0.3",oE=ke.SIX_HOURS,aE="publisher",Yp="irn",cE="error",Jp="wss://relay.walletconnect.com",lE="relayer",pr={message:"relayer_message",connect:"relayer_connect",disconnect:"relayer_disconnect",error:"relayer_error",connection_stalled:"relayer_connection_stalled",transport_closed:"relayer_transport_closed",publish:"relayer_publish"},uE="_subscription",Bo={payload:"payload",connect:"connect",disconnect:"disconnect",error:"error"},hE=ke.ONE_SECOND/2,fE="2.7.5",dE="0.3",$n={created:"subscription_created",deleted:"subscription_deleted",expired:"subscription_expired",disabled:"subscription_disabled",sync:"subscription_sync",resubscribed:"subscription_resubscribed"},pE="subscription",gE="0.3",mE=ke.FIVE_SECONDS*1e3,wE="pairing",vE="0.3",ko={wc_pairingDelete:{req:{ttl:ke.ONE_DAY,prompt:!1,tag:1e3},res:{ttl:ke.ONE_DAY,prompt:!1,tag:1001}},wc_pairingPing:{req:{ttl:ke.THIRTY_SECONDS,prompt:!1,tag:1002},res:{ttl:ke.THIRTY_SECONDS,prompt:!1,tag:1003}},unregistered_method:{req:{ttl:ke.ONE_DAY,prompt:!1,tag:0},res:{ttl:ke.ONE_DAY,prompt:!1,tag:0}}},Pn={created:"history_created",updated:"history_updated",deleted:"history_deleted",sync:"history_sync"},yE="history",bE="0.3",_E="expirer",sn={created:"expirer_created",deleted:"expirer_deleted",expired:"expirer_expired",sync:"expirer_sync"},EE="0.3",sh="verify-api",Xp="https://verify.walletconnect.com";class xE{constructor(e,r){this.core=e,this.logger=r,this.keychain=new Map,this.name=rE,this.version=nE,this.initialized=!1,this.storagePrefix=hi,this.init=async()=>{if(!this.initialized){const n=await this.getKeyChain();typeof n<"u"&&(this.keychain=n),this.initialized=!0}},this.has=n=>(this.isInitialized(),this.keychain.has(n)),this.set=async(n,i)=>{this.isInitialized(),this.keychain.set(n,i),await this.persist()},this.get=n=>{this.isInitialized();const i=this.keychain.get(n);if(typeof i>"u"){const{message:o}=_e("NO_MATCHING_KEY",`${this.name}: ${n}`);throw new Error(o)}return i},this.del=async n=>{this.isInitialized(),this.keychain.delete(n),await this.persist()},this.core=e,this.logger=pt.generateChildLogger(r,this.name)}get context(){return pt.getLoggerContext(this.logger)}get storageKey(){return this.storagePrefix+this.version+"//"+this.name}async setKeyChain(e){await this.core.storage.setItem(this.storageKey,A1(e))}async getKeyChain(){const e=await this.core.storage.getItem(this.storageKey);return typeof e<"u"?D1(e):void 0}async persist(){await this.setKeyChain(this.keychain)}isInitialized(){if(!this.initialized){const{message:e}=_e("NOT_INITIALIZED",this.name);throw new Error(e)}}}class CE{constructor(e,r,n){this.core=e,this.logger=r,this.name=eE,this.initialized=!1,this.init=async()=>{this.initialized||(await this.keychain.init(),this.initialized=!0)},this.hasKeys=i=>(this.isInitialized(),this.keychain.has(i)),this.getClientId=async()=>{this.isInitialized();const i=await this.getClientSeed(),o=pp(i);return dp(o.publicKey)},this.generateKeyPair=()=>{this.isInitialized();const i=N5();return this.setPrivateKey(i.publicKey,i.privateKey)},this.signJWT=async i=>{this.isInitialized();const o=await this.getClientSeed(),c=pp(o),l=Cu();return await L4(l,i,tE,c)},this.generateSharedKey=(i,o,c)=>{this.isInitialized();const l=this.getPrivateKey(i),h=L5(l,o);return this.setSymKey(h,c)},this.setSymKey=async(i,o)=>{this.isInitialized();const c=o||M5(i);return await this.keychain.set(c,i),c},this.deleteKeyPair=async i=>{this.isInitialized(),await this.keychain.del(i)},this.deleteSymKey=async i=>{this.isInitialized(),await this.keychain.del(i)},this.encode=async(i,o,c)=>{this.isInitialized();const l=_1(c),h=Mo(o);if(E1(l)){const _=l.senderPublicKey,O=l.receiverPublicKey;i=await this.generateSharedKey(_,O)}const d=this.getSymKey(i),{type:v,senderPublicKey:E}=l;return j5({type:v,symKey:d,message:h,senderPublicKey:E})},this.decode=async(i,o,c)=>{this.isInitialized();const l=k5(o,c);if(E1(l)){const v=l.receiverPublicKey,E=l.senderPublicKey;i=await this.generateSharedKey(v,E)}const h=this.getSymKey(i),d=F5({symKey:h,encoded:o});return qu(d)},this.getPayloadType=i=>{const o=Va(i);return Io(o.type)},this.getPayloadSenderPublicKey=i=>{const o=Va(i);return o.senderPublicKey?Ar(o.senderPublicKey,Dr):void 0},this.core=e,this.logger=pt.generateChildLogger(r,this.name),this.keychain=n||new xE(this.core,this.logger)}get context(){return pt.getLoggerContext(this.logger)}async setPrivateKey(e,r){return await this.keychain.set(e,r),e}getPrivateKey(e){return this.keychain.get(e)}async getClientSeed(){let e="";try{e=this.keychain.get(Zp)}catch{e=Cu(),await this.keychain.set(Zp,e)}return Y8(e,"base16")}getSymKey(e){return this.keychain.get(e)}isInitialized(){if(!this.initialized){const{message:e}=_e("NOT_INITIALIZED",this.name);throw new Error(e)}}}class IE extends h4{constructor(e,r){super(e,r),this.logger=e,this.core=r,this.messages=new Map,this.name=iE,this.version=sE,this.initialized=!1,this.storagePrefix=hi,this.init=async()=>{if(!this.initialized){this.logger.trace("Initialized");try{const n=await this.getRelayerMessages();typeof n<"u"&&(this.messages=n),this.logger.debug(`Successfully Restored records for ${this.name}`),this.logger.trace({type:"method",method:"restore",size:this.messages.size})}catch(n){this.logger.debug(`Failed to Restore records for ${this.name}`),this.logger.error(n)}finally{this.initialized=!0}}},this.set=async(n,i)=>{this.isInitialized();const o=Bi(i);let c=this.messages.get(n);return typeof c>"u"&&(c={}),typeof c[o]<"u"||(c[o]=i,this.messages.set(n,c),await this.persist()),o},this.get=n=>{this.isInitialized();let i=this.messages.get(n);return typeof i>"u"&&(i={}),i},this.has=(n,i)=>{this.isInitialized();const o=this.get(n),c=Bi(i);return typeof o[c]<"u"},this.del=async n=>{this.isInitialized(),this.messages.delete(n),await this.persist()},this.logger=pt.generateChildLogger(e,this.name),this.core=r}get context(){return pt.getLoggerContext(this.logger)}get storageKey(){return this.storagePrefix+this.version+"//"+this.name}async setRelayerMessages(e){await this.core.storage.setItem(this.storageKey,A1(e))}async getRelayerMessages(){const e=await this.core.storage.getItem(this.storageKey);return typeof e<"u"?D1(e):void 0}async persist(){await this.setRelayerMessages(this.messages)}isInitialized(){if(!this.initialized){const{message:e}=_e("NOT_INITIALIZED",this.name);throw new Error(e)}}}class SE extends f4{constructor(e,r){super(e,r),this.relayer=e,this.logger=r,this.events=new yr.exports.EventEmitter,this.name=aE,this.queue=new Map,this.publishTimeout=1e4,this.publish=async(n,i,o)=>{this.logger.debug("Publishing Payload"),this.logger.trace({type:"method",method:"publish",params:{topic:n,message:i,opts:o}});try{const c=o?.ttl||oE,l=Au(o),h=o?.prompt||!1,d=o?.tag||0,v={topic:n,message:i,opts:{ttl:c,relay:l,prompt:h,tag:d}},E=Bi(i);this.queue.set(E,v);try{await await Ka(this.rpcPublish(n,i,c,l,h,d),this.publishTimeout),this.relayer.events.emit(pr.publish,v)}catch{this.logger.debug("Publishing Payload stalled"),this.relayer.events.emit(pr.connection_stalled);return}this.onPublish(E,v),this.logger.debug("Successfully Published Payload"),this.logger.trace({type:"method",method:"publish",params:{topic:n,message:i,opts:o}})}catch(c){throw this.logger.debug("Failed to Publish Payload"),this.logger.error(c),c}},this.on=(n,i)=>{this.events.on(n,i)},this.once=(n,i)=>{this.events.once(n,i)},this.off=(n,i)=>{this.events.off(n,i)},this.removeListener=(n,i)=>{this.events.removeListener(n,i)},this.relayer=e,this.logger=pt.generateChildLogger(r,this.name),this.registerEventListeners()}get context(){return pt.getLoggerContext(this.logger)}rpcPublish(e,r,n,i,o,c){var l,h,d,v;const E={method:Ga(i.protocol).publish,params:{topic:e,message:r,ttl:n,prompt:o,tag:c}};return $r((l=E.params)==null?void 0:l.prompt)&&((h=E.params)==null||delete h.prompt),$r((d=E.params)==null?void 0:d.tag)&&((v=E.params)==null||delete v.tag),this.logger.debug("Outgoing Relay Payload"),this.logger.trace({type:"message",direction:"outgoing",request:E}),this.relayer.request(E)}onPublish(e,r){this.queue.delete(e)}checkQueue(){this.queue.forEach(async e=>{const{topic:r,message:n,opts:i}=e;await this.publish(r,n,i)})}registerEventListeners(){this.relayer.core.heartbeat.on(Po.HEARTBEAT_EVENTS.pulse,()=>{this.checkQueue()})}}class OE{constructor(){this.map=new Map,this.set=(e,r)=>{const n=this.get(e);this.exists(e,r)||this.map.set(e,[...n,r])},this.get=e=>this.map.get(e)||[],this.exists=(e,r)=>this.get(e).includes(r),this.delete=(e,r)=>{if(typeof r>"u"){this.map.delete(e);return}if(!this.map.has(e))return;const n=this.get(e);if(!this.exists(e,r))return;const i=n.filter(o=>o!==r);if(!i.length){this.map.delete(e);return}this.map.set(e,i)},this.clear=()=>{this.map.clear()}}get topics(){return Array.from(this.map.keys())}}var AE=Object.defineProperty,DE=Object.defineProperties,$E=Object.getOwnPropertyDescriptors,Qp=Object.getOwnPropertySymbols,PE=Object.prototype.hasOwnProperty,TE=Object.prototype.propertyIsEnumerable,eg=(t,e,r)=>e in t?AE(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Ho=(t,e)=>{for(var r in e||(e={}))PE.call(e,r)&&eg(t,r,e[r]);if(Qp)for(var r of Qp(e))TE.call(e,r)&&eg(t,r,e[r]);return t},oh=(t,e)=>DE(t,$E(e));class RE extends g4{constructor(e,r){super(e,r),this.relayer=e,this.logger=r,this.subscriptions=new Map,this.topicMap=new OE,this.events=new yr.exports.EventEmitter,this.name=pE,this.version=gE,this.pending=new Map,this.cached=[],this.initialized=!1,this.pendingSubscriptionWatchLabel="pending_sub_watch_label",this.pollingInterval=20,this.storagePrefix=hi,this.subscribeTimeout=1e4,this.restartInProgress=!1,this.batchSubscribeTopicsLimit=500,this.init=async()=>{this.initialized||(this.logger.trace("Initialized"),await this.restart(),this.registerEventListeners(),this.onEnable(),this.clientId=await this.relayer.core.crypto.getClientId())},this.subscribe=async(n,i)=>{await this.restartToComplete(),this.isInitialized(),this.logger.debug("Subscribing Topic"),this.logger.trace({type:"method",method:"subscribe",params:{topic:n,opts:i}});try{const o=Au(i),c={topic:n,relay:o};this.pending.set(n,c);const l=await this.rpcSubscribe(n,o);return this.onSubscribe(l,c),this.logger.debug("Successfully Subscribed Topic"),this.logger.trace({type:"method",method:"subscribe",params:{topic:n,opts:i}}),l}catch(o){throw this.logger.debug("Failed to Subscribe Topic"),this.logger.error(o),o}},this.unsubscribe=async(n,i)=>{await this.restartToComplete(),this.isInitialized(),typeof i?.id<"u"?await this.unsubscribeById(n,i.id,i):await this.unsubscribeByTopic(n,i)},this.isSubscribed=async n=>this.topics.includes(n)?!0:await new Promise((i,o)=>{const c=new ke.Watch;c.start(this.pendingSubscriptionWatchLabel);const l=setInterval(()=>{!this.pending.has(n)&&this.topics.includes(n)&&(clearInterval(l),c.stop(this.pendingSubscriptionWatchLabel),i(!0)),c.elapsed(this.pendingSubscriptionWatchLabel)>=mE&&(clearInterval(l),c.stop(this.pendingSubscriptionWatchLabel),o(!1))},this.pollingInterval)}),this.on=(n,i)=>{this.events.on(n,i)},this.once=(n,i)=>{this.events.once(n,i)},this.off=(n,i)=>{this.events.off(n,i)},this.removeListener=(n,i)=>{this.events.removeListener(n,i)},this.restart=async()=>{this.restartInProgress=!0,await this.restore(),await this.reset(),this.restartInProgress=!1},this.relayer=e,this.logger=pt.generateChildLogger(r,this.name),this.clientId=""}get context(){return pt.getLoggerContext(this.logger)}get storageKey(){return this.storagePrefix+this.version+"//"+this.name}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}hasSubscription(e,r){let n=!1;try{n=this.getSubscription(e).topic===r}catch{}return n}onEnable(){this.cached=[],this.initialized=!0}onDisable(){this.cached=this.values,this.subscriptions.clear(),this.topicMap.clear()}async unsubscribeByTopic(e,r){const n=this.topicMap.get(e);await Promise.all(n.map(async i=>await this.unsubscribeById(e,i,r)))}async unsubscribeById(e,r,n){this.logger.debug("Unsubscribing Topic"),this.logger.trace({type:"method",method:"unsubscribe",params:{topic:e,id:r,opts:n}});try{const i=Au(n);await this.rpcUnsubscribe(e,r,i);const o=Zt("USER_DISCONNECTED",`${this.name}, ${e}`);await this.onUnsubscribe(e,r,o),this.logger.debug("Successfully Unsubscribed Topic"),this.logger.trace({type:"method",method:"unsubscribe",params:{topic:e,id:r,opts:n}})}catch(i){throw this.logger.debug("Failed to Unsubscribe Topic"),this.logger.error(i),i}}async rpcSubscribe(e,r){const n={method:Ga(r.protocol).subscribe,params:{topic:e}};this.logger.debug("Outgoing Relay Payload"),this.logger.trace({type:"payload",direction:"outgoing",request:n});try{await await Ka(this.relayer.request(n),this.subscribeTimeout)}catch{this.logger.debug("Outgoing Relay Subscribe Payload stalled"),this.relayer.events.emit(pr.connection_stalled)}return Bi(e+this.clientId)}async rpcBatchSubscribe(e){if(!e.length)return;const r=e[0].relay,n={method:Ga(r.protocol).batchSubscribe,params:{topics:e.map(i=>i.topic)}};this.logger.debug("Outgoing Relay Payload"),this.logger.trace({type:"payload",direction:"outgoing",request:n});try{return await await Ka(this.relayer.request(n),this.subscribeTimeout)}catch{this.logger.debug("Outgoing Relay Payload stalled"),this.relayer.events.emit(pr.connection_stalled)}}rpcUnsubscribe(e,r,n){const i={method:Ga(n.protocol).unsubscribe,params:{topic:e,id:r}};return this.logger.debug("Outgoing Relay Payload"),this.logger.trace({type:"payload",direction:"outgoing",request:i}),this.relayer.request(i)}onSubscribe(e,r){this.setSubscription(e,oh(Ho({},r),{id:e})),this.pending.delete(r.topic)}onBatchSubscribe(e){e.length&&e.forEach(r=>{this.setSubscription(r.id,Ho({},r)),this.pending.delete(r.topic)})}async onUnsubscribe(e,r,n){this.events.removeAllListeners(r),this.hasSubscription(r,e)&&this.deleteSubscription(r,n),await this.relayer.messages.del(e)}async setRelayerSubscriptions(e){await this.relayer.core.storage.setItem(this.storageKey,e)}async getRelayerSubscriptions(){return await this.relayer.core.storage.getItem(this.storageKey)}setSubscription(e,r){this.subscriptions.has(e)||(this.logger.debug("Setting subscription"),this.logger.trace({type:"method",method:"setSubscription",id:e,subscription:r}),this.addSubscription(e,r))}addSubscription(e,r){this.subscriptions.set(e,Ho({},r)),this.topicMap.set(r.topic,e),this.events.emit($n.created,r)}getSubscription(e){this.logger.debug("Getting subscription"),this.logger.trace({type:"method",method:"getSubscription",id:e});const r=this.subscriptions.get(e);if(!r){const{message:n}=_e("NO_MATCHING_KEY",`${this.name}: ${e}`);throw new Error(n)}return r}deleteSubscription(e,r){this.logger.debug("Deleting subscription"),this.logger.trace({type:"method",method:"deleteSubscription",id:e,reason:r});const n=this.getSubscription(e);this.subscriptions.delete(e),this.topicMap.delete(n.topic,e),this.events.emit($n.deleted,oh(Ho({},n),{reason:r}))}async persist(){await this.setRelayerSubscriptions(this.values),this.events.emit($n.sync)}async reset(){if(this.cached.length){const e=Math.ceil(this.cached.length/this.batchSubscribeTopicsLimit);for(let r=0;r<e;r++){const n=this.cached.splice(0,this.batchSubscribeTopicsLimit);await this.batchSubscribe(n)}}this.events.emit($n.resubscribed)}async restore(){try{const e=await this.getRelayerSubscriptions();if(typeof e>"u"||!e.length)return;if(this.subscriptions.size){const{message:r}=_e("RESTORE_WILL_OVERRIDE",this.name);throw this.logger.error(r),this.logger.error(`${this.name}: ${JSON.stringify(this.values)}`),new Error(r)}this.cached=e,this.logger.debug(`Successfully Restored subscriptions for ${this.name}`),this.logger.trace({type:"method",method:"restore",subscriptions:this.values})}catch(e){this.logger.debug(`Failed to Restore subscriptions for ${this.name}`),this.logger.error(e)}}async batchSubscribe(e){if(!e.length)return;const r=await this.rpcBatchSubscribe(e);Hn(r)&&this.onBatchSubscribe(r.map((n,i)=>oh(Ho({},e[i]),{id:n})))}async onConnect(){this.restartInProgress||(await this.restart(),this.onEnable())}onDisconnect(){this.onDisable()}async checkPending(){if(this.relayer.transportExplicitlyClosed)return;const e=[];this.pending.forEach(r=>{e.push(r)}),await this.batchSubscribe(e)}registerEventListeners(){this.relayer.core.heartbeat.on(Po.HEARTBEAT_EVENTS.pulse,async()=>{await this.checkPending()}),this.relayer.on(pr.connect,async()=>{await this.onConnect()}),this.relayer.on(pr.disconnect,()=>{this.onDisconnect()}),this.events.on($n.created,async e=>{const r=$n.created;this.logger.info(`Emitting ${r}`),this.logger.debug({type:"event",event:r,data:e}),await this.persist()}),this.events.on($n.deleted,async e=>{const r=$n.deleted;this.logger.info(`Emitting ${r}`),this.logger.debug({type:"event",event:r,data:e}),await this.persist()})}isInitialized(){if(!this.initialized){const{message:e}=_e("NOT_INITIALIZED",this.name);throw new Error(e)}}async restartToComplete(){this.restartInProgress&&await new Promise(e=>{const r=setInterval(()=>{this.restartInProgress||(clearInterval(r),e())},this.pollingInterval)})}}var NE=Object.defineProperty,tg=Object.getOwnPropertySymbols,LE=Object.prototype.hasOwnProperty,ME=Object.prototype.propertyIsEnumerable,rg=(t,e,r)=>e in t?NE(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,UE=(t,e)=>{for(var r in e||(e={}))LE.call(e,r)&&rg(t,r,e[r]);if(tg)for(var r of tg(e))ME.call(e,r)&&rg(t,r,e[r]);return t};class jE extends d4{constructor(e){super(e),this.protocol="wc",this.version=2,this.events=new yr.exports.EventEmitter,this.name=lE,this.transportExplicitlyClosed=!1,this.initialized=!1,this.reconnecting=!1,this.connectionStatusPollingInterval=20,this.staleConnectionErrors=["socket hang up","socket stalled"],this.request=async r=>{this.logger.debug("Publishing Request Payload");try{return await this.toEstablishConnection(),await this.provider.request(r)}catch(n){throw this.logger.debug("Failed to Publish Request"),this.logger.error(n),n}},this.core=e.core,this.logger=typeof e.logger<"u"&&typeof e.logger!="string"?pt.generateChildLogger(e.logger,this.name):pt.pino(pt.getDefaultLoggerOptions({level:e.logger||cE})),this.messages=new IE(this.logger,e.core),this.subscriber=new RE(this,this.logger),this.publisher=new SE(this,this.logger),this.relayUrl=e?.relayUrl||Jp,this.projectId=e.projectId,this.provider={}}async init(){this.logger.trace("Initialized"),await this.createProvider(),await Promise.all([this.messages.init(),this.transportOpen(),this.subscriber.init()]),this.registerEventListeners(),this.initialized=!0}get context(){return pt.getLoggerContext(this.logger)}get connected(){return this.provider.connection.connected}get connecting(){return this.provider.connection.connecting}async publish(e,r,n){this.isInitialized(),await this.publisher.publish(e,r,n),await this.recordMessageEvent({topic:e,message:r,publishedAt:Date.now()})}async subscribe(e,r){this.isInitialized();let n="";return await Promise.all([new Promise(i=>{this.subscriber.once($n.created,o=>{o.topic===e&&i()})}),new Promise(async i=>{n=await this.subscriber.subscribe(e,r),i()})]),n}async unsubscribe(e,r){this.isInitialized(),await this.subscriber.unsubscribe(e,r)}on(e,r){this.events.on(e,r)}once(e,r){this.events.once(e,r)}off(e,r){this.events.off(e,r)}removeListener(e,r){this.events.removeListener(e,r)}async transportClose(){this.transportExplicitlyClosed=!0,this.connected&&(await this.provider.disconnect(),this.events.emit(pr.transport_closed))}async transportOpen(e){if(this.transportExplicitlyClosed=!1,!this.reconnecting){this.relayUrl=e||this.relayUrl,this.reconnecting=!0;try{await Promise.all([new Promise(r=>{this.initialized||r(),this.subscriber.once($n.resubscribed,()=>{r()})}),await Promise.race([new Promise(async(r,n)=>{await Ka(this.provider.connect(),5e3,"socket stalled").catch(i=>n(i)).then(()=>r()).finally(()=>this.removeListener(pr.transport_closed,this.rejectTransportOpen))}),new Promise(r=>this.once(pr.transport_closed,this.rejectTransportOpen))])])}catch(r){this.logger.error(r);const n=r;if(!this.isConnectionStalled(n.message))throw r;this.events.emit(pr.transport_closed)}finally{this.reconnecting=!1}}}async restartTransport(e){this.transportExplicitlyClosed||(this.relayUrl=e||this.relayUrl,this.connected&&await Promise.all([new Promise(r=>{this.provider.once(Bo.disconnect,()=>{r()})}),this.transportClose()]),await this.createProvider(),await this.transportOpen())}isConnectionStalled(e){return this.staleConnectionErrors.some(r=>e.includes(r))}rejectTransportOpen(){throw new Error("closeTransport called before connection was established")}async createProvider(){const e=await this.core.crypto.signJWT(this.relayUrl);this.provider=new ui(new C_(X5({sdkVersion:fE,protocol:this.protocol,version:this.version,relayUrl:this.relayUrl,projectId:this.projectId,auth:e,useOnCloseEvent:!0}))),this.registerProviderListeners()}async recordMessageEvent(e){const{topic:r,message:n}=e;await this.messages.set(r,n)}async shouldIgnoreMessageEvent(e){const{topic:r,message:n}=e;return await this.subscriber.isSubscribed(r)?this.messages.has(r,n):!0}async onProviderPayload(e){if(this.logger.debug("Incoming Relay Payload"),this.logger.trace({type:"payload",direction:"incoming",payload:e}),Xu(e)){if(!e.method.endsWith(uE))return;const r=e.params,{topic:n,message:i,publishedAt:o}=r.data,c={topic:n,message:i,publishedAt:o};this.logger.debug("Emitting Relayer Payload"),this.logger.trace(UE({type:"event",event:r.id},c)),this.events.emit(r.id,c),await this.acknowledgePayload(e),await this.onMessageEvent(c)}}async onMessageEvent(e){await this.shouldIgnoreMessageEvent(e)||(this.events.emit(pr.message,e),await this.recordMessageEvent(e))}async acknowledgePayload(e){const r=Ju(e.id,!0);await this.provider.connection.send(r)}registerProviderListeners(){this.provider.on(Bo.payload,e=>this.onProviderPayload(e)),this.provider.on(Bo.connect,()=>{this.events.emit(pr.connect)}),this.provider.on(Bo.disconnect,()=>{this.onProviderDisconnect()}),this.provider.on(Bo.error,e=>{this.logger.error(e),this.events.emit(pr.error,e)})}registerEventListeners(){this.events.on(pr.connection_stalled,async()=>{await this.restartTransport()})}onProviderDisconnect(){this.events.emit(pr.disconnect),this.attemptToReconnect()}attemptToReconnect(){this.transportExplicitlyClosed||setTimeout(async()=>{await this.restartTransport()},ke.toMiliseconds(hE))}isInitialized(){if(!this.initialized){const{message:e}=_e("NOT_INITIALIZED",this.name);throw new Error(e)}}async toEstablishConnection(){if(!this.connected){if(this.connecting)return await new Promise(e=>{const r=setInterval(()=>{this.connected&&(clearInterval(r),e())},this.connectionStatusPollingInterval)});await this.restartTransport()}}}var FE=Object.defineProperty,ng=Object.getOwnPropertySymbols,BE=Object.prototype.hasOwnProperty,kE=Object.prototype.propertyIsEnumerable,ig=(t,e,r)=>e in t?FE(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,sg=(t,e)=>{for(var r in e||(e={}))BE.call(e,r)&&ig(t,r,e[r]);if(ng)for(var r of ng(e))kE.call(e,r)&&ig(t,r,e[r]);return t};class nc extends p4{constructor(e,r,n,i=hi,o=void 0){super(e,r,n,i),this.core=e,this.logger=r,this.name=n,this.map=new Map,this.version=dE,this.cached=[],this.initialized=!1,this.storagePrefix=hi,this.init=async()=>{this.initialized||(this.logger.trace("Initialized"),await this.restore(),this.cached.forEach(c=>{this.getKey&&c!==null&&!$r(c)?this.map.set(this.getKey(c),c):yb(c)?this.map.set(c.id,c):bb(c)&&this.map.set(c.topic,c)}),this.cached=[],this.initialized=!0)},this.set=async(c,l)=>{this.isInitialized(),this.map.has(c)?await this.update(c,l):(this.logger.debug("Setting value"),this.logger.trace({type:"method",method:"set",key:c,value:l}),this.map.set(c,l),await this.persist())},this.get=c=>(this.isInitialized(),this.logger.debug("Getting value"),this.logger.trace({type:"method",method:"get",key:c}),this.getData(c)),this.getAll=c=>(this.isInitialized(),c?this.values.filter(l=>Object.keys(c).every(h=>I_(l[h],c[h]))):this.values),this.update=async(c,l)=>{this.isInitialized(),this.logger.debug("Updating value"),this.logger.trace({type:"method",method:"update",key:c,update:l});const h=sg(sg({},this.getData(c)),l);this.map.set(c,h),await this.persist()},this.delete=async(c,l)=>{this.isInitialized(),this.map.has(c)&&(this.logger.debug("Deleting value"),this.logger.trace({type:"method",method:"delete",key:c,reason:l}),this.map.delete(c),await this.persist())},this.logger=pt.generateChildLogger(r,this.name),this.storagePrefix=i,this.getKey=o}get context(){return pt.getLoggerContext(this.logger)}get storageKey(){return this.storagePrefix+this.version+"//"+this.name}get length(){return this.map.size}get keys(){return Array.from(this.map.keys())}get values(){return Array.from(this.map.values())}async setDataStore(e){await this.core.storage.setItem(this.storageKey,e)}async getDataStore(){return await this.core.storage.getItem(this.storageKey)}getData(e){const r=this.map.get(e);if(!r){const{message:n}=_e("NO_MATCHING_KEY",`${this.name}: ${e}`);throw this.logger.error(n),new Error(n)}return r}async persist(){await this.setDataStore(this.values)}async restore(){try{const e=await this.getDataStore();if(typeof e>"u"||!e.length)return;if(this.map.size){const{message:r}=_e("RESTORE_WILL_OVERRIDE",this.name);throw this.logger.error(r),new Error(r)}this.cached=e,this.logger.debug(`Successfully Restored value for ${this.name}`),this.logger.trace({type:"method",method:"restore",value:this.values})}catch(e){this.logger.debug(`Failed to Restore value for ${this.name}`),this.logger.error(e)}}isInitialized(){if(!this.initialized){const{message:e}=_e("NOT_INITIALIZED",this.name);throw new Error(e)}}}class HE{constructor(e,r){this.core=e,this.logger=r,this.name=wE,this.version=vE,this.events=new yr.exports,this.initialized=!1,this.storagePrefix=hi,this.ignoredPayloadTypes=[Fi],this.registeredMethods=[],this.init=async()=>{this.initialized||(await this.pairings.init(),await this.cleanup(),this.registerRelayerEvents(),this.registerExpirerEvents(),this.initialized=!0,this.logger.trace("Initialized"))},this.register=({methods:n})=>{this.isInitialized(),this.registeredMethods=[...new Set([...this.registeredMethods,...n])]},this.create=async()=>{this.isInitialized();const n=Cu(),i=await this.core.crypto.setSymKey(n),o=Dn(ke.FIVE_MINUTES),c={protocol:Yp},l={topic:i,expiry:o,relay:c,active:!1},h=lb({protocol:this.core.protocol,version:this.core.version,topic:i,symKey:n,relay:c});return await this.pairings.set(i,l),await this.core.relayer.subscribe(i),this.core.expirer.set(i,o),{topic:i,uri:h}},this.pair=async n=>{this.isInitialized(),this.isValidPair(n);const{topic:i,symKey:o,relay:c}=ab(n.uri);if(this.pairings.keys.includes(i))throw new Error(`Pairing already exists: ${i}`);if(this.core.crypto.hasKeys(i))throw new Error(`Keychain already exists: ${i}`);const l=Dn(ke.FIVE_MINUTES),h={topic:i,relay:c,expiry:l,active:!1};return await this.pairings.set(i,h),await this.core.crypto.setSymKey(o,i),await this.core.relayer.subscribe(i,{relay:c}),this.core.expirer.set(i,l),n.activatePairing&&await this.activate({topic:i}),h},this.activate=async({topic:n})=>{this.isInitialized();const i=Dn(ke.THIRTY_DAYS);await this.pairings.update(n,{active:!0,expiry:i}),this.core.expirer.set(n,i)},this.ping=async n=>{this.isInitialized(),await this.isValidPing(n);const{topic:i}=n;if(this.pairings.keys.includes(i)){const o=await this.sendRequest(i,"wc_pairingPing",{}),{done:c,resolve:l,reject:h}=Os();this.events.once(er("pairing_ping",o),({error:d})=>{d?h(d):l()}),await c()}},this.updateExpiry=async({topic:n,expiry:i})=>{this.isInitialized(),await this.pairings.update(n,{expiry:i})},this.updateMetadata=async({topic:n,metadata:i})=>{this.isInitialized(),await this.pairings.update(n,{peerMetadata:i})},this.getPairings=()=>(this.isInitialized(),this.pairings.values),this.disconnect=async n=>{this.isInitialized(),await this.isValidDisconnect(n);const{topic:i}=n;this.pairings.keys.includes(i)&&(await this.sendRequest(i,"wc_pairingDelete",Zt("USER_DISCONNECTED")),await this.deletePairing(i))},this.sendRequest=async(n,i,o)=>{const c=ec(i,o),l=await this.core.crypto.encode(n,c),h=ko[i].req;return this.core.history.set(n,c),this.core.relayer.publish(n,l,h),c.id},this.sendResult=async(n,i,o)=>{const c=Ju(n,o),l=await this.core.crypto.encode(i,c),h=await this.core.history.get(i,n),d=ko[h.request.method].res;await this.core.relayer.publish(i,l,d),await this.core.history.resolve(c)},this.sendError=async(n,i,o)=>{const c=tc(n,o),l=await this.core.crypto.encode(i,c),h=await this.core.history.get(i,n),d=ko[h.request.method]?ko[h.request.method].res:ko.unregistered_method.res;await this.core.relayer.publish(i,l,d),await this.core.history.resolve(c)},this.deletePairing=async(n,i)=>{await this.core.relayer.unsubscribe(n),await Promise.all([this.pairings.delete(n,Zt("USER_DISCONNECTED")),this.core.crypto.deleteSymKey(n),i?Promise.resolve():this.core.expirer.del(n)])},this.cleanup=async()=>{const n=this.pairings.getAll().filter(i=>li(i.expiry));await Promise.all(n.map(i=>this.deletePairing(i.topic)))},this.onRelayEventRequest=n=>{const{topic:i,payload:o}=n,c=o.method;if(this.pairings.keys.includes(i))switch(c){case"wc_pairingPing":return this.onPairingPingRequest(i,o);case"wc_pairingDelete":return this.onPairingDeleteRequest(i,o);default:return this.onUnknownRpcMethodRequest(i,o)}},this.onRelayEventResponse=async n=>{const{topic:i,payload:o}=n,c=(await this.core.history.get(i,o.id)).request.method;if(this.pairings.keys.includes(i))switch(c){case"wc_pairingPing":return this.onPairingPingResponse(i,o);default:return this.onUnknownRpcMethodResponse(c)}},this.onPairingPingRequest=async(n,i)=>{const{id:o}=i;try{this.isValidPing({topic:n}),await this.sendResult(o,n,!0),this.events.emit("pairing_ping",{id:o,topic:n})}catch(c){await this.sendError(o,n,c),this.logger.error(c)}},this.onPairingPingResponse=(n,i)=>{const{id:o}=i;setTimeout(()=>{qn(i)?this.events.emit(er("pairing_ping",o),{}):_n(i)&&this.events.emit(er("pairing_ping",o),{error:i.error})},500)},this.onPairingDeleteRequest=async(n,i)=>{const{id:o}=i;try{this.isValidDisconnect({topic:n}),await this.deletePairing(n),this.events.emit("pairing_delete",{id:o,topic:n})}catch(c){await this.sendError(o,n,c),this.logger.error(c)}},this.onUnknownRpcMethodRequest=async(n,i)=>{const{id:o,method:c}=i;try{if(this.registeredMethods.includes(c))return;const l=Zt("WC_METHOD_UNSUPPORTED",c);await this.sendError(o,n,l),this.logger.error(l)}catch(l){await this.sendError(o,n,l),this.logger.error(l)}},this.onUnknownRpcMethodResponse=n=>{this.registeredMethods.includes(n)||this.logger.error(Zt("WC_METHOD_UNSUPPORTED",n))},this.isValidPair=n=>{if(!Hr(n)){const{message:i}=_e("MISSING_OR_INVALID",`pair() params: ${n}`);throw new Error(i)}if(!vb(n.uri)){const{message:i}=_e("MISSING_OR_INVALID",`pair() uri: ${n.uri}`);throw new Error(i)}},this.isValidPing=async n=>{if(!Hr(n)){const{message:o}=_e("MISSING_OR_INVALID",`ping() params: ${n}`);throw new Error(o)}const{topic:i}=n;await this.isValidPairingTopic(i)},this.isValidDisconnect=async n=>{if(!Hr(n)){const{message:o}=_e("MISSING_OR_INVALID",`disconnect() params: ${n}`);throw new Error(o)}const{topic:i}=n;await this.isValidPairingTopic(i)},this.isValidPairingTopic=async n=>{if(!dr(n,!1)){const{message:i}=_e("MISSING_OR_INVALID",`pairing topic should be a string: ${n}`);throw new Error(i)}if(!this.pairings.keys.includes(n)){const{message:i}=_e("NO_MATCHING_KEY",`pairing topic doesn't exist: ${n}`);throw new Error(i)}if(li(this.pairings.get(n).expiry)){await this.deletePairing(n);const{message:i}=_e("EXPIRED",`pairing topic: ${n}`);throw new Error(i)}},this.core=e,this.logger=pt.generateChildLogger(r,this.name),this.pairings=new nc(this.core,this.logger,this.name,this.storagePrefix)}get context(){return pt.getLoggerContext(this.logger)}isInitialized(){if(!this.initialized){const{message:e}=_e("NOT_INITIALIZED",this.name);throw new Error(e)}}registerRelayerEvents(){this.core.relayer.on(pr.message,async e=>{const{topic:r,message:n}=e;if(this.ignoredPayloadTypes.includes(this.core.crypto.getPayloadType(n)))return;const i=await this.core.crypto.decode(r,n);Xu(i)?(this.core.history.set(r,i),this.onRelayEventRequest({topic:r,payload:i})):Qu(i)&&(await this.core.history.resolve(i),this.onRelayEventResponse({topic:r,payload:i}))})}registerExpirerEvents(){this.core.expirer.on(sn.expired,async e=>{const{topic:r}=P1(e.target);r&&this.pairings.keys.includes(r)&&(await this.deletePairing(r,!0),this.events.emit("pairing_expire",{topic:r}))})}}class zE extends u4{constructor(e,r){super(e,r),this.core=e,this.logger=r,this.records=new Map,this.events=new yr.exports.EventEmitter,this.name=yE,this.version=bE,this.cached=[],this.initialized=!1,this.storagePrefix=hi,this.init=async()=>{this.initialized||(this.logger.trace("Initialized"),await this.restore(),this.cached.forEach(n=>this.records.set(n.id,n)),this.cached=[],this.registerEventListeners(),this.initialized=!0)},this.set=(n,i,o)=>{if(this.isInitialized(),this.logger.debug("Setting JSON-RPC request history record"),this.logger.trace({type:"method",method:"set",topic:n,request:i,chainId:o}),this.records.has(i.id))return;const c={id:i.id,topic:n,request:{method:i.method,params:i.params||null},chainId:o};this.records.set(c.id,c),this.events.emit(Pn.created,c)},this.resolve=async n=>{if(this.isInitialized(),this.logger.debug("Updating JSON-RPC response history record"),this.logger.trace({type:"method",method:"update",response:n}),!this.records.has(n.id))return;const i=await this.getRecord(n.id);typeof i.response>"u"&&(i.response=_n(n)?{error:n.error}:{result:n.result},this.records.set(i.id,i),this.events.emit(Pn.updated,i))},this.get=async(n,i)=>(this.isInitialized(),this.logger.debug("Getting record"),this.logger.trace({type:"method",method:"get",topic:n,id:i}),await this.getRecord(i)),this.delete=(n,i)=>{this.isInitialized(),this.logger.debug("Deleting record"),this.logger.trace({type:"method",method:"delete",id:i}),this.values.forEach(o=>{if(o.topic===n){if(typeof i<"u"&&o.id!==i)return;this.records.delete(o.id),this.events.emit(Pn.deleted,o)}})},this.exists=async(n,i)=>(this.isInitialized(),this.records.has(i)?(await this.getRecord(i)).topic===n:!1),this.on=(n,i)=>{this.events.on(n,i)},this.once=(n,i)=>{this.events.once(n,i)},this.off=(n,i)=>{this.events.off(n,i)},this.removeListener=(n,i)=>{this.events.removeListener(n,i)},this.logger=pt.generateChildLogger(r,this.name)}get context(){return pt.getLoggerContext(this.logger)}get storageKey(){return this.storagePrefix+this.version+"//"+this.name}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(r=>{if(typeof r.response<"u")return;const n={topic:r.topic,request:ec(r.request.method,r.request.params,r.id),chainId:r.chainId};return e.push(n)}),e}async setJsonRpcRecords(e){await this.core.storage.setItem(this.storageKey,e)}async getJsonRpcRecords(){return await this.core.storage.getItem(this.storageKey)}getRecord(e){this.isInitialized();const r=this.records.get(e);if(!r){const{message:n}=_e("NO_MATCHING_KEY",`${this.name}: ${e}`);throw new Error(n)}return r}async persist(){await this.setJsonRpcRecords(this.values),this.events.emit(Pn.sync)}async restore(){try{const e=await this.getJsonRpcRecords();if(typeof e>"u"||!e.length)return;if(this.records.size){const{message:r}=_e("RESTORE_WILL_OVERRIDE",this.name);throw this.logger.error(r),new Error(r)}this.cached=e,this.logger.debug(`Successfully Restored records for ${this.name}`),this.logger.trace({type:"method",method:"restore",records:this.values})}catch(e){this.logger.debug(`Failed to Restore records for ${this.name}`),this.logger.error(e)}}registerEventListeners(){this.events.on(Pn.created,e=>{const r=Pn.created;this.logger.info(`Emitting ${r}`),this.logger.debug({type:"event",event:r,record:e}),this.persist()}),this.events.on(Pn.updated,e=>{const r=Pn.updated;this.logger.info(`Emitting ${r}`),this.logger.debug({type:"event",event:r,record:e}),this.persist()}),this.events.on(Pn.deleted,e=>{const r=Pn.deleted;this.logger.info(`Emitting ${r}`),this.logger.debug({type:"event",event:r,record:e}),this.persist()})}isInitialized(){if(!this.initialized){const{message:e}=_e("NOT_INITIALIZED",this.name);throw new Error(e)}}}class WE extends m4{constructor(e,r){super(e,r),this.core=e,this.logger=r,this.expirations=new Map,this.events=new yr.exports.EventEmitter,this.name=_E,this.version=EE,this.cached=[],this.initialized=!1,this.storagePrefix=hi,this.init=async()=>{this.initialized||(this.logger.trace("Initialized"),await this.restore(),this.cached.forEach(n=>this.expirations.set(n.target,n)),this.cached=[],this.registerEventListeners(),this.initialized=!0)},this.has=n=>{try{const i=this.formatTarget(n);return typeof this.getExpiration(i)<"u"}catch{return!1}},this.set=(n,i)=>{this.isInitialized();const o=this.formatTarget(n),c={target:o,expiry:i};this.expirations.set(o,c),this.checkExpiry(o,c),this.events.emit(sn.created,{target:o,expiration:c})},this.get=n=>{this.isInitialized();const i=this.formatTarget(n);return this.getExpiration(i)},this.del=n=>{if(this.isInitialized(),this.has(n)){const i=this.formatTarget(n),o=this.getExpiration(i);this.expirations.delete(i),this.events.emit(sn.deleted,{target:i,expiration:o})}},this.on=(n,i)=>{this.events.on(n,i)},this.once=(n,i)=>{this.events.once(n,i)},this.off=(n,i)=>{this.events.off(n,i)},this.removeListener=(n,i)=>{this.events.removeListener(n,i)},this.logger=pt.generateChildLogger(r,this.name)}get context(){return pt.getLoggerContext(this.logger)}get storageKey(){return this.storagePrefix+this.version+"//"+this.name}get length(){return this.expirations.size}get keys(){return Array.from(this.expirations.keys())}get values(){return Array.from(this.expirations.values())}formatTarget(e){if(typeof e=="string")return Q5(e);if(typeof e=="number")return eb(e);const{message:r}=_e("UNKNOWN_TYPE",`Target type: ${typeof e}`);throw new Error(r)}async setExpirations(e){await this.core.storage.setItem(this.storageKey,e)}async getExpirations(){return await this.core.storage.getItem(this.storageKey)}async persist(){await this.setExpirations(this.values),this.events.emit(sn.sync)}async restore(){try{const e=await this.getExpirations();if(typeof e>"u"||!e.length)return;if(this.expirations.size){const{message:r}=_e("RESTORE_WILL_OVERRIDE",this.name);throw this.logger.error(r),new Error(r)}this.cached=e,this.logger.debug(`Successfully Restored expirations for ${this.name}`),this.logger.trace({type:"method",method:"restore",expirations:this.values})}catch(e){this.logger.debug(`Failed to Restore expirations for ${this.name}`),this.logger.error(e)}}getExpiration(e){const r=this.expirations.get(e);if(!r){const{message:n}=_e("NO_MATCHING_KEY",`${this.name}: ${e}`);throw this.logger.error(n),new Error(n)}return r}checkExpiry(e,r){const{expiry:n}=r;ke.toMiliseconds(n)-Date.now()<=0&&this.expire(e,r)}expire(e,r){this.expirations.delete(e),this.events.emit(sn.expired,{target:e,expiration:r})}checkExpirations(){this.core.relayer.connected&&this.expirations.forEach((e,r)=>this.checkExpiry(r,e))}registerEventListeners(){this.core.heartbeat.on(Po.HEARTBEAT_EVENTS.pulse,()=>this.checkExpirations()),this.events.on(sn.created,e=>{const r=sn.created;this.logger.info(`Emitting ${r}`),this.logger.debug({type:"event",event:r,data:e}),this.persist()}),this.events.on(sn.expired,e=>{const r=sn.expired;this.logger.info(`Emitting ${r}`),this.logger.debug({type:"event",event:r,data:e}),this.persist()}),this.events.on(sn.deleted,e=>{const r=sn.deleted;this.logger.info(`Emitting ${r}`),this.logger.debug({type:"event",event:r,data:e}),this.persist()})}isInitialized(){if(!this.initialized){const{message:e}=_e("NOT_INITIALIZED",this.name);throw new Error(e)}}}class qE extends w4{constructor(e,r){super(e,r),this.projectId=e,this.logger=r,this.name=sh,this.initialized=!1,this.init=async n=>{S1()||!Su()||(this.verifyUrl=n?.verifyUrl||Xp,await this.createIframe())},this.register=async n=>{var i;this.initialized||await this.init(),this.iframe&&((i=this.iframe.contentWindow)==null||i.postMessage(n.attestationId,this.verifyUrl),this.logger.info(`postMessage sent: ${n.attestationId} ${this.verifyUrl}`))},this.resolve=async n=>{var i;if(this.isDevEnv)return"";this.logger.info(`resolving attestation: ${n.attestationId}`);const o=this.startAbortTimer(ke.FIVE_SECONDS),c=await fetch(`${this.verifyUrl}/attestation/${n.attestationId}`,{signal:this.abortController.signal});return clearTimeout(o),c.status===200?(i=await c.json())==null?void 0:i.origin:""},this.createIframe=async()=>{try{await Promise.race([new Promise((n,i)=>{if(document.getElementById(sh))return n();const o=document.createElement("iframe");o.setAttribute("id",sh),o.setAttribute("src",`${this.verifyUrl}/${this.projectId}`),o.style.display="none",o.addEventListener("load",()=>{this.initialized=!0,n()}),o.addEventListener("error",c=>{i(c)}),document.body.append(o),this.iframe=o}),new Promise(n=>{setTimeout(()=>n("iframe load timeout"),ke.toMiliseconds(ke.ONE_SECOND/2))})])}catch(n){this.logger.error(`Verify iframe failed to load: ${this.verifyUrl}`),this.logger.error(n)}},this.logger=pt.generateChildLogger(r,this.name),this.verifyUrl=Xp,this.abortController=new AbortController,this.isDevEnv=Iu()&&process.env.IS_VITEST}get context(){return pt.getLoggerContext(this.logger)}startAbortTimer(e){return setTimeout(()=>this.abortController.abort(),ke.toMiliseconds(e))}}var VE=Object.defineProperty,og=Object.getOwnPropertySymbols,KE=Object.prototype.hasOwnProperty,GE=Object.prototype.propertyIsEnumerable,ag=(t,e,r)=>e in t?VE(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,cg=(t,e)=>{for(var r in e||(e={}))KE.call(e,r)&&ag(t,r,e[r]);if(og)for(var r of og(e))GE.call(e,r)&&ag(t,r,e[r]);return t};class ah extends l4{constructor(e){super(e),this.protocol=Gp,this.version=J8,this.name=ih,this.events=new yr.exports.EventEmitter,this.initialized=!1,this.on=(n,i)=>this.events.on(n,i),this.once=(n,i)=>this.events.once(n,i),this.off=(n,i)=>this.events.off(n,i),this.removeListener=(n,i)=>this.events.removeListener(n,i),this.projectId=e?.projectId,this.relayUrl=e?.relayUrl||Jp;const r=typeof e?.logger<"u"&&typeof e?.logger!="string"?e.logger:pt.pino(pt.getDefaultLoggerOptions({level:e?.logger||X8.logger}));this.logger=pt.generateChildLogger(r,this.name),this.heartbeat=new Po.HeartBeat,this.crypto=new CE(this,this.logger,e?.keychain),this.history=new zE(this,this.logger),this.expirer=new WE(this,this.logger),this.storage=e!=null&&e.storage?e.storage:new d6(cg(cg({},Q8),e?.storageOptions)),this.relayer=new jE({core:this,logger:this.logger,relayUrl:this.relayUrl,projectId:this.projectId}),this.pairing=new HE(this,this.logger),this.verify=new qE(this.projectId||"",this.logger)}static async init(e){const r=new ah(e);return await r.initialize(),r}get context(){return pt.getLoggerContext(this.logger)}async start(){this.initialized||await this.initialize()}async initialize(){this.logger.trace("Initialized");try{await this.crypto.init(),await this.history.init(),await this.expirer.init(),await this.relayer.init(),await this.heartbeat.init(),await this.pairing.init(),this.initialized=!0,this.logger.info("Core Initialization Success")}catch(e){throw this.logger.warn(`Core Initialization Failure at epoch ${Date.now()}`,e),this.logger.error(e.message),e}}}const ZE=ah,lg="wc",ug=2,hg="client",ch=`${lg}@${ug}:${hg}:`,lh={name:hg,logger:"error",controller:!1,relayUrl:"wss://relay.walletconnect.com"},YE="proposal",fg="Proposal expired",JE="session",ic=ke.SEVEN_DAYS,XE="engine",zo={wc_sessionPropose:{req:{ttl:ke.FIVE_MINUTES,prompt:!0,tag:1100},res:{ttl:ke.FIVE_MINUTES,prompt:!1,tag:1101}},wc_sessionSettle:{req:{ttl:ke.FIVE_MINUTES,prompt:!1,tag:1102},res:{ttl:ke.FIVE_MINUTES,prompt:!1,tag:1103}},wc_sessionUpdate:{req:{ttl:ke.ONE_DAY,prompt:!1,tag:1104},res:{ttl:ke.ONE_DAY,prompt:!1,tag:1105}},wc_sessionExtend:{req:{ttl:ke.ONE_DAY,prompt:!1,tag:1106},res:{ttl:ke.ONE_DAY,prompt:!1,tag:1107}},wc_sessionRequest:{req:{ttl:ke.FIVE_MINUTES,prompt:!0,tag:1108},res:{ttl:ke.FIVE_MINUTES,prompt:!1,tag:1109}},wc_sessionEvent:{req:{ttl:ke.FIVE_MINUTES,prompt:!0,tag:1110},res:{ttl:ke.FIVE_MINUTES,prompt:!1,tag:1111}},wc_sessionDelete:{req:{ttl:ke.ONE_DAY,prompt:!1,tag:1112},res:{ttl:ke.ONE_DAY,prompt:!1,tag:1113}},wc_sessionPing:{req:{ttl:ke.THIRTY_SECONDS,prompt:!1,tag:1114},res:{ttl:ke.THIRTY_SECONDS,prompt:!1,tag:1115}}},uh={min:ke.FIVE_MINUTES,max:ke.SEVEN_DAYS},QE="request",e7=["wc_sessionPropose","wc_sessionRequest","wc_authRequest"];var t7=Object.defineProperty,r7=Object.defineProperties,n7=Object.getOwnPropertyDescriptors,dg=Object.getOwnPropertySymbols,i7=Object.prototype.hasOwnProperty,s7=Object.prototype.propertyIsEnumerable,pg=(t,e,r)=>e in t?t7(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,on=(t,e)=>{for(var r in e||(e={}))i7.call(e,r)&&pg(t,r,e[r]);if(dg)for(var r of dg(e))s7.call(e,r)&&pg(t,r,e[r]);return t},hh=(t,e)=>r7(t,n7(e));class o7 extends y4{constructor(e){super(e),this.name=XE,this.events=new yr.exports,this.initialized=!1,this.ignoredPayloadTypes=[Fi],this.init=async()=>{this.initialized||(await this.cleanup(),this.registerRelayerEvents(),this.registerExpirerEvents(),this.client.core.pairing.register({methods:Object.keys(zo)}),this.initialized=!0)},this.connect=async r=>{this.isInitialized();const n=hh(on({},r),{requiredNamespaces:r.requiredNamespaces||{},optionalNamespaces:r.optionalNamespaces||{}});await this.isValidConnect(n);const{pairingTopic:i,requiredNamespaces:o,optionalNamespaces:c,sessionProperties:l,relays:h}=n;let d=i,v,E=!1;if(d&&(E=this.client.core.pairing.pairings.get(d).active),!d||!E){const{topic:L,uri:$}=await this.client.core.pairing.create();d=L,v=$}const _=await this.client.core.crypto.generateKeyPair(),O=on({requiredNamespaces:o,optionalNamespaces:c,relays:h??[{protocol:Yp}],proposer:{publicKey:_,metadata:this.client.metadata}},l&&{sessionProperties:l}),{reject:P,resolve:U,done:H}=Os(ke.FIVE_MINUTES,fg);if(this.events.once(er("session_connect"),async({error:L,session:$})=>{if(L)P(L);else if($){$.self.publicKey=_;const T=hh(on({},$),{requiredNamespaces:$.requiredNamespaces,optionalNamespaces:$.optionalNamespaces});await this.client.session.set($.topic,T),await this.setExpiry($.topic,$.expiry),d&&await this.client.core.pairing.updateMetadata({topic:d,metadata:$.peer.metadata}),U(T)}}),!d){const{message:L}=_e("NO_MATCHING_KEY",`connect() pairing topic: ${d}`);throw new Error(L)}const G=await this.sendRequest(d,"wc_sessionPropose",O),N=Dn(ke.FIVE_MINUTES);return await this.setProposal(G,on({id:G,expiry:N},O)),{uri:v,approval:H}},this.pair=async r=>(this.isInitialized(),await this.client.core.pairing.pair(r)),this.approve=async r=>{this.isInitialized(),await this.isValidApprove(r);const{id:n,relayProtocol:i,namespaces:o,sessionProperties:c}=r,l=this.client.proposal.get(n);let{pairingTopic:h,proposer:d,requiredNamespaces:v,optionalNamespaces:E}=l;h=h||"",Ds(v)||(v=db(o,"approve()"));const _=await this.client.core.crypto.generateKeyPair(),O=d.publicKey,P=await this.client.core.crypto.generateSharedKey(_,O);h&&n&&(await this.client.core.pairing.updateMetadata({topic:h,metadata:d.metadata}),await this.sendResult(n,h,{relay:{protocol:i??"irn"},responderPublicKey:_}),await this.client.proposal.delete(n,Zt("USER_DISCONNECTED")),await this.client.core.pairing.activate({topic:h}));const U=on({relay:{protocol:i??"irn"},namespaces:o,requiredNamespaces:v,optionalNamespaces:E,pairingTopic:h,controller:{publicKey:_,metadata:this.client.metadata},expiry:Dn(ic)},c&&{sessionProperties:c});await this.client.core.relayer.subscribe(P),await this.sendRequest(P,"wc_sessionSettle",U);const H=hh(on({},U),{topic:P,pairingTopic:h,acknowledged:!1,self:U.controller,peer:{publicKey:d.publicKey,metadata:d.metadata},controller:_});return await this.client.session.set(P,H),await this.setExpiry(P,Dn(ic)),{topic:P,acknowledged:()=>new Promise(G=>setTimeout(()=>G(this.client.session.get(P)),500))}},this.reject=async r=>{this.isInitialized(),await this.isValidReject(r);const{id:n,reason:i}=r,{pairingTopic:o}=this.client.proposal.get(n);o&&(await this.sendError(n,o,i),await this.client.proposal.delete(n,Zt("USER_DISCONNECTED")))},this.update=async r=>{this.isInitialized(),await this.isValidUpdate(r);const{topic:n,namespaces:i}=r,o=await this.sendRequest(n,"wc_sessionUpdate",{namespaces:i}),{done:c,resolve:l,reject:h}=Os();return this.events.once(er("session_update",o),({error:d})=>{d?h(d):l()}),await this.client.session.update(n,{namespaces:i}),{acknowledged:c}},this.extend=async r=>{this.isInitialized(),await this.isValidExtend(r);const{topic:n}=r,i=await this.sendRequest(n,"wc_sessionExtend",{}),{done:o,resolve:c,reject:l}=Os();return this.events.once(er("session_extend",i),({error:h})=>{h?l(h):c()}),await this.setExpiry(n,Dn(ic)),{acknowledged:o}},this.request=async r=>{this.isInitialized(),await this.isValidRequest(r);const{chainId:n,request:i,topic:o,expiry:c}=r,l=await this.sendRequest(o,"wc_sessionRequest",{request:i,chainId:n},c),{done:h,resolve:d,reject:v}=Os(c);return this.events.once(er("session_request",l),({error:E,result:_})=>{E?v(E):d(_)}),this.client.events.emit("session_request_sent",{topic:o,request:i,chainId:n,id:l}),await h()},this.respond=async r=>{this.isInitialized(),await this.isValidRespond(r);const{topic:n,response:i}=r,{id:o}=i;qn(i)?await this.sendResult(o,n,i.result):_n(i)&&await this.sendError(o,n,i.error),this.deletePendingSessionRequest(r.response.id,{message:"fulfilled",code:0})},this.ping=async r=>{this.isInitialized(),await this.isValidPing(r);const{topic:n}=r;if(this.client.session.keys.includes(n)){const i=await this.sendRequest(n,"wc_sessionPing",{}),{done:o,resolve:c,reject:l}=Os();this.events.once(er("session_ping",i),({error:h})=>{h?l(h):c()}),await o()}else this.client.core.pairing.pairings.keys.includes(n)&&await this.client.core.pairing.ping({topic:n})},this.emit=async r=>{this.isInitialized(),await this.isValidEmit(r);const{topic:n,event:i,chainId:o}=r;await this.sendRequest(n,"wc_sessionEvent",{event:i,chainId:o})},this.disconnect=async r=>{this.isInitialized(),await this.isValidDisconnect(r);const{topic:n}=r;this.client.session.keys.includes(n)?(await this.sendRequest(n,"wc_sessionDelete",Zt("USER_DISCONNECTED")),await this.deleteSession(n)):await this.client.core.pairing.disconnect({topic:n})},this.find=r=>(this.isInitialized(),this.client.session.getAll().filter(n=>mb(n,r))),this.getPendingSessionRequests=()=>(this.isInitialized(),this.client.pendingRequest.getAll()),this.cleanupDuplicatePairings=async r=>{try{const n=this.client.core.pairing.pairings.get(r.pairingTopic),i=this.client.core.pairing.pairings.getAll().filter(o=>{var c,l;return((c=o.peerMetadata)==null?void 0:c.url)&&((l=o.peerMetadata)==null?void 0:l.url)===r.self.metadata.url&&o.topic!==n.topic});if(i.length===0)return;this.client.logger.info(`Cleaning up ${i.length} duplicate pairing(s)`),await Promise.all(i.map(o=>this.client.core.pairing.disconnect({topic:o.topic}))),this.client.logger.info("Duplicate pairings clean up finished")}catch(n){this.client.logger.error(n)}},this.deleteSession=async(r,n)=>{const{self:i}=this.client.session.get(r);await this.client.core.relayer.unsubscribe(r),await Promise.all([this.client.session.delete(r,Zt("USER_DISCONNECTED")),this.client.core.crypto.deleteKeyPair(i.publicKey),this.client.core.crypto.deleteSymKey(r),n?Promise.resolve():this.client.core.expirer.del(r)])},this.deleteProposal=async(r,n)=>{await Promise.all([this.client.proposal.delete(r,Zt("USER_DISCONNECTED")),n?Promise.resolve():this.client.core.expirer.del(r)])},this.deletePendingSessionRequest=async(r,n,i=!1)=>{await Promise.all([this.client.pendingRequest.delete(r,n),i?Promise.resolve():this.client.core.expirer.del(r)])},this.setExpiry=async(r,n)=>{this.client.session.keys.includes(r)&&await this.client.session.update(r,{expiry:n}),this.client.core.expirer.set(r,n)},this.setProposal=async(r,n)=>{await this.client.proposal.set(r,n),this.client.core.expirer.set(r,n.expiry)},this.setPendingSessionRequest=async r=>{const n=zo.wc_sessionRequest.req.ttl,{id:i,topic:o,params:c}=r;await this.client.pendingRequest.set(i,{id:i,topic:o,params:c}),n&&this.client.core.expirer.set(i,Dn(n))},this.sendRequest=async(r,n,i,o)=>{const c=ec(n,i);if(Su()&&e7.includes(n)){const d=Bi(JSON.stringify(c));await this.client.core.verify.register({attestationId:d})}const l=await this.client.core.crypto.encode(r,c),h=zo[n].req;return o&&(h.ttl=o),this.client.core.history.set(r,c),this.client.core.relayer.publish(r,l,h),c.id},this.sendResult=async(r,n,i)=>{const o=Ju(r,i),c=await this.client.core.crypto.encode(n,o),l=await this.client.core.history.get(n,r),h=zo[l.request.method].res;this.client.core.relayer.publish(n,c,h),await this.client.core.history.resolve(o)},this.sendError=async(r,n,i)=>{const o=tc(r,i),c=await this.client.core.crypto.encode(n,o),l=await this.client.core.history.get(n,r),h=zo[l.request.method].res;this.client.core.relayer.publish(n,c,h),await this.client.core.history.resolve(o)},this.cleanup=async()=>{const r=[],n=[];this.client.session.getAll().forEach(i=>{li(i.expiry)&&r.push(i.topic)}),this.client.proposal.getAll().forEach(i=>{li(i.expiry)&&n.push(i.id)}),await Promise.all([...r.map(i=>this.deleteSession(i)),...n.map(i=>this.deleteProposal(i))])},this.onRelayEventRequest=r=>{const{topic:n,payload:i}=r,o=i.method;switch(o){case"wc_sessionPropose":return this.onSessionProposeRequest(n,i);case"wc_sessionSettle":return this.onSessionSettleRequest(n,i);case"wc_sessionUpdate":return this.onSessionUpdateRequest(n,i);case"wc_sessionExtend":return this.onSessionExtendRequest(n,i);case"wc_sessionPing":return this.onSessionPingRequest(n,i);case"wc_sessionDelete":return this.onSessionDeleteRequest(n,i);case"wc_sessionRequest":return this.onSessionRequest(n,i);case"wc_sessionEvent":return this.onSessionEventRequest(n,i);default:return this.client.logger.info(`Unsupported request method ${o}`)}},this.onRelayEventResponse=async r=>{const{topic:n,payload:i}=r,o=(await this.client.core.history.get(n,i.id)).request.method;switch(o){case"wc_sessionPropose":return this.onSessionProposeResponse(n,i);case"wc_sessionSettle":return this.onSessionSettleResponse(n,i);case"wc_sessionUpdate":return this.onSessionUpdateResponse(n,i);case"wc_sessionExtend":return this.onSessionExtendResponse(n,i);case"wc_sessionPing":return this.onSessionPingResponse(n,i);case"wc_sessionRequest":return this.onSessionRequestResponse(n,i);default:return this.client.logger.info(`Unsupported response method ${o}`)}},this.onSessionProposeRequest=async(r,n)=>{const{params:i,id:o}=n;try{this.isValidConnect(on({},n.params));const c=Dn(ke.FIVE_MINUTES),l=on({id:o,pairingTopic:r,expiry:c},i);await this.setProposal(o,l);const h=Bi(JSON.stringify(n)),d=await this.getVerifyContext(h,l.proposer.metadata);this.client.events.emit("session_proposal",{id:o,params:l,verifyContext:d})}catch(c){await this.sendError(o,r,c),this.client.logger.error(c)}},this.onSessionProposeResponse=async(r,n)=>{const{id:i}=n;if(qn(n)){const{result:o}=n;this.client.logger.trace({type:"method",method:"onSessionProposeResponse",result:o});const c=this.client.proposal.get(i);this.client.logger.trace({type:"method",method:"onSessionProposeResponse",proposal:c});const l=c.proposer.publicKey;this.client.logger.trace({type:"method",method:"onSessionProposeResponse",selfPublicKey:l});const h=o.responderPublicKey;this.client.logger.trace({type:"method",method:"onSessionProposeResponse",peerPublicKey:h});const d=await this.client.core.crypto.generateSharedKey(l,h);this.client.logger.trace({type:"method",method:"onSessionProposeResponse",sessionTopic:d});const v=await this.client.core.relayer.subscribe(d);this.client.logger.trace({type:"method",method:"onSessionProposeResponse",subscriptionId:v}),await this.client.core.pairing.activate({topic:r})}else _n(n)&&(await this.client.proposal.delete(i,Zt("USER_DISCONNECTED")),this.events.emit(er("session_connect"),{error:n.error}))},this.onSessionSettleRequest=async(r,n)=>{const{id:i,params:o}=n;try{this.isValidSessionSettleRequest(o);const{relay:c,controller:l,expiry:h,namespaces:d,requiredNamespaces:v,optionalNamespaces:E,sessionProperties:_,pairingTopic:O}=n.params,P=on({topic:r,relay:c,expiry:h,namespaces:d,acknowledged:!0,pairingTopic:O,requiredNamespaces:v,optionalNamespaces:E,controller:l.publicKey,self:{publicKey:"",metadata:this.client.metadata},peer:{publicKey:l.publicKey,metadata:l.metadata}},_&&{sessionProperties:_});await this.sendResult(n.id,r,!0),this.events.emit(er("session_connect"),{session:P}),this.cleanupDuplicatePairings(P)}catch(c){await this.sendError(i,r,c),this.client.logger.error(c)}},this.onSessionSettleResponse=async(r,n)=>{const{id:i}=n;qn(n)?(await this.client.session.update(r,{acknowledged:!0}),this.events.emit(er("session_approve",i),{})):_n(n)&&(await this.client.session.delete(r,Zt("USER_DISCONNECTED")),this.events.emit(er("session_approve",i),{error:n.error}))},this.onSessionUpdateRequest=async(r,n)=>{const{params:i,id:o}=n;try{this.isValidUpdate(on({topic:r},i)),await this.client.session.update(r,{namespaces:i.namespaces}),await this.sendResult(o,r,!0),this.client.events.emit("session_update",{id:o,topic:r,params:i})}catch(c){await this.sendError(o,r,c),this.client.logger.error(c)}},this.onSessionUpdateResponse=(r,n)=>{const{id:i}=n;qn(n)?this.events.emit(er("session_update",i),{}):_n(n)&&this.events.emit(er("session_update",i),{error:n.error})},this.onSessionExtendRequest=async(r,n)=>{const{id:i}=n;try{this.isValidExtend({topic:r}),await this.setExpiry(r,Dn(ic)),await this.sendResult(i,r,!0),this.client.events.emit("session_extend",{id:i,topic:r})}catch(o){await this.sendError(i,r,o),this.client.logger.error(o)}},this.onSessionExtendResponse=(r,n)=>{const{id:i}=n;qn(n)?this.events.emit(er("session_extend",i),{}):_n(n)&&this.events.emit(er("session_extend",i),{error:n.error})},this.onSessionPingRequest=async(r,n)=>{const{id:i}=n;try{this.isValidPing({topic:r}),await this.sendResult(i,r,!0),this.client.events.emit("session_ping",{id:i,topic:r})}catch(o){await this.sendError(i,r,o),this.client.logger.error(o)}},this.onSessionPingResponse=(r,n)=>{const{id:i}=n;setTimeout(()=>{qn(n)?this.events.emit(er("session_ping",i),{}):_n(n)&&this.events.emit(er("session_ping",i),{error:n.error})},500)},this.onSessionDeleteRequest=async(r,n)=>{const{id:i}=n;try{this.isValidDisconnect({topic:r,reason:n.params}),await Promise.all([new Promise(o=>{this.client.core.relayer.once(pr.publish,async()=>{o(await this.deleteSession(r))})}),this.sendResult(i,r,!0)]),this.client.events.emit("session_delete",{id:i,topic:r})}catch(o){await this.sendError(i,r,o),this.client.logger.error(o)}},this.onSessionRequest=async(r,n)=>{const{id:i,params:o}=n;try{this.isValidRequest(on({topic:r},o)),await this.setPendingSessionRequest({id:i,topic:r,params:o});const c=Bi(JSON.stringify(n)),l=this.client.session.get(r),h=await this.getVerifyContext(c,l.peer.metadata);this.client.events.emit("session_request",{id:i,topic:r,params:o,verifyContext:h})}catch(c){await this.sendError(i,r,c),this.client.logger.error(c)}},this.onSessionRequestResponse=(r,n)=>{const{id:i}=n;qn(n)?this.events.emit(er("session_request",i),{result:n.result}):_n(n)&&this.events.emit(er("session_request",i),{error:n.error})},this.onSessionEventRequest=async(r,n)=>{const{id:i,params:o}=n;try{this.isValidEmit(on({topic:r},o)),this.client.events.emit("session_event",{id:i,topic:r,params:o})}catch(c){await this.sendError(i,r,c),this.client.logger.error(c)}},this.isValidConnect=async r=>{if(!Hr(r)){const{message:h}=_e("MISSING_OR_INVALID",`connect() params: ${JSON.stringify(r)}`);throw new Error(h)}const{pairingTopic:n,requiredNamespaces:i,optionalNamespaces:o,sessionProperties:c,relays:l}=r;if($r(n)||await this.isValidPairingTopic(n),!Ab(l,!0)){const{message:h}=_e("MISSING_OR_INVALID",`connect() relays: ${l}`);throw new Error(h)}!$r(i)&&Ds(i)!==0&&this.validateNamespaces(i,"requiredNamespaces"),!$r(o)&&Ds(o)!==0&&this.validateNamespaces(o,"optionalNamespaces"),$r(c)||this.validateSessionProps(c,"sessionProperties")},this.validateNamespaces=(r,n)=>{const i=Ob(r,"connect()",n);if(i)throw new Error(i.message)},this.isValidApprove=async r=>{if(!Hr(r))throw new Error(_e("MISSING_OR_INVALID",`approve() params: ${r}`).message);const{id:n,namespaces:i,relayProtocol:o,sessionProperties:c}=r;await this.isValidProposalId(n);const l=this.client.proposal.get(n),h=Ya(i,"approve()");if(h)throw new Error(h.message);const d=F1(l.requiredNamespaces,i,"approve()");if(d)throw new Error(d.message);if(!dr(o,!0)){const{message:v}=_e("MISSING_OR_INVALID",`approve() relayProtocol: ${o}`);throw new Error(v)}$r(c)||this.validateSessionProps(c,"sessionProperties")},this.isValidReject=async r=>{if(!Hr(r)){const{message:o}=_e("MISSING_OR_INVALID",`reject() params: ${r}`);throw new Error(o)}const{id:n,reason:i}=r;if(await this.isValidProposalId(n),!$b(i)){const{message:o}=_e("MISSING_OR_INVALID",`reject() reason: ${JSON.stringify(i)}`);throw new Error(o)}},this.isValidSessionSettleRequest=r=>{if(!Hr(r)){const{message:d}=_e("MISSING_OR_INVALID",`onSessionSettleRequest() params: ${r}`);throw new Error(d)}const{relay:n,controller:i,namespaces:o,expiry:c}=r;if(!U1(n)){const{message:d}=_e("MISSING_OR_INVALID","onSessionSettleRequest() relay protocol should be a string");throw new Error(d)}const l=_b(i,"onSessionSettleRequest()");if(l)throw new Error(l.message);const h=Ya(o,"onSessionSettleRequest()");if(h)throw new Error(h.message);if(li(c)){const{message:d}=_e("EXPIRED","onSessionSettleRequest()");throw new Error(d)}},this.isValidUpdate=async r=>{if(!Hr(r)){const{message:h}=_e("MISSING_OR_INVALID",`update() params: ${r}`);throw new Error(h)}const{topic:n,namespaces:i}=r;await this.isValidSessionTopic(n);const o=this.client.session.get(n),c=Ya(i,"update()");if(c)throw new Error(c.message);const l=F1(o.requiredNamespaces,i,"update()");if(l)throw new Error(l.message)},this.isValidExtend=async r=>{if(!Hr(r)){const{message:i}=_e("MISSING_OR_INVALID",`extend() params: ${r}`);throw new Error(i)}const{topic:n}=r;await this.isValidSessionTopic(n)},this.isValidRequest=async r=>{if(!Hr(r)){const{message:h}=_e("MISSING_OR_INVALID",`request() params: ${r}`);throw new Error(h)}const{topic:n,request:i,chainId:o,expiry:c}=r;await this.isValidSessionTopic(n);const{namespaces:l}=this.client.session.get(n);if(!j1(l,o)){const{message:h}=_e("MISSING_OR_INVALID",`request() chainId: ${o}`);throw new Error(h)}if(!Pb(i)){const{message:h}=_e("MISSING_OR_INVALID",`request() ${JSON.stringify(i)}`);throw new Error(h)}if(!Nb(l,o,i.method)){const{message:h}=_e("MISSING_OR_INVALID",`request() method: ${i.method}`);throw new Error(h)}if(c&&!jb(c,uh)){const{message:h}=_e("MISSING_OR_INVALID",`request() expiry: ${c}. Expiry must be a number (in seconds) between ${uh.min} and ${uh.max}`);throw new Error(h)}},this.isValidRespond=async r=>{if(!Hr(r)){const{message:o}=_e("MISSING_OR_INVALID",`respond() params: ${r}`);throw new Error(o)}const{topic:n,response:i}=r;if(await this.isValidSessionTopic(n),!Tb(i)){const{message:o}=_e("MISSING_OR_INVALID",`respond() response: ${JSON.stringify(i)}`);throw new Error(o)}},this.isValidPing=async r=>{if(!Hr(r)){const{message:i}=_e("MISSING_OR_INVALID",`ping() params: ${r}`);throw new Error(i)}const{topic:n}=r;await this.isValidSessionOrPairingTopic(n)},this.isValidEmit=async r=>{if(!Hr(r)){const{message:l}=_e("MISSING_OR_INVALID",`emit() params: ${r}`);throw new Error(l)}const{topic:n,event:i,chainId:o}=r;await this.isValidSessionTopic(n);const{namespaces:c}=this.client.session.get(n);if(!j1(c,o)){const{message:l}=_e("MISSING_OR_INVALID",`emit() chainId: ${o}`);throw new Error(l)}if(!Rb(i)){const{message:l}=_e("MISSING_OR_INVALID",`emit() event: ${JSON.stringify(i)}`);throw new Error(l)}if(!Lb(c,o,i.name)){const{message:l}=_e("MISSING_OR_INVALID",`emit() event: ${JSON.stringify(i)}`);throw new Error(l)}},this.isValidDisconnect=async r=>{if(!Hr(r)){const{message:i}=_e("MISSING_OR_INVALID",`disconnect() params: ${r}`);throw new Error(i)}const{topic:n}=r;await this.isValidSessionOrPairingTopic(n)},this.getVerifyContext=async(r,n)=>{const i={verified:{verifyUrl:n.verifyUrl||"",validation:"UNKNOWN",origin:n.url||""}};try{const o=await this.client.core.verify.resolve({attestationId:r,verifyUrl:n.verifyUrl});o&&(i.verified.origin=o,i.verified.validation=o===n.url?"VALID":"INVALID")}catch(o){this.client.logger.error(o)}return this.client.logger.info(`Verify context: ${JSON.stringify(i)}`),i},this.validateSessionProps=(r,n)=>{Object.values(r).forEach(i=>{if(!dr(i,!1)){const{message:o}=_e("MISSING_OR_INVALID",`${n} must be in Record<string, string> format. Received: ${JSON.stringify(i)}`);throw new Error(o)}})}}isInitialized(){if(!this.initialized){const{message:e}=_e("NOT_INITIALIZED",this.name);throw new Error(e)}}registerRelayerEvents(){this.client.core.relayer.on(pr.message,async e=>{const{topic:r,message:n}=e;if(this.ignoredPayloadTypes.includes(this.client.core.crypto.getPayloadType(n)))return;const i=await this.client.core.crypto.decode(r,n);Xu(i)?(this.client.core.history.set(r,i),this.onRelayEventRequest({topic:r,payload:i})):Qu(i)&&(await this.client.core.history.resolve(i),this.onRelayEventResponse({topic:r,payload:i}))})}registerExpirerEvents(){this.client.core.expirer.on(sn.expired,async e=>{const{topic:r,id:n}=P1(e.target);if(n&&this.client.pendingRequest.keys.includes(n))return await this.deletePendingSessionRequest(n,_e("EXPIRED"),!0);r?this.client.session.keys.includes(r)&&(await this.deleteSession(r,!0),this.client.events.emit("session_expire",{topic:r})):n&&(await this.deleteProposal(n,!0),this.client.events.emit("proposal_expire",{id:n}))})}isValidPairingTopic(e){if(!dr(e,!1)){const{message:r}=_e("MISSING_OR_INVALID",`pairing topic should be a string: ${e}`);throw new Error(r)}if(!this.client.core.pairing.pairings.keys.includes(e)){const{message:r}=_e("NO_MATCHING_KEY",`pairing topic doesn't exist: ${e}`);throw new Error(r)}if(li(this.client.core.pairing.pairings.get(e).expiry)){const{message:r}=_e("EXPIRED",`pairing topic: ${e}`);throw new Error(r)}}async isValidSessionTopic(e){if(!dr(e,!1)){const{message:r}=_e("MISSING_OR_INVALID",`session topic should be a string: ${e}`);throw new Error(r)}if(!this.client.session.keys.includes(e)){const{message:r}=_e("NO_MATCHING_KEY",`session topic doesn't exist: ${e}`);throw new Error(r)}if(li(this.client.session.get(e).expiry)){await this.deleteSession(e);const{message:r}=_e("EXPIRED",`session topic: ${e}`);throw new Error(r)}}async isValidSessionOrPairingTopic(e){if(this.client.session.keys.includes(e))await this.isValidSessionTopic(e);else if(this.client.core.pairing.pairings.keys.includes(e))this.isValidPairingTopic(e);else if(dr(e,!1)){const{message:r}=_e("NO_MATCHING_KEY",`session or pairing topic doesn't exist: ${e}`);throw new Error(r)}else{const{message:r}=_e("MISSING_OR_INVALID",`session or pairing topic should be a string: ${e}`);throw new Error(r)}}async isValidProposalId(e){if(!Db(e)){const{message:r}=_e("MISSING_OR_INVALID",`proposal id should be a number: ${e}`);throw new Error(r)}if(!this.client.proposal.keys.includes(e)){const{message:r}=_e("NO_MATCHING_KEY",`proposal id doesn't exist: ${e}`);throw new Error(r)}if(li(this.client.proposal.get(e).expiry)){await this.deleteProposal(e);const{message:r}=_e("EXPIRED",`proposal id: ${e}`);throw new Error(r)}}}class a7 extends nc{constructor(e,r){super(e,r,YE,ch),this.core=e,this.logger=r}}class c7 extends nc{constructor(e,r){super(e,r,JE,ch),this.core=e,this.logger=r}}class l7 extends nc{constructor(e,r){super(e,r,QE,ch,n=>n.id),this.core=e,this.logger=r}}class fh extends v4{constructor(e){super(e),this.protocol=lg,this.version=ug,this.name=lh.name,this.events=new yr.exports.EventEmitter,this.on=(n,i)=>this.events.on(n,i),this.once=(n,i)=>this.events.once(n,i),this.off=(n,i)=>this.events.off(n,i),this.removeListener=(n,i)=>this.events.removeListener(n,i),this.removeAllListeners=n=>this.events.removeAllListeners(n),this.connect=async n=>{try{return await this.engine.connect(n)}catch(i){throw this.logger.error(i.message),i}},this.pair=async n=>{try{return await this.engine.pair(n)}catch(i){throw this.logger.error(i.message),i}},this.approve=async n=>{try{return await this.engine.approve(n)}catch(i){throw this.logger.error(i.message),i}},this.reject=async n=>{try{return await this.engine.reject(n)}catch(i){throw this.logger.error(i.message),i}},this.update=async n=>{try{return await this.engine.update(n)}catch(i){throw this.logger.error(i.message),i}},this.extend=async n=>{try{return await this.engine.extend(n)}catch(i){throw this.logger.error(i.message),i}},this.request=async n=>{try{return await this.engine.request(n)}catch(i){throw this.logger.error(i.message),i}},this.respond=async n=>{try{return await this.engine.respond(n)}catch(i){throw this.logger.error(i.message),i}},this.ping=async n=>{try{return await this.engine.ping(n)}catch(i){throw this.logger.error(i.message),i}},this.emit=async n=>{try{return await this.engine.emit(n)}catch(i){throw this.logger.error(i.message),i}},this.disconnect=async n=>{try{return await this.engine.disconnect(n)}catch(i){throw this.logger.error(i.message),i}},this.find=n=>{try{return this.engine.find(n)}catch(i){throw this.logger.error(i.message),i}},this.getPendingSessionRequests=()=>{try{return this.engine.getPendingSessionRequests()}catch(n){throw this.logger.error(n.message),n}},this.name=e?.name||lh.name,this.metadata=e?.metadata||G5();const r=typeof e?.logger<"u"&&typeof e?.logger!="string"?e.logger:pt.pino(pt.getDefaultLoggerOptions({level:e?.logger||lh.logger}));this.core=e?.core||new ZE(e),this.logger=pt.generateChildLogger(r,this.name),this.session=new c7(this.core,this.logger),this.proposal=new a7(this.core,this.logger),this.pendingRequest=new l7(this.core,this.logger),this.engine=new o7(this)}static async init(e){const r=new fh(e);return await r.initialize(),r}get context(){return pt.getLoggerContext(this.logger)}get pairing(){return this.core.pairing.pairings}async initialize(){this.logger.trace("Initialized");try{await this.core.start(),await this.session.init(),await this.proposal.init(),await this.pendingRequest.init(),await this.engine.init(),this.core.verify.init({verifyUrl:this.metadata.verifyUrl}),this.logger.info("SignClient Initialization Success")}catch(e){throw this.logger.info("SignClient Initialization Failure"),this.logger.error(e.message),e}}}var dh={exports:{}};(function(t,e){var r=typeof self<"u"?self:fr,n=function(){function o(){this.fetch=!1,this.DOMException=r.DOMException}return o.prototype=r,new o}();(function(o){(function(c){var l={searchParams:"URLSearchParams"in o,iterable:"Symbol"in o&&"iterator"in Symbol,blob:"FileReader"in o&&"Blob"in o&&function(){try{return new Blob,!0}catch{return!1}}(),formData:"FormData"in o,arrayBuffer:"ArrayBuffer"in o};function h(S){return S&&DataView.prototype.isPrototypeOf(S)}if(l.arrayBuffer)var d=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],v=ArrayBuffer.isView||function(S){return S&&d.indexOf(Object.prototype.toString.call(S))>-1};function E(S){if(typeof S!="string"&&(S=String(S)),/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(S))throw new TypeError("Invalid character in header field name");return S.toLowerCase()}function _(S){return typeof S!="string"&&(S=String(S)),S}function O(S){var j={next:function(){var ce=S.shift();return{done:ce===void 0,value:ce}}};return l.iterable&&(j[Symbol.iterator]=function(){return j}),j}function P(S){this.map={},S instanceof P?S.forEach(function(j,ce){this.append(ce,j)},this):Array.isArray(S)?S.forEach(function(j){this.append(j[0],j[1])},this):S&&Object.getOwnPropertyNames(S).forEach(function(j){this.append(j,S[j])},this)}P.prototype.append=function(S,j){S=E(S),j=_(j);var ce=this.map[S];this.map[S]=ce?ce+", "+j:j},P.prototype.delete=function(S){delete this.map[E(S)]},P.prototype.get=function(S){return S=E(S),this.has(S)?this.map[S]:null},P.prototype.has=function(S){return this.map.hasOwnProperty(E(S))},P.prototype.set=function(S,j){this.map[E(S)]=_(j)},P.prototype.forEach=function(S,j){for(var ce in this.map)this.map.hasOwnProperty(ce)&&S.call(j,this.map[ce],ce,this)},P.prototype.keys=function(){var S=[];return this.forEach(function(j,ce){S.push(ce)}),O(S)},P.prototype.values=function(){var S=[];return this.forEach(function(j){S.push(j)}),O(S)},P.prototype.entries=function(){var S=[];return this.forEach(function(j,ce){S.push([ce,j])}),O(S)},l.iterable&&(P.prototype[Symbol.iterator]=P.prototype.entries);function U(S){if(S.bodyUsed)return Promise.reject(new TypeError("Already read"));S.bodyUsed=!0}function H(S){return new Promise(function(j,ce){S.onload=function(){j(S.result)},S.onerror=function(){ce(S.error)}})}function G(S){var j=new FileReader,ce=H(j);return j.readAsArrayBuffer(S),ce}function N(S){var j=new FileReader,ce=H(j);return j.readAsText(S),ce}function L(S){for(var j=new Uint8Array(S),ce=new Array(j.length),le=0;le<j.length;le++)ce[le]=String.fromCharCode(j[le]);return ce.join("")}function $(S){if(S.slice)return S.slice(0);var j=new Uint8Array(S.byteLength);return j.set(new Uint8Array(S)),j.buffer}function T(){return this.bodyUsed=!1,this._initBody=function(S){this._bodyInit=S,S?typeof S=="string"?this._bodyText=S:l.blob&&Blob.prototype.isPrototypeOf(S)?this._bodyBlob=S:l.formData&&FormData.prototype.isPrototypeOf(S)?this._bodyFormData=S:l.searchParams&&URLSearchParams.prototype.isPrototypeOf(S)?this._bodyText=S.toString():l.arrayBuffer&&l.blob&&h(S)?(this._bodyArrayBuffer=$(S.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):l.arrayBuffer&&(ArrayBuffer.prototype.isPrototypeOf(S)||v(S))?this._bodyArrayBuffer=$(S):this._bodyText=S=Object.prototype.toString.call(S):this._bodyText="",this.headers.get("content-type")||(typeof S=="string"?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):l.searchParams&&URLSearchParams.prototype.isPrototypeOf(S)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},l.blob&&(this.blob=function(){var S=U(this);if(S)return S;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){return this._bodyArrayBuffer?U(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(G)}),this.text=function(){var S=U(this);if(S)return S;if(this._bodyBlob)return N(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(L(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},l.formData&&(this.formData=function(){return this.text().then(J)}),this.json=function(){return this.text().then(JSON.parse)},this}var I=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function f(S){var j=S.toUpperCase();return I.indexOf(j)>-1?j:S}function x(S,j){j=j||{};var ce=j.body;if(S instanceof x){if(S.bodyUsed)throw new TypeError("Already read");this.url=S.url,this.credentials=S.credentials,j.headers||(this.headers=new P(S.headers)),this.method=S.method,this.mode=S.mode,this.signal=S.signal,!ce&&S._bodyInit!=null&&(ce=S._bodyInit,S.bodyUsed=!0)}else this.url=String(S);if(this.credentials=j.credentials||this.credentials||"same-origin",(j.headers||!this.headers)&&(this.headers=new P(j.headers)),this.method=f(j.method||this.method||"GET"),this.mode=j.mode||this.mode||null,this.signal=j.signal||this.signal,this.referrer=null,(this.method==="GET"||this.method==="HEAD")&&ce)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(ce)}x.prototype.clone=function(){return new x(this,{body:this._bodyInit})};function J(S){var j=new FormData;return S.trim().split("&").forEach(function(ce){if(ce){var le=ce.split("="),re=le.shift().replace(/\+/g," "),ne=le.join("=").replace(/\+/g," ");j.append(decodeURIComponent(re),decodeURIComponent(ne))}}),j}function z(S){var j=new P,ce=S.replace(/\r?\n[\t ]+/g," ");return ce.split(/\r?\n/).forEach(function(le){var re=le.split(":"),ne=re.shift().trim();if(ne){var ae=re.join(":").trim();j.append(ne,ae)}}),j}T.call(x.prototype);function ee(S,j){j||(j={}),this.type="default",this.status=j.status===void 0?200:j.status,this.ok=this.status>=200&&this.status<300,this.statusText="statusText"in j?j.statusText:"OK",this.headers=new P(j.headers),this.url=j.url||"",this._initBody(S)}T.call(ee.prototype),ee.prototype.clone=function(){return new ee(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new P(this.headers),url:this.url})},ee.error=function(){var S=new ee(null,{status:0,statusText:""});return S.type="error",S};var de=[301,302,303,307,308];ee.redirect=function(S,j){if(de.indexOf(j)===-1)throw new RangeError("Invalid status code");return new ee(null,{status:j,headers:{location:S}})},c.DOMException=o.DOMException;try{new c.DOMException}catch{c.DOMException=function(j,ce){this.message=j,this.name=ce;var le=Error(j);this.stack=le.stack},c.DOMException.prototype=Object.create(Error.prototype),c.DOMException.prototype.constructor=c.DOMException}function me(S,j){return new Promise(function(ce,le){var re=new x(S,j);if(re.signal&&re.signal.aborted)return le(new c.DOMException("Aborted","AbortError"));var ne=new XMLHttpRequest;function ae(){ne.abort()}ne.onload=function(){var ie={status:ne.status,statusText:ne.statusText,headers:z(ne.getAllResponseHeaders()||"")};ie.url="responseURL"in ne?ne.responseURL:ie.headers.get("X-Request-URL");var Ae="response"in ne?ne.response:ne.responseText;ce(new ee(Ae,ie))},ne.onerror=function(){le(new TypeError("Network request failed"))},ne.ontimeout=function(){le(new TypeError("Network request failed"))},ne.onabort=function(){le(new c.DOMException("Aborted","AbortError"))},ne.open(re.method,re.url,!0),re.credentials==="include"?ne.withCredentials=!0:re.credentials==="omit"&&(ne.withCredentials=!1),"responseType"in ne&&l.blob&&(ne.responseType="blob"),re.headers.forEach(function(ie,Ae){ne.setRequestHeader(Ae,ie)}),re.signal&&(re.signal.addEventListener("abort",ae),ne.onreadystatechange=function(){ne.readyState===4&&re.signal.removeEventListener("abort",ae)}),ne.send(typeof re._bodyInit>"u"?null:re._bodyInit)})}return me.polyfill=!0,o.fetch||(o.fetch=me,o.Headers=P,o.Request=x,o.Response=ee),c.Headers=P,c.Request=x,c.Response=ee,c.fetch=me,Object.defineProperty(c,"__esModule",{value:!0}),c})({})})(n),n.fetch.ponyfill=!0,delete n.fetch.polyfill;var i=n;e=i.fetch,e.default=i.fetch,e.fetch=i.fetch,e.Headers=i.Headers,e.Request=i.Request,e.Response=i.Response,t.exports=e})(dh,dh.exports);var gg=hw(dh.exports);const mg={headers:{Accept:"application/json","Content-Type":"application/json"},method:"POST"},wg=10;class Vi{constructor(e){if(this.url=e,this.events=new yr.exports.EventEmitter,this.isAvailable=!1,this.registering=!1,!Ip(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,r){this.events.on(e,r)}once(e,r){this.events.once(e,r)}off(e,r){this.events.off(e,r)}removeListener(e,r){this.events.removeListener(e,r)}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,r){this.isAvailable||await this.register();try{const n=Mo(e),o=await(await gg(this.url,Object.assign(Object.assign({},mg),{body:n}))).json();this.onPayload({data:o})}catch(n){this.onError(e.id,n)}}async register(e=this.url){if(!Ip(e))throw new Error(`Provided URL is not compatible with HTTP connection: ${e}`);if(this.registering){const r=this.events.getMaxListeners();return(this.events.listenerCount("register_error")>=r||this.events.listenerCount("open")>=r)&&this.events.setMaxListeners(r+1),new Promise((n,i)=>{this.events.once("register_error",o=>{this.resetMaxListeners(),i(o)}),this.events.once("open",()=>{if(this.resetMaxListeners(),typeof this.isAvailable>"u")return i(new Error("HTTP connection is missing or invalid"));n()})})}this.url=e,this.registering=!0;try{const r=Mo({id:1,jsonrpc:"2.0",method:"test",params:[]});await gg(e,Object.assign(Object.assign({},mg),{body:r})),this.onOpen()}catch(r){const n=this.parseError(r);throw this.events.emit("register_error",n),this.onClose(),n}}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(typeof e.data>"u")return;const r=typeof e.data=="string"?qu(e.data):e.data;this.events.emit("payload",r)}onError(e,r){const n=this.parseError(r),i=n.message||n.toString(),o=tc(e,i);this.events.emit("payload",o)}parseError(e,r=this.url){return vp(e,r,"HTTP")}resetMaxListeners(){this.events.getMaxListeners()>wg&&this.events.setMaxListeners(wg)}}const vg="error",u7="wss://relay.walletconnect.com",h7="wc",f7="universal_provider",yg=`${h7}@${2}:${f7}:`,d7="https://rpc.walletconnect.com/v1",fi={DEFAULT_CHAIN_CHANGED:"default_chain_changed"};var Wo=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},ph={exports:{}};/**
|
|
73
73
|
* @license
|
|
74
74
|
* Lodash <https://lodash.com/>
|
|
75
75
|
* Copyright OpenJS Foundation and other contributors <https://openjsf.org/>
|
|
@@ -95,7 +95,7 @@ __p += '`),wt&&(pe+=`' +
|
|
|
95
95
|
function print() { __p += __j.call(arguments, '') }
|
|
96
96
|
`:`;
|
|
97
97
|
`)+pe+`return __p
|
|
98
|
-
}`;var ot=cw(function(){return vt(A,Pe+"return "+pe).apply(r,M)});if(ot.source=pe,Y0(ot))throw ot;return ot}function FR(s){return yt(s).toLowerCase()}function BR(s){return yt(s).toUpperCase()}function kR(s,a,u){if(s=yt(s),s&&(u||a===r))return wm(s);if(!s||!(a=en(a)))return s;var g=Cn(s),y=Cn(a),A=vm(g,y),M=ym(g,y)+1;return Ri(g,A,M).join("")}function HR(s,a,u){if(s=yt(s),s&&(u||a===r))return s.slice(0,_m(s)+1);if(!s||!(a=en(a)))return s;var g=Cn(s),y=ym(g,Cn(a))+1;return Ri(g,0,y).join("")}function zR(s,a,u){if(s=yt(s),s&&(u||a===r))return s.replace(Vt,"");if(!s||!(a=en(a)))return s;var g=Cn(s),y=vm(g,Cn(a));return Ri(g,y).join("")}function WR(s,a){var u=z,g=ee;if(Bt(a)){var y="separator"in a?a.separator:y;u="length"in a?it(a.length):u,g="omission"in a?en(a.omission):g}s=yt(s);var A=s.length;if(oo(s)){var M=Cn(s);A=M.length}if(u>=A)return s;var k=u-ao(g);if(k<1)return g;var Z=M?Ri(M,0,k).join(""):s.slice(0,k);if(y===r)return Z+g;if(M&&(k+=Z.length-k),J0(y)){if(s.slice(k).search(y)){var ue,he=Z;for(y.global||(y=d0(y.source,yt(hn.exec(y))+"g")),y.lastIndex=0;ue=y.exec(he);)var pe=ue.index;Z=Z.slice(0,pe===r?k:pe)}}else if(s.indexOf(en(y),k)!=k){var be=Z.lastIndexOf(y);be>-1&&(Z=Z.slice(0,be))}return Z+g}function qR(s){return s=yt(s),s&&Ht.test(s)?s.replace(Ci,bA):s}var VR=go(function(s,a,u){return s+(u?" ":"")+a.toUpperCase()}),ed=l2("toUpperCase");function aw(s,a,u){return s=yt(s),a=u?r:a,a===r?gA(s)?xA(s):oA(s):s.match(a)||[]}var cw=ct(function(s,a){try{return wr(s,r,a)}catch(u){return Y0(u)?u:new Ye(u)}}),KR=ni(function(s,a){return dn(a,function(u){u=kn(u),ti(s,u,G0(s[u],s))}),s});function GR(s){var a=s==null?0:s.length,u=ze();return s=a?Ut(s,function(g){if(typeof g[1]!="function")throw new pn(c);return[u(g[0]),g[1]]}):[],ct(function(g){for(var y=-1;++y<a;){var A=s[y];if(wr(A[0],this,g))return wr(A[1],this,g)}})}function ZR(s){return bD(mn(s,E))}function td(s){return function(){return s}}function YR(s,a){return s==null||s!==s?a:s}var JR=h2(),XR=h2(!0);function Gr(s){return s}function rd(s){return km(typeof s=="function"?s:mn(s,E))}function QR(s){return zm(mn(s,E))}function eN(s,a){return Wm(s,mn(a,E))}var tN=ct(function(s,a){return function(u){return Aa(u,s,a)}}),rN=ct(function(s,a){return function(u){return Aa(s,u,a)}});function nd(s,a,u){var g=vr(a),y=Pl(a,g);u==null&&!(Bt(a)&&(y.length||!g.length))&&(u=a,a=s,s=this,y=Pl(a,vr(a)));var A=!(Bt(u)&&"chain"in u)||!!u.chain,M=si(s);return dn(y,function(k){var Z=a[k];s[k]=Z,M&&(s.prototype[k]=function(){var ue=this.__chain__;if(A||ue){var he=s(this.__wrapped__),pe=he.__actions__=qr(this.__actions__);return pe.push({func:Z,args:arguments,thisArg:s}),he.__chain__=ue,he}return Z.apply(s,Oi([this.value()],arguments))})}),s}function nN(){return mt._===this&&(mt._=DA),this}function id(){}function iN(s){return s=it(s),ct(function(a){return qm(a,s)})}var sN=L0(Ut),oN=L0(fm),aN=L0(o0);function lw(s){return H0(s)?a0(kn(s)):UD(s)}function cN(s){return function(a){return s==null?r:ys(s,a)}}var lN=d2(),uN=d2(!0);function sd(){return[]}function od(){return!1}function hN(){return{}}function fN(){return""}function dN(){return!0}function pN(s,a){if(s=it(s),s<1||s>re)return[];var u=ie,g=Sr(s,ie);a=ze(a),s-=ie;for(var y=u0(g,a);++u<s;)a(u);return y}function gN(s){return Qe(s)?Ut(s,kn):tn(s)?[s]:qr(D2(yt(s)))}function mN(s){var a=++OA;return yt(s)+a}var wN=Ul(function(s,a){return s+a},0),vN=M0("ceil"),yN=Ul(function(s,a){return s/a},1),bN=M0("floor");function _N(s){return s&&s.length?$l(s,Gr,_0):r}function EN(s,a){return s&&s.length?$l(s,ze(a,2),_0):r}function xN(s){return gm(s,Gr)}function CN(s,a){return gm(s,ze(a,2))}function IN(s){return s&&s.length?$l(s,Gr,I0):r}function SN(s,a){return s&&s.length?$l(s,ze(a,2),I0):r}var ON=Ul(function(s,a){return s*a},1),AN=M0("round"),DN=Ul(function(s,a){return s-a},0);function $N(s){return s&&s.length?l0(s,Gr):0}function PN(s,a){return s&&s.length?l0(s,ze(a,2)):0}return C.after=QP,C.ary=B2,C.assign=BT,C.assignIn=ew,C.assignInWith=Yl,C.assignWith=kT,C.at=HT,C.before=k2,C.bind=G0,C.bindAll=KR,C.bindKey=H2,C.castArray=hT,C.chain=U2,C.chunk=b$,C.compact=_$,C.concat=E$,C.cond=GR,C.conforms=ZR,C.constant=td,C.countBy=$P,C.create=zT,C.curry=z2,C.curryRight=W2,C.debounce=q2,C.defaults=WT,C.defaultsDeep=qT,C.defer=eT,C.delay=tT,C.difference=x$,C.differenceBy=C$,C.differenceWith=I$,C.drop=S$,C.dropRight=O$,C.dropRightWhile=A$,C.dropWhile=D$,C.fill=$$,C.filter=TP,C.flatMap=LP,C.flatMapDeep=MP,C.flatMapDepth=UP,C.flatten=R2,C.flattenDeep=P$,C.flattenDepth=T$,C.flip=rT,C.flow=JR,C.flowRight=XR,C.fromPairs=R$,C.functions=XT,C.functionsIn=QT,C.groupBy=jP,C.initial=L$,C.intersection=M$,C.intersectionBy=U$,C.intersectionWith=j$,C.invert=tR,C.invertBy=rR,C.invokeMap=BP,C.iteratee=rd,C.keyBy=kP,C.keys=vr,C.keysIn=Kr,C.map=Wl,C.mapKeys=iR,C.mapValues=sR,C.matches=QR,C.matchesProperty=eN,C.memoize=Vl,C.merge=oR,C.mergeWith=tw,C.method=tN,C.methodOf=rN,C.mixin=nd,C.negate=Kl,C.nthArg=iN,C.omit=aR,C.omitBy=cR,C.once=nT,C.orderBy=HP,C.over=sN,C.overArgs=iT,C.overEvery=oN,C.overSome=aN,C.partial=Z0,C.partialRight=V2,C.partition=zP,C.pick=lR,C.pickBy=rw,C.property=lw,C.propertyOf=cN,C.pull=H$,C.pullAll=L2,C.pullAllBy=z$,C.pullAllWith=W$,C.pullAt=q$,C.range=lN,C.rangeRight=uN,C.rearg=sT,C.reject=VP,C.remove=V$,C.rest=oT,C.reverse=V0,C.sampleSize=GP,C.set=hR,C.setWith=fR,C.shuffle=ZP,C.slice=K$,C.sortBy=XP,C.sortedUniq=eP,C.sortedUniqBy=tP,C.split=LR,C.spread=aT,C.tail=rP,C.take=nP,C.takeRight=iP,C.takeRightWhile=sP,C.takeWhile=oP,C.tap=_P,C.throttle=cT,C.thru=zl,C.toArray=J2,C.toPairs=nw,C.toPairsIn=iw,C.toPath=gN,C.toPlainObject=Q2,C.transform=dR,C.unary=lT,C.union=aP,C.unionBy=cP,C.unionWith=lP,C.uniq=uP,C.uniqBy=hP,C.uniqWith=fP,C.unset=pR,C.unzip=K0,C.unzipWith=M2,C.update=gR,C.updateWith=mR,C.values=vo,C.valuesIn=wR,C.without=dP,C.words=aw,C.wrap=uT,C.xor=pP,C.xorBy=gP,C.xorWith=mP,C.zip=wP,C.zipObject=vP,C.zipObjectDeep=yP,C.zipWith=bP,C.entries=nw,C.entriesIn=iw,C.extend=ew,C.extendWith=Yl,nd(C,C),C.add=wN,C.attempt=cw,C.camelCase=_R,C.capitalize=sw,C.ceil=vN,C.clamp=vR,C.clone=fT,C.cloneDeep=pT,C.cloneDeepWith=gT,C.cloneWith=dT,C.conformsTo=mT,C.deburr=ow,C.defaultTo=YR,C.divide=yN,C.endsWith=ER,C.eq=Sn,C.escape=xR,C.escapeRegExp=CR,C.every=PP,C.find=RP,C.findIndex=P2,C.findKey=VT,C.findLast=NP,C.findLastIndex=T2,C.findLastKey=KT,C.floor=bN,C.forEach=j2,C.forEachRight=F2,C.forIn=GT,C.forInRight=ZT,C.forOwn=YT,C.forOwnRight=JT,C.get=X0,C.gt=wT,C.gte=vT,C.has=eR,C.hasIn=Q0,C.head=N2,C.identity=Gr,C.includes=FP,C.indexOf=N$,C.inRange=yR,C.invoke=nR,C.isArguments=Es,C.isArray=Qe,C.isArrayBuffer=yT,C.isArrayLike=Vr,C.isArrayLikeObject=Xt,C.isBoolean=bT,C.isBuffer=Ni,C.isDate=_T,C.isElement=ET,C.isEmpty=xT,C.isEqual=CT,C.isEqualWith=IT,C.isError=Y0,C.isFinite=ST,C.isFunction=si,C.isInteger=K2,C.isLength=Gl,C.isMap=G2,C.isMatch=OT,C.isMatchWith=AT,C.isNaN=DT,C.isNative=$T,C.isNil=TT,C.isNull=PT,C.isNumber=Z2,C.isObject=Bt,C.isObjectLike=Gt,C.isPlainObject=Na,C.isRegExp=J0,C.isSafeInteger=RT,C.isSet=Y2,C.isString=Zl,C.isSymbol=tn,C.isTypedArray=wo,C.isUndefined=NT,C.isWeakMap=LT,C.isWeakSet=MT,C.join=F$,C.kebabCase=IR,C.last=vn,C.lastIndexOf=B$,C.lowerCase=SR,C.lowerFirst=OR,C.lt=UT,C.lte=jT,C.max=_N,C.maxBy=EN,C.mean=xN,C.meanBy=CN,C.min=IN,C.minBy=SN,C.stubArray=sd,C.stubFalse=od,C.stubObject=hN,C.stubString=fN,C.stubTrue=dN,C.multiply=ON,C.nth=k$,C.noConflict=nN,C.noop=id,C.now=ql,C.pad=AR,C.padEnd=DR,C.padStart=$R,C.parseInt=PR,C.random=bR,C.reduce=WP,C.reduceRight=qP,C.repeat=TR,C.replace=RR,C.result=uR,C.round=AN,C.runInContext=V,C.sample=KP,C.size=YP,C.snakeCase=NR,C.some=JP,C.sortedIndex=G$,C.sortedIndexBy=Z$,C.sortedIndexOf=Y$,C.sortedLastIndex=J$,C.sortedLastIndexBy=X$,C.sortedLastIndexOf=Q$,C.startCase=MR,C.startsWith=UR,C.subtract=DN,C.sum=$N,C.sumBy=PN,C.template=jR,C.times=pN,C.toFinite=oi,C.toInteger=it,C.toLength=X2,C.toLower=FR,C.toNumber=yn,C.toSafeInteger=FT,C.toString=yt,C.toUpper=BR,C.trim=kR,C.trimEnd=HR,C.trimStart=zR,C.truncate=WR,C.unescape=qR,C.uniqueId=mN,C.upperCase=VR,C.upperFirst=ed,C.each=j2,C.eachRight=F2,C.first=N2,nd(C,function(){var s={};return Fn(C,function(a,u){bt.call(C.prototype,u)||(s[u]=a)}),s}(),{chain:!1}),C.VERSION=n,dn(["bind","bindKey","curry","curryRight","partial","partialRight"],function(s){C[s].placeholder=C}),dn(["drop","take"],function(s,a){dt.prototype[s]=function(u){u=u===r?1:hr(it(u),0);var g=this.__filtered__&&!a?new dt(this):this.clone();return g.__filtered__?g.__takeCount__=Sr(u,g.__takeCount__):g.__views__.push({size:Sr(u,ie),type:s+(g.__dir__<0?"Right":"")}),g},dt.prototype[s+"Right"]=function(u){return this.reverse()[s](u).reverse()}}),dn(["filter","map","takeWhile"],function(s,a){var u=a+1,g=u==S||u==ce;dt.prototype[s]=function(y){var A=this.clone();return A.__iteratees__.push({iteratee:ze(y,3),type:u}),A.__filtered__=A.__filtered__||g,A}}),dn(["head","last"],function(s,a){var u="take"+(a?"Right":"");dt.prototype[s]=function(){return this[u](1).value()[0]}}),dn(["initial","tail"],function(s,a){var u="drop"+(a?"":"Right");dt.prototype[s]=function(){return this.__filtered__?new dt(this):this[u](1)}}),dt.prototype.compact=function(){return this.filter(Gr)},dt.prototype.find=function(s){return this.filter(s).head()},dt.prototype.findLast=function(s){return this.reverse().find(s)},dt.prototype.invokeMap=ct(function(s,a){return typeof s=="function"?new dt(this):this.map(function(u){return Aa(u,s,a)})}),dt.prototype.reject=function(s){return this.filter(Kl(ze(s)))},dt.prototype.slice=function(s,a){s=it(s);var u=this;return u.__filtered__&&(s>0||a<0)?new dt(u):(s<0?u=u.takeRight(-s):s&&(u=u.drop(s)),a!==r&&(a=it(a),u=a<0?u.dropRight(-a):u.take(a-s)),u)},dt.prototype.takeRightWhile=function(s){return this.reverse().takeWhile(s).reverse()},dt.prototype.toArray=function(){return this.take(ie)},Fn(dt.prototype,function(s,a){var u=/^(?:filter|find|map|reject)|While$/.test(a),g=/^(?:head|last)$/.test(a),y=C[g?"take"+(a=="last"?"Right":""):a],A=g||/^find/.test(a);y&&(C.prototype[a]=function(){var M=this.__wrapped__,k=g?[1]:arguments,Z=M instanceof dt,ue=k[0],he=Z||Qe(M),pe=function(ft){var wt=y.apply(C,Oi([ft],k));return g&&be?wt[0]:wt};he&&u&&typeof ue=="function"&&ue.length!=1&&(Z=he=!1);var be=this.__chain__,Pe=!!this.__actions__.length,We=A&&!be,ot=Z&&!Pe;if(!A&&he){M=ot?M:new dt(this);var qe=s.apply(M,k);return qe.__actions__.push({func:zl,args:[pe],thisArg:r}),new gn(qe,be)}return We&&ot?s.apply(this,k):(qe=this.thru(pe),We?g?qe.value()[0]:qe.value():qe)})}),dn(["pop","push","shift","sort","splice","unshift"],function(s){var a=gl[s],u=/^(?:push|sort|unshift)$/.test(s)?"tap":"thru",g=/^(?:pop|shift)$/.test(s);C.prototype[s]=function(){var y=arguments;if(g&&!this.__chain__){var A=this.value();return a.apply(Qe(A)?A:[],y)}return this[u](function(M){return a.apply(Qe(M)?M:[],y)})}}),Fn(dt.prototype,function(s,a){var u=C[a];if(u){var g=u.name+"";bt.call(ho,g)||(ho[g]=[]),ho[g].push({name:a,func:u})}}),ho[Ml(r,G).name]=[{name:"wrapper",func:r}],dt.prototype.clone=qA,dt.prototype.reverse=VA,dt.prototype.value=KA,C.prototype.at=EP,C.prototype.chain=xP,C.prototype.commit=CP,C.prototype.next=IP,C.prototype.plant=OP,C.prototype.reverse=AP,C.prototype.toJSON=C.prototype.valueOf=C.prototype.value=DP,C.prototype.first=C.prototype.head,_a&&(C.prototype[_a]=SP),C},co=CA();Jt?((Jt.exports=co)._=co,St._=co):mt._=co}).call(Wo)})(ph,ph.exports);var p7=Object.defineProperty,g7=Object.defineProperties,m7=Object.getOwnPropertyDescriptors,bg=Object.getOwnPropertySymbols,w7=Object.prototype.hasOwnProperty,v7=Object.prototype.propertyIsEnumerable,_g=(t,e,r)=>e in t?p7(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,sc=(t,e)=>{for(var r in e||(e={}))w7.call(e,r)&&_g(t,r,e[r]);if(bg)for(var r of bg(e))v7.call(e,r)&&_g(t,r,e[r]);return t},y7=(t,e)=>g7(t,m7(e));function an(t,e,r){let n;const i=gh(t);return e.rpcMap&&(n=e.rpcMap[i]),n||(n=`${d7}?chainId=eip155:${i}&projectId=${r}`),n}function gh(t){return t.includes("eip155")?Number(t.split(":")[1]):Number(t)}function b7(t,e){if(!e.includes(t))throw new Error(`Chain '${t}' not approved. Please use one of the following: ${e.toString()}`)}function _7(t){return t.map(e=>`${e.split(":")[0]}:${e.split(":")[1]}`)}function E7(t,e){const r=Object.keys(e.namespaces).filter(i=>i.includes(t));if(!r.length)return[];const n=[];return r.forEach(i=>{const o=e.namespaces[i].accounts;n.push(...o)}),n}function x7(t,e={}){const r=Eg(t),n=Eg(e);return ph.exports.merge(r,n)}function Eg(t){var e,r,n,i;const o={};if(!Ds(t))return o;for(const[c,l]of Object.entries(t)){const h=N1(c)?[c]:l.chains,d=l.methods||[],v=l.events||[],E=l.rpcMap||{},_=Za(c);o[_]=y7(sc(sc({},o[_]),l),{chains:Ou(h,(e=o[_])==null?void 0:e.chains),methods:Ou(d,(r=o[_])==null?void 0:r.methods),events:Ou(v,(n=o[_])==null?void 0:n.events),rpcMap:sc(sc({},E),(i=o[_])==null?void 0:i.rpcMap)})}return o}const Ki=(t,e)=>{const r=n=>{n.request!==e.request||n.topic!==e.topic||(t.events.removeListener("session_request_sent",r),C7(e,t.core.storage))};t.on("session_request_sent",r)};async function C7(t,e){try{const r=await e.getItem("WALLETCONNECT_DEEPLINK_CHOICE");if(!r)return;const n=typeof r=="string"?JSON.parse(r):r,i=n?.href;if(typeof i!="string")return;i.endsWith("/")&&i.slice(0,-1);const o=`${i}/wc?requestId=${t.id}&sessionTopic=${t.topic}`,c=O1();c===ki.browser?window.open(o,"_self","noreferrer noopener"):c===ki.reactNative&&typeof(global==null?void 0:global.Linking)<"u"&&await global.Linking.openURL(o)}catch(r){console.error(r)}}class I7{constructor(e){this.name="polkadot",this.namespace=e.namespace,this.events=e.events,this.client=e.client,this.chainId=this.getDefaultChain(),this.httpProviders=this.createHttpProviders()}updateNamespace(e){this.namespace=Object.assign(this.namespace,e)}requestAccounts(){return this.getAccounts()}getDefaultChain(){if(this.chainId)return this.chainId;if(this.namespace.defaultChain)return this.namespace.defaultChain;const e=this.namespace.chains[0];if(!e)throw new Error("ChainId not found");return e.split(":")[1]}request(e){return this.namespace.methods.includes(e.request.method)?(Ki(this.client,e),this.client.request(e)):this.getHttpProvider().request(e.request)}setDefaultChain(e,r){if(this.chainId=e,!this.httpProviders[e]){const n=r||an(`${this.name}:${e}`,this.namespace);if(!n)throw new Error(`No RPC url provided for chainId: ${e}`);this.setHttpProvider(e,n)}this.events.emit(fi.DEFAULT_CHAIN_CHANGED,`${this.name}:${this.chainId}`)}getAccounts(){const e=this.namespace.accounts;return e?e.filter(r=>r.split(":")[1]===this.chainId.toString()).map(r=>r.split(":")[2])||[]:[]}createHttpProviders(){const e={};return this.namespace.chains.forEach(r=>{var n;e[r]=this.createHttpProvider(r,(n=this.namespace.rpcMap)==null?void 0:n[r])}),e}getHttpProvider(){const e=`${this.name}:${this.chainId}`,r=this.httpProviders[e];if(typeof r>"u")throw new Error(`JSON-RPC provider for ${e} not found`);return r}setHttpProvider(e,r){const n=this.createHttpProvider(e,r);n&&(this.httpProviders[e]=n)}createHttpProvider(e,r){const n=r||an(e,this.namespace);return typeof n>"u"?void 0:new ui(new Vi(n))}}class S7{constructor(e){this.name="eip155",this.namespace=e.namespace,this.client=e.client,this.events=e.events,this.httpProviders=this.createHttpProviders(),this.chainId=parseInt(this.getDefaultChain())}async request(e){var r;switch(e.request.method){case"eth_requestAccounts":return this.getAccounts();case"eth_accounts":return this.getAccounts();case"wallet_switchEthereumChain":return this.handleSwitchChain(e.request.params?(r=e.request.params[0])==null?void 0:r.chainId:"0x0"),null;case"eth_chainId":return parseInt(this.getDefaultChain())}return this.namespace.methods.includes(e.request.method)?(Ki(this.client,e),await this.client.request(e)):this.getHttpProvider().request(e.request)}updateNamespace(e){this.namespace=Object.assign(this.namespace,e)}setDefaultChain(e,r){const n=gh(e);if(!this.httpProviders[n]){const i=r||an(`${this.name}:${n}`,this.namespace,this.client.core.projectId);if(!i)throw new Error(`No RPC url provided for chainId: ${n}`);this.setHttpProvider(n,i)}this.chainId=n,this.events.emit(fi.DEFAULT_CHAIN_CHANGED,`${this.name}:${n}`)}requestAccounts(){return this.getAccounts()}getDefaultChain(){if(this.chainId)return this.chainId.toString();if(this.namespace.defaultChain)return this.namespace.defaultChain;const e=this.namespace.chains[0];if(!e)throw new Error("ChainId not found");return e.split(":")[1]}createHttpProvider(e,r){const n=r||an(`${this.name}:${e}`,this.namespace,this.client.core.projectId);return typeof n>"u"?void 0:new ui(new Vi(n))}setHttpProvider(e,r){const n=this.createHttpProvider(e,r);n&&(this.httpProviders[e]=n)}createHttpProviders(){const e={};return this.namespace.chains.forEach(r=>{var n;const i=gh(r);e[i]=this.createHttpProvider(i,(n=this.namespace.rpcMap)==null?void 0:n[r])}),e}getAccounts(){const e=this.namespace.accounts;return e?[...new Set(e.filter(r=>r.split(":")[1]===this.chainId.toString()).map(r=>r.split(":")[2]))]:[]}getHttpProvider(){const e=this.chainId,r=this.httpProviders[e];if(typeof r>"u")throw new Error(`JSON-RPC provider for ${e} not found`);return r}handleSwitchChain(e){const r=parseInt(e,16),n=`${this.name}:${r}`;b7(n,this.namespace.chains),this.setDefaultChain(`${r}`)}}class O7{constructor(e){this.name="solana",this.namespace=e.namespace,this.events=e.events,this.client=e.client,this.chainId=this.getDefaultChain(),this.httpProviders=this.createHttpProviders()}updateNamespace(e){this.namespace=Object.assign(this.namespace,e)}requestAccounts(){return this.getAccounts()}request(e){return this.namespace.methods.includes(e.request.method)?(Ki(this.client,e),this.client.request(e)):this.getHttpProvider().request(e.request)}setDefaultChain(e,r){if(!this.httpProviders[e]){const n=r||an(`${this.name}:${e}`,this.namespace,this.client.core.projectId);if(!n)throw new Error(`No RPC url provided for chainId: ${e}`);this.setHttpProvider(e,n)}this.chainId=e,this.events.emit(fi.DEFAULT_CHAIN_CHANGED,`${this.name}:${this.chainId}`)}getDefaultChain(){if(this.chainId)return this.chainId;if(this.namespace.defaultChain)return this.namespace.defaultChain;const e=this.namespace.chains[0];if(!e)throw new Error("ChainId not found");return e.split(":")[1]}getAccounts(){const e=this.namespace.accounts;return e?[...new Set(e.filter(r=>r.split(":")[1]===this.chainId.toString()).map(r=>r.split(":")[2]))]:[]}createHttpProviders(){const e={};return this.namespace.chains.forEach(r=>{var n;e[r]=this.createHttpProvider(r,(n=this.namespace.rpcMap)==null?void 0:n[r])}),e}getHttpProvider(){const e=`${this.name}:${this.chainId}`,r=this.httpProviders[e];if(typeof r>"u")throw new Error(`JSON-RPC provider for ${e} not found`);return r}setHttpProvider(e,r){const n=this.createHttpProvider(e,r);n&&(this.httpProviders[e]=n)}createHttpProvider(e,r){const n=r||an(e,this.namespace,this.client.core.projectId);return typeof n>"u"?void 0:new ui(new Vi(n))}}class A7{constructor(e){this.name="cosmos",this.namespace=e.namespace,this.events=e.events,this.client=e.client,this.chainId=this.getDefaultChain(),this.httpProviders=this.createHttpProviders()}updateNamespace(e){this.namespace=Object.assign(this.namespace,e)}requestAccounts(){return this.getAccounts()}getDefaultChain(){if(this.chainId)return this.chainId;if(this.namespace.defaultChain)return this.namespace.defaultChain;const e=this.namespace.chains[0];if(!e)throw new Error("ChainId not found");return e.split(":")[1]}request(e){return this.namespace.methods.includes(e.request.method)?(Ki(this.client,e),this.client.request(e)):this.getHttpProvider().request(e.request)}setDefaultChain(e,r){if(this.chainId=e,!this.httpProviders[e]){const n=r||an(`${this.name}:${e}`,this.namespace,this.client.core.projectId);if(!n)throw new Error(`No RPC url provided for chainId: ${e}`);this.setHttpProvider(e,n)}this.events.emit(fi.DEFAULT_CHAIN_CHANGED,`${this.name}:${this.chainId}`)}getAccounts(){const e=this.namespace.accounts;return e?[...new Set(e.filter(r=>r.split(":")[1]===this.chainId.toString()).map(r=>r.split(":")[2]))]:[]}createHttpProviders(){const e={};return this.namespace.chains.forEach(r=>{var n;e[r]=this.createHttpProvider(r,(n=this.namespace.rpcMap)==null?void 0:n[r])}),e}getHttpProvider(){const e=`${this.name}:${this.chainId}`,r=this.httpProviders[e];if(typeof r>"u")throw new Error(`JSON-RPC provider for ${e} not found`);return r}setHttpProvider(e,r){const n=this.createHttpProvider(e,r);n&&(this.httpProviders[e]=n)}createHttpProvider(e,r){const n=r||an(e,this.namespace,this.client.core.projectId);return typeof n>"u"?void 0:new ui(new Vi(n))}}class D7{constructor(e){this.name="cip34",this.namespace=e.namespace,this.events=e.events,this.client=e.client,this.chainId=this.getDefaultChain(),this.httpProviders=this.createHttpProviders()}updateNamespace(e){this.namespace=Object.assign(this.namespace,e)}requestAccounts(){return this.getAccounts()}getDefaultChain(){if(this.chainId)return this.chainId;if(this.namespace.defaultChain)return this.namespace.defaultChain;const e=this.namespace.chains[0];if(!e)throw new Error("ChainId not found");return e.split(":")[1]}request(e){return this.namespace.methods.includes(e.request.method)?(Ki(this.client,e),this.client.request(e)):this.getHttpProvider().request(e.request)}setDefaultChain(e,r){if(this.chainId=e,!this.httpProviders[e]){const n=r||this.getCardanoRPCUrl(e);if(!n)throw new Error(`No RPC url provided for chainId: ${e}`);this.setHttpProvider(e,n)}this.events.emit(fi.DEFAULT_CHAIN_CHANGED,`${this.name}:${this.chainId}`)}getAccounts(){const e=this.namespace.accounts;return e?[...new Set(e.filter(r=>r.split(":")[1]===this.chainId.toString()).map(r=>r.split(":")[2]))]:[]}createHttpProviders(){const e={};return this.namespace.chains.forEach(r=>{const n=this.getCardanoRPCUrl(r);e[r]=this.createHttpProvider(r,n)}),e}getHttpProvider(){const e=`${this.name}:${this.chainId}`,r=this.httpProviders[e];if(typeof r>"u")throw new Error(`JSON-RPC provider for ${e} not found`);return r}getCardanoRPCUrl(e){const r=this.namespace.rpcMap;if(r)return r[e]}setHttpProvider(e,r){const n=this.createHttpProvider(e,r);n&&(this.httpProviders[e]=n)}createHttpProvider(e,r){const n=r||this.getCardanoRPCUrl(e);return typeof n>"u"?void 0:new ui(new Vi(n))}}class $7{constructor(e){this.name="elrond",this.namespace=e.namespace,this.events=e.events,this.client=e.client,this.chainId=this.getDefaultChain(),this.httpProviders=this.createHttpProviders()}updateNamespace(e){this.namespace=Object.assign(this.namespace,e)}requestAccounts(){return this.getAccounts()}request(e){return this.namespace.methods.includes(e.request.method)?(Ki(this.client,e),this.client.request(e)):this.getHttpProvider().request(e.request)}setDefaultChain(e,r){if(!this.httpProviders[e]){const n=r||an(`${this.name}:${e}`,this.namespace,this.client.core.projectId);if(!n)throw new Error(`No RPC url provided for chainId: ${e}`);this.setHttpProvider(e,n)}this.chainId=e,this.events.emit(fi.DEFAULT_CHAIN_CHANGED,`${this.name}:${this.chainId}`)}getDefaultChain(){if(this.chainId)return this.chainId;if(this.namespace.defaultChain)return this.namespace.defaultChain;const e=this.namespace.chains[0];if(!e)throw new Error("ChainId not found");return e.split(":")[1]}getAccounts(){const e=this.namespace.accounts;return e?[...new Set(e.filter(r=>r.split(":")[1]===this.chainId.toString()).map(r=>r.split(":")[2]))]:[]}createHttpProviders(){const e={};return this.namespace.chains.forEach(r=>{var n;e[r]=this.createHttpProvider(r,(n=this.namespace.rpcMap)==null?void 0:n[r])}),e}getHttpProvider(){const e=`${this.name}:${this.chainId}`,r=this.httpProviders[e];if(typeof r>"u")throw new Error(`JSON-RPC provider for ${e} not found`);return r}setHttpProvider(e,r){const n=this.createHttpProvider(e,r);n&&(this.httpProviders[e]=n)}createHttpProvider(e,r){const n=r||an(e,this.namespace,this.client.core.projectId);return typeof n>"u"?void 0:new ui(new Vi(n))}}class P7{constructor(e){this.name="multiversx",this.namespace=e.namespace,this.events=e.events,this.client=e.client,this.chainId=this.getDefaultChain(),this.httpProviders=this.createHttpProviders()}updateNamespace(e){this.namespace=Object.assign(this.namespace,e)}requestAccounts(){return this.getAccounts()}request(e){return this.namespace.methods.includes(e.request.method)?(Ki(this.client,e),this.client.request(e)):this.getHttpProvider().request(e.request)}setDefaultChain(e,r){if(!this.httpProviders[e]){const n=r||an(`${this.name}:${e}`,this.namespace,this.client.core.projectId);if(!n)throw new Error(`No RPC url provided for chainId: ${e}`);this.setHttpProvider(e,n)}this.chainId=e,this.events.emit(fi.DEFAULT_CHAIN_CHANGED,`${this.name}:${this.chainId}`)}getDefaultChain(){if(this.chainId)return this.chainId;if(this.namespace.defaultChain)return this.namespace.defaultChain;const e=this.namespace.chains[0];if(!e)throw new Error("ChainId not found");return e.split(":")[1]}getAccounts(){const e=this.namespace.accounts;return e?[...new Set(e.filter(r=>r.split(":")[1]===this.chainId.toString()).map(r=>r.split(":")[2]))]:[]}createHttpProviders(){const e={};return this.namespace.chains.forEach(r=>{var n;e[r]=this.createHttpProvider(r,(n=this.namespace.rpcMap)==null?void 0:n[r])}),e}getHttpProvider(){const e=`${this.name}:${this.chainId}`,r=this.httpProviders[e];if(typeof r>"u")throw new Error(`JSON-RPC provider for ${e} not found`);return r}setHttpProvider(e,r){const n=this.createHttpProvider(e,r);n&&(this.httpProviders[e]=n)}createHttpProvider(e,r){const n=r||an(e,this.namespace,this.client.core.projectId);return typeof n>"u"?void 0:new ui(new Vi(n))}}var T7=Object.defineProperty,R7=Object.defineProperties,N7=Object.getOwnPropertyDescriptors,xg=Object.getOwnPropertySymbols,L7=Object.prototype.hasOwnProperty,M7=Object.prototype.propertyIsEnumerable,Cg=(t,e,r)=>e in t?T7(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,oc=(t,e)=>{for(var r in e||(e={}))L7.call(e,r)&&Cg(t,r,e[r]);if(xg)for(var r of xg(e))M7.call(e,r)&&Cg(t,r,e[r]);return t},mh=(t,e)=>R7(t,N7(e));class wh{constructor(e){this.events=new yr.exports,this.rpcProviders={},this.shouldAbortPairingAttempt=!1,this.maxPairingAttempts=10,this.providerOpts=e,this.logger=typeof e?.logger<"u"&&typeof e?.logger!="string"?e.logger:pt.pino(pt.getDefaultLoggerOptions({level:e?.logger||vg}))}static async init(e){const r=new wh(e);return await r.initialize(),r}async request(e,r){const[n,i]=this.validateChain(r);if(!this.session)throw new Error("Please call connect() before request()");return await this.getProvider(n).request({request:oc({},e),chainId:`${n}:${i}`,topic:this.session.topic})}sendAsync(e,r,n){this.request(e,n).then(i=>r(null,i)).catch(i=>r(i,void 0))}async enable(){if(!this.client)throw new Error("Sign Client not initialized");return this.session||await this.connect({namespaces:this.namespaces,optionalNamespaces:this.optionalNamespaces,sessionProperties:this.sessionProperties}),await this.requestAccounts()}async disconnect(){var e;if(!this.session)throw new Error("Please call connect() before enable()");await this.client.disconnect({topic:(e=this.session)==null?void 0:e.topic,reason:Zt("USER_DISCONNECTED")}),await this.cleanup()}async connect(e){if(!this.client)throw new Error("Sign Client not initialized");if(this.setNamespaces(e),await this.cleanupPendingPairings(),!e.skipPairing)return await this.pair(e.pairingTopic)}on(e,r){this.events.on(e,r)}once(e,r){this.events.once(e,r)}removeListener(e,r){this.events.removeListener(e,r)}off(e,r){this.events.off(e,r)}get isWalletConnect(){return!0}async pair(e){this.shouldAbortPairingAttempt=!1;let r=0;do{if(this.shouldAbortPairingAttempt)throw new Error("Pairing aborted");if(r>=this.maxPairingAttempts)throw new Error("Max auto pairing attempts reached");const{uri:n,approval:i}=await this.client.connect({pairingTopic:e,requiredNamespaces:this.namespaces,optionalNamespaces:this.optionalNamespaces,sessionProperties:this.sessionProperties});n&&(this.uri=n,this.events.emit("display_uri",n)),await i().then(o=>{this.session=o}).catch(o=>{if(o.message!==fg)throw o;r++})}while(!this.session);return this.onConnect(),this.session}setDefaultChain(e,r){try{const[n,i]=this.validateChain(e);this.getProvider(n).setDefaultChain(i,r)}catch(n){if(!/Please call connect/.test(n.message))throw n}}async cleanupPendingPairings(e={}){this.logger.info("Cleaning up inactive pairings...");const r=this.client.pairing.getAll();if(Hn(r)){for(const n of r)e.deletePairings?this.client.core.expirer.set(n.topic,0):await this.client.core.relayer.subscriber.unsubscribe(n.topic);this.logger.info(`Inactive pairings cleared: ${r.length}`)}}abortPairingAttempt(){this.shouldAbortPairingAttempt=!0}async checkStorage(){if(this.namespaces=await this.getFromStore("namespaces")||{},this.optionalNamespaces=await this.getFromStore("optionalNamespaces")||{},this.client.session.length){const e=this.client.session.keys.length-1;this.session=this.client.session.get(this.client.session.keys[e]),this.createProviders()}}async initialize(){this.logger.trace("Initialized"),await this.createClient(),await this.checkStorage(),this.registerEventListeners()}async createClient(){this.client=this.providerOpts.client||await fh.init({logger:this.providerOpts.logger||vg,relayUrl:this.providerOpts.relayUrl||u7,projectId:this.providerOpts.projectId,metadata:this.providerOpts.metadata,storageOptions:this.providerOpts.storageOptions,name:this.providerOpts.name}),this.logger.trace("SignClient Initialized")}createProviders(){if(!this.client)throw new Error("Sign Client not initialized");if(!this.session)throw new Error("Session not initialized. Please call connect() before enable()");[...new Set(Object.keys(this.session.namespaces).map(e=>Za(e)))].forEach(e=>{if(!this.session)return;const r=E7(e,this.session),n=_7(r),i=x7(this.namespaces,this.optionalNamespaces),o=mh(oc({},i[e]),{accounts:r,chains:n});switch(e){case"eip155":this.rpcProviders[e]=new S7({client:this.client,namespace:o,events:this.events});break;case"solana":this.rpcProviders[e]=new O7({client:this.client,namespace:o,events:this.events});break;case"cosmos":this.rpcProviders[e]=new A7({client:this.client,namespace:o,events:this.events});break;case"polkadot":this.rpcProviders[e]=new I7({client:this.client,namespace:o,events:this.events});break;case"cip34":this.rpcProviders[e]=new D7({client:this.client,namespace:o,events:this.events});break;case"elrond":this.rpcProviders[e]=new $7({client:this.client,namespace:o,events:this.events});break;case"multiversx":this.rpcProviders[e]=new P7({client:this.client,namespace:o,events:this.events});break}})}registerEventListeners(){if(typeof this.client>"u")throw new Error("Sign Client is not initialized");this.client.on("session_ping",e=>{this.events.emit("session_ping",e)}),this.client.on("session_event",e=>{const{params:r}=e,{event:n}=r;n.name==="accountsChanged"?this.events.emit("accountsChanged",n.data):n.name==="chainChanged"?this.onChainChanged(r.chainId):this.events.emit(n.name,n.data),this.events.emit("session_event",e)}),this.client.on("session_update",({topic:e,params:r})=>{var n;const{namespaces:i}=r,o=(n=this.client)==null?void 0:n.session.get(e);this.session=mh(oc({},o),{namespaces:i}),this.onSessionUpdate(),this.events.emit("session_update",{topic:e,params:r})}),this.client.on("session_delete",async e=>{await this.cleanup(),this.events.emit("session_delete",e),this.events.emit("disconnect",mh(oc({},Zt("USER_DISCONNECTED")),{data:e.topic}))}),this.on(fi.DEFAULT_CHAIN_CHANGED,e=>{this.onChainChanged(e,!0)})}getProvider(e){if(!this.rpcProviders[e])throw new Error(`Provider not found: ${e}`);return this.rpcProviders[e]}onSessionUpdate(){Object.keys(this.rpcProviders).forEach(e=>{var r;this.getProvider(e).updateNamespace((r=this.session)==null?void 0:r.namespaces[e])})}setNamespaces(e){const{namespaces:r,optionalNamespaces:n,sessionProperties:i}=e;if(!r||!Object.keys(r).length)throw new Error("Namespaces must be not empty");this.namespaces=r,this.optionalNamespaces=n,this.sessionProperties=i,this.persist("namespaces",r),this.persist("optionalNamespaces",n)}validateChain(e){const[r,n]=e?.split(":")||["",""];if(r&&!Object.keys(this.namespaces).map(c=>Za(c)).includes(r))throw new Error(`Namespace '${r}' is not configured. Please call connect() first with namespace config.`);if(r&&n)return[r,n];const i=Za(Object.keys(this.namespaces)[0]),o=this.rpcProviders[i].getDefaultChain();return[i,o]}async requestAccounts(){const[e]=this.validateChain();return await this.getProvider(e).requestAccounts()}onChainChanged(e,r=!1){var n;const[i,o]=this.validateChain(e);r||this.getProvider(i).setDefaultChain(o),((n=this.namespaces[i])!=null?n:this.namespaces[`${i}:${o}`]).defaultChain=o,this.persist("namespaces",this.namespaces),this.events.emit("chainChanged",o)}onConnect(){this.createProviders(),this.events.emit("connect",{session:this.session})}async cleanup(){this.session=void 0,await this.cleanupPendingPairings({deletePairings:!0})}persist(e,r){this.client.core.storage.setItem(`${yg}/${e}`,r)}async getFromStore(e){return await this.client.core.storage.getItem(`${yg}/${e}`)}}const U7=wh,j7="wc",F7="ethereum_provider",B7=`${j7}@${2}:${F7}:`,k7="https://rpc.walletconnect.com/v1/",ac=["eth_sendTransaction","personal_sign"],H7=["eth_accounts","eth_requestAccounts","eth_call","eth_getBalance","eth_sendRawTransaction","eth_sign","eth_signTransaction","eth_signTypedData","eth_signTypedData_v3","eth_signTypedData_v4","wallet_switchEthereumChain","wallet_addEthereumChain","wallet_getPermissions","wallet_requestPermissions","wallet_registerOnboarding","wallet_watchAsset","wallet_scanQRCode"],cc=["chainChanged","accountsChanged"],z7=["message","disconnect","connect"];var W7=Object.defineProperty,q7=Object.defineProperties,V7=Object.getOwnPropertyDescriptors,Ig=Object.getOwnPropertySymbols,K7=Object.prototype.hasOwnProperty,G7=Object.prototype.propertyIsEnumerable,Sg=(t,e,r)=>e in t?W7(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,vh=(t,e)=>{for(var r in e||(e={}))K7.call(e,r)&&Sg(t,r,e[r]);if(Ig)for(var r of Ig(e))G7.call(e,r)&&Sg(t,r,e[r]);return t},Og=(t,e)=>q7(t,V7(e));function yh(t){return Number(t[0].split(":")[1])}function bh(t){return`0x${t.toString(16)}`}function Z7(t){const{chains:e,optionalChains:r,methods:n,optionalMethods:i,events:o,optionalEvents:c,rpcMap:l}=t;if(!Hn(e))throw new Error("Invalid chains");const h=e,d=n||ac,v=o||cc,E={[yh(h)]:l[yh(h)]},_={chains:h,methods:d,events:v,rpcMap:E},O=o?.filter(G=>!cc.includes(G)),P=n?.filter(G=>!ac.includes(G));if(!r&&!c&&!i&&!(O!=null&&O.length)&&!(P!=null&&P.length))return{required:_};const U=O?.length&&P?.length||!r,H={chains:[...new Set(U?h.concat(r||[]):r)],methods:[...new Set(d.concat(i||[]))],events:[...new Set(v.concat(c||[]))],rpcMap:l};return{required:_,optional:H}}class lc{constructor(){this.events=new yr.exports.EventEmitter,this.namespace="eip155",this.accounts=[],this.chainId=1,this.STORAGE_KEY=B7,this.on=(e,r)=>(this.events.on(e,r),this),this.once=(e,r)=>(this.events.once(e,r),this),this.removeListener=(e,r)=>(this.events.removeListener(e,r),this),this.off=(e,r)=>(this.events.off(e,r),this),this.parseAccount=e=>this.isCompatibleChainId(e)?this.parseAccountId(e).address:e,this.signer={},this.rpc={}}static async init(e){const r=new lc;return await r.initialize(e),r}async request(e){return await this.signer.request(e,this.formatChainId(this.chainId))}sendAsync(e,r){this.signer.sendAsync(e,r,this.formatChainId(this.chainId))}get connected(){return this.signer.client?this.signer.client.core.relayer.connected:!1}get connecting(){return this.signer.client?this.signer.client.core.relayer.connecting:!1}async enable(){return this.session||await this.connect(),await this.request({method:"eth_requestAccounts"})}async connect(e){if(!this.signer.client)throw new Error("Provider not initialized. Call init() first");this.loadConnectOpts(e);const{required:r,optional:n}=Z7(this.rpc);try{const i=await new Promise(async(c,l)=>{var h;this.rpc.showQrModal&&((h=this.modal)==null||h.subscribeModal(d=>{!d.open&&!this.signer.session&&(this.signer.abortPairingAttempt(),l(new Error("Connection request reset. Please try again.")))})),await this.signer.connect(Og(vh({namespaces:{[this.namespace]:r}},n&&{optionalNamespaces:{[this.namespace]:n}}),{pairingTopic:e?.pairingTopic})).then(d=>{c(d)}).catch(d=>{l(new Error(d.message))})});if(!i)return;this.setChainIds(this.rpc.chains);const o=T5(i.namespaces,[this.namespace]);this.setAccounts(o),this.events.emit("connect",{chainId:bh(this.chainId)})}catch(i){throw this.signer.logger.error(i),i}finally{this.modal&&this.modal.closeModal()}}async disconnect(){this.session&&await this.signer.disconnect(),this.reset()}get isWalletConnect(){return!0}get session(){return this.signer.session}registerEventListeners(){this.signer.on("session_event",e=>{const{params:r}=e,{event:n}=r;n.name==="accountsChanged"?(this.accounts=this.parseAccounts(n.data),this.events.emit("accountsChanged",this.accounts)):n.name==="chainChanged"?this.setChainId(this.formatChainId(n.data)):this.events.emit(n.name,n.data),this.events.emit("session_event",e)}),this.signer.on("chainChanged",e=>{const r=parseInt(e);this.chainId=r,this.events.emit("chainChanged",bh(this.chainId)),this.persist()}),this.signer.on("session_update",e=>{this.events.emit("session_update",e)}),this.signer.on("session_delete",e=>{this.reset(),this.events.emit("session_delete",e),this.events.emit("disconnect",Og(vh({},Zt("USER_DISCONNECTED")),{data:e.topic,name:"USER_DISCONNECTED"}))}),this.signer.on("display_uri",e=>{var r,n;this.rpc.showQrModal&&((r=this.modal)==null||r.closeModal(),(n=this.modal)==null||n.openModal({uri:e})),this.events.emit("display_uri",e)})}setHttpProvider(e){this.request({method:"wallet_switchEthereumChain",params:[{chainId:e.toString(16)}]})}isCompatibleChainId(e){return typeof e=="string"?e.startsWith(`${this.namespace}:`):!1}formatChainId(e){return`${this.namespace}:${e}`}parseChainId(e){return Number(e.split(":")[1])}setChainIds(e){const r=e.filter(n=>this.isCompatibleChainId(n)).map(n=>this.parseChainId(n));r.length&&(this.chainId=r[0],this.events.emit("chainChanged",bh(this.chainId)),this.persist())}setChainId(e){if(this.isCompatibleChainId(e)){const r=this.parseChainId(e);this.chainId=r,this.setHttpProvider(r)}}parseAccountId(e){const[r,n,i]=e.split(":");return{chainId:`${r}:${n}`,address:i}}setAccounts(e){this.accounts=e.filter(r=>this.parseChainId(this.parseAccountId(r).chainId)===this.chainId).map(r=>this.parseAccountId(r).address),this.events.emit("accountsChanged",this.accounts)}getRpcConfig(e){var r,n;return{chains:((r=e.chains)==null?void 0:r.map(i=>this.formatChainId(i)))||[`${this.namespace}:1`],optionalChains:e.optionalChains?e.optionalChains.map(i=>this.formatChainId(i)):void 0,methods:e?.methods||ac,events:e?.events||cc,optionalMethods:e?.optionalMethods||[],optionalEvents:e?.optionalEvents||[],rpcMap:e?.rpcMap||this.buildRpcMap(e.chains.concat(e.optionalChains||[]),e.projectId),showQrModal:Boolean(e?.showQrModal),qrModalOptions:(n=e?.qrModalOptions)!=null?n:void 0,projectId:e.projectId,metadata:e.metadata}}buildRpcMap(e,r){const n={};return e.forEach(i=>{n[i]=this.getRpcUrl(i,r)}),n}async initialize(e){if(this.rpc=this.getRpcConfig(e),this.chainId=yh(this.rpc.chains),this.signer=await U7.init({projectId:this.rpc.projectId,metadata:this.rpc.metadata}),this.registerEventListeners(),await this.loadPersistedSession(),this.rpc.showQrModal)try{const{Web3Modal:r}=await Promise.resolve().then(function(){return Sx});this.modal=new r(vh({walletConnectVersion:2,projectId:this.rpc.projectId,standaloneChains:this.rpc.chains},this.rpc.qrModalOptions))}catch{throw new Error("To use QR modal, please install @web3modal/standalone package")}}loadConnectOpts(e){if(!e)return;const{chains:r,optionalChains:n,rpcMap:i}=e;r&&Hn(r)&&(this.rpc.chains=r.map(o=>this.formatChainId(o)),r.forEach(o=>{this.rpc.rpcMap[o]=i?.[o]||this.getRpcUrl(o)})),n&&Hn(n)&&(this.rpc.optionalChains=[],this.rpc.optionalChains=n?.map(o=>this.formatChainId(o)),n.forEach(o=>{this.rpc.rpcMap[o]=i?.[o]||this.getRpcUrl(o)}))}getRpcUrl(e,r){var n;return((n=this.rpc.rpcMap)==null?void 0:n[e])||`${k7}?chainId=eip155:${e}&projectId=${r||this.rpc.projectId}`}async loadPersistedSession(){if(!this.session)return;const e=await this.signer.client.core.storage.getItem(`${this.STORAGE_KEY}/chainId`);this.setChainIds(e?[this.formatChainId(e)]:this.session.namespaces[this.namespace].accounts),this.setAccounts(this.session.namespaces[this.namespace].accounts)}reset(){this.chainId=1,this.accounts=[]}persist(){this.session&&this.signer.client.core.storage.setItem(`${this.STORAGE_KEY}/chainId`,this.chainId)}parseAccounts(e){return typeof e=="string"||e instanceof String?[this.parseAccount(e)]:e.map(r=>this.parseAccount(r))}}const Y7=lc,J7=Symbol(),Ag=Object.getPrototypeOf,_h=new WeakMap,X7=t=>t&&(_h.has(t)?_h.get(t):Ag(t)===Object.prototype||Ag(t)===Array.prototype),Q7=t=>X7(t)&&t[J7]||null,Dg=(t,e=!0)=>{_h.set(t,e)},Eh=t=>typeof t=="object"&&t!==null,di=new WeakMap,uc=new WeakSet,ex=(t=Object.is,e=(d,v)=>new Proxy(d,v),r=d=>Eh(d)&&!uc.has(d)&&(Array.isArray(d)||!(Symbol.iterator in d))&&!(d instanceof WeakMap)&&!(d instanceof WeakSet)&&!(d instanceof Error)&&!(d instanceof Number)&&!(d instanceof Date)&&!(d instanceof String)&&!(d instanceof RegExp)&&!(d instanceof ArrayBuffer),n=d=>{switch(d.status){case"fulfilled":return d.value;case"rejected":throw d.reason;default:throw d}},i=new WeakMap,o=(d,v,E=n)=>{const _=i.get(d);if(_?.[0]===v)return _[1];const O=Array.isArray(d)?[]:Object.create(Object.getPrototypeOf(d));return Dg(O,!0),i.set(d,[v,O]),Reflect.ownKeys(d).forEach(P=>{if(Object.getOwnPropertyDescriptor(O,P))return;const U=Reflect.get(d,P),H={value:U,enumerable:!0,configurable:!0};if(uc.has(U))Dg(U,!1);else if(U instanceof Promise)delete H.value,H.get=()=>E(U);else if(di.has(U)){const[G,N]=di.get(U);H.value=o(G,N(),E)}Object.defineProperty(O,P,H)}),O},c=new WeakMap,l=[1,1],h=d=>{if(!Eh(d))throw new Error("object required");const v=c.get(d);if(v)return v;let E=l[0];const _=new Set,O=(J,z=++l[0])=>{E!==z&&(E=z,_.forEach(ee=>ee(J,z)))};let P=l[1];const U=(J=++l[1])=>(P!==J&&!_.size&&(P=J,G.forEach(([z])=>{const ee=z[1](J);ee>E&&(E=ee)})),E),H=J=>(z,ee)=>{const de=[...z];de[1]=[J,...de[1]],O(de,ee)},G=new Map,N=(J,z)=>{if(void 0!=="production"&&G.has(J))throw new Error("prop listener already exists");if(_.size){const ee=z[3](H(J));G.set(J,[z,ee])}else G.set(J,[z])},L=J=>{var z;const ee=G.get(J);ee&&(G.delete(J),(z=ee[1])==null||z.call(ee))},$=J=>(_.add(J),_.size===1&&G.forEach(([ee,de],me)=>{if(void 0!=="production"&&de)throw new Error("remove already exists");const S=ee[3](H(me));G.set(me,[ee,S])}),()=>{_.delete(J),_.size===0&&G.forEach(([ee,de],me)=>{de&&(de(),G.set(me,[ee]))})}),T=Array.isArray(d)?[]:Object.create(Object.getPrototypeOf(d)),f=e(T,{deleteProperty(J,z){const ee=Reflect.get(J,z);L(z);const de=Reflect.deleteProperty(J,z);return de&&O(["delete",[z],ee]),de},set(J,z,ee,de){const me=Reflect.has(J,z),S=Reflect.get(J,z,de);if(me&&(t(S,ee)||c.has(ee)&&t(S,c.get(ee))))return!0;L(z),Eh(ee)&&(ee=Q7(ee)||ee);let j=ee;if(ee instanceof Promise)ee.then(ce=>{ee.status="fulfilled",ee.value=ce,O(["resolve",[z],ce])}).catch(ce=>{ee.status="rejected",ee.reason=ce,O(["reject",[z],ce])});else{!di.has(ee)&&r(ee)&&(j=h(ee));const ce=!uc.has(j)&&di.get(j);ce&&N(z,ce)}return Reflect.set(J,z,j,de),O(["set",[z],ee,S]),!0}});c.set(d,f);const x=[T,U,o,$];return di.set(f,x),Reflect.ownKeys(d).forEach(J=>{const z=Object.getOwnPropertyDescriptor(d,J);"value"in z&&(f[J]=d[J],delete z.value,delete z.writable),Object.defineProperty(T,J,z)}),f})=>[h,di,uc,t,e,r,n,i,o,c,l],[tx]=ex();function Tn(t={}){return tx(t)}function Vn(t,e,r){const n=di.get(t);void 0!=="production"&&!n&&console.warn("Please use proxy object");let i;const o=[],c=n[3];let l=!1;const d=c(v=>{if(o.push(v),r){e(o.splice(0));return}i||(i=Promise.resolve().then(()=>{i=void 0,l&&e(o.splice(0))}))});return l=!0,()=>{l=!1,d()}}function rx(t,e){const r=di.get(t);void 0!=="production"&&!r&&console.warn("Please use proxy object");const[n,i,o]=r;return o(n,i(),e)}var $g={},hc={};hc.byteLength=sx,hc.toByteArray=ax,hc.fromByteArray=ux;for(var Rn=[],cn=[],nx=typeof Uint8Array<"u"?Uint8Array:Array,xh="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",Ps=0,ix=xh.length;Ps<ix;++Ps)Rn[Ps]=xh[Ps],cn[xh.charCodeAt(Ps)]=Ps;cn["-".charCodeAt(0)]=62,cn["_".charCodeAt(0)]=63;function Pg(t){var e=t.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=t.indexOf("=");r===-1&&(r=e);var n=r===e?0:4-r%4;return[r,n]}function sx(t){var e=Pg(t),r=e[0],n=e[1];return(r+n)*3/4-n}function ox(t,e,r){return(e+r)*3/4-r}function ax(t){var e,r=Pg(t),n=r[0],i=r[1],o=new nx(ox(t,n,i)),c=0,l=i>0?n-4:n,h;for(h=0;h<l;h+=4)e=cn[t.charCodeAt(h)]<<18|cn[t.charCodeAt(h+1)]<<12|cn[t.charCodeAt(h+2)]<<6|cn[t.charCodeAt(h+3)],o[c++]=e>>16&255,o[c++]=e>>8&255,o[c++]=e&255;return i===2&&(e=cn[t.charCodeAt(h)]<<2|cn[t.charCodeAt(h+1)]>>4,o[c++]=e&255),i===1&&(e=cn[t.charCodeAt(h)]<<10|cn[t.charCodeAt(h+1)]<<4|cn[t.charCodeAt(h+2)]>>2,o[c++]=e>>8&255,o[c++]=e&255),o}function cx(t){return Rn[t>>18&63]+Rn[t>>12&63]+Rn[t>>6&63]+Rn[t&63]}function lx(t,e,r){for(var n,i=[],o=e;o<r;o+=3)n=(t[o]<<16&16711680)+(t[o+1]<<8&65280)+(t[o+2]&255),i.push(cx(n));return i.join("")}function ux(t){for(var e,r=t.length,n=r%3,i=[],o=16383,c=0,l=r-n;c<l;c+=o)i.push(lx(t,c,c+o>l?l:c+o));return n===1?(e=t[r-1],i.push(Rn[e>>2]+Rn[e<<4&63]+"==")):n===2&&(e=(t[r-2]<<8)+t[r-1],i.push(Rn[e>>10]+Rn[e>>4&63]+Rn[e<<2&63]+"=")),i.join("")}var Ch={};/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */Ch.read=function(t,e,r,n,i){var o,c,l=i*8-n-1,h=(1<<l)-1,d=h>>1,v=-7,E=r?i-1:0,_=r?-1:1,O=t[e+E];for(E+=_,o=O&(1<<-v)-1,O>>=-v,v+=l;v>0;o=o*256+t[e+E],E+=_,v-=8);for(c=o&(1<<-v)-1,o>>=-v,v+=n;v>0;c=c*256+t[e+E],E+=_,v-=8);if(o===0)o=1-d;else{if(o===h)return c?NaN:(O?-1:1)*(1/0);c=c+Math.pow(2,n),o=o-d}return(O?-1:1)*c*Math.pow(2,o-n)},Ch.write=function(t,e,r,n,i,o){var c,l,h,d=o*8-i-1,v=(1<<d)-1,E=v>>1,_=i===23?Math.pow(2,-24)-Math.pow(2,-77):0,O=n?0:o-1,P=n?1:-1,U=e<0||e===0&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(l=isNaN(e)?1:0,c=v):(c=Math.floor(Math.log(e)/Math.LN2),e*(h=Math.pow(2,-c))<1&&(c--,h*=2),c+E>=1?e+=_/h:e+=_*Math.pow(2,1-E),e*h>=2&&(c++,h/=2),c+E>=v?(l=0,c=v):c+E>=1?(l=(e*h-1)*Math.pow(2,i),c=c+E):(l=e*Math.pow(2,E-1)*Math.pow(2,i),c=0));i>=8;t[r+O]=l&255,O+=P,l/=256,i-=8);for(c=c<<i|l,d+=i;d>0;t[r+O]=c&255,O+=P,c/=256,d-=8);t[r+O-P]|=U*128};/*!
|
|
98
|
+
}`;var ot=cw(function(){return vt(A,Pe+"return "+pe).apply(r,M)});if(ot.source=pe,Y0(ot))throw ot;return ot}function FR(s){return yt(s).toLowerCase()}function BR(s){return yt(s).toUpperCase()}function kR(s,a,u){if(s=yt(s),s&&(u||a===r))return wm(s);if(!s||!(a=en(a)))return s;var g=Cn(s),y=Cn(a),A=vm(g,y),M=ym(g,y)+1;return Ri(g,A,M).join("")}function HR(s,a,u){if(s=yt(s),s&&(u||a===r))return s.slice(0,_m(s)+1);if(!s||!(a=en(a)))return s;var g=Cn(s),y=ym(g,Cn(a))+1;return Ri(g,0,y).join("")}function zR(s,a,u){if(s=yt(s),s&&(u||a===r))return s.replace(Vt,"");if(!s||!(a=en(a)))return s;var g=Cn(s),y=vm(g,Cn(a));return Ri(g,y).join("")}function WR(s,a){var u=z,g=ee;if(Bt(a)){var y="separator"in a?a.separator:y;u="length"in a?it(a.length):u,g="omission"in a?en(a.omission):g}s=yt(s);var A=s.length;if(oo(s)){var M=Cn(s);A=M.length}if(u>=A)return s;var k=u-ao(g);if(k<1)return g;var Z=M?Ri(M,0,k).join(""):s.slice(0,k);if(y===r)return Z+g;if(M&&(k+=Z.length-k),J0(y)){if(s.slice(k).search(y)){var ue,he=Z;for(y.global||(y=d0(y.source,yt(hn.exec(y))+"g")),y.lastIndex=0;ue=y.exec(he);)var pe=ue.index;Z=Z.slice(0,pe===r?k:pe)}}else if(s.indexOf(en(y),k)!=k){var be=Z.lastIndexOf(y);be>-1&&(Z=Z.slice(0,be))}return Z+g}function qR(s){return s=yt(s),s&&Ht.test(s)?s.replace(Ci,bA):s}var VR=go(function(s,a,u){return s+(u?" ":"")+a.toUpperCase()}),ed=l2("toUpperCase");function aw(s,a,u){return s=yt(s),a=u?r:a,a===r?gA(s)?xA(s):oA(s):s.match(a)||[]}var cw=ct(function(s,a){try{return wr(s,r,a)}catch(u){return Y0(u)?u:new Ye(u)}}),KR=ni(function(s,a){return dn(a,function(u){u=kn(u),ti(s,u,G0(s[u],s))}),s});function GR(s){var a=s==null?0:s.length,u=ze();return s=a?Ut(s,function(g){if(typeof g[1]!="function")throw new pn(c);return[u(g[0]),g[1]]}):[],ct(function(g){for(var y=-1;++y<a;){var A=s[y];if(wr(A[0],this,g))return wr(A[1],this,g)}})}function ZR(s){return bD(mn(s,E))}function td(s){return function(){return s}}function YR(s,a){return s==null||s!==s?a:s}var JR=h2(),XR=h2(!0);function Gr(s){return s}function rd(s){return km(typeof s=="function"?s:mn(s,E))}function QR(s){return zm(mn(s,E))}function eN(s,a){return Wm(s,mn(a,E))}var tN=ct(function(s,a){return function(u){return Aa(u,s,a)}}),rN=ct(function(s,a){return function(u){return Aa(s,u,a)}});function nd(s,a,u){var g=vr(a),y=Pl(a,g);u==null&&!(Bt(a)&&(y.length||!g.length))&&(u=a,a=s,s=this,y=Pl(a,vr(a)));var A=!(Bt(u)&&"chain"in u)||!!u.chain,M=si(s);return dn(y,function(k){var Z=a[k];s[k]=Z,M&&(s.prototype[k]=function(){var ue=this.__chain__;if(A||ue){var he=s(this.__wrapped__),pe=he.__actions__=qr(this.__actions__);return pe.push({func:Z,args:arguments,thisArg:s}),he.__chain__=ue,he}return Z.apply(s,Oi([this.value()],arguments))})}),s}function nN(){return mt._===this&&(mt._=DA),this}function id(){}function iN(s){return s=it(s),ct(function(a){return qm(a,s)})}var sN=L0(Ut),oN=L0(fm),aN=L0(o0);function lw(s){return H0(s)?a0(kn(s)):UD(s)}function cN(s){return function(a){return s==null?r:ys(s,a)}}var lN=d2(),uN=d2(!0);function sd(){return[]}function od(){return!1}function hN(){return{}}function fN(){return""}function dN(){return!0}function pN(s,a){if(s=it(s),s<1||s>re)return[];var u=ie,g=Sr(s,ie);a=ze(a),s-=ie;for(var y=u0(g,a);++u<s;)a(u);return y}function gN(s){return Qe(s)?Ut(s,kn):tn(s)?[s]:qr(D2(yt(s)))}function mN(s){var a=++OA;return yt(s)+a}var wN=Ul(function(s,a){return s+a},0),vN=M0("ceil"),yN=Ul(function(s,a){return s/a},1),bN=M0("floor");function _N(s){return s&&s.length?$l(s,Gr,_0):r}function EN(s,a){return s&&s.length?$l(s,ze(a,2),_0):r}function xN(s){return gm(s,Gr)}function CN(s,a){return gm(s,ze(a,2))}function IN(s){return s&&s.length?$l(s,Gr,I0):r}function SN(s,a){return s&&s.length?$l(s,ze(a,2),I0):r}var ON=Ul(function(s,a){return s*a},1),AN=M0("round"),DN=Ul(function(s,a){return s-a},0);function $N(s){return s&&s.length?l0(s,Gr):0}function PN(s,a){return s&&s.length?l0(s,ze(a,2)):0}return C.after=QP,C.ary=B2,C.assign=BT,C.assignIn=ew,C.assignInWith=Yl,C.assignWith=kT,C.at=HT,C.before=k2,C.bind=G0,C.bindAll=KR,C.bindKey=H2,C.castArray=hT,C.chain=U2,C.chunk=b$,C.compact=_$,C.concat=E$,C.cond=GR,C.conforms=ZR,C.constant=td,C.countBy=$P,C.create=zT,C.curry=z2,C.curryRight=W2,C.debounce=q2,C.defaults=WT,C.defaultsDeep=qT,C.defer=eT,C.delay=tT,C.difference=x$,C.differenceBy=C$,C.differenceWith=I$,C.drop=S$,C.dropRight=O$,C.dropRightWhile=A$,C.dropWhile=D$,C.fill=$$,C.filter=TP,C.flatMap=LP,C.flatMapDeep=MP,C.flatMapDepth=UP,C.flatten=R2,C.flattenDeep=P$,C.flattenDepth=T$,C.flip=rT,C.flow=JR,C.flowRight=XR,C.fromPairs=R$,C.functions=XT,C.functionsIn=QT,C.groupBy=jP,C.initial=L$,C.intersection=M$,C.intersectionBy=U$,C.intersectionWith=j$,C.invert=tR,C.invertBy=rR,C.invokeMap=BP,C.iteratee=rd,C.keyBy=kP,C.keys=vr,C.keysIn=Kr,C.map=Wl,C.mapKeys=iR,C.mapValues=sR,C.matches=QR,C.matchesProperty=eN,C.memoize=Vl,C.merge=oR,C.mergeWith=tw,C.method=tN,C.methodOf=rN,C.mixin=nd,C.negate=Kl,C.nthArg=iN,C.omit=aR,C.omitBy=cR,C.once=nT,C.orderBy=HP,C.over=sN,C.overArgs=iT,C.overEvery=oN,C.overSome=aN,C.partial=Z0,C.partialRight=V2,C.partition=zP,C.pick=lR,C.pickBy=rw,C.property=lw,C.propertyOf=cN,C.pull=H$,C.pullAll=L2,C.pullAllBy=z$,C.pullAllWith=W$,C.pullAt=q$,C.range=lN,C.rangeRight=uN,C.rearg=sT,C.reject=VP,C.remove=V$,C.rest=oT,C.reverse=V0,C.sampleSize=GP,C.set=hR,C.setWith=fR,C.shuffle=ZP,C.slice=K$,C.sortBy=XP,C.sortedUniq=eP,C.sortedUniqBy=tP,C.split=LR,C.spread=aT,C.tail=rP,C.take=nP,C.takeRight=iP,C.takeRightWhile=sP,C.takeWhile=oP,C.tap=_P,C.throttle=cT,C.thru=zl,C.toArray=J2,C.toPairs=nw,C.toPairsIn=iw,C.toPath=gN,C.toPlainObject=Q2,C.transform=dR,C.unary=lT,C.union=aP,C.unionBy=cP,C.unionWith=lP,C.uniq=uP,C.uniqBy=hP,C.uniqWith=fP,C.unset=pR,C.unzip=K0,C.unzipWith=M2,C.update=gR,C.updateWith=mR,C.values=vo,C.valuesIn=wR,C.without=dP,C.words=aw,C.wrap=uT,C.xor=pP,C.xorBy=gP,C.xorWith=mP,C.zip=wP,C.zipObject=vP,C.zipObjectDeep=yP,C.zipWith=bP,C.entries=nw,C.entriesIn=iw,C.extend=ew,C.extendWith=Yl,nd(C,C),C.add=wN,C.attempt=cw,C.camelCase=_R,C.capitalize=sw,C.ceil=vN,C.clamp=vR,C.clone=fT,C.cloneDeep=pT,C.cloneDeepWith=gT,C.cloneWith=dT,C.conformsTo=mT,C.deburr=ow,C.defaultTo=YR,C.divide=yN,C.endsWith=ER,C.eq=Sn,C.escape=xR,C.escapeRegExp=CR,C.every=PP,C.find=RP,C.findIndex=P2,C.findKey=VT,C.findLast=NP,C.findLastIndex=T2,C.findLastKey=KT,C.floor=bN,C.forEach=j2,C.forEachRight=F2,C.forIn=GT,C.forInRight=ZT,C.forOwn=YT,C.forOwnRight=JT,C.get=X0,C.gt=wT,C.gte=vT,C.has=eR,C.hasIn=Q0,C.head=N2,C.identity=Gr,C.includes=FP,C.indexOf=N$,C.inRange=yR,C.invoke=nR,C.isArguments=Es,C.isArray=Qe,C.isArrayBuffer=yT,C.isArrayLike=Vr,C.isArrayLikeObject=Xt,C.isBoolean=bT,C.isBuffer=Ni,C.isDate=_T,C.isElement=ET,C.isEmpty=xT,C.isEqual=CT,C.isEqualWith=IT,C.isError=Y0,C.isFinite=ST,C.isFunction=si,C.isInteger=K2,C.isLength=Gl,C.isMap=G2,C.isMatch=OT,C.isMatchWith=AT,C.isNaN=DT,C.isNative=$T,C.isNil=TT,C.isNull=PT,C.isNumber=Z2,C.isObject=Bt,C.isObjectLike=Gt,C.isPlainObject=Na,C.isRegExp=J0,C.isSafeInteger=RT,C.isSet=Y2,C.isString=Zl,C.isSymbol=tn,C.isTypedArray=wo,C.isUndefined=NT,C.isWeakMap=LT,C.isWeakSet=MT,C.join=F$,C.kebabCase=IR,C.last=vn,C.lastIndexOf=B$,C.lowerCase=SR,C.lowerFirst=OR,C.lt=UT,C.lte=jT,C.max=_N,C.maxBy=EN,C.mean=xN,C.meanBy=CN,C.min=IN,C.minBy=SN,C.stubArray=sd,C.stubFalse=od,C.stubObject=hN,C.stubString=fN,C.stubTrue=dN,C.multiply=ON,C.nth=k$,C.noConflict=nN,C.noop=id,C.now=ql,C.pad=AR,C.padEnd=DR,C.padStart=$R,C.parseInt=PR,C.random=bR,C.reduce=WP,C.reduceRight=qP,C.repeat=TR,C.replace=RR,C.result=uR,C.round=AN,C.runInContext=V,C.sample=KP,C.size=YP,C.snakeCase=NR,C.some=JP,C.sortedIndex=G$,C.sortedIndexBy=Z$,C.sortedIndexOf=Y$,C.sortedLastIndex=J$,C.sortedLastIndexBy=X$,C.sortedLastIndexOf=Q$,C.startCase=MR,C.startsWith=UR,C.subtract=DN,C.sum=$N,C.sumBy=PN,C.template=jR,C.times=pN,C.toFinite=oi,C.toInteger=it,C.toLength=X2,C.toLower=FR,C.toNumber=yn,C.toSafeInteger=FT,C.toString=yt,C.toUpper=BR,C.trim=kR,C.trimEnd=HR,C.trimStart=zR,C.truncate=WR,C.unescape=qR,C.uniqueId=mN,C.upperCase=VR,C.upperFirst=ed,C.each=j2,C.eachRight=F2,C.first=N2,nd(C,function(){var s={};return Fn(C,function(a,u){bt.call(C.prototype,u)||(s[u]=a)}),s}(),{chain:!1}),C.VERSION=n,dn(["bind","bindKey","curry","curryRight","partial","partialRight"],function(s){C[s].placeholder=C}),dn(["drop","take"],function(s,a){dt.prototype[s]=function(u){u=u===r?1:hr(it(u),0);var g=this.__filtered__&&!a?new dt(this):this.clone();return g.__filtered__?g.__takeCount__=Sr(u,g.__takeCount__):g.__views__.push({size:Sr(u,ie),type:s+(g.__dir__<0?"Right":"")}),g},dt.prototype[s+"Right"]=function(u){return this.reverse()[s](u).reverse()}}),dn(["filter","map","takeWhile"],function(s,a){var u=a+1,g=u==S||u==ce;dt.prototype[s]=function(y){var A=this.clone();return A.__iteratees__.push({iteratee:ze(y,3),type:u}),A.__filtered__=A.__filtered__||g,A}}),dn(["head","last"],function(s,a){var u="take"+(a?"Right":"");dt.prototype[s]=function(){return this[u](1).value()[0]}}),dn(["initial","tail"],function(s,a){var u="drop"+(a?"":"Right");dt.prototype[s]=function(){return this.__filtered__?new dt(this):this[u](1)}}),dt.prototype.compact=function(){return this.filter(Gr)},dt.prototype.find=function(s){return this.filter(s).head()},dt.prototype.findLast=function(s){return this.reverse().find(s)},dt.prototype.invokeMap=ct(function(s,a){return typeof s=="function"?new dt(this):this.map(function(u){return Aa(u,s,a)})}),dt.prototype.reject=function(s){return this.filter(Kl(ze(s)))},dt.prototype.slice=function(s,a){s=it(s);var u=this;return u.__filtered__&&(s>0||a<0)?new dt(u):(s<0?u=u.takeRight(-s):s&&(u=u.drop(s)),a!==r&&(a=it(a),u=a<0?u.dropRight(-a):u.take(a-s)),u)},dt.prototype.takeRightWhile=function(s){return this.reverse().takeWhile(s).reverse()},dt.prototype.toArray=function(){return this.take(ie)},Fn(dt.prototype,function(s,a){var u=/^(?:filter|find|map|reject)|While$/.test(a),g=/^(?:head|last)$/.test(a),y=C[g?"take"+(a=="last"?"Right":""):a],A=g||/^find/.test(a);y&&(C.prototype[a]=function(){var M=this.__wrapped__,k=g?[1]:arguments,Z=M instanceof dt,ue=k[0],he=Z||Qe(M),pe=function(ft){var wt=y.apply(C,Oi([ft],k));return g&&be?wt[0]:wt};he&&u&&typeof ue=="function"&&ue.length!=1&&(Z=he=!1);var be=this.__chain__,Pe=!!this.__actions__.length,We=A&&!be,ot=Z&&!Pe;if(!A&&he){M=ot?M:new dt(this);var qe=s.apply(M,k);return qe.__actions__.push({func:zl,args:[pe],thisArg:r}),new gn(qe,be)}return We&&ot?s.apply(this,k):(qe=this.thru(pe),We?g?qe.value()[0]:qe.value():qe)})}),dn(["pop","push","shift","sort","splice","unshift"],function(s){var a=gl[s],u=/^(?:push|sort|unshift)$/.test(s)?"tap":"thru",g=/^(?:pop|shift)$/.test(s);C.prototype[s]=function(){var y=arguments;if(g&&!this.__chain__){var A=this.value();return a.apply(Qe(A)?A:[],y)}return this[u](function(M){return a.apply(Qe(M)?M:[],y)})}}),Fn(dt.prototype,function(s,a){var u=C[a];if(u){var g=u.name+"";bt.call(ho,g)||(ho[g]=[]),ho[g].push({name:a,func:u})}}),ho[Ml(r,G).name]=[{name:"wrapper",func:r}],dt.prototype.clone=qA,dt.prototype.reverse=VA,dt.prototype.value=KA,C.prototype.at=EP,C.prototype.chain=xP,C.prototype.commit=CP,C.prototype.next=IP,C.prototype.plant=OP,C.prototype.reverse=AP,C.prototype.toJSON=C.prototype.valueOf=C.prototype.value=DP,C.prototype.first=C.prototype.head,_a&&(C.prototype[_a]=SP),C},co=CA();Jt?((Jt.exports=co)._=co,St._=co):mt._=co}).call(Wo)})(ph,ph.exports);var p7=Object.defineProperty,g7=Object.defineProperties,m7=Object.getOwnPropertyDescriptors,bg=Object.getOwnPropertySymbols,w7=Object.prototype.hasOwnProperty,v7=Object.prototype.propertyIsEnumerable,_g=(t,e,r)=>e in t?p7(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,sc=(t,e)=>{for(var r in e||(e={}))w7.call(e,r)&&_g(t,r,e[r]);if(bg)for(var r of bg(e))v7.call(e,r)&&_g(t,r,e[r]);return t},y7=(t,e)=>g7(t,m7(e));function an(t,e,r){let n;const i=gh(t);return e.rpcMap&&(n=e.rpcMap[i]),n||(n=`${d7}?chainId=eip155:${i}&projectId=${r}`),n}function gh(t){return t.includes("eip155")?Number(t.split(":")[1]):Number(t)}function b7(t,e){if(!e.includes(t))throw new Error(`Chain '${t}' not approved. Please use one of the following: ${e.toString()}`)}function _7(t){return t.map(e=>`${e.split(":")[0]}:${e.split(":")[1]}`)}function E7(t,e){const r=Object.keys(e.namespaces).filter(i=>i.includes(t));if(!r.length)return[];const n=[];return r.forEach(i=>{const o=e.namespaces[i].accounts;n.push(...o)}),n}function x7(t,e={}){const r=Eg(t),n=Eg(e);return ph.exports.merge(r,n)}function Eg(t){var e,r,n,i;const o={};if(!Ds(t))return o;for(const[c,l]of Object.entries(t)){const h=N1(c)?[c]:l.chains,d=l.methods||[],v=l.events||[],E=l.rpcMap||{},_=Za(c);o[_]=y7(sc(sc({},o[_]),l),{chains:Ou(h,(e=o[_])==null?void 0:e.chains),methods:Ou(d,(r=o[_])==null?void 0:r.methods),events:Ou(v,(n=o[_])==null?void 0:n.events),rpcMap:sc(sc({},E),(i=o[_])==null?void 0:i.rpcMap)})}return o}const Ki=(t,e)=>{const r=n=>{n.request!==e.request||n.topic!==e.topic||(t.events.removeListener("session_request_sent",r),C7(e,t.core.storage))};t.on("session_request_sent",r)};async function C7(t,e){try{const r=await e.getItem("WALLETCONNECT_DEEPLINK_CHOICE");if(!r)return;const n=typeof r=="string"?JSON.parse(r):r;let i=n?.href;if(typeof i!="string")return;i.endsWith("/")&&(i=i.slice(0,-1));const o=`${i}/wc?requestId=${t.id}&sessionTopic=${t.topic}`,c=O1();c===ki.browser?window.open(o,"_self","noreferrer noopener"):c===ki.reactNative&&typeof(global==null?void 0:global.Linking)<"u"&&await global.Linking.openURL(o)}catch(r){console.error(r)}}class I7{constructor(e){this.name="polkadot",this.namespace=e.namespace,this.events=e.events,this.client=e.client,this.chainId=this.getDefaultChain(),this.httpProviders=this.createHttpProviders()}updateNamespace(e){this.namespace=Object.assign(this.namespace,e)}requestAccounts(){return this.getAccounts()}getDefaultChain(){if(this.chainId)return this.chainId;if(this.namespace.defaultChain)return this.namespace.defaultChain;const e=this.namespace.chains[0];if(!e)throw new Error("ChainId not found");return e.split(":")[1]}request(e){return this.namespace.methods.includes(e.request.method)?(Ki(this.client,e),this.client.request(e)):this.getHttpProvider().request(e.request)}setDefaultChain(e,r){if(this.chainId=e,!this.httpProviders[e]){const n=r||an(`${this.name}:${e}`,this.namespace);if(!n)throw new Error(`No RPC url provided for chainId: ${e}`);this.setHttpProvider(e,n)}this.events.emit(fi.DEFAULT_CHAIN_CHANGED,`${this.name}:${this.chainId}`)}getAccounts(){const e=this.namespace.accounts;return e?e.filter(r=>r.split(":")[1]===this.chainId.toString()).map(r=>r.split(":")[2])||[]:[]}createHttpProviders(){const e={};return this.namespace.chains.forEach(r=>{var n;e[r]=this.createHttpProvider(r,(n=this.namespace.rpcMap)==null?void 0:n[r])}),e}getHttpProvider(){const e=`${this.name}:${this.chainId}`,r=this.httpProviders[e];if(typeof r>"u")throw new Error(`JSON-RPC provider for ${e} not found`);return r}setHttpProvider(e,r){const n=this.createHttpProvider(e,r);n&&(this.httpProviders[e]=n)}createHttpProvider(e,r){const n=r||an(e,this.namespace);return typeof n>"u"?void 0:new ui(new Vi(n))}}class S7{constructor(e){this.name="eip155",this.namespace=e.namespace,this.client=e.client,this.events=e.events,this.httpProviders=this.createHttpProviders(),this.chainId=parseInt(this.getDefaultChain())}async request(e){var r;switch(e.request.method){case"eth_requestAccounts":return this.getAccounts();case"eth_accounts":return this.getAccounts();case"wallet_switchEthereumChain":return this.handleSwitchChain(e.request.params?(r=e.request.params[0])==null?void 0:r.chainId:"0x0"),null;case"eth_chainId":return parseInt(this.getDefaultChain())}return this.namespace.methods.includes(e.request.method)?(Ki(this.client,e),await this.client.request(e)):this.getHttpProvider().request(e.request)}updateNamespace(e){this.namespace=Object.assign(this.namespace,e)}setDefaultChain(e,r){const n=gh(e);if(!this.httpProviders[n]){const i=r||an(`${this.name}:${n}`,this.namespace,this.client.core.projectId);if(!i)throw new Error(`No RPC url provided for chainId: ${n}`);this.setHttpProvider(n,i)}this.chainId=n,this.events.emit(fi.DEFAULT_CHAIN_CHANGED,`${this.name}:${n}`)}requestAccounts(){return this.getAccounts()}getDefaultChain(){if(this.chainId)return this.chainId.toString();if(this.namespace.defaultChain)return this.namespace.defaultChain;const e=this.namespace.chains[0];if(!e)throw new Error("ChainId not found");return e.split(":")[1]}createHttpProvider(e,r){const n=r||an(`${this.name}:${e}`,this.namespace,this.client.core.projectId);return typeof n>"u"?void 0:new ui(new Vi(n))}setHttpProvider(e,r){const n=this.createHttpProvider(e,r);n&&(this.httpProviders[e]=n)}createHttpProviders(){const e={};return this.namespace.chains.forEach(r=>{var n;const i=gh(r);e[i]=this.createHttpProvider(i,(n=this.namespace.rpcMap)==null?void 0:n[r])}),e}getAccounts(){const e=this.namespace.accounts;return e?[...new Set(e.filter(r=>r.split(":")[1]===this.chainId.toString()).map(r=>r.split(":")[2]))]:[]}getHttpProvider(){const e=this.chainId,r=this.httpProviders[e];if(typeof r>"u")throw new Error(`JSON-RPC provider for ${e} not found`);return r}handleSwitchChain(e){const r=parseInt(e,16),n=`${this.name}:${r}`;b7(n,this.namespace.chains),this.setDefaultChain(`${r}`)}}class O7{constructor(e){this.name="solana",this.namespace=e.namespace,this.events=e.events,this.client=e.client,this.chainId=this.getDefaultChain(),this.httpProviders=this.createHttpProviders()}updateNamespace(e){this.namespace=Object.assign(this.namespace,e)}requestAccounts(){return this.getAccounts()}request(e){return this.namespace.methods.includes(e.request.method)?(Ki(this.client,e),this.client.request(e)):this.getHttpProvider().request(e.request)}setDefaultChain(e,r){if(!this.httpProviders[e]){const n=r||an(`${this.name}:${e}`,this.namespace,this.client.core.projectId);if(!n)throw new Error(`No RPC url provided for chainId: ${e}`);this.setHttpProvider(e,n)}this.chainId=e,this.events.emit(fi.DEFAULT_CHAIN_CHANGED,`${this.name}:${this.chainId}`)}getDefaultChain(){if(this.chainId)return this.chainId;if(this.namespace.defaultChain)return this.namespace.defaultChain;const e=this.namespace.chains[0];if(!e)throw new Error("ChainId not found");return e.split(":")[1]}getAccounts(){const e=this.namespace.accounts;return e?[...new Set(e.filter(r=>r.split(":")[1]===this.chainId.toString()).map(r=>r.split(":")[2]))]:[]}createHttpProviders(){const e={};return this.namespace.chains.forEach(r=>{var n;e[r]=this.createHttpProvider(r,(n=this.namespace.rpcMap)==null?void 0:n[r])}),e}getHttpProvider(){const e=`${this.name}:${this.chainId}`,r=this.httpProviders[e];if(typeof r>"u")throw new Error(`JSON-RPC provider for ${e} not found`);return r}setHttpProvider(e,r){const n=this.createHttpProvider(e,r);n&&(this.httpProviders[e]=n)}createHttpProvider(e,r){const n=r||an(e,this.namespace,this.client.core.projectId);return typeof n>"u"?void 0:new ui(new Vi(n))}}class A7{constructor(e){this.name="cosmos",this.namespace=e.namespace,this.events=e.events,this.client=e.client,this.chainId=this.getDefaultChain(),this.httpProviders=this.createHttpProviders()}updateNamespace(e){this.namespace=Object.assign(this.namespace,e)}requestAccounts(){return this.getAccounts()}getDefaultChain(){if(this.chainId)return this.chainId;if(this.namespace.defaultChain)return this.namespace.defaultChain;const e=this.namespace.chains[0];if(!e)throw new Error("ChainId not found");return e.split(":")[1]}request(e){return this.namespace.methods.includes(e.request.method)?(Ki(this.client,e),this.client.request(e)):this.getHttpProvider().request(e.request)}setDefaultChain(e,r){if(this.chainId=e,!this.httpProviders[e]){const n=r||an(`${this.name}:${e}`,this.namespace,this.client.core.projectId);if(!n)throw new Error(`No RPC url provided for chainId: ${e}`);this.setHttpProvider(e,n)}this.events.emit(fi.DEFAULT_CHAIN_CHANGED,`${this.name}:${this.chainId}`)}getAccounts(){const e=this.namespace.accounts;return e?[...new Set(e.filter(r=>r.split(":")[1]===this.chainId.toString()).map(r=>r.split(":")[2]))]:[]}createHttpProviders(){const e={};return this.namespace.chains.forEach(r=>{var n;e[r]=this.createHttpProvider(r,(n=this.namespace.rpcMap)==null?void 0:n[r])}),e}getHttpProvider(){const e=`${this.name}:${this.chainId}`,r=this.httpProviders[e];if(typeof r>"u")throw new Error(`JSON-RPC provider for ${e} not found`);return r}setHttpProvider(e,r){const n=this.createHttpProvider(e,r);n&&(this.httpProviders[e]=n)}createHttpProvider(e,r){const n=r||an(e,this.namespace,this.client.core.projectId);return typeof n>"u"?void 0:new ui(new Vi(n))}}class D7{constructor(e){this.name="cip34",this.namespace=e.namespace,this.events=e.events,this.client=e.client,this.chainId=this.getDefaultChain(),this.httpProviders=this.createHttpProviders()}updateNamespace(e){this.namespace=Object.assign(this.namespace,e)}requestAccounts(){return this.getAccounts()}getDefaultChain(){if(this.chainId)return this.chainId;if(this.namespace.defaultChain)return this.namespace.defaultChain;const e=this.namespace.chains[0];if(!e)throw new Error("ChainId not found");return e.split(":")[1]}request(e){return this.namespace.methods.includes(e.request.method)?(Ki(this.client,e),this.client.request(e)):this.getHttpProvider().request(e.request)}setDefaultChain(e,r){if(this.chainId=e,!this.httpProviders[e]){const n=r||this.getCardanoRPCUrl(e);if(!n)throw new Error(`No RPC url provided for chainId: ${e}`);this.setHttpProvider(e,n)}this.events.emit(fi.DEFAULT_CHAIN_CHANGED,`${this.name}:${this.chainId}`)}getAccounts(){const e=this.namespace.accounts;return e?[...new Set(e.filter(r=>r.split(":")[1]===this.chainId.toString()).map(r=>r.split(":")[2]))]:[]}createHttpProviders(){const e={};return this.namespace.chains.forEach(r=>{const n=this.getCardanoRPCUrl(r);e[r]=this.createHttpProvider(r,n)}),e}getHttpProvider(){const e=`${this.name}:${this.chainId}`,r=this.httpProviders[e];if(typeof r>"u")throw new Error(`JSON-RPC provider for ${e} not found`);return r}getCardanoRPCUrl(e){const r=this.namespace.rpcMap;if(r)return r[e]}setHttpProvider(e,r){const n=this.createHttpProvider(e,r);n&&(this.httpProviders[e]=n)}createHttpProvider(e,r){const n=r||this.getCardanoRPCUrl(e);return typeof n>"u"?void 0:new ui(new Vi(n))}}class $7{constructor(e){this.name="elrond",this.namespace=e.namespace,this.events=e.events,this.client=e.client,this.chainId=this.getDefaultChain(),this.httpProviders=this.createHttpProviders()}updateNamespace(e){this.namespace=Object.assign(this.namespace,e)}requestAccounts(){return this.getAccounts()}request(e){return this.namespace.methods.includes(e.request.method)?(Ki(this.client,e),this.client.request(e)):this.getHttpProvider().request(e.request)}setDefaultChain(e,r){if(!this.httpProviders[e]){const n=r||an(`${this.name}:${e}`,this.namespace,this.client.core.projectId);if(!n)throw new Error(`No RPC url provided for chainId: ${e}`);this.setHttpProvider(e,n)}this.chainId=e,this.events.emit(fi.DEFAULT_CHAIN_CHANGED,`${this.name}:${this.chainId}`)}getDefaultChain(){if(this.chainId)return this.chainId;if(this.namespace.defaultChain)return this.namespace.defaultChain;const e=this.namespace.chains[0];if(!e)throw new Error("ChainId not found");return e.split(":")[1]}getAccounts(){const e=this.namespace.accounts;return e?[...new Set(e.filter(r=>r.split(":")[1]===this.chainId.toString()).map(r=>r.split(":")[2]))]:[]}createHttpProviders(){const e={};return this.namespace.chains.forEach(r=>{var n;e[r]=this.createHttpProvider(r,(n=this.namespace.rpcMap)==null?void 0:n[r])}),e}getHttpProvider(){const e=`${this.name}:${this.chainId}`,r=this.httpProviders[e];if(typeof r>"u")throw new Error(`JSON-RPC provider for ${e} not found`);return r}setHttpProvider(e,r){const n=this.createHttpProvider(e,r);n&&(this.httpProviders[e]=n)}createHttpProvider(e,r){const n=r||an(e,this.namespace,this.client.core.projectId);return typeof n>"u"?void 0:new ui(new Vi(n))}}class P7{constructor(e){this.name="multiversx",this.namespace=e.namespace,this.events=e.events,this.client=e.client,this.chainId=this.getDefaultChain(),this.httpProviders=this.createHttpProviders()}updateNamespace(e){this.namespace=Object.assign(this.namespace,e)}requestAccounts(){return this.getAccounts()}request(e){return this.namespace.methods.includes(e.request.method)?(Ki(this.client,e),this.client.request(e)):this.getHttpProvider().request(e.request)}setDefaultChain(e,r){if(!this.httpProviders[e]){const n=r||an(`${this.name}:${e}`,this.namespace,this.client.core.projectId);if(!n)throw new Error(`No RPC url provided for chainId: ${e}`);this.setHttpProvider(e,n)}this.chainId=e,this.events.emit(fi.DEFAULT_CHAIN_CHANGED,`${this.name}:${this.chainId}`)}getDefaultChain(){if(this.chainId)return this.chainId;if(this.namespace.defaultChain)return this.namespace.defaultChain;const e=this.namespace.chains[0];if(!e)throw new Error("ChainId not found");return e.split(":")[1]}getAccounts(){const e=this.namespace.accounts;return e?[...new Set(e.filter(r=>r.split(":")[1]===this.chainId.toString()).map(r=>r.split(":")[2]))]:[]}createHttpProviders(){const e={};return this.namespace.chains.forEach(r=>{var n;e[r]=this.createHttpProvider(r,(n=this.namespace.rpcMap)==null?void 0:n[r])}),e}getHttpProvider(){const e=`${this.name}:${this.chainId}`,r=this.httpProviders[e];if(typeof r>"u")throw new Error(`JSON-RPC provider for ${e} not found`);return r}setHttpProvider(e,r){const n=this.createHttpProvider(e,r);n&&(this.httpProviders[e]=n)}createHttpProvider(e,r){const n=r||an(e,this.namespace,this.client.core.projectId);return typeof n>"u"?void 0:new ui(new Vi(n))}}var T7=Object.defineProperty,R7=Object.defineProperties,N7=Object.getOwnPropertyDescriptors,xg=Object.getOwnPropertySymbols,L7=Object.prototype.hasOwnProperty,M7=Object.prototype.propertyIsEnumerable,Cg=(t,e,r)=>e in t?T7(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,oc=(t,e)=>{for(var r in e||(e={}))L7.call(e,r)&&Cg(t,r,e[r]);if(xg)for(var r of xg(e))M7.call(e,r)&&Cg(t,r,e[r]);return t},mh=(t,e)=>R7(t,N7(e));class wh{constructor(e){this.events=new yr.exports,this.rpcProviders={},this.shouldAbortPairingAttempt=!1,this.maxPairingAttempts=10,this.providerOpts=e,this.logger=typeof e?.logger<"u"&&typeof e?.logger!="string"?e.logger:pt.pino(pt.getDefaultLoggerOptions({level:e?.logger||vg}))}static async init(e){const r=new wh(e);return await r.initialize(),r}async request(e,r){const[n,i]=this.validateChain(r);if(!this.session)throw new Error("Please call connect() before request()");return await this.getProvider(n).request({request:oc({},e),chainId:`${n}:${i}`,topic:this.session.topic})}sendAsync(e,r,n){this.request(e,n).then(i=>r(null,i)).catch(i=>r(i,void 0))}async enable(){if(!this.client)throw new Error("Sign Client not initialized");return this.session||await this.connect({namespaces:this.namespaces,optionalNamespaces:this.optionalNamespaces,sessionProperties:this.sessionProperties}),await this.requestAccounts()}async disconnect(){var e;if(!this.session)throw new Error("Please call connect() before enable()");await this.client.disconnect({topic:(e=this.session)==null?void 0:e.topic,reason:Zt("USER_DISCONNECTED")}),await this.cleanup()}async connect(e){if(!this.client)throw new Error("Sign Client not initialized");if(this.setNamespaces(e),await this.cleanupPendingPairings(),!e.skipPairing)return await this.pair(e.pairingTopic)}on(e,r){this.events.on(e,r)}once(e,r){this.events.once(e,r)}removeListener(e,r){this.events.removeListener(e,r)}off(e,r){this.events.off(e,r)}get isWalletConnect(){return!0}async pair(e){this.shouldAbortPairingAttempt=!1;let r=0;do{if(this.shouldAbortPairingAttempt)throw new Error("Pairing aborted");if(r>=this.maxPairingAttempts)throw new Error("Max auto pairing attempts reached");const{uri:n,approval:i}=await this.client.connect({pairingTopic:e,requiredNamespaces:this.namespaces,optionalNamespaces:this.optionalNamespaces,sessionProperties:this.sessionProperties});n&&(this.uri=n,this.events.emit("display_uri",n)),await i().then(o=>{this.session=o}).catch(o=>{if(o.message!==fg)throw o;r++})}while(!this.session);return this.onConnect(),this.session}setDefaultChain(e,r){try{const[n,i]=this.validateChain(e);this.getProvider(n).setDefaultChain(i,r)}catch(n){if(!/Please call connect/.test(n.message))throw n}}async cleanupPendingPairings(e={}){this.logger.info("Cleaning up inactive pairings...");const r=this.client.pairing.getAll();if(Hn(r)){for(const n of r)e.deletePairings?this.client.core.expirer.set(n.topic,0):await this.client.core.relayer.subscriber.unsubscribe(n.topic);this.logger.info(`Inactive pairings cleared: ${r.length}`)}}abortPairingAttempt(){this.shouldAbortPairingAttempt=!0}async checkStorage(){if(this.namespaces=await this.getFromStore("namespaces")||{},this.optionalNamespaces=await this.getFromStore("optionalNamespaces")||{},this.client.session.length){const e=this.client.session.keys.length-1;this.session=this.client.session.get(this.client.session.keys[e]),this.createProviders()}}async initialize(){this.logger.trace("Initialized"),await this.createClient(),await this.checkStorage(),this.registerEventListeners()}async createClient(){this.client=this.providerOpts.client||await fh.init({logger:this.providerOpts.logger||vg,relayUrl:this.providerOpts.relayUrl||u7,projectId:this.providerOpts.projectId,metadata:this.providerOpts.metadata,storageOptions:this.providerOpts.storageOptions,name:this.providerOpts.name}),this.logger.trace("SignClient Initialized")}createProviders(){if(!this.client)throw new Error("Sign Client not initialized");if(!this.session)throw new Error("Session not initialized. Please call connect() before enable()");[...new Set(Object.keys(this.session.namespaces).map(e=>Za(e)))].forEach(e=>{if(!this.session)return;const r=E7(e,this.session),n=_7(r),i=x7(this.namespaces,this.optionalNamespaces),o=mh(oc({},i[e]),{accounts:r,chains:n});switch(e){case"eip155":this.rpcProviders[e]=new S7({client:this.client,namespace:o,events:this.events});break;case"solana":this.rpcProviders[e]=new O7({client:this.client,namespace:o,events:this.events});break;case"cosmos":this.rpcProviders[e]=new A7({client:this.client,namespace:o,events:this.events});break;case"polkadot":this.rpcProviders[e]=new I7({client:this.client,namespace:o,events:this.events});break;case"cip34":this.rpcProviders[e]=new D7({client:this.client,namespace:o,events:this.events});break;case"elrond":this.rpcProviders[e]=new $7({client:this.client,namespace:o,events:this.events});break;case"multiversx":this.rpcProviders[e]=new P7({client:this.client,namespace:o,events:this.events});break}})}registerEventListeners(){if(typeof this.client>"u")throw new Error("Sign Client is not initialized");this.client.on("session_ping",e=>{this.events.emit("session_ping",e)}),this.client.on("session_event",e=>{const{params:r}=e,{event:n}=r;n.name==="accountsChanged"?this.events.emit("accountsChanged",n.data):n.name==="chainChanged"?this.onChainChanged(r.chainId):this.events.emit(n.name,n.data),this.events.emit("session_event",e)}),this.client.on("session_update",({topic:e,params:r})=>{var n;const{namespaces:i}=r,o=(n=this.client)==null?void 0:n.session.get(e);this.session=mh(oc({},o),{namespaces:i}),this.onSessionUpdate(),this.events.emit("session_update",{topic:e,params:r})}),this.client.on("session_delete",async e=>{await this.cleanup(),this.events.emit("session_delete",e),this.events.emit("disconnect",mh(oc({},Zt("USER_DISCONNECTED")),{data:e.topic}))}),this.on(fi.DEFAULT_CHAIN_CHANGED,e=>{this.onChainChanged(e,!0)})}getProvider(e){if(!this.rpcProviders[e])throw new Error(`Provider not found: ${e}`);return this.rpcProviders[e]}onSessionUpdate(){Object.keys(this.rpcProviders).forEach(e=>{var r;this.getProvider(e).updateNamespace((r=this.session)==null?void 0:r.namespaces[e])})}setNamespaces(e){const{namespaces:r,optionalNamespaces:n,sessionProperties:i}=e;if(!r||!Object.keys(r).length)throw new Error("Namespaces must be not empty");this.namespaces=r,this.optionalNamespaces=n,this.sessionProperties=i,this.persist("namespaces",r),this.persist("optionalNamespaces",n)}validateChain(e){const[r,n]=e?.split(":")||["",""];if(r&&!Object.keys(this.namespaces).map(c=>Za(c)).includes(r))throw new Error(`Namespace '${r}' is not configured. Please call connect() first with namespace config.`);if(r&&n)return[r,n];const i=Za(Object.keys(this.namespaces)[0]),o=this.rpcProviders[i].getDefaultChain();return[i,o]}async requestAccounts(){const[e]=this.validateChain();return await this.getProvider(e).requestAccounts()}onChainChanged(e,r=!1){var n;const[i,o]=this.validateChain(e);r||this.getProvider(i).setDefaultChain(o),((n=this.namespaces[i])!=null?n:this.namespaces[`${i}:${o}`]).defaultChain=o,this.persist("namespaces",this.namespaces),this.events.emit("chainChanged",o)}onConnect(){this.createProviders(),this.events.emit("connect",{session:this.session})}async cleanup(){this.session=void 0,await this.cleanupPendingPairings({deletePairings:!0})}persist(e,r){this.client.core.storage.setItem(`${yg}/${e}`,r)}async getFromStore(e){return await this.client.core.storage.getItem(`${yg}/${e}`)}}const U7=wh,j7="wc",F7="ethereum_provider",B7=`${j7}@${2}:${F7}:`,k7="https://rpc.walletconnect.com/v1/",ac=["eth_sendTransaction","personal_sign"],H7=["eth_accounts","eth_requestAccounts","eth_call","eth_getBalance","eth_sendRawTransaction","eth_sign","eth_signTransaction","eth_signTypedData","eth_signTypedData_v3","eth_signTypedData_v4","wallet_switchEthereumChain","wallet_addEthereumChain","wallet_getPermissions","wallet_requestPermissions","wallet_registerOnboarding","wallet_watchAsset","wallet_scanQRCode"],cc=["chainChanged","accountsChanged"],z7=["message","disconnect","connect"];var W7=Object.defineProperty,q7=Object.defineProperties,V7=Object.getOwnPropertyDescriptors,Ig=Object.getOwnPropertySymbols,K7=Object.prototype.hasOwnProperty,G7=Object.prototype.propertyIsEnumerable,Sg=(t,e,r)=>e in t?W7(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,vh=(t,e)=>{for(var r in e||(e={}))K7.call(e,r)&&Sg(t,r,e[r]);if(Ig)for(var r of Ig(e))G7.call(e,r)&&Sg(t,r,e[r]);return t},Og=(t,e)=>q7(t,V7(e));function yh(t){return Number(t[0].split(":")[1])}function bh(t){return`0x${t.toString(16)}`}function Z7(t){const{chains:e,optionalChains:r,methods:n,optionalMethods:i,events:o,optionalEvents:c,rpcMap:l}=t;if(!Hn(e))throw new Error("Invalid chains");const h=e,d=n||ac,v=o||cc,E={[yh(h)]:l[yh(h)]},_={chains:h,methods:d,events:v,rpcMap:E},O=o?.filter(G=>!cc.includes(G)),P=n?.filter(G=>!ac.includes(G));if(!r&&!c&&!i&&!(O!=null&&O.length)&&!(P!=null&&P.length))return{required:_};const U=O?.length&&P?.length||!r,H={chains:[...new Set(U?h.concat(r||[]):r)],methods:[...new Set(d.concat(i||[]))],events:[...new Set(v.concat(c||[]))],rpcMap:l};return{required:_,optional:H}}class lc{constructor(){this.events=new yr.exports.EventEmitter,this.namespace="eip155",this.accounts=[],this.chainId=1,this.STORAGE_KEY=B7,this.on=(e,r)=>(this.events.on(e,r),this),this.once=(e,r)=>(this.events.once(e,r),this),this.removeListener=(e,r)=>(this.events.removeListener(e,r),this),this.off=(e,r)=>(this.events.off(e,r),this),this.parseAccount=e=>this.isCompatibleChainId(e)?this.parseAccountId(e).address:e,this.signer={},this.rpc={}}static async init(e){const r=new lc;return await r.initialize(e),r}async request(e){return await this.signer.request(e,this.formatChainId(this.chainId))}sendAsync(e,r){this.signer.sendAsync(e,r,this.formatChainId(this.chainId))}get connected(){return this.signer.client?this.signer.client.core.relayer.connected:!1}get connecting(){return this.signer.client?this.signer.client.core.relayer.connecting:!1}async enable(){return this.session||await this.connect(),await this.request({method:"eth_requestAccounts"})}async connect(e){if(!this.signer.client)throw new Error("Provider not initialized. Call init() first");this.loadConnectOpts(e);const{required:r,optional:n}=Z7(this.rpc);try{const i=await new Promise(async(c,l)=>{var h;this.rpc.showQrModal&&((h=this.modal)==null||h.subscribeModal(d=>{!d.open&&!this.signer.session&&(this.signer.abortPairingAttempt(),l(new Error("Connection request reset. Please try again.")))})),await this.signer.connect(Og(vh({namespaces:{[this.namespace]:r}},n&&{optionalNamespaces:{[this.namespace]:n}}),{pairingTopic:e?.pairingTopic})).then(d=>{c(d)}).catch(d=>{l(new Error(d.message))})});if(!i)return;this.setChainIds(this.rpc.chains);const o=T5(i.namespaces,[this.namespace]);this.setAccounts(o),this.events.emit("connect",{chainId:bh(this.chainId)})}catch(i){throw this.signer.logger.error(i),i}finally{this.modal&&this.modal.closeModal()}}async disconnect(){this.session&&await this.signer.disconnect(),this.reset()}get isWalletConnect(){return!0}get session(){return this.signer.session}registerEventListeners(){this.signer.on("session_event",e=>{const{params:r}=e,{event:n}=r;n.name==="accountsChanged"?(this.accounts=this.parseAccounts(n.data),this.events.emit("accountsChanged",this.accounts)):n.name==="chainChanged"?this.setChainId(this.formatChainId(n.data)):this.events.emit(n.name,n.data),this.events.emit("session_event",e)}),this.signer.on("chainChanged",e=>{const r=parseInt(e);this.chainId=r,this.events.emit("chainChanged",bh(this.chainId)),this.persist()}),this.signer.on("session_update",e=>{this.events.emit("session_update",e)}),this.signer.on("session_delete",e=>{this.reset(),this.events.emit("session_delete",e),this.events.emit("disconnect",Og(vh({},Zt("USER_DISCONNECTED")),{data:e.topic,name:"USER_DISCONNECTED"}))}),this.signer.on("display_uri",e=>{var r,n;this.rpc.showQrModal&&((r=this.modal)==null||r.closeModal(),(n=this.modal)==null||n.openModal({uri:e})),this.events.emit("display_uri",e)})}setHttpProvider(e){this.request({method:"wallet_switchEthereumChain",params:[{chainId:e.toString(16)}]})}isCompatibleChainId(e){return typeof e=="string"?e.startsWith(`${this.namespace}:`):!1}formatChainId(e){return`${this.namespace}:${e}`}parseChainId(e){return Number(e.split(":")[1])}setChainIds(e){const r=e.filter(n=>this.isCompatibleChainId(n)).map(n=>this.parseChainId(n));r.length&&(this.chainId=r[0],this.events.emit("chainChanged",bh(this.chainId)),this.persist())}setChainId(e){if(this.isCompatibleChainId(e)){const r=this.parseChainId(e);this.chainId=r,this.setHttpProvider(r)}}parseAccountId(e){const[r,n,i]=e.split(":");return{chainId:`${r}:${n}`,address:i}}setAccounts(e){this.accounts=e.filter(r=>this.parseChainId(this.parseAccountId(r).chainId)===this.chainId).map(r=>this.parseAccountId(r).address),this.events.emit("accountsChanged",this.accounts)}getRpcConfig(e){var r,n;return{chains:((r=e.chains)==null?void 0:r.map(i=>this.formatChainId(i)))||[`${this.namespace}:1`],optionalChains:e.optionalChains?e.optionalChains.map(i=>this.formatChainId(i)):void 0,methods:e?.methods||ac,events:e?.events||cc,optionalMethods:e?.optionalMethods||[],optionalEvents:e?.optionalEvents||[],rpcMap:e?.rpcMap||this.buildRpcMap(e.chains.concat(e.optionalChains||[]),e.projectId),showQrModal:Boolean(e?.showQrModal),qrModalOptions:(n=e?.qrModalOptions)!=null?n:void 0,projectId:e.projectId,metadata:e.metadata}}buildRpcMap(e,r){const n={};return e.forEach(i=>{n[i]=this.getRpcUrl(i,r)}),n}async initialize(e){if(this.rpc=this.getRpcConfig(e),this.chainId=yh(this.rpc.chains),this.signer=await U7.init({projectId:this.rpc.projectId,metadata:this.rpc.metadata}),this.registerEventListeners(),await this.loadPersistedSession(),this.rpc.showQrModal)try{const{Web3Modal:r}=await Promise.resolve().then(function(){return Sx});this.modal=new r(vh({walletConnectVersion:2,projectId:this.rpc.projectId,standaloneChains:this.rpc.chains},this.rpc.qrModalOptions))}catch{throw new Error("To use QR modal, please install @web3modal/standalone package")}}loadConnectOpts(e){if(!e)return;const{chains:r,optionalChains:n,rpcMap:i}=e;r&&Hn(r)&&(this.rpc.chains=r.map(o=>this.formatChainId(o)),r.forEach(o=>{this.rpc.rpcMap[o]=i?.[o]||this.getRpcUrl(o)})),n&&Hn(n)&&(this.rpc.optionalChains=[],this.rpc.optionalChains=n?.map(o=>this.formatChainId(o)),n.forEach(o=>{this.rpc.rpcMap[o]=i?.[o]||this.getRpcUrl(o)}))}getRpcUrl(e,r){var n;return((n=this.rpc.rpcMap)==null?void 0:n[e])||`${k7}?chainId=eip155:${e}&projectId=${r||this.rpc.projectId}`}async loadPersistedSession(){if(!this.session)return;const e=await this.signer.client.core.storage.getItem(`${this.STORAGE_KEY}/chainId`);this.setChainIds(e?[this.formatChainId(e)]:this.session.namespaces[this.namespace].accounts),this.setAccounts(this.session.namespaces[this.namespace].accounts)}reset(){this.chainId=1,this.accounts=[]}persist(){this.session&&this.signer.client.core.storage.setItem(`${this.STORAGE_KEY}/chainId`,this.chainId)}parseAccounts(e){return typeof e=="string"||e instanceof String?[this.parseAccount(e)]:e.map(r=>this.parseAccount(r))}}const Y7=lc,J7=Symbol(),Ag=Object.getPrototypeOf,_h=new WeakMap,X7=t=>t&&(_h.has(t)?_h.get(t):Ag(t)===Object.prototype||Ag(t)===Array.prototype),Q7=t=>X7(t)&&t[J7]||null,Dg=(t,e=!0)=>{_h.set(t,e)},Eh=t=>typeof t=="object"&&t!==null,di=new WeakMap,uc=new WeakSet,ex=(t=Object.is,e=(d,v)=>new Proxy(d,v),r=d=>Eh(d)&&!uc.has(d)&&(Array.isArray(d)||!(Symbol.iterator in d))&&!(d instanceof WeakMap)&&!(d instanceof WeakSet)&&!(d instanceof Error)&&!(d instanceof Number)&&!(d instanceof Date)&&!(d instanceof String)&&!(d instanceof RegExp)&&!(d instanceof ArrayBuffer),n=d=>{switch(d.status){case"fulfilled":return d.value;case"rejected":throw d.reason;default:throw d}},i=new WeakMap,o=(d,v,E=n)=>{const _=i.get(d);if(_?.[0]===v)return _[1];const O=Array.isArray(d)?[]:Object.create(Object.getPrototypeOf(d));return Dg(O,!0),i.set(d,[v,O]),Reflect.ownKeys(d).forEach(P=>{if(Object.getOwnPropertyDescriptor(O,P))return;const U=Reflect.get(d,P),H={value:U,enumerable:!0,configurable:!0};if(uc.has(U))Dg(U,!1);else if(U instanceof Promise)delete H.value,H.get=()=>E(U);else if(di.has(U)){const[G,N]=di.get(U);H.value=o(G,N(),E)}Object.defineProperty(O,P,H)}),O},c=new WeakMap,l=[1,1],h=d=>{if(!Eh(d))throw new Error("object required");const v=c.get(d);if(v)return v;let E=l[0];const _=new Set,O=(J,z=++l[0])=>{E!==z&&(E=z,_.forEach(ee=>ee(J,z)))};let P=l[1];const U=(J=++l[1])=>(P!==J&&!_.size&&(P=J,G.forEach(([z])=>{const ee=z[1](J);ee>E&&(E=ee)})),E),H=J=>(z,ee)=>{const de=[...z];de[1]=[J,...de[1]],O(de,ee)},G=new Map,N=(J,z)=>{if(void 0!=="production"&&G.has(J))throw new Error("prop listener already exists");if(_.size){const ee=z[3](H(J));G.set(J,[z,ee])}else G.set(J,[z])},L=J=>{var z;const ee=G.get(J);ee&&(G.delete(J),(z=ee[1])==null||z.call(ee))},$=J=>(_.add(J),_.size===1&&G.forEach(([ee,de],me)=>{if(void 0!=="production"&&de)throw new Error("remove already exists");const S=ee[3](H(me));G.set(me,[ee,S])}),()=>{_.delete(J),_.size===0&&G.forEach(([ee,de],me)=>{de&&(de(),G.set(me,[ee]))})}),T=Array.isArray(d)?[]:Object.create(Object.getPrototypeOf(d)),f=e(T,{deleteProperty(J,z){const ee=Reflect.get(J,z);L(z);const de=Reflect.deleteProperty(J,z);return de&&O(["delete",[z],ee]),de},set(J,z,ee,de){const me=Reflect.has(J,z),S=Reflect.get(J,z,de);if(me&&(t(S,ee)||c.has(ee)&&t(S,c.get(ee))))return!0;L(z),Eh(ee)&&(ee=Q7(ee)||ee);let j=ee;if(ee instanceof Promise)ee.then(ce=>{ee.status="fulfilled",ee.value=ce,O(["resolve",[z],ce])}).catch(ce=>{ee.status="rejected",ee.reason=ce,O(["reject",[z],ce])});else{!di.has(ee)&&r(ee)&&(j=h(ee));const ce=!uc.has(j)&&di.get(j);ce&&N(z,ce)}return Reflect.set(J,z,j,de),O(["set",[z],ee,S]),!0}});c.set(d,f);const x=[T,U,o,$];return di.set(f,x),Reflect.ownKeys(d).forEach(J=>{const z=Object.getOwnPropertyDescriptor(d,J);"value"in z&&(f[J]=d[J],delete z.value,delete z.writable),Object.defineProperty(T,J,z)}),f})=>[h,di,uc,t,e,r,n,i,o,c,l],[tx]=ex();function Tn(t={}){return tx(t)}function Vn(t,e,r){const n=di.get(t);void 0!=="production"&&!n&&console.warn("Please use proxy object");let i;const o=[],c=n[3];let l=!1;const d=c(v=>{if(o.push(v),r){e(o.splice(0));return}i||(i=Promise.resolve().then(()=>{i=void 0,l&&e(o.splice(0))}))});return l=!0,()=>{l=!1,d()}}function rx(t,e){const r=di.get(t);void 0!=="production"&&!r&&console.warn("Please use proxy object");const[n,i,o]=r;return o(n,i(),e)}var $g={},hc={};hc.byteLength=sx,hc.toByteArray=ax,hc.fromByteArray=ux;for(var Rn=[],cn=[],nx=typeof Uint8Array<"u"?Uint8Array:Array,xh="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",Ps=0,ix=xh.length;Ps<ix;++Ps)Rn[Ps]=xh[Ps],cn[xh.charCodeAt(Ps)]=Ps;cn["-".charCodeAt(0)]=62,cn["_".charCodeAt(0)]=63;function Pg(t){var e=t.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=t.indexOf("=");r===-1&&(r=e);var n=r===e?0:4-r%4;return[r,n]}function sx(t){var e=Pg(t),r=e[0],n=e[1];return(r+n)*3/4-n}function ox(t,e,r){return(e+r)*3/4-r}function ax(t){var e,r=Pg(t),n=r[0],i=r[1],o=new nx(ox(t,n,i)),c=0,l=i>0?n-4:n,h;for(h=0;h<l;h+=4)e=cn[t.charCodeAt(h)]<<18|cn[t.charCodeAt(h+1)]<<12|cn[t.charCodeAt(h+2)]<<6|cn[t.charCodeAt(h+3)],o[c++]=e>>16&255,o[c++]=e>>8&255,o[c++]=e&255;return i===2&&(e=cn[t.charCodeAt(h)]<<2|cn[t.charCodeAt(h+1)]>>4,o[c++]=e&255),i===1&&(e=cn[t.charCodeAt(h)]<<10|cn[t.charCodeAt(h+1)]<<4|cn[t.charCodeAt(h+2)]>>2,o[c++]=e>>8&255,o[c++]=e&255),o}function cx(t){return Rn[t>>18&63]+Rn[t>>12&63]+Rn[t>>6&63]+Rn[t&63]}function lx(t,e,r){for(var n,i=[],o=e;o<r;o+=3)n=(t[o]<<16&16711680)+(t[o+1]<<8&65280)+(t[o+2]&255),i.push(cx(n));return i.join("")}function ux(t){for(var e,r=t.length,n=r%3,i=[],o=16383,c=0,l=r-n;c<l;c+=o)i.push(lx(t,c,c+o>l?l:c+o));return n===1?(e=t[r-1],i.push(Rn[e>>2]+Rn[e<<4&63]+"==")):n===2&&(e=(t[r-2]<<8)+t[r-1],i.push(Rn[e>>10]+Rn[e>>4&63]+Rn[e<<2&63]+"=")),i.join("")}var Ch={};/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */Ch.read=function(t,e,r,n,i){var o,c,l=i*8-n-1,h=(1<<l)-1,d=h>>1,v=-7,E=r?i-1:0,_=r?-1:1,O=t[e+E];for(E+=_,o=O&(1<<-v)-1,O>>=-v,v+=l;v>0;o=o*256+t[e+E],E+=_,v-=8);for(c=o&(1<<-v)-1,o>>=-v,v+=n;v>0;c=c*256+t[e+E],E+=_,v-=8);if(o===0)o=1-d;else{if(o===h)return c?NaN:(O?-1:1)*(1/0);c=c+Math.pow(2,n),o=o-d}return(O?-1:1)*c*Math.pow(2,o-n)},Ch.write=function(t,e,r,n,i,o){var c,l,h,d=o*8-i-1,v=(1<<d)-1,E=v>>1,_=i===23?Math.pow(2,-24)-Math.pow(2,-77):0,O=n?0:o-1,P=n?1:-1,U=e<0||e===0&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(l=isNaN(e)?1:0,c=v):(c=Math.floor(Math.log(e)/Math.LN2),e*(h=Math.pow(2,-c))<1&&(c--,h*=2),c+E>=1?e+=_/h:e+=_*Math.pow(2,1-E),e*h>=2&&(c++,h/=2),c+E>=v?(l=0,c=v):c+E>=1?(l=(e*h-1)*Math.pow(2,i),c=c+E):(l=e*Math.pow(2,E-1)*Math.pow(2,i),c=0));i>=8;t[r+O]=l&255,O+=P,l/=256,i-=8);for(c=c<<i|l,d+=i;d>0;t[r+O]=c&255,O+=P,c/=256,d-=8);t[r+O-P]|=U*128};/*!
|
|
99
99
|
* The buffer module from node.js, for the browser.
|
|
100
100
|
*
|
|
101
101
|
* @author Feross Aboukhadijeh <https://feross.org>
|